NAIA  1.0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
Utils.h
Go to the documentation of this file.
1 #ifndef NAIA_UTILS_H
2 #define NAIA_UTILS_H
3 
4 #include <algorithm>
5 #include <array>
6 #include <limits>
7 #include <map>
8 
10 
11 // templated helper functions
12 #include "Containers/Utils.hpp"
13 
14 // bitmask-able enums declaration
15 namespace NAIA {
16 enum class Category;
17 }
19 
20 namespace NAIA {
21 
30 inline std::vector<std::string> TokenizeString(const std::string &input, const char separator) {
31  std::vector<std::string> result;
32 
33  for (auto iter = cbegin(input);; /*nothing here*/) {
34  auto sepIter = std::find(iter, end(input), separator);
35 
36  result.emplace_back(iter, sepIter);
37 
38  if (sepIter == cend(input))
39  break;
40  iter = std::next(sepIter);
41  }
42 
43  return result;
44 }
45 
54 template <class T> using LayerVariable = std::map<unsigned int, T>;
55 
60 enum class Category {
61  None = 0,
62  HasTof = 1 << 0,
63  HasTrack = 1 << 1,
64  HasEcal = 1 << 2,
65  HasTrd = 1 << 3,
66  HasRich = 1 << 4,
67  HasTofStandalone = 1 << 5,
68  HasTrdStandalone = 1 << 6,
69  Charge1_Trk = 1 << 7,
70  Charge2_Trk = 1 << 8,
71  ChargeGT2_Trk = 1 << 9,
72  Charge1_Tof = 1 << 10,
73  Charge2_Tof = 1 << 11,
74  ChargeGT2_Tof = 1 << 12,
75  Charge1_Trk_St = 1 << 13,
76  Charge2_Trk_St = 1 << 14,
77  ChargeGT2_Trk_St = 1 << 15,
78  Charge1_Tof_St = 1 << 16,
79  Charge2_Tof_St = 1 << 17,
80  ChargeGT2_Tof_St = 1 << 18,
81 };
82 
85 namespace TrTrack {
86 // helper categories to handle charge reconstructions
88 constexpr unsigned int numChargeRecos = 3;
91  STD,
92  HL,
93  YJ,
94 };
96 constexpr std::array<ChargeRecoType, numChargeRecos> recoTypes{ChargeRecoType::STD, ChargeRecoType::HL,
98 
99 // helper category for track z positions
101 constexpr unsigned int numFitPositionHeights = 16;
104  Layer1 = 0,
120 };
121 
123 constexpr std::array<FitPositionHeight, numFitPositionHeights> fitPositionHeights = {
130 
135 constexpr std::array<float, numFitPositionHeights> fitPositionHeightZ = {
136  159.04, 53.05, 29.22, 25.24, 1.706, -2.292, -25.26, -29.25,
137  -136.03, 64.425, 61.325, -62.875, -64.425, 0, -142.732, -159.382};
138 
140 static const std::array<std::string, numFitPositionHeights> fitPositionNames{
141  "Layer1", "Layer2", "Layer3", "Layer4", "Layer5", "Layer6", "Layer7", "Layer8",
142  "Layer9", "TofLayer0", "TofLayer1", "TofLayer2", "TofLayer3", "EcalCOG", "EcalTop", "EcalBottom"};
143 
145 constexpr unsigned int numTrLayers = 9;
146 
148 constexpr std::array<FitPositionHeight, numTrLayers> layerPositionHeights = {
152 
153 // helper categories to handle track spans
155 constexpr unsigned int numSpans = 7;
156 enum Span {
157  NoSpan = -1,
165 };
167 constexpr std::array<Span, numSpans> spanTypes{Span::InnerOnly, Span::InnerL1, Span::InnerL9,
171 static const std::array<std::string, numSpans> spanNames{"InnerOnly", "InnerL1", "InnerL9", "FullSpan",
172  "UpperHalfInner", "LowerHalfInner", "InnerNoMS"};
173 
174 // helper categories to handle track fits
176 constexpr unsigned int numFits = 4;
178 enum Fit {
179  NoFit = -1,
182  GBL,
184 };
186 constexpr std::array<Fit, numFits> fitTypes{Fit::Choutko, Fit::Kalman, Fit::GBL, Fit::KalmanElectron};
188 static const std::array<std::string, numFits> fitNames{"Choutko", "Kalman", "GBL", "KalmanElectron"};
189 
190 // helper categories to handle track geometries
192 constexpr unsigned int numTrGeos = 4;
195 constexpr std::array<TrGeometry, numTrGeos> trGeoTypes{TrGeometry::Default, TrGeometry::InnerOnly, TrGeometry::InnerL1,
198 static const std::array<std::string, numTrGeos> trGeoNames{"Default", "InnerOnly", "InnerL1", "FullSpan"};
199 
200 // helper categories to handle track sides
202 constexpr unsigned int numSides = 2;
204 enum Side { X, Y };
206 constexpr std::array<Side, numSides> sides{Side::X, Side::Y};
208 static const std::array<std::string, numSides> sideNames{"X", "Y"};
209 
210 // helper categories to handle track sides
212 constexpr unsigned int numTrackDistances = 7;
216 constexpr std::array<DistanceFromTrack, numTrackDistances> trackDistances{
220 static const std::array<std::string, numTrackDistances> trackDistanceNames{"OnTrack", "Onemm", "Onecm", "Twocm",
221  "Fivecm", "Tencm", "AllLayer"};
222 
223 } // namespace TrTrack
224 
225 namespace TrdK {
226 
227 // helper categories to handle charge reconstructions
229 constexpr unsigned int numChargeTypes = 3;
235 };
237 constexpr std::array<ChargeType, numChargeTypes> recoTypes{ChargeType::Total, ChargeType::Upper, ChargeType::Lower};
239 static const std::array<std::string, numChargeTypes> recoNames{"Total", "Upper", "Lower"};
240 
241 // helper categories to handle likelihoods
243 constexpr unsigned int numLikelihoodTypes = 3;
247 constexpr std::array<LikelihoodType, numLikelihoodTypes> likelihoodTypes{
250 static const std::array<std::string, numLikelihoodTypes> likelihoodNames{"Electron", "Proton", "Helium"};
251 
252 // helper categories to handle likelihood ratios
254 constexpr unsigned int numLikelihoodRTypes = 3;
257  ep,
258  eHe,
259  pHe,
260 };
262 constexpr std::array<LikelihoodRType, numLikelihoodRTypes> likelihoodRTypes{LikelihoodRType::ep, LikelihoodRType::eHe,
265 static const std::array<std::string, numLikelihoodRTypes> likelihoodRNames{"ep", "eHe", "pHe"};
266 
267 // helper categories to handle ontrack/offtrack variables
269 constexpr unsigned int numQualTypes = 2;
271 enum QualType {
274 };
276 constexpr std::array<QualType, numQualTypes> qualTypes{QualType::OnTrack, QualType::OffTrack};
278 static const std::array<std::string, numQualTypes> qualNames{"OnTrack", "OffTrack"};
279 
280 } // namespace TrdK
281 
282 namespace Ecal {
283 // helper categories to handle energy reconstructions
285 constexpr unsigned int numEnergyRecos = 5;
287 // clang-format off
294 };
295 // clang-format on
296 
298 constexpr std::array<EnergyRecoType, numEnergyRecos> recoTypes{
302 static const std::array<std::string, numEnergyRecos> recoNames{"EnergyD", "EnergyE", "EnergyCorrEneE_E",
303  "EnergyCorrEne2017", "EcalKEle"};
304 
305 // helper categories to handle WeiWei's likelihoods
307 constexpr unsigned int numLikelihoodTypes = 2;
311 constexpr std::array<LikelihoodType, numLikelihoodTypes> likelihoodTypeNames{LikelihoodType::Integral,
313 
314 // helper categories to handle BDT types
316 constexpr unsigned int numBDTTypes = 4;
320 constexpr std::array<BDTType, numBDTTypes> BDTTypes{BDTType::v5std, BDTType::v5ada, BDTType::v7std, BDTType::v7ada};
322 static const std::array<std::string, numBDTTypes> BDTNames{"v5std", "v5ada", "v7std", "v7ada"};
323 
324 } // namespace Ecal
325 
326 namespace Tof {
327 
328 const float tofRefZ = 160.;
329 
330 // helper categories to handle charge reconstructions
332 constexpr unsigned int numChargeTypes = 3;
338 };
340 constexpr std::array<ChargeType, numChargeTypes> recoTypes{ChargeType::Total, ChargeType::Upper, ChargeType::Lower};
342 static const std::array<std::string, numChargeTypes> recoNames{"Total", "Upper", "Lower"};
343 
344 // helper categories to handle beta reconstructions
346 constexpr unsigned int numBetaTypes = 2;
348 enum BetaType {
351 };
353 constexpr std::array<BetaType, numBetaTypes> betaTypes{BetaType::BetaH, BetaType::Evgeni};
355 static const std::array<std::string, numBetaTypes> betaNames{"BetaH", "Evgeni"};
356 
357 // helper categories to handle beta clusters
359 constexpr unsigned int numBetaClusterTypes = 2;
363 constexpr std::array<BetaClusterType, numBetaClusterTypes> betaClusterTypes{BetaClusterType::OnTime,
366 static const std::array<std::string, numBetaClusterTypes> betaClusterTypeNames{"OnTime", "OffTime"};
367 
368 } // namespace Tof
369 
370 namespace MCTruth {
372 constexpr unsigned int numMCHeights = 13;
376 constexpr std::array<MCHeight, numMCHeights> MCHeights{MCHeight::GenerationPoint,
377  MCHeight::L1,
379  MCHeight::L2,
380  MCHeight::L3,
381  MCHeight::L4,
382  MCHeight::L5,
383  MCHeight::L6,
384  MCHeight::L7,
385  MCHeight::L8,
388  MCHeight::L9};
389 
391 constexpr std::array<float, numMCHeights> MCHeightsZ{std::numeric_limits<float>::max(),
392  159.04,
393  64.425,
394  53.05,
395  29.22,
396  25.24,
397  1.706,
398  -2.292,
399  -25.26,
400  -29.25,
401  -62.875,
402  -71.87,
403  -135.03};
404 
405 } // namespace MCTruth
406 
407 namespace Rich {
408 // helper categories to handle beta reconstructions
410 enum RichMeasType { NONE = 0, NaF, Agl };
411 
413 constexpr unsigned int numBetaTypes = 4;
415 enum BetaType {
416  CIEMAT, //< Refit and corrected
417  SIMPLE, //< Reconstructed velocity using only hits (no charge)
418  REFIT, //<Beta estimate taking into account the number of photoelectrons for each hit
419  LIP //< Beta with LIP standalone algo
420 };
422 constexpr std::array<BetaType, numBetaTypes> betaTypes{BetaType::CIEMAT, BetaType::SIMPLE, BetaType::REFIT,
423  BetaType::LIP};
425 static const std::array<std::string, numBetaTypes> betaNames{"CIEMAT", "SIMPLE", "REFIT", "LIP"};
426 } // namespace Rich
427 
428 } // namespace NAIA
429 
430 #endif
static const std::array< std::string, numQualTypes > qualNames
Definition: Utils.h:278
constexpr std::array< ChargeRecoType, numChargeRecos > recoTypes
Definition: Utils.h:96
constexpr unsigned int numMCHeights
Definition: Utils.h:372
This event is classified as charge 1 according to tracker standalone (0.5 &lt; Q &lt; 1.5)
Tof standalone data is available for this event.
This event is classified as charge 1 according to tof standalone (0.5 &lt; Q &lt; 1.5)
LikelihoodRType
Definition: Utils.h:256
This event is classified as charge 2 according to tof (1.5 &lt; Q &lt; 2.5)
static const std::array< std::string, numChargeTypes > recoNames
Definition: Utils.h:239
TrTrack data is available for this event.
Genfint General Broken Lines track fit.
Definition: Utils.h:182
Hu Liu reconstruction.
Definition: Utils.h:92
This event is classified as charge &gt;2 according to tracker standalone (Q &gt; 2.5)
Track constructed with the upper part of the inner tracker (layers 2 to 6)
Definition: Utils.h:162
constexpr unsigned int numTrackDistances
Definition: Utils.h:212
Rich data is available for this event.
static const std::array< std::string, numTrackDistances > trackDistanceNames
Definition: Utils.h:220
static const std::array< std::string, numLikelihoodTypes > likelihoodNames
Definition: Utils.h:250
FitPositionHeight
Definition: Utils.h:103
constexpr std::array< BetaType, numBetaTypes > betaTypes
Definition: Utils.h:353
constexpr unsigned int numTrGeos
Definition: Utils.h:192
const float tofRefZ
Definition: Utils.h:328
Track constructed with the upper part of the inner tracker (layers 3 to 8)
Definition: Utils.h:163
proton/helium likelihood ratio
Definition: Utils.h:259
constexpr std::array< Span, numSpans > spanTypes
Definition: Utils.h:167
constexpr std::array< QualType, numQualTypes > qualTypes
Definition: Utils.h:276
Category
Definition: Utils.h:60
This event is classified as charge &gt;2 according to tof (Q &gt; 2.5)
TRD standalone data is available for this event.
LikelihoodType
Definition: Utils.h:245
constexpr std::array< MCHeight, numMCHeights > MCHeights
Definition: Utils.h:376
constexpr std::array< FitPositionHeight, numTrLayers > layerPositionHeights
Definition: Utils.h:148
constexpr std::array< float, numMCHeights > MCHeightsZ
Definition: Utils.h:391
Ecal energy (W. Xu 3D reconstruction)
Definition: Utils.h:293
static const std::array< std::string, numBetaClusterTypes > betaClusterTypeNames
Definition: Utils.h:366
This event is classified as charge 1 according to tracker (0.5 &lt; Q &lt; 1.5)
electron/helium likelihood ratio
Definition: Utils.h:258
Track constructed with inner tracker + layer 1 hits.
Definition: Utils.h:159
BetaType
Definition: Utils.h:348
constexpr std::array< float, numFitPositionHeights > fitPositionHeightZ
Definition: Utils.h:135
static const std::array< std::string, numTrGeos > trGeoNames
Definition: Utils.h:198
static const std::array< std::string, numSides > sideNames
Definition: Utils.h:208
Charge estimated using the upper half of the TRD.
Definition: Utils.h:233
static const std::array< std::string, numFits > fitNames
Definition: Utils.h:188
constexpr unsigned int numBetaTypes
Definition: Utils.h:346
RichMeasType
Definition: Utils.h:410
constexpr unsigned int numQualTypes
Definition: Utils.h:269
constexpr std::array< LikelihoodRType, numLikelihoodRTypes > likelihoodRTypes
Definition: Utils.h:262
constexpr unsigned int numFits
Definition: Utils.h:176
constexpr unsigned int numFitPositionHeights
Definition: Utils.h:101
std::map< unsigned int, T > LayerVariable
Definition: Utils.h:54
EnergyRecoType
Definition: Utils.h:288
Hits laying off the TRD track (all the rest)
Definition: Utils.h:273
ChargeRecoType
Definition: Utils.h:90
ChargeType
Definition: Utils.h:334
static const std::array< std::string, numLikelihoodRTypes > likelihoodRNames
Definition: Utils.h:265
constexpr std::array< Fit, numFits > fitTypes
Definition: Utils.h:186
constexpr unsigned int numLikelihoodTypes
Definition: Utils.h:243
This event is classified as charge &gt;2 according to tof standalone (Q &gt; 2.5)
Ecal data is available for this event.
TRD data is available for this event.
static const std::array< std::string, numBDTTypes > BDTNames
Definition: Utils.h:322
Track constructed with inner tracker + layer9 hits.
Definition: Utils.h:160
constexpr std::array< Side, numSides > sides
Definition: Utils.h:206
GenFit kalman filter track fit.
Definition: Utils.h:181
This event is classified as charge 1 according to tof (0.5 &lt; Q &lt; 1.5)
static const std::array< std::string, numFitPositionHeights > fitPositionNames
Definition: Utils.h:140
Ecal energy (2017 reconstruction)
Definition: Utils.h:292
constexpr unsigned int numChargeRecos
Definition: Utils.h:88
constexpr unsigned int numBDTTypes
Definition: Utils.h:316
Track constructed with all available hits (inner tracker + layer 1 + layer 9)
Definition: Utils.h:161
This event is classified as charge 2 according to tracker (1.5 &lt; Q &lt; 2.5)
This event is classified as charge 2 according to tracker standalone (1.5 &lt; Q &lt; 2.5)
IHEP reconstruction.
Definition: Utils.h:349
LikelihoodType
Definition: Utils.h:309
Ecal energy (standard reconstruction)
Definition: Utils.h:290
Total deposited energy in Ecal.
Definition: Utils.h:289
constexpr unsigned int numEnergyRecos
Definition: Utils.h:285
Charge estimated using the whole TRD.
Definition: Utils.h:232
ChargeType
Definition: Utils.h:231
constexpr std::array< LikelihoodType, numLikelihoodTypes > likelihoodTypeNames
Definition: Utils.h:311
constexpr unsigned int numBetaClusterTypes
Definition: Utils.h:359
constexpr std::array< LikelihoodType, numLikelihoodTypes > likelihoodTypes
Definition: Utils.h:247
constexpr std::array< BetaClusterType, numBetaClusterTypes > betaClusterTypes
Definition: Utils.h:363
std::vector< std::string > TokenizeString(const std::string &input, const char separator)
Utility function that splits a string according to the provided separator.
Definition: Utils.h:30
DistanceFromTrack
Definition: Utils.h:214
constexpr unsigned int numChargeTypes
Definition: Utils.h:229
This event is classified as charge &gt;2 according to tracker (Q &gt; 2.5)
Track constructed without correcting for multiple scattering.
Definition: Utils.h:164
GenFit kalman filter track fit assuming electron mass.
Definition: Utils.h:183
Ecal energy (electron hypothesys, Using different methods to recover anode efficiency, rear leakage, lateral leakage and temperature effects)
Definition: Utils.h:291
constexpr unsigned int numTrLayers
Definition: Utils.h:145
constexpr std::array< DistanceFromTrack, numTrackDistances > trackDistances
Definition: Utils.h:216
NAIAChain::EventItr end(NAIAChain &chain)
Definition: NAIAChain.h:298
BetaClusterType
Definition: Utils.h:361
constexpr std::array< TrGeometry, numTrGeos > trGeoTypes
Definition: Utils.h:195
electron/proton likelihood ratio
Definition: Utils.h:257
static const std::array< std::string, numBetaTypes > betaNames
Definition: Utils.h:355
Yi Jia reconstruction.
Definition: Utils.h:93
Track constructed with only inner tracker hits.
Definition: Utils.h:158
static const std::array< std::string, numSpans > spanNames
Definition: Utils.h:171
This event is classified as charge 2 according to tof standalone (1.5 &lt; Q &lt; 2.5)
constexpr unsigned int numSpans
Definition: Utils.h:155
constexpr unsigned int numLikelihoodRTypes
Definition: Utils.h:254
Standard tracker charge reconstruction.
Definition: Utils.h:91
Tof data is available for this event.
constexpr std::array< FitPositionHeight, numFitPositionHeights > fitPositionHeights
Definition: Utils.h:123
constexpr std::array< BDTType, numBDTTypes > BDTTypes
Definition: Utils.h:320
#define NAIA_ENABLE_BITMASK_OPERATORS(x)
Definition: bitmask.h:15
standard track fit
Definition: Utils.h:180
Charge estimated using the lower half of the TRD.
Definition: Utils.h:234
constexpr unsigned int numSides
Definition: Utils.h:202