Short Course NSS2008

Setup environment (AFS)

source /afs/

Demo 1: compile and run a brachytherapy simulation locally

The objective is to understand the basics of a Geant 4 simulation application.

$ cd apps/G4Brachy
$ source
$ gmake

$ ./workdir/bin/Linux-g++/Brachy macros/default.mac 1

$ show_hist brachytherapy.xml 20 30

$ gmake clean

Exercise 1: Running a Geant4 application: particle beam

Perform the following steps:
  • Compile the Geant4 particle beam example application. Solution:
         $ cd apps/G4ParticleBeam
         $ source
         $ gmake
  • Execute the particle beam example using the macro file electronbeam.mac. The application simulates 5.5 MeV electrons impinging on a water box and computes the longitudinal energy deposition profile inside the box. By default 100 events are simulated. Solution:
         ./workdir/bin/Linux-g++/ParticleBeam macros/electronbeam.mac 1
  • The simulation program created an xml file (simoutput.xml) containing a histogram "energydeposit". Visualize the computed energy deposition profile by executing
         show_hist simoutput.xml energydeposit
  • Rerun the application with an increased number of events (3000) and visualize the output. Solution: Change in the macro file the following command:
         \run\beamOn 3000
    and execute again
         $ ./workdir/bin/Linux-g++/ParticleBeam macros/electronbeam.mac 1
         $ show_hist simoutput.xml energydeposit
  • As a next step change the incident angle of the beam to 60 deg and rerun the application. Visualize the results. Solution: Change in the macro file the following command:
         /source/incidentAngle 60.0 deg

Demo 2.1: Ganga Primer

The objective here is learn how Ganga works using very basic commands.

Create a small executable file (using editor or shell cat command):

$ cat > say_hello
#!/usr/bin/env bash
echo Hello $*
$ chmod u+x say_hello
$ ./say_hello XXX
Hello XXX

Submit jobs using ganga (interactively):

$ ganga 

j = Job()
j.application.args = ['DRESDEN']'Hello Dresden!'
print j

j2 = j.copy()

j2.application.args = ['GRID','AUS', 'DRESDEN!!!']'Hello Grid!'

Useful commands and options in the interactive shell:

# optionally select the CE, one of:


!ls -l $j.outputdir


Demo 2.1: Geant4 with Ganga

First create a small wrapper file which will source the environment, compile and run the application. The entire directory G4Brachy is packed into a tarfile and sent with the job. Use editor or cat command.

Remember to gmake clean in the apps/G4Brachy directory to avoid shipping unnecessary binary files

$cd apps
$tar cfz G4Brachy.tgz G4Brachy
$cat > run_brachy
#!/usr/bin/env bash
tar xfzv G4Brachy.tgz
cd G4Brachy
gmake clean #just in case we forgot to clean before the job was sent
./workdir/bin/Linux-g++/Brachy macros/default.mac $1
mv *.xml .. #move all outputs one level up so Ganga will find it
$ chmod u+x run_brachy

$ ganga

j = Job()

j2 = j.copy()

if j.status == 'completed': 
 !show_hist $j.outputdir/brachytherapy.xml 20 30

Exercise 2.1: Particle Beam

To be defined.

Demo 2.2: Geant4 with Ganga (split jobs)

Objective: simulate more events using a fixed number of processors

Now the code gets more complex, so we will save it in a file and let ganga execute in one go.

$ cd apps
$ cat > submit_brachy

j = Job()


j.splitter = ArgSplitter()
for i in range(10):



Now you may run all the commands in one go:

$ ganga submit_brachy

Start ganga in the interactive mode and have a look at the job - it should contain 10 subjobs:

$ ganga

j = jobs[-1]
print j

Exercise 2.2: Particle Beam

increase the statistics

Demo 3.0: Geant4 with Ganga + DIANE on the Grid

Objective: simulate more events using variable number of processors (up to specified number) and splitting job into many more smaller pieces.

The easiest way to understand what's going on is to start two windows.

Window 1: master will receive the intermediate results and will print messages to show what is going on

diane-run apps/G4Brachy/macros/

Take note of the run directory.

Window 2: submission of jobs and visualisation

ganga --diane-worker-number=10 # 10 jobs on the Grid

ganga --diane-worker-number=1  # one job locally

show_hist_live rundir/merged1D_brachytherapy.xml 20 30

Exercise 3.0: Particle Beam

IMPORTANT: modify port number in the run file!


-- JakubMoscicki - 17 Oct 2008

Edit | Attach | Watch | Print version | History: r8 < r7 < r6 < r5 < r4 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r8 - 2009-02-25 - JakubMoscicki
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    ArdaGrid All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback