Geant4 Cross Reference |
1 ---------------------------------------------- 1 ------------------------------------------------------------------- 2 2 3 ========================================= 3 ========================================================= 4 Geant4 - an Object-Oriented Toolkit for S 4 Geant4 - an Object-Oriented Toolkit for Simulation in HEP 5 ========================================= 5 ========================================================= 6 6 7 Example B2 7 Example B2 8 ---------- 8 ---------- 9 9 10 This example simulates a simplified fixed tar 10 This example simulates a simplified fixed target experiment. 11 11 12 1- GEOMETRY DEFINITION 12 1- GEOMETRY DEFINITION 13 << 13 14 The setup consists of a target followed b 14 The setup consists of a target followed by six chambers of increasing 15 transverse size at defined instances from << 15 transverse size at defined instances from the target. These chambers are 16 located in a region called the Tracker re << 16 located in a region called the Tracker region. 17 Their shape are cylinders, constructed as 17 Their shape are cylinders, constructed as simple cylinders 18 (in B2a::DetectorConstruction) and as par << 18 (in B2aDetectorConstruction) and as parametrised volumes 19 (in B2b::DetectorConstruction), see also << 19 (in B2bDetectorConstruction), see also B2bChamberParameterisation class. 20 20 21 In addition, a global, uniform, and trans << 21 In addition, a global, uniform, and transverse magnetic field can be 22 applied using G4GlobalMagFieldMessenger, << 22 applied using G4GlobalMagFieldMessenger, instantiated in 23 B2[a,b]::DetectorConstruction::ConstructS << 23 B2[a,b]DetectorConstruction::ConstructSDandField with a non zero field value, 24 or via interactive commands. << 24 or via interactive commands. 25 For example: 25 For example: 26 26 27 /globalField/setValue 0.2 0 0 tesla 27 /globalField/setValue 0.2 0 0 tesla 28 << 28 29 An instance of the B2::TrackerSD class is << 29 An instance of the B2TrackerSD class is created and associated with each 30 logical chamber volume (in B2a) and with << 30 logical chamber volume (in B2a) and with the one G4LogicalVolume associated 31 with G4PVParameterised (in B2b). << 31 with G4PVParameterised (in B2b). 32 32 33 One can change the materials of the targe 33 One can change the materials of the target and the chambers 34 interactively via the commands defined in << 34 interactively via the commands defined in B2aDetectorMessenger 35 (or B2b::DetectorMessenger). For example: << 35 (or B2bDetectorMessenger). For example: 36 36 37 /B2/det/setTargetMaterial G4_WATER 37 /B2/det/setTargetMaterial G4_WATER 38 /B2/det/setChamberMaterial G4_Ar 38 /B2/det/setChamberMaterial G4_Ar 39 << 39 40 2- PHYSICS LIST 40 2- PHYSICS LIST 41 41 42 The particle's type and the physic proces 42 The particle's type and the physic processes which will be available 43 in this example are set in the FTFP_BERT << 43 in this example are set in the FTFP_BERT physics list. This physics list 44 requires data files for electromagnetic a 44 requires data files for electromagnetic and hadronic processes. 45 See more on installation of the datasets 45 See more on installation of the datasets in Geant4 Installation Guide, 46 Chapter 3.3: Note On Geant4 Datasets: 46 Chapter 3.3: Note On Geant4 Datasets: 47 http://geant4.web.cern.ch/geant4/UserDocu 47 http://geant4.web.cern.ch/geant4/UserDocumentation/UsersGuides/InstallationGuide/html/ch03s03.html 48 The following datasets: G4LEDATA, G4LEVEL 48 The following datasets: G4LEDATA, G4LEVELGAMMADATA, G4SAIDXSDATA and 49 G4ENSDFSTATEDATA are mandatory for this e 49 G4ENSDFSTATEDATA are mandatory for this example. 50 << 50 51 In addition, the build-in interactive com 51 In addition, the build-in interactive command: 52 /process/(in)activate processName 52 /process/(in)activate processName 53 allows the user to activate/inactivate th 53 allows the user to activate/inactivate the processes one by one. 54 54 55 3- ACTION INITALIZATION 55 3- ACTION INITALIZATION 56 56 57 A newly introduced class, B2::ActionInitial << 57 A newly introduced class, B2ActionInitialization, 58 instantiates and registers to Geant4 kernel 58 instantiates and registers to Geant4 kernel all user action classes. 59 << 59 60 While in sequential mode the action classes 60 While in sequential mode the action classes are instatiated just once, 61 via invoking the method: 61 via invoking the method: 62 B2::ActionInitialization::Build() << 62 B2ActionInitialization::Build() 63 in multi-threading mode the same method is 63 in multi-threading mode the same method is invoked for each thread worker 64 and so all user action classes are defined 64 and so all user action classes are defined thread-local. 65 65 66 A run action class is instantiated both thr << 66 A run action class is instantiated both thread-local 67 and global that's why its instance has is c 67 and global that's why its instance has is created also in the method 68 B2::ActionInitialization::BuildForMaster << 68 B2ActionInitialization::BuildForMaster() 69 which is invoked only in multi-threading mo 69 which is invoked only in multi-threading mode. 70 70 71 4- PRIMARY GENERATOR 71 4- PRIMARY GENERATOR 72 72 73 The primary generator action class employ << 73 The primary generator action class employs the G4ParticleGun. 74 The primary kinematics consists of a sing << 74 The primary kinematics consists of a single particle which hits the target 75 to the world boundary and hits the target << 75 perpendicular to the entrance face. The type of the particle 76 face. The type of the particle and its en << 76 and its energy can be changed via the G4 built-in commands of 77 Geant4 built-in commands of the G4Particl << 77 the G4ParticleGun class. 78 << 78 79 5- RUNS and EVENTS 79 5- RUNS and EVENTS 80 << 80 81 A run is a set of events. 81 A run is a set of events. 82 << 82 83 The user has control: 83 The user has control: 84 - at Begin and End of each run (class << 84 - at Begin and End of each run (class B2RunAction) 85 - at Begin and End of each event (clas << 85 - at Begin and End of each event (class B2EventAction) 86 - at Begin and End of each track (clas 86 - at Begin and End of each track (class TrackingAction, not used here) 87 - at End of each step (class SteppingAction, 87 - at End of each step (class SteppingAction, not used here) 88 << 88 89 The event number is written to the log fi << 89 The event number is written to the log file every requested number 90 of events in B2::EventAction::BeginOfEven << 90 of events in B2EventAction::BeginOfEventAction() and 91 B2::EventAction::EndOfEventAction(). << 91 B2EventAction::EndOfEventAction(). 92 Moreover, for the first 100 events and ev << 92 Moreover, for the first 100 events and every 100 events thereafter 93 information about the number of stored tr << 93 information about the number of stored trajectories in the event 94 is printed as well as the number of hits << 94 is printed as well as the number of hits stored in the G4VHitsCollection. 95 << 95 96 The run number is printed at B2::RunActio << 96 The run number is printed at B2RunAction::BeginOfRunAction(), where the 97 G4RunManager is also informed how to SetR << 97 G4RunManager is also informed how to SetRandomNumberStore for storing 98 initial random number seeds per run or pe << 98 initial random number seeds per run or per event. 99 99 100 6- USER LIMITS 100 6- USER LIMITS 101 << 101 102 This example also illustrates how to intro 102 This example also illustrates how to introduce tracking constraints 103 like maximum step length, minimum kinetic 103 like maximum step length, minimum kinetic energy etc. via the G4UserLimits 104 class and associated G4StepLimiter and G4U << 104 class and associated G4StepLimiter and G4UserSpecialCuts processes. 105 See B2a::DetectorConstruction (or B2b::Det << 105 See B2aDetectorConstruction (or B2bDetectorConstruction). 106 106 107 The maximum step limit in the tracker regi 107 The maximum step limit in the tracker region can be set by the interactive 108 command (see B2a::DetectorMessenger, B2b:: << 108 command (see B2aDetectorMessenger, B2bDetectorMessenger classes). 109 For example: 109 For example: 110 110 111 /B2/det/stepMax 1.0 mm 111 /B2/det/stepMax 1.0 mm 112 112 113 7- DETECTOR RESPONSE 113 7- DETECTOR RESPONSE 114 << 114 115 A HIT is a step per step record of all th 115 A HIT is a step per step record of all the information needed to 116 simulate and analyse the detector respons 116 simulate and analyse the detector response. 117 << 117 118 In this example the Tracker chambers are 118 In this example the Tracker chambers are considered to be the detector. 119 Therefore, the chambers are declared 'sen 119 Therefore, the chambers are declared 'sensitive detectors' (SD) in 120 the B2a::DetectorConstruction (or B2b::De << 120 the B2aDetectorConstruction (or B2bDetectorConstruction) class. 121 They are associated with an instance of t << 121 They are associated with an instance of the B2TrackerSD class. 122 << 122 123 Then, a Hit is defined as a set of 4 info 123 Then, a Hit is defined as a set of 4 informations per step, inside 124 the chambers, namely: 124 the chambers, namely: 125 - the track identifier (an integer), 125 - the track identifier (an integer), 126 - the chamber number, 126 - the chamber number, 127 - the total energy deposit in this step, and 127 - the total energy deposit in this step, and 128 - the position of the energy deposit. 128 - the position of the energy deposit. 129 129 130 A given hit is an instance of the class B << 130 A given hit is an instance of the class B2TrackerHit which is created 131 during the tracking of a particle, step b 131 during the tracking of a particle, step by step, in the method 132 B2::TrackerSD::ProcessHits(). This hit is << 132 B2TrackerSD::ProcessHits(). This hit is inserted in a HitsCollection. 133 133 134 The HitsCollection is printed at the end 134 The HitsCollection is printed at the end of each event (via the method 135 B2::TrackerSD::EndOfEvent()), under the c << 135 B2TrackerSD::EndOfEvent()), under the control of the command: 136 /hits/verbose 2 136 /hits/verbose 2 137 137 138 The following paragraphs are common to all ba 138 The following paragraphs are common to all basic examples 139 139 140 A- VISUALISATION 140 A- VISUALISATION 141 141 142 The visualization manager is set via the G4 142 The visualization manager is set via the G4VisExecutive class 143 in the main() function in exampleB2a.cc (or << 143 in the main() function in exampleB2a.cc (or exampleB2b.cc). 144 The initialisation of the drawing is done v 144 The initialisation of the drawing is done via a set of /vis/ commands 145 in the macro vis.mac. This macro is automat 145 in the macro vis.mac. This macro is automatically read from 146 the main function when the example is used 146 the main function when the example is used in interactive running mode. 147 147 148 By default, vis.mac opens an OpenGL viewer 148 By default, vis.mac opens an OpenGL viewer (/vis/open OGL). 149 The user can change the initial viewer by c 149 The user can change the initial viewer by commenting out this line 150 and instead uncommenting one of the other / 150 and instead uncommenting one of the other /vis/open statements, such as 151 HepRepFile or DAWNFILE (which produce files 151 HepRepFile or DAWNFILE (which produce files that can be viewed with the 152 HepRApp and DAWN viewers, respectively). N 152 HepRApp and DAWN viewers, respectively). Note that one can always 153 open new viewers at any time from the comma 153 open new viewers at any time from the command line. For example, if 154 you already have a view in, say, an OpenGL 154 you already have a view in, say, an OpenGL window with a name 155 "viewer-0", then 155 "viewer-0", then 156 /vis/open DAWNFILE 156 /vis/open DAWNFILE 157 then to get the same view 157 then to get the same view 158 /vis/viewer/copyView viewer-0 158 /vis/viewer/copyView viewer-0 159 or to get the same view *plus* scene-modifi 159 or to get the same view *plus* scene-modifications 160 /vis/viewer/set/all viewer-0 160 /vis/viewer/set/all viewer-0 161 then to see the result 161 then to see the result 162 /vis/viewer/flush 162 /vis/viewer/flush 163 163 164 The DAWNFILE, HepRepFile drivers are always 164 The DAWNFILE, HepRepFile drivers are always available 165 (since they require no external libraries), 165 (since they require no external libraries), but the OGL driver requires 166 that the Geant4 libraries have been built w 166 that the Geant4 libraries have been built with the OpenGL option. 167 167 168 Since 11.1, the TSG visualization driver ca << 169 file output in png, jpeg, gl2ps formats wit << 170 It can be controlled via UI commands provid << 171 demonstrated in the tsg_offscreen.mac macro << 172 << 173 For more information on visualization, incl 168 For more information on visualization, including information on how to 174 install and run DAWN, OpenGL and HepRApp, s 169 install and run DAWN, OpenGL and HepRApp, see the visualization tutorials, 175 for example, 170 for example, 176 http://geant4.slac.stanford.edu/Presentatio 171 http://geant4.slac.stanford.edu/Presentations/vis/G4[VIS]Tutorial/G4[VIS]Tutorial.html 177 (where [VIS] can be replaced by DAWN, OpenG 172 (where [VIS] can be replaced by DAWN, OpenGL and HepRApp) 178 173 179 The tracks are automatically drawn at the e 174 The tracks are automatically drawn at the end of each event, accumulated 180 for all events and erased at the beginning 175 for all events and erased at the beginning of the next run. 181 176 182 B- USER INTERFACES 177 B- USER INTERFACES 183 << 178 184 The user command interface is set via the G 179 The user command interface is set via the G4UIExecutive class 185 in the main() function in exampleB2a.cc << 180 in the main() function in exampleB2a.cc 186 << 181 The selection of the user command interface is then done automatically 187 The selection of the user command interface << 182 according to the Geant4 configuration or it can be done explicitly via 188 according to the Geant4 configuration or it << 183 the third argument of the G4UIExecutive constructor (see exampleB4a.cc). 189 the third argument of the G4UIExecutive con << 184 190 << 191 The gui.mac macros are provided in examples << 192 is automatically executed if Geant4 is buil << 193 It is also possible to customise the icons << 194 demonstrated in the icons.mac macro in exam << 195 << 196 C- HOW TO RUN 185 C- HOW TO RUN 197 << 186 198 - Execute exampleB2a in the 'interactive m 187 - Execute exampleB2a in the 'interactive mode' with visualization 199 % exampleB2a 188 % exampleB2a 200 and type in the commands from run1.mac l << 189 and type in the commands from run1.mac line by line: 201 Idle> /tracking/verbose 1 << 190 Idle> /tracking/verbose 1 202 Idle> /run/beamOn 1 191 Idle> /run/beamOn 1 203 Idle> ... 192 Idle> ... 204 Idle> exit 193 Idle> exit 205 or 194 or 206 Idle> /control/execute run1.mac or ru << 195 Idle> /control/execute run1.mac or run2.mac 207 .... 196 .... 208 Idle> exit 197 Idle> exit 209 198 210 - Execute exampleB2a in the 'batch' mode f << 199 - Execute exampleB2a in the 'batch' mode from macro files 211 (without visualization) 200 (without visualization) 212 % exampleB2a run2.mac 201 % exampleB2a run2.mac 213 % exampleB2a exampleB2.in > exampleB2. 202 % exampleB2a exampleB2.in > exampleB2.out 214 << 203