GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 36 / 0 / 36
Functions: 100.0% 1 / 0 / 1
Branches: 48.9% 46 / 0 / 94

examples/iguana_ex_cpp_00_run_functions.cc
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, using `hipo::banklist`
4 ///
5 /// This example requires the user to have the C++ `hipo::banklist` objects, which are lists of `hipo::bank` objects.
6 ///
7 /// - see `iguana_ex_cpp_00_run_functions_with_banks.cc` if you prefer just `hipo::bank` objects, rather than `hipo::banklist`
8 /// - see other examples if you do not have `hipo::bank` objects
9 ///
10 /// @par Usage
11 /// ```bash
12 /// iguana_ex_cpp_00_run_functions [HIPO_FILE] [NUM_EVENTS]
13 ///
14 /// HIPO_FILE the HIPO file to analyze
15 ///
16 /// NUM_EVENTS the number of events to analyze;
17 /// set to zero to analyze all events
18 /// ```
19 /// @end_doc_example
20
21 #include <hipo4/reader.h>
22 #include <iguana/algorithms/AlgorithmSequence.h>
23
24 /// main function
25 1 int main(int argc, char** argv)
26 {
27
28 // parse arguments
29
1/2
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 12 not taken.
1 char const* inFileName = argc > 1 ? argv[1] : "data.hipo";
30
1/2
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 12 not taken.
1 int const numEvents = argc > 2 ? std::stoi(argv[2]) : 3;
31
32 // read input file
33
1/2
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 131 not taken.
1 hipo::reader reader(inFileName, {0});
34
35 // set list of banks to be read
36
1/2
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 201 not taken.
2 hipo::banklist banks = reader.getBanks({"RUN::config",
37 "REC::Particle",
38 "REC::Calorimeter",
39 "REC::Track",
40
1/2
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 135 not taken.
1 "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
2/4
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 199 not taken.
✓ Branch 21 → 22 taken 1 time.
✗ Branch 21 → 197 not taken.
1 iguana::AlgorithmSequence seq;
45
3/8
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 143 not taken.
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 137 not taken.
✓ Branch 29 → 30 taken 1 time.
✗ Branch 29 → 32 not taken.
✗ Branch 143 → 144 not taken.
✗ Branch 143 → 146 not taken.
2 seq.Add("clas12::EventBuilderFilter"); // filter by Event Builder PID (a filter algorithm)
46
3/8
✓ Branch 35 → 36 taken 1 time.
✗ Branch 35 → 155 not taken.
✓ Branch 36 → 37 taken 1 time.
✗ Branch 36 → 149 not taken.
✓ Branch 42 → 43 taken 1 time.
✗ Branch 42 → 45 not taken.
✗ Branch 155 → 156 not taken.
✗ Branch 155 → 158 not taken.
2 seq.Add("clas12::SectorFinder"); // get the sector for each particle (a creator algorithm)
47
3/8
✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 167 not taken.
✓ Branch 49 → 50 taken 1 time.
✗ Branch 49 → 161 not taken.
✓ Branch 55 → 56 taken 1 time.
✗ Branch 55 → 58 not taken.
✗ Branch 167 → 168 not taken.
✗ Branch 167 → 170 not taken.
2 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
2/4
✓ Branch 60 → 61 taken 1 time.
✗ Branch 60 → 197 not taken.
✓ Branch 61 → 62 taken 1 time.
✗ Branch 61 → 173 not taken.
1 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
1/2
✓ Branch 67 → 68 taken 1 time.
✗ Branch 67 → 197 not taken.
1 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
2/4
✓ Branch 68 → 69 taken 1 time.
✗ Branch 68 → 197 not taken.
✓ Branch 69 → 70 taken 1 time.
✗ Branch 69 → 179 not taken.
1 auto b_config = iguana::tools::GetBankIndex(banks, "RUN::config");
65
2/4
✓ Branch 75 → 76 taken 1 time.
✗ Branch 75 → 197 not taken.
✓ Branch 76 → 77 taken 1 time.
✗ Branch 76 → 185 not taken.
1 auto b_particle = iguana::tools::GetBankIndex(banks, "REC::Particle");
66
2/4
✓ Branch 82 → 83 taken 1 time.
✗ Branch 82 → 197 not taken.
✓ Branch 83 → 84 taken 1 time.
✗ Branch 83 → 191 not taken.
1 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
5/8
✓ Branch 115 → 116 taken 101 times.
✗ Branch 115 → 197 not taken.
✓ Branch 116 → 117 taken 101 times.
✗ Branch 116 → 120 not taken.
✓ Branch 117 → 118 taken 101 times.
✗ Branch 117 → 119 not taken.
✓ Branch 118 → 119 taken 100 times.
✓ Branch 118 → 120 taken 1 time.
101 while(reader.next(banks) && (numEvents == 0 || iEvent++ < numEvents)) {
71
72 // references to this event's banks
73
1/2
✓ Branch 119 → 90 taken 100 times.
✗ Branch 119 → 197 not taken.
100 auto& bank_config = banks.at(b_config);
74
1/2
✓ Branch 90 → 91 taken 100 times.
✗ Branch 90 → 197 not taken.
100 auto& bank_particle = banks.at(b_particle);
75
1/2
✓ Branch 91 → 92 taken 100 times.
✗ Branch 91 → 197 not taken.
100 auto& bank_sector = banks.at(b_sector);
76
77 // print the event number
78
2/4
✓ Branch 93 → 94 taken 100 times.
✗ Branch 93 → 197 not taken.
✓ Branch 94 → 95 taken 100 times.
✗ Branch 94 → 197 not taken.
100 fmt::println("===== EVENT {} =====", bank_config.getInt("event", 0));
79
80 // print the particle bank before Iguana algorithms
81
1/2
✓ Branch 94 → 95 taken 100 times.
✗ Branch 94 → 197 not taken.
100 fmt::println("----- BEFORE IGUANA -----");
82
1/2
✓ Branch 95 → 96 taken 100 times.
✗ Branch 95 → 197 not taken.
100 bank_particle.show(); // the original particle bank
83
84 // run the sequence of Iguana algorithms
85
1/2
✓ Branch 96 → 97 taken 100 times.
✗ Branch 96 → 197 not taken.
100 seq.Run(banks);
86
87 // print the banks after Iguana algorithms
88
1/2
✓ Branch 97 → 98 taken 100 times.
✗ Branch 97 → 197 not taken.
100 fmt::println("----- AFTER IGUANA -----");
89
1/2
✓ Branch 98 → 99 taken 100 times.
✗ Branch 98 → 197 not taken.
100 bank_particle.show(); // the filtered particle bank, with corrected momenta
90
1/2
✓ Branch 99 → 100 taken 100 times.
✗ Branch 99 → 197 not taken.
100 bank_sector.show(); // the new sector bank
91
92 // print a table; first the header
93
1/2
✓ Branch 101 → 102 taken 100 times.
✗ Branch 101 → 197 not taken.
100 fmt::print("----- Analysis Particles -----\n");
94 100 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
3/4
✓ Branch 102 → 103 taken 100 times.
✗ Branch 102 → 197 not taken.
✓ Branch 112 → 104 taken 379 times.
✓ Branch 112 → 113 taken 100 times.
479 for(auto const& row : bank_particle.getRowList()) {
99 379 auto p = std::hypot(
100 bank_particle.getFloat("px", row),
101 bank_particle.getFloat("py", row),
102 bank_particle.getFloat("pz", row));
103 379 auto pdg = bank_particle.getInt("pid", row);
104 379 auto sector = bank_sector.getInt("sector", row);
105 379 fmt::print(" {:<20} {:<20} {:<20.3f} {:<20}\n", row, pdg, p, sector);
106 }
107 100 fmt::print("\n");
108 }
109
110 // stop algorithms
111
1/2
✓ Branch 120 → 121 taken 1 time.
✗ Branch 120 → 197 not taken.
1 seq.Stop();
112 return 0;
113 1 }
114