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