Iguana 0.0.0
Implementation Guardian of Analysis Algorithms
Loading...
Searching...
No Matches
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
30algo_eventbuilder_filter = iguana.clas12.EventBuilderFilter()
31algo_momentum_correction = iguana.clas12.MomentumCorrection()
32
33algo_eventbuilder_filter.SetOption('log', 'debug')
34algo_momentum_correction.SetOption('log', 'debug')
35algo_eventbuilder_filter.SetOption('pids', [11, 211, -211])
36
37algo_eventbuilder_filter.Start()
38algo_momentum_correction.Start()
39
40iEvent = 0
41while(reader.next(banks) and (numEvents==0 or iEvent < numEvents)):
42 iEvent += 1
43
44 particleBank = banks[0]
45 configBank = banks[1]
46 particleBank.show()
47
48 for row in particleBank.getRowList():
49
50 pid = particleBank.getInt('pid', row)
51 if(algo_eventbuilder_filter.Filter(pid)):
52
53 sector = 1 # FIXME: get the sector number. The algorithm `clas12::SectorFinder` can do this, however
54 # it requires reading full `hipo::bank` objects, whereas this example is meant to demonstrate
55 # `iguana` usage operating _only_ on bank row elements
56
57 p_corrected = algo_momentum_correction.Transform(
58 particleBank.getFloat("px", row),
59 particleBank.getFloat("py", row),
60 particleBank.getFloat("pz", row),
61 sector,
62 pid,
63 configBank.getFloat("torus", 0)
64 )
65
66 print(f'Accepted PID {pid}:')
67 print(f' p_old = ({particleBank.getFloat("px", row)}, {particleBank.getFloat("py", row)}, {particleBank.getFloat("pz", row)})')
68 print(f' p_new = ({p_corrected.px}, {p_corrected.py}, {p_corrected.pz})')
69
70algo_eventbuilder_filter.Stop()
71algo_momentum_correction.Stop()
72
73"""!@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