Iguana
1.2.1
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
// configure algorithms with a custom YAML file
51
// - in practice, specify the path(s) to your preferred configuration file(s); see documentation
52
// on 'How to Configure Algorithms' for details, and alternative methods for algorithm configuration
53
// - in this example, the file is from the source-code path `./config/examples/`, which was copied to
54
// the installation subdirectory `etc/iguana/`, within the default configuration-file search path
55
seq.
SetConfigFileForEachAlgorithm
(
"examples/config_for_examples.yaml"
);
56
// alternatively: use this configuration for the algorithm that needs it
57
// seq.Get("clas12::EventBuilderFilter")->SetConfigFile("examples/config_for_examples.yaml");
58
59
// start the algorithms
60
seq.
Start
(banks);
61
62
// get bank index, for each bank we want to use after Iguana algorithms run
63
// NOTE: new banks from creator algorithms are initialized by `Start`
64
auto
b_config =
iguana::tools::GetBankIndex
(banks,
"RUN::config"
);
65
auto
b_particle =
iguana::tools::GetBankIndex
(banks,
"REC::Particle"
);
66
auto
b_sector = seq.
GetCreatedBankIndex
(banks,
"clas12::SectorFinder"
);
// newly created bank; string parameter is algorithm name, not bank name
67
68
// run the algorithm sequence on each event
69
int
iEvent = 0;
70
while
(reader.next(banks) && (numEvents == 0 || iEvent++ < numEvents)) {
71
72
// references to this event's banks
73
auto
& bank_config = banks.at(b_config);
74
auto
& bank_particle = banks.at(b_particle);
75
auto
& bank_sector = banks.at(b_sector);
76
77
// print the event number
78
fmt::println(
"===== EVENT {} ====="
, bank_config.getInt(
"event"
, 0));
79
80
// print the particle bank before Iguana algorithms
81
fmt::println(
"----- BEFORE IGUANA -----"
);
82
bank_particle.show();
// the original particle bank
83
84
// run the sequence of Iguana algorithms
85
seq.
Run
(banks);
86
87
// print the banks after Iguana algorithms
88
fmt::println(
"----- AFTER IGUANA -----"
);
89
bank_particle.show();
// the filtered particle bank, with corrected momenta
90
bank_sector.show();
// the new sector bank
91
92
// print a table; first the header
93
fmt::print(
"----- Analysis Particles -----\n"
);
94
fmt::print(
" {:<20} {:<20} {:<20} {:<20}\n"
,
"row == pindex"
,
"PDG"
,
"|p|"
,
"sector"
);
95
// then print a row for each particle
96
// - use the `hipo::bank::getRowList()` method to loop over the bank rows that PASS the filter
97
// - if you'd rather loop over ALL bank rows, iterate from `i=0` up to `i < hipo::bank::getRows()` instead
98
for
(
auto
const
& row : bank_particle.getRowList()) {
99
auto
p = std::hypot(
100
bank_particle.getFloat(
"px"
, row),
101
bank_particle.getFloat(
"py"
, row),
102
bank_particle.getFloat(
"pz"
, row));
103
auto
pdg = bank_particle.getInt(
"pid"
, row);
104
auto
sector = bank_sector.getInt(
"sector"
, row);
105
fmt::print(
" {:<20} {:<20} {:<20.3f} {:<20}\n"
, row, pdg, p, sector);
106
}
107
fmt::print(
"\n"
);
108
}
109
110
// stop algorithms
111
seq.
Stop
();
112
return
0;
113
}
iguana::AlgorithmSequence
Algorithm: An algorithm that can run a sequence of algorithms
Definition
AlgorithmSequence.h:46
iguana::AlgorithmSequence::GetCreatedBankIndex
hipo::banklist::size_type GetCreatedBankIndex(hipo::banklist &banks, std::string const &algo_instance_name) const noexcept(false)
iguana::AlgorithmSequence::Add
void Add(std::string const &algo_class_name, std::string const &algo_instance_name="")
iguana::AlgorithmSequence::SetConfigFileForEachAlgorithm
void SetConfigFileForEachAlgorithm(std::string const &name)
Set a custom configuration file for each algorithm in the sequence.
iguana::Algorithm::Run
virtual bool Run(hipo::banklist &banks) const final
Run Function: Process an event's hipo::banklist
iguana::Algorithm::Stop
virtual void Stop() final
Stop Function: Finalize this algorithm after all events are processed.
iguana::Algorithm::Start
virtual void Start(hipo::banklist &banks) final
Start Function: Initialize this algorithm before any events are processed, with the intent to process...
main
int main(int argc, char **argv)
main function
Definition
iguana_ex_cpp_00_run_functions.cc:25
iguana::tools::GetBankIndex
hipo::banklist::size_type GetBankIndex(hipo::banklist &banks, std::string const &bank_name, unsigned int const &variant=0) noexcept(false)
iguana_v1.2.1
examples
iguana_ex_cpp_00_run_functions.cc
Generated by
1.18.0