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