Iguana 0.0.0
Implementation Guardian of Analysis Algorithms
Loading...
Searching...
No Matches
iguana_ex_cpp_01_action_functions.cc
Go to the documentation of this file.
1
15#include <hipo4/reader.h>
16#include <iguana/algorithms/clas12/EventBuilderFilter/Algorithm.h>
17#include <iguana/algorithms/clas12/MomentumCorrection/Algorithm.h>
18
20int main(int argc, char** argv)
21{
22
23 // parse arguments
24 int argi = 1;
25 char const* inFileName = argc > argi ? argv[argi++] : "data.hipo";
26 int const numEvents = argc > argi ? std::stoi(argv[argi++]) : 1;
27
28 // read input file
29 hipo::reader reader(inFileName,{0});
30
31 // set banks
32 hipo::banklist banks = reader.getBanks({"REC::Particle", "RUN::config"});
33 enum banks_enum { b_particle,
34 b_config }; // TODO: users shouldn't have to do this
35
36 // set the concurrency model to single-threaded, since this example is single-threaded;
37 // not doing this will use the thread-safe model, `"memoize"`
39
40 // create the algorithms
41 iguana::clas12::EventBuilderFilter algo_eventbuilder_filter;
42 iguana::clas12::MomentumCorrection algo_momentum_correction;
43
44 // set log levels
45 algo_eventbuilder_filter.SetOption("log", "debug");
46 algo_momentum_correction.SetOption("log", "debug");
47
48 // set algorithm options
49 algo_eventbuilder_filter.SetOption<std::vector<int>>("pids", {11, 211, -211});
50
51 // start the algorithms
52 algo_eventbuilder_filter.Start();
53 algo_momentum_correction.Start();
54
55 // run the algorithm sequence on each event
56 int iEvent = 0;
57 while(reader.next(banks) && (numEvents == 0 || iEvent++ < numEvents)) {
58
59 // show the particle bank
60 auto& particleBank = banks.at(b_particle);
61 auto& configBank = banks.at(b_config);
62 particleBank.show();
63
64 // loop over bank rows
65 for(auto const& row : particleBank.getRowList()) {
66
67 // check the PID with EventBuilderFilter
68 auto pid = particleBank.getInt("pid", row);
69 if(algo_eventbuilder_filter.Filter(pid)) {
70
71 int sector = 1; // FIXME: get the sector number. The algorithm `clas12::SectorFinder` can do this, however
72 // it requires reading full `hipo::bank` objects, whereas this example is meant to demonstrate
73 // `iguana` usage operating _only_ on bank row elements
74
75 // if accepted PID, correct its momentum
76 auto [px, py, pz] = algo_momentum_correction.Transform(
77 particleBank.getFloat("px", row),
78 particleBank.getFloat("py", row),
79 particleBank.getFloat("pz", row),
80 sector,
81 pid,
82 configBank.getFloat("torus", 0));
83
84 // then print the result
85 fmt::print("Accepted PID {}:\n", pid);
86 auto printMomentum = [](auto v1, auto v2)
87 { fmt::print(" {:>20} {:>20}\n", v1, v2); };
88 printMomentum("p_old", "p_new");
89 printMomentum("--------", "--------");
90 printMomentum(particleBank.getFloat("px", row), px);
91 printMomentum(particleBank.getFloat("py", row), py);
92 printMomentum(particleBank.getFloat("pz", row), pz);
93 }
94 }
95 }
96
97 // stop the algorithms
98 algo_eventbuilder_filter.Stop();
99 algo_momentum_correction.Stop();
100 return 0;
101}
OPTION_TYPE SetOption(std::string const &key, const OPTION_TYPE val)
Definition Algorithm.h:79
Algorithm: Filter the REC::Particle (or similar) bank by PID from the Event Builder
Definition Algorithm.h:18
void Stop() override
Finalize this algorithm after all events are processed.
void Start(hipo::banklist &banks) override
Initialize this algorithm before any events are processed, with the intent to process banks
bool Filter(int const pid) const
Action Function: checks if the PDG pid is a part of the list of user-specified PDGs
Algorithm: Momentum Corrections
Definition Algorithm.h:17
void Start(hipo::banklist &banks) override
Initialize this algorithm before any events are processed, with the intent to process banks
void Stop() override
Finalize this algorithm after all events are processed.
Momentum3 Transform(vector_element_t const px, vector_element_t const py, vector_element_t const pz, int const sec, int const pid, float const torus) const
Action Function: Apply the momentum correction
int main(int argc, char **argv)
main function
GlobalParam< std::string > GlobalConcurrencyModel
The concurrency model, for running certain algorithms in a thread-safe way.