GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 74.4% 32 / 0 / 43
Functions: 100.0% 4 / 0 / 4
Branches: 40.0% 28 / 0 / 70

src/iguana/algorithms/clas12/MatchParticleProximity/Algorithm.cc
Line Branch Exec Source
1 #include "Algorithm.h"
2 #include "iguana/algorithms/physics/Tools.h"
3
4 namespace iguana::clas12 {
5
6 REGISTER_IGUANA_ALGORITHM(MatchParticleProximity, "clas12::MatchParticleProximity");
7
8 ///////////////////////////////////////////////////////////////////////////////
9
10 1 void MatchParticleProximity::ConfigHook()
11 {
12
4/8
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 31 not taken.
✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 16 taken 1 time.
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 37 not taken.
3 o_bank_a = GetOptionScalar<std::string>({"bank_a"});
13
4/8
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 40 not taken.
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 38 not taken.
✓ Branch 27 → 28 taken 1 time.
✓ Branch 27 → 30 taken 1 time.
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 44 not taken.
3 o_bank_b = GetOptionScalar<std::string>({"bank_b"});
14 1 }
15
16 ///////////////////////////////////////////////////////////////////////////////
17
18 1 void MatchParticleProximity::StartHook(hipo::banklist& banks)
19 {
20 // banklist indices
21 1 b_bank_a = GetBankIndex(banks, o_bank_a);
22 1 b_bank_b = GetBankIndex(banks, o_bank_b);
23
24 // create the output bank
25
1/2
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 16 not taken.
1 auto result_schema = CreateBank(banks, b_result, "clas12::MatchParticleProximity");
26
1/2
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 22 not taken.
1 i_pindex_a = result_schema.getEntryOrder("pindex_a");
27
1/2
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 22 not taken.
1 i_pindex_b = result_schema.getEntryOrder("pindex_b");
28
1/2
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 22 not taken.
1 i_proximity = result_schema.getEntryOrder("proximity");
29 1 }
30
31 ///////////////////////////////////////////////////////////////////////////////
32
33 1000 bool MatchParticleProximity::RunHook(hipo::banklist& banks) const
34 {
35
1/2
✓ Branch 6 → 7 taken 1000 times.
✗ Branch 6 → 13 not taken.
1000 return Run(
36
1/2
✓ Branch 5 → 6 taken 1000 times.
✗ Branch 5 → 13 not taken.
1000 GetBank(banks, b_bank_a, o_bank_a),
37
1/2
✓ Branch 4 → 5 taken 1000 times.
✗ Branch 4 → 13 not taken.
1000 GetBank(banks, b_bank_b, o_bank_b),
38
1/2
✓ Branch 3 → 4 taken 1000 times.
✗ Branch 3 → 13 not taken.
2000 GetBank(banks, b_result, "clas12::MatchParticleProximity"));
39 }
40
41 1000 bool MatchParticleProximity::Run(
42 hipo::bank const& bank_a,
43 hipo::bank const& bank_b,
44 hipo::bank& result_bank) const
45 {
46 1000 result_bank.reset(); // IMPORTANT: always first `reset` the created bank(s)
47
48
1/2
✓ Branch 6 → 7 taken 1000 times.
✗ Branch 6 → 69 not taken.
2000 ShowBank(bank_a, Logger::Header("INPUT BANK A"));
49
1/2
✓ Branch 15 → 16 taken 1000 times.
✗ Branch 15 → 75 not taken.
3000 ShowBank(bank_b, Logger::Header("INPUT BANK B"));
50
51 // output rows
52 std::vector<MatchParticleProximityVars> result_rows;
53
54 // loop over ALL bank-A particles, to find matching bank-B particles
55
2/2
✓ Branch 46 → 22 taken 6993 times.
✓ Branch 46 → 47 taken 1000 times.
7993 for(int row_a = 0; row_a < bank_a.getRows(); row_a++) {
56
57 // matching variables
58 double min_prox = -1; // minimum proximity
59 int pindex_b = -1; // matching `pindex` of `bank_b`
60
61 // particle info
62 6993 auto pid_a = bank_a.getInt("pid", row_a);
63 ROOT::Math::XYZVector p_a(
64 6993 bank_a.getFloat("px", row_a),
65 6993 bank_a.getFloat("py", row_a),
66 6993 bank_a.getFloat("pz", row_a));
67 auto theta_a = p_a.theta();
68 auto phi_a = p_a.phi();
69
70 // loop over ALL bank-B particles, and find the one with the smallest proximity to
71 // the current bank-A particle
72
1/2
✗ Branch 41 → 28 not taken.
✓ Branch 41 → 42 taken 6993 times.
6993 for(int row_b = 0; row_b < bank_b.getRows(); row_b++) {
73 // PID must match
74 if(pid_a == bank_b.getInt("pid", row_b)) {
75 // particle info
76 ROOT::Math::XYZVector p_b(
77 bank_b.getFloat("px", row_b),
78 bank_b.getFloat("py", row_b),
79 bank_b.getFloat("pz", row_b));
80 auto theta_b = p_b.theta();
81 auto phi_b = p_b.phi();
82 // calculate Euclidean distance in (theta,phi) space
83 auto prox = std::hypot(
84 physics::tools::AdjustAnglePi(theta_b - theta_a),
85 physics::tools::AdjustAnglePi(phi_b - phi_a));
86 // if smallest proximity, this is the best one
87 if(min_prox < 0 || prox < min_prox) {
88 min_prox = prox;
89 pindex_b = row_b;
90 }
91 }
92 }
93
94 // if a match was found, populate the output bank
95
1/2
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 45 taken 6993 times.
6993 if(pindex_b >= 0)
96 result_rows.push_back({
97 .pindex_a = row_a,
98 .pindex_b = pindex_b,
99 .proximity = min_prox,
100 });
101 }
102
103 // fill output bank
104
1/2
✓ Branch 49 → 55 taken 1000 times.
✗ Branch 49 → 87 not taken.
1000 result_bank.setRows(result_rows.size());
105
1/2
✗ Branch 55 → 50 not taken.
✓ Branch 55 → 56 taken 1000 times.
1000 for(decltype(result_rows)::size_type row = 0; row < result_rows.size(); row++) {
106 auto const& result_row = result_rows.at(row);
107 result_bank.putShort(i_pindex_a, row, result_row.pindex_a);
108 result_bank.putShort(i_pindex_b, row, result_row.pindex_b);
109 result_bank.putDouble(i_proximity, row, result_row.proximity);
110 }
111
112
3/8
✓ Branch 56 → 57 taken 1000 times.
✗ Branch 56 → 87 not taken.
✓ Branch 59 → 60 taken 1000 times.
✗ Branch 59 → 81 not taken.
✗ Branch 65 → 66 not taken.
✓ Branch 65 → 68 taken 1000 times.
✗ Branch 87 → 88 not taken.
✗ Branch 87 → 90 not taken.
3000 ShowBank(result_bank, Logger::Header("CREATED BANK"));
113
1/2
✗ Branch 65 → 66 not taken.
✓ Branch 65 → 68 taken 1000 times.
1000 return result_bank.getRows() > 0;
114 }
115
116 ///////////////////////////////////////////////////////////////////////////////
117
118 }
119