Loading [MathJax]/extensions/tex2jax.js
Iguana 0.9.0
Implementation Guardian of Analysis Algorithms
iguana_ex_cpp_00_run_functions.cc
Go to the documentation of this file.
1
15
16#include <hipo4/reader.h>
17#include <iguana/algorithms/AlgorithmSequence.h>
18
20int main(int argc, char** argv)
21{
22
23 // parse arguments
24 char const* inFileName = argc > 1 ? argv[1] : "data.hipo";
25 int const numEvents = argc > 2 ? std::stoi(argv[2]) : 3;
26
27 // read input file
28 hipo::reader reader(inFileName,{0});
29
30 // set list of banks to be read
31 hipo::banklist banks = reader.getBanks({"RUN::config",
32 "REC::Particle",
33 "REC::Calorimeter",
34 "REC::Track",
35 "REC::Scintillator"});
36
37 // iguana algorithm sequence
38 // NOTE: the order that they are added to the sequence here will be the same order in which they will be run
40 seq.Add("clas12::EventBuilderFilter"); // filter by Event Builder PID (a filter algorithm)
41 seq.Add("clas12::SectorFinder"); // get the sector for each particle (a creator algorithm)
42 seq.Add("clas12::MomentumCorrection"); // momentum corrections (a transformer algorithm)
43 // seq.PrintSequence();
44
45 // set log levels
46 // NOTE: this can also be done in a config file
47 seq.SetOption("clas12::EventBuilderFilter", "log", "info");
48 seq.SetOption("clas12::SectorFinder", "log", "info");
49 seq.SetOption("clas12::MomentumCorrection", "log", "info");
50
51 // set algorithm options
52 // NOTE: this can also be done in a config file, but setting options here OVERRIDES config file settings
53 seq.SetOption<std::vector<int>>("clas12::EventBuilderFilter", "pids", {11, 211, -211});
54
55 // start the algorithms
56 seq.Start(banks);
57
58 // get bank index, for each bank we want to use after Iguana algorithms run
59 // NOTE: new banks from creator algorithms are initialized by `Start`
60 auto b_config = hipo::getBanklistIndex(banks, "RUN::config");
61 auto b_particle = hipo::getBanklistIndex(banks, "REC::Particle");
62 auto b_sector = hipo::getBanklistIndex(banks, "REC::Particle::Sector"); // new created bank
63
64 // run the algorithm sequence on each event
65 int iEvent = 0;
66 while(reader.next(banks) && (numEvents == 0 || iEvent++ < numEvents)) {
67
68 // references to this event's banks
69 auto& bank_config = banks.at(b_config);
70 auto& bank_particle = banks.at(b_particle);
71 auto& bank_sector = banks.at(b_sector);
72
73 // print the event number
74 fmt::println("===== EVENT {} =====", bank_config.getInt("event", 0));
75
76 // print the particle bank before Iguana algorithms
77 fmt::println("----- BEFORE IGUANA -----");
78 bank_particle.show(); // the original particle bank
79
80 // run the sequence of Iguana algorithms
81 seq.Run(banks);
82
83 // print the banks after Iguana algorithms
84 fmt::println("----- AFTER IGUANA -----");
85 bank_particle.show(); // the filtered particle bank, with corrected momenta
86 bank_sector.show(); // the new sector bank
87
88 // print a table; first the header
89 fmt::print("----- Analysis Particles -----\n");
90 fmt::print(" {:<20} {:<20} {:<20} {:<20}\n", "row == pindex", "PDG", "|p|", "sector");
91 // then print a row for each particle
92 // - use the `hipo::bank::getRowList()` method to loop over the bank rows that PASS the filter
93 // - if you'd rather loop over ALL bank rows, iterate from `i=0` up to `i < hipo::bank::getRows()` instead
94 for(auto const& row : bank_particle.getRowList()) {
95 auto p = std::hypot(
96 bank_particle.getFloat("px", row),
97 bank_particle.getFloat("py", row),
98 bank_particle.getFloat("pz", row));
99 auto pdg = bank_particle.getInt("pid", row);
100 auto sector = bank_sector.getInt("sector", row);
101 fmt::print(" {:<20} {:<20} {:<20.3f} {:<20}\n", row, pdg, p, sector);
102 }
103 fmt::print("\n");
104
105 }
106
107 // stop algorithms
108 seq.Stop();
109 return 0;
110}
An algorithm that can run a sequence of algorithms.
void SetOption(std::string const &algo_name, std::string const &key, const OPTION_TYPE val)
void Stop() override
Finalize this algorithm after all events are processed.
void Run(hipo::banklist &banks) const override
Run this algorithm for an event.
void Add(std::string const &class_name, std::string const &instance_name="")
void Start(hipo::banklist &banks) override
Initialize this algorithm before any events are processed, with the intent to process banks
int main(int argc, char **argv)
main function