diff --git a/Common/Core/PID/PIDHelpers.h b/Common/Core/PID/PIDHelpers.h new file mode 100644 index 00000000000..6342c9fae71 --- /dev/null +++ b/Common/Core/PID/PIDHelpers.h @@ -0,0 +1,58 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// \file PIDHelpers.h +/// \brief Lightweight PID helper functions, usable without the full PID modules + +#ifndef COMMON_CORE_PID_PIDHELPERS_H_ +#define COMMON_CORE_PID_PIDHELPERS_H_ + +#include +#include + +#include + +#include + +namespace o2::aod::pid +{ +/// Get O2 PID index corresponding to MC PDG code. +/// \param pdgCode PDG code of the particle (the sign is ignored) +/// \param defaultPid value returned for PDG codes not among the species handled by o2::track::PID +/// (pion by default, as needed for the TPC Tune-on-Data sampling; pass -1 to flag them instead) +inline int getPIDIndex(const int pdgCode, const int defaultPid = o2::track::PID::Pion) +{ + switch (std::abs(pdgCode)) { + case static_cast(kElectron): + return o2::track::PID::Electron; + case static_cast(kMuonMinus): + return o2::track::PID::Muon; + case static_cast(kPiPlus): + return o2::track::PID::Pion; + case static_cast(kKPlus): + return o2::track::PID::Kaon; + case static_cast(kProton): + return o2::track::PID::Proton; + case static_cast(o2::constants::physics::Pdg::kDeuteron): + return o2::track::PID::Deuteron; + case static_cast(o2::constants::physics::Pdg::kTriton): + return o2::track::PID::Triton; + case static_cast(o2::constants::physics::Pdg::kHelium3): + return o2::track::PID::Helium3; + case static_cast(o2::constants::physics::Pdg::kAlpha): + return o2::track::PID::Alpha; + default: + return defaultPid; + } +} +} // namespace o2::aod::pid + +#endif // COMMON_CORE_PID_PIDHELPERS_H_ diff --git a/Common/Tools/PID/pidTPCModule.h b/Common/Tools/PID/pidTPCModule.h index 44234ed5dfa..d79c7ce9479 100644 --- a/Common/Tools/PID/pidTPCModule.h +++ b/Common/Tools/PID/pidTPCModule.h @@ -23,6 +23,7 @@ #include "Common/CCDB/ctpRateFetcher.h" #include "Common/Core/CollisionTypeHelper.h" +#include "Common/Core/PID/PIDHelpers.h" // IWYU pragma: export (getPIDIndex was defined here before) #include "Common/Core/PID/TPCPIDResponse.h" #include "Common/Core/RecoDecay.h" #include "Common/Core/TableHelper.h" @@ -150,33 +151,6 @@ struct pidTPCConfigurables : o2::framework::ConfigurableGroup { o2::framework::Configurable phiEntranceCoeff2{"phiEntranceCoeff2", 85.f, "phiEntrance = phi + phiEntranceCoeff1 * LightSpeedDm2PS * 0.5 * phiEntranceCoeff2 * 1/pT[GeV/c]"}; }; -// helper getter - FIXME should be separate -int getPIDIndex(const int pdgCode) // Get O2 PID index corresponding to MC PDG code -{ - switch (std::abs(pdgCode)) { - case 11: - return o2::track::PID::Electron; - case 13: - return o2::track::PID::Muon; - case 211: - return o2::track::PID::Pion; - case 321: - return o2::track::PID::Kaon; - case 2212: - return o2::track::PID::Proton; - case 1000010020: - return o2::track::PID::Deuteron; - case 1000010030: - return o2::track::PID::Triton; - case 1000020030: - return o2::track::PID::Helium3; - case 1000020040: - return o2::track::PID::Alpha; - default: // treat as pion if not any of the above - return o2::track::PID::Pion; - } -} - typedef struct Str_dEdx_correction { TMatrixD fMatrix; bool warning = true; diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index 18304bd70a6..19996be2311 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -104,6 +104,7 @@ struct TreeWriterTpcV0 { Produces rowTPCTree; Produces rowTPCTreeWithTrkQA; + Produces rowTPCTreeMc; CfgCommon cfgsCommon; @@ -180,13 +181,15 @@ struct TreeWriterTpcV0 { using MyBCTable = soa::Join; using TrksTmo = soa::Join; using TrksTmoWithDEdxCorrection = soa::Join; + using TrksMc = soa::Join; + using TrksTmoMc = soa::Join; Preslice perCollisionV0s = aod::v0data::collisionId; Preslice perCollisionCascs = aod::cascdata::collisionId; void init(o2::framework::InitContext&) { - const std::array doprocess{doprocessStandard, doprocessStandardWithCorrecteddEdx, doprocessWithdEdxTrQA, doprocessWithdEdxTrQAWithCorrecteddEdx, doprocessWithTrQA, doprocessWithTrQAWithCorrecteddEdx, doprocessDummy}; + const std::array doprocess{doprocessStandard, doprocessStandardWithCorrecteddEdx, doprocessWithdEdxTrQA, doprocessWithdEdxTrQAWithCorrecteddEdx, doprocessWithTrQA, doprocessWithTrQAWithCorrecteddEdx, doprocessStandardMc, doprocessWithdEdxTrQAMc, doprocessWithTrQAMc, doprocessDummy}; if (std::accumulate(doprocess.begin(), doprocess.end(), 0) != 1) { LOGP(fatal, "One and only one process function should be enabled"); } @@ -223,18 +226,18 @@ struct TreeWriterTpcV0 { } } - template + template V0Daughter createV0Daughter(const V0Casc& v0Casc, const T& track, const int motherId, const int daughterId, const bool isPositive = true) { switch (daughterId) { case DaughterElectron: - return V0Daughter{track.tpcNSigmaEl(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaEl(), track.tpcExpSignalEl(tpcSignalGeneric(track)), PidElectron, NSigmaTofElectorn + 1.f, false}; + return V0Daughter{track.tpcNSigmaEl(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaEl(), track.tpcExpSignalEl(tpcSignalForPid(track)), PidElectron, NSigmaTofElectorn + 1.f, false}; case DaughterPion: - return V0Daughter{track.tpcNSigmaPi(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaPi(), track.tpcExpSignalPi(tpcSignalGeneric(track)), PidPion, nSigmaTofDauTrackPi, rejectNoTofDauTrackPi}; + return V0Daughter{track.tpcNSigmaPi(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaPi(), track.tpcExpSignalPi(tpcSignalForPid(track)), PidPion, nSigmaTofDauTrackPi, rejectNoTofDauTrackPi}; case DaughterProton: - return V0Daughter{track.tpcNSigmaPr(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaPr(), track.tpcExpSignalPr(tpcSignalGeneric(track)), PidProton, nSigmaTofDauTrackPr, rejectNoTofDauTrackPr}; + return V0Daughter{track.tpcNSigmaPr(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaPr(), track.tpcExpSignalPr(tpcSignalForPid(track)), PidProton, nSigmaTofDauTrackPr, rejectNoTofDauTrackPr}; case DaughterKaon: - return V0Daughter{track.tpcNSigmaKa(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaKa(), track.tpcExpSignalKa(tpcSignalGeneric(track)), PidKaon, nSigmaTofDauTrackKa, rejectNoTofDauTrackKa}; + return V0Daughter{track.tpcNSigmaKa(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaKa(), track.tpcExpSignalKa(tpcSignalForPid(track)), PidKaon, nSigmaTofDauTrackKa, rejectNoTofDauTrackKa}; default: { LOGP(fatal, "createV0Daughter: unknown daughterId"); return {}; @@ -451,9 +454,12 @@ struct TreeWriterTpcV0 { } } - template - void runV0(Colls const& collisions, TrksType const& myTracks, V0sWithID const& myV0s, CascsWithID const& myCascs, TrkQAType const& tracksQA) + template + void runV0(Colls const& collisions, TrksType const& myTracks, V0sWithID const& myV0s, CascsWithID const& myCascs, TrkQAType const& tracksQA, McPartsType const& mcParticles = nullptr) { + constexpr bool IsMc = !std::is_same_v; + static_assert(!(IsMc && IsCorrectedDeDx), "MC mode stores the Tune-on-Data signal, not combinable with the dE/dx correction"); + if (collisions.size() != 0) { const auto timestamp = collisions.begin().bc_as().timestamp(); LOG(info) << "fRndm is seeded with timestamp of the 0-th bunch crossing (" << timestamp << ")"; @@ -484,6 +490,9 @@ struct TreeWriterTpcV0 { } else { rowTPCTreeWithTrkQA.reserve(expectedOutputTableSize); } + if constexpr (IsMc) { + rowTPCTreeMc.reserve(expectedOutputTableSize); + } std::string irSource{}; bool isFirstCollision{true}; @@ -536,7 +545,7 @@ struct TreeWriterTpcV0 { const auto v0Id = getAddId(v0); const V0Mother v0Mother = createV0Mother(v0Id); const auto daughterId = isPositive ? v0Mother.posDaughterId : v0Mother.negDaughterId; - const V0Daughter daughter = createV0Daughter(v0, dauTrackWithITSPid, v0Id, daughterId, isPositive); + const V0Daughter daughter = createV0Daughter(v0, dauTrackWithITSPid, v0Id, daughterId, isPositive); const bool passTrackSelection = isTrackSelected(dauTrack, cfgsCommon.trackSelection); const bool passNSigmaTofCut = std::fabs(daughter.tofNSigma) < daughter.nSigmaTofDauTrack || std::fabs(daughter.tofNSigma - NSigmaTofUnmatched) < nSigmaTofUnmatchedEqualityTolerance; @@ -556,6 +565,11 @@ struct TreeWriterTpcV0 { evaluateOccupancyVariables(dauTrack, occValues); } fillSkimmedV0Table(mother, dauTrack, trackQAInstance, existTrkQA, collision, daughter.tpcNSigma, daughter.tofNSigma, daughter.itsNSigma, daughter.tpcExpSignal, daughter.id, runnumber, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent); + if constexpr (IsMc) { + // one MC row for each row of the main table, to keep them aligned + const McInfo mcInfo = getMcInfo(dauTrack, mcParticles); + rowTPCTreeMc(mcInfo.tunedTpcSignal, mcInfo.pdgCode, mcInfo.motherPdgCode, mcInfo.isPhysicalPrimary, mcInfo.pidIndex); + } return true; } } @@ -673,6 +687,42 @@ struct TreeWriterTpcV0 { } PROCESS_SWITCH(TreeWriterTpcV0, processWithTrQAWithCorrecteddEdx, "Standard V0 Samples with Track QA for PID with corrected dEdx", false); + void processStandardMc(Colls const& collisions, + TrksMc const& myTracks, + V0sWithID const& myV0s, + CascsWithID const& myCascs, + aod::BCsWithTimestamps const&, + aod::McParticles const& mcParticles) + { + runV0(collisions, myTracks, myV0s, myCascs, static_cast(nullptr), mcParticles); + } + PROCESS_SWITCH(TreeWriterTpcV0, processStandardMc, "Standard V0 Samples for PID, MC with Tune-on-Data signal and MC truth", false); + + void processWithdEdxTrQAMc(Colls const& collisions, + TrksMc const& myTracks, + V0sWithID const& myV0s, + CascsWithID const& myCascs, + aod::BCsWithTimestamps const&, + aod::TracksQAVersion const& tracksQA, + aod::McParticles const& mcParticles) + { + runV0(collisions, myTracks, myV0s, myCascs, tracksQA, mcParticles); + } + PROCESS_SWITCH(TreeWriterTpcV0, processWithdEdxTrQAMc, "Standard V0 Samples with dEdx from Track QA for PID, MC with Tune-on-Data signal and MC truth", false); + + void processWithTrQAMc(Colls const& collisions, + TrksTmoMc const& myTracks, + V0sWithID const& myV0s, + CascsWithID const& myCascs, + MyBCTable const&, + aod::TracksQAVersion const& tracksQA, + TrackMeanOccs const&, + aod::McParticles const& mcParticles) + { + runV0(collisions, myTracks, myV0s, myCascs, tracksQA, mcParticles); + } + PROCESS_SWITCH(TreeWriterTpcV0, processWithTrQAMc, "Standard V0 Samples with Track QA for PID, MC with Tune-on-Data signal and MC truth", false); + void processDummy(Colls const&) {} PROCESS_SWITCH(TreeWriterTpcV0, processDummy, "Dummy function", false); @@ -682,6 +732,7 @@ struct TreeWriterTpcTof { Produces rowTPCTOFTree; Produces rowTPCTOFTreeWithTrkQA; + Produces rowTPCTOFTreeMc; CfgCommon cfgsCommon; @@ -758,15 +809,19 @@ struct TreeWriterTpcTof { using MyBCTable = soa::Join; using TrksTmo = soa::Join; using TrksTmoWithDEdxCorrection = soa::Join; + using TrksMc = soa::Join; + using TrksTmoMc = soa::Join; Preslice perCollisionTracks = aod::track::collisionId; Preslice perCollisionTracksWithCorrecteddEdx = aod::track::collisionId; Preslice perCollisionTracksTmo = aod::track::collisionId; Preslice perCollisionTracksTmoWithCorrecteddEdx = aod::track::collisionId; + Preslice perCollisionTracksMc = aod::track::collisionId; + Preslice perCollisionTracksTmoMc = aod::track::collisionId; void init(o2::framework::InitContext&) { - const std::array doprocess{doprocessStandard, doprocessStandardWithCorrecteddEdx, doprocessWithdEdxTrQA, doprocessWithdEdxTrQAWithCorrecteddEdx, doprocessWithTrQA, doprocessWithTrQAWithCorrecteddEdx, doprocessDummy}; + const std::array doprocess{doprocessStandard, doprocessStandardWithCorrecteddEdx, doprocessWithdEdxTrQA, doprocessWithdEdxTrQAWithCorrecteddEdx, doprocessWithTrQA, doprocessWithTrQAWithCorrecteddEdx, doprocessStandardMc, doprocessWithdEdxTrQAMc, doprocessWithTrQAMc, doprocessDummy}; if (std::accumulate(doprocess.begin(), doprocess.end(), 0) != 1) { LOGP(fatal, "One and only one process function should be enabled"); } @@ -898,9 +953,12 @@ struct TreeWriterTpcTof { } } /// fillSkimmedTpcTofTable - template - void runTof(Colls const& collisions, TrksType const& myTracks, TrkQAType const& tracksQA, Preslice const& perCollisionTracksType, TMOType const& trackMeanOccs) + template + void runTof(Colls const& collisions, TrksType const& myTracks, TrkQAType const& tracksQA, Preslice const& perCollisionTracksType, TMOType const& trackMeanOccs, McPartsType const& mcParticles = nullptr) { + constexpr bool IsMc = !std::is_same_v; + static_assert(!(IsMc && IsCorrectedDeDx), "MC mode stores the Tune-on-Data signal, not combinable with the dE/dx correction"); + if (collisions.size() != 0) { const auto timestamp = collisions.begin().bc_as().timestamp(); LOG(info) << "fRndm is seeded with timestamp of the 0-th bunch crossing (" << timestamp << ")"; @@ -924,6 +982,9 @@ struct TreeWriterTpcTof { } else { rowTPCTOFTreeWithTrkQA.reserve(expectedOutputTableSize); } + if constexpr (IsMc) { + rowTPCTOFTreeMc.reserve(expectedOutputTableSize); + } std::string irSource{}; bool isFirstCollision{true}; @@ -975,21 +1036,26 @@ struct TreeWriterTpcTof { trackQA = tracksQA.iteratorAt(trkIndex); } - TofTrack tofTriton(maxMomHardCutOnlyTr, maxMomTPCOnlyTr, trk.tpcNSigmaTr(), nSigmaTPCOnlyTr, trk.tofNSigmaTr(), trk.itsNSigmaTr(), trk.tpcExpSignalTr(tpcSignalGeneric(trk)), PidTriton, nSigmaTofTpctofTr, nSigmaTpcTpctofTr); + TofTrack tofTriton(maxMomHardCutOnlyTr, maxMomTPCOnlyTr, trk.tpcNSigmaTr(), nSigmaTPCOnlyTr, trk.tofNSigmaTr(), trk.itsNSigmaTr(), trk.tpcExpSignalTr(tpcSignalForPid(trk)), PidTriton, nSigmaTofTpctofTr, nSigmaTpcTpctofTr); - TofTrack tofDeuteron(maxMomHardCutOnlyDe, maxMomTPCOnlyDe, trk.tpcNSigmaDe(), nSigmaTPCOnlyDe, trk.tofNSigmaDe(), trk.itsNSigmaDe(), trk.tpcExpSignalDe(tpcSignalGeneric(trk)), PidDeuteron, nSigmaTofTpctofDe, nSigmaTpcTpctofDe); + TofTrack tofDeuteron(maxMomHardCutOnlyDe, maxMomTPCOnlyDe, trk.tpcNSigmaDe(), nSigmaTPCOnlyDe, trk.tofNSigmaDe(), trk.itsNSigmaDe(), trk.tpcExpSignalDe(tpcSignalForPid(trk)), PidDeuteron, nSigmaTofTpctofDe, nSigmaTpcTpctofDe); - TofTrack tofProton(maxMomHardCutOnlyPr, maxMomTPCOnlyPr, trk.tpcNSigmaPr(), nSigmaTPCOnlyPr, trk.tofNSigmaPr(), trk.itsNSigmaPr(), trk.tpcExpSignalPr(tpcSignalGeneric(trk)), PidProton, nSigmaTofTpctofPr, nSigmaTpcTpctofPr); + TofTrack tofProton(maxMomHardCutOnlyPr, maxMomTPCOnlyPr, trk.tpcNSigmaPr(), nSigmaTPCOnlyPr, trk.tofNSigmaPr(), trk.itsNSigmaPr(), trk.tpcExpSignalPr(tpcSignalForPid(trk)), PidProton, nSigmaTofTpctofPr, nSigmaTpcTpctofPr); - TofTrack tofKaon(maxMomHardCutOnlyKa, maxMomTPCOnlyKa, trk.tpcNSigmaKa(), nSigmaTPCOnlyKa, trk.tofNSigmaKa(), trk.itsNSigmaKa(), trk.tpcExpSignalKa(tpcSignalGeneric(trk)), PidKaon, nSigmaTofTpctofKa, nSigmaTpcTpctofKa); + TofTrack tofKaon(maxMomHardCutOnlyKa, maxMomTPCOnlyKa, trk.tpcNSigmaKa(), nSigmaTPCOnlyKa, trk.tofNSigmaKa(), trk.itsNSigmaKa(), trk.tpcExpSignalKa(tpcSignalForPid(trk)), PidKaon, nSigmaTofTpctofKa, nSigmaTpcTpctofKa); - TofTrack tofPion(maxMomHardCutOnlyPi, maxMomTPCOnlyPi, trk.tpcNSigmaPi(), nSigmaTPCOnlyPi, trk.tofNSigmaPi(), trk.itsNSigmaPi(), trk.tpcExpSignalPi(tpcSignalGeneric(trk)), PidPion, nSigmaTofTpctofPi, nSigmaTpcTpctofPi); + TofTrack tofPion(maxMomHardCutOnlyPi, maxMomTPCOnlyPi, trk.tpcNSigmaPi(), nSigmaTPCOnlyPi, trk.tofNSigmaPi(), trk.itsNSigmaPi(), trk.tpcExpSignalPi(tpcSignalForPid(trk)), PidPion, nSigmaTofTpctofPi, nSigmaTpcTpctofPi); OccupancyValues occValues{}; if constexpr (ModeId == ModeWithTrkQA) { evaluateOccupancyVariables(trk, occValues); } + [[maybe_unused]] McInfo mcInfo{}; + if constexpr (IsMc) { + mcInfo = getMcInfo(trk, mcParticles); + } + for (const auto& tofTrack : {&tofTriton, &tofDeuteron, &tofProton, &tofKaon, &tofPion}) { const bool passMomHardCut = trk.tpcInnerParam() < tofTrack->maxMomHardCutOnly; const bool passMomTpcOnly = trk.tpcInnerParam() <= tofTrack->maxMomTPCOnly && std::fabs(tofTrack->tpcNSigma) < tofTrack->nSigmaTPCOnly; @@ -1006,6 +1072,10 @@ struct TreeWriterTpcTof { continue; } fillSkimmedTpcTofTable(trk, trackQA, existTrkQA, collision, tofTrack->tpcNSigma, tofTrack->tofNSigma, tofTrack->itsNSigma, tofTrack->tpcExpSignal, tofTrack->pid, runnumber, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent); + if constexpr (IsMc) { + // one MC row for each row of the main table, to keep them aligned + rowTPCTOFTreeMc(mcInfo.tunedTpcSignal, mcInfo.pdgCode, mcInfo.motherPdgCode, mcInfo.isPhysicalPrimary, mcInfo.pidIndex); + } } } } @@ -1075,6 +1145,36 @@ struct TreeWriterTpcTof { } PROCESS_SWITCH(TreeWriterTpcTof, processWithTrQAWithCorrecteddEdx, "Samples for PID with TrackQA info with correced dEdx", false); + void processStandardMc(Colls const& collisions, + TrksMc const& myTracks, + aod::BCsWithTimestamps const&, + aod::McParticles const& mcParticles) + { + runTof(collisions, myTracks, static_cast(nullptr), perCollisionTracksMc, static_cast(nullptr), mcParticles); + } + PROCESS_SWITCH(TreeWriterTpcTof, processStandardMc, "Standard Samples for PID, MC with Tune-on-Data signal and MC truth", false); + + void processWithdEdxTrQAMc(Colls const& collisions, + TrksMc const& myTracks, + aod::BCsWithTimestamps const&, + aod::TracksQAVersion const& tracksQA, + aod::McParticles const& mcParticles) + { + runTof(collisions, myTracks, tracksQA, perCollisionTracksMc, static_cast(nullptr), mcParticles); + } + PROCESS_SWITCH(TreeWriterTpcTof, processWithdEdxTrQAMc, "Samples for PID with TrackQA info, MC with Tune-on-Data signal and MC truth", false); + + void processWithTrQAMc(Colls const& collisions, + TrksTmoMc const& myTracks, + MyBCTable const&, + aod::TracksQAVersion const& tracksQA, + TrackMeanOccs const& trackMeanOccs, + aod::McParticles const& mcParticles) + { + runTof(collisions, myTracks, tracksQA, perCollisionTracksTmoMc, trackMeanOccs, mcParticles); + } + PROCESS_SWITCH(TreeWriterTpcTof, processWithTrQAMc, "Samples for PID with TrackQA info, MC with Tune-on-Data signal and MC truth", false); + void processDummy(Colls const&) {} PROCESS_SWITCH(TreeWriterTpcTof, processDummy, "Dummy function", false); diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.h b/DPG/Tasks/TPC/tpcSkimsTableCreator.h index 7a46ffa2c9c..34b6cb0ea5a 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.h +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.h @@ -60,6 +60,12 @@ DECLARE_SOA_COLUMN(HadronicRate, hadronicRate, float); DECLARE_SOA_COLUMN(BcGlobalIndex, bcGlobalIndex, int); DECLARE_SOA_COLUMN(BcTimeFrameId, bcTimeFrameId, int); DECLARE_SOA_COLUMN(BcBcInTimeFrame, bcBcInTimeFrame, int); +// MC-only columns +DECLARE_SOA_COLUMN(McTunedTPCSignal, mcTunedTPCSignal, float); //! TPC dE/dx after Tune-on-Data (MC only) +DECLARE_SOA_COLUMN(McPdgCode, mcPdgCode, int); //! PDG code of the associated MC particle (0 if no MC match) +DECLARE_SOA_COLUMN(McMotherPdgCode, mcMotherPdgCode, int); //! PDG code of the first mother of the associated MC particle (0 if none) +DECLARE_SOA_COLUMN(McIsPhysicalPrimary, mcIsPhysicalPrimary, bool); //! Physical-primary flag of the associated MC particle +DECLARE_SOA_COLUMN(McPidIndex, mcPidIndex, int8_t); //! True species as o2::track::PID index (-1 if not e/mu/pi/K/p/d/t/He3/alpha or no MC match) } // namespace tpcskims #define TPCSKIMS_COLUMNS_BASE \ @@ -101,6 +107,13 @@ DECLARE_SOA_COLUMN(BcBcInTimeFrame, bcBcInTimeFrame, int); #define TPCSKIMS_COLUMNS_TOF \ TPCSKIMS_COLUMNS_BASE +#define TPCSKIMS_COLUMNS_MC \ + tpcskims::McTunedTPCSignal, \ + tpcskims::McPdgCode, \ + tpcskims::McMotherPdgCode, \ + tpcskims::McIsPhysicalPrimary, \ + tpcskims::McPidIndex + #define TPCSKIMS_COLUMNS_TRACK_QA \ tpcskims::BcGlobalIndex, \ tpcskims::BcTimeFrameId, \ @@ -139,6 +152,15 @@ DECLARE_SOA_TABLE(SkimmedTPCTOFTreeWithTrkQA, "AOD", "TPCTOFSKIMWQA", TPCSKIMS_COLUMNS_TOF, TPCSKIMS_COLUMNS_TRACK_QA); +// MC companion tables: filled only by the *Mc process functions, one row for each row of +// SkimmedTPCV0Tree(WithTrkQA) / SkimmedTPCTOFTree(WithTrkQA), in the same order (row-aligned, joinable) +DECLARE_SOA_TABLE(SkimmedTPCV0TreeMc, "AOD", "TPCSKIMV0MC", + TPCSKIMS_COLUMNS_MC); + +DECLARE_SOA_TABLE(SkimmedTPCTOFTreeMc, "AOD", "TPCTOFSKIMMC", + TPCSKIMS_COLUMNS_MC); + +#undef TPCSKIMS_COLUMNS_MC #undef TPCSKIMS_COLUMNS_TRACK_QA #undef TPCSKIMS_COLUMNS_TOF #undef TPCSKIMS_COLUMNS_V0 diff --git a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h index 7f959a64e8d..1567e8a8ddc 100644 --- a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h +++ b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h @@ -23,6 +23,7 @@ #include "tpcSkimsTableCreator.h" #include "Common/Core/CollisionTypeHelper.h" +#include "Common/Core/PID/PIDHelpers.h" #include "Common/DataModel/OccupancyTables.h" #include @@ -97,6 +98,48 @@ double tpcSignalGeneric(const TrkType& track) } } +/// TPC signal consistent with the one used by the PID task to evaluate nSigma. +/// In MC with Tune-on-Data the PID task computes nSigma from the tuned signal, +/// so the expected signal (tpcExpSignalXx) must be evaluated from it as well. +template +double tpcSignalForPid(const TrkType& track) +{ + if constexpr (IsMc) { + return track.mcTunedTPCSignal(); + } else { + return tpcSignalGeneric(track); + } +} + +/// MC truth information stored in the MC companion tables +struct McInfo { + float tunedTpcSignal{UndefValueFloat}; + int pdgCode{0}; + int motherPdgCode{0}; + bool isPhysicalPrimary{false}; + int8_t pidIndex{-1}; +}; + +/// Collect MC information of a track (requires McTrackLabels and mcTPCTuneOnData joined to the track table) +template +McInfo getMcInfo(const TrkType& track, const McPartsType& mcParticles) +{ + McInfo info{}; + info.tunedTpcSignal = track.mcTunedTPCSignal(); + if (!track.has_mcParticle()) { + return info; + } + // explicit lookup: robust also for tables built with soa::Attach, which do not carry the index binding + const auto mcParticle = mcParticles.rawIteratorAt(track.mcParticleId()); + info.pdgCode = mcParticle.pdgCode(); + info.isPhysicalPrimary = mcParticle.isPhysicalPrimary(); + info.pidIndex = static_cast(o2::aod::pid::getPIDIndex(info.pdgCode, -1)); // -1: not a species handled by o2::track::PID + if (mcParticle.has_mothers()) { + info.motherPdgCode = mcParticles.rawIteratorAt(mcParticle.mothersIds().front()).pdgCode(); + } + return info; +} + /// Determine interaction rate source from CCDB std::string evaluateIrSource(const o2::framework::Service& ccdb, const std::string& ccdbPathGrpLhcIf, const uint64_t timestamp) {