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
14import hipopy.hipopy
as hp
20 'iguana/algorithms/clas12/EventBuilderFilter/Algorithm.h',
21 'iguana/algorithms/clas12/SectorFinder/Algorithm.h',
22 'iguana/algorithms/clas12/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
48algo_eventbuilder_filter.SetOption(
'log',
'info')
49algo_sector_finder.SetOption(
'log',
'info')
50algo_momentum_correction.SetOption(
'log',
'info')
53algo_eventbuilder_filter.SetOption(
'pids', [11, 211, -211])
56algo_eventbuilder_filter.Start()
57algo_sector_finder.Start()
58algo_momentum_correction.Start()
61for iBatch, batch
in enumerate(hp.iterate([inFile],banks=banks,step=step)):
63 for iEvent, pxs
in enumerate(batch[
'REC::Particle_px']):
66 print(f
'evnum = {batch["RUN::config_event"][iEvent][0]}')
72 for row, _px
in enumerate(pxs):
73 pid = batch[
'REC::Particle_pid'][iEvent][row]
76 if(algo_eventbuilder_filter.Filter(pid)):
80 sector = algo_sector_finder.GetStandardSector(
81 batch[
'REC::Track_sector'][iEvent],
82 batch[
'REC::Track_pindex'][iEvent],
83 batch[
'REC::Calorimeter_sector'][iEvent],
84 batch[
'REC::Calorimeter_pindex'][iEvent],
85 batch[
'REC::Scintillator_sector'][iEvent],
86 batch[
'REC::Scintillator_pindex'][iEvent],
90 p_corrected = algo_momentum_correction.Transform(
91 batch[
'REC::Particle_px'][iEvent][row],
92 batch[
'REC::Particle_py'][iEvent][row],
93 batch[
'REC::Particle_pz'][iEvent][row],
96 batch[
'RUN::config_torus'][iEvent][0]
100 print(f
'Analysis Particle PDG = {pid}')
101 print(f
' sector = {sector}')
102 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})')
103 print(f
' p_new = ({p_corrected.px:11.5f}, {p_corrected.py:11.5f}, {p_corrected.pz:11.5f})')
106 if (iBatch+1>=nbatches):
break
109algo_eventbuilder_filter.Stop()
110algo_sector_finder.Stop()
111algo_momentum_correction.Stop()
Algorithm: Filter the REC::Particle (or similar) bank by PID from the Event Builder
Algorithm: Momentum Corrections
Algorithm: Find the sector for all rows in REC::Particle