source: trunk/examples/advanced/Tiara/source/py_modules/tiaraApplication.py@ 1158

Last change on this file since 1158 was 807, checked in by garnier, 17 years ago

update

File size: 9.0 KB
Line 
1# $Id: tiaraApplication.py,v 1.7 2006/06/26 10:13:14 ahoward Exp $
2# -------------------------------------------------------------------
3# GEANT4 tag $Name: $
4# -------------------------------------------------------------------
5#
6import string
7import CLHEP
8import G4Kernel
9import Tiara
10
11import tiaraSpecifications
12import tallyData
13
14
15
16class TiaraApplet(object):
17 tiaraSim = None
18 def __init__(self, tiaraSpecs, tSim = None, usePI = True):
19 if usePI:
20 import myPI
21 self.tree = myPI.tf.create()
22 self.hf = myPI.af.createHistogramFactory (self.tree)
23 print self.hf
24 print "hf"
25 hf_ptr = str(self.hf._theObject)
26 print hf_ptr
27 print "hf_ptr before split"
28 hf_ptr = string.split(str(self.hf._theObject))[-1]
29 print hf_ptr
30 print "hf_ptr after split"
31 hf_ptr2 = hf_ptr.split('x')[1]
32 for i in range(len(hf_ptr2),8) :
33 hf_ptr2 = '0'+hf_ptr2
34
35 self.hf.this='_' + hf_ptr2 + '_p_AIDA__IHistogramFactory'
36 self.hf.thisown = 1
37 print self.hf.this
38 print "hf.this after split"
39 else:
40 self.tree = None
41 self.hf = None
42
43 if (not TiaraApplet.tiaraSim):
44 if not tSim:
45 print "Error: TiaraApplet: argument is empty, and no tiaraSim exists!"
46 else:
47 TiaraApplet.tiaraSim = tSim
48 self.tiaraSpecs = tiaraSpecs
49 self.tiaraHall = Tiara.TiaraGeometry(self.tiaraSpecs.\
50 materials)
51 self.cellScorerStore = Tiara.TiaraCellScorerStore()
52 self.sampler = G4Kernel.G4MassGeometrySampler("neutron")
53 self.eventAction = None
54 self.scorer = None
55 self.primGen = None
56 self.scSrc = None
57 self.physicsList = None
58 self.nameExt = ""
59 self.scoreDets = []
60 self.scoreDetectorCreator = None
61 self.noComponents = 0
62 self.createdDPS = 0
63 self.tiaraSim.SetGeometry(self.tiaraHall)
64
65 def specifyPhysicsList(self, pl, particleCut):
66 self.particleCut = particleCut
67 self.physicsList = pl
68
69 def setScoreDetectorCreator(self, creator):
70 self.scoreDetectorCreator=creator
71
72 def visMode(self):
73 if self.eventAction:
74 print "TiaraApplet.visMode(): event action exists already"
75 else:
76 self.eventAction = Tiara.TiaraVisEventAction()
77# now later self.tiaraSim.AddVisRunAction()
78 self.tiaraSim.AddTiaraEventAction(self.eventAction)
79 return
80
81 def timedMode(self, time, randomNumFileName = ""):
82 if self.eventAction:
83 print "TiaraApplet.timedMode(): event action exists already"
84 else:
85 self.eventAction = Tiara.TiaraTimedEventAction(time)
86 if randomNumFileName:
87 self.eventAction.SetRnadomNumFilename(randomNumFileName)
88 self.tiaraSim.AddTiaraEventAction(self.eventAction)
89 return
90
91
92 def buildColimator(self):
93 posColi = \
94 CLHEP.Hep3Vector(0,0, self.tiaraSpecs.
95 dimensions.targetPosZ +
96 self.tiaraSpecs.
97 dimensions.distTargetExperiment +
98 self.tiaraSpecs.\
99 experiment.colWidth/2)
100
101 logCol = self.tiaraHall.BuildCollimator(self.tiaraSpecs.\
102 experiment.colWidth,
103 "iron",
104 "air")
105 self.tiaraHall.PlaceExpComponent(posColi,
106 logCol,
107 "colimator")
108 return
109
110 def buildShield(self):
111 log = self.tiaraHall.BuildShield(self.tiaraSpecs.\
112 experiment.shieldWidth,
113 self.tiaraSpecs.\
114 experiment.shieldMaterial)
115 posShield = CLHEP.Hep3Vector(0,0, self.tiaraSpecs.
116 dimensions.targetPosZ +
117 self.tiaraSpecs.
118 dimensions.
119 distTargetExperiment +
120 self.tiaraSpecs.experiment.
121 colWidth +
122 self.tiaraSpecs.experiment.\
123 shieldWidth/2)
124 self.tiaraHall.PlaceExpComponent(posShield, log, "shield")
125 return
126
127 def buildGeometry(self):
128 self.tiaraHall.BuildGeometry(self.tiaraSpecs.dimensions)
129 if self.noComponents != 1:
130 self.tiaraHall.CreateComponents()
131 if self.tiaraSpecs.experiment.colWidth > 0:
132 self.buildColimator()
133 self.buildShield()
134
135 def createCellScorers(self):
136 self.cellScorer = []
137 tally = Tiara.TiaraTally()
138 tally.setBinEdges(tiaraSpecifications.\
139 tallyBinEdges[self.tiaraSpecs.\
140 experiment.energy])
141 for det in self.scoreDets:
142 det.scorer = None
143 if self.hf:
144 det.scorer = \
145 Tiara.\
146 TiaraCellScorer(self.hf,
147 det.name,
148 self.tiaraSpecs.
149 experiment.binEdgesScinti,
150 self.tiaraSpecs.
151 experiment.binEdgesBonner,
152 tally)
153 else:
154 det.scorer = \
155 Tiara.\
156 TiaraCellScorer(det.name,
157 tally)
158 self.cellScorer.append(det.scorer)
159
160
161 def buildDetectors(self):
162 tally = Tiara.TiaraTally()
163 tally.setBinEdges(tiaraSpecifications.\
164 tallyBinEdges[self.tiaraSpecs.
165 experiment.energy])
166
167 physSrcDet = self.tiaraHall.AddSourceDetector()
168 self.scSrc = None
169 if self.hf:
170 self.scSrc = Tiara.\
171 TiaraCellScorer(self.hf,
172 "source_detector",
173 self.tiaraSpecs.
174 experiment.binEdgesScinti,
175 self.tiaraSpecs.
176 experiment.binEdgesBonner,
177 tally)
178
179 else:
180 self.scSrc = Tiara.\
181 TiaraCellScorer("source_detector",
182 tally)
183
184
185 self.scoreDets = self.scoreDetectorCreator.\
186 createScoreDetectors(self.tiaraHall)
187
188 self.createCellScorers()
189
190 self.cellScorerStore.AddTiaraCellScorer(self.scSrc,
191 G4Kernel.G4GeometryCell(physSrcDet,
192 0))
193
194 for det in self.scoreDets:
195 self.cellScorerStore.AddTiaraCellScorer(det.scorer,
196 G4Kernel.\
197 G4GeometryCell(det.
198 phys,
199 0))
200
201 self.scorer = G4Kernel.G4CellStoreScorer(self.cellScorerStore.
202 GetG4VCellScorerStore())
203
204 self.eventAction.SetScorerStore(self.cellScorerStore)
205
206 return
207
208 def setPhysics(self):
209 self.tiaraSim.SetPhysicsList(self.physicsList)
210 return
211
212 def visAdd(self):
213 self.tiaraSim.AddVisRunAction()
214 return
215
216 def setPrimaryGenerator(self, primGen):
217 self.primGen = primGen
218 self.tiaraSim.SetPrimaryGenerator(self.primGen)
219 return
220
221 def fillShelve(self, shelveDB):
222 t = self.primGen.GetTally()
223 shelveDB["generatorTally"] = tallyData.createTallyDat(t)
224 t = self.scSrc.GetTally()
225 shelveDB["sourceDetectorTally"] = tallyData.createTallyDat(t)
226 for det in self.scoreDets:
227 t = det.scorer.GetTally()
228 shelveDB[det.name + "Tally"] = tallyData.createTallyDat(t)
229 shelveDB["runTime"] = self.eventAction.GetTotalProcessedTime()
230
231 def config(self):
232
233 self.buildDetectors()
234 self.tiaraSim.initialize()
235
236 if len(self.particleCut) > 0:
237 for p in self.particleCut:
238 self.tiaraSim.AddParticleCut(p, self.particleCut[p]);
239
240 self.sampler.PrepareScoring(self.scorer)
241 self.sampler.Configure()
242
243
Note: See TracBrowser for help on using the repository browser.