GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/clas12/SectorFinder/Algorithm.cc
Date: 2025-11-25 17:57:04
Coverage Exec Excl Total
Lines: 74.3% 81 0 109
Functions: 87.5% 7 0 8
Branches: 46.5% 113 0 243

Line Branch Exec Source
1 #include "Algorithm.h"
2
3 namespace iguana::clas12 {
4
5 REGISTER_IGUANA_ALGORITHM(SectorFinder, "REC::Particle::Sector");
6
7 9 void SectorFinder::Start(hipo::banklist& banks)
8 {
9
10 // define options, their default values, and cache them
11 9 ParseYAMLConfig();
12
2/4
✓ Branch 4 → 5 taken 9 times.
✗ Branch 4 → 111 not taken.
✓ Branch 5 → 6 taken 9 times.
✗ Branch 5 → 105 not taken.
18 o_bankname_charged = GetOptionScalar<std::string>("bank_charged");
13 try {
14
3/6
✓ Branch 18 → 19 taken 9 times.
✗ Branch 18 → 121 not taken.
✓ Branch 20 → 21 taken 9 times.
✗ Branch 20 → 119 not taken.
✓ Branch 21 → 22 taken 9 times.
✗ Branch 21 → 113 not taken.
27 o_bankname_neutral = GetOptionScalar<std::string>("bank_neutral");
15 }
16 catch(std::runtime_error const& ex) {
17 m_log->Warn("searching instead for configuration parameter named 'bank_uncharged'...");
18 o_bankname_neutral = GetOptionScalar<std::string>("bank_uncharged");
19 m_log->Warn("...found 'bank_uncharged' and using it; note that 'bank_uncharged' has been renamed to 'bank_neutral', please update your configuration");
20 }
21
22 bool setDefaultBanks = false;
23 // get expected bank indices
24
4/6
✓ Branch 36 → 37 taken 9 times.
✗ Branch 36 → 153 not taken.
✓ Branch 37 → 38 taken 9 times.
✗ Branch 37 → 40 not taken.
✓ Branch 42 → 43 taken 1 time.
✓ Branch 42 → 45 taken 8 times.
18 b_particle = GetBankIndex(banks, "REC::Particle");
25
2/2
✓ Branch 42 → 43 taken 1 time.
✓ Branch 42 → 45 taken 8 times.
9 if(o_bankname_charged != "default") {
26 1 b_user_charged = GetBankIndex(banks, o_bankname_charged);
27 1 userSpecifiedBank_charged = true;
28 }
29 else {
30
2/4
✓ Branch 46 → 47 taken 8 times.
✗ Branch 46 → 159 not taken.
✓ Branch 47 → 48 taken 8 times.
✗ Branch 47 → 50 not taken.
8 b_track = GetBankIndex(banks, "REC::Track");
31
2/4
✓ Branch 53 → 54 taken 8 times.
✗ Branch 53 → 165 not taken.
✗ Branch 54 → 55 not taken.
✓ Branch 54 → 57 taken 8 times.
8 b_calorimeter = GetBankIndex(banks, "REC::Calorimeter");
32
2/4
✓ Branch 60 → 61 taken 8 times.
✗ Branch 60 → 171 not taken.
✗ Branch 61 → 62 not taken.
✓ Branch 61 → 64 taken 8 times.
8 b_scint = GetBankIndex(banks, "REC::Scintillator");
33 setDefaultBanks = true;
34 8 userSpecifiedBank_charged = false;
35 }
36
37
1/2
✗ Branch 67 → 68 not taken.
✓ Branch 67 → 70 taken 9 times.
9 if(o_bankname_neutral != "default") {
38 b_user_neutral = GetBankIndex(banks, o_bankname_neutral);
39 userSpecifiedBank_neutral = true;
40 }
41 else {
42 // avoid setting default banks twice
43
2/2
✓ Branch 70 → 71 taken 1 time.
✓ Branch 70 → 93 taken 8 times.
9 if(!setDefaultBanks) {
44
2/4
✓ Branch 72 → 73 taken 1 time.
✗ Branch 72 → 177 not taken.
✓ Branch 73 → 74 taken 1 time.
✗ Branch 73 → 76 not taken.
1 b_track = GetBankIndex(banks, "REC::Track");
45
2/4
✓ Branch 79 → 80 taken 1 time.
✗ Branch 79 → 183 not taken.
✗ Branch 80 → 81 not taken.
✓ Branch 80 → 83 taken 1 time.
1 b_calorimeter = GetBankIndex(banks, "REC::Calorimeter");
46
2/4
✓ Branch 86 → 87 taken 1 time.
✗ Branch 86 → 189 not taken.
✗ Branch 87 → 88 not taken.
✓ Branch 87 → 90 taken 1 time.
2 b_scint = GetBankIndex(banks, "REC::Scintillator");
47 setDefaultBanks = true;
48 }
49 9 userSpecifiedBank_neutral = false;
50 }
51
52 // create the output bank
53
1/2
✓ Branch 95 → 96 taken 9 times.
✗ Branch 95 → 195 not taken.
9 auto result_schema = CreateBank(banks, b_result, "REC::Particle::Sector");
54
1/2
✓ Branch 101 → 102 taken 9 times.
✗ Branch 101 → 201 not taken.
9 i_sector = result_schema.getEntryOrder("sector");
55
1/2
✓ Branch 102 → 103 taken 9 times.
✗ Branch 102 → 201 not taken.
9 i_pindex = result_schema.getEntryOrder("pindex");
56 9 }
57
58 3843 bool SectorFinder::Run(hipo::banklist& banks) const
59 {
60
3/4
✓ Branch 2 → 3 taken 882 times.
✓ Branch 2 → 4 taken 2961 times.
✓ Branch 3 → 4 taken 882 times.
✗ Branch 3 → 5 not taken.
3843 auto includeDefaultBanks = !(userSpecifiedBank_charged && userSpecifiedBank_neutral);
61
3/6
✓ Branch 13 → 14 taken 3843 times.
✗ Branch 13 → 18 not taken.
✓ Branch 18 → 19 taken 3843 times.
✗ Branch 18 → 21 not taken.
✓ Branch 23 → 24 taken 3843 times.
✗ Branch 23 → 70 not taken.
11529 return RunImpl(
62
2/4
✓ Branch 21 → 22 taken 3843 times.
✗ Branch 21 → 76 not taken.
✓ Branch 22 → 23 taken 3843 times.
✗ Branch 22 → 70 not taken.
3843 &GetBank(banks, b_particle, "REC::Particle"),
63
3/8
✓ Branch 19 → 20 taken 3843 times.
✗ Branch 19 → 83 not taken.
✓ Branch 20 → 21 taken 3843 times.
✗ Branch 20 → 77 not taken.
✓ Branch 29 → 30 taken 3843 times.
✗ Branch 29 → 36 not taken.
✗ Branch 76 → 77 not taken.
✗ Branch 76 → 83 not taken.
7686 includeDefaultBanks ? &GetBank(banks, b_track, "REC::Track") : nullptr,
64
3/8
✓ Branch 16 → 17 taken 3843 times.
✗ Branch 16 → 91 not taken.
✓ Branch 17 → 18 taken 3843 times.
✗ Branch 17 → 85 not taken.
✓ Branch 36 → 37 taken 3843 times.
✗ Branch 36 → 43 not taken.
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 91 not taken.
7686 includeDefaultBanks ? &GetBank(banks, b_calorimeter, "REC::Calorimeter") : nullptr,
65
5/12
✓ Branch 14 → 15 taken 3843 times.
✗ Branch 14 → 99 not taken.
✓ Branch 15 → 16 taken 3843 times.
✗ Branch 15 → 93 not taken.
✓ Branch 43 → 44 taken 3843 times.
✗ Branch 43 → 50 not taken.
✓ Branch 50 → 51 taken 882 times.
✓ Branch 50 → 57 taken 2961 times.
✗ Branch 92 → 93 not taken.
✗ Branch 92 → 99 not taken.
✗ Branch 100 → 101 not taken.
✗ Branch 100 → 107 not taken.
11529 includeDefaultBanks ? &GetBank(banks, b_scint, "REC::Scintillator") : nullptr,
66
3/4
✓ Branch 10 → 11 taken 882 times.
✓ Branch 10 → 13 taken 2961 times.
✓ Branch 12 → 13 taken 882 times.
✗ Branch 12 → 101 not taken.
4725 userSpecifiedBank_charged ? &GetBank(banks, b_user_charged) : nullptr,
67
1/4
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 10 taken 3843 times.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 109 not taken.
3843 userSpecifiedBank_neutral ? &GetBank(banks, b_user_neutral) : nullptr,
68
1/2
✓ Branch 6 → 7 taken 3843 times.
✗ Branch 6 → 116 not taken.
7686 &GetBank(banks, b_result, "REC::Particle::Sector"));
69 }
70
71 3926 bool SectorFinder::RunImpl(
72 hipo::bank const* particleBank,
73 hipo::bank const* trackBank,
74 hipo::bank const* calBank,
75 hipo::bank const* scintBank,
76 hipo::bank const* userChargedBank,
77 hipo::bank const* userNeutralBank,
78 hipo::bank* resultBank) const
79 {
80 3926 resultBank->reset(); // IMPORTANT: always first `reset` the created bank(s)
81
82 std::vector<int> sectors_track;
83 std::vector<int> pindices_track;
84 std::vector<int> sectors_cal;
85 std::vector<int> pindices_cal;
86 std::vector<int> sectors_scint;
87 std::vector<int> pindices_scint;
88 std::vector<int> sectors_user_neutral;
89 std::vector<int> pindices_user_neutral;
90 std::vector<int> sectors_user_charged;
91 std::vector<int> pindices_user_charged;
92
93
3/4
✓ Branch 3 → 4 taken 882 times.
✓ Branch 3 → 5 taken 3044 times.
✓ Branch 4 → 5 taken 882 times.
✗ Branch 4 → 13 not taken.
3926 if(!userSpecifiedBank_charged || !userSpecifiedBank_neutral) {
94
2/4
✓ Branch 5 → 6 taken 3926 times.
✗ Branch 5 → 10 not taken.
✓ Branch 6 → 7 taken 3926 times.
✗ Branch 6 → 10 not taken.
3926 if(trackBank != nullptr && calBank != nullptr && scintBank != nullptr) {
95
1/2
✓ Branch 7 → 8 taken 3926 times.
✗ Branch 7 → 108 not taken.
3926 GetListsSectorPindex(*trackBank, sectors_track, pindices_track);
96
1/2
✓ Branch 8 → 9 taken 3926 times.
✗ Branch 8 → 108 not taken.
3926 GetListsSectorPindex(*scintBank, sectors_scint, pindices_scint);
97
1/2
✓ Branch 9 → 13 taken 3926 times.
✗ Branch 9 → 108 not taken.
3926 GetListsSectorPindex(*calBank, sectors_cal, pindices_cal);
98 }
99 else
100 throw std::runtime_error("SectorFinder::RunImpl called with unexpected null pointer to either the track, calorimeter, or scintillator bank(s); please contact the maintainers");
101 }
102
103
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 19 taken 3926 times.
3926 if(userSpecifiedBank_neutral) {
104 if(userNeutralBank != nullptr)
105 GetListsSectorPindex(*userNeutralBank, sectors_user_neutral, pindices_user_neutral);
106 else
107 throw std::runtime_error("SectorFinder::RunImpl called with unexpected null pointer to a user-specified bank; please contact the maintainers");
108 }
109
110
2/2
✓ Branch 19 → 20 taken 882 times.
✓ Branch 19 → 25 taken 3044 times.
3926 if(userSpecifiedBank_charged) {
111
1/2
✓ Branch 20 → 21 taken 882 times.
✗ Branch 20 → 22 not taken.
882 if(userChargedBank != nullptr)
112
1/2
✓ Branch 21 → 25 taken 882 times.
✗ Branch 21 → 108 not taken.
882 GetListsSectorPindex(*userChargedBank, sectors_user_charged, pindices_user_charged);
113 else
114 throw std::runtime_error("SectorFinder::RunImpl called with unexpected null pointer to a user-specified bank; please contact the maintainers");
115 }
116
117 // trace logging
118
2/4
✓ Branch 25 → 26 taken 3926 times.
✗ Branch 25 → 108 not taken.
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 38 taken 3926 times.
3926 if(m_log->GetLevel() <= Logger::Level::trace) {
119 m_log->Trace("pindices_track = {}", fmt::join(pindices_track, ","));
120 m_log->Trace("sectors_track = {}", fmt::join(sectors_track, ","));
121 m_log->Trace("pindices_scint = {}", fmt::join(pindices_scint, ","));
122 m_log->Trace("sectors_scint = {}", fmt::join(sectors_scint, ","));
123 m_log->Trace("pindices_cal = {}", fmt::join(pindices_cal, ","));
124 m_log->Trace("sectors_cal = {}", fmt::join(sectors_cal, ","));
125 m_log->Trace("pindices_user_neutral = {}", fmt::join(pindices_user_neutral, ","));
126 m_log->Trace("sectors_user_neutral = {}", fmt::join(sectors_user_neutral, ","));
127 m_log->Trace("pindices_user_charged = {}", fmt::join(pindices_user_charged, ","));
128 m_log->Trace("sectors_user_charged = {}", fmt::join(sectors_user_charged, ","));
129 }
130
131 // sync new bank with particle bank
132
1/2
✓ Branch 38 → 39 taken 3926 times.
✗ Branch 38 → 108 not taken.
3926 resultBank->setRows(particleBank->getRows());
133
3/6
✓ Branch 39 → 40 taken 3926 times.
✗ Branch 39 → 108 not taken.
✓ Branch 40 → 41 taken 3926 times.
✗ Branch 40 → 108 not taken.
✓ Branch 41 → 42 taken 3926 times.
✗ Branch 41 → 108 not taken.
3926 resultBank->getMutableRowList().setList(particleBank->getRowList());
134
135 // some downstream algorithms may still need sector info, so obtain sector for _all_ particles,
136 // not just the ones that were filtered out (use `.getRows()` rather than `.getRowList()`)
137
2/2
✓ Branch 55 → 43 taken 28354 times.
✓ Branch 55 → 56 taken 3926 times.
32280 for(int row = 0; row < particleBank->getRows(); row++) {
138
139 28354 auto charge = particleBank->getInt("charge", row);
140 int sect = UNKNOWN_SECTOR;
141
142 // if user-specified bank
143
4/4
✓ Branch 44 → 45 taken 14945 times.
✓ Branch 44 → 46 taken 13409 times.
✓ Branch 47 → 48 taken 3003 times.
✓ Branch 47 → 51 taken 25351 times.
28354 if(charge == 0 ? userSpecifiedBank_neutral : userSpecifiedBank_charged)
144
2/4
✓ Branch 48 → 49 taken 3003 times.
✗ Branch 48 → 50 not taken.
✓ Branch 50 → 52 taken 3003 times.
✗ Branch 50 → 108 not taken.
6006 sect = GetSector(
145 charge == 0 ? sectors_user_neutral : sectors_user_charged,
146 charge == 0 ? pindices_user_neutral : pindices_user_charged,
147 row);
148 else // if not user-specified bank, use the standard method
149
1/2
✓ Branch 51 → 52 taken 25351 times.
✗ Branch 51 → 108 not taken.
25351 sect = GetStandardSector(
150 sectors_track,
151 pindices_track,
152 sectors_cal,
153 pindices_cal,
154 sectors_scint,
155 pindices_scint,
156 row);
157
158 28354 resultBank->putInt(i_sector, row, sect);
159 28354 resultBank->putShort(i_pindex, row, static_cast<int16_t>(row));
160 }
161
162
4/8
✓ Branch 56 → 57 taken 3926 times.
✗ Branch 56 → 108 not taken.
✓ Branch 59 → 60 taken 3926 times.
✗ Branch 59 → 102 not taken.
✓ Branch 65 → 66 taken 752 times.
✓ Branch 65 → 68 taken 3174 times.
✗ Branch 108 → 109 not taken.
✗ Branch 108 → 111 not taken.
11778 ShowBank(*resultBank, Logger::Header("CREATED BANK"));
163 3926 return true;
164 }
165
166 12660 void SectorFinder::GetListsSectorPindex(hipo::bank const& bank, std::vector<int>& sectors, std::vector<int>& pindices) const
167 {
168
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 12660 times.
12660 if(m_log->GetLevel() <= Logger::Level::trace) {
169 m_log->Trace("called `GetListsSectorPindex` for the following bank:");
170 bank.show();
171 }
172
2/2
✓ Branch 25 → 8 taken 63440 times.
✓ Branch 25 → 26 taken 12660 times.
76100 for(auto const& row : bank.getRowList()) {
173 // check that we're only using FD detectors
174 // eg have "sectors" in CND which we don't want to add here
175 63440 auto det = bank.getByte("detector", row);
176
2/2
✓ Branch 18 → 19 taken 50405 times.
✓ Branch 18 → 24 taken 13035 times.
63440 if(listFDDets.find(det) != listFDDets.end()) {
177 50405 sectors.push_back(bank.getInt("sector", row));
178 50405 pindices.push_back(bank.getShort("pindex", row));
179 }
180 }
181 12660 }
182
183 64383 int SectorFinder::GetSector(std::vector<int> const& sectors, std::vector<int> const& pindices, int const& pindex_particle) const
184 {
185
2/2
✓ Branch 10 → 3 taken 245630 times.
✓ Branch 10 → 11 taken 46560 times.
584380 for(std::size_t i = 0; i < sectors.size(); i++) {
186
2/2
✓ Branch 4 → 5 taken 17823 times.
✓ Branch 4 → 7 taken 227807 times.
245630 if(pindices.at(i) == pindex_particle) {
187
2/2
✓ Branch 6 → 11 taken 30 times.
✓ Branch 6 → 12 taken 17793 times.
17823 auto sect = sectors.at(i);
188
2/2
✓ Branch 6 → 11 taken 30 times.
✓ Branch 6 → 12 taken 17793 times.
17823 return IsValidSector(sect) ? sect : UNKNOWN_SECTOR;
189 }
190 }
191 return UNKNOWN_SECTOR; // pindex not found
192 }
193
194 25552 int SectorFinder::GetStandardSector(
195 std::vector<int> const& sectors_track,
196 std::vector<int> const& pindices_track,
197 std::vector<int> const& sectors_cal,
198 std::vector<int> const& pindices_cal,
199 std::vector<int> const& sectors_scint,
200 std::vector<int> const& pindices_scint,
201 int const& pindex_particle) const
202 {
203 enum det_enum { kTrack,
204 kScint,
205 kCal,
206 nDet }; // try to get sector from these detectors, in this order
207
2/2
✓ Branch 33 → 3 taken 61380 times.
✓ Branch 33 → 34 taken 9428 times.
70808 for(int d = 0; d < nDet; d++) {
208 int sect = UNKNOWN_SECTOR;
209 std::string det_name;
210
3/3
✓ Branch 3 → 4 taken 25552 times.
✓ Branch 3 → 6 taken 19496 times.
✓ Branch 3 → 8 taken 16332 times.
61380 switch(d) {
211 25552 case kTrack:
212
1/2
✓ Branch 4 → 5 taken 25552 times.
✗ Branch 4 → 41 not taken.
25552 sect = GetSector(sectors_track, pindices_track, pindex_particle);
213 det_name = "track";
214 break;
215 19496 case kScint:
216
1/2
✓ Branch 6 → 7 taken 19496 times.
✗ Branch 6 → 41 not taken.
19496 sect = GetSector(sectors_scint, pindices_scint, pindex_particle);
217 det_name = "scint";
218 break;
219 16332 case kCal:
220
1/2
✓ Branch 8 → 9 taken 16332 times.
✗ Branch 8 → 41 not taken.
16332 sect = GetSector(sectors_cal, pindices_cal, pindex_particle);
221 det_name = "cal";
222 break;
223 }
224
5/12
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 61380 times.
✓ Branch 14 → 15 taken 61380 times.
✗ Branch 14 → 35 not taken.
✓ Branch 15 → 16 taken 61380 times.
✗ Branch 15 → 18 not taken.
✓ Branch 20 → 21 taken 16124 times.
✓ Branch 20 → 27 taken 45256 times.
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 38 not taken.
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 44 not taken.
184140 m_log->Trace("{} pindex {} sect {}", det_name, pindex_particle, sect);
225
2/2
✓ Branch 20 → 21 taken 16124 times.
✓ Branch 20 → 27 taken 45256 times.
61380 if(IsValidSector(sect)) // return this sector number; if not valid, continue to next detector in `det_enum`
226 return sect;
227 }
228 return UNKNOWN_SECTOR; // not found in any detector in `det_enum`
229 }
230
231 std::vector<int> SectorFinder::GetStandardSector(
232 std::vector<int> const& sectors_track,
233 std::vector<int> const& pindices_track,
234 std::vector<int> const& sectors_cal,
235 std::vector<int> const& pindices_cal,
236 std::vector<int> const& sectors_scint,
237 std::vector<int> const& pindices_scint,
238 std::vector<int> const& pindices_particle) const
239 {
240 std::vector<int> sect_list;
241 for(auto const& pindex : pindices_particle)
242 sect_list.push_back(GetStandardSector(
243 sectors_track,
244 pindices_track,
245 sectors_cal,
246 pindices_cal,
247 sectors_scint,
248 pindices_scint,
249 pindex));
250 return sect_list;
251 }
252
253 7 void SectorFinder::Stop()
254 {
255 7 }
256
257 }
258