GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 5 / 0 / 5
Functions: 100.0% 3 / 0 / 3
Branches: 40.0% 8 / 0 / 20

src/iguana/algorithms/clas12/SectorFinder/Algorithm.h
Line Branch Exec Source
1 #pragma once
2
3 #include "iguana/algorithms/Algorithm.h"
4 #include "iguana/algorithms/TypeDefs.h"
5
6 namespace iguana::clas12 {
7
8 /// @algo_brief{Find the sector for all rows in `REC::Particle`}
9 /// @algo_type_creator
10 ///
11 /// @doc_config{clas12/SectorFinder}
12 ///
13 /// If `bank_charged` and/or `bank_neutral` is default, then all of the following banks are needed, in addition to `REC::Particle`:
14 ///
15 /// - `REC::Track`
16 /// - `REC::Calorimeter`
17 /// - `REC::Scintillator`
18 ///
19 /// Otherwise only the bank(s) specified by `bank_charged` and `bank_neutral` is/are needed, if both of them are non-default.
20 ///
21 /// If the sector cannot be determined, the value `UNKNOWN_SECTOR` will be used instead.
22 ///
23 /// The action function ::GetStandardSector identifies the sector(s) using these banks in a priority order, whereas
24 /// the action function ::GetSector uses a single bank's data.
25 /// Note: rows that have been filtered out of `REC::Particle` will still have their sectors determined.
26 class SectorFinder : public Algorithm
27 {
28
29
7/18
✓ Branch 2 → 3 taken 9 times.
✗ Branch 2 → 6 not taken.
✗ Branch 5 → 7 not taken.
✓ Branch 5 → 8 taken 9 times.
✓ Branch 9 → 10 taken 9 times.
✗ Branch 9 → 33 not taken.
✓ Branch 10 → 11 taken 9 times.
✗ Branch 10 → 17 not taken.
✓ Branch 17 → 18 taken 9 times.
✗ Branch 17 → 43 not taken.
✓ Branch 18 → 19 taken 9 times.
✗ Branch 18 → 41 not taken.
✓ Branch 25 → 26 taken 9 times.
✗ Branch 25 → 41 not taken.
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 40 not taken.
✗ Branch 43 → 44 not taken.
✗ Branch 43 → 46 not taken.
86 DEFINE_IGUANA_ALGORITHM(SectorFinder, clas12::SectorFinder)
30
31 private: // hooks
32 void ConfigHook() override;
33 void StartHook(hipo::banklist& banks) override;
34 bool RunHook(hipo::banklist& banks) const override;
35
36 public:
37
38 /// if this algorithm cannot determine the sector, this value will be used
39 static int const UNKNOWN_SECTOR = -1;
40
41 /// @run_function
42 /// uses track, calorimeter, and scintillator banks for both charged and neutral particles
43 /// @see this algorithm contains multiple run functions, for if you prefer to use other banks
44 /// @param [in] particleBank `REC::Particle`
45 /// @param [in] trackBank `REC::Track`
46 /// @param [in] calBank `REC::Calorimeter`
47 /// @param [in] scintBank `REC::Scintillator`
48 /// @param [out] resultBank the output `REC::Particle::Sector` bank
49 /// @run_function_returns_true
50 bool Run(
51 hipo::bank const& particleBank,
52 hipo::bank const& trackBank,
53 hipo::bank const& calBank,
54 hipo::bank const& scintBank,
55 hipo::bank& resultBank) const
56 {
57
1/2
✓ Branch 58 → 59 taken 93 times.
✗ Branch 58 → 125 not taken.
93 return RunImpl(&particleBank, &trackBank, &calBank, &scintBank, nullptr, nullptr, &resultBank);
58 }
59
60 /// @run_function
61 /// uses track, calorimeter, and scintillator banks for neutral particles, and a custom bank for charged particles
62 /// @see this algorithm contains multiple run functions, for if you prefer to use other banks
63 /// @param [in] particleBank `REC::Particle`
64 /// @param [in] trackBank `REC::Track`
65 /// @param [in] calBank `REC::Calorimeter`
66 /// @param [in] scintBank `REC::Scintillator`
67 /// @param [in] userChargedBank custom bank used to obtain charged-particles' sectors
68 /// @param [out] resultBank the output `REC::Particle::Sector` bank
69 /// @run_function_returns_true
70 bool RunWithCustomChargedBank(
71 hipo::bank const& particleBank,
72 hipo::bank const& trackBank,
73 hipo::bank const& calBank,
74 hipo::bank const& scintBank,
75 hipo::bank const& userChargedBank,
76 hipo::bank& resultBank) const
77 {
78 return RunImpl(&particleBank, &trackBank, &calBank, &scintBank, &userChargedBank, nullptr, &resultBank);
79 }
80
81 /// @run_function
82 /// uses track, calorimeter, and scintillator banks for charged particles, and a custom bank for neutral particles
83 /// @see this algorithm contains multiple run functions, for if you prefer to use other banks
84 /// @param [in] particleBank `REC::Particle`
85 /// @param [in] trackBank `REC::Track`
86 /// @param [in] calBank `REC::Calorimeter`
87 /// @param [in] scintBank `REC::Scintillator`
88 /// @param [in] userNeutralBank custom bank used to obtain neutral-particles' sectors
89 /// @param [out] resultBank the output `REC::Particle::Sector` bank
90 /// @run_function_returns_true
91 bool RunWithCustomNeutralBank(
92 hipo::bank const& particleBank,
93 hipo::bank const& trackBank,
94 hipo::bank const& calBank,
95 hipo::bank const& scintBank,
96 hipo::bank const& userNeutralBank,
97 hipo::bank& resultBank) const
98 {
99 return RunImpl(&particleBank, &trackBank, &calBank, &scintBank, nullptr, &userNeutralBank, &resultBank);
100 }
101
102 /// @run_function
103 /// uses custom banks for both charged and neutral particles
104 /// @see this algorithm contains multiple run functions, for if you prefer to use other banks
105 /// @param [in] particleBank `REC::Particle`
106 /// @param [in] userChargedBank custom bank used to obtain charged-particles' sectors
107 /// @param [in] userNeutralBank custom bank used to obtain neutral-particles' sectors
108 /// @param [out] resultBank the output `REC::Particle::Sector` bank
109 /// @run_function_returns_true
110 bool RunWithCustomBanks(
111 hipo::bank const& particleBank,
112 hipo::bank const& userChargedBank,
113 hipo::bank const& userNeutralBank,
114 hipo::bank& resultBank) const
115 {
116 return RunImpl(&particleBank, nullptr, nullptr, nullptr, &userChargedBank, &userNeutralBank, &resultBank);
117 }
118
119 /// @action_function{scalar creator} for a given particle with index `pindex_particle`, get its sector from
120 /// a detector bank's list of `sectors` and `pindices` (both must be ordered in the same way)
121 ///
122 /// @note this is done instead of finding the `pindex` in the bank directly, to have an action function
123 ///
124 /// @par Example
125 /// ```cpp
126 ///
127 /// //... Initialise algorithms & banks ...
128 ///
129 /// //For each event, do:
130 ///
131 /// std::vector<int> sectors;
132 /// std::vector<int> pindices
133 ///
134 /// //bank is a hipo::bank object from which we want to get the sectors
135 /// //for example the bank object related to REC::Calorimeter
136 /// for(auto const& row : bank.getRowList()) {
137 ///
138 /// int det=bank.getInt("detector",row);
139 ///
140 /// //NB: you should check you read from an FD detector
141 /// // e.g. det 7 is the ECAL (see/use `iguana::DetectorType` enum)
142 /// if(det==7){
143 /// sectors.push_back(bank.getInt("sector", row));
144 /// pindices.push_back(bank.getShort("pindex", row));
145 /// }
146 /// }
147 ///
148 /// //partbank is a hipo::bank object related to REC::Particle
149 /// //algo_sector_finder is the iguana::clas12::SectorFinder object
150 /// for(auto const& row : partbank.getRowList()) {
151 /// int sector = algo_sector_finder.GetSector(sectors, pindices, row);
152 /// }
153 /// ```
154 ///
155 /// @see ::GetStandardSector, which calls this method for detectors in a priority order
156 ///
157 /// @param sectors list of sectors in a detector bank
158 /// @param pindices list of pindices in a detector bank
159 /// @param pindex_particle index in `REC::Particle` bank for which to get sector
160 /// @returns sector for `pindex_particle` in list, `UNKNOWN_SECTOR` if `pindex_particle` not in inputted list
161 int GetSector(
162 std::vector<int> const& sectors,
163 std::vector<int> const& pindices,
164 int const& pindex_particle) const;
165
166 /// @action_function{scalar creator} for a given particle with index `pindex_particle`, get its sector from
167 /// using the standard method
168 ///
169 /// The following detectors' banks will be searched in order, and once the sector is found for any detector, it is returned:
170 ///
171 /// - `REC::Track`, using `sectors_track` and `pindices_track`
172 /// - `REC::Calorimeter`, using `sectors_cal` and `pindices_cal`
173 /// - `REC::Scintillator`, using `sectors_scint` and `pindices_scint`
174 ///
175 /// @see ::GetSector, which exemplifies using only one bank's lists of `sectors` and `pindices`
176 ///
177 /// @param sectors_track list of sectors in `REC::Track`
178 /// @param pindices_track list of pindices in `REC::Track`
179 /// @param sectors_cal list of sectors in `REC::Calorimeter`
180 /// @param pindices_cal list of pindices in `REC::Calorimeter`
181 /// @param sectors_scint list of sectors in `REC::Scintillator`
182 /// @param pindices_scint list of pindices in `REC::Scintillator`
183 /// @param pindex_particle index in `REC::Particle` bank for which to get sector
184 /// @returns sector for `pindex_particle` in lists, `UNKNOWN_SECTOR` if `pindex_particle` not any of the inputted lists
185 int GetStandardSector(
186 std::vector<int> const& sectors_track,
187 std::vector<int> const& pindices_track,
188 std::vector<int> const& sectors_cal,
189 std::vector<int> const& pindices_cal,
190 std::vector<int> const& sectors_scint,
191 std::vector<int> const& pindices_scint,
192 int const& pindex_particle) const;
193
194 /// @action_function{vector creator} get sectors for all particles, using the standard method
195 ///
196 /// @overloads_scalar
197 ///
198 /// @see ::GetSector, which exemplifies using only one bank's lists of `sectors` and `pindices`
199 ///
200 /// @param sectors_track list of sectors in `REC::Track`
201 /// @param pindices_track list of pindices in `REC::Track`
202 /// @param sectors_cal list of sectors in `REC::Calorimeter`
203 /// @param pindices_cal list of pindices in `REC::Calorimeter`
204 /// @param sectors_scint list of sectors in `REC::Scintillator`
205 /// @param pindices_scint list of pindices in `REC::Scintillator`
206 /// @param pindices_particle the `REC::Particle` list of `pindices`
207 /// @returns list of sectors for each particle with `pindex` in `pindices_particle`
208 std::vector<int> GetStandardSector(
209 std::vector<int> const& sectors_track,
210 std::vector<int> const& pindices_track,
211 std::vector<int> const& sectors_cal,
212 std::vector<int> const& pindices_cal,
213 std::vector<int> const& sectors_scint,
214 std::vector<int> const& pindices_scint,
215 std::vector<int> const& pindices_particle) const;
216
217 /// fill lists of sectors and pindices present in the input bank
218 ///
219 /// @note this is not an action function, but here for convenience
220 ///
221 /// @param bank bank from which to get lists of sectors and pindices
222 /// @param sectors list to fill with sectors in the bank
223 /// @param pindices list to fill with pindices in the bank
224 void GetListsSectorPindex(hipo::bank const& bank, std::vector<int>& sectors, std::vector<int>& pindices) const;
225
226 private:
227
228 /// @brief private implementation of the run function, called by public run functions
229 /// @param [in] particleBank `REC::Particle`
230 /// @param [in] trackBank `REC::Track`
231 /// @param [in] calBank `REC::Calorimeter`
232 /// @param [in] scintBank `REC::Scintillator`
233 /// @param [in] userChargedBank custom bank used to obtain charged-particles' sectors
234 /// @param [in] userNeutralBank custom bank used to obtain neutral-particles' sectors
235 /// @param [out] resultBank the output `REC::Particle::Sector` bank
236 /// @run_function_returns_true
237 bool RunImpl(
238 hipo::bank const* particleBank,
239 hipo::bank const* trackBank,
240 hipo::bank const* calBank,
241 hipo::bank const* scintBank,
242 hipo::bank const* userChargedBank,
243 hipo::bank const* userNeutralBank,
244 hipo::bank* resultBank) const;
245
246 /// `hipo::banklist` index for the particle bank
247 hipo::banklist::size_type b_particle;
248 hipo::banklist::size_type b_track;
249 hipo::banklist::size_type b_calorimeter;
250 hipo::banklist::size_type b_scint;
251 hipo::banklist::size_type b_user_charged;
252 hipo::banklist::size_type b_user_neutral;
253 hipo::banklist::size_type b_result;
254 bool userSpecifiedBank_charged{false};
255 bool userSpecifiedBank_neutral{false};
256
257 // `b_result` bank item indices
258 int i_sector;
259 int i_pindex;
260
261 /// Configuration options
262 std::string o_bankname_charged;
263 std::string o_bankname_neutral;
264
265 // only want sectors from FD detectors
266 std::set<int> const listFDDets{
267 DetectorType::DC,
268 DetectorType::ECAL,
269 DetectorType::FTOF,
270 DetectorType::HTCC,
271 DetectorType::LTCC,
272 DetectorType::RICH};
273 };
274
275 }
276