Geant4 Cross Reference |
1 1 2 ========================================= 2 ========================================================= 3 Geant4 - an Object-Oriented Toolkit for S 3 Geant4 - an Object-Oriented Toolkit for Simulation in HEP 4 ========================================= 4 ========================================================= 5 5 6 6 7 7 8 field04 Example 8 field04 Example 9 --------------- 9 --------------- 10 10 11 This example shows how to define/use OVER << 11 This example shows how to define/use OVERLAPPING field elements 12 in Geant4. Fields might be either magneti 12 in Geant4. Fields might be either magnetic, electric or both. 13 13 14 Credit goes to Tom Roberts and Muons Inc. 14 Credit goes to Tom Roberts and Muons Inc. since much of the code 15 and ideas were taken at liberty from the << 15 and ideas were taken at liberty from the (GNU GPL) source of 16 G4BEAMLINE release 1.12. 16 G4BEAMLINE release 1.12. 17 17 18 http://g4beamline.muonsinc.com 18 http://g4beamline.muonsinc.com 19 19 20 ************** 20 ************** 21 *Classes Used* 21 *Classes Used* 22 ************** 22 ************** 23 23 24 1 - main() 24 1 - main() 25 25 26 See field04.cc. 26 See field04.cc. 27 << 27 28 The example can be run with the follow 28 The example can be run with the following optional arguments: 29 29 30 % field04 [-m macro ] [-p physicsList] << 30 % field04 [-m macro ] [-p physicsList] [-r randomSeed] [-s preinit|idle] 31 31 32 If a macro is provided with the option 32 If a macro is provided with the option "-m", the program runs in a batch mode, 33 otherwise the program open the interac 33 otherwise the program open the interactive session after executing the 34 default initialization macro init_vis. 34 default initialization macro init_vis.mac. The option "-s preinit" can be used 35 to start the program without initializ 35 to start the program without initialization in PreInit phase. 36 36 37 For example: 37 For example: 38 to assign the F04PhysicsList: << 38 to assign the F04PhysicsList: 39 % field04 -p QGSP_BERT 39 % field04 -p QGSP_BERT 40 40 41 an initial random number seed with: 41 an initial random number seed with: 42 % field04 field04.in -r 12345 42 % field04 field04.in -r 12345 43 43 44 to start with a macro file and an init 44 to start with a macro file and an initial seed: 45 % field04 -m field04.in -r 12345 45 % field04 -m field04.in -r 12345 46 46 47 47 48 2- GEOMETRY DEFINITION 48 2- GEOMETRY DEFINITION 49 49 50 The geometry consists of two solenoida 50 The geometry consists of two solenoidal magnets: a "CaptureMgnt" 51 followed by a (blue-colored "TransferM 51 followed by a (blue-colored "TransferMgnt". By definition, the 52 axis and center of the "CaptureMgnt" c 52 axis and center of the "CaptureMgnt" coincide with the "World". The 53 position of the "TransferMgnt" relativ 53 position of the "TransferMgnt" relative to the downstream end of the 54 "CaptureMgnt", as well as its axis ang 54 "CaptureMgnt", as well as its axis angle, both may vary. A cylindrical 55 "Target" is positioned inside the "Cap 55 "Target" is positioned inside the "CaptureMgnt". Its axis can vary 56 from 0 to 180 deg, and hence also the 56 from 0 to 180 deg, and hence also the direction of the incoming 57 proton beam wrt the "CaptureMgnt"'s ax 57 proton beam wrt the "CaptureMgnt"'s axis. A "Degrader" is located 58 inside the "TransferMgnt", its default 58 inside the "TransferMgnt", its default position being at the 59 upstream end of the "TransferMgnt". Fi 59 upstream end of the "TransferMgnt". Finally, also a "TestPlane" is 60 located inside the "TransferMgnt", by 60 located inside the "TransferMgnt", by default at its downstream end. 61 61 62 62 63 The "World" consists of a solid cylind 63 The "World" consists of a solid cylinder made of a given material. 64 (It is the responsibility of the use 64 (It is the responsibility of the user to make the world 65 large enough to contain the rest of 65 large enough to contain the rest of the geometry!) 66 66 67 Three parameters define the world : 67 Three parameters define the world : 68 - the material of the world, 68 - the material of the world, 69 - the world radius, 69 - the world radius, 70 - the world length. 70 - the world length. 71 71 72 Example (default values): 72 Example (default values): 73 /field04/SetWorldMat G4_AIR 73 /field04/SetWorldMat G4_AIR 74 /field04/SetWorldR 5.0 m 74 /field04/SetWorldR 5.0 m 75 /field04/SetWorldZ 50.0 m 75 /field04/SetWorldZ 50.0 m 76 76 77 77 78 The "Target" is a solid cylinder made 78 The "Target" is a solid cylinder made of a given material. 79 79 80 Five parameters define the target: 80 Five parameters define the target: 81 - the material of the target, 81 - the material of the target, 82 - the target radius, 82 - the target radius, 83 - the target thickness, 83 - the target thickness, 84 - the target position inside the "Capt 84 - the target position inside the "CaptureMgnt", 85 - the target axis angle relative to th 85 - the target axis angle relative to that of the "CaptureMgnt". 86 86 87 Example (default values): 87 Example (default values): 88 /field04/SetTgtMat G4_W 88 /field04/SetTgtMat G4_W 89 /field04/SetTgtRad 0.4 cm 89 /field04/SetTgtRad 0.4 cm 90 /field04/SetTgtThick 16.0 cm 90 /field04/SetTgtThick 16.0 cm 91 /field04/SetTgtPos 0.0 cm 91 /field04/SetTgtPos 0.0 cm 92 /field04/SetTgtAng 170 92 /field04/SetTgtAng 170 93 93 94 94 95 The "Degrader" is a solid cylinder ma 95 The "Degrader" is a solid cylinder made of a given material. 96 96 97 Four parameters define the degrader: 97 Four parameters define the degrader: 98 - the material of the degrader, 98 - the material of the degrader, 99 - the degrader radius, 99 - the degrader radius, 100 - the degrader thickness, 100 - the degrader thickness, 101 - the degrader position relative to th 101 - the degrader position relative to the "TransferMgnt" center. 102 102 103 Example (default values): 103 Example (default values): 104 /field04/SetDgrMat G4_Pb 104 /field04/SetDgrMat G4_Pb 105 /field04/SetDgrRad 30.0 cm 105 /field04/SetDgrRad 30.0 cm 106 /field04/SetDgrThick 0.1 cm 106 /field04/SetDgrThick 0.1 cm 107 #/field04/SetDgrPos -7.4 m 107 #/field04/SetDgrPos -7.4 m 108 108 109 109 110 The "CaptureMgnt" is a solenoid (vacuu 110 The "CaptureMgnt" is a solenoid (vacuum cylinder). It is either 111 a two-sided or a one-sided magnetic bo 111 a two-sided or a one-sided magnetic bottle with the B field 112 varying linearly from the center value 112 varying linearly from the center value B1 to the edge value B2. 113 The one-sided F04FocusSolenoid has the 113 The one-sided F04FocusSolenoid has the open end at +z and focuses 114 on the z < 0 side. 114 on the z < 0 side. 115 115 116 Four parameters define the "CaptureMgn 116 Four parameters define the "CaptureMgnt": 117 - the magnet radius, 117 - the magnet radius, 118 - the magnet length, 118 - the magnet length, 119 - the weaker magnetic field at the cen 119 - the weaker magnetic field at the center B1 120 - the stronger magnetic field at the e 120 - the stronger magnetic field at the edge B2 121 121 122 Example (default values): 122 Example (default values): 123 /field04/SetCaptureR 0.6 m << 123 /field04/SetCaptureR 0.6 m 124 /field04/SetCaptureZ 4.0 m 124 /field04/SetCaptureZ 4.0 m 125 /field/SetCaptureB1 2.5 tesla << 125 /field/SetCaptureB1 2.5 tesla 126 /field/SetCaptureB2 5.0 tesla 126 /field/SetCaptureB2 5.0 tesla 127 127 128 128 129 The "TransferMgnt" is a solenoid (vacu << 129 The "TransferMgnt" is a solenoid (vacuum cylinder) with a 130 constant B-field. When the "TransferMg 130 constant B-field. When the "TransferMgnt" follows immediately 131 the "CaptureMgnt", its relative positi 131 the "CaptureMgnt", its relative position is at 0 cm. 132 132 133 Four parameters define the "TransferMg 133 Four parameters define the "TransferMgnt": 134 - the magnet radius, 134 - the magnet radius, 135 - the magnet length, 135 - the magnet length, 136 - the magnet field, 136 - the magnet field, 137 - the magnet relative position 137 - the magnet relative position 138 (its upstream face wrt the downstrea 138 (its upstream face wrt the downstream face of the "CaptureMgnt".) 139 139 140 Example (default values): 140 Example (default values): 141 /field04/SetTransferR 0.3 m 141 /field04/SetTransferR 0.3 m 142 /field04/SetTransferZ 15.0 m 142 /field04/SetTransferZ 15.0 m 143 /field/SetTransferB 5.0 tesla 143 /field/SetTransferB 5.0 tesla 144 /field04/SetTransferP 0.0 m 144 /field04/SetTransferP 0.0 m 145 145 146 The default geometry is constructed in 146 The default geometry is constructed in F04DetectorConstruction class, 147 but all the parameters can be changed << 147 but all the parameters can be changed via the commands defined in 148 the F04DetectorMessenger class. 148 the F04DetectorMessenger class. 149 149 150 150 151 3- MATERIAL DEFINITION 151 3- MATERIAL DEFINITION 152 152 153 Material definitions are done through 153 Material definitions are done through the singleton class F04Materials 154 which keeps a pointer to the G4NistMan 154 which keeps a pointer to the G4NistManager. It has a method 155 GetMaterial by name (G4String) which i 155 GetMaterial by name (G4String) which in turn invokes the 156 G4NistManager::FindOrBuildMaterial, an 156 G4NistManager::FindOrBuildMaterial, and/or G4Material::GetMaterial 157 methods. It has also a method CreateMa 157 methods. It has also a method CreateMaterials which, for materials 158 absent from the NIST data base, shows 158 absent from the NIST data base, shows how to create them using the 159 G4NistManager::ConstructNewMaterial me 159 G4NistManager::ConstructNewMaterial method. 160 160 161 161 162 4- AN EVENT: THE PRIMARY GENERATOR 162 4- AN EVENT: THE PRIMARY GENERATOR 163 163 164 The primary kinematic consists of a si 164 The primary kinematic consists of a single particle which hits the 165 target perpendicular to its upstream f 165 target perpendicular to its upstream face. The type of the particle 166 and its energy are set in the F04Prima 166 and its energy are set in the F04PrimaryGeneratorAction class, and can 167 be changed via the G4 build-in command 167 be changed via the G4 build-in commands of the G4ParticleGun class. 168 In addition, there is a fRndmFlag, whi 168 In addition, there is a fRndmFlag, which once set allows the beam to 169 explore randomly the whole cross secti 169 explore randomly the whole cross section of the target. The default 170 beam consists of 500 MeV protons, star 170 beam consists of 500 MeV protons, starting at the upstream face of 171 the target, directed along dx = dy = 0 171 the target, directed along dx = dy = 0, dz = 1 wrt the target frame. 172 The default direction should NOT be ch 172 The default direction should NOT be changed! The arguments of the 173 x/y/zvertex commands are relative to t 173 x/y/zvertex commands are relative to the target center. 174 174 175 Example: 175 Example: 176 /gun/random on 176 /gun/random on 177 #/gun/xvertex 0 mm 177 #/gun/xvertex 0 mm 178 #/gun/yvertex 0 mm 178 #/gun/yvertex 0 mm 179 #/gun/zvertex -100 mm 179 #/gun/zvertex -100 mm 180 180 181 181 182 5- DETECTOR RESPONSE 182 5- DETECTOR RESPONSE 183 183 184 Information is extracted from the prog 184 Information is extracted from the program via F04SteppingAction 185 at the TestPlane. 185 at the TestPlane. 186 186 187 187 188 6- PHYSICS << 188 6- PHYSICS 189 189 190 The F04PhysicsList extends a selected 190 The F04PhysicsList extends a selected Geant4 physics list. 191 The base physics list name is provided << 191 The base physics list name is provided by its name in the F04PhysicsList 192 constructor. 192 constructor. 193 193 194 In addition to processes defined in th << 194 In addition to processes defined in the base Geant4 physics list, 195 there is added the F04StepMax process << 195 there is added the F04StepMax process and the decay of pions can be assigned 196 via dedicated commands in F04PhysicsLi 196 via dedicated commands in F04PhysicsListMessenger. 197 197 198 The command to define maximum step: 198 The command to define maximum step: 199 /exp/phys/stepMax value unit 199 /exp/phys/stepMax value unit 200 200 201 The decay of pions can be assigned via 201 The decay of pions can be assigned via (pi -> e nu, pi -> mu nu): 202 202 203 /decay/pienu 203 /decay/pienu 204 /decay/pimunu 204 /decay/pimunu 205 205 206 The pienu assignment includes a small 206 The pienu assignment includes a small fraction of radiative decay: 207 e nu gamma (G4PionRadiativeDecayChanne 207 e nu gamma (G4PionRadiativeDecayChannel). 208 208 209 The standard/default muon decay chain 209 The standard/default muon decay chain is modified to be 98.6% 210 G4MuonDecayChannelWithSpin and 1.4% G4 210 G4MuonDecayChannelWithSpin and 1.4% G4MuonRadiativeDecayChannelWithSpin 211 in ConstructParticle(). 211 in ConstructParticle(). 212 212 213 The pion decay process G4PolDecay inhe 213 The pion decay process G4PolDecay inherits from G4Decay and implements 214 the virtual method - empty in the base 214 the virtual method - empty in the base class - DaughterPolarization 215 215 216 The muon decay process is G4DecayWithS 216 The muon decay process is G4DecayWithSpin 217 217 218 Furthermore, the following commands ar 218 Furthermore, the following commands are also available, but 219 may only be used AFTER /run/initialize 219 may only be used AFTER /run/initialize 220 220 221 /process/inactivate msc 221 /process/inactivate msc 222 /process/activate msc 222 /process/activate msc 223 223 224 7- Overlapping Fields 224 7- Overlapping Fields 225 225 226 The F04GlobalField (a singleton) is in << 226 The F04GlobalField (a singleton) is instantiated in 227 F04DetectorConstruction() and assigned << 227 F04DetectorConstruction() and assigned to the global field manager 228 in UpdateField(): 228 in UpdateField(): 229 229 230 fFieldManager = GetGlobalFieldManager( 230 fFieldManager = GetGlobalFieldManager(); 231 fFieldManager->SetDetectorField(this); 231 fFieldManager->SetDetectorField(this); 232 232 233 The F04GlobalField has a std::vector<E 233 The F04GlobalField has a std::vector<ElementField*> FieldList 234 234 235 The field from each individual beamlin 235 The field from each individual beamline element is given by a 236 F04ElementField object. Any number of 236 F04ElementField object. Any number of overlapping F04ElementField 237 objects can be added to the F04GlobalF 237 objects can be added to the F04GlobalField. Any element that 238 represents an element with an EM field 238 represents an element with an EM field must add the appropriate 239 F04ElementField to the global F04Globa 239 F04ElementField to the global F04GlobalField object. 240 240 241 Of course, the F04GlobalField has the 241 Of course, the F04GlobalField has the method GetFieldValue implemented. 242 242 243 Before /run/initialize in the macro fi 243 Before /run/initialize in the macro file or command, the update 244 field command must have been issued if 244 field command must have been issued if any of the other following 245 field commands was employed: 245 field commands was employed: 246 246 247 /field/update 247 /field/update 248 248 249 Other options are: 249 Other options are: 250 250 251 /field/setStepperType 4 251 /field/setStepperType 4 252 /field/setMinStep 10 mm 252 /field/setMinStep 10 mm 253 /field/setDeltaChord 3.0 mm 253 /field/setDeltaChord 3.0 mm 254 /field/setDeltaOneStep 0.01 mm 254 /field/setDeltaOneStep 0.01 mm 255 /field/setDeltaIntersection 0.1 mm 255 /field/setDeltaIntersection 0.1 mm 256 /field/setEpsMin 2.5e-7 mm 256 /field/setEpsMin 2.5e-7 mm 257 /field/setEpsMax 0.05 mm 257 /field/setEpsMax 0.05 mm 258 << 258 259 Each field element has a rectilinear b 259 Each field element has a rectilinear bounding box in global 260 coordinate space which is checked befo 260 coordinate space which is checked before a point is verified to 261 actually be inside the F04ElementField 261 actually be inside the F04ElementField (IsWithin and IsOutside). 262 SetGlobalPoint is called 8 times for t 262 SetGlobalPoint is called 8 times for the corners of the local 263 bounding box, after a local->global co 263 bounding box, after a local->global coordinate transform. 264 264 265 The F04ElementField is the interface c << 265 The F04ElementField is the interface class used by F04GlobalField to 266 compute the field value at a given poi 266 compute the field value at a given point[]. 267 267 268 A beamline element, for example the F0 268 A beamline element, for example the F04SimpleSolenoid, will derive 269 from F04ElementField and implement the 269 from F04ElementField and implement the computation for the element. 270 270 271 simpleSolenoid << 271 simpleSolenoid 272 = new F04SimpleSolenoid(B, l, logicT 272 = new F04SimpleSolenoid(B, l, logicTransferMgnt,TransferMgntCenter); 273 273 274 Besides the magnetic field and the len 274 Besides the magnetic field and the length of the simple solenoid, 275 the constructor needs the knowledge of 275 the constructor needs the knowledge of the G4LogicalVolume for 276 the beamline element and where its cen 276 the beamline element and where its center is located in the 277 'World'. 277 'World'. 278 278 279 The F04ElementField has a G4AffineTran 279 The F04ElementField has a G4AffineTransform "fGlobal2local" which 280 allows the quick computation of coordi 280 allows the quick computation of coordinate transformations. It can 281 only be determined by knowing the elem 281 only be determined by knowing the element's coordinate origin in 282 the global frame and after all of the 282 the global frame and after all of the geometry has been defined. 283 For this reason, the object is prepare 283 For this reason, the object is prepared in two stages, through the 284 constructor providing it with the coor 284 constructor providing it with the coordinate center and a pointer 285 to the G4LogicalVolume. Later the Cons 285 to the G4LogicalVolume. Later the Construct() method is called to 286 calculate the fGlobal2local and the bo 286 calculate the fGlobal2local and the bounding box. This can be done 287 from the F04RunAction::BeginOfRunActio 287 from the F04RunAction::BeginOfRunAction method, for only then are we 288 certain that the geometry has been com 288 certain that the geometry has been completely built: 289 289 290 FieldList* fields = F04GlobalField::Ge 290 FieldList* fields = F04GlobalField::GetObject()->GetFields(); 291 291 292 if (fields) { 292 if (fields) { 293 if (fields->size()>0) { 293 if (fields->size()>0) { 294 FieldList::iterator i; 294 FieldList::iterator i; 295 for (i=fields->begin(); i!=field 295 for (i=fields->begin(); i!=fields->end(); ++i)(*i)->Construct(); 296 } 296 } 297 } 297 } 298 298 299 The F04ElementField constructor will a 299 The F04ElementField constructor will also add the derived object into 300 F04GlobalField. Finally, its AddFieldV 300 F04GlobalField. Finally, its AddFieldValue() will add the field value 301 for this element to field[]. << 301 for this element to field[]. 302 302 303 303 304 8- User Action Classes 304 8- User Action Classes 305 305 306 F04RunActionMessenger: 306 F04RunActionMessenger: 307 307 308 /rndm/save freq - to save 308 /rndm/save freq - to save rndm status in external files 309 0 not saved 309 0 not saved 310 >0 saved on: b 310 >0 saved on: beginOfRun.rndm 311 1 saved on: 311 1 saved on: endOfRun.rndm 312 2 saved on: e 312 2 saved on: endOfEvent.rndm 313 /rndm/read random/run0evt 313 /rndm/read random/run0evt8268.rndm 314 314 315 F04RunAction: << 315 F04RunAction: 316 BeginOfRunAction: Deal wi 316 BeginOfRunAction: Deal with random number storage, 317 initialization etc. Call 317 initialization etc. Call the Construct() method of 318 F04ElementFields in the F 318 F04ElementFields in the FieldList of F04GlobalField object. 319 EndOfRunAction: random nu 319 EndOfRunAction: random number storage/status printing. 320 320 321 F04EventActionMessenger: 321 F04EventActionMessenger: 322 /event/setverbose 322 /event/setverbose 323 323 324 F04EventAction(RunAction* RA): 324 F04EventAction(RunAction* RA): 325 Customized BeginOfEvent p 325 Customized BeginOfEvent printing 326 EndofEvent: 326 EndofEvent: 327 saveEngingStatus and show 327 saveEngingStatus and showEngineStatus according to flag 328 in F04RunAction 328 in F04RunAction 329 329 330 F04TrackingAction: 330 F04TrackingAction: 331 PreUserTrackingAction: In 331 PreUserTrackingAction: Instantiate F04UserTrackInformation 332 and set the application T 332 and set the application TrackStatus. 333 PostUserTrackingAction: R 333 PostUserTrackingAction: Retreive F04UserTrackInformation 334 and decide to save random 334 and decide to save random number status accordingly. 335 335 336 F04SteppingActionMessenger: 336 F04SteppingActionMessenger: 337 337 338 F04SteppingAction: 338 F04SteppingAction: 339 UserSteppingAction: Kill 339 UserSteppingAction: Kill primary if/when outside Target 340 volume. Diagnostic/histog 340 volume. Diagnostic/histogram filling for particles at a 341 TestPlane. Find decay pos 341 TestPlane. Find decay position and when particle 342 FIRST reverses z-momentum 342 FIRST reverses z-momentum component via using a 343 F04UserTrackInformation o 343 F04UserTrackInformation object. 344 344 345 F04StackingAction: 345 F04StackingAction: 346 Track only primaries, pi+ 346 Track only primaries, pi+ or mu+ 347 347 348 F04UserTrackInformation: 348 F04UserTrackInformation: 349 Keep an application F04Tr 349 Keep an application F04TrackStatus for the track: 350 undefined, left, rig 350 undefined, left, right, reverse 351 351 352 F04SteppingVerbose: 352 F04SteppingVerbose: 353 Only print track header an 353 Only print track header and step information for 354 pi+ and mu+. << 354 pi+ and mu+. 355 Note: the information for 355 Note: the information for primary protons is not printed. 356 356 357 F04Trajectory, TrajectoryPoint: 357 F04Trajectory, TrajectoryPoint: 358 Example of application spe 358 Example of application specific implementations 359 359 360 9- HOW TO START ? 360 9- HOW TO START ? 361 361 362 - Execute field04 in 'batch' mode from 362 - Execute field04 in 'batch' mode from macro files e.g. 363 % field04 -m field04.in 363 % field04 -m field04.in 364 364 365 - Execute field04 in 'interactive' mod 365 - Execute field04 in 'interactive' mode with visualization 366 % field04 366 % field04 367 .... 367 .... 368 Idle> type your commands 368 Idle> type your commands 369 .... 369 .... 370 370 371 - Execute field04 in 'interactive' mod 371 - Execute field04 in 'interactive' mode without initialization 372 % field04 -s preinit 372 % field04 -s preinit 373 .... 373 .... 374 Idle> type your commands, then 374 Idle> type your commands, then 375 Idle> /run/initialize 375 Idle> /run/initialize 376 Idle> /control/execute vis.mac 376 Idle> /control/execute vis.mac 377 .... 377 ....