4@begin_doc_example{python}
5@file iguana_ex_python_hipopy.py
6@brief Python iguana example using HIPOPy: https://github.com/mfmceneaney/hipopy
13import hipopy.hipopy
as hp
19 'iguana/algorithms/clas12/EventBuilderFilter/Algorithm.h',
20 'iguana/algorithms/clas12/MomentumCorrection/Algorithm.h',
23from cppyy.gbl
import hipo, iguana
26 print(
'Usage: python3',osp.basename(__file__),
' <inFile> <step> <nbatches>')
28inFile = sys.argv[1]
if len(sys.argv)>1
else 'data.hipo'
29step = int(sys.argv[2])
if len(sys.argv)>2
else 3
30nbatches = int(sys.argv[3])
if len(sys.argv)>3
else 1
32banks = [
"REC::Particle",
"RUN::config"]
37algo_eventbuilder_filter.SetOption(
'log',
'debug')
38algo_momentum_correction.SetOption(
'log',
'debug')
39algo_eventbuilder_filter.SetOption(
'pids', [11, 211, -211])
41algo_eventbuilder_filter.Start()
42algo_momentum_correction.Start()
44for iBatch, batch
in enumerate(hp.iterate([inFile],banks=banks,step=step)):
46 for iEvent, pxs
in enumerate(batch[
'REC::Particle_px']):
48 print(key,
':',batch[key][iEvent])
50 for row, _px
in enumerate(pxs):
51 pid = batch[
'REC::Particle_pid'][iEvent][row]
53 if(algo_eventbuilder_filter.Filter(pid)):
58 p_corrected = algo_momentum_correction.Transform(
59 batch[
'REC::Particle_px'][iEvent][row],
60 batch[
'REC::Particle_py'][iEvent][row],
61 batch[
'REC::Particle_pz'][iEvent][row],
64 batch[
'RUN::config_torus'][iEvent][0]
67 print(f
'Accepted PID {pid}:')
68 print(f
' p_old = ({batch["REC::Particle_px"][iEvent][row]}, {batch["REC::Particle_py"][iEvent][row]}, {batch["REC::Particle_pz"][iEvent][row]})')
69 print(f
' p_new = ({p_corrected.px}, {p_corrected.py}, {p_corrected.pz})')
72 if (iBatch>=nbatches):
break
74algo_eventbuilder_filter.Stop()
75algo_momentum_correction.Stop()
Algorithm: Filter the REC::Particle (or similar) bank by PID from the Event Builder
Algorithm: Momentum Corrections