From c53d476451fe5bf3462417bfd3c4a1f3171e5410 Mon Sep 17 00:00:00 2001 From: Fabrizio Grosa Date: Thu, 6 Jan 2022 10:23:17 +0100 Subject: [PATCH 1/2] [PWGHF] Add protection for tracks without associated MC particle --- Common/Core/RecoDecay.h | 3 +++ .../TableProducer/HFCandidateCreator3Prong.cxx | 4 +++- .../HFD0CandidateSelectorALICE3Barrel.cxx | 13 +++++++++---- .../HFD0CandidateSelectorparametrizedPID.cxx | 12 ++++++++---- .../HFLcCandidateSelectorparametrizedPID.cxx | 18 ++++++++++++------ PWGHF/Tasks/HFMCValidation.cxx | 4 +++- 6 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Common/Core/RecoDecay.h b/Common/Core/RecoDecay.h index a9f822f0c78..49befeda5aa 100644 --- a/Common/Core/RecoDecay.h +++ b/Common/Core/RecoDecay.h @@ -724,6 +724,9 @@ class RecoDecay } // Loop over decay candidate prongs for (std::size_t iProng = 0; iProng < N; ++iProng) { + if (!arrDaughters[iProng].has_mcParticle()) { + return -1; + } auto particleI = arrDaughters[iProng].mcParticle(); // ith daughter particle arrDaughtersIndex[iProng] = particleI.globalIndex(); // Get the list of daughter indices from the mother of the first prong. diff --git a/PWGHF/TableProducer/HFCandidateCreator3Prong.cxx b/PWGHF/TableProducer/HFCandidateCreator3Prong.cxx index 2251addf6e2..2e07cd05be7 100644 --- a/PWGHF/TableProducer/HFCandidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/HFCandidateCreator3Prong.cxx @@ -192,7 +192,9 @@ struct HFCandidateCreator3ProngExpressions { flag = sign * (1 << DecayType::LcToPKPi); //Printf("Flagging the different Λc± → p± K∓ π± decay channels"); - swapping = int8_t(std::abs(arrayDaughters[0].mcParticle().pdgCode()) == kPiPlus); + if (arrayDaughters[0].has_mcParticle()) { + swapping = int8_t(std::abs(arrayDaughters[0].mcParticle().pdgCode()) == kPiPlus); + } RecoDecay::getDaughters(particlesMC, particlesMC.iteratorAt(indexRec), &arrDaughIndex, array{0}, 1); if (arrDaughIndex.size() == 2) { for (auto iProng = 0u; iProng < arrDaughIndex.size(); ++iProng) { diff --git a/PWGHF/TableProducer/HFD0CandidateSelectorALICE3Barrel.cxx b/PWGHF/TableProducer/HFD0CandidateSelectorALICE3Barrel.cxx index 84ed37258fd..4666275d4c6 100644 --- a/PWGHF/TableProducer/HFD0CandidateSelectorALICE3Barrel.cxx +++ b/PWGHF/TableProducer/HFD0CandidateSelectorALICE3Barrel.cxx @@ -229,10 +229,15 @@ struct HFD0CandidateSelectorALICE3Barrel { continue; } - const auto mcParticlePositive = trackPos.mcParticle(); - const auto mcParticleNegative = trackNeg.mcParticle(); - int pdgPositive = mcParticlePositive.pdgCode(); - int pdgNegative = mcParticleNegative.pdgCode(); + int pdgPositive = 0; + int pdgNegative = 0; + if(trackPos.has_mcParticle()) { + pdgPositive = trackPos.mcParticle().pdgCode(); + } + if(trackNeg.has_mcParticle()) { + pdgNegative = trackNeg.mcParticle().pdgCode(); + } + //std::cout << "barrel= " << pdgPositive <<"\t"<< pdgNegative << "\n"; float nsigmaTOFNegKaon = -5000.0; float nsigmaRICHNegKaon = -5000.0; diff --git a/PWGHF/TableProducer/HFD0CandidateSelectorparametrizedPID.cxx b/PWGHF/TableProducer/HFD0CandidateSelectorparametrizedPID.cxx index 523b4c5647d..c3a62c6c4e7 100644 --- a/PWGHF/TableProducer/HFD0CandidateSelectorparametrizedPID.cxx +++ b/PWGHF/TableProducer/HFD0CandidateSelectorparametrizedPID.cxx @@ -232,10 +232,14 @@ struct HFD0CandidateSelectorparametrizedPID { continue; } - const auto mcParticlePositive = trackPos.mcParticle(); - const auto mcParticleNegative = trackNeg.mcParticle(); - int pdgPositive = mcParticlePositive.pdgCode(); - int pdgNegative = mcParticleNegative.pdgCode(); + int pdgPositive = 0; + int pdgNegative = 0; + if(trackPos.has_mcParticle()) { + pdgPositive = trackPos.mcParticle().pdgCode(); + } + if(trackNeg.has_mcParticle()) { + pdgNegative = trackNeg.mcParticle().pdgCode(); + } bool selectPosPion = false; bool selectNegKaon = false; diff --git a/PWGHF/TableProducer/HFLcCandidateSelectorparametrizedPID.cxx b/PWGHF/TableProducer/HFLcCandidateSelectorparametrizedPID.cxx index 6948df4c96b..ec2c3795649 100644 --- a/PWGHF/TableProducer/HFLcCandidateSelectorparametrizedPID.cxx +++ b/PWGHF/TableProducer/HFLcCandidateSelectorparametrizedPID.cxx @@ -202,12 +202,18 @@ struct HFLcCandidateSelectorparametrizedPID { auto etaPos2Track = std::abs(trackPos2.eta()); auto etaNegTrack = std::abs(trackNeg.eta()); - const auto mcParticlePositive1 = trackPos1.mcParticle(); - const auto mcParticlePositive2 = trackPos2.mcParticle(); - const auto mcParticleNegative = trackNeg.mcParticle(); - int pdgPositive1 = mcParticlePositive1.pdgCode(); - int pdgPositive2 = mcParticlePositive2.pdgCode(); - int pdgNegative = mcParticleNegative.pdgCode(); + int pdgPositive1 = 0; + int pdgPositive2 = 0; + int pdgNegative = 0; + if(trackPos1.has_mcParticle()) { + pdgPositive1 = trackPos1.mcParticle().pdgCode(); + } + if(trackPos2.has_mcParticle()) { + pdgPositive2 = trackPos2.mcParticle().pdgCode(); + } + if(trackNeg.has_mcParticle()) { + pdgNegative = trackNeg.mcParticle().pdgCode(); + } bool selectPos1Proton = false; bool selectPos1Pion = false; diff --git a/PWGHF/Tasks/HFMCValidation.cxx b/PWGHF/Tasks/HFMCValidation.cxx index 7f12529cfd7..e9dd4a52bc3 100644 --- a/PWGHF/Tasks/HFMCValidation.cxx +++ b/PWGHF/Tasks/HFMCValidation.cxx @@ -172,7 +172,9 @@ struct ValidationRecLevel { continue; } if (std::abs(candidate.flagMCMatchRec()) == 1 << hf_cand_prong2::DecayType::D0ToPiK) { - indexParticle = RecoDecay::getMother(particlesMC, candidate.index0_as().mcParticle(), pdg::Code::kD0, true); + if(candidate.index0_as().has_mcParticle()) { + indexParticle = RecoDecay::getMother(particlesMC, candidate.index0_as().mcParticle(), pdg::Code::kD0, true); + } auto mother = particlesMC.iteratorAt(indexParticle); registry.fill(HIST("histPt"), candidate.pt() - mother.pt()); registry.fill(HIST("histPx"), candidate.px() - mother.px()); From ffb08b43e7a29dbc073583e81f4172cd02592264 Mon Sep 17 00:00:00 2001 From: Fabrizio Grosa Date: Thu, 6 Jan 2022 10:28:59 +0100 Subject: [PATCH 2/2] Fix format --- PWGHF/TableProducer/HFD0CandidateSelectorALICE3Barrel.cxx | 4 ++-- .../TableProducer/HFD0CandidateSelectorparametrizedPID.cxx | 4 ++-- .../TableProducer/HFLcCandidateSelectorparametrizedPID.cxx | 6 +++--- PWGHF/Tasks/HFMCValidation.cxx | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/PWGHF/TableProducer/HFD0CandidateSelectorALICE3Barrel.cxx b/PWGHF/TableProducer/HFD0CandidateSelectorALICE3Barrel.cxx index 4666275d4c6..09c05907c69 100644 --- a/PWGHF/TableProducer/HFD0CandidateSelectorALICE3Barrel.cxx +++ b/PWGHF/TableProducer/HFD0CandidateSelectorALICE3Barrel.cxx @@ -231,10 +231,10 @@ struct HFD0CandidateSelectorALICE3Barrel { int pdgPositive = 0; int pdgNegative = 0; - if(trackPos.has_mcParticle()) { + if (trackPos.has_mcParticle()) { pdgPositive = trackPos.mcParticle().pdgCode(); } - if(trackNeg.has_mcParticle()) { + if (trackNeg.has_mcParticle()) { pdgNegative = trackNeg.mcParticle().pdgCode(); } diff --git a/PWGHF/TableProducer/HFD0CandidateSelectorparametrizedPID.cxx b/PWGHF/TableProducer/HFD0CandidateSelectorparametrizedPID.cxx index c3a62c6c4e7..f210bb53db1 100644 --- a/PWGHF/TableProducer/HFD0CandidateSelectorparametrizedPID.cxx +++ b/PWGHF/TableProducer/HFD0CandidateSelectorparametrizedPID.cxx @@ -234,10 +234,10 @@ struct HFD0CandidateSelectorparametrizedPID { int pdgPositive = 0; int pdgNegative = 0; - if(trackPos.has_mcParticle()) { + if (trackPos.has_mcParticle()) { pdgPositive = trackPos.mcParticle().pdgCode(); } - if(trackNeg.has_mcParticle()) { + if (trackNeg.has_mcParticle()) { pdgNegative = trackNeg.mcParticle().pdgCode(); } diff --git a/PWGHF/TableProducer/HFLcCandidateSelectorparametrizedPID.cxx b/PWGHF/TableProducer/HFLcCandidateSelectorparametrizedPID.cxx index ec2c3795649..61b712be5cd 100644 --- a/PWGHF/TableProducer/HFLcCandidateSelectorparametrizedPID.cxx +++ b/PWGHF/TableProducer/HFLcCandidateSelectorparametrizedPID.cxx @@ -205,13 +205,13 @@ struct HFLcCandidateSelectorparametrizedPID { int pdgPositive1 = 0; int pdgPositive2 = 0; int pdgNegative = 0; - if(trackPos1.has_mcParticle()) { + if (trackPos1.has_mcParticle()) { pdgPositive1 = trackPos1.mcParticle().pdgCode(); } - if(trackPos2.has_mcParticle()) { + if (trackPos2.has_mcParticle()) { pdgPositive2 = trackPos2.mcParticle().pdgCode(); } - if(trackNeg.has_mcParticle()) { + if (trackNeg.has_mcParticle()) { pdgNegative = trackNeg.mcParticle().pdgCode(); } diff --git a/PWGHF/Tasks/HFMCValidation.cxx b/PWGHF/Tasks/HFMCValidation.cxx index e9dd4a52bc3..e7de79f1e9d 100644 --- a/PWGHF/Tasks/HFMCValidation.cxx +++ b/PWGHF/Tasks/HFMCValidation.cxx @@ -172,7 +172,7 @@ struct ValidationRecLevel { continue; } if (std::abs(candidate.flagMCMatchRec()) == 1 << hf_cand_prong2::DecayType::D0ToPiK) { - if(candidate.index0_as().has_mcParticle()) { + if (candidate.index0_as().has_mcParticle()) { indexParticle = RecoDecay::getMother(particlesMC, candidate.index0_as().mcParticle(), pdg::Code::kD0, true); } auto mother = particlesMC.iteratorAt(indexParticle);