Line | Branch | Exec | Source |
---|---|---|---|
1 | /// @begin_doc_example{cpp} | ||
2 | /// @file iguana_ex_cpp_00_run_functions.cc | ||
3 | /// @brief Example using **full HIPO banks** with Iguana algorithms' `Run` functions. This example requires the | ||
4 | /// user to have the C++ `hipo::bank` objects; see other examples if you do not have banks in this format. | ||
5 | /// @par Usage | ||
6 | /// ```bash | ||
7 | /// iguana_ex_cpp_00_run_functions [HIPO_FILE] [NUM_EVENTS] | ||
8 | /// | ||
9 | /// HIPO_FILE the HIPO file to analyze | ||
10 | /// | ||
11 | /// NUM_EVENTS the number of events to analyze; | ||
12 | /// set to zero to analyze all events | ||
13 | /// ``` | ||
14 | /// @end_doc_example | ||
15 | |||
16 | #include <hipo4/reader.h> | ||
17 | #include <iguana/algorithms/AlgorithmSequence.h> | ||
18 | |||
19 | /// main function | ||
20 | 1 | int main(int argc, char** argv) | |
21 | { | ||
22 | |||
23 | // parse arguments | ||
24 |
1/2✓ Branch 0 (2→3) taken 1 times.
✗ Branch 1 (2→12) not taken.
|
1 | char const* inFileName = argc > 1 ? argv[1] : "data.hipo"; |
25 |
1/2✓ Branch 0 (3→4) taken 1 times.
✗ Branch 1 (3→12) not taken.
|
1 | int const numEvents = argc > 2 ? std::stoi(argv[2]) : 3; |
26 | |||
27 | // read input file | ||
28 |
1/2✓ Branch 0 (13→14) taken 1 times.
✗ Branch 1 (13→186) not taken.
|
1 | hipo::reader reader(inFileName,{0}); |
29 | |||
30 | // set list of banks to be read | ||
31 |
1/2✓ Branch 0 (17→18) taken 1 times.
✗ Branch 1 (17→302) not taken.
|
2 | hipo::banklist banks = reader.getBanks({"RUN::config", |
32 | "REC::Particle", | ||
33 | "REC::Calorimeter", | ||
34 | "REC::Track", | ||
35 |
1/2✓ Branch 0 (18→19) taken 1 times.
✗ Branch 1 (18→190) not taken.
|
1 | "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 | ||
39 |
2/4✓ Branch 0 (20→21) taken 1 times.
✗ Branch 1 (20→300) not taken.
✓ Branch 2 (21→22) taken 1 times.
✗ Branch 3 (21→298) not taken.
|
1 | iguana::AlgorithmSequence seq; |
40 |
3/8✓ Branch 0 (22→23) taken 1 times.
✗ Branch 1 (22→198) not taken.
✓ Branch 2 (23→24) taken 1 times.
✗ Branch 3 (23→192) not taken.
✓ Branch 4 (29→30) taken 1 times.
✗ Branch 5 (29→32) not taken.
✗ Branch 6 (198→199) not taken.
✗ Branch 7 (198→201) not taken.
|
2 | seq.Add("clas12::EventBuilderFilter"); // filter by Event Builder PID (a filter algorithm) |
41 |
3/8✓ Branch 0 (35→36) taken 1 times.
✗ Branch 1 (35→210) not taken.
✓ Branch 2 (36→37) taken 1 times.
✗ Branch 3 (36→204) not taken.
✓ Branch 4 (42→43) taken 1 times.
✗ Branch 5 (42→45) not taken.
✗ Branch 6 (210→211) not taken.
✗ Branch 7 (210→213) not taken.
|
2 | seq.Add("clas12::SectorFinder"); // get the sector for each particle (a creator algorithm) |
42 |
3/8✓ Branch 0 (48→49) taken 1 times.
✗ Branch 1 (48→222) not taken.
✓ Branch 2 (49→50) taken 1 times.
✗ Branch 3 (49→216) not taken.
✓ Branch 4 (55→56) taken 1 times.
✗ Branch 5 (55→58) not taken.
✗ Branch 6 (222→223) not taken.
✗ Branch 7 (222→225) not taken.
|
2 | 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 |
3/8✓ Branch 0 (60→61) taken 1 times.
✗ Branch 1 (60→298) not taken.
✓ Branch 2 (61→62) taken 1 times.
✗ Branch 3 (61→234) not taken.
✓ Branch 4 (70→71) taken 1 times.
✗ Branch 5 (70→73) not taken.
✗ Branch 6 (234→235) not taken.
✗ Branch 7 (234→237) not taken.
|
2 | seq.SetOption("clas12::EventBuilderFilter", "log", "info"); |
48 |
3/8✓ Branch 0 (75→76) taken 1 times.
✗ Branch 1 (75→298) not taken.
✓ Branch 2 (76→77) taken 1 times.
✗ Branch 3 (76→246) not taken.
✓ Branch 4 (85→86) taken 1 times.
✗ Branch 5 (85→88) not taken.
✗ Branch 6 (246→247) not taken.
✗ Branch 7 (246→249) not taken.
|
2 | seq.SetOption("clas12::SectorFinder", "log", "info"); |
49 |
3/8✓ Branch 0 (90→91) taken 1 times.
✗ Branch 1 (90→298) not taken.
✓ Branch 2 (91→92) taken 1 times.
✗ Branch 3 (91→258) not taken.
✓ Branch 4 (100→101) taken 1 times.
✗ Branch 5 (100→103) not taken.
✗ Branch 6 (258→259) not taken.
✗ Branch 7 (258→261) not taken.
|
2 | 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 |
6/16✓ Branch 0 (105→106) taken 1 times.
✗ Branch 1 (105→298) not taken.
✓ Branch 2 (106→107) taken 1 times.
✗ Branch 3 (106→276) not taken.
✓ Branch 4 (107→108) taken 1 times.
✗ Branch 5 (107→270) not taken.
✓ Branch 6 (108→109) taken 1 times.
✗ Branch 7 (108→264) not taken.
✓ Branch 8 (114→115) taken 1 times.
✗ Branch 9 (114→117) not taken.
✓ Branch 10 (119→120) taken 1 times.
✗ Branch 11 (119→122) not taken.
✗ Branch 12 (270→271) not taken.
✗ Branch 13 (270→273) not taken.
✗ Branch 14 (276→277) not taken.
✗ Branch 15 (276→279) not taken.
|
3 | seq.SetOption<std::vector<int>>("clas12::EventBuilderFilter", "pids", {11, 211, -211}); |
54 | |||
55 | // start the algorithms | ||
56 |
1/2✓ Branch 0 (122→123) taken 1 times.
✗ Branch 1 (122→298) not taken.
|
1 | 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 |
2/4✓ Branch 0 (123→124) taken 1 times.
✗ Branch 1 (123→298) not taken.
✓ Branch 2 (124→125) taken 1 times.
✗ Branch 3 (124→280) not taken.
|
1 | auto b_config = hipo::getBanklistIndex(banks, "RUN::config"); |
61 |
2/4✓ Branch 0 (130→131) taken 1 times.
✗ Branch 1 (130→298) not taken.
✓ Branch 2 (131→132) taken 1 times.
✗ Branch 3 (131→286) not taken.
|
1 | auto b_particle = hipo::getBanklistIndex(banks, "REC::Particle"); |
62 |
2/4✓ Branch 0 (137→138) taken 1 times.
✗ Branch 1 (137→298) not taken.
✓ Branch 2 (138→139) taken 1 times.
✗ Branch 3 (138→292) not taken.
|
1 | 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 |
5/8✓ Branch 0 (170→171) taken 101 times.
✗ Branch 1 (170→298) not taken.
✓ Branch 2 (171→172) taken 101 times.
✗ Branch 3 (171→175) not taken.
✓ Branch 4 (172→173) taken 101 times.
✗ Branch 5 (172→174) not taken.
✓ Branch 6 (173→174) taken 100 times.
✓ Branch 7 (173→175) taken 1 times.
|
101 | while(reader.next(banks) && (numEvents == 0 || iEvent++ < numEvents)) { |
67 | |||
68 | // references to this event's banks | ||
69 |
1/2✓ Branch 0 (174→145) taken 100 times.
✗ Branch 1 (174→298) not taken.
|
100 | auto& bank_config = banks.at(b_config); |
70 |
1/2✓ Branch 0 (145→146) taken 100 times.
✗ Branch 1 (145→298) not taken.
|
100 | auto& bank_particle = banks.at(b_particle); |
71 |
1/2✓ Branch 0 (146→147) taken 100 times.
✗ Branch 1 (146→298) not taken.
|
100 | auto& bank_sector = banks.at(b_sector); |
72 | |||
73 | // print the event number | ||
74 |
2/4✓ Branch 0 (148→149) taken 100 times.
✗ Branch 1 (148→298) not taken.
✓ Branch 2 (149→150) taken 100 times.
✗ Branch 3 (149→298) not taken.
|
100 | fmt::println("===== EVENT {} =====", bank_config.getInt("event", 0)); |
75 | |||
76 | // print the particle bank before Iguana algorithms | ||
77 |
1/2✓ Branch 0 (149→150) taken 100 times.
✗ Branch 1 (149→298) not taken.
|
100 | fmt::println("----- BEFORE IGUANA -----"); |
78 |
1/2✓ Branch 0 (150→151) taken 100 times.
✗ Branch 1 (150→298) not taken.
|
100 | bank_particle.show(); // the original particle bank |
79 | |||
80 | // run the sequence of Iguana algorithms | ||
81 |
1/2✓ Branch 0 (151→152) taken 100 times.
✗ Branch 1 (151→298) not taken.
|
100 | seq.Run(banks); |
82 | |||
83 | // print the banks after Iguana algorithms | ||
84 |
1/2✓ Branch 0 (152→153) taken 100 times.
✗ Branch 1 (152→298) not taken.
|
100 | fmt::println("----- AFTER IGUANA -----"); |
85 |
1/2✓ Branch 0 (153→154) taken 100 times.
✗ Branch 1 (153→298) not taken.
|
100 | bank_particle.show(); // the filtered particle bank, with corrected momenta |
86 |
1/2✓ Branch 0 (154→155) taken 100 times.
✗ Branch 1 (154→298) not taken.
|
100 | bank_sector.show(); // the new sector bank |
87 | |||
88 | // print a table; first the header | ||
89 |
1/2✓ Branch 0 (156→157) taken 100 times.
✗ Branch 1 (156→298) not taken.
|
100 | fmt::print("----- Analysis Particles -----\n"); |
90 | 100 | 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 |
3/4✓ Branch 0 (157→158) taken 100 times.
✗ Branch 1 (157→298) not taken.
✓ Branch 2 (167→159) taken 193 times.
✓ Branch 3 (167→168) taken 100 times.
|
293 | for(auto const& row : bank_particle.getRowList()) { |
95 | 193 | auto p = std::hypot( | |
96 | bank_particle.getFloat("px", row), | ||
97 | bank_particle.getFloat("py", row), | ||
98 | bank_particle.getFloat("pz", row)); | ||
99 | 193 | auto pdg = bank_particle.getInt("pid", row); | |
100 | 193 | auto sector = bank_sector.getInt("sector", row); | |
101 | 193 | fmt::print(" {:<20} {:<20} {:<20.3f} {:<20}\n", row, pdg, p, sector); | |
102 | } | ||
103 | 100 | fmt::print("\n"); | |
104 | |||
105 | } | ||
106 | |||
107 | // stop algorithms | ||
108 |
1/2✓ Branch 0 (175→176) taken 1 times.
✗ Branch 1 (175→298) not taken.
|
1 | seq.Stop(); |
109 | return 0; | ||
110 | 1 | } | |
111 |