4@begin_doc_example{python}
5@file iguana_ex_python_00_run_functions.py
6@brief Python version of `iguana_ex_cpp_00_run_functions.cc` (for more details, see this `.cc` file)
7@note You may need to run this example using `stdbuf -o0` (preceding your command) if the output appears to be jumbled
17pyiguana.include(
'hipo4/reader.h',
'iguana/algorithms/AlgorithmSequence.h')
19from cppyy.gbl
import hipo, iguana
23inFile = sys.argv[1]
if len(sys.argv)>1
else 'data.hipo'
24numEvents = int(sys.argv[2])
if len(sys.argv)>2
else 3
27reader = hipo.reader(inFile)
30banks = reader.getBanks([
40seq.Add(
'clas12::EventBuilderFilter')
41seq.Add(
'clas12::SectorFinder')
42seq.Add(
'clas12::MomentumCorrection')
47seq.SetOption(
'clas12::EventBuilderFilter',
'log',
'info')
48seq.SetOption(
'clas12::SectorFinder',
'log',
'info')
49seq.SetOption(
'clas12::MomentumCorrection',
'log',
'info')
53seq.SetOption(
'clas12::EventBuilderFilter',
'pids', [11, 211, -211])
60b_config = hipo.getBanklistIndex(banks,
'RUN::config')
61b_particle = hipo.getBanklistIndex(banks,
'REC::Particle')
62b_sector = hipo.getBanklistIndex(banks,
'REC::Particle::Sector')
66while(reader.next(banks)
and (numEvents==0
or iEvent < numEvents)):
73 print(f
'===== EVENT {banks[b_config].getInt("event", 0)} =====', flush=
True)
76 print(
'----- BEFORE IGUANA -----', flush=
True)
77 banks[b_particle].show()
83 print(
'----- AFTER IGUANA -----', flush=
True)
84 banks[b_particle].show()
85 banks[b_sector].show()
88 print(
'----- Analysis Particles -----', flush=
True)
89 print(f
' {"row == pindex":<20} {"PDG":<20} {"|p|":<20} {"sector":<20}', flush=
True)
94 for row
in list(banks[b_particle].getRowList()):
96 banks[b_particle].getFloat(
'px', row),
97 banks[b_particle].getFloat(
'py', row),
98 banks[b_particle].getFloat(
'pz', row))
99 pdg = banks[b_particle].getInt(
'pid', row)
100 sector = banks[b_sector].getInt(
'sector', row)
101 print(f
' {row:<20} {pdg:<20} {p:<20.3f} {sector:<20}', flush=
True)
An algorithm that can run a sequence of algorithms.