GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/clas12/MatchParticleProximity/Algorithm.cc
Date: 2025-12-23 16:10:08
Coverage Exec Excl Total
Lines: 75.0% 33 0 44
Functions: 100.0% 4 0 4
Branches: 38.7% 24 0 62

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