Line | Branch | Exec | Source |
---|---|---|---|
1 | /// @begin_doc_example{cpp} | ||
2 | /// @file iguana_ex_cpp_01_action_functions.cc | ||
3 | /// @brief Example using Iguana action functions on data from bank rows. This is useful for | ||
4 | /// users who do not have the `hipo::bank` objects, instead only having the numerical data from them. | ||
5 | /// @par Usage | ||
6 | /// ```bash | ||
7 | /// iguana_ex_cpp_01_action_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 | /// | ||
15 | /// @note while this example _does_ use `hipo::bank` objects to read HIPO data, it demonstrates | ||
16 | /// using action functions called with the data _from_ these banks. | ||
17 | /// | ||
18 | /// @end_doc_example | ||
19 | #include <hipo4/reader.h> | ||
20 | #include <iguana/algorithms/clas12/EventBuilderFilter/Algorithm.h> | ||
21 | #include <iguana/algorithms/clas12/MomentumCorrection/Algorithm.h> | ||
22 | |||
23 | /// main function | ||
24 | 1 | int main(int argc, char** argv) | |
25 | { | ||
26 | |||
27 | // parse arguments | ||
28 | int argi = 1; | ||
29 |
1/2✓ Branch 0 (2→3) taken 1 times.
✗ Branch 1 (2→12) not taken.
|
1 | char const* inFileName = argc > argi ? argv[argi++] : "data.hipo"; |
30 |
1/2✓ Branch 0 (3→4) taken 1 times.
✗ Branch 1 (3→12) not taken.
|
1 | int const numEvents = argc > argi ? std::stoi(argv[argi++]) : 1; |
31 | |||
32 | // read input file | ||
33 |
1/2✓ Branch 0 (13→14) taken 1 times.
✗ Branch 1 (13→116) not taken.
|
1 | hipo::reader reader(inFileName,{0}); |
34 | |||
35 | // set list of banks to be read | ||
36 |
2/4✓ Branch 0 (17→18) taken 1 times.
✗ Branch 1 (17→169) not taken.
✓ Branch 2 (18→19) taken 1 times.
✗ Branch 3 (18→120) not taken.
|
1 | hipo::banklist banks = reader.getBanks({"REC::Particle", "RUN::config"}); |
37 | |||
38 | // get bank index, for each bank we want to use after Iguana algorithms run | ||
39 |
2/4✓ Branch 0 (20→21) taken 1 times.
✗ Branch 1 (20→167) not taken.
✓ Branch 2 (21→22) taken 1 times.
✗ Branch 3 (21→122) not taken.
|
1 | auto b_particle = hipo::getBanklistIndex(banks, "REC::Particle"); |
40 |
2/4✓ Branch 0 (27→28) taken 1 times.
✗ Branch 1 (27→167) not taken.
✓ Branch 2 (28→29) taken 1 times.
✗ Branch 3 (28→128) not taken.
|
1 | auto b_config = hipo::getBanklistIndex(banks, "RUN::config"); |
41 | |||
42 | // set the concurrency model to single-threaded, since this example is single-threaded; | ||
43 | // not doing this will use the thread-safe model, `"memoize"` | ||
44 |
2/4✓ Branch 0 (34→35) taken 1 times.
✗ Branch 1 (34→167) not taken.
✓ Branch 2 (35→36) taken 1 times.
✗ Branch 3 (35→134) not taken.
|
1 | iguana::GlobalConcurrencyModel = "single"; |
45 | |||
46 | // create the algorithms | ||
47 |
1/2✓ Branch 0 (41→42) taken 1 times.
✗ Branch 1 (41→167) not taken.
|
1 | iguana::clas12::EventBuilderFilter algo_eventbuilder_filter; |
48 |
1/2✓ Branch 0 (42→43) taken 1 times.
✗ Branch 1 (42→164) not taken.
|
1 | iguana::clas12::MomentumCorrection algo_momentum_correction; |
49 | |||
50 | // set log levels | ||
51 |
2/4✓ Branch 0 (43→44) taken 1 times.
✗ Branch 1 (43→162) not taken.
✓ Branch 2 (44→45) taken 1 times.
✗ Branch 3 (44→140) not taken.
|
1 | algo_eventbuilder_filter.SetOption("log", "debug"); |
52 |
2/4✓ Branch 0 (50→51) taken 1 times.
✗ Branch 1 (50→162) not taken.
✓ Branch 2 (51→52) taken 1 times.
✗ Branch 3 (51→146) not taken.
|
1 | algo_momentum_correction.SetOption("log", "debug"); |
53 | |||
54 | // set algorithm options | ||
55 |
4/10✓ Branch 0 (57→58) taken 1 times.
✗ Branch 1 (57→162) not taken.
✓ Branch 2 (58→59) taken 1 times.
✗ Branch 3 (58→158) not taken.
✓ Branch 4 (59→60) taken 1 times.
✗ Branch 5 (59→152) not taken.
✓ Branch 6 (68→69) taken 1 times.
✗ Branch 7 (68→71) not taken.
✗ Branch 8 (158→159) not taken.
✗ Branch 9 (158→161) not taken.
|
2 | algo_eventbuilder_filter.SetOption<std::vector<int>>("pids", {11, 211, -211}); |
56 | |||
57 | // start the algorithms | ||
58 |
1/2✓ Branch 0 (71→72) taken 1 times.
✗ Branch 1 (71→162) not taken.
|
1 | algo_eventbuilder_filter.Start(); |
59 |
1/2✓ Branch 0 (72→97) taken 1 times.
✗ Branch 1 (72→162) not taken.
|
1 | algo_momentum_correction.Start(); |
60 | |||
61 | // run the algorithm sequence on each event | ||
62 | int iEvent = 0; | ||
63 |
5/8✓ Branch 0 (97→98) taken 101 times.
✗ Branch 1 (97→162) not taken.
✓ Branch 2 (98→99) taken 101 times.
✗ Branch 3 (98→102) not taken.
✓ Branch 4 (99→100) taken 101 times.
✗ Branch 5 (99→101) not taken.
✓ Branch 6 (100→101) taken 100 times.
✓ Branch 7 (100→102) taken 1 times.
|
101 | while(reader.next(banks) && (numEvents == 0 || iEvent++ < numEvents)) { |
64 | |||
65 | // show the particle bank | ||
66 |
1/2✓ Branch 0 (101→73) taken 100 times.
✗ Branch 1 (101→162) not taken.
|
100 | auto& particleBank = banks.at(b_particle); |
67 |
1/2✓ Branch 0 (73→74) taken 100 times.
✗ Branch 1 (73→162) not taken.
|
100 | auto& configBank = banks.at(b_config); |
68 |
1/2✓ Branch 0 (74→75) taken 100 times.
✗ Branch 1 (74→162) not taken.
|
100 | particleBank.show(); |
69 | |||
70 | // loop over bank rows | ||
71 |
3/4✓ Branch 0 (75→76) taken 100 times.
✗ Branch 1 (75→162) not taken.
✓ Branch 2 (96→77) taken 683 times.
✓ Branch 3 (96→97) taken 100 times.
|
783 | for(auto const& row : particleBank.getRowList()) { |
72 | |||
73 | // check the PID with EventBuilderFilter | ||
74 | 683 | auto pid = particleBank.getInt("pid", row); | |
75 |
3/4✓ Branch 0 (78→79) taken 683 times.
✗ Branch 1 (78→162) not taken.
✓ Branch 2 (79→80) taken 201 times.
✓ Branch 3 (79→95) taken 482 times.
|
683 | if(algo_eventbuilder_filter.Filter(pid)) { |
76 | |||
77 | int sector = 1; // FIXME: get the sector number. The algorithm `clas12::SectorFinder` can do this, however | ||
78 | // it requires reading full `hipo::bank` objects, whereas this example is meant to demonstrate | ||
79 | // `iguana` usage operating _only_ on bank row elements | ||
80 | |||
81 | // if accepted PID, correct its momentum | ||
82 |
1/2✓ Branch 0 (84→85) taken 201 times.
✗ Branch 1 (84→162) not taken.
|
402 | auto [px, py, pz] = algo_momentum_correction.Transform( |
83 | 201 | particleBank.getFloat("px", row), | |
84 | 201 | particleBank.getFloat("py", row), | |
85 | 201 | particleBank.getFloat("pz", row), | |
86 | sector, | ||
87 | pid, | ||
88 | configBank.getFloat("torus", 0)); | ||
89 | |||
90 | // then print the result | ||
91 |
1/2✓ Branch 0 (86→87) taken 201 times.
✗ Branch 1 (86→162) not taken.
|
201 | fmt::print("Accepted PID {}:\n", pid); |
92 | auto printMomentum = [](auto v1, auto v2) | ||
93 |
1/2✓ Branch 0 (87→88) taken 201 times.
✗ Branch 1 (87→162) not taken.
|
402 | { fmt::print(" {:>20} {:>20}\n", v1, v2); }; |
94 | printMomentum("p_old", "p_new"); | ||
95 | printMomentum("--------", "--------"); | ||
96 | 201 | printMomentum(particleBank.getFloat("px", row), px); | |
97 | 201 | printMomentum(particleBank.getFloat("py", row), py); | |
98 | 201 | printMomentum(particleBank.getFloat("pz", row), pz); | |
99 | } | ||
100 | } | ||
101 | } | ||
102 | |||
103 | // stop the algorithms | ||
104 |
1/2✓ Branch 0 (102→103) taken 1 times.
✗ Branch 1 (102→162) not taken.
|
1 | algo_eventbuilder_filter.Stop(); |
105 |
1/2✓ Branch 0 (103→104) taken 1 times.
✗ Branch 1 (103→162) not taken.
|
1 | algo_momentum_correction.Stop(); |
106 | return 0; | ||
107 | 1 | } | |
108 |