Skip to content

Commit 2bb9e32

Browse files
authored
[Common] RecoDecay: Fix linter errors. Fix includes. Improve documentation. (#12341)
1 parent 3f270dc commit 2bb9e32

File tree

1 file changed

+64
-55
lines changed

1 file changed

+64
-55
lines changed

Common/Core/RecoDecay.h

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,20 @@
1717
#ifndef COMMON_CORE_RECODECAY_H_
1818
#define COMMON_CORE_RECODECAY_H_
1919

20-
// C++ includes
21-
#include <algorithm> // std::find
22-
#include <array> // std::array
23-
#include <cmath> // std::abs, std::sqrt
24-
#include <cstdio>
25-
#include <tuple> // std::apply
26-
#include <utility> // std::move
27-
#include <vector> // std::vector
28-
29-
// ROOT includes
20+
#include <CommonConstants/MathConstants.h>
21+
3022
#include <TMCProcess.h> // for VMC Particle Production Process
3123
#include <TPDGCode.h> // for PDG codes
3224

33-
// O2 includes
34-
#include "CommonConstants/MathConstants.h"
25+
#include <algorithm> // std::find
26+
#include <array> // std::array
27+
#include <cmath> // std::abs, std::sqrt
28+
#include <cstddef> // std::size_t
29+
#include <cstdint> // intX_t
30+
#include <tuple> // std::apply
31+
#include <type_traits> // std::decay_t
32+
#include <utility> // std::move
33+
#include <vector> // std::vector
3534

3635
/// Base class for calculating properties of reconstructed decays
3736
///
@@ -43,11 +42,18 @@
4342

4443
struct RecoDecay {
4544
// mapping of charm-hadron origin type
46-
enum OriginType { None = 0,
47-
Prompt,
48-
NonPrompt };
49-
50-
static constexpr int8_t StatusCodeAfterFlavourOscillation = 92; // decay products after B0(s) flavour oscillation
45+
enum OriginType {
46+
None = 0,
47+
Prompt,
48+
NonPrompt
49+
};
50+
51+
static constexpr int8_t StatusCodeAfterFlavourOscillation{92}; // decay products after B0(s) flavour oscillation
52+
static constexpr int PdgQuarkMax{8}; // largest quark PDG code; o2-linter: disable=pdg/explicit-code (t' does not have a named constant.)
53+
static constexpr int PdgBosonMin{PDG_t::kGluon}; // smallest boson (gauge or H) PDG code
54+
static constexpr int PdgBosonMax{37}; // largest boson (gauge or H) PDG code; o2-linter: disable=pdg/explicit-code (H+ does not have a named constant.)
55+
static constexpr int PdgDivisorMeson{100}; // order of magnitude of the meson PDG codes
56+
static constexpr int PdgDivisorBaryon{1000}; // order of magnitude of the baryon PDG codes
5157

5258
// Auxiliary functions
5359

@@ -110,7 +116,7 @@ struct RecoDecay {
110116

111117
/// Calculates scalar product of vectors.
112118
/// \note Promotes numbers to double to avoid precision loss in float multiplication.
113-
/// \param N dimension
119+
/// \tparam N dimension
114120
/// \param vec1,vec2 vectors
115121
/// \return scalar product
116122
template <std::size_t N, typename T, typename U>
@@ -137,7 +143,7 @@ struct RecoDecay {
137143
}
138144

139145
/// Calculates magnitude squared of a vector.
140-
/// \param N dimension
146+
/// \tparam N dimension
141147
/// \param vec vector
142148
/// \return magnitude squared
143149
template <std::size_t N, typename T>
@@ -435,7 +441,7 @@ struct RecoDecay {
435441
}
436442

437443
/// Calculates invariant mass squared from momenta and masses of several particles (prongs).
438-
/// \param N number of prongs
444+
/// \tparam N number of prongs
439445
/// \param arrMom array of N 3-momentum arrays
440446
/// \param arrMass array of N masses (in the same order as arrMom)
441447
/// \return invariant mass squared
@@ -445,7 +451,7 @@ struct RecoDecay {
445451
std::array<double, 3> momTotal{0., 0., 0.}; // candidate momentum vector
446452
double energyTot{0.}; // candidate energy
447453
for (std::size_t iProng = 0; iProng < N; ++iProng) {
448-
for (std::size_t iMom = 0; iMom < 3; ++iMom) {
454+
for (std::size_t iMom = 0; iMom < 3; ++iMom) { // o2-linter: disable=magic-number ({x, y, z} coordinates)
449455
momTotal[iMom] += arrMom[iProng][iMom];
450456
} // loop over momentum components
451457
energyTot += e(arrMom[iProng], arrMass[iProng]);
@@ -535,6 +541,7 @@ struct RecoDecay {
535541
}
536542

537543
/// Finds the mother of an MC particle by looking for the expected PDG code in the mother chain.
544+
/// \tparam acceptFlavourOscillation switch to accept decays where the mother oscillated (e.g. B0 -> B0bar)
538545
/// \param particlesMC table with MC particles
539546
/// \param particle MC particle
540547
/// \param pdgMother expected mother PDG code
@@ -613,7 +620,7 @@ struct RecoDecay {
613620
}
614621

615622
/// Gets the complete list of indices of final-state daughters of an MC particle.
616-
/// \param checkProcess switch to accept only decay daughters by checking the production process of MC particles
623+
/// \tparam checkProcess switch to accept only decay daughters by checking the production process of MC particles
617624
/// \param particle MC particle
618625
/// \param list vector where the indices of final-state daughters will be added
619626
/// \param arrPdgFinal array of PDG codes of particles to be considered final if found
@@ -686,7 +693,7 @@ struct RecoDecay {
686693
}
687694

688695
/// Checks whether the reconstructed decay candidate is the expected decay.
689-
/// \tparam acceptFlavourOscillation switch to accept flavour oscillastion (i.e. B0 -> B0bar -> D+pi-)
696+
/// \tparam acceptFlavourOscillation switch to accept decays where the mother oscillated (e.g. B0 -> B0bar)
690697
/// \tparam checkProcess switch to accept only decay daughters by checking the production process of MC particles
691698
/// \tparam acceptIncompleteReco switch to accept candidates with only part of the daughters reconstructed
692699
/// \tparam acceptTrackDecay switch to accept candidates with daughter tracks of pions and kaons which decayed
@@ -750,11 +757,11 @@ struct RecoDecay {
750757
auto motherI = particleI.template mothers_first_as<T>();
751758
auto pdgI = std::abs(particleI.pdgCode());
752759
auto pdgMotherI = std::abs(motherI.pdgCode());
753-
if (pdgI == kMuonMinus && pdgMotherI == kPiPlus) {
760+
if (pdgI == PDG_t::kMuonMinus && pdgMotherI == PDG_t::kPiPlus) {
754761
// π → μ
755762
nPiToMuLocal++;
756763
particleI = motherI;
757-
} else if (pdgI == kPiPlus && pdgMotherI == kKPlus) {
764+
} else if (pdgI == PDG_t::kPiPlus && pdgMotherI == PDG_t::kKPlus) {
758765
// K → π
759766
nKaToPiLocal++;
760767
particleI = motherI;
@@ -871,7 +878,8 @@ struct RecoDecay {
871878
}
872879

873880
/// Checks whether the MC particle is the expected one.
874-
/// \param checkProcess switch to accept only decay daughters by checking the production process of MC particles
881+
/// \tparam acceptFlavourOscillation switch to accept decays where the mother oscillated (e.g. B0 -> B0bar)
882+
/// \tparam checkProcess switch to accept only decay daughters by checking the production process of MC particles
875883
/// \param particlesMC table with MC particles
876884
/// \param candidate candidate MC particle
877885
/// \param pdgParticle expected particle PDG code
@@ -890,7 +898,8 @@ struct RecoDecay {
890898
}
891899

892900
/// Check whether the MC particle is the expected one and whether it decayed via the expected decay channel.
893-
/// \param checkProcess switch to accept only decay daughters by checking the production process of MC particles
901+
/// \tparam acceptFlavourOscillation switch to accept decays where the mother oscillated (e.g. B0 -> B0bar)
902+
/// \tparam checkProcess switch to accept only decay daughters by checking the production process of MC particles
894903
/// \param particlesMC table with MC particles
895904
/// \param candidate candidate MC particle
896905
/// \param pdgParticle expected particle PDG code
@@ -1014,7 +1023,7 @@ struct RecoDecay {
10141023
arrayIds.push_back(initVec); // the first vector contains the index of the original particle
10151024
auto pdgParticle = std::abs(particle.pdgCode());
10161025
bool couldBePrompt = false;
1017-
if (pdgParticle / 100 == kCharm || pdgParticle / 1000 == kCharm) {
1026+
if (pdgParticle / PdgDivisorMeson == PDG_t::kCharm || pdgParticle / PdgDivisorBaryon == PDG_t::kCharm) {
10181027
couldBePrompt = true;
10191028
}
10201029
while (arrayIds[-stage].size() > 0) {
@@ -1024,11 +1033,11 @@ struct RecoDecay {
10241033
auto particleMother = particlesMC.rawIteratorAt(iPart - particlesMC.offset());
10251034
if (particleMother.has_mothers()) {
10261035

1027-
// we exit immediately if searchUpToQuark is false and the first mother is a parton (an hadron should never be the mother of a parton)
1036+
// we exit immediately if searchUpToQuark is false and the first mother is a quark or a boson (a hadron should never be the mother of a parton)
10281037
if (!searchUpToQuark) {
10291038
auto mother = particlesMC.rawIteratorAt(particleMother.mothersIds().front() - particlesMC.offset());
10301039
auto pdgParticleIMother = std::abs(mother.pdgCode()); // PDG code of the mother
1031-
if (pdgParticleIMother < 9 || (pdgParticleIMother > 20 && pdgParticleIMother < 38)) {
1040+
if (pdgParticleIMother <= PdgQuarkMax || (pdgParticleIMother >= PdgBosonMin && pdgParticleIMother <= PdgBosonMax)) {
10321041
return OriginType::Prompt;
10331042
}
10341043
}
@@ -1047,31 +1056,31 @@ struct RecoDecay {
10471056

10481057
if (searchUpToQuark) {
10491058
if (idxBhadMothers) {
1050-
if (pdgParticleIMother / 100 == kBottom || // b mesons
1051-
pdgParticleIMother / 1000 == kBottom) // b baryons
1059+
if (pdgParticleIMother / PdgDivisorMeson == PDG_t::kBottom || // b mesons
1060+
pdgParticleIMother / PdgDivisorBaryon == PDG_t::kBottom) // b baryons
10521061
{
10531062
idxBhadMothers->push_back(iMother);
10541063
}
10551064
}
1056-
if (pdgParticleIMother == kBottom) { // b quark
1065+
if (pdgParticleIMother == PDG_t::kBottom) { // b quark
10571066
return OriginType::NonPrompt;
10581067
}
1059-
if (pdgParticleIMother == kCharm) { // c quark
1068+
if (pdgParticleIMother == PDG_t::kCharm) { // c quark
10601069
return OriginType::Prompt;
10611070
}
10621071
} else {
10631072
if (
1064-
(pdgParticleIMother / 100 == kBottom || // b mesons
1065-
pdgParticleIMother / 1000 == kBottom) // b baryons
1073+
(pdgParticleIMother / PdgDivisorMeson == PDG_t::kBottom || // b mesons
1074+
pdgParticleIMother / PdgDivisorBaryon == PDG_t::kBottom) // b baryons
10661075
) {
10671076
if (idxBhadMothers) {
10681077
idxBhadMothers->push_back(iMother);
10691078
}
10701079
return OriginType::NonPrompt;
10711080
}
10721081
if (
1073-
(pdgParticleIMother / 100 == kCharm || // c mesons
1074-
pdgParticleIMother / 1000 == kCharm) // c baryons
1082+
(pdgParticleIMother / PdgDivisorMeson == PDG_t::kCharm || // c mesons
1083+
pdgParticleIMother / PdgDivisorBaryon == PDG_t::kCharm) // c baryons
10751084
) {
10761085
couldBePrompt = true;
10771086
}
@@ -1112,7 +1121,7 @@ struct RecoDecay {
11121121
arrayIds.push_back(initVec); // the first vector contains the index of the original particle
11131122
auto pdgParticle = std::abs(particle.pdgCode());
11141123
bool couldBeCharm = false;
1115-
if (pdgParticle / 100 == kCharm || pdgParticle / 1000 == kCharm) {
1124+
if (pdgParticle / PdgDivisorMeson == PDG_t::kCharm || pdgParticle / PdgDivisorBaryon == PDG_t::kCharm) {
11161125
couldBeCharm = true;
11171126
}
11181127
while (arrayIds[-stage].size() > 0) {
@@ -1122,21 +1131,21 @@ struct RecoDecay {
11221131
auto particleMother = particlesMC.rawIteratorAt(iPart - particlesMC.offset());
11231132
if (particleMother.has_mothers()) {
11241133

1125-
// we break immediately if searchUpToQuark is false and the first mother is a parton (an hadron should never be the mother of a parton)
1134+
// we break immediately if searchUpToQuark is false and the first mother is a quark or a boson (a hadron should never be the mother of a parton)
11261135
if (!searchUpToQuark) {
11271136
auto mother = particlesMC.rawIteratorAt(particleMother.mothersIds().front() - particlesMC.offset());
11281137
auto pdgParticleIMother = std::abs(mother.pdgCode()); // PDG code of the mother
1129-
if (pdgParticleIMother < 9 || (pdgParticleIMother > 20 && pdgParticleIMother < 38)) {
1138+
if (pdgParticleIMother <= PdgQuarkMax || (pdgParticleIMother >= PdgBosonMin && pdgParticleIMother <= PdgBosonMax)) {
11301139
// auto PDGPaticle = std::abs(particleMother.pdgCode());
11311140
if (
1132-
(pdgParticle / 100 == kBottom || // b mesons
1133-
pdgParticle / 1000 == kBottom) // b baryons
1141+
(pdgParticle / PdgDivisorMeson == PDG_t::kBottom || // b mesons
1142+
pdgParticle / PdgDivisorBaryon == PDG_t::kBottom) // b baryons
11341143
) {
11351144
return OriginType::NonPrompt; // beauty
11361145
}
11371146
if (
1138-
(pdgParticle / 100 == kCharm || // c mesons
1139-
pdgParticle / 1000 == kCharm) // c baryons
1147+
(pdgParticle / PdgDivisorMeson == PDG_t::kCharm || // c mesons
1148+
pdgParticle / PdgDivisorBaryon == PDG_t::kCharm) // c baryons
11401149
) {
11411150
return OriginType::Prompt; // charm
11421151
}
@@ -1160,31 +1169,31 @@ struct RecoDecay {
11601169

11611170
if (searchUpToQuark) {
11621171
if (idxBhadMothers) {
1163-
if (pdgParticleIMother / 100 == kBottom || // b mesons
1164-
pdgParticleIMother / 1000 == kBottom) // b baryons
1172+
if (pdgParticleIMother / PdgDivisorMeson == PDG_t::kBottom || // b mesons
1173+
pdgParticleIMother / PdgDivisorBaryon == PDG_t::kBottom) // b baryons
11651174
{
11661175
idxBhadMothers->push_back(iMother);
11671176
}
11681177
}
1169-
if (pdgParticleIMother == kBottom) { // b quark
1170-
return OriginType::NonPrompt; // beauty
1178+
if (pdgParticleIMother == PDG_t::kBottom) { // b quark
1179+
return OriginType::NonPrompt; // beauty
11711180
}
1172-
if (pdgParticleIMother == kCharm) { // c quark
1173-
return OriginType::Prompt; // charm
1181+
if (pdgParticleIMother == PDG_t::kCharm) { // c quark
1182+
return OriginType::Prompt; // charm
11741183
}
11751184
} else {
11761185
if (
1177-
(pdgParticleIMother / 100 == kBottom || // b mesons
1178-
pdgParticleIMother / 1000 == kBottom) // b baryons
1186+
(pdgParticleIMother / PdgDivisorMeson == PDG_t::kBottom || // b mesons
1187+
pdgParticleIMother / PdgDivisorBaryon == PDG_t::kBottom) // b baryons
11791188
) {
11801189
if (idxBhadMothers) {
11811190
idxBhadMothers->push_back(iMother);
11821191
}
11831192
return OriginType::NonPrompt; // beauty
11841193
}
11851194
if (
1186-
(pdgParticleIMother / 100 == kCharm || // c mesons
1187-
pdgParticleIMother / 1000 == kCharm) // c baryons
1195+
(pdgParticleIMother / PdgDivisorMeson == PDG_t::kCharm || // c mesons
1196+
pdgParticleIMother / PdgDivisorBaryon == PDG_t::kCharm) // c baryons
11881197
) {
11891198
couldBeCharm = true;
11901199
}

0 commit comments

Comments
 (0)