8 from AthenaPython
import PyAthena
9 StatusCode = PyAthena.StatusCode
13 def keep (dec, l, op = 'set'):
20 if isinstance (l, list):
21 for i, x
in enumerate(l):
22 dec.keep (i, x, opflag)
29 """A simple python algorithm to thin data
31 def __init__(self, name = "PyWriteThinnedData", **kw):
34 super(PyWriteThinnedData,self).
__init__(**kw)
37 self.
Decay = kw.get(
'Decay',
"TwoBodyDecay")
39 self.
Filter = kw.get(
'Filter', [
False]*10)
42 self.
msg.
info(
"Initializing %s", self.name )
44 self.
sg = PyAthena.py_svc(
"StoreGateSvc")
48 cppyy.load_library(
"libAthExThinningEventDict")
49 from RootUtils
import PyROOTFixes
51 return StatusCode.Success
54 self.
msg.
debug(
"Executing %s...", self.name )
56 for t
in (
"test1",
"test2",
"test3",):
57 if self.
test(t) != StatusCode.Success:
58 self.
msg.warning(
"Could not perform 'thinning %s'",t )
60 if allGood:
return StatusCode.Success
61 return StatusCode.Failure
64 self.
msg.
info(
"Performing thinning test [%s]...", testName )
67 particlesName =
"%s_%s" % (self.
Particles,testName)
68 particles = self.
sg.
retrieve(
"AthExParticles", particlesName )
70 self.
msg.warning(
"Could not fetch particles at [%s] !!",
72 return StatusCode.Failure
73 self.
msg.
info(
"particles: %i", particles.size() )
76 iparticles = self.
sg.
retrieve(
"AthExIParticles", particlesName )
77 if iparticles
is None:
78 self.
msg.warning(
"Could not fetch iparticles at [%s] !!",
80 return StatusCode.Failure
81 self.
msg.
info(
"iparticles: %i", iparticles.size() )
83 if ( iparticles.size() != particles.size()
or
84 iparticles.at(0).
px() != particles.at(0).
px() ):
85 self.
msg.
error(
"symlinked containers are corrupted: " )
86 self.
msg.
error(
" #iparticles: %i", iparticles.size() )
87 self.
msg.
error(
" # particles: %i", particles.size() )
88 self.
msg.
error(
" ipx[0] = %r", iparticles.at(0).
px() )
89 self.
msg.
error(
" px[0] = %r", particles.at(0).
px() )
90 return StatusCode.Failure
94 "%s_%s" % (self.
Decay, testName) )
96 self.
msg.warning(
"Could not fetch Decay at [%s] !!",
98 return StatusCode.Failure
101 elephantino = self.
sg.
retrieve(
"AthExElephantino",
103 if elephantino
is None:
104 self.
msg.warning(
"Could not fetch Elephantino at [%s] !!",
106 return StatusCode.Failure
108 self.
msg.
info(
"IN particles: %i", particles.size() )
110 self.
msg.
info(
" p1: px= %r", decay.p1().
px() / Units.GeV )
111 self.
msg.
info(
" p2: px= %r", decay.p2().
px() / Units.GeV )
112 self.
msg.
info(
" l1: px= %r", decay.l1().
px() / Units.GeV )
113 self.
msg.
info(
" l2: px= %r", decay.l2().
px() / Units.GeV )
115 self.
msg.
info(
"IN elephantino:" )
116 self.
msg.
info(
" leg1: px= %r", elephantino.leg1().
px() / Units.GeV )
117 self.
msg.
info(
" leg2: px= %r", elephantino.leg2().
px() / Units.GeV )
118 self.
msg.
info(
" leg3: px= %r", elephantino.leg3().
px() / Units.GeV )
119 self.
msg.
info(
" leg4: px= %r", elephantino.leg4().
px() / Units.GeV )
120 self.
msg.
info(
" ear1: px= %r", elephantino.ear1().
px() / Units.GeV )
121 self.
msg.
info(
" ear2: px= %r", elephantino.ear2().
px() / Units.GeV )
124 dec = ROOT.SG.ThinningDecision (particlesName)
125 if testName ==
"test1":
127 self.
msg.warning(
"Could not exercize Thinning !!" )
128 elif testName ==
"test2":
130 self.
msg.warning(
"Could not exercize Thinning !!" )
131 elif testName ==
"test3":
133 self.
msg.warning(
"Could not exercize Thinning !!" )
135 self.
msg.
error(
"Unknown test [%s]", testName )
136 return StatusCode.Failure
138 if not self.
sg.record (dec, particlesName +
'_THINNED_StreamUSR_0'):
139 return StatusCode.Failure
140 ROOT.SetOwnership (dec,
False)
142 self.
msg.
info(
"Decay is now:" )
143 self.
msg.
info(
" p1: px= %r", decay.p1().
px() / Units.GeV )
144 self.
msg.
info(
" p2: px= %r", decay.p2().
px() / Units.GeV )
145 self.
msg.
info(
" l1: px= %r", decay.l1().
px() / Units.GeV )
146 self.
msg.
info(
" l2: px= %r", decay.l2().
px() / Units.GeV )
148 self.
msg.
info(
"Elephantino is now: " )
149 self.
msg.
info(
" leg1: px= %r", elephantino.leg1().
px() / Units.GeV )
150 self.
msg.
info(
" leg2: px= %r", elephantino.leg2().
px() / Units.GeV )
151 self.
msg.
info(
" leg3: px= %r", elephantino.leg3().
px() / Units.GeV )
152 self.
msg.
info(
" leg4: px= %r", elephantino.leg4().
px() / Units.GeV )
153 self.
msg.
info(
" ear1: px= %r", elephantino.ear1().
px() / Units.GeV )
154 self.
msg.
info(
" ear2: px= %r", elephantino.ear2().
px() / Units.GeV )
156 self.
msg.
info(
"[%s] has been performed.", testName )
157 return StatusCode.Success
161 RemovedIdx = ROOT.SG.ThinningDecisionBase.RemovedIdx
162 self.
msg.
info(
"Particles | filter :" )
163 for i
in range(particles.size()):
164 if filter[i]: kr =
"keep"
166 self.
msg.
info(
"%9s | %s", (i+1)*10, kr )
169 filter[len(filter)//2:] = [
True]*(len(filter)//2)
170 self.
msg.
info(
"Filter %r", filter )
172 self.
msg.
info(
"... Processing [pre-thinning] ..." )
175 self.
msg.
info(
"======== Index table =========" )
176 tmp = ROOT.SG.ThinningDecisionBase (dec)
179 os.sys.stdout.flush()
180 for i
in range(particles.size()):
181 newIdx = tmp.index(i)
182 if newIdx == RemovedIdx: newIdx =
"-"
183 self.
msg.
info(
" idx %i -> %s", i, newIdx )
186 filter[:len(filter)//2] = [
True]*(len(filter)//2)
187 self.
msg.
info(
"Filter %r", filter )
189 self.
msg.
info(
"... Processing [thinning] ..." )
190 keep (dec, filter,
'and')
192 self.
msg.
info(
"======== Index table =========" )
193 tmp = ROOT.SG.ThinningDecisionBase (dec)
195 for i
in range(particles.size()):
196 newIdx = tmp.index(i)
197 if newIdx == RemovedIdx: newIdx =
"-"
198 self.
msg.
info(
" idx %i -> %s", i, newIdx )
200 return StatusCode.Success
204 RemovedIdx = ROOT.SG.ThinningDecisionBase.RemovedIdx
205 self.
msg.
info(
"Particles | filter :" )
206 for i
in range(particles.size()):
207 if filter[i]: kr =
"keep"
209 self.
msg.
info(
"%9s | %s", (i+1)*10, kr )
212 filter[len(filter)//2:] = [
False]*(len(filter)//2)
213 self.
msg.
info(
"Filter %s", filter )
215 self.
msg.
info(
"... Processing [pre-thinning] ..." )
218 self.
msg.
info(
"======== Index table =========" )
219 tmp = ROOT.SG.ThinningDecisionBase (dec)
221 for i
in range(particles.size()):
222 newIdx = tmp.index(i)
223 if newIdx == RemovedIdx: newIdx =
"-"
224 self.
msg.
info(
" idx %i -> %s", i, newIdx )
227 filter[:len(filter)//2] = [
False]*(len(filter)//2)
228 self.
msg.
info(
"Filter %s", filter )
230 self.
msg.
info(
"... Processing [thinning] ..." )
231 keep (dec, filter,
'or')
233 self.
msg.
info(
"======== Index table =========" )
234 tmp = ROOT.SG.ThinningDecisionBase (dec)
236 for i
in range(particles.size()):
237 newIdx = tmp.index(i)
238 if newIdx == RemovedIdx: newIdx =
"-"
239 self.
msg.
info(
" idx %i -> %s", i, newIdx )
241 return StatusCode.Success
245 RemovedIdx = ROOT.SG.ThinningDecisionBase.RemovedIdx
246 self.
msg.
info(
"IParticles | filter :" )
247 for i
in range(iparticles.size()):
248 if filter[i]: kr =
"keep"
250 self.
msg.
info(
"%9s | %s", (i+1)*10, kr )
253 filter[len(filter)//2:] = [
True]*(len(filter)//2)
254 self.
msg.
info(
"Filter %r", filter )
256 self.
msg.
info(
"... Processing [pre-thinning] ..." )
259 self.
msg.
info(
"======== Index table =========" )
260 tmp = ROOT.SG.ThinningDecisionBase (dec)
262 for i
in range(iparticles.size()):
263 newIdx = tmp.index(i)
264 if newIdx == RemovedIdx: newIdx =
"-"
265 self.
msg.
info(
" idx %i -> %s", i, newIdx )
268 filter[:len(filter)//2] = [
True]*(len(filter)//2)
269 self.
msg.
info(
"Filter %r", filter )
271 self.
msg.
info(
"... Processing [thinning] ..." )
272 keep (dec, filter,
'and')
274 self.
msg.
info(
"======== Index table =========" )
275 tmp = ROOT.SG.ThinningDecisionBase (dec)
277 for i
in range(iparticles.size()):
278 newIdx = tmp.index(i)
279 if newIdx == RemovedIdx: newIdx =
"-"
280 self.
msg.
info(
" idx %i -> %s", i, newIdx )
282 return StatusCode.Success
285 self.
msg.
info(
"Finalizing %s...", self.name )
286 return StatusCode.Success
292 """A simple python algorithm to read non-thinned data
294 def __init__(self, name = "PyReadNonThinnedData", **kw):
297 super(PyReadNonThinnedData,self).
__init__(**kw)
300 self.
Decay = kw.get(
'Decay',
"TwoBodyDecay")
304 self.
msg.
info(
"Initializing %s", self.name )
306 self.
sg = PyAthena.py_svc(
"StoreGateSvc")
310 cppyy.load_library(
"libAthExThinningEventDict")
311 from RootUtils
import PyROOTFixes
312 return StatusCode.Success
316 _warning = self.
msg.warning
317 _info = self.
msg.info
318 _info(
"Executing %s...", self.name )
319 for test
in (
"test1",
"test2",
"test3"):
321 particles = sg.retrieve(
"AthExParticles", key)
322 if particles
is None:
323 _warning(
"Could not fetch particles at [%s] !!", key)
324 return StatusCode.Failure
326 iparticles = sg.retrieve(
"AthExIParticles", key)
327 if iparticles
is None:
328 _warning(
"Could not fetch iparticles at [%s] !!", key)
329 return StatusCode.Failure
331 key =
"%s_%s" % (self.
Decay, test)
332 decay = sg.retrieve(
"AthExDecay", key)
334 _warning(
"Could not fetch Decay at [%s] !!", key)
335 return StatusCode.Failure
338 elephantino = self.
sg.
retrieve(
"AthExElephantino", key)
339 if elephantino
is None:
340 _warning(
"Could not fetch Elephantino at [%s] !!", key)
341 return StatusCode.Failure
343 _info(
"Test: %s", test)
344 _info(
"IN particles: %i", particles.size() )
345 _info(
"IN iparticles: %i", iparticles.size() )
347 _info(
" p1: px= %r", decay.p1().
px() / Units.GeV )
348 _info(
" p2: px= %r", decay.p2().
px() / Units.GeV )
349 _info(
" l1: px= %r", decay.l1().
px() / Units.GeV )
350 _info(
" l2: px= %r", decay.l2().
px() / Units.GeV )
352 _info(
"IN elephantino:" )
353 _info(
" leg1: px= %r", elephantino.leg1().
px() / Units.GeV )
354 _info(
" leg2: px= %r", elephantino.leg2().
px() / Units.GeV )
355 _info(
" leg3: px= %r", elephantino.leg3().
px() / Units.GeV )
356 _info(
" leg4: px= %r", elephantino.leg4().
px() / Units.GeV )
357 _info(
" ear1: px= %r", elephantino.ear1().
px() / Units.GeV )
358 _info(
" ear2: px= %r", elephantino.ear2().
px() / Units.GeV )
359 return StatusCode.Success
362 self.
msg.
info(
"Finalizing %s...", self.name )
363 return StatusCode.Success
369 """a simple algorithm to read back AthExFatObject"""
373 super (PyReadFatObject, self).__init__ (**kw)
382 _info = self.
msg.info
383 _info(
'==> initialize...')
385 self.
sg = PyAthena.py_svc (
"StoreGateSvc")
387 self.
msg.error (
"could not retrieve the event store !")
388 return StatusCode.Failure
390 _info (
"input particles: [%s]", self.
particles)
391 _info (
"input fatobject: [%s]", self.
fatobject)
393 return StatusCode.Success
396 _info = self.
msg.info
399 self.
msg.error (
"could not retrieve particles at [%s] !",
401 return StatusCode.Failure
402 _info (
"particles' size: %i", particles.size())
406 self.
msg.error (
"could not retrieve fatobject at [%s] !",
408 return StatusCode.Failure
410 raw = fatobject.particle()
411 lnk = fatobject.particleLink()
412 _info (
"fat.raw.px: %s",
413 "slimmed" if not raw
else (raw.px()/Units.GeV))
414 _info (
"fat.lnk.e : %s",
415 "slimmed" if not lnk.isValid()
else (lnk.e() /Units.GeV))
417 return StatusCode.Success
420 self.
msg.
info(
'==> finalize...')
421 return StatusCode.Success