4@begin_doc_example{python}
5@file iguana_ex_python_hipopy.py
6@brief Python iguana example using HIPOPy: https://github.com/mfmceneaney/hipopy
7@note You may need to run this example using `stdbuf -o0` (preceding your command) if the output appears to be jumbled
12import hipopy.hipopy
as hp
20 'iguana/algorithms/clas12/EventBuilderFilter/Algorithm.h',
21 'iguana/algorithms/clas12/SectorFinder/Algorithm.h',
22 'iguana/algorithms/clas12/rga/MomentumCorrection/Algorithm.h',
25from cppyy.gbl
import hipo, iguana
28 print(
'Usage: python3',osp.basename(__file__),
' <inFile> <step> <nbatches>')
30inFile = sys.argv[1]
if len(sys.argv)>1
else 'data.hipo'
31step = int(sys.argv[2])
if len(sys.argv)>2
else 3
32nbatches = int(sys.argv[3])
if len(sys.argv)>3
else 1
48config_file =
"examples/config_for_examples.yaml"
49algo_eventbuilder_filter.SetConfigFile(config_file)
50algo_sector_finder.SetConfigFile(config_file)
51algo_momentum_correction.SetConfigFile(config_file)
54algo_eventbuilder_filter.Start()
55algo_sector_finder.Start()
56algo_momentum_correction.Start()
59for iBatch, batch
in enumerate(hp.iterate([inFile],banks=banks,step=step)):
61 for iEvent, pxs
in enumerate(batch[
'REC::Particle_px']):
64 print(f
'evnum = {batch["RUN::config_event"][iEvent][0]}')
70 for row, _px
in enumerate(pxs):
71 pid = batch[
'REC::Particle_pid'][iEvent][row]
74 if(algo_eventbuilder_filter.Filter(pid)):
78 sector = algo_sector_finder.GetStandardSector(
79 batch[
'REC::Track_sector'][iEvent],
80 batch[
'REC::Track_pindex'][iEvent],
81 batch[
'REC::Calorimeter_sector'][iEvent],
82 batch[
'REC::Calorimeter_pindex'][iEvent],
83 batch[
'REC::Scintillator_sector'][iEvent],
84 batch[
'REC::Scintillator_pindex'][iEvent],
88 p_corrected = algo_momentum_correction.Transform(
89 batch[
'REC::Particle_px'][iEvent][row],
90 batch[
'REC::Particle_py'][iEvent][row],
91 batch[
'REC::Particle_pz'][iEvent][row],
94 batch[
'RUN::config_torus'][iEvent][0]
98 print(f
'Analysis Particle PDG = {pid}')
99 print(f
' sector = {sector}')
100 print(f
' p_old = ({batch["REC::Particle_px"][iEvent][row]:11.5f}, {batch["REC::Particle_py"][iEvent][row]:11.5f}, {batch["REC::Particle_pz"][iEvent][row]:11.5f})')
101 print(f
' p_new = ({p_corrected.px:11.5f}, {p_corrected.py:11.5f}, {p_corrected.pz:11.5f})')
104 if (iBatch+1>=nbatches):
break
107algo_eventbuilder_filter.Stop()
108algo_sector_finder.Stop()
109algo_momentum_correction.Stop()
Algorithm: Filter the particle bank (REC::Particle, or similar) bank by PID from the Event Builder
Algorithm: Find the sector for all rows in REC::Particle
Algorithm: Momentum Corrections