Geant4 Cross Reference |
1 1 2 ========================================== 2 ========================================================= 3 Geant4 - an Object-Oriented Toolkit for Si 3 Geant4 - an Object-Oriented Toolkit for Simulation in HEP 4 ========================================== 4 ========================================================= 5 5 6 Extended Example saxs 6 Extended Example saxs 7 -------------------- 7 -------------------- 8 8 9 The example saxs implements the typical setu 9 The example saxs implements the typical setup of a Small Angle X-ray 10 Scattering (SAXS) experiment. It is meant to 10 Scattering (SAXS) experiment. It is meant to illustrate the 11 usage of molecular interference (MI) of Rayl 11 usage of molecular interference (MI) of Rayleigh (coherent) scattering 12 of photons inside the matter, which is imple 12 of photons inside the matter, which is implemented in the 13 G4PenelopeRayleighModelMI model. 13 G4PenelopeRayleighModelMI model. 14 14 15 1- GEOMETRY 15 1- GEOMETRY 16 16 17 The setup consists of a phantom/sample unde 17 The setup consists of a phantom/sample under investigation, slits 18 to collimate the photon beam and a shielded 18 to collimate the photon beam and a shielded detector to collect 19 the photons scattered by the phantom (see S 19 the photons scattered by the phantom (see SAXSDetectorConstruction). 20 20 21 The geometry is scalable through the intera 21 The geometry is scalable through the interactive commands defined 22 in the SAXSDetectorConstructionMessenger cl 22 in the SAXSDetectorConstructionMessenger class. All the significant 23 quantities, such as the setup (scattering) 23 quantities, such as the setup (scattering) rotation angle, the position 24 and size of all the volumes, as well as the 24 and size of all the volumes, as well as the phantom material can be 25 set via macro commands. 25 set via macro commands. 26 26 27 Two macro files come with this example: sax 27 Two macro files come with this example: saxs.in and saxs_slits.in. 28 28 29 In the saxs.in macro, the phantom is a cyli 29 In the saxs.in macro, the phantom is a cylinder with a diameter and 30 a height of 10 mm made of a mixture of 80% 30 a height of 10 mm made of a mixture of 80% fat and 20% water. 31 In general, if the argument of /det/setPhan 31 In general, if the argument of /det/setPhantomMaterial command is 2, 32 as in this case, the material is a biologic 32 as in this case, the material is a biological tissue ("MedMat") 33 defined as a mixture of fat, water, collage 33 defined as a mixture of fat, water, collagen and hydroxyapatite. 34 The weight fraction of the mixture componen 34 The weight fraction of the mixture components can be set through commands 35 /det/setComp0, /det/setComp1, /det/setComp2 35 /det/setComp0, /det/setComp1, /det/setComp2, /det/setComp3, respectively. 36 The tissue form factor (including MI) is au 36 The tissue form factor (including MI) is automatically calculated as a 37 weighed sum of the form factors of the basi 37 weighed sum of the form factors of the basis components. 38 In this case, no slits are foreseen and the 38 In this case, no slits are foreseen and the sensitive detector 39 positioned 400 mm downstream of the phantom 39 positioned 400 mm downstream of the phantom collects all the photons 40 transmitted and scattered by the phantom, w 40 transmitted and scattered by the phantom, which is irradiated 41 by a pencil beam with an energy of 20 keV. 41 by a pencil beam with an energy of 20 keV. 42 42 43 In the saxs_slits.in macro, the phantom is 43 In the saxs_slits.in macro, the phantom is again a cylinder with a 44 diameter and a height of 10 mm. The phantom 44 diameter and a height of 10 mm. The phantom is made of a custom 45 material ("CustomMat") whose density and co 45 material ("CustomMat") whose density and composition is set through 46 /det/setCustomMatDensity and /det/setCustom 46 /det/setCustomMatDensity and /det/setCustomMatHmassfract, 47 /det/setCustomMatNmassfract, /det/setCustom 47 /det/setCustomMatNmassfract, /det/setCustomMatOmassfract commands, 48 respectively. In general, a custom material 48 respectively. In general, a custom material can be defined by 49 specifying the mass fraction of H, C, N, O, 49 specifying the mass fraction of H, C, N, O, Na, P, S, Cl, K, and Ca via 50 commands analogous to those mentioned above 50 commands analogous to those mentioned above. In this case, the material 51 composition corresponds to that of ammonium 51 composition corresponds to that of ammonium nitrate (NH4NO3). 52 For a custom material, the user can provide 52 For a custom material, the user can provide the path of the file with 53 the material form factor (with MI) through 53 the material form factor (with MI) through the /det/SetCustomMatFF 54 command. As an example, the file myFF.dat c 54 command. As an example, the file myFF.dat contains the form factor of 55 NH4NO3 measured by Harding in 1999. 55 NH4NO3 measured by Harding in 1999. 56 In this case the slits upstream and downstr 56 In this case the slits upstream and downstream the phantom 57 are present. This setup is suitable for bot 57 are present. This setup is suitable for both monochromatic and 58 polychromatic beams. To speed-up the simula 58 polychromatic beams. To speed-up the simulation, a monochromatic 59 photon beam was chosen, but a polychromatic 59 photon beam was chosen, but a polychromatic beam can be easily defined. 60 60 61 2- PHYSICS 61 2- PHYSICS 62 62 63 In this example, only electromagnetic proce 63 In this example, only electromagnetic processes and decays are considered. 64 They are defined in a custom physics list t 64 They are defined in a custom physics list that allows the user to 65 choose among various EM PhysicsList constru 65 choose among various EM PhysicsList constructors. In particular, 66 by choosing G4EmPenelopePhysicsMI and setti 66 by choosing G4EmPenelopePhysicsMI and setting fUseMIFlag as true, 67 it is possible to enable the molecular inte 67 it is possible to enable the molecular interference effects. This 68 is the default configuration. 68 is the default configuration. 69 69 70 3- ACTION INITALIZATION 70 3- ACTION INITALIZATION 71 71 72 SAXSActionInitialization class instantiates 72 SAXSActionInitialization class instantiates and registers to 73 Geant4 kernel all user action classes. Whil 73 Geant4 kernel all user action classes. While in sequential mode 74 the action classes are instatiated just onc 74 the action classes are instatiated just once, by invoking the 75 method: SAXSActionInitialization::Build(), 75 method: SAXSActionInitialization::Build(), 76 in multi-threading mode the same method is 76 in multi-threading mode the same method is invoked for each thread 77 worker and so all user action classes are d 77 worker and so all user action classes are defined thread-local. 78 78 79 A run action class is instantiated both thr 79 A run action class is instantiated both thread-local and global. 80 That's why its instance is created also in 80 That's why its instance is created also in the method 81 SAXSActionInitialization::BuildForMaster(), 81 SAXSActionInitialization::BuildForMaster(), which is 82 invoked only in multi-threading mode. 82 invoked only in multi-threading mode. 83 83 84 4- PRIMARY GENERATOR 84 4- PRIMARY GENERATOR 85 85 86 The primary generator action class employs 86 The primary generator action class employs the G4GeneralParticleSource (GPS) 87 generator. The primary beam has to be defin 87 generator. The primary beam has to be defined via the G4 built-in 88 commands of the G4GeneralParticleSource in 88 commands of the G4GeneralParticleSource in a input macro file. 89 In particular, a photon beam directed towar 89 In particular, a photon beam directed toward the phantom must be defined 90 to test the MI effects. The X-ray beam can 90 to test the MI effects. The X-ray beam can be monochromatic or 91 polychromatic, parallel or divergent. 91 polychromatic, parallel or divergent. 92 92 93 5- EVENT AND DETECTOR RESPONSE 93 5- EVENT AND DETECTOR RESPONSE 94 94 95 An event consists of the generation of a si 95 An event consists of the generation of a single particle which is 96 transported through the phantom and then to 96 transported through the phantom and then to the sensitive detector. 97 97 98 The interactions of the photons inside the 98 The interactions of the photons inside the phantom, and in particular, 99 the scattering events, are scored in a dedi 99 the scattering events, are scored in a dedicated ntuple through the 100 SAXSSteppingAction class. 100 SAXSSteppingAction class. 101 101 102 The hits of the particles on the sensitive 102 The hits of the particles on the sensitive detector positioned 103 downstream of the phantom (SAXSSensitiveDet 103 downstream of the phantom (SAXSSensitiveDetectorHit) are recorded 104 in a dedicated ntuple through the SAXSSensi 104 in a dedicated ntuple through the SAXSSensitiveDetector class. 105 105 106 6- ANALYSIS: 106 6- ANALYSIS: 107 107 108 The analysis tools are used to accumulate s 108 The analysis tools are used to accumulate statistics. 109 ntuple are created in SAXSRunAction::SAXSRu 109 ntuple are created in SAXSRunAction::SAXSRunAction() 110 constructor for the following quantities: 110 constructor for the following quantities: 111 111 112 Ntuple1 (part) - Particles impinging on the 112 Ntuple1 (part) - Particles impinging on the Sensitive Detector (SD): 113 - energy of the particles 113 - energy of the particles 114 - position of the hits 114 - position of the hits 115 - momentum of the particles 115 - momentum of the particles 116 - time of the hits 116 - time of the hits 117 - type of impinging particles 117 - type of impinging particles 118 - ID number of the impinging particles 118 - ID number of the impinging particles 119 - number of scattering events a primary had 119 - number of scattering events a primary had before hitting the SD 120 - event number of the hits 120 - event number of the hits 121 121 122 Ntuple2 (scatt) - Interactions of photons in 122 Ntuple2 (scatt) - Interactions of photons inside the phantom: 123 - ID of the process occurred 123 - ID of the process occurred 124 (0-> transportation, 1->Rayleigh, 2->Com 124 (0-> transportation, 1->Rayleigh, 2->Compton, 3->Photoelectic) 125 - initial energy of the particles 125 - initial energy of the particles 126 - scattering angle 126 - scattering angle 127 127 128 The ntuples are saved in the output file in << 128 The ntuples are saved in the output file in a format >> 129 selected in SAXSAnalysis.hh. 129 130 130 When running in multi-threading mode, the n 131 When running in multi-threading mode, the ntuples accumulated 131 on threads are automatically merged in a si 132 on threads are automatically merged in a single output file. 132 133 133 The default output format is root. Two root 134 The default output format is root. Two root scripts come with 134 this example to analyze the output file: sc 135 this example to analyze the output file: scattAnalysis.C and 135 ADXRD.C. The first can be used to analyze t 136 ADXRD.C. The first can be used to analyze the scatt ntuple, while 136 the second can be used for part ntuple. 137 the second can be used for part ntuple. 137 138 138 7- HOW TO RUN 139 7- HOW TO RUN 139 140 140 - Execute saxs in the 'interactive mode' w 141 - Execute saxs in the 'interactive mode' with visualization: 141 % ./saxs 142 % ./saxs 142 and type in the commands line by line: 143 and type in the commands line by line: 143 Idle> /control/verbose 2 144 Idle> /control/verbose 2 144 Idle> /tracking/verbose 1 145 Idle> /tracking/verbose 1 145 Idle> ... 146 Idle> ... 146 Idle> /run/beamOn 10 147 Idle> /run/beamOn 10 147 Idle> ... 148 Idle> ... 148 Idle> exit 149 Idle> exit 149 or it is possible to run a macro file (t 150 or it is possible to run a macro file (test.in is a simple macro where the 150 primary beam is defined through the usua 151 primary beam is defined through the usual GPS commands): 151 Idle> /control/execute test.in 152 Idle> /control/execute test.in 152 Idle> /run/beamOn 10 153 Idle> /run/beamOn 10 153 .... 154 .... 154 Idle> exit 155 Idle> exit 155 156 156 - Execute saxs in the 'batch' mode from ma 157 - Execute saxs in the 'batch' mode from macro files 157 (without visualization) 158 (without visualization) 158 % ./saxs saxs.in [Ncores] 159 % ./saxs saxs.in [Ncores] 159 % ./saxs saxs_slits.in [Ncores] 160 % ./saxs saxs_slits.in [Ncores] 160 Ncores (optional argument) is the number 161 Ncores (optional argument) is the number of threads the user wants to use in 161 MT mode. 162 MT mode. 162 163 163 164 164 The following paragraphs are common to all ba 165 The following paragraphs are common to all basic examples 165 166 166 A- VISUALISATION 167 A- VISUALISATION 167 168 168 The visualization manager is set via the G4 169 The visualization manager is set via the G4VisExecutive class 169 in the main() function in saxs.cc. 170 in the main() function in saxs.cc. 170 The initialisation of the drawing is done v 171 The initialisation of the drawing is done via a set of /vis/ commands 171 in the macro vis.mac. This macro is automat 172 in the macro vis.mac. This macro is automatically read from 172 the main function when the example is used 173 the main function when the example is used in interactive running mode. 173 174 174 By default, vis.mac opens an OpenGL viewer 175 By default, vis.mac opens an OpenGL viewer (/vis/open OGL). 175 The user can change the initial viewer by c 176 The user can change the initial viewer by commenting out this line 176 and instead uncommenting one of the other / 177 and instead uncommenting one of the other /vis/open statements, such as 177 HepRepFile or DAWNFILE (which produce files 178 HepRepFile or DAWNFILE (which produce files that can be viewed with the 178 HepRApp and DAWN viewers, respectively). N 179 HepRApp and DAWN viewers, respectively). Note that one can always 179 open new viewers at any time from the comma 180 open new viewers at any time from the command line. For example, if 180 you already have a view in, say, an OpenGL 181 you already have a view in, say, an OpenGL window with a name 181 "viewer-0", then 182 "viewer-0", then 182 /vis/open DAWNFILE 183 /vis/open DAWNFILE 183 then to get the same view 184 then to get the same view 184 /vis/viewer/copyView viewer-0 185 /vis/viewer/copyView viewer-0 185 or to get the same view *plus* scene-modifi 186 or to get the same view *plus* scene-modifications 186 /vis/viewer/set/all viewer-0 187 /vis/viewer/set/all viewer-0 187 then to see the result 188 then to see the result 188 /vis/viewer/flush 189 /vis/viewer/flush 189 190 190 The DAWNFILE, HepRepFile drivers are always 191 The DAWNFILE, HepRepFile drivers are always available 191 (since they require no external libraries), 192 (since they require no external libraries), but the OGL driver requires 192 that the Geant4 libraries have been built w 193 that the Geant4 libraries have been built with the OpenGL option. 193 194 194 vis.mac has additional commands that demons 195 vis.mac has additional commands that demonstrate additional functionality 195 of the vis system, such as displaying text, 196 of the vis system, such as displaying text, axes, scales, date, logo and 196 shows how to change viewpoint and style. 197 shows how to change viewpoint and style. 197 To see even more commands use help or ls or 198 To see even more commands use help or ls or browse the available UI commands 198 in the Application Developers Guide. 199 in the Application Developers Guide. 199 200 200 For more information on visualization, incl 201 For more information on visualization, including information on how to 201 install and run DAWN, OpenGL and HepRApp, s 202 install and run DAWN, OpenGL and HepRApp, see the visualization tutorials, 202 for example, 203 for example, 203 http://geant4.slac.stanford.edu/Presentatio 204 http://geant4.slac.stanford.edu/Presentations/vis/G4[VIS]Tutorial/G4[VIS]Tutorial.html 204 (where [VIS] can be replaced by DAWN, OpenG 205 (where [VIS] can be replaced by DAWN, OpenGL and HepRApp) 205 206 206 The tracks are automatically drawn at the e 207 The tracks are automatically drawn at the end of each event, accumulated 207 for all events and erased at the beginning 208 for all events and erased at the beginning of the next run. 208 209 209 B- USER INTERFACES 210 B- USER INTERFACES 210 211 211 The user command interface is set via the G 212 The user command interface is set via the G4UIExecutive class 212 in the main() function in saxs.cc 213 in the main() function in saxs.cc 213 The selection of the user command interface 214 The selection of the user command interface is then done automatically 214 according to the Geant4 configuration or it 215 according to the Geant4 configuration or it can be done explicitly via 215 the third argument of the G4UIExecutive con 216 the third argument of the G4UIExecutive constructor (see exampleB4a.cc). 216 217 217 218