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