Skip to content

Commit 5053cdc

Browse files
committed
Improve type safety
1 parent 8c8de7f commit 5053cdc

27 files changed

+330
-281
lines changed

PWGHF/Core/CentralityEstimation.h

Lines changed: 30 additions & 28 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+
using TMult = uint16_t; // type of numContrib
158159
float centrality{-1};
159-
float multiplicity{0.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
@@ -1186,7 +1186,7 @@ DECLARE_SOA_COLUMN(Sign, sign, int8_t); //!
11861186
DECLARE_SOA_COLUMN(ItsNClsSoftPi, itsNClsSoftPi, int); //! minimum value of number of ITS clusters for the decay daughter tracks
11871187
DECLARE_SOA_COLUMN(TpcNClsCrossedRowsSoftPi, tpcNClsCrossedRowsSoftPi, int); //! minimum value of number of TPC crossed rows for the decay daughter tracks
11881188
DECLARE_SOA_COLUMN(TpcChi2NClSoftPi, tpcChi2NClSoftPi, float); //! maximum value of TPC chi2 for the decay daughter tracks
1189-
DECLARE_SOA_DYNAMIC_COLUMN(Px, px, //!
1189+
DECLARE_SOA_DYNAMIC_COLUMN(Px, px, //!
11901190
[](float pxProng0, float pxProng1, float pxProng2) -> float { return 1.f * pxProng0 + 1.f * pxProng1 + 1.f * pxProng2; });
11911191
DECLARE_SOA_DYNAMIC_COLUMN(Py, py, //!
11921192
[](float pyProng0, float pyProng1, float pyProng2) -> float { return 1.f * pyProng0 + 1.f * pyProng1 + 1.f * pyProng2; });
@@ -1398,16 +1398,16 @@ DECLARE_SOA_COLUMN(InvMassProng1, invMassProng1, float); //! Invariant Mass of V
13981398
DECLARE_SOA_COLUMN(Sign, sign, int8_t); //! Sign of the Resonance candidate
13991399
DECLARE_SOA_COLUMN(IsWrongSign, isWrongSign, int8_t); //! Flag for wrong sign of the Resonance candidate, 1 = wrong sign, 0 = right sign
14001400

1401-
DECLARE_SOA_COLUMN(FlagMcMatchRec, flagMcMatchRec, int8_t); // flag for resonance decay channel classification reconstruction level
1402-
DECLARE_SOA_COLUMN(FlagMcMatchRecD, flagMcMatchRecD, int8_t); // flag for D meson bachelor decay channel classification reconstruction level
1403-
DECLARE_SOA_COLUMN(FlagMcMatchChanD, flagMcMatchChanD, int8_t); // flag for D meson resonant channel classification reconstruction level
1404-
DECLARE_SOA_COLUMN(FlagMcMatchGen, flagMcMatchGen, int8_t); // flag for decay channel classification generator level
1405-
DECLARE_SOA_COLUMN(DebugMcRec, debugMcRec, uint16_t); // debug flag for mis-association at reconstruction level
1406-
DECLARE_SOA_COLUMN(Origin, origin, int8_t); // Flag for origin of MC particle 1=promt, 2=FD
1407-
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*
1408-
DECLARE_SOA_COLUMN(PtGen, ptGen, float); // Pt at generation level in GeV/c
1409-
DECLARE_SOA_COLUMN(InvMassGen, invMassGen, float); //! Invariant mass at generation level in GeV/c2
1410-
DECLARE_SOA_DYNAMIC_COLUMN(Pt, pt, //!
1401+
DECLARE_SOA_COLUMN(FlagMcMatchRec, flagMcMatchRec, int8_t); // flag for resonance decay channel classification reconstruction level
1402+
DECLARE_SOA_COLUMN(FlagMcMatchRecD, flagMcMatchRecD, int8_t); // flag for D meson bachelor decay channel classification reconstruction level
1403+
DECLARE_SOA_COLUMN(FlagMcMatchChanD, flagMcMatchChanD, int8_t); // flag for D meson resonant channel classification reconstruction level
1404+
DECLARE_SOA_COLUMN(FlagMcMatchGen, flagMcMatchGen, int8_t); // flag for decay channel classification generator level
1405+
DECLARE_SOA_COLUMN(DebugMcRec, debugMcRec, uint16_t); // debug flag for mis-association at reconstruction level
1406+
DECLARE_SOA_COLUMN(Origin, origin, int8_t); // Flag for origin of MC particle 1=promt, 2=FD
1407+
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*
1408+
DECLARE_SOA_COLUMN(PtGen, ptGen, float); // Pt at generation level in GeV/c
1409+
DECLARE_SOA_COLUMN(InvMassGen, invMassGen, float); //! Invariant mass at generation level in GeV/c2
1410+
DECLARE_SOA_DYNAMIC_COLUMN(Pt, pt, //!
14111411
[](float pxProng0, float pxProng1, float pyProng0, float pyProng1) -> float { return RecoDecay::pt((1.f * pxProng0 + 1.f * pxProng1), (1.f * pyProng0 + 1.f * pyProng1)); });
14121412
DECLARE_SOA_DYNAMIC_COLUMN(PtProng0, ptProng0, //!
14131413
[](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
@@ -1021,7 +1021,7 @@ struct HfDataCreatorCharmHadPiReduced {
10211021
{
10221022
registry.fill(HIST("hEvents"), 1 + Event::Processed);
10231023
float centrality = -1.f;
1024-
auto hfRejMap = hfEvSel.getHfCollisionRejectionMask<true, o2::hf_centrality::CentralityEstimator::None, aod::BCsWithTimestamps>(collision, centrality, ccdb, registry);
1024+
const auto hfRejMap = hfEvSel.getHfCollisionRejectionMask<true, o2::hf_centrality::CentralityEstimator::None, aod::BCsWithTimestamps>(collision, centrality, ccdb, registry);
10251025
if (configs.skipRejectedCollisions && hfRejMap != 0) {
10261026
return;
10271027
}
@@ -1487,15 +1487,16 @@ struct HfDataCreatorCharmHadPiReduced {
14871487
// Check event selection
14881488
float centDummy{-1.f}, centFT0C{-1.f}, centFT0M{-1.f};
14891489
const auto collSlice = collisions.sliceBy(preslices.colPerMcCollision, mcCollision.globalIndex());
1490-
auto hfRejMap = hfEvSelMc.getHfMcCollisionRejectionMask<BCsInfo, o2::hf_centrality::CentralityEstimator::None>(mcCollision, collSlice, centDummy);
1490+
const auto hfRejMap = hfEvSelMc.getHfMcCollisionRejectionMask<BCsInfo, o2::hf_centrality::CentralityEstimator::None>(mcCollision, collSlice, centDummy);
14911491
if (configs.skipRejectedCollisions && hfRejMap != 0) {
14921492
return;
14931493
}
14941494

14951495
// get centrality
1496-
float multiplicity{0.f};
1496+
using TMult = uint16_t; // type of numContrib
1497+
TMult multiplicity{};
14971498
for (const auto& collision : collSlice) {
1498-
float collMult = collision.numContrib();
1499+
const TMult collMult = collision.numContrib();
14991500
if (collMult > multiplicity) {
15001501
centFT0C = collision.centFT0C();
15011502
centFT0M = collision.centFT0M();

PWGHF/D2H/TableProducer/dataCreatorCharmResoReduced.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

PWGHF/D2H/TableProducer/dataCreatorJpsiHadReduced.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ struct HfDataCreatorJpsiHadReduced {
728728

729729
registry.fill(HIST("hEvents"), 1 + Event::Processed);
730730
float centrality = -1.f;
731-
auto hfRejMap = hfEvSel.getHfCollisionRejectionMask<true, o2::hf_centrality::CentralityEstimator::None, aod::BCsWithTimestamps>(collision, centrality, ccdb, registry);
731+
const auto hfRejMap = hfEvSel.getHfCollisionRejectionMask<true, o2::hf_centrality::CentralityEstimator::None, aod::BCsWithTimestamps>(collision, centrality, ccdb, registry);
732732
if (skipRejectedCollisions && hfRejMap != 0) {
733733
return;
734734
}

PWGHF/D2H/Tasks/taskD0.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ struct HfTaskD0 {
391391
cent = getCentralityColl(collision, centEstimator);
392392
}
393393
if (storeOccupancy && occEstimator != OccupancyEstimator::None) {
394-
occ = getOccupancyColl(collision, occEstimator);
394+
occ = o2::hf_occupancy::getOccupancyColl(collision, occEstimator);
395395
}
396396
}
397397

@@ -558,7 +558,7 @@ struct HfTaskD0 {
558558
cent = getCentralityColl(collision, centEstimator);
559559
}
560560
if (storeOccupancy && occEstimator != OccupancyEstimator::None) {
561-
occ = getOccupancyColl(collision, occEstimator);
561+
occ = o2::hf_occupancy::getOccupancyColl(collision, occEstimator);
562562
}
563563
float massD0, massD0bar;
564564
if constexpr (reconstructionType == aod::hf_cand::VertexerType::KfParticle) {
@@ -844,7 +844,7 @@ struct HfTaskD0 {
844844
cent = getCentralityGenColl(recoCollsPerMcCollCent, centEstimator);
845845
}
846846
if (storeOccupancy && occEstimator != OccupancyEstimator::None) {
847-
occ = getOccupancyGenColl(recoCollsPerMcCollCent, occEstimator);
847+
occ = o2::hf_occupancy::getOccupancyGenColl(recoCollsPerMcCollCent, occEstimator);
848848
}
849849
} else {
850850
const auto& recoCollsPerMcColl = collisions.sliceBy(colPerMcCollision, particle.mcCollision().globalIndex());

0 commit comments

Comments
 (0)