From 6ad4fd0ef02f09c9116edea9b990b315e5e450bb Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Thu, 19 Nov 2026 23:42:59 +0100 Subject: [PATCH 01/22] enable save momentum histograms --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 57 ++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index ec4c98f2d6d..6b93ca8c47a 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -114,6 +114,9 @@ struct TreeWriterTpcV0 { Configurable requireGoodRct{"requireGoodRct", false, "require good detector flag in run condtion table"}; // Configurable for the path of CCDB General Run Parameters LHC Interface information Configurable ccdbPathGrpLhcIf{"ccdbPathGrpLhcIf", "GLO/Config/GRPLHCIF", "Path on the CCDB for the GRPLHCIF object"}; + // Configurables flagging saving trees and/or HistogramSpec + Configurable saveTrees{"saveTrees", true, "Flag to save trees"}; + Configurable saveMomentumHistograms{"saveMomentumHistograms", false, "Flag to save momentum histograms"}; HistogramRegistry registry{"registry", {}}; @@ -185,6 +188,10 @@ struct TreeWriterTpcV0 { LOGP(fatal, "One and only one process function should be enabled"); } + if (!(saveTrees || saveMomentumHistograms)) { + LOGP(fatal, "At least one out of trees or momentum histograms should be saved"); + } + ccdb->setURL("http://alice-ccdb.cern.ch"); ccdb->setCaching(true); ccdb->setFatalWhenNull(false); @@ -195,6 +202,11 @@ struct TreeWriterTpcV0 { registry.add("hV0OutputRatio", "V0 out/in ratio;V0 out/in ratio;Entries", {HistType::kTH1F, {{100, 0, reserveV0Ratio}}}); registry.add("hCascOutputRatio", "Casc out/in ratio;Casc out/in ratio;Entries", {HistType::kTH1F, {{100, 0, reserveCascRatio}}}); } + + if (saveMomentumHistograms) { + registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2F, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2F, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + } } template @@ -509,13 +521,23 @@ struct TreeWriterTpcV0 { const bool passDownsamplig = downsampleTsalisCharged(fRndm, dauTrack.pt(), daughter.downsamplingTsalis, daughter.mass, sqrtSNN, daughter.maxPt4dwnsmplTsalis); const bool passNSigmaTofCut = std::fabs(daughter.tofNSigma) < daughter.nSigmaTofDauTrack || std::fabs(daughter.tofNSigma - NSigmaTofUnmatched) < nSigmaTofUnmatchedEqualityTolerance; const bool passMatchTofRequirement = !daughter.rejectNoTofDauTrack || std::fabs(daughter.tofNSigma - NSigmaTofUnmatched) > nSigmaTofUnmatchedEqualityTolerance; - if (passTrackSelection && passDownsamplig && passNSigmaTofCut && passMatchTofRequirement) { - OccupancyValues occValues{}; - if constexpr (ModeId == ModeWithTrkQA) { - evaluateOccupancyVariables(dauTrack, occValues); + if (passTrackSelection && passNSigmaTofCut && passMatchTofRequirement) { + if (saveMomentumHistograms) { + const double log10p = std::log10(dauTrack.tpcInnerParam()); + if (isPositive) { + registry.fill(HIST("hMomentumPos"), log10p, daughterId); + } else { + registry.fill(HIST("hMomentumNeg"), log10p, daughterId); + } + } + if (saveTrees && passDownsamplig) { + OccupancyValues occValues{}; + if constexpr (ModeId == ModeWithTrkQA) { + evaluateOccupancyVariables(dauTrack, occValues); + } + fillSkimmedV0Table(mother, dauTrack, trackQAInstance, existTrkQA, collision, daughter.tpcNSigma, daughter.tofNSigma, daughter.itsNSigma, daughter.tpcExpSignal, daughter.id, runnumber, daughter.dwnSmplFactor, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent); + return true; } - fillSkimmedV0Table(mother, dauTrack, trackQAInstance, existTrkQA, collision, daughter.tpcNSigma, daughter.tofNSigma, daughter.itsNSigma, daughter.tpcExpSignal, daughter.id, runnumber, daughter.dwnSmplFactor, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent); - return true; } return false; }; @@ -694,6 +716,9 @@ struct TreeWriterTpcTof { Configurable requireGoodRct{"requireGoodRct", false, "require good detector flag in run condtion table"}; // Configurable for the path of CCDB General Run Parameters LHC Interface information Configurable ccdbPathGrpLhcIf{"ccdbPathGrpLhcIf", "GLO/Config/GRPLHCIF", "Path on the CCDB for the GRPLHCIF object"}; + // Configurables flagging saving trees and/or HistogramSpec + Configurable saveTrees{"saveTrees", true, "Flag to save trees"}; + Configurable saveMomentumHistograms{"saveMomentumHistograms", false, "Flag to save momentum histograms"}; HistogramRegistry registry{"registry", {}}; @@ -755,6 +780,11 @@ struct TreeWriterTpcTof { if (saveReserveQaHisto) { registry.add("hTrackOutputRatio", "Track out/in ratio;Track out/in ratio;Entries", {HistType::kTH1F, {{100, 0, reserveTrackRatio}}}); } + + if (saveMomentumHistograms) { + registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2F, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2F, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + } } template @@ -951,8 +981,19 @@ struct TreeWriterTpcTof { const bool passMomTpcOnly = trk.tpcInnerParam() <= tofTrack->maxMomTPCOnly && std::fabs(tofTrack->tpcNSigma) < tofTrack->nSigmaTPCOnly; const bool passMomTpcTof = trk.tpcInnerParam() > tofTrack->maxMomTPCOnly && std::fabs(tofTrack->tofNSigma) < tofTrack->nSigmaTofTpctof && std::fabs(tofTrack->tpcNSigma) < tofTrack->nSigmaTpcTpctof; const bool passDownsamplig = downsampleTsalisCharged(fRndm, trk.pt(), tofTrack->downsamplingTsalis, tofTrack->mass, sqrtSNN); - if (passMomHardCut && (passMomTpcOnly || passMomTpcTof) && passDownsamplig) { - fillSkimmedTpcTofTable(trk, trackQA, existTrkQA, collision, tofTrack->tpcNSigma, tofTrack->tofNSigma, tofTrack->itsNSigma, tofTrack->tpcExpSignal, tofTrack->pid, runnumber, tofTrack->dwnSmplFactor, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent); + if (passMomHardCut && (passMomTpcOnly || passMomTpcTof)) { + if (saveMomentumHistograms) { + const double log10p = std::log10(trk.tpcInnerParam()); + const bool isPositive = (trk.signed1Pt() > 0); + if (isPositive) { + registry.fill(HIST("hMomentumPos"), log10p, tofTrack->pid); + } else { + registry.fill(HIST("hMomentumNeg"), log10p, tofTrack->pid); + } + } + if (saveTrees && passDownsamplig) { + fillSkimmedTpcTofTable(trk, trackQA, existTrkQA, collision, tofTrack->tpcNSigma, tofTrack->tofNSigma, tofTrack->itsNSigma, tofTrack->tpcExpSignal, tofTrack->pid, runnumber, tofTrack->dwnSmplFactor, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent); + } } } } /// Loop tracks From bc92b06203264801f9e6a96478c072368cb7e057 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Thu, 19 Nov 2026 23:52:55 +0100 Subject: [PATCH 02/22] add guard against empty output run --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index 6b93ca8c47a..f341c7bf326 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -771,6 +771,10 @@ struct TreeWriterTpcTof { LOGP(fatal, "One and only one process function should be enabled"); } + if (!(saveTrees || saveMomentumHistograms)) { + LOGP(fatal, "At least one out of trees or momentum histograms should be saved"); + } + ccdb->setURL("http://alice-ccdb.cern.ch"); ccdb->setCaching(true); ccdb->setFatalWhenNull(false); From c3282ee5421828825b4b31d582357c6d6fccffaf Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Fri, 20 Nov 2026 00:40:49 +0100 Subject: [PATCH 03/22] v0: read adaptive dwnspl histograms from ccdb --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index f341c7bf326..1b428862c35 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -37,6 +37,7 @@ #include "Common/TableProducer/PID/pidTPCBase.h" #include +#include #include #include #include @@ -48,6 +49,8 @@ #include #include +#include +#include #include #include @@ -55,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -91,6 +95,9 @@ struct TreeWriterTpcV0 { Configurable applyEvSel{"applyEvSel", 2, "Flag to apply rapidity cut: 0 -> no event selection, 1 -> Run 2 event selection, 2 -> Run 3 event selection"}; Configurable trackSelection{"trackSelection", 0, "Track selection: 0 -> No Cut, 1 -> kGlobalTrack, 2 -> kGlobalTrackWoPtEta, 3 -> kGlobalTrackWoDCA, 4 -> kQualityTracks, 5 -> kInAcceptanceTracks"}; /// Configurables downsampling + Configurable applyAdaptiveDownsampling{"applyAdaptiveDownsampling", false, "Apply downsampling driven by expected momentum distribution"}; + Configurable ccdbPathForAdaptDwnsplFile{"ccdbPathForAdaptDwnsplFile", "", "CCDB path for file with expected-momentum histograms"}; + Configurable adaptDwnsplFileName{"adaptDwnsplFileName", "AnalysisResults.root", "Name of the file with expected-momentum histograms"}; Configurable dwnSmplFactorPi{"dwnSmplFactorPi", 1., "downsampling factor for pions, default fraction to keep is 1."}; Configurable dwnSmplFactorPr{"dwnSmplFactorPr", 1., "downsampling factor for protons, default fraction to keep is 1."}; Configurable dwnSmplFactorEl{"dwnSmplFactorEl", 1., "downsampling factor for electrons, default fraction to keep is 1."}; @@ -164,6 +171,7 @@ struct TreeWriterTpcV0 { }; Service ccdb{}; + o2::ccdb::CcdbApi ccdbApi; ctpRateFetcher mRateFetcher{}; @@ -171,6 +179,9 @@ struct TreeWriterTpcV0 { TRandom3* fRndm = new TRandom3(); + TH2* mHistMomentumPos{}; + TH2* mHistMomentumNeg{}; + using Trks = soa::Join; using TrksWithDEdxCorrection = soa::Join; using Colls = soa::Join; @@ -207,6 +218,37 @@ struct TreeWriterTpcV0 { registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2F, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2F, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); } + + if (applyAdaptiveDownsampling) { + ccdbApi.init("http://alice-ccdb.cern.ch"); + const std::map metadata; + // Retrieve the file from CCDB + const bool isFileAvailable = ccdbApi.retrieveBlob(ccdbPathForAdaptDwnsplFile, ".", metadata, -1, false, adaptDwnsplFileName); + if (!isFileAvailable) { + LOGF(fatal, "Failed to retrieve expected-momentum histograms file from CCDB: %s/%s", ccdbPathForAdaptDwnsplFile.value.c_str(), adaptDwnsplFileName.value.c_str()); + return; + } + TFile* adaptDwsplFile = TFile::Open(adaptDwnsplFileName.value.c_str(), "read"); + if (adaptDwsplFile == nullptr || adaptDwsplFile->IsZombie()) { + LOGF(fatal, "Failed to open expected-momentum histograms file from CCDB: %s/%s", ccdbPathForAdaptDwnsplFile.value.c_str(), adaptDwnsplFileName.value.c_str()); + return; + } + mHistMomentumPos = dynamic_cast(adaptDwsplFile->Get("tree-writer-tpc-v0/hMomentumPos")->Clone()); // TODO make Configurable + mHistMomentumNeg = dynamic_cast(adaptDwsplFile->Get("tree-writer-tpc-v0/hMomentumNeg")->Clone()); + if (mHistMomentumPos == nullptr) { + LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", "tree-writer-tpc-v0/hMomentumPos"); + return; + } + if (mHistMomentumNeg == nullptr) { + LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", "tree-writer-tpc-v0/hMomentumNeg"); + return; + } + mHistMomentumPos->SetDirectory(nullptr); + mHistMomentumNeg->SetDirectory(nullptr); + adaptDwsplFile->Close(); + delete adaptDwsplFile; + adaptDwsplFile = nullptr; + } } template From 13bfa39edd22d8e24df52eab6e59973bb504fcda Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Fri, 20 Nov 2026 12:41:19 +0100 Subject: [PATCH 04/22] hMomentum(Pos,Neg): TH2F->TH2D --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index 1b428862c35..63fe93db9c5 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -215,8 +215,8 @@ struct TreeWriterTpcV0 { } if (saveMomentumHistograms) { - registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2F, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); - registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2F, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); } if (applyAdaptiveDownsampling) { @@ -828,8 +828,8 @@ struct TreeWriterTpcTof { } if (saveMomentumHistograms) { - registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2F, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); - registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2F, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); } } From 222c25119f8687d77d2885d81a1aba10462fca3c Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Fri, 20 Nov 2026 18:56:36 +0100 Subject: [PATCH 05/22] v0: bugfix pid --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index 63fe93db9c5..49345443649 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -567,9 +567,9 @@ struct TreeWriterTpcV0 { if (saveMomentumHistograms) { const double log10p = std::log10(dauTrack.tpcInnerParam()); if (isPositive) { - registry.fill(HIST("hMomentumPos"), log10p, daughterId); + registry.fill(HIST("hMomentumPos"), log10p, daughter.id); } else { - registry.fill(HIST("hMomentumNeg"), log10p, daughterId); + registry.fill(HIST("hMomentumNeg"), log10p, daughter.id); } } if (saveTrees && passDownsamplig) { From dd7c6fdaeaaef4c620a07ebb30bc34ad70d90727 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Fri, 20 Nov 2026 19:25:54 +0100 Subject: [PATCH 06/22] label particle axis --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 8 ++++++++ DPG/Tasks/TPC/tpcSkimsTableCreator.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index 49345443649..8564a1bd587 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -217,6 +217,10 @@ struct TreeWriterTpcV0 { if (saveMomentumHistograms) { registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + for (int iParticle = 0; iParticle < o2::track::PID::NIDs; ++iParticle) { + registry.get(HIST("hMomentumPos"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); + registry.get(HIST("hMomentumNeg"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); + } } if (applyAdaptiveDownsampling) { @@ -830,6 +834,10 @@ struct TreeWriterTpcTof { if (saveMomentumHistograms) { registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + for (int iParticle = 0; iParticle < o2::track::PID::NIDs; ++iParticle) { + registry.get(HIST("hMomentumPos"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); + registry.get(HIST("hMomentumNeg"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); + } } } diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.h b/DPG/Tasks/TPC/tpcSkimsTableCreator.h index 9172d8d2447..3778fd663f0 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.h +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.h @@ -25,7 +25,9 @@ #include #include +#include #include +#include namespace o2::aod { @@ -163,5 +165,7 @@ constexpr double UndefValueDouble{-999.}; constexpr double MultiplicityNorm{11000.}; constexpr float OneToKilo{1e-3f}; + +constexpr std::array ParticleNames{"e", "#mu", "#pi", "K", "p", "d", "t", "{}^{3}He", "#alpha"}; } // namespace o2::dpg_tpcskimstablecreator #endif // DPG_TASKS_TPC_TPCSKIMSTABLECREATOR_H_ From 30206cf0781251d93894a79bbfb4dfa2970a1389 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Fri, 20 Nov 2026 19:51:00 +0100 Subject: [PATCH 07/22] make hardcoded things configurable --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index 8564a1bd587..34de5805514 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -94,10 +94,13 @@ struct TreeWriterTpcV0 { Configurable nClNorm{"nClNorm", 152., "Number of cluster normalization. Run 2: 159, Run 3 152"}; Configurable applyEvSel{"applyEvSel", 2, "Flag to apply rapidity cut: 0 -> no event selection, 1 -> Run 2 event selection, 2 -> Run 3 event selection"}; Configurable trackSelection{"trackSelection", 0, "Track selection: 0 -> No Cut, 1 -> kGlobalTrack, 2 -> kGlobalTrackWoPtEta, 3 -> kGlobalTrackWoDCA, 4 -> kQualityTracks, 5 -> kInAcceptanceTracks"}; - /// Configurables downsampling + /// Configurables adaptive downsampling Configurable applyAdaptiveDownsampling{"applyAdaptiveDownsampling", false, "Apply downsampling driven by expected momentum distribution"}; Configurable ccdbPathForAdaptDwnsplFile{"ccdbPathForAdaptDwnsplFile", "", "CCDB path for file with expected-momentum histograms"}; Configurable adaptDwnsplFileName{"adaptDwnsplFileName", "AnalysisResults.root", "Name of the file with expected-momentum histograms"}; + Configurable adaptDwnsplHistoPosName{"adaptDwnsplHistoPosName", "tree-writer-tpc-v0/hMomentumPos", "Name of the histogram with expected-momentum of positively charged particles"}; + Configurable adaptDwnsplHistoNegName{"adaptDwnsplHistoNegName", "tree-writer-tpc-v0/hMomentumNeg", "Name of the histogram with expected-momentum of negatively charged particles"}; + /// Configurables downsampling Configurable dwnSmplFactorPi{"dwnSmplFactorPi", 1., "downsampling factor for pions, default fraction to keep is 1."}; Configurable dwnSmplFactorPr{"dwnSmplFactorPr", 1., "downsampling factor for protons, default fraction to keep is 1."}; Configurable dwnSmplFactorEl{"dwnSmplFactorEl", 1., "downsampling factor for electrons, default fraction to keep is 1."}; @@ -124,6 +127,7 @@ struct TreeWriterTpcV0 { // Configurables flagging saving trees and/or HistogramSpec Configurable saveTrees{"saveTrees", true, "Flag to save trees"}; Configurable saveMomentumHistograms{"saveMomentumHistograms", false, "Flag to save momentum histograms"}; + ConfigurableAxis axisMomentumHistograms{"axisMomentumHistograms", {200, std::log10(0.1), std::log10(20.)}, "log_{10}(#it{p} / (GeV/#it{c}))"}; HistogramRegistry registry{"registry", {}}; @@ -215,8 +219,8 @@ struct TreeWriterTpcV0 { } if (saveMomentumHistograms) { - registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); - registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); for (int iParticle = 0; iParticle < o2::track::PID::NIDs; ++iParticle) { registry.get(HIST("hMomentumPos"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); registry.get(HIST("hMomentumNeg"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); @@ -237,14 +241,14 @@ struct TreeWriterTpcV0 { LOGF(fatal, "Failed to open expected-momentum histograms file from CCDB: %s/%s", ccdbPathForAdaptDwnsplFile.value.c_str(), adaptDwnsplFileName.value.c_str()); return; } - mHistMomentumPos = dynamic_cast(adaptDwsplFile->Get("tree-writer-tpc-v0/hMomentumPos")->Clone()); // TODO make Configurable - mHistMomentumNeg = dynamic_cast(adaptDwsplFile->Get("tree-writer-tpc-v0/hMomentumNeg")->Clone()); + mHistMomentumPos = dynamic_cast(adaptDwsplFile->Get(adaptDwnsplHistoPosName.value.c_str())->Clone()); + mHistMomentumNeg = dynamic_cast(adaptDwsplFile->Get(adaptDwnsplHistoNegName.value.c_str())->Clone()); if (mHistMomentumPos == nullptr) { - LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", "tree-writer-tpc-v0/hMomentumPos"); + LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", adaptDwnsplHistoPosName.value.c_str()); return; } if (mHistMomentumNeg == nullptr) { - LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", "tree-writer-tpc-v0/hMomentumNeg"); + LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", adaptDwnsplHistoNegName.value.c_str()); return; } mHistMomentumPos->SetDirectory(nullptr); @@ -765,6 +769,7 @@ struct TreeWriterTpcTof { // Configurables flagging saving trees and/or HistogramSpec Configurable saveTrees{"saveTrees", true, "Flag to save trees"}; Configurable saveMomentumHistograms{"saveMomentumHistograms", false, "Flag to save momentum histograms"}; + ConfigurableAxis axisMomentumHistograms{"axisMomentumHistograms", {200, std::log10(0.1), std::log10(20.)}, "log_{10}(#it{p} / (GeV/#it{c}))"}; HistogramRegistry registry{"registry", {}}; @@ -832,8 +837,8 @@ struct TreeWriterTpcTof { } if (saveMomentumHistograms) { - registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); - registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{200, std::log10(0.1), std::log10(20.)}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); for (int iParticle = 0; iParticle < o2::track::PID::NIDs; ++iParticle) { registry.get(HIST("hMomentumPos"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); registry.get(HIST("hMomentumNeg"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); From 941b46f2c302f91ddde7ebe36bddc8cf0dba9dc9 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Fri, 20 Nov 2026 23:23:48 +0100 Subject: [PATCH 08/22] factor out initAdaptDwnsplHistograms(), extend to tpctof --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 46 +++++++---------------- DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h | 37 ++++++++++++++++++ 2 files changed, 51 insertions(+), 32 deletions(-) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index 34de5805514..707188efdee 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -37,7 +37,6 @@ #include "Common/TableProducer/PID/pidTPCBase.h" #include -#include #include #include #include @@ -49,7 +48,6 @@ #include #include -#include #include #include #include @@ -58,7 +56,6 @@ #include #include #include -#include #include #include #include @@ -175,7 +172,6 @@ struct TreeWriterTpcV0 { }; Service ccdb{}; - o2::ccdb::CcdbApi ccdbApi; ctpRateFetcher mRateFetcher{}; @@ -228,34 +224,7 @@ struct TreeWriterTpcV0 { } if (applyAdaptiveDownsampling) { - ccdbApi.init("http://alice-ccdb.cern.ch"); - const std::map metadata; - // Retrieve the file from CCDB - const bool isFileAvailable = ccdbApi.retrieveBlob(ccdbPathForAdaptDwnsplFile, ".", metadata, -1, false, adaptDwnsplFileName); - if (!isFileAvailable) { - LOGF(fatal, "Failed to retrieve expected-momentum histograms file from CCDB: %s/%s", ccdbPathForAdaptDwnsplFile.value.c_str(), adaptDwnsplFileName.value.c_str()); - return; - } - TFile* adaptDwsplFile = TFile::Open(adaptDwnsplFileName.value.c_str(), "read"); - if (adaptDwsplFile == nullptr || adaptDwsplFile->IsZombie()) { - LOGF(fatal, "Failed to open expected-momentum histograms file from CCDB: %s/%s", ccdbPathForAdaptDwnsplFile.value.c_str(), adaptDwnsplFileName.value.c_str()); - return; - } - mHistMomentumPos = dynamic_cast(adaptDwsplFile->Get(adaptDwnsplHistoPosName.value.c_str())->Clone()); - mHistMomentumNeg = dynamic_cast(adaptDwsplFile->Get(adaptDwnsplHistoNegName.value.c_str())->Clone()); - if (mHistMomentumPos == nullptr) { - LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", adaptDwnsplHistoPosName.value.c_str()); - return; - } - if (mHistMomentumNeg == nullptr) { - LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", adaptDwnsplHistoNegName.value.c_str()); - return; - } - mHistMomentumPos->SetDirectory(nullptr); - mHistMomentumNeg->SetDirectory(nullptr); - adaptDwsplFile->Close(); - delete adaptDwsplFile; - adaptDwsplFile = nullptr; + initAdaptDwnsplHistograms(ccdbPathForAdaptDwnsplFile, adaptDwnsplFileName, adaptDwnsplHistoPosName, adaptDwnsplHistoNegName, mHistMomentumPos, mHistMomentumNeg); } } @@ -770,6 +739,12 @@ struct TreeWriterTpcTof { Configurable saveTrees{"saveTrees", true, "Flag to save trees"}; Configurable saveMomentumHistograms{"saveMomentumHistograms", false, "Flag to save momentum histograms"}; ConfigurableAxis axisMomentumHistograms{"axisMomentumHistograms", {200, std::log10(0.1), std::log10(20.)}, "log_{10}(#it{p} / (GeV/#it{c}))"}; + /// Configurables adaptive downsampling + Configurable applyAdaptiveDownsampling{"applyAdaptiveDownsampling", false, "Apply downsampling driven by expected momentum distribution"}; + Configurable ccdbPathForAdaptDwnsplFile{"ccdbPathForAdaptDwnsplFile", "", "CCDB path for file with expected-momentum histograms"}; + Configurable adaptDwnsplFileName{"adaptDwnsplFileName", "AnalysisResults.root", "Name of the file with expected-momentum histograms"}; + Configurable adaptDwnsplHistoPosName{"adaptDwnsplHistoPosName", "tree-writer-tpc-tof/hMomentumPos", "Name of the histogram with expected-momentum of positively charged particles"}; + Configurable adaptDwnsplHistoNegName{"adaptDwnsplHistoNegName", "tree-writer-tpc-tof/hMomentumNeg", "Name of the histogram with expected-momentum of negatively charged particles"}; HistogramRegistry registry{"registry", {}}; @@ -798,6 +773,9 @@ struct TreeWriterTpcTof { TRandom3* fRndm = new TRandom3(); + TH2* mHistMomentumPos{}; + TH2* mHistMomentumNeg{}; + using Trks = soa::Join(HIST("hMomentumNeg"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); } } + + if (applyAdaptiveDownsampling) { + initAdaptDwnsplHistograms(ccdbPathForAdaptDwnsplFile, adaptDwnsplFileName, adaptDwnsplHistoPosName, adaptDwnsplHistoNegName, mHistMomentumPos, mHistMomentumNeg); + } } template diff --git a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h index a3b3dcddc17..2448f0afeab 100644 --- a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h +++ b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h @@ -26,15 +26,19 @@ #include "Common/DataModel/OccupancyTables.h" #include +#include #include #include #include #include +#include +#include #include #include #include +#include #include namespace o2::dpg_tpcskimstablecreator @@ -175,5 +179,38 @@ void evaluateOccupancyVariables(const TrkType& track, OccupancyValues& occValues occValues.twmoRT0V0PrimUnfm80 = tmoFromTrack.twmoRobustT0V0PrimUnfm80(); } +inline void initAdaptDwnsplHistograms(const std::string& ccdbPathForAdaptDwnsplFile, const std::string& adaptDwnsplFileName, const std::string& adaptDwnsplHistoPosName, const std::string& adaptDwnsplHistoNegName, TH2*& histoPos, TH2*& histoNeg) +{ + o2::ccdb::CcdbApi ccdbApi; + ccdbApi.init("http://alice-ccdb.cern.ch"); + const std::map metadata; + // Retrieve the file from CCDB + const bool isFileAvailable = ccdbApi.retrieveBlob(ccdbPathForAdaptDwnsplFile, ".", metadata, -1, false, adaptDwnsplFileName); + if (!isFileAvailable) { + LOGF(fatal, "Failed to retrieve expected-momentum histograms file from CCDB: %s/%s", ccdbPathForAdaptDwnsplFile.c_str(), adaptDwnsplFileName.c_str()); + return; + } + TFile* adaptDwsplFile = TFile::Open(adaptDwnsplFileName.c_str(), "read"); + if (adaptDwsplFile == nullptr || adaptDwsplFile->IsZombie()) { + LOGF(fatal, "Failed to open expected-momentum histograms file from CCDB: %s/%s", ccdbPathForAdaptDwnsplFile.c_str(), adaptDwnsplFileName.c_str()); + return; + } + histoPos = dynamic_cast(adaptDwsplFile->Get(adaptDwnsplHistoPosName.c_str())->Clone()); + histoNeg = dynamic_cast(adaptDwsplFile->Get(adaptDwnsplHistoNegName.c_str())->Clone()); + if (histoPos == nullptr) { + LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", adaptDwnsplHistoPosName.c_str()); + return; + } + if (histoNeg == nullptr) { + LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", adaptDwnsplHistoNegName.c_str()); + return; + } + histoPos->SetDirectory(nullptr); + histoNeg->SetDirectory(nullptr); + adaptDwsplFile->Close(); + delete adaptDwsplFile; + adaptDwsplFile = nullptr; +} + } // namespace o2::dpg_tpcskimstablecreator #endif // DPG_TASKS_TPC_UTILSTPCSKIMSTABLECREATOR_H_ From dbf856012179376cc799a42ecd58deab7efb4579 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Fri, 20 Nov 2026 23:44:52 +0100 Subject: [PATCH 09/22] introduce adaptDwnsplHistoScaleFactor --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index 707188efdee..81091b886bb 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -97,6 +97,7 @@ struct TreeWriterTpcV0 { Configurable adaptDwnsplFileName{"adaptDwnsplFileName", "AnalysisResults.root", "Name of the file with expected-momentum histograms"}; Configurable adaptDwnsplHistoPosName{"adaptDwnsplHistoPosName", "tree-writer-tpc-v0/hMomentumPos", "Name of the histogram with expected-momentum of positively charged particles"}; Configurable adaptDwnsplHistoNegName{"adaptDwnsplHistoNegName", "tree-writer-tpc-v0/hMomentumNeg", "Name of the histogram with expected-momentum of negatively charged particles"}; + Configurable adaptDwnsplHistoScaleFactor{"adaptDwnsplHistoScaleFactor", 1.f, "Scaling factor for the histograms with expected-momentum"}; /// Configurables downsampling Configurable dwnSmplFactorPi{"dwnSmplFactorPi", 1., "downsampling factor for pions, default fraction to keep is 1."}; Configurable dwnSmplFactorPr{"dwnSmplFactorPr", 1., "downsampling factor for protons, default fraction to keep is 1."}; @@ -225,6 +226,10 @@ struct TreeWriterTpcV0 { if (applyAdaptiveDownsampling) { initAdaptDwnsplHistograms(ccdbPathForAdaptDwnsplFile, adaptDwnsplFileName, adaptDwnsplHistoPosName, adaptDwnsplHistoNegName, mHistMomentumPos, mHistMomentumNeg); + if (adaptDwnsplHistoScaleFactor != 1.f) { + mHistMomentumPos->Scale(adaptDwnsplHistoScaleFactor); + mHistMomentumNeg->Scale(adaptDwnsplHistoScaleFactor); + } } } @@ -745,6 +750,7 @@ struct TreeWriterTpcTof { Configurable adaptDwnsplFileName{"adaptDwnsplFileName", "AnalysisResults.root", "Name of the file with expected-momentum histograms"}; Configurable adaptDwnsplHistoPosName{"adaptDwnsplHistoPosName", "tree-writer-tpc-tof/hMomentumPos", "Name of the histogram with expected-momentum of positively charged particles"}; Configurable adaptDwnsplHistoNegName{"adaptDwnsplHistoNegName", "tree-writer-tpc-tof/hMomentumNeg", "Name of the histogram with expected-momentum of negatively charged particles"}; + Configurable adaptDwnsplHistoScaleFactor{"adaptDwnsplHistoScaleFactor", 1.f, "Scaling factor for the histograms with expected-momentum"}; HistogramRegistry registry{"registry", {}}; @@ -825,6 +831,10 @@ struct TreeWriterTpcTof { if (applyAdaptiveDownsampling) { initAdaptDwnsplHistograms(ccdbPathForAdaptDwnsplFile, adaptDwnsplFileName, adaptDwnsplHistoPosName, adaptDwnsplHistoNegName, mHistMomentumPos, mHistMomentumNeg); + if (adaptDwnsplHistoScaleFactor != 1.f) { + mHistMomentumPos->Scale(adaptDwnsplHistoScaleFactor); + mHistMomentumNeg->Scale(adaptDwnsplHistoScaleFactor); + } } } From e91aba58b203cd204aa605cf5332cebc871ec7f8 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Sun, 22 Nov 2026 19:23:51 +0100 Subject: [PATCH 10/22] apply adaptive downsampling --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 10 ++++++++++ DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h | 23 +++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index 81091b886bb..c9020fc060d 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -98,6 +98,7 @@ struct TreeWriterTpcV0 { Configurable adaptDwnsplHistoPosName{"adaptDwnsplHistoPosName", "tree-writer-tpc-v0/hMomentumPos", "Name of the histogram with expected-momentum of positively charged particles"}; Configurable adaptDwnsplHistoNegName{"adaptDwnsplHistoNegName", "tree-writer-tpc-v0/hMomentumNeg", "Name of the histogram with expected-momentum of negatively charged particles"}; Configurable adaptDwnsplHistoScaleFactor{"adaptDwnsplHistoScaleFactor", 1.f, "Scaling factor for the histograms with expected-momentum"}; + Configurable adaptDwnsplTargetYield{"adaptDwnsplTargetYield", 5000000.f, "Target yield of each particle species per log10(p) unity"}; /// Configurables downsampling Configurable dwnSmplFactorPi{"dwnSmplFactorPi", 1., "downsampling factor for pions, default fraction to keep is 1."}; Configurable dwnSmplFactorPr{"dwnSmplFactorPr", 1., "downsampling factor for protons, default fraction to keep is 1."}; @@ -555,6 +556,10 @@ struct TreeWriterTpcV0 { } } if (saveTrees && passDownsamplig) { + const TH2* histoMomentum = isPositive ? mHistMomentumPos : mHistMomentumNeg; + if (applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, dauTrack.tpcInnerParam(), daughter.id, adaptDwnsplTargetYield, histoMomentum)) { + return false; + } OccupancyValues occValues{}; if constexpr (ModeId == ModeWithTrkQA) { evaluateOccupancyVariables(dauTrack, occValues); @@ -751,6 +756,7 @@ struct TreeWriterTpcTof { Configurable adaptDwnsplHistoPosName{"adaptDwnsplHistoPosName", "tree-writer-tpc-tof/hMomentumPos", "Name of the histogram with expected-momentum of positively charged particles"}; Configurable adaptDwnsplHistoNegName{"adaptDwnsplHistoNegName", "tree-writer-tpc-tof/hMomentumNeg", "Name of the histogram with expected-momentum of negatively charged particles"}; Configurable adaptDwnsplHistoScaleFactor{"adaptDwnsplHistoScaleFactor", 1.f, "Scaling factor for the histograms with expected-momentum"}; + Configurable adaptDwnsplTargetYield{"adaptDwnsplTargetYield", 5000000.f, "Target yield of each particle species per log10(p) unity"}; HistogramRegistry registry{"registry", {}}; @@ -1043,6 +1049,10 @@ struct TreeWriterTpcTof { } } if (saveTrees && passDownsamplig) { + const TH2* histoMomentum = trk.signed1Pt() > 0 ? mHistMomentumPos : mHistMomentumNeg; + if (applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, trk.tpcInnerParam(), tofTrack->pid, adaptDwnsplTargetYield, histoMomentum)) { + continue; + } fillSkimmedTpcTofTable(trk, trackQA, existTrkQA, collision, tofTrack->tpcNSigma, tofTrack->tofNSigma, tofTrack->itsNSigma, tofTrack->tpcExpSignal, tofTrack->pid, runnumber, tofTrack->dwnSmplFactor, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent); } } diff --git a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h index 2448f0afeab..cfa832eaf4f 100644 --- a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h +++ b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h @@ -188,22 +188,24 @@ inline void initAdaptDwnsplHistograms(const std::string& ccdbPathForAdaptDwnsplF const bool isFileAvailable = ccdbApi.retrieveBlob(ccdbPathForAdaptDwnsplFile, ".", metadata, -1, false, adaptDwnsplFileName); if (!isFileAvailable) { LOGF(fatal, "Failed to retrieve expected-momentum histograms file from CCDB: %s/%s", ccdbPathForAdaptDwnsplFile.c_str(), adaptDwnsplFileName.c_str()); - return; } TFile* adaptDwsplFile = TFile::Open(adaptDwnsplFileName.c_str(), "read"); if (adaptDwsplFile == nullptr || adaptDwsplFile->IsZombie()) { LOGF(fatal, "Failed to open expected-momentum histograms file from CCDB: %s/%s", ccdbPathForAdaptDwnsplFile.c_str(), adaptDwnsplFileName.c_str()); - return; } histoPos = dynamic_cast(adaptDwsplFile->Get(adaptDwnsplHistoPosName.c_str())->Clone()); histoNeg = dynamic_cast(adaptDwsplFile->Get(adaptDwnsplHistoNegName.c_str())->Clone()); if (histoPos == nullptr) { LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", adaptDwnsplHistoPosName.c_str()); - return; } if (histoNeg == nullptr) { LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", adaptDwnsplHistoNegName.c_str()); - return; + } + if (histoPos->GetXaxis()->IsVariableBinSize()) { + LOGF(fatal, "Histogram %s has variable bin size, which is not allowed!", adaptDwnsplHistoPosName.c_str()); + } + if (histoNeg->GetXaxis()->IsVariableBinSize()) { + LOGF(fatal, "Histogram %s has variable bin size, which is not allowed!", adaptDwnsplHistoNegName.c_str()); } histoPos->SetDirectory(nullptr); histoNeg->SetDirectory(nullptr); @@ -212,5 +214,18 @@ inline void initAdaptDwnsplHistograms(const std::string& ccdbPathForAdaptDwnsplF adaptDwsplFile = nullptr; } +inline bool performAdaptiveDownsampling(TRandom3* fRndm, const double p, const o2::track::PID::ID pid, const double targetYield, const TH2* histoExpected) +{ + const double targetYieldPerBin = targetYield * histoExpected->GetXaxis()->GetBinWidth(1); + const double yieldExpected = histoExpected->GetBinContent(histoExpected->GetXaxis()->FindBin(std::log10(p)), pid); + if (yieldExpected < targetYieldPerBin) { + return true; + } + if (fRndm->Uniform(1) > (targetYieldPerBin / yieldExpected)) { + return false; + } + return true; +} + } // namespace o2::dpg_tpcskimstablecreator #endif // DPG_TASKS_TPC_UTILSTPCSKIMSTABLECREATOR_H_ From d9671dcd22568a7b3d85050c5eb467154bc8cd04 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Sun, 22 Nov 2026 19:53:24 +0100 Subject: [PATCH 11/22] rm old-style downsamplings --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 407 ++++++++---------- .../TPC/treeCreatorPidTpcDiagnostics.cxx | 3 +- DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h | 40 +- 3 files changed, 189 insertions(+), 261 deletions(-) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index c9020fc060d..2b52fabb6bd 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -99,19 +99,6 @@ struct TreeWriterTpcV0 { Configurable adaptDwnsplHistoNegName{"adaptDwnsplHistoNegName", "tree-writer-tpc-v0/hMomentumNeg", "Name of the histogram with expected-momentum of negatively charged particles"}; Configurable adaptDwnsplHistoScaleFactor{"adaptDwnsplHistoScaleFactor", 1.f, "Scaling factor for the histograms with expected-momentum"}; Configurable adaptDwnsplTargetYield{"adaptDwnsplTargetYield", 5000000.f, "Target yield of each particle species per log10(p) unity"}; - /// Configurables downsampling - Configurable dwnSmplFactorPi{"dwnSmplFactorPi", 1., "downsampling factor for pions, default fraction to keep is 1."}; - Configurable dwnSmplFactorPr{"dwnSmplFactorPr", 1., "downsampling factor for protons, default fraction to keep is 1."}; - Configurable dwnSmplFactorEl{"dwnSmplFactorEl", 1., "downsampling factor for electrons, default fraction to keep is 1."}; - Configurable dwnSmplFactorKa{"dwnSmplFactorKa", 1., "downsampling factor for kaons, default fraction to keep is 1."}; - Configurable downsamplingTsalisPions{"downsamplingTsalisPions", -1., "Downsampling factor to reduce the number of pions"}; - Configurable downsamplingTsalisProtons{"downsamplingTsalisProtons", -1., "Downsampling factor to reduce the number of protons"}; - Configurable downsamplingTsalisElectrons{"downsamplingTsalisElectrons", -1., "Downsampling factor to reduce the number of electrons"}; - Configurable downsamplingTsalisKaons{"downsamplingTsalisKaons", -1., "Downsampling factor to reduce the number of kaons"}; - Configurable maxPt4dwnsmplTsalisPions{"maxPt4dwnsmplTsalisPions", 100., "Maximum Pt for applying downsampling factor of pions"}; - Configurable maxPt4dwnsmplTsalisProtons{"maxPt4dwnsmplTsalisProtons", 100., "Maximum Pt for applying downsampling factor of protons"}; - Configurable maxPt4dwnsmplTsalisElectrons{"maxPt4dwnsmplTsalisElectrons", 100., "Maximum Pt for applying downsampling factor of electrons"}; - Configurable maxPt4dwnsmplTsalisKaons{"maxPt4dwnsmplTsalisKaons", 100., "Maximum Pt for applying downsampling factor of kaons"}; // Configurables for output tables reservation size Configurable reserveV0Ratio{"reserveV0Ratio", 0.05, "Ratio of how many tracks from V0s are expected in the output table to the input V0 table size"}; Configurable reserveCascRatio{"reserveCascRatio", 0.0025, "Ratio of how many tracks from cascades are expected in the output table to the input Cascade table size"}; @@ -155,15 +142,11 @@ struct TreeWriterTpcV0 { }; struct V0Daughter { - double downsamplingTsalis{UndefValueDouble}; - double mass{UndefValueDouble}; - double maxPt4dwnsmplTsalis{UndefValueDouble}; double tpcNSigma{UndefValueDouble}; double tofNSigma{UndefValueDouble}; double itsNSigma{UndefValueDouble}; double tpcExpSignal{UndefValueDouble}; o2::track::PID::ID id{0}; - double dwnSmplFactor{UndefValueDouble}; double nSigmaTofDauTrack{UndefValueDouble}; bool rejectNoTofDauTrack{false}; }; @@ -239,13 +222,13 @@ struct TreeWriterTpcV0 { { switch (daughterId) { case DaughterElectron: - return V0Daughter{downsamplingTsalisElectrons, MassElectron, maxPt4dwnsmplTsalisElectrons, track.tpcNSigmaEl(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaEl(), track.tpcExpSignalEl(tpcSignalGeneric(track)), PidElectron, dwnSmplFactorEl, NSigmaTofElectorn + 1.f, false}; + return V0Daughter{track.tpcNSigmaEl(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaEl(), track.tpcExpSignalEl(tpcSignalGeneric(track)), PidElectron, NSigmaTofElectorn + 1.f, false}; case DaughterPion: - return V0Daughter{downsamplingTsalisPions, MassPiPlus, maxPt4dwnsmplTsalisPions, track.tpcNSigmaPi(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaPi(), track.tpcExpSignalPi(tpcSignalGeneric(track)), PidPion, dwnSmplFactorPi, nSigmaTofDauTrackPi, rejectNoTofDauTrackPi}; + return V0Daughter{track.tpcNSigmaPi(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaPi(), track.tpcExpSignalPi(tpcSignalGeneric(track)), PidPion, nSigmaTofDauTrackPi, rejectNoTofDauTrackPi}; case DaughterProton: - return V0Daughter{downsamplingTsalisProtons, MassProton, maxPt4dwnsmplTsalisProtons, track.tpcNSigmaPr(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaPr(), track.tpcExpSignalPr(tpcSignalGeneric(track)), PidProton, dwnSmplFactorPr, nSigmaTofDauTrackPr, rejectNoTofDauTrackPr}; + return V0Daughter{track.tpcNSigmaPr(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaPr(), track.tpcExpSignalPr(tpcSignalGeneric(track)), PidProton, nSigmaTofDauTrackPr, rejectNoTofDauTrackPr}; case DaughterKaon: - return V0Daughter{downsamplingTsalisKaons, MassKPlus, maxPt4dwnsmplTsalisKaons, track.tpcNSigmaKa(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaKa(), track.tpcExpSignalKa(tpcSignalGeneric(track)), PidKaon, dwnSmplFactorKa, nSigmaTofDauTrackKa, rejectNoTofDauTrackKa}; + return V0Daughter{track.tpcNSigmaKa(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaKa(), track.tpcExpSignalKa(tpcSignalGeneric(track)), PidKaon, nSigmaTofDauTrackKa, rejectNoTofDauTrackKa}; default: { LOGP(fatal, "createV0Daughter: unknown daughterId"); return V0Daughter(); @@ -310,7 +293,7 @@ struct TreeWriterTpcV0 { } template - void fillSkimmedV0Table(V0Casc const& v0casc, T const& track, aod::TracksQA const& trackQA, const bool existTrkQA, C const& collision, const float nSigmaTPC, const float nSigmaTOF, const float nSigmaITS, const float dEdxExp, const o2::track::PID::ID id, const int runnumber, const double dwnSmplFactor, const float hadronicRate, const int bcGlobalIndex, const int bcTimeFrameId, const int bcBcInTimeFrame, const OccupancyValues& occValues, const bool isGoodRctEvent) + void fillSkimmedV0Table(V0Casc const& v0casc, T const& track, aod::TracksQA const& trackQA, const bool existTrkQA, C const& collision, const float nSigmaTPC, const float nSigmaTOF, const float nSigmaITS, const float dEdxExp, const o2::track::PID::ID id, const int runnumber, const float hadronicRate, const int bcGlobalIndex, const int bcTimeFrameId, const int bcBcInTimeFrame, const OccupancyValues& occValues, const bool isGoodRctEvent) { const double ncl = track.tpcNClsFound(); const double nclPID = track.tpcNClsPID(); @@ -329,98 +312,95 @@ struct TreeWriterTpcV0 { const float v0radius = getRadius(v0casc); const float gammapsipair = v0casc.psipair(); - const double pseudoRndm = track.pt() * 1000. - static_cast(track.pt() * 1000); - if (pseudoRndm < dwnSmplFactor) { - const float usedDedx = tpcSignalGeneric(track); - float tpcdEdxNorm{UndefValueFloat}; - if constexpr (ModeId != ModeStandard) { - tpcdEdxNorm = existTrkQA ? trackQA.tpcdEdxNorm() : UndefValueFloat; - } - if constexpr (ModeId == ModeStandard || ModeId == ModeWithdEdxTrkQA) { - rowTPCTree(isGoodRctEvent, - usedDedx, - 1. / dEdxExp, - track.tpcInnerParam(), - track.tgl(), - track.signed1Pt(), - track.eta(), - track.phi(), - track.y(), - mass, - bg, - multTPC / MultiplicityNorm, - std::sqrt(nClNorm / ncl), - nclPID, - id, - nSigmaTPC, - nSigmaTOF, - nSigmaITS, - runnumber, - trackOcc, - ft0Occ, - occMedianTime, - hadronicRate, - tpcdEdxNorm, - alpha, - qt, - cosPA, - pT, - v0radius, - gammapsipair); - } else { - rowTPCTreeWithTrkQA(isGoodRctEvent, - usedDedx, - 1. / dEdxExp, - track.tpcInnerParam(), - track.tgl(), - track.signed1Pt(), - track.eta(), - track.phi(), - track.y(), - mass, - bg, - multTPC / MultiplicityNorm, - std::sqrt(nClNorm / ncl), - nclPID, - id, - nSigmaTPC, - nSigmaTOF, - nSigmaITS, - runnumber, - trackOcc, - ft0Occ, - occMedianTime, - hadronicRate, - tpcdEdxNorm, - alpha, - qt, - cosPA, - pT, - v0radius, - gammapsipair, - bcGlobalIndex, - bcTimeFrameId, - bcBcInTimeFrame, - existTrkQA ? trackQA.tpcClusterByteMask() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxMax0R() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxMax1R() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxMax2R() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxMax3R() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxTot0R() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxTot1R() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxTot2R() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxTot3R() : UndefValueInt, - occValues.tmoPrimUnfm80, - occValues.tmoFV0AUnfm80, - occValues.tmoFT0AUnfm80, - occValues.tmoFT0CUnfm80, - occValues.tmoRT0V0PrimUnfm80, - occValues.twmoPrimUnfm80, - occValues.twmoFV0AUnfm80, - occValues.twmoFT0AUnfm80, - occValues.twmoFT0CUnfm80, - occValues.twmoRT0V0PrimUnfm80); - } + const float usedDedx = tpcSignalGeneric(track); + float tpcdEdxNorm{UndefValueFloat}; + if constexpr (ModeId != ModeStandard) { + tpcdEdxNorm = existTrkQA ? trackQA.tpcdEdxNorm() : UndefValueFloat; + } + if constexpr (ModeId == ModeStandard || ModeId == ModeWithdEdxTrkQA) { + rowTPCTree(isGoodRctEvent, + usedDedx, + 1. / dEdxExp, + track.tpcInnerParam(), + track.tgl(), + track.signed1Pt(), + track.eta(), + track.phi(), + track.y(), + mass, + bg, + multTPC / MultiplicityNorm, + std::sqrt(nClNorm / ncl), + nclPID, + id, + nSigmaTPC, + nSigmaTOF, + nSigmaITS, + runnumber, + trackOcc, + ft0Occ, + occMedianTime, + hadronicRate, + tpcdEdxNorm, + alpha, + qt, + cosPA, + pT, + v0radius, + gammapsipair); + } else { + rowTPCTreeWithTrkQA(isGoodRctEvent, + usedDedx, + 1. / dEdxExp, + track.tpcInnerParam(), + track.tgl(), + track.signed1Pt(), + track.eta(), + track.phi(), + track.y(), + mass, + bg, + multTPC / MultiplicityNorm, + std::sqrt(nClNorm / ncl), + nclPID, + id, + nSigmaTPC, + nSigmaTOF, + nSigmaITS, + runnumber, + trackOcc, + ft0Occ, + occMedianTime, + hadronicRate, + tpcdEdxNorm, + alpha, + qt, + cosPA, + pT, + v0radius, + gammapsipair, + bcGlobalIndex, + bcTimeFrameId, + bcBcInTimeFrame, + existTrkQA ? trackQA.tpcClusterByteMask() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxMax0R() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxMax1R() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxMax2R() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxMax3R() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxTot0R() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxTot1R() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxTot2R() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxTot3R() : UndefValueInt, + occValues.tmoPrimUnfm80, + occValues.tmoFV0AUnfm80, + occValues.tmoFT0AUnfm80, + occValues.tmoFT0CUnfm80, + occValues.tmoRT0V0PrimUnfm80, + occValues.twmoPrimUnfm80, + occValues.twmoFV0AUnfm80, + occValues.twmoFT0AUnfm80, + occValues.twmoFT0CUnfm80, + occValues.twmoRT0V0PrimUnfm80); } } /// fillSkimmedV0Table @@ -489,7 +469,6 @@ struct TreeWriterTpcV0 { } std::string irSource{}; - float sqrtSNN{}; bool isFirstCollision{true}; for (const auto& collision : collisions) { if (!isEventSelected(collision, applyEvSel)) { @@ -504,7 +483,7 @@ struct TreeWriterTpcV0 { const auto cascs = myCascs.sliceBy(perCollisionCascs, static_cast(collision.globalIndex())); const auto bc = collision.bc_as(); if (isFirstCollision) { - evaluateIrSourceAndSqrtSnn(ccdb, ccdbPathGrpLhcIf, bc.timestamp(), irSource, sqrtSNN); + irSource = evaluateIrSource(ccdb, ccdbPathGrpLhcIf, bc.timestamp()); } isFirstCollision = false; const int runnumber = bc.runNumber(); @@ -543,7 +522,6 @@ struct TreeWriterTpcV0 { const V0Daughter daughter = createV0Daughter(v0, dauTrackWithITSPid, v0Id, daughterId, isPositive); const bool passTrackSelection = isTrackSelected(dauTrack, trackSelection); - const bool passDownsamplig = downsampleTsalisCharged(fRndm, dauTrack.pt(), daughter.downsamplingTsalis, daughter.mass, sqrtSNN, daughter.maxPt4dwnsmplTsalis); const bool passNSigmaTofCut = std::fabs(daughter.tofNSigma) < daughter.nSigmaTofDauTrack || std::fabs(daughter.tofNSigma - NSigmaTofUnmatched) < nSigmaTofUnmatchedEqualityTolerance; const bool passMatchTofRequirement = !daughter.rejectNoTofDauTrack || std::fabs(daughter.tofNSigma - NSigmaTofUnmatched) > nSigmaTofUnmatchedEqualityTolerance; if (passTrackSelection && passNSigmaTofCut && passMatchTofRequirement) { @@ -555,7 +533,7 @@ struct TreeWriterTpcV0 { registry.fill(HIST("hMomentumNeg"), log10p, daughter.id); } } - if (saveTrees && passDownsamplig) { + if (saveTrees) { const TH2* histoMomentum = isPositive ? mHistMomentumPos : mHistMomentumNeg; if (applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, dauTrack.tpcInnerParam(), daughter.id, adaptDwnsplTargetYield, histoMomentum)) { return false; @@ -564,7 +542,7 @@ struct TreeWriterTpcV0 { if constexpr (ModeId == ModeWithTrkQA) { evaluateOccupancyVariables(dauTrack, occValues); } - fillSkimmedV0Table(mother, dauTrack, trackQAInstance, existTrkQA, collision, daughter.tpcNSigma, daughter.tofNSigma, daughter.itsNSigma, daughter.tpcExpSignal, daughter.id, runnumber, daughter.dwnSmplFactor, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent); + fillSkimmedV0Table(mother, dauTrack, trackQAInstance, existTrkQA, collision, daughter.tpcNSigma, daughter.tofNSigma, daughter.itsNSigma, daughter.tpcExpSignal, daughter.id, runnumber, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent); return true; } } @@ -702,39 +680,28 @@ struct TreeWriterTpcTof { Configurable nSigmaTPCOnlyTr{"nSigmaTPCOnlyTr", 4., "number of sigma for TPC only cut triton"}; Configurable nSigmaTpcTpctofTr{"nSigmaTpcTpctofTr", 4., "number of sigma for TPC cut for TPC and TOF combined triton"}; Configurable nSigmaTofTpctofTr{"nSigmaTofTpctofTr", 3., "number of sigma for TOF cut for TPC and TOF combined triton"}; - Configurable dwnSmplFactorTr{"dwnSmplFactorTr", 1., "downsampling factor for triton, default fraction to keep is 1."}; /// Deuteron Configurable maxMomTPCOnlyDe{"maxMomTPCOnlyDe", 1.0, "Maximum momentum for TPC only cut deuteron"}; Configurable maxMomHardCutOnlyDe{"maxMomHardCutOnlyDe", 50, "Maximum TPC inner momentum for deuteron"}; Configurable nSigmaTPCOnlyDe{"nSigmaTPCOnlyDe", 4., "number of sigma for TPC only cut deuteron"}; Configurable nSigmaTpcTpctofDe{"nSigmaTpcTpctofDe", 4., "number of sigma for TPC cut for TPC and TOF combined deuteron"}; Configurable nSigmaTofTpctofDe{"nSigmaTofTpctofDe", 3., "number of sigma for TOF cut for TPC and TOF combined deuteron"}; - Configurable dwnSmplFactorDe{"dwnSmplFactorDe", 1., "downsampling factor for deuteron, default fraction to keep is 1."}; /// Proton Configurable maxMomTPCOnlyPr{"maxMomTPCOnlyPr", 0.6, "Maximum momentum for TPC only cut proton"}; Configurable nSigmaTPCOnlyPr{"nSigmaTPCOnlyPr", 4., "number of sigma for TPC only cut proton"}; Configurable nSigmaTpcTpctofPr{"nSigmaTpcTpctofPr", 4., "number of sigma for TPC cut for TPC and TOF combined proton"}; Configurable nSigmaTofTpctofPr{"nSigmaTofTpctofPr", 3., "number of sigma for TOF cut for TPC and TOF combined proton"}; - Configurable dwnSmplFactorPr{"dwnSmplFactorPr", 1., "downsampling factor for protons, default fraction to keep is 1."}; /// Kaon Configurable maxMomTPCOnlyKa{"maxMomTPCOnlyKa", 0.3, "Maximum momentum for TPC only cut kaon"}; Configurable maxMomHardCutOnlyKa{"maxMomHardCutOnlyKa", 50, "Maximum TPC inner momentum for kaons"}; Configurable nSigmaTPCOnlyKa{"nSigmaTPCOnlyKa", 4., "number of sigma for TPC only cut kaon"}; Configurable nSigmaTpcTpctofKa{"nSigmaTpcTpctofKa", 4., "number of sigma for TPC cut for TPC and TOF combined kaon"}; Configurable nSigmaTofTpctofKa{"nSigmaTofTpctofKa", 3., "number of sigma for TOF cut for TPC and TOF combined kaon"}; - Configurable dwnSmplFactorKa{"dwnSmplFactorKa", 1., "downsampling factor for kaons, default fraction to keep is 1."}; /// Pion Configurable maxMomTPCOnlyPi{"maxMomTPCOnlyPi", 0.5, "Maximum momentum for TPC only cut pion"}; Configurable nSigmaTPCOnlyPi{"nSigmaTPCOnlyPi", 4., "number of sigma for TPC only cut pion"}; Configurable nSigmaTpcTpctofPi{"nSigmaTpcTpctofPi", 4., "number of sigma for TPC cut for TPC and TOF combined pion"}; Configurable nSigmaTofTpctofPi{"nSigmaTofTpctofPi", 4., "number of sigma for TOF cut for TPC and TOF combined pion"}; - Configurable dwnSmplFactorPi{"dwnSmplFactorPi", 1., "downsampling factor for pions, default fraction to keep is 1."}; - /// pT dependent downsampling - Configurable downsamplingTsalisTritons{"downsamplingTsalisTritons", -1., "Downsampling factor to reduce the number of tritons"}; - Configurable downsamplingTsalisDeuterons{"downsamplingTsalisDeuterons", -1., "Downsampling factor to reduce the number of deuterons"}; - Configurable downsamplingTsalisProtons{"downsamplingTsalisProtons", -1., "Downsampling factor to reduce the number of protons"}; - Configurable downsamplingTsalisKaons{"downsamplingTsalisKaons", -1., "Downsampling factor to reduce the number of kaons"}; - Configurable downsamplingTsalisPions{"downsamplingTsalisPions", -1., "Downsampling factor to reduce the number of pions"}; // Configurable for output table reservation size Configurable reserveTrackRatio{"reserveTrackRatio", 0.003, "Ratio of how many tracks are expected in the output table to the input Tracks table size"}; Configurable saveReserveQaHisto{"saveReserveQaHisto", true, "Flag to save the DF-wise ratio of output table size to that of input table"}; @@ -766,13 +733,10 @@ struct TreeWriterTpcTof { double maxMomTPCOnly{UndefValueDouble}; double tpcNSigma{UndefValueDouble}; double nSigmaTPCOnly{UndefValueDouble}; - double downsamplingTsalis{UndefValueDouble}; - double mass{UndefValueDouble}; double tofNSigma{UndefValueDouble}; double itsNSigma{UndefValueDouble}; double tpcExpSignal{UndefValueDouble}; o2::track::PID::ID pid{0}; - double dwnSmplFactor{UndefValueDouble}; double nSigmaTofTpctof{UndefValueDouble}; double nSigmaTpcTpctof{UndefValueDouble}; }; @@ -845,7 +809,7 @@ struct TreeWriterTpcTof { } template - void fillSkimmedTpcTofTable(T const& track, aod::TracksQA const& trackQA, const bool existTrkQA, C const& collision, const float nSigmaTPC, const float nSigmaTOF, const float nSigmaITS, const float dEdxExp, const o2::track::PID::ID id, const int runnumber, const double dwnSmplFactor, const double hadronicRate, const int bcGlobalIndex, const int bcTimeFrameId, const int bcBcInTimeFrame, const OccupancyValues& occValues, const bool isGoodRctEvent) + void fillSkimmedTpcTofTable(T const& track, aod::TracksQA const& trackQA, const bool existTrkQA, C const& collision, const float nSigmaTPC, const float nSigmaTOF, const float nSigmaITS, const float dEdxExp, const o2::track::PID::ID id, const int runnumber, const double hadronicRate, const int bcGlobalIndex, const int bcTimeFrameId, const int bcBcInTimeFrame, const OccupancyValues& occValues, const bool isGoodRctEvent) { const double ncl = track.tpcNClsFound(); const double nclPID = track.tpcNClsPID(); @@ -857,86 +821,83 @@ struct TreeWriterTpcTof { const auto ft0Occ = collision.ft0cOccupancyInTimeRange(); const auto occMedianTime = collision.occupancyMedianTime(); - const double pseudoRndm = track.pt() * 1000. - static_cast(track.pt() * 1000); - if (pseudoRndm < dwnSmplFactor) { - const float usedEdx = tpcSignalGeneric(track); - float tpcdEdxNorm{UndefValueFloat}; - if constexpr (ModeId != ModeStandard) { - tpcdEdxNorm = existTrkQA ? trackQA.tpcdEdxNorm() : UndefValueFloat; - } - if (ModeId == ModeStandard || ModeId == ModeWithdEdxTrkQA) { - rowTPCTOFTree(isGoodRctEvent, - usedEdx, - 1. / dEdxExp, - track.tpcInnerParam(), - track.tgl(), - track.signed1Pt(), - track.eta(), - track.phi(), - track.y(), - mass, - bg, - multTPC / MultiplicityNorm, - std::sqrt(nClNorm / ncl), - nclPID, - id, - nSigmaTPC, - nSigmaTOF, - nSigmaITS, - runnumber, - trackOcc, - ft0Occ, - occMedianTime, - hadronicRate, - tpcdEdxNorm); - } else { - rowTPCTOFTreeWithTrkQA(isGoodRctEvent, - usedEdx, - 1. / dEdxExp, - track.tpcInnerParam(), - track.tgl(), - track.signed1Pt(), - track.eta(), - track.phi(), - track.y(), - mass, - bg, - multTPC / MultiplicityNorm, - std::sqrt(nClNorm / ncl), - nclPID, - id, - nSigmaTPC, - nSigmaTOF, - nSigmaITS, - runnumber, - trackOcc, - ft0Occ, - occMedianTime, - hadronicRate, - tpcdEdxNorm, - bcGlobalIndex, - bcTimeFrameId, - bcBcInTimeFrame, - existTrkQA ? trackQA.tpcClusterByteMask() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxMax0R() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxMax1R() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxMax2R() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxMax3R() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxTot0R() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxTot1R() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxTot2R() : UndefValueInt, - existTrkQA ? trackQA.tpcdEdxTot3R() : UndefValueInt, - occValues.tmoPrimUnfm80, - occValues.tmoFV0AUnfm80, - occValues.tmoFT0AUnfm80, - occValues.tmoFT0CUnfm80, - occValues.tmoRT0V0PrimUnfm80, - occValues.twmoPrimUnfm80, - occValues.twmoFV0AUnfm80, - occValues.twmoFT0AUnfm80, - occValues.twmoFT0CUnfm80, - occValues.twmoRT0V0PrimUnfm80); - } + const float usedEdx = tpcSignalGeneric(track); + float tpcdEdxNorm{UndefValueFloat}; + if constexpr (ModeId != ModeStandard) { + tpcdEdxNorm = existTrkQA ? trackQA.tpcdEdxNorm() : UndefValueFloat; + } + if (ModeId == ModeStandard || ModeId == ModeWithdEdxTrkQA) { + rowTPCTOFTree(isGoodRctEvent, + usedEdx, + 1. / dEdxExp, + track.tpcInnerParam(), + track.tgl(), + track.signed1Pt(), + track.eta(), + track.phi(), + track.y(), + mass, + bg, + multTPC / MultiplicityNorm, + std::sqrt(nClNorm / ncl), + nclPID, + id, + nSigmaTPC, + nSigmaTOF, + nSigmaITS, + runnumber, + trackOcc, + ft0Occ, + occMedianTime, + hadronicRate, + tpcdEdxNorm); + } else { + rowTPCTOFTreeWithTrkQA(isGoodRctEvent, + usedEdx, + 1. / dEdxExp, + track.tpcInnerParam(), + track.tgl(), + track.signed1Pt(), + track.eta(), + track.phi(), + track.y(), + mass, + bg, + multTPC / MultiplicityNorm, + std::sqrt(nClNorm / ncl), + nclPID, + id, + nSigmaTPC, + nSigmaTOF, + nSigmaITS, + runnumber, + trackOcc, + ft0Occ, + occMedianTime, + hadronicRate, + tpcdEdxNorm, + bcGlobalIndex, + bcTimeFrameId, + bcBcInTimeFrame, + existTrkQA ? trackQA.tpcClusterByteMask() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxMax0R() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxMax1R() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxMax2R() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxMax3R() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxTot0R() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxTot1R() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxTot2R() : UndefValueInt, + existTrkQA ? trackQA.tpcdEdxTot3R() : UndefValueInt, + occValues.tmoPrimUnfm80, + occValues.tmoFV0AUnfm80, + occValues.tmoFT0AUnfm80, + occValues.tmoFT0CUnfm80, + occValues.tmoRT0V0PrimUnfm80, + occValues.twmoPrimUnfm80, + occValues.twmoFV0AUnfm80, + occValues.twmoFT0AUnfm80, + occValues.twmoFT0CUnfm80, + occValues.twmoRT0V0PrimUnfm80); } } /// fillSkimmedTpcTofTable @@ -968,7 +929,6 @@ struct TreeWriterTpcTof { } std::string irSource{}; - float sqrtSNN{}; bool isFirstCollision{true}; for (const auto& collision : collisions) { const auto tracks = myTracks.sliceBy(perCollisionTracksType, collision.globalIndex()); @@ -990,7 +950,7 @@ struct TreeWriterTpcTof { const auto bc = collision.bc_as(); if (isFirstCollision) { - evaluateIrSourceAndSqrtSnn(ccdb, ccdbPathGrpLhcIf, bc.timestamp(), irSource, sqrtSNN); + irSource = evaluateIrSource(ccdb, ccdbPathGrpLhcIf, bc.timestamp()); } isFirstCollision = false; const int runnumber = bc.runNumber(); @@ -1018,15 +978,15 @@ struct TreeWriterTpcTof { trackQA = tracksQA.iteratorAt(trkIndex); } - TofTrack tofTriton(true, maxMomHardCutOnlyTr, maxMomTPCOnlyTr, trk.tpcNSigmaTr(), nSigmaTPCOnlyTr, downsamplingTsalisTritons, MassTriton, trk.tofNSigmaTr(), trk.itsNSigmaTr(), trk.tpcExpSignalTr(tpcSignalGeneric(trk)), PidTriton, dwnSmplFactorTr, nSigmaTofTpctofTr, nSigmaTpcTpctofTr); + TofTrack tofTriton(true, maxMomHardCutOnlyTr, maxMomTPCOnlyTr, trk.tpcNSigmaTr(), nSigmaTPCOnlyTr, trk.tofNSigmaTr(), trk.itsNSigmaTr(), trk.tpcExpSignalTr(tpcSignalGeneric(trk)), PidTriton, nSigmaTofTpctofTr, nSigmaTpcTpctofTr); - TofTrack tofDeuteron(true, maxMomHardCutOnlyDe, maxMomTPCOnlyDe, trk.tpcNSigmaDe(), nSigmaTPCOnlyDe, downsamplingTsalisDeuterons, MassDeuteron, trk.tofNSigmaDe(), trk.itsNSigmaDe(), trk.tpcExpSignalDe(tpcSignalGeneric(trk)), PidDeuteron, dwnSmplFactorDe, nSigmaTofTpctofDe, nSigmaTpcTpctofDe); + TofTrack tofDeuteron(true, maxMomHardCutOnlyDe, maxMomTPCOnlyDe, trk.tpcNSigmaDe(), nSigmaTPCOnlyDe, trk.tofNSigmaDe(), trk.itsNSigmaDe(), trk.tpcExpSignalDe(tpcSignalGeneric(trk)), PidDeuteron, nSigmaTofTpctofDe, nSigmaTpcTpctofDe); - TofTrack tofProton(false, UndefValueDouble, maxMomTPCOnlyPr, trk.tpcNSigmaPr(), nSigmaTPCOnlyPr, downsamplingTsalisProtons, MassProton, trk.tofNSigmaPr(), trk.itsNSigmaPr(), trk.tpcExpSignalPr(tpcSignalGeneric(trk)), PidProton, dwnSmplFactorPr, nSigmaTofTpctofPr, nSigmaTpcTpctofPr); + TofTrack tofProton(false, UndefValueDouble, maxMomTPCOnlyPr, trk.tpcNSigmaPr(), nSigmaTPCOnlyPr, trk.tofNSigmaPr(), trk.itsNSigmaPr(), trk.tpcExpSignalPr(tpcSignalGeneric(trk)), PidProton, nSigmaTofTpctofPr, nSigmaTpcTpctofPr); - TofTrack tofKaon(true, maxMomHardCutOnlyKa, maxMomTPCOnlyKa, trk.tpcNSigmaKa(), nSigmaTPCOnlyKa, downsamplingTsalisKaons, MassKPlus, trk.tofNSigmaKa(), trk.itsNSigmaKa(), trk.tpcExpSignalKa(tpcSignalGeneric(trk)), PidKaon, dwnSmplFactorKa, nSigmaTofTpctofKa, nSigmaTpcTpctofKa); + TofTrack tofKaon(true, maxMomHardCutOnlyKa, maxMomTPCOnlyKa, trk.tpcNSigmaKa(), nSigmaTPCOnlyKa, trk.tofNSigmaKa(), trk.itsNSigmaKa(), trk.tpcExpSignalKa(tpcSignalGeneric(trk)), PidKaon, nSigmaTofTpctofKa, nSigmaTpcTpctofKa); - TofTrack tofPion(false, UndefValueDouble, maxMomTPCOnlyPi, trk.tpcNSigmaPi(), nSigmaTPCOnlyPi, downsamplingTsalisPions, MassPiPlus, trk.tofNSigmaPi(), trk.itsNSigmaPi(), trk.tpcExpSignalPi(tpcSignalGeneric(trk)), PidPion, dwnSmplFactorPi, nSigmaTofTpctofPi, nSigmaTpcTpctofPi); + TofTrack tofPion(false, UndefValueDouble, maxMomTPCOnlyPi, trk.tpcNSigmaPi(), nSigmaTPCOnlyPi, trk.tofNSigmaPi(), trk.itsNSigmaPi(), trk.tpcExpSignalPi(tpcSignalGeneric(trk)), PidPion, nSigmaTofTpctofPi, nSigmaTpcTpctofPi); OccupancyValues occValues{}; if constexpr (ModeId == ModeWithTrkQA) { @@ -1037,7 +997,6 @@ struct TreeWriterTpcTof { const bool passMomHardCut = !tofTrack->isApplyHardCutOnly || trk.tpcInnerParam() < tofTrack->maxMomHardCutOnly; const bool passMomTpcOnly = trk.tpcInnerParam() <= tofTrack->maxMomTPCOnly && std::fabs(tofTrack->tpcNSigma) < tofTrack->nSigmaTPCOnly; const bool passMomTpcTof = trk.tpcInnerParam() > tofTrack->maxMomTPCOnly && std::fabs(tofTrack->tofNSigma) < tofTrack->nSigmaTofTpctof && std::fabs(tofTrack->tpcNSigma) < tofTrack->nSigmaTpcTpctof; - const bool passDownsamplig = downsampleTsalisCharged(fRndm, trk.pt(), tofTrack->downsamplingTsalis, tofTrack->mass, sqrtSNN); if (passMomHardCut && (passMomTpcOnly || passMomTpcTof)) { if (saveMomentumHistograms) { const double log10p = std::log10(trk.tpcInnerParam()); @@ -1048,12 +1007,12 @@ struct TreeWriterTpcTof { registry.fill(HIST("hMomentumNeg"), log10p, tofTrack->pid); } } - if (saveTrees && passDownsamplig) { + if (saveTrees) { const TH2* histoMomentum = trk.signed1Pt() > 0 ? mHistMomentumPos : mHistMomentumNeg; if (applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, trk.tpcInnerParam(), tofTrack->pid, adaptDwnsplTargetYield, histoMomentum)) { continue; } - fillSkimmedTpcTofTable(trk, trackQA, existTrkQA, collision, tofTrack->tpcNSigma, tofTrack->tofNSigma, tofTrack->itsNSigma, tofTrack->tpcExpSignal, tofTrack->pid, runnumber, tofTrack->dwnSmplFactor, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent); + fillSkimmedTpcTofTable(trk, trackQA, existTrkQA, collision, tofTrack->tpcNSigma, tofTrack->tofNSigma, tofTrack->itsNSigma, tofTrack->tpcExpSignal, tofTrack->pid, runnumber, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent); } } } diff --git a/DPG/Tasks/TPC/treeCreatorPidTpcDiagnostics.cxx b/DPG/Tasks/TPC/treeCreatorPidTpcDiagnostics.cxx index 8b20cb6889a..3c052275a94 100644 --- a/DPG/Tasks/TPC/treeCreatorPidTpcDiagnostics.cxx +++ b/DPG/Tasks/TPC/treeCreatorPidTpcDiagnostics.cxx @@ -205,7 +205,6 @@ struct TreeCreatorPidTpcDiagnostics { } std::string irSource{}; - float sqrtSNN{}; // placeholder to satisfy evaluateIrSourceAndSqrtSnn's signature bool isFirstCollision{true}; for (const auto& collision : collisions) { if (!isEventSelected(collision, applyEvSel) || (std::abs(collision.posZ()) > cutVtxZ)) { @@ -219,7 +218,7 @@ struct TreeCreatorPidTpcDiagnostics { const auto bc = collision.bc_as(); if (isFirstCollision) { - evaluateIrSourceAndSqrtSnn(ccdb, ccdbPathGrpLhcIf, bc.timestamp(), irSource, sqrtSNN); + irSource = evaluateIrSource(ccdb, ccdbPathGrpLhcIf, bc.timestamp()); } isFirstCollision = false; const float ft0Occ = collision.ft0cOccupancyInTimeRange(); diff --git a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h index cfa832eaf4f..abd271268a6 100644 --- a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h +++ b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h @@ -69,34 +69,6 @@ bool isEventSelected(const CollisionType& collision, const int applyEvSel) } }; -/// Random downsampling trigger function using Tsalis/Hagedorn spectra fit (sqrt(s) = 62.4 GeV to 13 TeV) -/// as in https://iopscience.iop.org/article/10.1088/2399-6528/aab00f/pdf -inline bool downsampleTsalisCharged(TRandom3* fRndm, const double pt, const double factor1Pt, const double mass, const double sqrtSNN, const double maxPt = 1e9) -{ - if (factor1Pt < 0. || pt > maxPt) { - return true; - } - - auto tsalisCharged = [&](const double pT) { - const double a = 6.81, b = 59.24; - const double c = 0.082, d = 0.151; - const double mt = std::sqrt(mass * mass + pT * pT); - const double n = a + b / sqrtSNN; - const double t = c + d / sqrtSNN; - const double p0 = n * t; - const double result = std::pow((1. + mt / p0), -n); - return result; - }; - - const double prob = tsalisCharged(pt) * pt; - const double probNorm = tsalisCharged(1.); - if ((fRndm->Rndm() * ((prob / probNorm) * pt * pt)) > factor1Pt) { - return false; - } else { - return true; - } -}; - // Track selection template bool isTrackSelected(const TrackType& track, const int trackSelection) @@ -123,9 +95,10 @@ double tpcSignalGeneric(const TrkType& track) } } -/// Determine interaction rate source and sqrtSNN from CCDB -void evaluateIrSourceAndSqrtSnn(const o2::framework::Service& ccdb, const std::string& ccdbPathGrpLhcIf, const uint64_t timestamp, std::string& irSource, float& sqrtSNN) +/// Determine interaction rate source from CCDB +std::string evaluateIrSource(const o2::framework::Service& ccdb, const std::string& ccdbPathGrpLhcIf, const uint64_t timestamp) { + std::string irSource{""}; o2::parameters::GRPLHCIFData* genRunParams = ccdb->template getForTimeStamp(ccdbPathGrpLhcIf, timestamp); if (genRunParams != nullptr) { const auto collSys = CollisionSystemType::getCollisionTypeFromGrp(genRunParams); @@ -134,14 +107,11 @@ void evaluateIrSourceAndSqrtSnn(const o2::framework::ServicegetSqrtS(); LOG(info) << "irSource determined from General Run Parameters: " << irSource; - LOG(info) << "sqrtSNN determined from General Run Parameters: " << sqrtSNN << " GeV"; } else { - irSource = ""; - sqrtSNN = 5360.f; - LOG(warning) << "No General Run Parameters object found. irSource will remain undefined, sqrtSNN defaulted to 5360 GeV"; + LOG(warning) << "No General Run Parameters object found. irSource will remain undefined"; } + return irSource; } struct OccupancyValues { From b7a802ccb7035d018cade3c50613f0935de6237e Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Sun, 22 Nov 2026 20:06:01 +0100 Subject: [PATCH 12/22] tof: introduce maxMomHardCutOnly for Pr, Pi --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index 2b52fabb6bd..bfd935b19de 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -688,6 +688,7 @@ struct TreeWriterTpcTof { Configurable nSigmaTofTpctofDe{"nSigmaTofTpctofDe", 3., "number of sigma for TOF cut for TPC and TOF combined deuteron"}; /// Proton Configurable maxMomTPCOnlyPr{"maxMomTPCOnlyPr", 0.6, "Maximum momentum for TPC only cut proton"}; + Configurable maxMomHardCutOnlyPr{"maxMomHardCutOnlyPr", 50, "Maximum TPC inner momentum for proton"}; Configurable nSigmaTPCOnlyPr{"nSigmaTPCOnlyPr", 4., "number of sigma for TPC only cut proton"}; Configurable nSigmaTpcTpctofPr{"nSigmaTpcTpctofPr", 4., "number of sigma for TPC cut for TPC and TOF combined proton"}; Configurable nSigmaTofTpctofPr{"nSigmaTofTpctofPr", 3., "number of sigma for TOF cut for TPC and TOF combined proton"}; @@ -699,6 +700,7 @@ struct TreeWriterTpcTof { Configurable nSigmaTofTpctofKa{"nSigmaTofTpctofKa", 3., "number of sigma for TOF cut for TPC and TOF combined kaon"}; /// Pion Configurable maxMomTPCOnlyPi{"maxMomTPCOnlyPi", 0.5, "Maximum momentum for TPC only cut pion"}; + Configurable maxMomHardCutOnlyPi{"maxMomHardCutOnlyPi", 50, "Maximum TPC inner momentum for pion"}; Configurable nSigmaTPCOnlyPi{"nSigmaTPCOnlyPi", 4., "number of sigma for TPC only cut pion"}; Configurable nSigmaTpcTpctofPi{"nSigmaTpcTpctofPi", 4., "number of sigma for TPC cut for TPC and TOF combined pion"}; Configurable nSigmaTofTpctofPi{"nSigmaTofTpctofPi", 4., "number of sigma for TOF cut for TPC and TOF combined pion"}; @@ -728,7 +730,6 @@ struct TreeWriterTpcTof { HistogramRegistry registry{"registry", {}}; struct TofTrack { - bool isApplyHardCutOnly{false}; double maxMomHardCutOnly{UndefValueDouble}; double maxMomTPCOnly{UndefValueDouble}; double tpcNSigma{UndefValueDouble}; @@ -978,15 +979,15 @@ struct TreeWriterTpcTof { trackQA = tracksQA.iteratorAt(trkIndex); } - TofTrack tofTriton(true, 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(tpcSignalGeneric(trk)), PidTriton, nSigmaTofTpctofTr, nSigmaTpcTpctofTr); - TofTrack tofDeuteron(true, 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(tpcSignalGeneric(trk)), PidDeuteron, nSigmaTofTpctofDe, nSigmaTpcTpctofDe); - TofTrack tofProton(false, UndefValueDouble, 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(tpcSignalGeneric(trk)), PidProton, nSigmaTofTpctofPr, nSigmaTpcTpctofPr); - TofTrack tofKaon(true, 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(tpcSignalGeneric(trk)), PidKaon, nSigmaTofTpctofKa, nSigmaTpcTpctofKa); - TofTrack tofPion(false, UndefValueDouble, 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(tpcSignalGeneric(trk)), PidPion, nSigmaTofTpctofPi, nSigmaTpcTpctofPi); OccupancyValues occValues{}; if constexpr (ModeId == ModeWithTrkQA) { @@ -994,7 +995,7 @@ struct TreeWriterTpcTof { } for (const auto& tofTrack : {&tofTriton, &tofDeuteron, &tofProton, &tofKaon, &tofPion}) { - const bool passMomHardCut = !tofTrack->isApplyHardCutOnly || trk.tpcInnerParam() < tofTrack->maxMomHardCutOnly; + const bool passMomHardCut = trk.tpcInnerParam() < tofTrack->maxMomHardCutOnly; const bool passMomTpcOnly = trk.tpcInnerParam() <= tofTrack->maxMomTPCOnly && std::fabs(tofTrack->tpcNSigma) < tofTrack->nSigmaTPCOnly; const bool passMomTpcTof = trk.tpcInnerParam() > tofTrack->maxMomTPCOnly && std::fabs(tofTrack->tofNSigma) < tofTrack->nSigmaTofTpctof && std::fabs(tofTrack->tpcNSigma) < tofTrack->nSigmaTpcTpctof; if (passMomHardCut && (passMomTpcOnly || passMomTpcTof)) { From 85b1bfd97f81dd7160fa527d070b513729daf39a Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Sun, 22 Nov 2026 20:27:53 +0100 Subject: [PATCH 13/22] factor out common configurables --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 149 ++++++++++++------------- 1 file changed, 69 insertions(+), 80 deletions(-) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index bfd935b19de..81bd3c3a2c4 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -76,18 +76,8 @@ using CascsWithID = soa::Join concept V0OrCasc = std::same_as || std::same_as; -struct TreeWriterTpcV0 { - - Produces rowTPCTree; - Produces rowTPCTreeWithTrkQA; - +struct CfgCommon : ConfigurableGroup { /// Configurables general - Configurable nSigmaTofDauTrackPi{"nSigmaTofDauTrackPi", 999.f, "n-sigma TOF cut on the pion daughter tracks"}; - Configurable nSigmaTofDauTrackPr{"nSigmaTofDauTrackPr", 999.f, "n-sigma TOF cut on the proton daughter tracks"}; - Configurable nSigmaTofDauTrackKa{"nSigmaTofDauTrackKa", 999.f, "n-sigma TOF cut on the kaon daughter tracks"}; - Configurable rejectNoTofDauTrackPi{"rejectNoTofDauTrackPi", false, "reject not matched to TOF pion daughter tracks"}; - Configurable rejectNoTofDauTrackPr{"rejectNoTofDauTrackPr", false, "reject not matched to TOF proton daughter tracks"}; - Configurable rejectNoTofDauTrackKa{"rejectNoTofDauTrackKa", false, "reject not matched to TOF kaon daughter tracks"}; Configurable nClNorm{"nClNorm", 152., "Number of cluster normalization. Run 2: 159, Run 3 152"}; Configurable applyEvSel{"applyEvSel", 2, "Flag to apply rapidity cut: 0 -> no event selection, 1 -> Run 2 event selection, 2 -> Run 3 event selection"}; Configurable trackSelection{"trackSelection", 0, "Track selection: 0 -> No Cut, 1 -> kGlobalTrack, 2 -> kGlobalTrackWoPtEta, 3 -> kGlobalTrackWoDCA, 4 -> kQualityTracks, 5 -> kInAcceptanceTracks"}; @@ -95,13 +85,8 @@ struct TreeWriterTpcV0 { Configurable applyAdaptiveDownsampling{"applyAdaptiveDownsampling", false, "Apply downsampling driven by expected momentum distribution"}; Configurable ccdbPathForAdaptDwnsplFile{"ccdbPathForAdaptDwnsplFile", "", "CCDB path for file with expected-momentum histograms"}; Configurable adaptDwnsplFileName{"adaptDwnsplFileName", "AnalysisResults.root", "Name of the file with expected-momentum histograms"}; - Configurable adaptDwnsplHistoPosName{"adaptDwnsplHistoPosName", "tree-writer-tpc-v0/hMomentumPos", "Name of the histogram with expected-momentum of positively charged particles"}; - Configurable adaptDwnsplHistoNegName{"adaptDwnsplHistoNegName", "tree-writer-tpc-v0/hMomentumNeg", "Name of the histogram with expected-momentum of negatively charged particles"}; Configurable adaptDwnsplHistoScaleFactor{"adaptDwnsplHistoScaleFactor", 1.f, "Scaling factor for the histograms with expected-momentum"}; - Configurable adaptDwnsplTargetYield{"adaptDwnsplTargetYield", 5000000.f, "Target yield of each particle species per log10(p) unity"}; - // Configurables for output tables reservation size - Configurable reserveV0Ratio{"reserveV0Ratio", 0.05, "Ratio of how many tracks from V0s are expected in the output table to the input V0 table size"}; - Configurable reserveCascRatio{"reserveCascRatio", 0.0025, "Ratio of how many tracks from cascades are expected in the output table to the input Cascade table size"}; + Configurable adaptDwnsplTargetYieldsplHistoScaleFactor{"adaptDwnsplTargetYieldsplHistoScaleFactor", 5000000.f, "Target yield of each particle species per log10(p) unity"}; Configurable saveReserveQaHisto{"saveReserveQaHisto", true, "Flag to save the DF-wise ratio of output table size to that of input table"}; // Configurables for run condtion table Configurable rctLabel{"rctLabel", "CBT_hadronPID", "select 1 [CBT, CBT_hadronPID, CBT_muon_glo] see O2Physics/Common/CCDB/RCTSelectionFlags.h"}; @@ -114,6 +99,29 @@ struct TreeWriterTpcV0 { Configurable saveTrees{"saveTrees", true, "Flag to save trees"}; Configurable saveMomentumHistograms{"saveMomentumHistograms", false, "Flag to save momentum histograms"}; ConfigurableAxis axisMomentumHistograms{"axisMomentumHistograms", {200, std::log10(0.1), std::log10(20.)}, "log_{10}(#it{p} / (GeV/#it{c}))"}; +}; + +struct TreeWriterTpcV0 { + + Produces rowTPCTree; + Produces rowTPCTreeWithTrkQA; + + CfgCommon cfgsCommon; + + /// Configurables general + Configurable nSigmaTofDauTrackPi{"nSigmaTofDauTrackPi", 999.f, "n-sigma TOF cut on the pion daughter tracks"}; + Configurable nSigmaTofDauTrackPr{"nSigmaTofDauTrackPr", 999.f, "n-sigma TOF cut on the proton daughter tracks"}; + Configurable nSigmaTofDauTrackKa{"nSigmaTofDauTrackKa", 999.f, "n-sigma TOF cut on the kaon daughter tracks"}; + Configurable rejectNoTofDauTrackPi{"rejectNoTofDauTrackPi", false, "reject not matched to TOF pion daughter tracks"}; + Configurable rejectNoTofDauTrackPr{"rejectNoTofDauTrackPr", false, "reject not matched to TOF proton daughter tracks"}; + Configurable rejectNoTofDauTrackKa{"rejectNoTofDauTrackKa", false, "reject not matched to TOF kaon daughter tracks"}; + + /// Configurables adaptive downsampling + Configurable adaptDwnsplHistoPosName{"adaptDwnsplHistoPosName", "tree-writer-tpc-v0/hMomentumPos", "Name of the histogram with expected-momentum of positively charged particles"}; + Configurable adaptDwnsplHistoNegName{"adaptDwnsplHistoNegName", "tree-writer-tpc-v0/hMomentumNeg", "Name of the histogram with expected-momentum of negatively charged particles"}; + // Configurables for output tables reservation size + Configurable reserveV0Ratio{"reserveV0Ratio", 0.05, "Ratio of how many tracks from V0s are expected in the output table to the input V0 table size"}; + Configurable reserveCascRatio{"reserveCascRatio", 0.0025, "Ratio of how many tracks from cascades are expected in the output table to the input Cascade table size"}; HistogramRegistry registry{"registry", {}}; @@ -184,7 +192,7 @@ struct TreeWriterTpcV0 { LOGP(fatal, "One and only one process function should be enabled"); } - if (!(saveTrees || saveMomentumHistograms)) { + if (!(cfgsCommon.saveTrees || cfgsCommon.saveMomentumHistograms)) { LOGP(fatal, "At least one out of trees or momentum histograms should be saved"); } @@ -192,27 +200,27 @@ struct TreeWriterTpcV0 { ccdb->setCaching(true); ccdb->setFatalWhenNull(false); - rctChecker.init(rctLabel, checkZdc, treatLimitedAcceptanceAsBad); + rctChecker.init(cfgsCommon.rctLabel, cfgsCommon.checkZdc, cfgsCommon.treatLimitedAcceptanceAsBad); - if (saveReserveQaHisto) { + if (cfgsCommon.saveReserveQaHisto) { registry.add("hV0OutputRatio", "V0 out/in ratio;V0 out/in ratio;Entries", {HistType::kTH1F, {{100, 0, reserveV0Ratio}}}); registry.add("hCascOutputRatio", "Casc out/in ratio;Casc out/in ratio;Entries", {HistType::kTH1F, {{100, 0, reserveCascRatio}}}); } - if (saveMomentumHistograms) { - registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); - registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + if (cfgsCommon.saveMomentumHistograms) { + registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{cfgsCommon.axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{cfgsCommon.axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); for (int iParticle = 0; iParticle < o2::track::PID::NIDs; ++iParticle) { registry.get(HIST("hMomentumPos"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); registry.get(HIST("hMomentumNeg"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); } } - if (applyAdaptiveDownsampling) { - initAdaptDwnsplHistograms(ccdbPathForAdaptDwnsplFile, adaptDwnsplFileName, adaptDwnsplHistoPosName, adaptDwnsplHistoNegName, mHistMomentumPos, mHistMomentumNeg); - if (adaptDwnsplHistoScaleFactor != 1.f) { - mHistMomentumPos->Scale(adaptDwnsplHistoScaleFactor); - mHistMomentumNeg->Scale(adaptDwnsplHistoScaleFactor); + if (cfgsCommon.applyAdaptiveDownsampling) { + initAdaptDwnsplHistograms(cfgsCommon.ccdbPathForAdaptDwnsplFile, cfgsCommon.adaptDwnsplFileName, adaptDwnsplHistoPosName, adaptDwnsplHistoNegName, mHistMomentumPos, mHistMomentumNeg); + if (cfgsCommon.adaptDwnsplHistoScaleFactor != 1.f) { + mHistMomentumPos->Scale(cfgsCommon.adaptDwnsplHistoScaleFactor); + mHistMomentumNeg->Scale(cfgsCommon.adaptDwnsplHistoScaleFactor); } } } @@ -330,7 +338,7 @@ struct TreeWriterTpcV0 { mass, bg, multTPC / MultiplicityNorm, - std::sqrt(nClNorm / ncl), + std::sqrt(cfgsCommon.nClNorm / ncl), nclPID, id, nSigmaTPC, @@ -361,7 +369,7 @@ struct TreeWriterTpcV0 { mass, bg, multTPC / MultiplicityNorm, - std::sqrt(nClNorm / ncl), + std::sqrt(cfgsCommon.nClNorm / ncl), nclPID, id, nSigmaTPC, @@ -471,11 +479,11 @@ struct TreeWriterTpcV0 { std::string irSource{}; bool isFirstCollision{true}; for (const auto& collision : collisions) { - if (!isEventSelected(collision, applyEvSel)) { + if (!isEventSelected(collision, cfgsCommon.applyEvSel)) { continue; } const bool isGoodRctEvent = rctChecker.checkTable(collision); - if (requireGoodRct && !isGoodRctEvent) { + if (cfgsCommon.requireGoodRct && !isGoodRctEvent) { continue; } @@ -483,7 +491,7 @@ struct TreeWriterTpcV0 { const auto cascs = myCascs.sliceBy(perCollisionCascs, static_cast(collision.globalIndex())); const auto bc = collision.bc_as(); if (isFirstCollision) { - irSource = evaluateIrSource(ccdb, ccdbPathGrpLhcIf, bc.timestamp()); + irSource = evaluateIrSource(ccdb, cfgsCommon.ccdbPathGrpLhcIf, bc.timestamp()); } isFirstCollision = false; const int runnumber = bc.runNumber(); @@ -521,11 +529,11 @@ struct TreeWriterTpcV0 { const auto daughterId = isPositive ? v0Mother.posDaughterId : v0Mother.negDaughterId; const V0Daughter daughter = createV0Daughter(v0, dauTrackWithITSPid, v0Id, daughterId, isPositive); - const bool passTrackSelection = isTrackSelected(dauTrack, trackSelection); + const bool passTrackSelection = isTrackSelected(dauTrack, cfgsCommon.trackSelection); const bool passNSigmaTofCut = std::fabs(daughter.tofNSigma) < daughter.nSigmaTofDauTrack || std::fabs(daughter.tofNSigma - NSigmaTofUnmatched) < nSigmaTofUnmatchedEqualityTolerance; const bool passMatchTofRequirement = !daughter.rejectNoTofDauTrack || std::fabs(daughter.tofNSigma - NSigmaTofUnmatched) > nSigmaTofUnmatchedEqualityTolerance; if (passTrackSelection && passNSigmaTofCut && passMatchTofRequirement) { - if (saveMomentumHistograms) { + if (cfgsCommon.saveMomentumHistograms) { const double log10p = std::log10(dauTrack.tpcInnerParam()); if (isPositive) { registry.fill(HIST("hMomentumPos"), log10p, daughter.id); @@ -533,9 +541,9 @@ struct TreeWriterTpcV0 { registry.fill(HIST("hMomentumNeg"), log10p, daughter.id); } } - if (saveTrees) { + if (cfgsCommon.saveTrees) { const TH2* histoMomentum = isPositive ? mHistMomentumPos : mHistMomentumNeg; - if (applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, dauTrack.tpcInnerParam(), daughter.id, adaptDwnsplTargetYield, histoMomentum)) { + if (cfgsCommon.applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, dauTrack.tpcInnerParam(), daughter.id, cfgsCommon.adaptDwnsplTargetYieldsplHistoScaleFactor, histoMomentum)) { return false; } OccupancyValues occValues{}; @@ -588,7 +596,7 @@ struct TreeWriterTpcV0 { LOG(info) << "nV0Entries / V0 table size = " << static_cast(nV0Entries) / myV0s.size(); LOG(info) << "nCascEntries / Cascade table size = " << static_cast(nCascEntries) / myCascs.size(); - if (saveReserveQaHisto) { + if (cfgsCommon.saveReserveQaHisto) { registry.fill(HIST("hV0OutputRatio"), static_cast(nV0Entries) / myV0s.size()); registry.fill(HIST("hCascOutputRatio"), static_cast(nCascEntries) / myCascs.size()); } @@ -670,10 +678,8 @@ struct TreeWriterTpcTof { Produces rowTPCTOFTree; Produces rowTPCTOFTreeWithTrkQA; - /// Configurables general - Configurable nClNorm{"nClNorm", 152., "Number of cluster normalization. Run 2: 159, Run 3 152"}; - Configurable applyEvSel{"applyEvSel", 2, "Flag to apply rapidity cut: 0 -> no event selection, 1 -> Run 2 event selection, 2 -> Run 3 event selection"}; - Configurable trackSelection{"trackSelection", 1, "Track selection: 0 -> No Cut, 1 -> kGlobalTrack, 2 -> kGlobalTrackWoPtEta, 3 -> kGlobalTrackWoDCA, 4 -> kQualityTracks, 5 -> kInAcceptanceTracks"}; + CfgCommon cfgsCommon; + /// Triton Configurable maxMomTPCOnlyTr{"maxMomTPCOnlyTr", 1.5, "Maximum momentum for TPC only cut triton"}; Configurable maxMomHardCutOnlyTr{"maxMomHardCutOnlyTr", 50, "Maximum TPC inner momentum for triton"}; @@ -706,26 +712,9 @@ struct TreeWriterTpcTof { Configurable nSigmaTofTpctofPi{"nSigmaTofTpctofPi", 4., "number of sigma for TOF cut for TPC and TOF combined pion"}; // Configurable for output table reservation size Configurable reserveTrackRatio{"reserveTrackRatio", 0.003, "Ratio of how many tracks are expected in the output table to the input Tracks table size"}; - Configurable saveReserveQaHisto{"saveReserveQaHisto", true, "Flag to save the DF-wise ratio of output table size to that of input table"}; // Configurables for run condtion table - Configurable rctLabel{"rctLabel", "CBT_hadronPID", "select 1 [CBT, CBT_hadronPID, CBT_muon_glo] see O2Physics/Common/CCDB/RCTSelectionFlags.h"}; - Configurable checkZdc{"checkZdc", false, "set ZDC flag for PbPb"}; - Configurable treatLimitedAcceptanceAsBad{"treatLimitedAcceptanceAsBad", false, "reject all events where the detectors relevant for the specified Runlist are flagged as LimitedAcceptance"}; - Configurable requireGoodRct{"requireGoodRct", false, "require good detector flag in run condtion table"}; - // Configurable for the path of CCDB General Run Parameters LHC Interface information - Configurable ccdbPathGrpLhcIf{"ccdbPathGrpLhcIf", "GLO/Config/GRPLHCIF", "Path on the CCDB for the GRPLHCIF object"}; - // Configurables flagging saving trees and/or HistogramSpec - Configurable saveTrees{"saveTrees", true, "Flag to save trees"}; - Configurable saveMomentumHistograms{"saveMomentumHistograms", false, "Flag to save momentum histograms"}; - ConfigurableAxis axisMomentumHistograms{"axisMomentumHistograms", {200, std::log10(0.1), std::log10(20.)}, "log_{10}(#it{p} / (GeV/#it{c}))"}; - /// Configurables adaptive downsampling - Configurable applyAdaptiveDownsampling{"applyAdaptiveDownsampling", false, "Apply downsampling driven by expected momentum distribution"}; - Configurable ccdbPathForAdaptDwnsplFile{"ccdbPathForAdaptDwnsplFile", "", "CCDB path for file with expected-momentum histograms"}; - Configurable adaptDwnsplFileName{"adaptDwnsplFileName", "AnalysisResults.root", "Name of the file with expected-momentum histograms"}; Configurable adaptDwnsplHistoPosName{"adaptDwnsplHistoPosName", "tree-writer-tpc-tof/hMomentumPos", "Name of the histogram with expected-momentum of positively charged particles"}; Configurable adaptDwnsplHistoNegName{"adaptDwnsplHistoNegName", "tree-writer-tpc-tof/hMomentumNeg", "Name of the histogram with expected-momentum of negatively charged particles"}; - Configurable adaptDwnsplHistoScaleFactor{"adaptDwnsplHistoScaleFactor", 1.f, "Scaling factor for the histograms with expected-momentum"}; - Configurable adaptDwnsplTargetYield{"adaptDwnsplTargetYield", 5000000.f, "Target yield of each particle species per log10(p) unity"}; HistogramRegistry registry{"registry", {}}; @@ -777,7 +766,7 @@ struct TreeWriterTpcTof { LOGP(fatal, "One and only one process function should be enabled"); } - if (!(saveTrees || saveMomentumHistograms)) { + if (!(cfgsCommon.saveTrees || cfgsCommon.saveMomentumHistograms)) { LOGP(fatal, "At least one out of trees or momentum histograms should be saved"); } @@ -785,26 +774,26 @@ struct TreeWriterTpcTof { ccdb->setCaching(true); ccdb->setFatalWhenNull(false); - rctChecker.init(rctLabel, checkZdc, treatLimitedAcceptanceAsBad); + rctChecker.init(cfgsCommon.rctLabel, cfgsCommon.checkZdc, cfgsCommon.treatLimitedAcceptanceAsBad); - if (saveReserveQaHisto) { + if (cfgsCommon.saveReserveQaHisto) { registry.add("hTrackOutputRatio", "Track out/in ratio;Track out/in ratio;Entries", {HistType::kTH1F, {{100, 0, reserveTrackRatio}}}); } - if (saveMomentumHistograms) { - registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); - registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + if (cfgsCommon.saveMomentumHistograms) { + registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{cfgsCommon.axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{cfgsCommon.axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); for (int iParticle = 0; iParticle < o2::track::PID::NIDs; ++iParticle) { registry.get(HIST("hMomentumPos"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); registry.get(HIST("hMomentumNeg"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); } } - if (applyAdaptiveDownsampling) { - initAdaptDwnsplHistograms(ccdbPathForAdaptDwnsplFile, adaptDwnsplFileName, adaptDwnsplHistoPosName, adaptDwnsplHistoNegName, mHistMomentumPos, mHistMomentumNeg); - if (adaptDwnsplHistoScaleFactor != 1.f) { - mHistMomentumPos->Scale(adaptDwnsplHistoScaleFactor); - mHistMomentumNeg->Scale(adaptDwnsplHistoScaleFactor); + if (cfgsCommon.applyAdaptiveDownsampling) { + initAdaptDwnsplHistograms(cfgsCommon.ccdbPathForAdaptDwnsplFile, cfgsCommon.adaptDwnsplFileName, adaptDwnsplHistoPosName, adaptDwnsplHistoNegName, mHistMomentumPos, mHistMomentumNeg); + if (cfgsCommon.adaptDwnsplHistoScaleFactor != 1.f) { + mHistMomentumPos->Scale(cfgsCommon.adaptDwnsplHistoScaleFactor); + mHistMomentumNeg->Scale(cfgsCommon.adaptDwnsplHistoScaleFactor); } } } @@ -840,7 +829,7 @@ struct TreeWriterTpcTof { mass, bg, multTPC / MultiplicityNorm, - std::sqrt(nClNorm / ncl), + std::sqrt(cfgsCommon.nClNorm / ncl), nclPID, id, nSigmaTPC, @@ -865,7 +854,7 @@ struct TreeWriterTpcTof { mass, bg, multTPC / MultiplicityNorm, - std::sqrt(nClNorm / ncl), + std::sqrt(cfgsCommon.nClNorm / ncl), nclPID, id, nSigmaTPC, @@ -933,11 +922,11 @@ struct TreeWriterTpcTof { bool isFirstCollision{true}; for (const auto& collision : collisions) { const auto tracks = myTracks.sliceBy(perCollisionTracksType, collision.globalIndex()); - if (!isEventSelected(collision, applyEvSel)) { + if (!isEventSelected(collision, cfgsCommon.applyEvSel)) { continue; } const bool isGoodRctEvent = rctChecker.checkTable(collision); - if (requireGoodRct && !isGoodRctEvent) { + if (cfgsCommon.requireGoodRct && !isGoodRctEvent) { continue; } @@ -951,7 +940,7 @@ struct TreeWriterTpcTof { const auto bc = collision.bc_as(); if (isFirstCollision) { - irSource = evaluateIrSource(ccdb, ccdbPathGrpLhcIf, bc.timestamp()); + irSource = evaluateIrSource(ccdb, cfgsCommon.ccdbPathGrpLhcIf, bc.timestamp()); } isFirstCollision = false; const int runnumber = bc.runNumber(); @@ -966,7 +955,7 @@ struct TreeWriterTpcTof { bcBcInTimeFrame = bc.bcInTF(); } for (auto const& trk : tracksWithITSPid) { - if (!isTrackSelected(trk, trackSelection)) { + if (!isTrackSelected(trk, cfgsCommon.trackSelection)) { continue; } // get the corresponding trackQA using labelTracks2TracKQA and get variables of interest @@ -999,7 +988,7 @@ struct TreeWriterTpcTof { const bool passMomTpcOnly = trk.tpcInnerParam() <= tofTrack->maxMomTPCOnly && std::fabs(tofTrack->tpcNSigma) < tofTrack->nSigmaTPCOnly; const bool passMomTpcTof = trk.tpcInnerParam() > tofTrack->maxMomTPCOnly && std::fabs(tofTrack->tofNSigma) < tofTrack->nSigmaTofTpctof && std::fabs(tofTrack->tpcNSigma) < tofTrack->nSigmaTpcTpctof; if (passMomHardCut && (passMomTpcOnly || passMomTpcTof)) { - if (saveMomentumHistograms) { + if (cfgsCommon.saveMomentumHistograms) { const double log10p = std::log10(trk.tpcInnerParam()); const bool isPositive = (trk.signed1Pt() > 0); if (isPositive) { @@ -1008,9 +997,9 @@ struct TreeWriterTpcTof { registry.fill(HIST("hMomentumNeg"), log10p, tofTrack->pid); } } - if (saveTrees) { + if (cfgsCommon.saveTrees) { const TH2* histoMomentum = trk.signed1Pt() > 0 ? mHistMomentumPos : mHistMomentumNeg; - if (applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, trk.tpcInnerParam(), tofTrack->pid, adaptDwnsplTargetYield, histoMomentum)) { + if (cfgsCommon.applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, trk.tpcInnerParam(), tofTrack->pid, cfgsCommon.adaptDwnsplTargetYieldsplHistoScaleFactor, histoMomentum)) { continue; } fillSkimmedTpcTofTable(trk, trackQA, existTrkQA, collision, tofTrack->tpcNSigma, tofTrack->tofNSigma, tofTrack->itsNSigma, tofTrack->tpcExpSignal, tofTrack->pid, runnumber, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent); @@ -1024,7 +1013,7 @@ struct TreeWriterTpcTof { LOG(info) << "nTrackEntries = " << rowTPCTOFTree.lastIndex() + 1; LOG(info) << "nTrackEntries / Track table size = " << static_cast((rowTPCTOFTree.lastIndex() + 1)) / myTracks.size(); - if (saveReserveQaHisto) { + if (cfgsCommon.saveReserveQaHisto) { registry.fill(HIST("hTrackOutputRatio"), static_cast((rowTPCTOFTree.lastIndex() + 1)) / myTracks.size()); } } /// runTof From eeeec19ccf2ffa0c68fe65150effeb3610442c4e Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Sun, 22 Nov 2026 21:21:54 +0100 Subject: [PATCH 14/22] do not retrieve adaptDwnsplFile twice --- DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h index abd271268a6..f085342a5e3 100644 --- a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h +++ b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h @@ -38,6 +38,7 @@ #include #include +#include #include #include @@ -154,10 +155,12 @@ inline void initAdaptDwnsplHistograms(const std::string& ccdbPathForAdaptDwnsplF o2::ccdb::CcdbApi ccdbApi; ccdbApi.init("http://alice-ccdb.cern.ch"); const std::map metadata; - // Retrieve the file from CCDB - const bool isFileAvailable = ccdbApi.retrieveBlob(ccdbPathForAdaptDwnsplFile, ".", metadata, -1, false, adaptDwnsplFileName); - if (!isFileAvailable) { - LOGF(fatal, "Failed to retrieve expected-momentum histograms file from CCDB: %s/%s", ccdbPathForAdaptDwnsplFile.c_str(), adaptDwnsplFileName.c_str()); + if (std::filesystem::exists(adaptDwnsplFileName.c_str())) { + // Retrieve the file from CCDB + const bool isFileAvailable = ccdbApi.retrieveBlob(ccdbPathForAdaptDwnsplFile, ".", metadata, -1, false, adaptDwnsplFileName); + if (!isFileAvailable) { + LOGF(fatal, "Failed to retrieve expected-momentum histograms file from CCDB: %s/%s", ccdbPathForAdaptDwnsplFile.c_str(), adaptDwnsplFileName.c_str()); + } } TFile* adaptDwsplFile = TFile::Open(adaptDwnsplFileName.c_str(), "read"); if (adaptDwsplFile == nullptr || adaptDwsplFile->IsZombie()) { From 424a5d40575a299f11069f48ce86036196b5a538 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Sun, 22 Nov 2026 21:51:14 +0100 Subject: [PATCH 15/22] bugfix previous commit --- DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h index f085342a5e3..a227c4752b2 100644 --- a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h +++ b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h @@ -155,7 +155,7 @@ inline void initAdaptDwnsplHistograms(const std::string& ccdbPathForAdaptDwnsplF o2::ccdb::CcdbApi ccdbApi; ccdbApi.init("http://alice-ccdb.cern.ch"); const std::map metadata; - if (std::filesystem::exists(adaptDwnsplFileName.c_str())) { + if (!std::filesystem::exists(adaptDwnsplFileName.c_str())) { // Retrieve the file from CCDB const bool isFileAvailable = ccdbApi.retrieveBlob(ccdbPathForAdaptDwnsplFile, ".", metadata, -1, false, adaptDwnsplFileName); if (!isFileAvailable) { From 051baf6692648816e69bec06a956edc3437167d0 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Sun, 22 Nov 2026 22:16:14 +0100 Subject: [PATCH 16/22] fix typo adaptDwnsplTargetYield --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index 81bd3c3a2c4..1dce349b8fe 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -86,7 +86,7 @@ struct CfgCommon : ConfigurableGroup { Configurable ccdbPathForAdaptDwnsplFile{"ccdbPathForAdaptDwnsplFile", "", "CCDB path for file with expected-momentum histograms"}; Configurable adaptDwnsplFileName{"adaptDwnsplFileName", "AnalysisResults.root", "Name of the file with expected-momentum histograms"}; Configurable adaptDwnsplHistoScaleFactor{"adaptDwnsplHistoScaleFactor", 1.f, "Scaling factor for the histograms with expected-momentum"}; - Configurable adaptDwnsplTargetYieldsplHistoScaleFactor{"adaptDwnsplTargetYieldsplHistoScaleFactor", 5000000.f, "Target yield of each particle species per log10(p) unity"}; + Configurable adaptDwnsplTargetYield{"adaptDwnsplTargetYield", 5000000.f, "Target yield of each particle species per log10(p) unity"}; Configurable saveReserveQaHisto{"saveReserveQaHisto", true, "Flag to save the DF-wise ratio of output table size to that of input table"}; // Configurables for run condtion table Configurable rctLabel{"rctLabel", "CBT_hadronPID", "select 1 [CBT, CBT_hadronPID, CBT_muon_glo] see O2Physics/Common/CCDB/RCTSelectionFlags.h"}; @@ -543,7 +543,7 @@ struct TreeWriterTpcV0 { } if (cfgsCommon.saveTrees) { const TH2* histoMomentum = isPositive ? mHistMomentumPos : mHistMomentumNeg; - if (cfgsCommon.applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, dauTrack.tpcInnerParam(), daughter.id, cfgsCommon.adaptDwnsplTargetYieldsplHistoScaleFactor, histoMomentum)) { + if (cfgsCommon.applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, dauTrack.tpcInnerParam(), daughter.id, cfgsCommon.adaptDwnsplTargetYield, histoMomentum)) { return false; } OccupancyValues occValues{}; @@ -999,7 +999,7 @@ struct TreeWriterTpcTof { } if (cfgsCommon.saveTrees) { const TH2* histoMomentum = trk.signed1Pt() > 0 ? mHistMomentumPos : mHistMomentumNeg; - if (cfgsCommon.applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, trk.tpcInnerParam(), tofTrack->pid, cfgsCommon.adaptDwnsplTargetYieldsplHistoScaleFactor, histoMomentum)) { + if (cfgsCommon.applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, trk.tpcInnerParam(), tofTrack->pid, cfgsCommon.adaptDwnsplTargetYield, histoMomentum)) { continue; } fillSkimmedTpcTofTable(trk, trackQA, existTrkQA, collision, tofTrack->tpcNSigma, tofTrack->tofNSigma, tofTrack->itsNSigma, tofTrack->tpcExpSignal, tofTrack->pid, runnumber, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent); From 0dfb5a57332377c7309870dc8fed0ee2bd2917d9 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Tue, 24 Nov 2026 00:32:58 +0100 Subject: [PATCH 17/22] merge hMomentum[Pos,Neg] to hParticleVsMomentum (write) --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 28 +++++++++----------------- DPG/Tasks/TPC/tpcSkimsTableCreator.h | 2 +- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index 1dce349b8fe..967c21a106e 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -208,11 +208,10 @@ struct TreeWriterTpcV0 { } if (cfgsCommon.saveMomentumHistograms) { - registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{cfgsCommon.axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); - registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{cfgsCommon.axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + registry.add("hParticleVsMomentum", "hParticleVsMomentum;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{cfgsCommon.axisMomentumHistograms}, {2 * o2::track::PID::NIDs, -0.5, 2 * o2::track::PID::NIDs - 0.5}}}); for (int iParticle = 0; iParticle < o2::track::PID::NIDs; ++iParticle) { - registry.get(HIST("hMomentumPos"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); - registry.get(HIST("hMomentumNeg"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); + registry.get(HIST("hParticleVsMomentum"))->GetYaxis()->SetBinLabel(iParticle + 1, (static_cast(ParticleNames.at(iParticle)) + "^{+}").c_str()); + registry.get(HIST("hParticleVsMomentum"))->GetYaxis()->SetBinLabel(iParticle + 1 + o2::track::PID::NIDs, (static_cast(ParticleNames.at(iParticle)) + "^{-}").c_str()); } } @@ -535,11 +534,8 @@ struct TreeWriterTpcV0 { if (passTrackSelection && passNSigmaTofCut && passMatchTofRequirement) { if (cfgsCommon.saveMomentumHistograms) { const double log10p = std::log10(dauTrack.tpcInnerParam()); - if (isPositive) { - registry.fill(HIST("hMomentumPos"), log10p, daughter.id); - } else { - registry.fill(HIST("hMomentumNeg"), log10p, daughter.id); - } + const int pidShift = isPositive ? 0 : o2::track::PID::NIDs; + registry.fill(HIST("hParticleVsMomentum"), log10p, pidShift + daughter.id); } if (cfgsCommon.saveTrees) { const TH2* histoMomentum = isPositive ? mHistMomentumPos : mHistMomentumNeg; @@ -781,11 +777,10 @@ struct TreeWriterTpcTof { } if (cfgsCommon.saveMomentumHistograms) { - registry.add("hMomentumPos", "hMomentumPos;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{cfgsCommon.axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); - registry.add("hMomentumNeg", "hMomentumNeg;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{cfgsCommon.axisMomentumHistograms}, {o2::track::PID::NIDs, 0, o2::track::PID::NIDs}}}); + registry.add("hParticleVsMomentum", "hParticleVsMomentum;log_{10}(#it{p} / (GeV/#it{c}));PID id", {HistType::kTH2D, {{cfgsCommon.axisMomentumHistograms}, {2 * o2::track::PID::NIDs, -0.5, 2 * o2::track::PID::NIDs - 0.5}}}); for (int iParticle = 0; iParticle < o2::track::PID::NIDs; ++iParticle) { - registry.get(HIST("hMomentumPos"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); - registry.get(HIST("hMomentumNeg"))->GetYaxis()->SetBinLabel(iParticle + 1, ParticleNames.at(iParticle).data()); + registry.get(HIST("hParticleVsMomentum"))->GetYaxis()->SetBinLabel(iParticle + 1, (static_cast(ParticleNames.at(iParticle)) + "^{+}").c_str()); + registry.get(HIST("hParticleVsMomentum"))->GetYaxis()->SetBinLabel(iParticle + 1 + o2::track::PID::NIDs, (static_cast(ParticleNames.at(iParticle)) + "^{-}").c_str()); } } @@ -991,11 +986,8 @@ struct TreeWriterTpcTof { if (cfgsCommon.saveMomentumHistograms) { const double log10p = std::log10(trk.tpcInnerParam()); const bool isPositive = (trk.signed1Pt() > 0); - if (isPositive) { - registry.fill(HIST("hMomentumPos"), log10p, tofTrack->pid); - } else { - registry.fill(HIST("hMomentumNeg"), log10p, tofTrack->pid); - } + const int pidShift = isPositive ? 0 : o2::track::PID::NIDs; + registry.fill(HIST("hParticleVsMomentum"), log10p, pidShift + tofTrack->pid); } if (cfgsCommon.saveTrees) { const TH2* histoMomentum = trk.signed1Pt() > 0 ? mHistMomentumPos : mHistMomentumNeg; diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.h b/DPG/Tasks/TPC/tpcSkimsTableCreator.h index 3778fd663f0..fcc51c26f0e 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.h +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.h @@ -166,6 +166,6 @@ constexpr double MultiplicityNorm{11000.}; constexpr float OneToKilo{1e-3f}; -constexpr std::array ParticleNames{"e", "#mu", "#pi", "K", "p", "d", "t", "{}^{3}He", "#alpha"}; +constexpr std::array ParticleNames{"e", "#mu", "#pi", "K", "p", "d", "t", "{}^{3}He", "#alpha"}; } // namespace o2::dpg_tpcskimstablecreator #endif // DPG_TASKS_TPC_TPCSKIMSTABLECREATOR_H_ From 534cf86603e886bc8640c517c317da2108939dfe Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Tue, 24 Nov 2026 00:59:23 +0100 Subject: [PATCH 18/22] merge hMomentum[Pos,Neg] to hParticleVsMomentum (read & apply) --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 30 +++++++++-------------- DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h | 27 ++++++++------------ 2 files changed, 21 insertions(+), 36 deletions(-) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index 967c21a106e..2a99c569c3b 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -117,8 +117,7 @@ struct TreeWriterTpcV0 { Configurable rejectNoTofDauTrackKa{"rejectNoTofDauTrackKa", false, "reject not matched to TOF kaon daughter tracks"}; /// Configurables adaptive downsampling - Configurable adaptDwnsplHistoPosName{"adaptDwnsplHistoPosName", "tree-writer-tpc-v0/hMomentumPos", "Name of the histogram with expected-momentum of positively charged particles"}; - Configurable adaptDwnsplHistoNegName{"adaptDwnsplHistoNegName", "tree-writer-tpc-v0/hMomentumNeg", "Name of the histogram with expected-momentum of negatively charged particles"}; + Configurable adaptDwnsplHistoName{"adaptDwnsplHistoName", "tree-writer-tpc-v0/hParticleVsMomentum", "Name of the histogram with expected-momentum of particles"}; // Configurables for output tables reservation size Configurable reserveV0Ratio{"reserveV0Ratio", 0.05, "Ratio of how many tracks from V0s are expected in the output table to the input V0 table size"}; Configurable reserveCascRatio{"reserveCascRatio", 0.0025, "Ratio of how many tracks from cascades are expected in the output table to the input Cascade table size"}; @@ -172,8 +171,7 @@ struct TreeWriterTpcV0 { TRandom3* fRndm = new TRandom3(); - TH2* mHistMomentumPos{}; - TH2* mHistMomentumNeg{}; + TH2* mHistMomentum{}; using Trks = soa::Join; using TrksWithDEdxCorrection = soa::Join; @@ -216,10 +214,9 @@ struct TreeWriterTpcV0 { } if (cfgsCommon.applyAdaptiveDownsampling) { - initAdaptDwnsplHistograms(cfgsCommon.ccdbPathForAdaptDwnsplFile, cfgsCommon.adaptDwnsplFileName, adaptDwnsplHistoPosName, adaptDwnsplHistoNegName, mHistMomentumPos, mHistMomentumNeg); + initAdaptDwnsplHistograms(cfgsCommon.ccdbPathForAdaptDwnsplFile, cfgsCommon.adaptDwnsplFileName, adaptDwnsplHistoName, mHistMomentum); if (cfgsCommon.adaptDwnsplHistoScaleFactor != 1.f) { - mHistMomentumPos->Scale(cfgsCommon.adaptDwnsplHistoScaleFactor); - mHistMomentumNeg->Scale(cfgsCommon.adaptDwnsplHistoScaleFactor); + mHistMomentum->Scale(cfgsCommon.adaptDwnsplHistoScaleFactor); } } } @@ -538,8 +535,7 @@ struct TreeWriterTpcV0 { registry.fill(HIST("hParticleVsMomentum"), log10p, pidShift + daughter.id); } if (cfgsCommon.saveTrees) { - const TH2* histoMomentum = isPositive ? mHistMomentumPos : mHistMomentumNeg; - if (cfgsCommon.applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, dauTrack.tpcInnerParam(), daughter.id, cfgsCommon.adaptDwnsplTargetYield, histoMomentum)) { + if (cfgsCommon.applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, dauTrack.tpcInnerParam(), daughter.id, cfgsCommon.adaptDwnsplTargetYield, mHistMomentum, isPositive)) { return false; } OccupancyValues occValues{}; @@ -709,8 +705,7 @@ struct TreeWriterTpcTof { // Configurable for output table reservation size Configurable reserveTrackRatio{"reserveTrackRatio", 0.003, "Ratio of how many tracks are expected in the output table to the input Tracks table size"}; // Configurables for run condtion table - Configurable adaptDwnsplHistoPosName{"adaptDwnsplHistoPosName", "tree-writer-tpc-tof/hMomentumPos", "Name of the histogram with expected-momentum of positively charged particles"}; - Configurable adaptDwnsplHistoNegName{"adaptDwnsplHistoNegName", "tree-writer-tpc-tof/hMomentumNeg", "Name of the histogram with expected-momentum of negatively charged particles"}; + Configurable adaptDwnsplHistoName{"adaptDwnsplHistoName", "tree-writer-tpc-v0/hParticleVsMomentum", "Name of the histogram with expected-momentum of particles"}; HistogramRegistry registry{"registry", {}}; @@ -735,8 +730,7 @@ struct TreeWriterTpcTof { TRandom3* fRndm = new TRandom3(); - TH2* mHistMomentumPos{}; - TH2* mHistMomentumNeg{}; + TH2* mHistMomentum{}; using Trks = soa::JoinScale(cfgsCommon.adaptDwnsplHistoScaleFactor); - mHistMomentumNeg->Scale(cfgsCommon.adaptDwnsplHistoScaleFactor); + mHistMomentum->Scale(cfgsCommon.adaptDwnsplHistoScaleFactor); } } } @@ -982,16 +975,15 @@ struct TreeWriterTpcTof { const bool passMomHardCut = trk.tpcInnerParam() < tofTrack->maxMomHardCutOnly; const bool passMomTpcOnly = trk.tpcInnerParam() <= tofTrack->maxMomTPCOnly && std::fabs(tofTrack->tpcNSigma) < tofTrack->nSigmaTPCOnly; const bool passMomTpcTof = trk.tpcInnerParam() > tofTrack->maxMomTPCOnly && std::fabs(tofTrack->tofNSigma) < tofTrack->nSigmaTofTpctof && std::fabs(tofTrack->tpcNSigma) < tofTrack->nSigmaTpcTpctof; + const bool isPositive = (trk.signed1Pt() > 0); if (passMomHardCut && (passMomTpcOnly || passMomTpcTof)) { if (cfgsCommon.saveMomentumHistograms) { const double log10p = std::log10(trk.tpcInnerParam()); - const bool isPositive = (trk.signed1Pt() > 0); const int pidShift = isPositive ? 0 : o2::track::PID::NIDs; registry.fill(HIST("hParticleVsMomentum"), log10p, pidShift + tofTrack->pid); } if (cfgsCommon.saveTrees) { - const TH2* histoMomentum = trk.signed1Pt() > 0 ? mHistMomentumPos : mHistMomentumNeg; - if (cfgsCommon.applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, trk.tpcInnerParam(), tofTrack->pid, cfgsCommon.adaptDwnsplTargetYield, histoMomentum)) { + if (cfgsCommon.applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, trk.tpcInnerParam(), tofTrack->pid, cfgsCommon.adaptDwnsplTargetYield, mHistMomentum, isPositive)) { continue; } fillSkimmedTpcTofTable(trk, trackQA, existTrkQA, collision, tofTrack->tpcNSigma, tofTrack->tofNSigma, tofTrack->itsNSigma, tofTrack->tpcExpSignal, tofTrack->pid, runnumber, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent); diff --git a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h index a227c4752b2..08472139a8f 100644 --- a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h +++ b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h @@ -150,7 +150,7 @@ void evaluateOccupancyVariables(const TrkType& track, OccupancyValues& occValues occValues.twmoRT0V0PrimUnfm80 = tmoFromTrack.twmoRobustT0V0PrimUnfm80(); } -inline void initAdaptDwnsplHistograms(const std::string& ccdbPathForAdaptDwnsplFile, const std::string& adaptDwnsplFileName, const std::string& adaptDwnsplHistoPosName, const std::string& adaptDwnsplHistoNegName, TH2*& histoPos, TH2*& histoNeg) +inline void initAdaptDwnsplHistograms(const std::string& ccdbPathForAdaptDwnsplFile, const std::string& adaptDwnsplFileName, const std::string& adaptDwnsplHistoName, TH2*& histo) { o2::ccdb::CcdbApi ccdbApi; ccdbApi.init("http://alice-ccdb.cern.ch"); @@ -166,31 +166,24 @@ inline void initAdaptDwnsplHistograms(const std::string& ccdbPathForAdaptDwnsplF if (adaptDwsplFile == nullptr || adaptDwsplFile->IsZombie()) { LOGF(fatal, "Failed to open expected-momentum histograms file from CCDB: %s/%s", ccdbPathForAdaptDwnsplFile.c_str(), adaptDwnsplFileName.c_str()); } - histoPos = dynamic_cast(adaptDwsplFile->Get(adaptDwnsplHistoPosName.c_str())->Clone()); - histoNeg = dynamic_cast(adaptDwsplFile->Get(adaptDwnsplHistoNegName.c_str())->Clone()); - if (histoPos == nullptr) { - LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", adaptDwnsplHistoPosName.c_str()); + histo = dynamic_cast(adaptDwsplFile->Get(adaptDwnsplHistoName.c_str())->Clone()); + if (histo == nullptr) { + LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", adaptDwnsplHistoName.c_str()); } - if (histoNeg == nullptr) { - LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", adaptDwnsplHistoNegName.c_str()); + if (histo->GetXaxis()->IsVariableBinSize()) { + LOGF(fatal, "Histogram %s has variable bin size, which is not allowed!", adaptDwnsplHistoName.c_str()); } - if (histoPos->GetXaxis()->IsVariableBinSize()) { - LOGF(fatal, "Histogram %s has variable bin size, which is not allowed!", adaptDwnsplHistoPosName.c_str()); - } - if (histoNeg->GetXaxis()->IsVariableBinSize()) { - LOGF(fatal, "Histogram %s has variable bin size, which is not allowed!", adaptDwnsplHistoNegName.c_str()); - } - histoPos->SetDirectory(nullptr); - histoNeg->SetDirectory(nullptr); + histo->SetDirectory(nullptr); adaptDwsplFile->Close(); delete adaptDwsplFile; adaptDwsplFile = nullptr; } -inline bool performAdaptiveDownsampling(TRandom3* fRndm, const double p, const o2::track::PID::ID pid, const double targetYield, const TH2* histoExpected) +inline bool performAdaptiveDownsampling(TRandom3* fRndm, const double p, const o2::track::PID::ID pid, const double targetYield, const TH2* histoExpected, const bool isPositive) { + const int pidShift = isPositive ? 0 : o2::track::PID::NIDs; const double targetYieldPerBin = targetYield * histoExpected->GetXaxis()->GetBinWidth(1); - const double yieldExpected = histoExpected->GetBinContent(histoExpected->GetXaxis()->FindBin(std::log10(p)), pid); + const double yieldExpected = histoExpected->GetBinContent(histoExpected->GetXaxis()->FindBin(std::log10(p)), histoExpected->GetYaxis()->FindBin(pidShift + pid)); if (yieldExpected < targetYieldPerBin) { return true; } From b4e982a8478e0d5e862dde7f0b17a401e2e49501 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Tue, 24 Nov 2026 01:07:27 +0100 Subject: [PATCH 19/22] guard against conflict between v0 & tof when download adaptDwnsplFileName --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 2 +- DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index 2a99c569c3b..9fc2c1c78c0 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -705,7 +705,7 @@ struct TreeWriterTpcTof { // Configurable for output table reservation size Configurable reserveTrackRatio{"reserveTrackRatio", 0.003, "Ratio of how many tracks are expected in the output table to the input Tracks table size"}; // Configurables for run condtion table - Configurable adaptDwnsplHistoName{"adaptDwnsplHistoName", "tree-writer-tpc-v0/hParticleVsMomentum", "Name of the histogram with expected-momentum of particles"}; + Configurable adaptDwnsplHistoName{"adaptDwnsplHistoName", "tree-writer-tpc-tof/hParticleVsMomentum", "Name of the histogram with expected-momentum of particles"}; HistogramRegistry registry{"registry", {}}; diff --git a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h index 08472139a8f..88d3869cc88 100644 --- a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h +++ b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h @@ -161,6 +161,8 @@ inline void initAdaptDwnsplHistograms(const std::string& ccdbPathForAdaptDwnsplF if (!isFileAvailable) { LOGF(fatal, "Failed to retrieve expected-momentum histograms file from CCDB: %s/%s", ccdbPathForAdaptDwnsplFile.c_str(), adaptDwnsplFileName.c_str()); } + } else { + LOGF(fatal, "The file %s already exists. Make sure that 'adaptDwnsplFileName' has different values for V0 and TPC-TOF", adaptDwnsplFileName.c_str()); } TFile* adaptDwsplFile = TFile::Open(adaptDwnsplFileName.c_str(), "read"); if (adaptDwsplFile == nullptr || adaptDwsplFile->IsZombie()) { From d9d3e1d740123b861ce6228b50ce6143c18bc72d Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Tue, 24 Nov 2026 01:17:01 +0100 Subject: [PATCH 20/22] minor improvement of performance --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 14 ++++++++++---- DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h | 3 +-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index 9fc2c1c78c0..dd8e2c68187 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -173,6 +173,8 @@ struct TreeWriterTpcV0 { TH2* mHistMomentum{}; + double mTargetYieldPerBin{}; + using Trks = soa::Join; using TrksWithDEdxCorrection = soa::Join; using Colls = soa::Join; @@ -213,11 +215,12 @@ struct TreeWriterTpcV0 { } } - if (cfgsCommon.applyAdaptiveDownsampling) { + if (cfgsCommon.applyAdaptiveDownsampling && cfgsCommon.saveTrees) { initAdaptDwnsplHistograms(cfgsCommon.ccdbPathForAdaptDwnsplFile, cfgsCommon.adaptDwnsplFileName, adaptDwnsplHistoName, mHistMomentum); if (cfgsCommon.adaptDwnsplHistoScaleFactor != 1.f) { mHistMomentum->Scale(cfgsCommon.adaptDwnsplHistoScaleFactor); } + mTargetYieldPerBin = cfgsCommon.adaptDwnsplTargetYield * mHistMomentum->GetXaxis()->GetBinWidth(1); } } @@ -535,7 +538,7 @@ struct TreeWriterTpcV0 { registry.fill(HIST("hParticleVsMomentum"), log10p, pidShift + daughter.id); } if (cfgsCommon.saveTrees) { - if (cfgsCommon.applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, dauTrack.tpcInnerParam(), daughter.id, cfgsCommon.adaptDwnsplTargetYield, mHistMomentum, isPositive)) { + if (cfgsCommon.applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, dauTrack.tpcInnerParam(), daughter.id, mTargetYieldPerBin, mHistMomentum, isPositive)) { return false; } OccupancyValues occValues{}; @@ -732,6 +735,8 @@ struct TreeWriterTpcTof { TH2* mHistMomentum{}; + double mTargetYieldPerBin{}; + using Trks = soa::JoinScale(cfgsCommon.adaptDwnsplHistoScaleFactor); } + mTargetYieldPerBin = cfgsCommon.adaptDwnsplTargetYield * mHistMomentum->GetXaxis()->GetBinWidth(1); } } @@ -983,7 +989,7 @@ struct TreeWriterTpcTof { registry.fill(HIST("hParticleVsMomentum"), log10p, pidShift + tofTrack->pid); } if (cfgsCommon.saveTrees) { - if (cfgsCommon.applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, trk.tpcInnerParam(), tofTrack->pid, cfgsCommon.adaptDwnsplTargetYield, mHistMomentum, isPositive)) { + if (cfgsCommon.applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, trk.tpcInnerParam(), tofTrack->pid, mTargetYieldPerBin, mHistMomentum, isPositive)) { continue; } fillSkimmedTpcTofTable(trk, trackQA, existTrkQA, collision, tofTrack->tpcNSigma, tofTrack->tofNSigma, tofTrack->itsNSigma, tofTrack->tpcExpSignal, tofTrack->pid, runnumber, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent); diff --git a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h index 88d3869cc88..d8236d237e4 100644 --- a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h +++ b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h @@ -181,10 +181,9 @@ inline void initAdaptDwnsplHistograms(const std::string& ccdbPathForAdaptDwnsplF adaptDwsplFile = nullptr; } -inline bool performAdaptiveDownsampling(TRandom3* fRndm, const double p, const o2::track::PID::ID pid, const double targetYield, const TH2* histoExpected, const bool isPositive) +inline bool performAdaptiveDownsampling(TRandom3* fRndm, const double p, const o2::track::PID::ID pid, const double targetYieldPerBin, const TH2* histoExpected, const bool isPositive) { const int pidShift = isPositive ? 0 : o2::track::PID::NIDs; - const double targetYieldPerBin = targetYield * histoExpected->GetXaxis()->GetBinWidth(1); const double yieldExpected = histoExpected->GetBinContent(histoExpected->GetXaxis()->FindBin(std::log10(p)), histoExpected->GetYaxis()->FindBin(pidShift + pid)); if (yieldExpected < targetYieldPerBin) { return true; From d740a76dcce9467bd43672b6574a4788ff42b7d0 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Tue, 24 Nov 2026 17:25:00 +0100 Subject: [PATCH 21/22] utilsTpcSkimsTableCreator.h: return after LOGF(fatal) --- DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h index d8236d237e4..d0ecfcf1545 100644 --- a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h +++ b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h @@ -160,20 +160,25 @@ inline void initAdaptDwnsplHistograms(const std::string& ccdbPathForAdaptDwnsplF const bool isFileAvailable = ccdbApi.retrieveBlob(ccdbPathForAdaptDwnsplFile, ".", metadata, -1, false, adaptDwnsplFileName); if (!isFileAvailable) { LOGF(fatal, "Failed to retrieve expected-momentum histograms file from CCDB: %s/%s", ccdbPathForAdaptDwnsplFile.c_str(), adaptDwnsplFileName.c_str()); + return; } } else { LOGF(fatal, "The file %s already exists. Make sure that 'adaptDwnsplFileName' has different values for V0 and TPC-TOF", adaptDwnsplFileName.c_str()); + return; } TFile* adaptDwsplFile = TFile::Open(adaptDwnsplFileName.c_str(), "read"); if (adaptDwsplFile == nullptr || adaptDwsplFile->IsZombie()) { LOGF(fatal, "Failed to open expected-momentum histograms file from CCDB: %s/%s", ccdbPathForAdaptDwnsplFile.c_str(), adaptDwnsplFileName.c_str()); + return; } histo = dynamic_cast(adaptDwsplFile->Get(adaptDwnsplHistoName.c_str())->Clone()); if (histo == nullptr) { LOGF(fatal, "Histogram %s not found in expected-momentum histograms file!", adaptDwnsplHistoName.c_str()); + return; } if (histo->GetXaxis()->IsVariableBinSize()) { LOGF(fatal, "Histogram %s has variable bin size, which is not allowed!", adaptDwnsplHistoName.c_str()); + return; } histo->SetDirectory(nullptr); adaptDwsplFile->Close(); From 6b2a35529f9bb59646243094dac10d7314db4ced Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Tue, 24 Nov 2026 20:20:38 +0100 Subject: [PATCH 22/22] clang-tidy fixes --- DPG/Tasks/TPC/tpcSkimsTableCreator.cxx | 79 ++++++++++++----------- DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h | 1 + 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index dd8e2c68187..4fa97bb0081 100644 --- a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx +++ b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx @@ -37,7 +37,6 @@ #include "Common/TableProducer/PID/pidTPCBase.h" #include -#include #include #include #include @@ -126,13 +125,13 @@ struct TreeWriterTpcV0 { // an arbitrary value of N sigma TOF assigned by TOF task to tracks which are not matched to TOF hits constexpr static float NSigmaTofUnmatched{o2::aod::v0data::kNoTOFValue}; - const float nSigmaTofUnmatchedEqualityTolerance{std::fabs(NSigmaTofUnmatched) / 1e4f}; + const float nSigmaTofUnmatchedEqualityTolerance{std::fabs(NSigmaTofUnmatched) / 1e4f}; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members): should be constexpr, but constexpr-ness of std::fabs() is not guaranteed // an arbitrary value of "N sigma TOF" assigned to electorns (for uniformity reasons) constexpr static float NSigmaTofElectorn{1000.f}; enum { // Reconstructed V0 and cascade MotherUndef = -1, - MotherGamma = 0, + MotherGamma, MotherK0S, MotherLambda, MotherAntiLambda, @@ -142,7 +141,7 @@ struct TreeWriterTpcV0 { enum { DaughterUndef = -1, - DaughterElectron = 0, + DaughterElectron, DaughterPion, DaughterKaon, DaughterProton @@ -165,9 +164,9 @@ struct TreeWriterTpcV0 { Service ccdb{}; - ctpRateFetcher mRateFetcher{}; + ctpRateFetcher mRateFetcher; - o2::aod::rctsel::RCTFlagsChecker rctChecker{}; + o2::aod::rctsel::RCTFlagsChecker rctChecker; TRandom3* fRndm = new TRandom3(); @@ -238,7 +237,7 @@ struct TreeWriterTpcV0 { return V0Daughter{track.tpcNSigmaKa(), getStrangenessTofNSigma(v0Casc, motherId, daughterId, isPositive), track.itsNSigmaKa(), track.tpcExpSignalKa(tpcSignalGeneric(track)), PidKaon, nSigmaTofDauTrackKa, rejectNoTofDauTrackKa}; default: { LOGP(fatal, "createV0Daughter: unknown daughterId"); - return V0Daughter(); + return {}; } } } @@ -247,20 +246,20 @@ struct TreeWriterTpcV0 { { switch (motherId) { case MotherGamma: - return V0Mother{DaughterElectron, DaughterElectron}; + return V0Mother{.posDaughterId = DaughterElectron, .negDaughterId = DaughterElectron}; case MotherK0S: - return V0Mother{DaughterPion, DaughterPion}; + return V0Mother{.posDaughterId = DaughterPion, .negDaughterId = DaughterPion}; case MotherLambda: - return V0Mother{DaughterProton, DaughterPion}; + return V0Mother{.posDaughterId = DaughterProton, .negDaughterId = DaughterPion}; case MotherAntiLambda: - return V0Mother{DaughterPion, DaughterProton}; + return V0Mother{.posDaughterId = DaughterPion, .negDaughterId = DaughterProton}; case MotherOmega: - return V0Mother{DaughterUndef, DaughterKaon}; + return V0Mother{.posDaughterId = DaughterUndef, .negDaughterId = DaughterKaon}; case MotherAntiOmega: - return V0Mother{DaughterKaon, DaughterUndef}; + return V0Mother{.posDaughterId = DaughterKaon, .negDaughterId = DaughterUndef}; default: { LOGP(fatal, "createV0Mother: unknown motherId"); - return V0Mother(); + return {}; } } } @@ -269,21 +268,25 @@ struct TreeWriterTpcV0 { { if (motherId == MotherGamma && daughterId == DaughterElectron) { return NSigmaTofElectorn; - } else if (motherId == MotherK0S && daughterId == DaughterPion) { - if (isPositive) - return v0.tofNSigmaK0PiPlus(); - else - return v0.tofNSigmaK0PiMinus(); - } else if (motherId == MotherLambda) { - if (daughterId == DaughterProton && isPositive) + } + if (motherId == MotherK0S && daughterId == DaughterPion) { + return isPositive ? v0.tofNSigmaK0PiPlus() : v0.tofNSigmaK0PiMinus(); + } + if (motherId == MotherLambda) { + if (daughterId == DaughterProton && isPositive) { return v0.tofNSigmaLaPr(); - else if (daughterId == DaughterPion && !isPositive) + } + if (daughterId == DaughterPion && !isPositive) { return v0.tofNSigmaLaPi(); - } else if (motherId == MotherAntiLambda) { - if (daughterId == DaughterProton && !isPositive) + } + } + if (motherId == MotherAntiLambda) { + if (daughterId == DaughterProton && !isPositive) { return v0.tofNSigmaALaPr(); - else if (daughterId == DaughterPion && isPositive) + } + if (daughterId == DaughterPion && isPositive) { return v0.tofNSigmaALaPi(); + } } LOGP(fatal, "getStrangenessTofNSigma for V0: wrong combination of motherId, daughterId and sign"); @@ -292,8 +295,9 @@ struct TreeWriterTpcV0 { float getStrangenessTofNSigma(CascsWithID::iterator const& casc, const int motherId, const int daughterId, bool) { - if ((motherId == MotherOmega || motherId == MotherAntiOmega) && daughterId == DaughterKaon) + if ((motherId == MotherOmega || motherId == MotherAntiOmega) && daughterId == DaughterKaon) { return casc.tofNSigmaOmKa(); + } LOGP(fatal, "getStrangenessTofNSigma for cascade: wrong combination of motherId and daughterId"); return UndefValueFloat; @@ -415,30 +419,33 @@ struct TreeWriterTpcV0 { template double getCosPA(V0Casc const& v0casc, CollisionType const& collision) { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) { return v0casc.v0cosPA(); - else + } else { return v0casc.casccosPA(collision.posX(), collision.posY(), collision.posZ()); + } } /// Evaluate radius of v0 or casc template double getRadius(V0Casc const& v0casc) { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) { return v0casc.v0radius(); - else + } else { return v0casc.cascradius(); + } } /// Evaluate add id of v0 or casc template int getAddId(V0Casc const& v0casc) { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) { return v0casc.v0addid(); - else + } else { return v0casc.cascaddid(); + } } template @@ -468,7 +475,7 @@ struct TreeWriterTpcV0 { int nV0Entries{0}; int nCascEntries{0}; - const int64_t expectedOutputTableSize = static_cast(reserveV0Ratio * myV0s.size() + reserveCascRatio * myCascs.size()); + const auto expectedOutputTableSize = static_cast(reserveV0Ratio * myV0s.size() + reserveCascRatio * myCascs.size()); if constexpr (ModeId == ModeWithdEdxTrkQA || ModeId == ModeStandard) { rowTPCTree.reserve(expectedOutputTableSize); } else { @@ -577,7 +584,7 @@ struct TreeWriterTpcV0 { } const auto bachTrack = casc.bachelor_as(); // Omega and antiomega - const auto isDaughterPositive = cascId == MotherAntiOmega ? true : false; + const auto isDaughterPositive = cascId == MotherAntiOmega; if (fillDaughterTrack(casc, bachTrack, casc, isDaughterPositive)) { ++nCascEntries; } @@ -727,9 +734,9 @@ struct TreeWriterTpcTof { Service ccdb{}; - ctpRateFetcher mRateFetcher{}; + ctpRateFetcher mRateFetcher; - o2::aod::rctsel::RCTFlagsChecker rctChecker{}; + o2::aod::rctsel::RCTFlagsChecker rctChecker; TRandom3* fRndm = new TRandom3(); diff --git a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h index d0ecfcf1545..7f959a64e8d 100644 --- a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h +++ b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include