Loading [MathJax]/extensions/tex2jax.js
Iguana 0.0.0
Implementation Guardian of Analysis Algorithms
All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Modules Pages
iguana_ex_python_01_action_functions.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3"""!
4@begin_doc_example{python}
5@file iguana_ex_python_01_action_functions.py
6@brief Python version of `iguana_ex_cpp_01_action_functions.cc` (for more details, see this `.cc` file)
7@end_doc_example
8@doxygen_off
9"""
10
11import pyiguana
12import sys
13
14# include the header files that you need
15pyiguana.include(
16 'hipo4/reader.h',
17 'iguana/algorithms/clas12/EventBuilderFilter/Algorithm.h',
18 'iguana/algorithms/clas12/MomentumCorrection/Algorithm.h',
19 )
20# then import the bound namespaces (must be after including the headers)
21from cppyy.gbl import hipo, iguana
22# from here the syntax is analogous to the C++ example
23
24inFile = sys.argv[1] if len(sys.argv)>1 else 'data.hipo'
25numEvents = int(sys.argv[2]) if len(sys.argv)>2 else 3
26
27reader = hipo.reader(inFile)
28banks = reader.getBanks(["REC::Particle", "RUN::config"]);
29
30b_particle = hipo.getBanklistIndex(banks, "REC::Particle")
31b_config = hipo.getBanklistIndex(banks, "RUN::config")
32
33algo_eventbuilder_filter = iguana.clas12.EventBuilderFilter()
34algo_momentum_correction = iguana.clas12.MomentumCorrection()
35
36algo_eventbuilder_filter.SetOption('log', 'debug')
37algo_momentum_correction.SetOption('log', 'debug')
38algo_eventbuilder_filter.SetOption('pids', [11, 211, -211])
39
40algo_eventbuilder_filter.Start()
41algo_momentum_correction.Start()
42
43iEvent = 0
44while(reader.next(banks) and (numEvents==0 or iEvent < numEvents)):
45 iEvent += 1
46
47 particleBank = banks[b_particle]
48 configBank = banks[b_config]
49 particleBank.show()
50
51 for row in particleBank.getRowList():
52
53 pid = particleBank.getInt('pid', row)
54 if(algo_eventbuilder_filter.Filter(pid)):
55
56 sector = 1 # FIXME: get the sector number. The algorithm `clas12::SectorFinder` can do this, however
57 # it requires reading full `hipo::bank` objects, whereas this example is meant to demonstrate
58 # `iguana` usage operating _only_ on bank row elements
59
60 p_corrected = algo_momentum_correction.Transform(
61 particleBank.getFloat("px", row),
62 particleBank.getFloat("py", row),
63 particleBank.getFloat("pz", row),
64 sector,
65 pid,
66 configBank.getFloat("torus", 0)
67 )
68
69 print(f'Accepted PID {pid}:')
70 print(f' p_old = ({particleBank.getFloat("px", row)}, {particleBank.getFloat("py", row)}, {particleBank.getFloat("pz", row)})')
71 print(f' p_new = ({p_corrected.px}, {p_corrected.py}, {p_corrected.pz})')
72
73algo_eventbuilder_filter.Stop()
74algo_momentum_correction.Stop()
75
76"""!@doxygen_on"""
Algorithm: Filter the REC::Particle (or similar) bank by PID from the Event Builder
Definition Algorithm.h:18
Algorithm: Momentum Corrections
Definition Algorithm.h:17