Skip to content

Commit 09d9d99

Browse files
authored
[PWGHF] Utils: Fix and improve type safety, const correctness, readability. (#12575)
1 parent c8b8dc1 commit 09d9d99

27 files changed

+348
-299
lines changed

PWGHF/Core/CentralityEstimation.h

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,53 +59,53 @@ concept hasNTracksPVCent = requires(T collision) {
5959
/// Evaluate centrality/multiplicity percentile using FT0A estimator
6060
/// \param candidate is candidate
6161
/// \return centrality/multiplicity percentile of the collision
62-
template <hasFT0ACent Coll>
63-
float getCentralityColl(const Coll& collision)
62+
template <hasFT0ACent TCollision>
63+
float getCentralityColl(const TCollision& collision)
6464
{
6565
return collision.centFT0A();
6666
}
6767

6868
/// Evaluate centrality/multiplicity percentile using FT0C estimator
6969
/// \param candidate is candidate
7070
/// \return centrality/multiplicity percentile of the collision
71-
template <hasFT0CCent Coll>
72-
float getCentralityColl(const Coll& collision)
71+
template <hasFT0CCent TCollision>
72+
float getCentralityColl(const TCollision& collision)
7373
{
7474
return collision.centFT0C();
7575
}
7676

7777
/// Evaluate centrality/multiplicity percentile using FT0M estimator
7878
/// \param candidate is candidate
7979
/// \return centrality/multiplicity percentile of the collision
80-
template <hasFT0MCent Coll>
81-
float getCentralityColl(const Coll& collision)
80+
template <hasFT0MCent TCollision>
81+
float getCentralityColl(const TCollision& collision)
8282
{
8383
return collision.centFT0M();
8484
}
8585

8686
/// Evaluate centrality/multiplicity percentile using FV0A estimator
8787
/// \param candidate is candidate
8888
/// \return centrality/multiplicity percentile of the collision
89-
template <hasFV0ACent Coll>
90-
float getCentralityColl(const Coll& collision)
89+
template <hasFV0ACent TCollision>
90+
float getCentralityColl(const TCollision& collision)
9191
{
9292
return collision.centFV0A();
9393
}
9494

9595
/// Evaluate centrality/multiplicity percentile using NTracksPV estimator
9696
/// \param candidate is candidate
9797
/// \return centrality/multiplicity percentile of the collision
98-
template <hasNTracksPVCent Coll>
99-
float getCentralityColl(const Coll& collision)
98+
template <hasNTracksPVCent TCollision>
99+
float getCentralityColl(const TCollision& collision)
100100
{
101101
return collision.centNTPV();
102102
}
103103

104104
/// Default case if no centrality/multiplicity estimator is provided
105105
/// \param candidate is candidate
106106
/// \return dummy value for centrality/multiplicity percentile of the collision
107-
template <typename Coll>
108-
float getCentralityColl(const Coll&)
107+
template <typename TCollision>
108+
float getCentralityColl(const TCollision&)
109109
{
110110
return 105.0f;
111111
}
@@ -114,36 +114,36 @@ float getCentralityColl(const Coll&)
114114
/// \param collision is the collision with the centrality information
115115
/// \param centEstimator integer to select the centrality estimator
116116
/// \return collision centrality
117-
template <typename Coll>
118-
float getCentralityColl(const Coll& collision, int centEstimator)
117+
template <typename TCollision>
118+
float getCentralityColl(const TCollision& collision, const int centEstimator)
119119
{
120120
switch (centEstimator) {
121121
case CentralityEstimator::FT0A:
122-
if constexpr (hasFT0ACent<Coll>) {
122+
if constexpr (hasFT0ACent<TCollision>) {
123123
return collision.centFT0A();
124124
}
125125
LOG(fatal) << "Collision does not have centFT0A().";
126126
break;
127127
case CentralityEstimator::FT0C:
128-
if constexpr (hasFT0CCent<Coll>) {
128+
if constexpr (hasFT0CCent<TCollision>) {
129129
return collision.centFT0C();
130130
}
131131
LOG(fatal) << "Collision does not have centFT0C().";
132132
break;
133133
case CentralityEstimator::FT0M:
134-
if constexpr (hasFT0MCent<Coll>) {
134+
if constexpr (hasFT0MCent<TCollision>) {
135135
return collision.centFT0M();
136136
}
137137
LOG(fatal) << "Collision does not have centFT0M().";
138138
break;
139139
case CentralityEstimator::FV0A:
140-
if constexpr (hasFV0ACent<Coll>) {
140+
if constexpr (hasFV0ACent<TCollision>) {
141141
return collision.centFV0A();
142142
}
143143
LOG(fatal) << "Collision does not have centFV0A().";
144144
break;
145145
default:
146-
LOG(fatal) << "Centrality estimator not valid. Possible values are V0A, T0M, T0A, T0C.";
146+
LOG(fatal) << "Centrality estimator not valid. See CentralityEstimator for valid values.";
147147
break;
148148
}
149149
return -999.f;
@@ -152,13 +152,14 @@ float getCentralityColl(const Coll& collision, int centEstimator)
152152
/// \brief Function to get MC collision centrality
153153
/// \param collSlice collection of reconstructed collisions associated to a generated one
154154
/// \return generated MC collision centrality
155-
template <typename CCs>
156-
float getCentralityGenColl(CCs const& collSlice)
155+
template <typename TCollisions>
156+
float getCentralityGenColl(TCollisions const& collSlice)
157157
{
158-
float centrality{-1};
159-
float multiplicity{0.f};
158+
using TMult = uint16_t; // type of numContrib
159+
float centrality{-1.f};
160+
TMult multiplicity{};
160161
for (const auto& collision : collSlice) {
161-
float collMult = collision.numContrib();
162+
const TMult collMult = collision.numContrib();
162163
if (collMult > multiplicity) {
163164
centrality = getCentralityColl(collision);
164165
multiplicity = collMult;
@@ -171,13 +172,14 @@ float getCentralityGenColl(CCs const& collSlice)
171172
/// \param collSlice collection of reconstructed collisions associated to a generated one
172173
/// \param centEstimator integer to select the centrality estimator
173174
/// \return generated MC collision centrality
174-
template <typename CCs>
175-
float getCentralityGenColl(CCs const& collSlice, int centEstimator)
175+
template <typename TCollisions>
176+
float getCentralityGenColl(TCollisions const& collSlice, const int centEstimator)
176177
{
177-
float centrality{-1};
178-
float multiplicity{0.f};
178+
using TMult = uint16_t; // type of numContrib
179+
float centrality{-1.f};
180+
TMult multiplicity{};
179181
for (const auto& collision : collSlice) {
180-
float collMult = collision.numContrib();
182+
const TMult collMult = collision.numContrib();
181183
if (collMult > multiplicity) {
182184
centrality = getCentralityColl(collision, centEstimator);
183185
multiplicity = collMult;

PWGHF/Core/DecayChannels.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ namespace o2::hf_decay
3030
// - HF cascades to LF cascades (Ωc0/Ξc0 → Ξ+ π−, Ξc+ → Ξ+ π− π+)
3131
// - Σc
3232

33+
using HfDecayChannel = int8_t;
34+
3335
namespace hf_cand_2prong
3436
{
3537
/// @brief 2-prong candidates: main channels
36-
enum DecayChannelMain : int8_t {
38+
enum DecayChannelMain : HfDecayChannel {
3739
// D0
3840
D0ToPiK = 1, // π+ K−
3941
D0ToPiKPi0 = 2, // π+ K− π0
@@ -47,7 +49,7 @@ enum DecayChannelMain : int8_t {
4749
NChannelsMain = JpsiToMuMu // last channel
4850
};
4951
/// @brief 2-prong candidates: resonant channels
50-
enum DecayChannelResonant : int8_t {
52+
enum DecayChannelResonant : HfDecayChannel {
5153
// D0
5254
D0ToRhoplusPi = 1, // ρ+ π−
5355
D0ToRhoplusK = 2, // ρ+ K−
@@ -61,7 +63,7 @@ enum DecayChannelResonant : int8_t {
6163
namespace hf_cand_3prong
6264
{
6365
/// @brief 3-prong candidates: main channels
64-
enum DecayChannelMain : int8_t {
66+
enum DecayChannelMain : HfDecayChannel {
6567
// D+
6668
DplusToPiKPi = 1, // π+ K− π+
6769
DplusToPiKPiPi0 = 2, // π+ K− π+ π0
@@ -94,7 +96,7 @@ enum DecayChannelMain : int8_t {
9496
NChannelsMain = XicToSPiPi // last channel
9597
};
9698
/// @brief 3-prong candidates: resonant channels
97-
enum DecayChannelResonant : int8_t {
99+
enum DecayChannelResonant : HfDecayChannel {
98100
// D+
99101
DplusToPhiPi = 1, // φ π+
100102
DplusToKstar0K = 2, // anti-K*0 K+
@@ -136,7 +138,7 @@ enum DecayChannelResonant : int8_t {
136138
namespace hf_cand_dstar
137139
{
138140
/// @brief D*+ candidates: main channels
139-
enum DecayChannelMain : int8_t {
141+
enum DecayChannelMain : HfDecayChannel {
140142
// D*+
141143
DstarToPiKPi = 1, // π+ K− π+ (from [(D0 → π+ K−) π+])
142144
DstarToPiKPiPi0 = 2, // π+ K− π+ π0 (from [(D0 → π+ K− π0) π+] or [(D+ → π+ K− π+) π0])
@@ -148,7 +150,7 @@ enum DecayChannelMain : int8_t {
148150
namespace hf_cand_beauty
149151
{
150152
/// @brief beauty candidates: main channels
151-
enum DecayChannelMain : int8_t {
153+
enum DecayChannelMain : HfDecayChannel {
152154
// B0
153155
B0ToDminusPi = 1, // D− π+
154156
B0ToDminusPiPi0 = 2, // D− π+ π0
@@ -176,7 +178,7 @@ enum DecayChannelMain : int8_t {
176178
NChannelsMain = B0ToDsPi // last channel
177179
};
178180
/// @brief beauty candidates: resonant channels
179-
enum DecayChannelResonant : int8_t {
181+
enum DecayChannelResonant : HfDecayChannel {
180182
// B0
181183
B0ToDminusRhoplus = 1, // D− ρ+
182184
B0ToDstarminusPi = 2, // D*− π+
@@ -195,7 +197,7 @@ enum DecayChannelResonant : int8_t {
195197
NChannelsResonant = BplusToDstar0Pi // last channel
196198
};
197199
/// @brief beauty candidates: beauty to J/ψ decay channels
198-
enum DecayChannelToJpsiMain : int8_t {
200+
enum DecayChannelToJpsiMain : HfDecayChannel {
199201
// B0
200202
B0ToJpsiPiK = 1, // J/ψ π− K+
201203
// Bs0
@@ -210,7 +212,7 @@ enum DecayChannelToJpsiMain : int8_t {
210212
NChannelsToJpsiMain = BcToJpsiPi // last channel
211213
};
212214
/// @brief beauty candidates: beauty to J/ψ resonant decay channels
213-
enum DecayChannelToJpsiResonant : int8_t {
215+
enum DecayChannelToJpsiResonant : HfDecayChannel {
214216
// B0
215217
B0ToJpsiKstar0 = 1, // J/ψ K*0(892)
216218
// Bs0
@@ -223,7 +225,7 @@ enum DecayChannelToJpsiResonant : int8_t {
223225
namespace hf_cand_reso
224226
{
225227
/// @brief resonance candidates: main channels
226-
enum DecayChannelMain : int8_t {
228+
enum DecayChannelMain : HfDecayChannel {
227229
// D1(2420)0
228230
D1zeroToDstarPi = 1, // D*+ π-
229231
// D2*(2460)0

PWGHF/D2H/DataModel/ReducedDataModel.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ namespace aod
5050
{
5151
namespace hf_reduced_collision
5252
{
53-
DECLARE_SOA_COLUMN(Bz, bz, float); //! Magnetic field in z-direction
54-
DECLARE_SOA_COLUMN(HfCollisionRejectionMap, hfCollisionRejectionMap, uint32_t); //! Bitmask with failed selection criteria
53+
DECLARE_SOA_COLUMN(Bz, bz, float); //! Magnetic field in z-direction
54+
DECLARE_SOA_COLUMN(HfCollisionRejectionMap, hfCollisionRejectionMap, o2::hf_evsel::HfCollisionRejectionMask); //! Bitmask with failed selection criteria
5555
// keep track of the number of studied events (for normalization purposes)
5656
DECLARE_SOA_COLUMN(OriginalCollisionCount, originalCollisionCount, int); //! Size of COLLISION table processed
5757
DECLARE_SOA_COLUMN(ZvtxSelectedCollisionCount, zvtxSelectedCollisionCount, int); //! Number of COLLISIONS with |zvtx| < zvtxMax
@@ -1235,7 +1235,7 @@ DECLARE_SOA_COLUMN(Sign, sign, int8_t); //!
12351235
DECLARE_SOA_COLUMN(ItsNClsSoftPi, itsNClsSoftPi, int); //! minimum value of number of ITS clusters for the decay daughter tracks
12361236
DECLARE_SOA_COLUMN(TpcNClsCrossedRowsSoftPi, tpcNClsCrossedRowsSoftPi, int); //! minimum value of number of TPC crossed rows for the decay daughter tracks
12371237
DECLARE_SOA_COLUMN(TpcChi2NClSoftPi, tpcChi2NClSoftPi, float); //! maximum value of TPC chi2 for the decay daughter tracks
1238-
DECLARE_SOA_DYNAMIC_COLUMN(Px, px, //!
1238+
DECLARE_SOA_DYNAMIC_COLUMN(Px, px, //!
12391239
[](float pxProng0, float pxProng1, float pxProng2) -> float { return 1.f * pxProng0 + 1.f * pxProng1 + 1.f * pxProng2; });
12401240
DECLARE_SOA_DYNAMIC_COLUMN(Py, py, //!
12411241
[](float pyProng0, float pyProng1, float pyProng2) -> float { return 1.f * pyProng0 + 1.f * pyProng1 + 1.f * pyProng2; });
@@ -1447,16 +1447,16 @@ DECLARE_SOA_COLUMN(InvMassProng1, invMassProng1, float); //! Invariant Mass of V
14471447
DECLARE_SOA_COLUMN(Sign, sign, int8_t); //! Sign of the Resonance candidate
14481448
DECLARE_SOA_COLUMN(IsWrongSign, isWrongSign, int8_t); //! Flag for wrong sign of the Resonance candidate, 1 = wrong sign, 0 = right sign
14491449

1450-
DECLARE_SOA_COLUMN(FlagMcMatchRec, flagMcMatchRec, int8_t); // flag for resonance decay channel classification reconstruction level
1451-
DECLARE_SOA_COLUMN(FlagMcMatchRecD, flagMcMatchRecD, int8_t); // flag for D meson bachelor decay channel classification reconstruction level
1452-
DECLARE_SOA_COLUMN(FlagMcMatchChanD, flagMcMatchChanD, int8_t); // flag for D meson resonant channel classification reconstruction level
1453-
DECLARE_SOA_COLUMN(FlagMcMatchGen, flagMcMatchGen, int8_t); // flag for decay channel classification generator level
1454-
DECLARE_SOA_COLUMN(DebugMcRec, debugMcRec, uint16_t); // debug flag for mis-association at reconstruction level
1455-
DECLARE_SOA_COLUMN(Origin, origin, int8_t); // Flag for origin of MC particle 1=promt, 2=FD
1456-
DECLARE_SOA_COLUMN(SignD0, signD0, int8_t); // Sign of the D0 in the channels with D* -> D0 pi, needed in case of non-matched D*
1457-
DECLARE_SOA_COLUMN(PtGen, ptGen, float); // Pt at generation level in GeV/c
1458-
DECLARE_SOA_COLUMN(InvMassGen, invMassGen, float); //! Invariant mass at generation level in GeV/c2
1459-
DECLARE_SOA_DYNAMIC_COLUMN(Pt, pt, //!
1450+
DECLARE_SOA_COLUMN(FlagMcMatchRec, flagMcMatchRec, int8_t); // flag for resonance decay channel classification reconstruction level
1451+
DECLARE_SOA_COLUMN(FlagMcMatchRecD, flagMcMatchRecD, int8_t); // flag for D meson bachelor decay channel classification reconstruction level
1452+
DECLARE_SOA_COLUMN(FlagMcMatchChanD, flagMcMatchChanD, int8_t); // flag for D meson resonant channel classification reconstruction level
1453+
DECLARE_SOA_COLUMN(FlagMcMatchGen, flagMcMatchGen, int8_t); // flag for decay channel classification generator level
1454+
DECLARE_SOA_COLUMN(DebugMcRec, debugMcRec, uint16_t); // debug flag for mis-association at reconstruction level
1455+
DECLARE_SOA_COLUMN(Origin, origin, int8_t); // Flag for origin of MC particle 1=promt, 2=FD
1456+
DECLARE_SOA_COLUMN(SignD0, signD0, int8_t); // Sign of the D0 in the channels with D* -> D0 pi, needed in case of non-matched D*
1457+
DECLARE_SOA_COLUMN(PtGen, ptGen, float); // Pt at generation level in GeV/c
1458+
DECLARE_SOA_COLUMN(InvMassGen, invMassGen, float); //! Invariant mass at generation level in GeV/c2
1459+
DECLARE_SOA_DYNAMIC_COLUMN(Pt, pt, //!
14601460
[](float pxProng0, float pxProng1, float pyProng0, float pyProng1) -> float { return RecoDecay::pt((1.f * pxProng0 + 1.f * pxProng1), (1.f * pyProng0 + 1.f * pyProng1)); });
14611461
DECLARE_SOA_DYNAMIC_COLUMN(PtProng0, ptProng0, //!
14621462
[](float pxProng0, float pyProng0) -> float { return RecoDecay::pt(pxProng0, pyProng0); });

PWGHF/D2H/TableProducer/dataCreatorCharmHadPiReduced.cxx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ struct HfDataCreatorCharmHadPiReduced {
10251025
{
10261026
registry.fill(HIST("hEvents"), 1 + Event::Processed);
10271027
float centrality = -1.f;
1028-
auto hfRejMap = hfEvSel.getHfCollisionRejectionMask<true, o2::hf_centrality::CentralityEstimator::None, aod::BCsWithTimestamps>(collision, centrality, ccdb, registry);
1028+
const auto hfRejMap = hfEvSel.getHfCollisionRejectionMask<true, o2::hf_centrality::CentralityEstimator::None, aod::BCsWithTimestamps>(collision, centrality, ccdb, registry);
10291029
if (configs.skipRejectedCollisions && hfRejMap != 0) {
10301030
return;
10311031
}
@@ -1498,15 +1498,16 @@ struct HfDataCreatorCharmHadPiReduced {
14981498
// Check event selection
14991499
float centDummy{-1.f}, centFT0C{-1.f}, centFT0M{-1.f};
15001500
const auto collSlice = collisions.sliceBy(preslices.colPerMcCollision, mcCollision.globalIndex());
1501-
auto hfRejMap = hfEvSelMc.getHfMcCollisionRejectionMask<BCsInfo, o2::hf_centrality::CentralityEstimator::None>(mcCollision, collSlice, centDummy);
1501+
const auto hfRejMap = hfEvSelMc.getHfMcCollisionRejectionMask<BCsInfo, o2::hf_centrality::CentralityEstimator::None>(mcCollision, collSlice, centDummy);
15021502
if (configs.skipRejectedCollisions && hfRejMap != 0) {
15031503
return;
15041504
}
15051505

15061506
// get centrality
1507-
float multiplicity{0.f};
1507+
using TMult = uint16_t; // type of numContrib
1508+
TMult multiplicity{};
15081509
for (const auto& collision : collSlice) {
1509-
float collMult = collision.numContrib();
1510+
const TMult collMult = collision.numContrib();
15101511
if (collMult > multiplicity) {
15111512
centFT0C = collision.centFT0C();
15121513
centFT0M = collision.centFT0M();

PWGHF/D2H/TableProducer/dataCreatorCharmResoReduced.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,8 @@ struct HfDataCreatorCharmResoReduced {
830830
CCand const& candCharmBach,
831831
BBachTr const& bachelorTrack,
832832
Tr const& tracks,
833-
int& indexHfCandCharm,
834-
int64_t& indexCandTrBach)
833+
const int64_t indexHfCandCharm,
834+
const int64_t indexCandTrBach)
835835
{
836836
std::vector<typename Tr::iterator> vecDaughtersReso{};
837837
int8_t sign{0}, nKinkedTracks{0}, origin{0}, flagCharmBach{0}, flagCharmBachInterm{0}, flagTrack{0}, flagReso{0};
@@ -992,7 +992,7 @@ struct HfDataCreatorCharmResoReduced {
992992
{
993993
// helpers for ReducedTables filling
994994
float centrality = -1.f;
995-
uint16_t hfRejMap = hfEvSel.getHfCollisionRejectionMask<true, o2::hf_centrality::CentralityEstimator::None, BCs>(collision, centrality, ccdb, registry);
995+
const auto hfRejMap = hfEvSel.getHfCollisionRejectionMask<true, o2::hf_centrality::CentralityEstimator::None, BCs>(collision, centrality, ccdb, registry);
996996
if (rejectCollisionsWithBadEvSel && hfRejMap != 0) {
997997
return;
998998
}
@@ -1546,7 +1546,7 @@ struct HfDataCreatorCharmResoReduced {
15461546
const auto mcParticlesPerMcColl = mcParticles.sliceBy(mcParticlesPerMcCollision, mcCollision.globalIndex());
15471547
// Slice the collisions table to get the collision info for the current MC collision
15481548
float centrality{-1.f};
1549-
uint16_t rejectionMask{0};
1549+
o2::hf_evsel::HfCollisionRejectionMask rejectionMask{};
15501550
int nSplitColl = 0;
15511551
const auto collSlice = collInfos.sliceBy(colPerMcCollision, mcCollision.globalIndex());
15521552
rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask<BCsInfo, o2::hf_centrality::CentralityEstimator::None>(mcCollision, collSlice, centrality);

0 commit comments

Comments
 (0)