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::rga::MomentumCorrection')
47seq.SetOption(
'clas12::EventBuilderFilter',
'log',
'info')
48seq.SetOption(
'clas12::SectorFinder',
'log',
'info')
49seq.SetOption(
'clas12::rga::MomentumCorrection',
'log',
'info')
53seq.SetOption(
'clas12::EventBuilderFilter',
'pids', [11, 211, -211])
59sector_finder_bank_name = seq.GetCreatedBankName(
"clas12::SectorFinder");
63b_config = hipo.getBanklistIndex(banks,
'RUN::config')
64b_particle = hipo.getBanklistIndex(banks,
'REC::Particle')
65b_sector = hipo.getBanklistIndex(banks, sector_finder_bank_name)
69while(reader.next(banks)
and (numEvents==0
or iEvent < numEvents)):
76 print(f
'===== EVENT {banks[b_config].getInt("event", 0)} =====', flush=
True)
79 print(
'----- BEFORE IGUANA -----', flush=
True)
80 banks[b_particle].show()
86 print(
'----- AFTER IGUANA -----', flush=
True)
87 banks[b_particle].show()
88 banks[b_sector].show()
91 print(
'----- Analysis Particles -----', flush=
True)
92 print(f
' {"row == pindex":<20} {"PDG":<20} {"|p|":<20} {"sector":<20}', flush=
True)
97 for row
in list(banks[b_particle].getRowList()):
99 banks[b_particle].getFloat(
'px', row),
100 banks[b_particle].getFloat(
'py', row),
101 banks[b_particle].getFloat(
'pz', row))
102 pdg = banks[b_particle].getInt(
'pid', row)
103 sector = banks[b_sector].getInt(
'sector', row)
104 print(f
' {row:<20} {pdg:<20} {p:<20.3f} {sector:<20}', flush=
True)
Algorithm: An algorithm that can run a sequence of algorithms