Skip to content

Commit 179c214

Browse files
committed
Generalize pdg switcher + suppress linter warnings
1 parent 621c8da commit 179c214

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

PWGHF/TableProducer/candidateCreator2Prong.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ struct HfCandidateCreator2ProngExpressions {
783783
// D0(bar) → π+ K−, π+ K− π0, π+ π−, π+ π− π0, K+ K−
784784
for (const auto& [chn, finalState] : hf_cand_2prong::daughtersD0Main) {
785785
std::array<int, 2> finalStateParts2Prong = std::array{finalState[0], finalState[1]};
786-
if (finalState.size() == 3) { // Partly Reco 2-prong decays
786+
if (finalState.size() == 3) { // Partly Reco 3-prong decays, o2-linter: disable=magic-number
787787
if (matchKinkedDecayTopology && matchInteractionsWithMaterial) {
788788
indexRec = RecoDecay::getMatchedMCRec<false, false, true, true, true>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, &nKinkedTracks, &nInteractionsWithMaterial);
789789
} else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) {
@@ -797,12 +797,12 @@ struct HfCandidateCreator2ProngExpressions {
797797
if (indexRec > -1) {
798798
auto motherParticle = mcParticles.rawIteratorAt(indexRec);
799799
std::array<int, 3> finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]};
800-
convertPi0ToAntiPi0(motherParticle.pdgCode(), finalStateParts2ProngAll);
800+
changeFinalStatePdgSign(motherParticle.pdgCode(), +kPi0, finalStateParts2ProngAll);
801801
if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, Pdg::kD0, finalStateParts2ProngAll, true, &sign, FinalStateDepth)) {
802802
indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one does not match the reconstructed one
803803
}
804804
}
805-
} else if (finalState.size() == 2) { // Fully Reco 2-prong decays
805+
} else if (finalState.size() == 2) { // Fully Reco 2-prong decays, o2-linter: disable=magic-number
806806
if (matchKinkedDecayTopology && matchInteractionsWithMaterial) {
807807
indexRec = RecoDecay::getMatchedMCRec<false, false, false, true, true>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, &nKinkedTracks, &nInteractionsWithMaterial);
808808
} else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) {

PWGHF/TableProducer/candidateCreator3Prong.cxx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ struct HfCandidateCreator3ProngExpressions {
959959
auto finalStates = getDecayChannelMain(pdg);
960960
for (const auto& [chn, finalState] : finalStates) {
961961
std::array<int, 3> finalStateParts3Prong = std::array{finalState[0], finalState[1], finalState[2]};
962-
if (finalState.size() > 3) { // Partly Reco 4-prong decays
962+
if (finalState.size() > 3) { // Partly Reco decays with 4 or 5 final state particles, o2-linter: disable=magic-number
963963
if (matchKinkedDecayTopology && matchInteractionsWithMaterial) {
964964
indexRec = RecoDecay::getMatchedMCRec<false, false, true, true, true>(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial);
965965
} else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) {
@@ -972,21 +972,21 @@ struct HfCandidateCreator3ProngExpressions {
972972

973973
if (indexRec > -1) {
974974
auto motherParticle = mcParticles.rawIteratorAt(indexRec);
975-
if (finalState.size() == 4) { // Check if the final state has 4 particles
975+
if (finalState.size() == 4) { // Check if the final state has 4 particles, o2-linter: disable=magic-number
976976
std::array<int, 4> finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3]};
977-
convertPi0ToAntiPi0(motherParticle.pdgCode(), finalStateParts3ProngAll);
977+
changeFinalStatePdgSign(motherParticle.pdgCode(), +kPi0, finalStateParts3ProngAll);
978978
if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, true, &sign, depth)) {
979979
indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one is not matched
980980
}
981-
} else if (finalState.size() == 5) { // Check if the final state has 5 particles
981+
} else if (finalState.size() == 5) { // Check if the final state has 5 particles, o2-linter: disable=magic-number
982982
std::array<int, 5> finalStateParts3ProngAll = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]};
983-
convertPi0ToAntiPi0(motherParticle.pdgCode(), finalStateParts3ProngAll);
983+
changeFinalStatePdgSign(motherParticle.pdgCode(), +kPi0, finalStateParts3ProngAll);
984984
if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, pdg, finalStateParts3ProngAll, true, &sign, depth)) {
985985
indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one is not matched
986986
}
987987
}
988988
}
989-
} else if (finalState.size() == 3) { // Fully Reco 3-prong decays
989+
} else if (finalState.size() == 3) { // Fully Reco 3-prong decays, o2-linter: disable=magic-number
990990
if (matchKinkedDecayTopology && matchInteractionsWithMaterial) {
991991
indexRec = RecoDecay::getMatchedMCRec<false, false, false, true, true>(mcParticles, arrayDaughters, pdg, finalStateParts3Prong, true, &sign, depth, &nKinkedTracks, &nInteractionsWithMaterial);
992992
} else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) {
@@ -1023,7 +1023,7 @@ struct HfCandidateCreator3ProngExpressions {
10231023
auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]);
10241024
arrPDGDaugh[iProng] = daughI.pdgCode();
10251025
}
1026-
channel = flagResonantDecay<true>(pdg, arrPDGDaugh);
1026+
channel = flagResonantDecay(pdg, arrPDGDaugh);
10271027
}
10281028
break; // Exit loop if a match is found
10291029
}

PWGHF/Utils/utilsMcGen.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ void fillMcMatchGen2Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V
6060
bool matched = false;
6161

6262
for (const auto& [chn, finalState] : o2::hf_decay::hf_cand_2prong::daughtersD0Main) {
63-
if (finalState.size() == 3) { // Partly Reco 3-prong decays
63+
if (finalState.size() == 3) { // Partly Reco 3-prong decays, o2-linter: disable=magic-number
6464
std::array<int, 3> finalStateParts = std::array{finalState[0], finalState[1], finalState[2]};
65-
o2::hf_decay::convertPi0ToAntiPi0(particle.pdgCode(), finalStateParts);
65+
o2::hf_decay::changeFinalStatePdgSign(particle.pdgCode(), +kPi0, finalStateParts);
6666
matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, MaxDepth);
67-
} else if (finalState.size() == 2) { // Fully Reco 2-prong decays
67+
} else if (finalState.size() == 2) { // Fully Reco 2-prong decays, o2-linter: disable=magic-number
6868
std::array<int, 2> finalStateParts = std::array{finalState[0], finalState[1]};
6969
matched = RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, finalStateParts, true, &sign, MaxDepth);
7070
} else {
@@ -164,17 +164,17 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V
164164

165165
std::vector<int> arrAllDaughtersIndex;
166166
for (const auto& [chn, finalState] : finalStates) {
167-
if (finalState.size() == 5) { // Partly Reco 3-prong decays from 5-prong decays
167+
if (finalState.size() == 5) { // Partly Reco 3-prong decays from 5-prong decays, o2-linter: disable=magic-number
168168
std::array<int, 5> finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3], finalState[4]};
169-
o2::hf_decay::convertPi0ToAntiPi0(particle.pdgCode(), finalStateParts);
169+
o2::hf_decay::changeFinalStatePdgSign(particle.pdgCode(), +kPi0, finalStateParts);
170170
RecoDecay::getDaughters<false>(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth);
171171
matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1);
172-
} else if (finalState.size() == 4) { // Partly Reco 3-prong decays from 4-prong decays
173-
std::array<int, 4> finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]};
174-
o2::hf_decay::convertPi0ToAntiPi0(particle.pdgCode(), finalStateParts);
172+
} else if (finalState.size() == 4) { // Partly Reco 3-prong decays from 4-prong decays, o2-linter: disable=magic-number
173+
std::array<int, 4> finalStateParts = std::array{finalState[0], finalState[1], finalState[2], finalState[3]};
174+
o2::hf_decay::changeFinalStatePdgSign(particle.pdgCode(), +kPi0, finalStateParts);
175175
RecoDecay::getDaughters<false>(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth);
176176
matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, -1);
177-
} else if (finalState.size() == 3) { // Fully Reco 3-prong decays
177+
} else if (finalState.size() == 3) { // Fully Reco 3-prong decays, o2-linter: disable=magic-number
178178
std::array<int, 3> finalStateParts = std::array{finalState[0], finalState[1], finalState[2]};
179179
RecoDecay::getDaughters<false>(particle, &arrAllDaughtersIndex, finalStateParts, maxDepth);
180180
matched = RecoDecay::isMatchedMCGen(mcParticles, particle, motherPdgCode, finalStateParts, true, &sign, maxDepth);
@@ -207,7 +207,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V
207207
auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]);
208208
arrPDGDaugh[iProng] = daughI.pdgCode();
209209
}
210-
channel = o2::hf_decay::flagResonantDecay<true>(motherPdgCode, arrPDGDaugh);
210+
channel = o2::hf_decay::flagResonantDecay(motherPdgCode, arrPDGDaugh);
211211
}
212212
break; // Exit loop if a match is found
213213
}
@@ -240,7 +240,7 @@ void fillMcMatchGen3Prong(T const& mcParticles, U const& mcParticlesPerMcColl, V
240240
}
241241
if (flag != 0) {
242242
RecoDecay::getDaughters(particle, &arrDaughIndex, std::array{0}, 1);
243-
if (arrDaughIndex.size() == 2) {
243+
if (arrDaughIndex.size() == NDaughtersResonant) {
244244
for (auto jProng = 0u; jProng < arrDaughIndex.size(); ++jProng) {
245245
auto daughJ = mcParticles.rawIteratorAt(arrDaughIndex[jProng]);
246246
arrPDGDaugh[jProng] = std::abs(daughJ.pdgCode());

PWGHF/Utils/utilsMcMatching.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ inline bool checkDecayChannel(std::array<int, N> const& arrPdgResoChn, std::arra
194194
/// \param motherPdg PDG code of the mother particle
195195
/// \param channel decay channel flag to be set
196196
/// \param arrDaughPdgs array of daughter PDG codes
197-
template <bool is3Prong = false, std::size_t N>
198-
inline int8_t flagResonantDecay(int motherPdg, std::array<int, N> const& arrDaughPdgs)
197+
template <std::size_t N>
198+
inline int8_t flagResonantDecay(const int motherPdg, std::array<int, N> const& arrDaughPdgs)
199199
{
200200
switch (motherPdg) {
201201
case o2::constants::physics::Pdg::kD0:
@@ -242,24 +242,25 @@ inline int8_t flagResonantDecay(int motherPdg, std::array<int, N> const& arrDaug
242242
break;
243243
default:
244244
LOG(fatal) << "Unknown PDG code for 3-prong final states: " << motherPdg;
245-
return {};
245+
return -1;
246246
}
247247
return 0;
248248
}
249249

250-
/// Convert Pi0 to AntiPi0 in the array of PDG codes for antiparticles since
251-
/// the Pi0s stemming from antiparticle decays keep the pdg code 111.
250+
/// Flip the sign of a specific PDG code in an array
251+
/// of PDG codes representing either a final or a resonant state
252252
/// \tparam N size of the array of PDG codes
253-
/// \param partPdgCode PDG code of the particle
254-
/// \param arrPdgIndexes array of PDG codes to be modified
253+
/// \param motherPdgCode PDG code of the mother particle
254+
/// \param partPdgCode PDG code of the target particle
255+
/// \param arrFinalStatePdgs array of PDG codes to be modified
255256
template <std::size_t N>
256-
inline void convertPi0ToAntiPi0(const int partPdgCode, std::array<int, N>& arrPdgIndexes)
257+
inline void changeFinalStatePdgSign(const int motherPdgCode, const int partPdgCode, std::array<int, N>& arrFinalStatePdgs)
257258
{
258-
if (partPdgCode < 0) {
259-
for (auto& part : arrPdgIndexes) { // o2-linter: disable=const-ref-in-for-loop (int elements)
260-
if (part == kPi0) {
261-
part = -part; // The Pi0 pdg code does not change between particle and antiparticle
262-
}
259+
if (motherPdgCode >= 0)
260+
return;
261+
for (auto& part : arrFinalStatePdgs) { // o2-linter: disable=const-ref-in-for-loop (arrFinalStatePdgs entries are modified)
262+
if (part == partPdgCode) {
263+
part = -part;
263264
}
264265
}
265266
}

0 commit comments

Comments
 (0)