[807] | 1 | #!/usr/bin/env python |
---|
| 2 | # |
---|
| 3 | # $Id: runSim.py,v 1.12 2005/12/15 16:23:11 ahoward Exp $ |
---|
| 4 | # ------------------------------------------------------------------- |
---|
| 5 | # GEANT4 tag $Name: $ |
---|
| 6 | # ------------------------------------------------------------------- |
---|
| 7 | |
---|
| 8 | # importing python libraries |
---|
| 9 | import os |
---|
| 10 | |
---|
| 11 | # importing wrapper modules (see the source/*Wrapper directories) |
---|
| 12 | # created by swig (from the source/*Wrapper/*.i files). |
---|
| 13 | import CLHEP |
---|
| 14 | import G4Kernel |
---|
| 15 | import Tiara |
---|
| 16 | |
---|
| 17 | # importing python modules specific to this example |
---|
| 18 | # (see source/py_modules) |
---|
| 19 | import tiaraApplication |
---|
| 20 | import tiaraGenerators |
---|
| 21 | import tiaraDetectors |
---|
| 22 | import tiaraSpecifications |
---|
| 23 | import myUtils |
---|
| 24 | import variableGeometry |
---|
| 25 | import slabGeometry |
---|
| 26 | import runSequence |
---|
| 27 | |
---|
| 28 | ########################################################################## |
---|
| 29 | # random number initialization |
---|
| 30 | ########################################################################## |
---|
| 31 | Tiara.setRandomSeed(891011); |
---|
| 32 | #Tiara.setRandomStatus("dTest/tiara-2003_5_27_20_5_39_pcgeant2/randomNumberFile_run00003"); |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | ########################################################################## |
---|
| 39 | # experiment and simulation specific data |
---|
| 40 | ########################################################################## |
---|
| 41 | # create a list of particles and give a lower energy cut |
---|
| 42 | particleCut = {"neutron" : 3 * CLHEP.MeV, |
---|
| 43 | "gamma" : 1 * CLHEP.MeV, |
---|
| 44 | "proton" : 1 * CLHEP.MeV, |
---|
| 45 | "deuteron": 1 * CLHEP.MeV, |
---|
| 46 | "triton" : 1 * CLHEP.MeV, |
---|
| 47 | "alpha" : 1 * CLHEP.MeV} |
---|
| 48 | |
---|
| 49 | # specify if the source neutrons shoul be form the 43 or 68 MeV protons |
---|
| 50 | beamEnergy = 68 * CLHEP.MeV |
---|
| 51 | # specify the shieldwidth [25, 50, 100, 150, (200 for 68 MeV case only)] |
---|
| 52 | shieldWidth = 100 * CLHEP.cm |
---|
| 53 | |
---|
| 54 | # set the total running time and the time for one run |
---|
| 55 | # followed by a printout |
---|
| 56 | # if the total running time, giving 0 will start a visualization |
---|
| 57 | # and timeForOneRun has no meaning |
---|
| 58 | totalTime = 5 * myUtils.min |
---|
| 59 | timeForOneRun = 2 * myUtils.min |
---|
| 60 | # if running the visualization mode by setting totalTime = 0, |
---|
| 61 | # a Geant4 session will be started. Start the visualization |
---|
| 62 | # by e.g.: |
---|
| 63 | # Idle> control/execute vis.mac |
---|
| 64 | # Idle> /run/beamOn 10 |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | # available physics lists: LHEP_LEAD, LHEP_PRECO_HP |
---|
| 68 | # LHEP_BIC LHEP_BIC_HP LHEP_PRECO LHEP |
---|
| 69 | #3physList = Tiara.LHEP() |
---|
| 70 | ##physList = Tiara.LHEP_PRECO() |
---|
| 71 | ##physList = Tiara.LHEP_PRECO_HP() |
---|
| 72 | physList = Tiara.LHEP_LEAD() |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | # specify the detectors |
---|
| 76 | scoreDetectorCreator = tiaraDetectors.ThreeZylindricDetectors() |
---|
| 77 | #scoreDetectorCreator = tiaraDetectors.DetectorSlab() |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | comment = "" |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | ########################################################################## |
---|
| 86 | # Create a Specification object of the configuaration data |
---|
| 87 | ########################################################################## |
---|
| 88 | |
---|
| 89 | # this should be fine for most settings |
---|
| 90 | experiment = tiaraSpecifications.Experiment(beamEnergy, |
---|
| 91 | particleCut["neutron"], |
---|
| 92 | particleCut, |
---|
| 93 | shieldWidth, |
---|
| 94 | "concrete") |
---|
| 95 | |
---|
| 96 | tiaraSpecs = tiaraSpecifications.Specifications(Tiara.TiaraDimensions(), |
---|
| 97 | experiment, |
---|
| 98 | Tiara.TiaraMaterials()) |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | ########################################################################## |
---|
| 104 | # definition of the importance geometry importance values and a scorer |
---|
| 105 | ########################################################################## |
---|
| 106 | # create a parallel geometry. |
---|
| 107 | impGeo = variableGeometry.VariableImpSlabGeometry(tiaraSpecs) |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | # introduce "importance cells" into the shielding region |
---|
| 111 | # In this case the width of all the shields in the shielding region |
---|
| 112 | # are equal and the importance staring from one doubles |
---|
| 113 | # from cell to cell in the beam direction. |
---|
| 114 | impGeo.addCellImportance(width=20.0 * CLHEP.cm, faktor=1) |
---|
| 115 | for i in range(4): |
---|
| 116 | # to run unbiased set: faktor=1 in the next line |
---|
| 117 | impGeo.addCellImportance(width=20.0 * CLHEP.cm, faktor=2) |
---|
| 118 | |
---|
| 119 | impGeo.construct() |
---|
| 120 | |
---|
| 121 | # Make sure the widths given in the above way add up to the |
---|
| 122 | # shield widths e.g. 25, 50, ... cm. |
---|
| 123 | # The importance geometries take care to give the importance value 1 |
---|
| 124 | # to the volume before the shield and to assign the same importance |
---|
| 125 | # as the last cell in the shield region to the volume behind the shield. |
---|
| 126 | |
---|
| 127 | # an alternative |
---|
| 128 | #impGeo = slabGeometry.SlabedImportanceGeometry(tiaraSpecs, |
---|
| 129 | # 10.0 * CLHEP.cm, |
---|
| 130 | # 1.5) |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | impScorer = G4Kernel.G4Scorer() |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | ########################################################################## |
---|
| 138 | # Creation of a TiaraApplet to define the run mode, physics list, |
---|
| 139 | # detector type and the primary generator |
---|
| 140 | ########################################################################## |
---|
| 141 | |
---|
| 142 | # this and the remaining part should be fine for most settings |
---|
| 143 | tApp = tiaraApplication.TiaraApplet(tiaraSpecs, |
---|
| 144 | Tiara.TiaraSim_GetTiaraSim()) |
---|
| 145 | |
---|
| 146 | if totalTime == 0: |
---|
| 147 | tApp.visMode() |
---|
| 148 | else: |
---|
| 149 | tApp.timedMode(timeForOneRun) |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | tApp.specifyPhysicsList(physList, particleCut) |
---|
| 153 | |
---|
| 154 | # detectors |
---|
| 155 | tApp.setScoreDetectorCreator(scoreDetectorCreator) |
---|
| 156 | tApp.buildGeometry() |
---|
| 157 | tiara_dir = os.environ["TIARA_BASE"] |
---|
| 158 | |
---|
| 159 | tApp.setPhysics() |
---|
| 160 | |
---|
| 161 | primGenBuilder = tiaraGenerators.\ |
---|
| 162 | TiaraDPSEnergyGenerator(tiaraSpecs, |
---|
| 163 | tiara_dir + |
---|
| 164 | "/data/expDataConverted/dpsSource.xml") |
---|
| 165 | #primGenBuilder = tiaraGenerators.TiaraPrimaryGenerator(tiaraSpecs) |
---|
| 166 | #primGenBuilder = tiaraGenerators.FixedEnergyPrimaryGenerator(tiaraSpecs) |
---|
| 167 | |
---|
| 168 | tApp.setPrimaryGenerator(primGenBuilder.primGen) |
---|
| 169 | |
---|
| 170 | tApp.noComponents = 0 |
---|
| 171 | tApp.config() |
---|
| 172 | |
---|
| 173 | ## The following lines should be probably moved here after release Geant4-7.0 |
---|
| 174 | ##physList = Tiara.LHEP() |
---|
| 175 | ##physList = Tiara.LHEP_PRECO() |
---|
| 176 | ##physList = Tiara.LHEP_PRECO_HP() |
---|
| 177 | ##physList = Tiara.LHEP_LEAD() |
---|
| 178 | ##tApp.specifyPhysicsList(physList, particleCut) |
---|
| 179 | ##tApp.setPrimaryGenerator(primGenBuilder.primGen) |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | |
---|
| 183 | ########################################################################## |
---|
| 184 | # creating of the sampler |
---|
| 185 | ########################################################################## |
---|
| 186 | parallelSampler = myUtils.createParallelSampler(impGeo, |
---|
| 187 | impScorer) |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | ########################################################################## |
---|
| 192 | # create a run config object, a run sequence and run the simulation |
---|
| 193 | ########################################################################## |
---|
| 194 | if totalTime > 0: |
---|
| 195 | rc = runSequence.RunConfig() |
---|
| 196 | |
---|
| 197 | rc.basePath = "simData" |
---|
| 198 | rc.tApp = tApp |
---|
| 199 | rc.tiaraSpecs = tiaraSpecs |
---|
| 200 | rc.impGeo = impGeo |
---|
| 201 | rc.impScorer = impScorer |
---|
| 202 | rc.totalTime = totalTime |
---|
| 203 | rc.comment = comment |
---|
| 204 | |
---|
| 205 | rs = runSequence.RunSequence(rc) |
---|
| 206 | rs.runNevents(100) |
---|
| 207 | rs.runLoop() |
---|
| 208 | else: |
---|
| 209 | tApp.tiaraSim.startSession() |
---|
| 210 | |
---|
| 211 | |
---|
| 212 | ########################################################################## |
---|
| 213 | ########################################################################## |
---|