diff --git a/PWGHF/D2H/Tasks/taskDs.cxx b/PWGHF/D2H/Tasks/taskDs.cxx index 7e79fe0f3ad..f3799760233 100644 --- a/PWGHF/D2H/Tasks/taskDs.cxx +++ b/PWGHF/D2H/Tasks/taskDs.cxx @@ -93,51 +93,6 @@ enum ResonantChannel : int8_t { Kstar0K = 2 }; -namespace o2::aod -{ -namespace hf_cand_ds_mini -{ -DECLARE_SOA_COLUMN(Pt, pt, float); //! Transverse momentum of D-meson candidate (GeV/c) -DECLARE_SOA_COLUMN(M, m, float); //! Invariant mass of D-meson candidates (GeV/c2) -DECLARE_SOA_COLUMN(MassKaKa, massKaKa, float); //! Invariant mass of kaon pairs (GeV/c2) -DECLARE_SOA_COLUMN(MassKaFirstPi, massKaFirstPi, float); //! Invariant mass of kaon(first) pion (GeV/c2) -DECLARE_SOA_COLUMN(MassKaSecondPi, massKaSecondPi, float); //! Invariant mass of kaon(second) pion (GeV/c2) -DECLARE_SOA_COLUMN(Centrality, centrality, float); //! Centrality of collision -DECLARE_SOA_COLUMN(ImpactParameter, impactParameter, float); //! Impact parameter of D-meson candidate -DECLARE_SOA_COLUMN(ImpactParameterMc, impactParameterMc, float); //! Generated impact parameter of D-meson candidate -DECLARE_SOA_COLUMN(DecayLength, decayLength, float); //! Decay length of D-meson candidate -DECLARE_SOA_COLUMN(DecayLengthXY, decayLengthXY, float); //! Transverse decay length of D-meson candidate -DECLARE_SOA_COLUMN(DecayLengthNormalised, decayLengthNormalised, float); //! Normalised decay length of D-meson candidate -DECLARE_SOA_COLUMN(DecayLengthXYNormalised, decayLengthXYNormalised, float); //! Normalised transverse decay length of D-meson candidate -DECLARE_SOA_COLUMN(FlagMc, flagMc, int); //! MC flag (according to DataType enum) -} // namespace hf_cand_ds_mini - -DECLARE_SOA_TABLE(HfCandDsMinis, "AOD", "HFDSMINI", //! Table with few Ds properties - hf_cand_ds_mini::M, - hf_cand_ds_mini::Pt, - hf_cand_ds_mini::Centrality); - -DECLARE_SOA_TABLE(HfCandDsMassMinis, "AOD", "HFDSMASSMINI", //! Table with Ds 2-prong masses - hf_cand_ds_mini::MassKaKa, - hf_cand_ds_mini::MassKaFirstPi, - hf_cand_ds_mini::MassKaSecondPi); - -DECLARE_SOA_TABLE(HfCandDsDlMinis, "AOD", "HFDSDLMINI", //! Table with decay length Ds properties - hf_cand_ds_mini::DecayLength, - hf_cand_ds_mini::DecayLengthXY, - hf_cand_ds_mini::DecayLengthNormalised, - hf_cand_ds_mini::DecayLengthXYNormalised); - -DECLARE_SOA_TABLE(HfCandDsD0Minis, "AOD", "HFDSD0MINI", //! Table with impact parameter (d0) - hf_cand_ds_mini::ImpactParameter); - -DECLARE_SOA_TABLE(HfCandDsD0McMinis, "AOD", "HFDSD0MCMINI", //! Table with generated impact parameter (d0) - hf_cand_ds_mini::ImpactParameterMc); - -DECLARE_SOA_TABLE(HfCandDsMcMinis, "AOD", "HFDSMCMINI", //! Table with MC decay type check - hf_cand_ds_mini::FlagMc); -} // namespace o2::aod - static std::unordered_map> channelsResonant = {{{Mother::Ds, {{ResonantChannel::PhiPi, hf_decay::hf_cand_3prong::DecayChannelResonant::DsToPhiPi}, {ResonantChannel::Kstar0K, hf_decay::hf_cand_3prong::DecayChannelResonant::DsToKstar0K}}}, {Mother::Dplus, {{ResonantChannel::PhiPi, hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToPhiPi}, {ResonantChannel::Kstar0K, hf_decay::hf_cand_3prong::DecayChannelResonant::DplusToKstar0K}}}}}; @@ -149,13 +104,6 @@ concept HasDsMlInfo = requires(T candidate) { /// Ds± analysis task struct HfTaskDs { - Produces hfCandDsMinis; - Produces hfCandDsMassMinis; - Produces hfCandDsDlMinis; - Produces hfCandDsD0Minis; - Produces hfCandDsMcMinis; - Produces hfCandDsD0McMinis; - Configurable decayChannel{"decayChannel", 1, "Switch between resonant decay channels: 1 for Ds/Dplus->PhiPi->KKpi, 2 for Ds/Dplus->K0*K->KKPi"}; Configurable fillDplusMc{"fillDplusMc", true, "Switch to fill Dplus MC information"}; Configurable selectionFlagDs{"selectionFlagDs", 7, "Selection Flag for Ds"}; @@ -170,12 +118,6 @@ struct HfTaskDs { Configurable storeOccupancy{"storeOccupancy", false, "Flag to store occupancy information"}; Configurable occEstimator{"occEstimator", 0, "Occupancy estimation (None: 0, ITS: 1, FT0C: 2)"}; Configurable fillMcBkgHistos{"fillMcBkgHistos", false, "Flag to fill and store histograms for MC background"}; - struct : ConfigurableGroup { - Configurable produceMiniTrees{"produceMiniTrees", false, "Flag to produce mini trees"}; - Configurable extendWithDecayLength{"extendWithDecayLength", false, "Flag to extend trees with decay length information"}; - Configurable extendWithImpactParameter{"extendWithImpactParameter", false, "Flag to extend trees with impact parameter information"}; - } miniTrees; - struct : ConfigurableGroup { Configurable ccdburl{"ccdburl", "http://alice-ccdb.cern.ch", "The CCDB endpoint url address"}; Configurable ccdbPath{"ccdbPath", "Centrality/Calibration", "The CCDB path for centrality/multiplicity information"}; @@ -598,72 +540,6 @@ struct HfTaskDs { } } - template - void fillMiniTrees(const Cand& candidate, FinalState finalState) - { - float mass{-1.f}, massKaKa{-1.f}, massKaFirstPi{-1.f}, massKaSecondPi{-1.f}; - if (finalState == FinalState::KKPi) { - mass = HfHelper::invMassDsToKKPi(candidate); - massKaKa = HfHelper::massKKPairDsToKKPi(candidate); - massKaFirstPi = HfHelper::massKFirstPiPairDsToKKPi(candidate); - massKaSecondPi = HfHelper::massKSecondPiPairDsToKKPi(candidate); - } else { - mass = HfHelper::invMassDsToPiKK(candidate); - massKaKa = HfHelper::massKKPairDsToPiKK(candidate); - massKaFirstPi = HfHelper::massKFirstPiPairDsToPiKK(candidate); - massKaSecondPi = HfHelper::massKSecondPiPairDsToPiKK(candidate); - } - auto pt = candidate.pt(); - - hfCandDsMinis(mass, pt, evaluateCentralityCand(candidate)); - hfCandDsMassMinis(massKaKa, massKaFirstPi, massKaSecondPi); - if (miniTrees.extendWithDecayLength) { - hfCandDsDlMinis(candidate.decayLength(), candidate.decayLengthXY(), candidate.decayLengthNormalised(), candidate.decayLengthXYNormalised()); - } - if (miniTrees.extendWithImpactParameter) { - hfCandDsD0Minis(candidate.impactParameterXY()); - } - } - - template - void fillMiniTreesMc(const Cand& candidate, DataType dataType, FinalState finalState, const CandDsMcGen& mcParticles, int indexMother) - { - float mass{-1.f}, massKaKa{-1.f}, massKaFirstPi{-1.f}, massKaSecondPi{-1.f}; - if (finalState == FinalState::KKPi) { - mass = HfHelper::invMassDsToKKPi(candidate); - massKaKa = HfHelper::massKKPairDsToKKPi(candidate); - massKaFirstPi = HfHelper::massKFirstPiPairDsToKKPi(candidate); - massKaSecondPi = HfHelper::massKSecondPiPairDsToKKPi(candidate); - } else { - mass = HfHelper::invMassDsToPiKK(candidate); - massKaKa = HfHelper::massKKPairDsToPiKK(candidate); - massKaFirstPi = HfHelper::massKFirstPiPairDsToPiKK(candidate); - massKaSecondPi = HfHelper::massKSecondPiPairDsToPiKK(candidate); - } - auto pt = candidate.pt(); - - hfCandDsMinis(mass, pt, evaluateCentralityCand(candidate)); - hfCandDsMassMinis(massKaKa, massKaFirstPi, massKaSecondPi); - if (miniTrees.extendWithDecayLength) { - hfCandDsDlMinis(candidate.decayLength(), candidate.decayLengthXY(), candidate.decayLengthNormalised(), candidate.decayLengthXYNormalised()); - } - if (miniTrees.extendWithImpactParameter) { - hfCandDsD0Minis(candidate.impactParameterXY()); - } - hfCandDsMcMinis(dataType); - - if (miniTrees.extendWithImpactParameter) { - // indexMother is != -1 here - auto particleMc = mcParticles.rawIteratorAt(indexMother); - auto prong0 = mcParticles.rawIteratorAt(particleMc.daughtersIds()[0]); - - std::array pv{particleMc.mcCollision().posX(), particleMc.mcCollision().posY(), particleMc.mcCollision().posZ()}; - std::array sv{prong0.vx(), prong0.vy(), prong0.vz()}; - auto genD0 = RecoDecay::impParXY(pv, sv, std::array{particleMc.px(), particleMc.py(), particleMc.pz()}); - hfCandDsD0McMinis(genD0); - } - } - /// Fill histograms of quantities for the KKPi daugther-mass hypothesis /// \param candidate is candidate /// \param dataType is data class, as defined in DataType enum @@ -724,9 +600,6 @@ struct HfTaskDs { } fillHisto(candidate, dataType); fillHistoKKPi(candidate, dataType); - if (miniTrees.produceMiniTrees) { - fillMiniTreesMc(candidate, dataType, FinalState::KKPi, mcParticles, indexMother); - } if (TESTBIT(candidate.isSelDsToKKPi(), aod::SelectionStep::RecoSkims)) { std::get(histosPtr[dataType]["hPtVsYRecoSkim"])->Fill(pt, yCand); } @@ -744,9 +617,6 @@ struct HfTaskDs { } fillHisto(candidate, dataType); fillHistoPiKK(candidate, dataType); - if (miniTrees.produceMiniTrees) { - fillMiniTreesMc(candidate, dataType, FinalState::PiKK, mcParticles, indexMother); - } if (TESTBIT(candidate.isSelDsToPiKK(), aod::SelectionStep::RecoSkims)) { std::get(histosPtr[dataType]["hPtVsYRecoSkim"])->Fill(pt, yCand); @@ -770,9 +640,6 @@ struct HfTaskDs { } fillHisto(candidate, DataType::Data); fillHistoKKPi(candidate, DataType::Data); - if (miniTrees.produceMiniTrees) { - fillMiniTrees(candidate, FinalState::KKPi); - } } if (candidate.isSelDsToPiKK() >= selectionFlagDs) { // PiKK if (yCandRecoMax >= 0. && std::abs(candidate.y(HfHelper::invMassDsToPiKK(candidate))) > yCandRecoMax) { @@ -780,9 +647,6 @@ struct HfTaskDs { } fillHisto(candidate, DataType::Data); fillHistoPiKK(candidate, DataType::Data); - if (miniTrees.produceMiniTrees) { - fillMiniTrees(candidate, FinalState::PiKK); - } } } diff --git a/PWGHF/TableProducer/treeCreatorDsToKKPi.cxx b/PWGHF/TableProducer/treeCreatorDsToKKPi.cxx index 98d42538fc3..1a0afb2da5b 100644 --- a/PWGHF/TableProducer/treeCreatorDsToKKPi.cxx +++ b/PWGHF/TableProducer/treeCreatorDsToKKPi.cxx @@ -38,6 +38,8 @@ #include #include +#include +#include #include #include #include @@ -245,6 +247,48 @@ DECLARE_SOA_TABLE(HfCandDsFullPs, "AOD", "HFCANDDSFULLP", full::Y, hf_cand_mc_flag::FlagMcMatchRec, hf_cand_mc_flag::OriginMcGen); + +namespace hf_cand_ds_mini +{ +DECLARE_SOA_COLUMN(Pt, pt, float); //! Transverse momentum of D-meson candidate (GeV/c) +DECLARE_SOA_COLUMN(M, m, float); //! Invariant mass of D-meson candidates (GeV/c2) +DECLARE_SOA_COLUMN(MassKaKa, massKaKa, float); //! Invariant mass of kaon pairs (GeV/c2) +DECLARE_SOA_COLUMN(MassKaFirstPi, massKaFirstPi, float); //! Invariant mass of kaon(first) pion (GeV/c2) +DECLARE_SOA_COLUMN(MassKaSecondPi, massKaSecondPi, float); //! Invariant mass of kaon(second) pion (GeV/c2) +DECLARE_SOA_COLUMN(Centrality, centrality, float); //! Centrality of collision +DECLARE_SOA_COLUMN(ImpactParameter, impactParameter, float); //! Impact parameter of D-meson candidate +DECLARE_SOA_COLUMN(ImpactParameterMc, impactParameterMc, float); //! Generated impact parameter of D-meson candidate +DECLARE_SOA_COLUMN(DecayLength, decayLength, float); //! Decay length of D-meson candidate +DECLARE_SOA_COLUMN(DecayLengthXY, decayLengthXY, float); //! Transverse decay length of D-meson candidate +DECLARE_SOA_COLUMN(DecayLengthNormalised, decayLengthNormalised, float); //! Normalised decay length of D-meson candidate +DECLARE_SOA_COLUMN(DecayLengthXYNormalised, decayLengthXYNormalised, float); //! Normalised transverse decay length of D-meson candidate +DECLARE_SOA_COLUMN(FlagMc, flagMc, int); //! MC flag (according to DataType enum) +} // namespace hf_cand_ds_mini + +DECLARE_SOA_TABLE(HfCandDsMinis, "AOD", "HFDSMINI", //! Table with few Ds properties + hf_cand_ds_mini::M, + hf_cand_ds_mini::Pt, + hf_cand_ds_mini::Centrality); + +DECLARE_SOA_TABLE(HfCandDsMassMinis, "AOD", "HFDSMASSMINI", //! Table with Ds 2-prong masses + hf_cand_ds_mini::MassKaKa, + hf_cand_ds_mini::MassKaFirstPi, + hf_cand_ds_mini::MassKaSecondPi); + +DECLARE_SOA_TABLE(HfCandDsDlMinis, "AOD", "HFDSDLMINI", //! Table with decay length Ds properties + hf_cand_ds_mini::DecayLength, + hf_cand_ds_mini::DecayLengthXY, + hf_cand_ds_mini::DecayLengthNormalised, + hf_cand_ds_mini::DecayLengthXYNormalised); + +DECLARE_SOA_TABLE(HfCandDsD0Minis, "AOD", "HFDSD0MINI", //! Table with impact parameter (d0) + hf_cand_ds_mini::ImpactParameter); + +DECLARE_SOA_TABLE(HfCandDsD0McMinis, "AOD", "HFDSD0MCMINI", //! Table with generated impact parameter (d0) + hf_cand_ds_mini::ImpactParameterMc); + +DECLARE_SOA_TABLE(HfCandDsMcMinis, "AOD", "HFDSMCMINI", //! Table with MC decay type check + hf_cand_ds_mini::FlagMc); } // namespace o2::aod enum Mother : int8_t { @@ -257,6 +301,18 @@ enum ResonantChannel : int8_t { Kstar0K = 2 }; +enum FinalState { KKPi = 0, + PiKK }; + +enum DataType { Data = 0, + McDsPrompt, + McDsNonPrompt, + McDplusPrompt, + McDplusNonPrompt, + McDplusBkg, + McLcBkg, + McBkg }; + namespace { std::unordered_map> channelsResonant = {{{Mother::Ds, {{ResonantChannel::PhiPi, hf_decay::hf_cand_3prong::DecayChannelResonant::DsToPhiPi}, {ResonantChannel::Kstar0K, hf_decay::hf_cand_3prong::DecayChannelResonant::DsToKstar0K}}}, @@ -269,6 +325,12 @@ struct HfTreeCreatorDsToKKPi { Produces rowCandidateFullEvents; Produces rowCandidateFullParticles; Produces rowCandidateLite; + Produces rowCandidateMini; + Produces rowCandidateMassMini; + Produces rowCandidateDlMini; + Produces rowCandidateD0Mini; + Produces rowCandidateMcMini; + Produces rowCandidateD0McMini; Configurable decayChannel{"decayChannel", 1, "Switch between resonant decay channels: 1 for Ds/Dplus->PhiPi->KKpi, 2 for Ds/Dplus->K0*K->KKPi"}; Configurable fillDplusMc{"fillDplusMc", false, "Switch to fill Dplus MC information"}; @@ -279,18 +341,25 @@ struct HfTreeCreatorDsToKKPi { Configurable fillOnlyBackground{"fillOnlyBackground", false, "Flag to fill derived tables with background for ML trainings"}; Configurable downSampleBkgFactor{"downSampleBkgFactor", 1., "Fraction of background candidates to keep for ML trainings"}; Configurable ptMaxForDownSample{"ptMaxForDownSample", 10., "Maximum pt for the application of the downsampling factor"}; + // mini tables (alternative to the full/lite tables) + struct : ConfigurableGroup { + Configurable produceMiniTrees{"produceMiniTrees", false, "Flag to produce mini trees instead of the full/lite candidate tables"}; + Configurable extendWithDecayLength{"extendWithDecayLength", false, "Flag to extend mini trees with decay length information"}; + Configurable extendWithImpactParameter{"extendWithImpactParameter", false, "Flag to extend mini trees with impact parameter information"}; + } miniTrees; using CandDsData = soa::Filtered>; using CandDsMcReco = soa::Filtered>; - using CandDsMcGen = soa::Filtered>; + using CandDsMcGen = soa::Join; using TracksWPid = soa::Join; + using TracksWPidMc = soa::Join; using CollisionsWithFT0C = soa::Join; using CollisionsWithFT0M = soa::Join; using CollisionsWithNTracksPV = soa::Join; Filter filterSelectCandidates = aod::hf_sel_candidate_ds::isSelDsToKKPi >= selectionFlagDs || aod::hf_sel_candidate_ds::isSelDsToPiKK >= selectionFlagDs; - Filter filterMcGenMatching = + Partition selectedMcParticles = nabs(o2::aod::hf_cand_mc_flag::flagMcMatchGen) == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKK) && (aod::hf_cand_mc_flag::flagMcDecayChanGen == channelsResonant[Mother::Ds][decayChannel] || (fillDplusMc && aod::hf_cand_mc_flag::flagMcDecayChanGen == channelsResonant[Mother::Dplus][decayChannel])); // Do not store Dplus MC if fillDplusMc is false @@ -311,6 +380,132 @@ struct HfTreeCreatorDsToKKPi { } } + /// Classify a MC candidate according to the DataType enum + /// \param candidate is the candidate + /// \return MC category of the candidate + template + DataType getDataType(const Cand& candidate) + { + const auto flag = std::abs(candidate.flagMcMatchRec()); + const auto channel = candidate.flagMcDecayChanRec(); + const auto origin = candidate.originMcRec(); + if (flag == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DsToPiKK) && channel == channelsResonant[Mother::Ds][decayChannel]) { + if (origin == RecoDecay::OriginType::Prompt) { + return DataType::McDsPrompt; + } + if (origin == RecoDecay::OriginType::NonPrompt) { + return DataType::McDsNonPrompt; + } + } + if (flag == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKK) && channel == channelsResonant[Mother::Dplus][decayChannel]) { + if (origin == RecoDecay::OriginType::Prompt) { + return DataType::McDplusPrompt; + } + if (origin == RecoDecay::OriginType::NonPrompt) { + return DataType::McDplusNonPrompt; + } + } + if (flag == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi)) { + return DataType::McDplusBkg; + } + if (flag == static_cast(hf_decay::hf_cand_3prong::DecayChannelMain::LcToPKPi)) { + return DataType::McLcBkg; + } + return DataType::McBkg; + } + + /// Find the MC mother of a matched candidate + /// \param candidate is the candidate + /// \param dataType is the MC category of the candidate + /// \param mcParticles are the MC particles + /// \return index of the MC mother, -1 if not found + template + int getIndexMother(const Cand& candidate, DataType dataType, const CandDsMcGen& mcParticles) + { + if (dataType == DataType::McBkg) { + return -1; + } + auto prong0 = candidate.template prong0_as(); + if (!prong0.has_mcParticle()) { + return -1; + } + int pdgMother = o2::constants::physics::Pdg::kDS; + if (dataType == DataType::McDplusPrompt || dataType == DataType::McDplusNonPrompt || dataType == DataType::McDplusBkg) { + pdgMother = o2::constants::physics::Pdg::kDPlus; + } else if (dataType == DataType::McLcBkg) { + pdgMother = o2::constants::physics::Pdg::kLambdaCPlus; + } + return RecoDecay::getMother(mcParticles, prong0.template mcParticle_as(), pdgMother, true); + } + + template + void fillMiniTables(const Cand& candidate, FinalState finalState) + { + float mass{-1.f}, massKaKa{-1.f}, massKaFirstPi{-1.f}, massKaSecondPi{-1.f}; + if (finalState == FinalState::KKPi) { + mass = HfHelper::invMassDsToKKPi(candidate); + massKaKa = HfHelper::massKKPairDsToKKPi(candidate); + massKaFirstPi = HfHelper::massKFirstPiPairDsToKKPi(candidate); + massKaSecondPi = HfHelper::massKSecondPiPairDsToKKPi(candidate); + } else { + mass = HfHelper::invMassDsToPiKK(candidate); + massKaKa = HfHelper::massKKPairDsToPiKK(candidate); + massKaFirstPi = HfHelper::massKFirstPiPairDsToPiKK(candidate); + massKaSecondPi = HfHelper::massKSecondPiPairDsToPiKK(candidate); + } + auto pt = candidate.pt(); + + rowCandidateMini(mass, pt, o2::hf_centrality::getCentralityColl(candidate.template collision_as())); + rowCandidateMassMini(massKaKa, massKaFirstPi, massKaSecondPi); + if (miniTrees.extendWithDecayLength) { + rowCandidateDlMini(candidate.decayLength(), candidate.decayLengthXY(), candidate.decayLengthNormalised(), candidate.decayLengthXYNormalised()); + } + if (miniTrees.extendWithImpactParameter) { + rowCandidateD0Mini(candidate.impactParameterXY()); + } + } + + template + void fillMiniTablesMc(const Cand& candidate, DataType dataType, FinalState finalState, const CandDsMcGen& mcParticles, int indexMother) + { + float mass{-1.f}, massKaKa{-1.f}, massKaFirstPi{-1.f}, massKaSecondPi{-1.f}; + if (finalState == FinalState::KKPi) { + mass = HfHelper::invMassDsToKKPi(candidate); + massKaKa = HfHelper::massKKPairDsToKKPi(candidate); + massKaFirstPi = HfHelper::massKFirstPiPairDsToKKPi(candidate); + massKaSecondPi = HfHelper::massKSecondPiPairDsToKKPi(candidate); + } else { + mass = HfHelper::invMassDsToPiKK(candidate); + massKaKa = HfHelper::massKKPairDsToPiKK(candidate); + massKaFirstPi = HfHelper::massKFirstPiPairDsToPiKK(candidate); + massKaSecondPi = HfHelper::massKSecondPiPairDsToPiKK(candidate); + } + auto pt = candidate.pt(); + + rowCandidateMini(mass, pt, o2::hf_centrality::getCentralityColl(candidate.template collision_as())); + rowCandidateMassMini(massKaKa, massKaFirstPi, massKaSecondPi); + if (miniTrees.extendWithDecayLength) { + rowCandidateDlMini(candidate.decayLength(), candidate.decayLengthXY(), candidate.decayLengthNormalised(), candidate.decayLengthXYNormalised()); + } + if (miniTrees.extendWithImpactParameter) { + rowCandidateD0Mini(candidate.impactParameterXY()); + } + rowCandidateMcMini(dataType); + + if (miniTrees.extendWithImpactParameter) { + if (indexMother == -1) { // MC mother not found (e.g. combinatorial background), fill dummy value to keep tables aligned + rowCandidateD0McMini(-999.f); + return; + } + auto particleMc = mcParticles.rawIteratorAt(indexMother); + auto prong0 = mcParticles.rawIteratorAt(particleMc.daughtersIds()[0]); + + std::array pv{particleMc.mcCollision().posX(), particleMc.mcCollision().posY(), particleMc.mcCollision().posZ()}; + std::array sv{prong0.vx(), prong0.vy(), prong0.vz()}; + auto genD0 = RecoDecay::impParXY(pv, sv, std::array{particleMc.px(), particleMc.py(), particleMc.pz()}); + rowCandidateD0McMini(genD0); + } + } template void fillEvent(const T& collision, int isEventReject, int runNumber) { @@ -329,8 +524,9 @@ struct HfTreeCreatorDsToKKPi { /// \param doMc true to fill MC information /// \param massHypo mass hypothesis considered: 0 = KKPi, 1 = PiKK /// \param candidate is candidate - template - void fillCandidateTable(const T& candidate) + /// \param mcParticles are the MC particles (only used to fill the MC mini tables) + template + void fillCandidateTable(const T& candidate, const TMcParticles& mcParticles = nullptr) { float invMassDs = 0; float deltaMassPhiKK = 0; @@ -371,9 +567,24 @@ struct HfTreeCreatorDsToKKPi { auto const& collision = candidate.template collision_as(); float centrality = o2::hf_centrality::getCentralityColl(collision); - auto prong0 = candidate.template prong0_as(); - auto prong1 = candidate.template prong1_as(); - auto prong2 = candidate.template prong2_as(); + if (miniTrees.produceMiniTrees) { + constexpr FinalState FinalStateCand = MassHypo == 0 ? FinalState::KKPi : FinalState::PiKK; + if constexpr (DoMc) { + const DataType dataType = getDataType(candidate); + int indexMother{-1}; + if (miniTrees.extendWithImpactParameter) { + indexMother = getIndexMother(candidate, dataType, mcParticles); + } + fillMiniTablesMc(candidate, dataType, FinalStateCand, mcParticles, indexMother); + } else { + fillMiniTables(candidate, FinalStateCand); + } + return; + } + + auto prong0 = candidate.template prong0_as(); + auto prong1 = candidate.template prong1_as(); + auto prong2 = candidate.template prong2_as(); if (fillCandidateLiteTable) { rowCandidateLite( @@ -528,7 +739,7 @@ struct HfTreeCreatorDsToKKPi { continue; } } - fillCandidateTable(candidate); + fillCandidateTable(candidate); } for (const auto& candidate : selectedDsToPiKKCand) { @@ -538,7 +749,7 @@ struct HfTreeCreatorDsToKKPi { continue; } } - fillCandidateTable(candidate); + fillCandidateTable(candidate); } } @@ -564,10 +775,10 @@ struct HfTreeCreatorDsToKKPi { for (const auto& candidate : reconstructedCandSig) { if (candidate.isCandidateSwapped() == 0) { - fillCandidateTable(candidate); + fillCandidateTable(candidate, mcParticles); } if (candidate.isCandidateSwapped() == 1) { - fillCandidateTable(candidate); + fillCandidateTable(candidate, mcParticles); } } } else if (fillOnlyBackground) { @@ -586,10 +797,10 @@ struct HfTreeCreatorDsToKKPi { } // Bkg candidates are not matched to MC so rely on selections only if (candidate.isSelDsToKKPi() >= selectionFlagDs) { - fillCandidateTable(candidate); + fillCandidateTable(candidate, mcParticles); } if (candidate.isSelDsToPiKK() >= selectionFlagDs) { - fillCandidateTable(candidate); + fillCandidateTable(candidate, mcParticles); } } } else { @@ -601,27 +812,27 @@ struct HfTreeCreatorDsToKKPi { for (const auto& candidate : reconstructedCandSig) { if (candidate.isCandidateSwapped() == 0) { - fillCandidateTable(candidate); + fillCandidateTable(candidate, mcParticles); } if (candidate.isCandidateSwapped() == 1) { - fillCandidateTable(candidate); + fillCandidateTable(candidate, mcParticles); } } for (const auto& candidate : reconstructedCandBkg) { // Bkg candidates are not matched to MC so rely on selections only if (candidate.isSelDsToKKPi() >= selectionFlagDs) { - fillCandidateTable(candidate); + fillCandidateTable(candidate, mcParticles); } if (candidate.isSelDsToPiKK() >= selectionFlagDs) { - fillCandidateTable(candidate); + fillCandidateTable(candidate, mcParticles); } } } // Filling particle properties - rowCandidateFullParticles.reserve(mcParticles.size()); - for (const auto& particle : mcParticles) { + rowCandidateFullParticles.reserve(selectedMcParticles.size()); + for (const auto& particle : selectedMcParticles) { rowCandidateFullParticles( particle.mcCollision().bcId(), particle.pt(), @@ -669,7 +880,7 @@ struct HfTreeCreatorDsToKKPi { aod::McCollisions const& mcCollisions, CandDsMcReco const& mcRecoCands, CandDsMcGen const& mcParticles, - TracksWPid const&) + TracksWPidMc const&) { runMc(collisions, mcCollisions, mcRecoCands, mcParticles); } @@ -679,7 +890,7 @@ struct HfTreeCreatorDsToKKPi { aod::McCollisions const& mcCollisions, CandDsMcReco const& mcRecoCands, CandDsMcGen const& mcParticles, - TracksWPid const&) + TracksWPidMc const&) { runMc(collisions, mcCollisions, mcRecoCands, mcParticles); } @@ -689,7 +900,7 @@ struct HfTreeCreatorDsToKKPi { aod::McCollisions const& mcCollisions, CandDsMcReco const& mcRecoCands, CandDsMcGen const& mcParticles, - TracksWPid const&) + TracksWPidMc const&) { runMc(collisions, mcCollisions, mcRecoCands, mcParticles); } @@ -699,7 +910,7 @@ struct HfTreeCreatorDsToKKPi { aod::McCollisions const& mcCollisions, CandDsMcReco const& mcRecoCands, CandDsMcGen const& mcParticles, - TracksWPid const&) + TracksWPidMc const&) { runMc(collisions, mcCollisions, mcRecoCands, mcParticles); }