Iguana 0.0.0
Implementation Guardian of Analysis Algorithms
Loading...
Searching...
No Matches
iguana_ex_python_00_run_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_00_run_functions.py
6@brief Python version of `iguana_ex_cpp_00_run_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('hipo4/reader.h', 'iguana/algorithms/AlgorithmSequence.h')
16# then import the bound namespaces (must be after including the headers)
17from cppyy.gbl import hipo, iguana
18# from here the syntax is analogous to the C++ example
19
20inFile = sys.argv[1] if len(sys.argv)>1 else 'data.hipo'
21numEvents = int(sys.argv[2]) if len(sys.argv)>2 else 3
22
23reader = hipo.reader(inFile)
24banks = reader.getBanks([
25 "RUN::config",
26 "REC::Particle",
27 "REC::Calorimeter",
28 "REC::Track",
29 "REC::Scintillator"])
30b_particle = hipo.getBanklistIndex(banks, "REC::Particle")
31
32seq = iguana.AlgorithmSequence('pyiguana')
33seq.Add('clas12::EventBuilderFilter')
34seq.Add('clas12::SectorFinder')
35seq.Add('clas12::MomentumCorrection')
36seq.PrintSequence()
37
38seq.SetOption('clas12::EventBuilderFilter', 'log', 'debug')
39seq.SetOption('clas12::MomentumCorrection', 'log', 'debug')
40
41seq.SetOption('clas12::EventBuilderFilter', 'pids', [11, 211, -211])
42
43def prettyPrint(message, bank):
44 print(f'{"="*30} {message} {"="*30}')
45 bank.show()
46
47iEvent = 0
48seq.Start(banks)
49while(reader.next(banks) and (numEvents==0 or iEvent < numEvents)):
50 iEvent += 1
51 prettyPrint("BEFORE", banks[b_particle])
52 seq.Run(banks)
53 prettyPrint("AFTER", banks[b_particle])
54
55seq.Stop()
56
57"""!@doxygen_on"""
An algorithm that can run a sequence of algorithms.
void prettyPrint(std::string header, hipo::bank &bank)
show a bank along with a header