Home / Packages / Simulation / Geant4 / Instructions

Instructions for Geant4 simulation

How to …

  1. Batch jobs
    1. run in batch mode
    2. watch or kill batch jobs
    3. terminate cleanly an LSF batch job
  2. Running interactively (with/without interactive Geant4 or Athena)
    1. Geant4 interactive session, Python non-interactive session
    2. Geant4 interactive session and Python interactive session
    3. Geant4 non-interactive session, Python interactive session">
  3. Running with python scripting only (preliminary) TBD
  4. Setting parameters
    1. run with/without GeoModel
    2. run with/without magnetic field
    3. define the primary vertex region and other restricted regions
    4. define G4 Regions and set cuts per G4 Region
    5. change a Physics List
    6. perform an action
  5. Working with macros
    1. create an html directory for all the available commands
    2. queue and execute more than one macro
  6. Visualize detector and particle trajectories
    1. visualize your detector
    2. make use of the new visualization commands
    3. make use of special visualization commands
    4. draw a particle trajectory
  7. See also

1) Batch jobs

How to run in batch mode - tbd

In directory "run" get the jobOptions and then execute the Athena G4 python script

		 >  athena.py   AtlasG4Sim/jobOptions.AtlasG4Sim.py  
		  or alternatively   
		 >  get_files   jobOptions.AtlasG4Sim.py 
> athena.py   jobOptions.AtlasG4Sim.py
or using the alias to athena.py > G4Atlas   jobOptions.AtlasG4Sim.py

How to watch or kill batch jobs

You can check the status of your job(s) by executing the bjobs command, which takes a jobID as parameter for the "long command". You can kill your jobs with command bkill

 
			>  bjobs 
> bjobs -l jobID
> bkill jobID

How to terminate cleanly an LSF batch job

To terminate an LSF batch job before it reaches its time limit, the service LSFTimeKeeper (package Control) has to be activated by including in your top-level jobOptions


				#include "LSFTimeKeeper/LSFTimeKeeperOptions.py"
			

If you do not run an LSF job, but still want your job to terminate after a certain time, add the following lines, where 3600 is the time in total CPU seconds. Be aware that the average event processing time reported by the LSF and POSIX time-keepers are calculated differently and may not agree with each other.


				AthenaEventLoopMgr.TimeKeeper = "SimplePOSIXTimeKeeperSvc"; 
SimplePOSIXTimeKeeperSvc.AllocTime = 3600;

↑ Top

2) Interactive jobs

How to run interactively

Under control of the python script athena.py the Geant4 and/or the Athena sessions can be run interactively.

Geant4 interactive session, Python non-interactive session
In the file jobOptions.AtlasG4Sim.py set InteractiveG4 to TRUE. When you execute G4Atlas, you will be prompted with PreInit>. The program will end when typing exit.
				 >   G4Atlas   jobOptions.AtlasG4Sim.py	
PreInit>
PreInit> exit
Geant4 interactive session and Python interactive session
Start G4Atlas with the -i option. You will be prompted with athena>. To start the G4 interactive session, type theApp.initialize(). The program will stop with the PreInit> prompt. By typing exit the program will return to the athena> prompt.
By typing theApp.run() the default number of events will be processed; by typing theApp.run(10) 10 events will be processed. After processing, the program returns to python. To terminate type theApp.exit().
 
					 >   G4Atlas -i jobOptions.AtlasG4Sim.py 
athena>
athena> theApp.initialize()
PreInit>
PreInit> exit
athena>

athena> theApp.run()   or   theApp.run(10)
athena> theApp.exit()
Geant4 non-interactive session and Python interactive session
In the file jobOptions.AtlasG4Sim.py leave the value for InteractiveG4 at its default value FALSE. The interactive G4 part will be skipped and the program stops in python with the athena> prompt. Continue as in the previous case.

3) How to run with python scripting only (preliminary)

TBD

↑ Top

4) Setting parameters

How to run with/without GeoModel

The jobOptions for GeoModel are jobOptions.AtlasGeoG4Sim.py. Use them similar to the instructions for jobOptions.AtlasG4Sim.py in "How to run in batch mode".

Warning: in rel 8.3.0 add the following line in your jobOptions


				#include "AtlasGeoModel/InDetGeoModel.txt"  (add after this line) 
#include "AtlasGeoModel/MuonGeoModel.txt"

How to run with/without magnetic field

The default is to use the magnetic field. To run without magnetic field, comment out the following line in the macro, which sets up the geometry, e.g. Atlas.mac or AtlasGeoModel.mac.


			/control/execute AtlasField.mac 
		

How to define the primary vertex region and other restricted regions

Vertex region and vertex spread, as well as the geometrical region for generation can be declared as follows


			/Filters/Vertex/toggle ON 
/Filters/Vertex/Spread 0.015 0.015 56. mm
/Filters/EtaPhiFilter/toggle ON
/Filters/EtaPhiFilter/EtaInterval -3.2 3.2

In this example the primary vertex will be Gaussian distributed with sigmas in (x,y,z) of the defined values and eta will be restricted to -3.2 lt; eta < 3.2

How to define G4 Regions and set cuts per G4 Region

The two examples show how a Region is defined, a geometrical volume assigned to it and cuts defined for the particles. Example for Muon MDTs:


			/Physics/Region/CreateNew DriftWall 
/Physics/Region/DriftWall/AddVolume MuonSystem::MDTDriftWall
/Physics/Region/DriftWall/SetParticleCut e- 0.005 mm

Example for LAr


			/Physics/Region/DriftWall/SetParticleCut e+ 0.005 mm 
/Physics/Region/CreateNew HEC
/Physics/Region/HEC/AddVolume LAr::HEC::LiquidArgon
/Physics/Region/HEC/SetParticleCut e-   0.020 mm
/Physics/Region/HEC/SetParticleCut e+   0.020 mm
/Physics/Region/HEC/SetParticleCut gamma 0.020 mm

Note: When you assign a Region to a logical volume, it includes all the daughter volumes. The above statements set the cuts for the entire LAr volume that encloses the HEC, as well as all volumes of the HEC itself.

How to change a physics list

The definition of the physics lists used by ATLAS is available on CVS, directory G4PhysicsList (*.hh and *.icc files on LXR). To know more about the physics list, refer to the Geant4 manual, Physics Lists (new pages not yet fully implemented, old pages no longer functional). The old G4 manual is still accessible, see Physics reference manual.

How to perform an action

To perform an action at the beginning of Run/Event/Step use these commands


			/Actions/RegisterForAction G4SimTimer BeginOfEvent 
/Actions/RegisterForAction G4SimTimer EndOfEvent
/Actions/RegisterForAction G4SimTimer BeginOfRun
/Actions/RegisterForAction G4SimTimer EndOfRun

In this example the G4SimTimer is requested to act at the Begin/End of the event and the Begin/End of the run.

5) Working with macros

How to create an html directory for all available commands

Create a new directory and then execute the command to create the HTML directory tree. Start to navigate the tree from the file _.html. If newdir is not specified, then the tree will be created in the directory, where the command was executed.


			> mkdir  newdir 

Preinit> control/createHTML newdir

How to queue and execute more than one macro

In your jobOptions file replace the line G4Svc.FADSMacro … , with a line which specifies the macros as shown below. The macros are executed in the order in which they are declared.


			G4Svc.FADSMacro         =  "Atlas.mac";  
  replace with
G4Svc.FADSMacro = "macro1.mac:macro2.mac:etc ";

Run interactively as explained above. Start from the Preinit> prompt and print the physics list


			Preinit> Physics/PrintLists   

Printing the list of pre-defined physics lists:
10
--- Physics list ExN01
--- Physics list ExN02
--- Physics list ExN03
--- Physics list ExN04
--- Physics list Fast_Physics
--- Physics list LHEP_BERT
--- Physics list LHEP_GN
--- Physics list QGSP_BERT
--- Physics list QGSP_GN

Do not forget to set the values of cuts such that they are best suited for your studies. Then set the new physics list.


			/Physics/SetGeneralCut 1 mm  
/Physics/GetPhysicsList QGSP_GN Physics/ConstructPhysicsList

↑ Top

6) Visualize detector and particle trajectories

How to visualize your detector

Activate in your jobOptions file the interactive G4 and visualization.


			G4Svc.InteractiveG4 = true;  
G4Svc.Visualize = true;

The command sequence is listed below using the example macro for displaying the beampipe (red), fastvisual.mac. Copy the macro Atlas.mac to your run directory. Copy also the file fastvisual.mac or provide your own macro. Then start the job as shown below. In the athena prompt athena> type the usual command to initialize, and in the PreInit> prompt execute the macro fastvisual.mac. By default a VRML 1.0 File g4_00.wrl is generated. This takes a while, the time is proportional to the number of volumes to be drawn. A graphics window will pop up; you can modify the windows dimensions, the visualization parameters, and - using the mouse - rotate, zoom, translate, and save your drawing as jpg file. To continue, close the window by choosing from menu "File" > "Close". This returns to the PreInit> prompt. Continue and terminate as described above.


			>  cd  <your_run_directory>  
> get_files Atlas.mac
  [ download file fastvisual.mac ]
> G4Atlas -i jobOptions.AtlasG4Sim.py

athena> theApp.initialize()

PreInit> /control/execute fastvisual.mac
  [ window pops up, when you are finished close it ]
PreInit> exit

athena> theApp.run()

How to make use of the new visualization commands

(Merge with previous section, once it is clarified where login.mac is located)

If you add to the jobOptions the following line, the interactive session will start the command with a list of all logical volumes currently defined, grouped by detector:

			G4Svc.FADSMacro         =  "login.mac:Atlas.mac";  
  [ starts the session with the command ]
/Geometry/ListAllVolumes

How to make use of special visualization commands


			/vis/DrawDetector     detName depthOfDescent
/vis/DrawLogicalVolume volName depthOfDescent

The first command draws an entire detector (e.g. TRT), the second command draws a logical volume (LV) tree.

How to draw a particle trajectory

To draw a particle trajectory, execute commands similar to the following example for the Inner Detector:


		/load G4UserActions
/load G4EventGraphics
/Actions/RegisterForAction DrawEventAction BeginOfEvent
/Actions/RegisterForAction DrawEventAction EndOfEvent
/Geometry/Volumes/SetMaxStep IDET::IDET 5 cm
/EventGraphics/TrackDisplayLevel 1
/EventGraphics/TrackColorScheme 3
/EventGraphics/TrackPtCut .3 GeV
/EventGraphics/NeutralTracks Off

See also

↑ Top