diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx b/DPG/Tasks/TPC/tpcSkimsTableCreator.cxx index ec4c98f2d6d..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 @@ -48,6 +47,7 @@ #include #include +#include #include #include @@ -75,11 +75,38 @@ using CascsWithID = soa::Join concept V0OrCasc = std::same_as || std::same_as; +struct CfgCommon : ConfigurableGroup { + /// 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", 0, "Track selection: 0 -> No Cut, 1 -> kGlobalTrack, 2 -> kGlobalTrackWoPtEta, 3 -> kGlobalTrackWoDCA, 4 -> kQualityTracks, 5 -> kInAcceptanceTracks"}; + /// 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 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"}; + 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}))"}; +}; + 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"}; @@ -87,45 +114,24 @@ struct TreeWriterTpcV0 { 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"}; - /// 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 adaptive downsampling + 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"}; - 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"}; HistogramRegistry registry{"registry", {}}; // 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, @@ -135,22 +141,18 @@ struct TreeWriterTpcV0 { enum { DaughterUndef = -1, - DaughterElectron = 0, + DaughterElectron, DaughterPion, DaughterKaon, DaughterProton }; 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}; }; @@ -162,12 +164,16 @@ struct TreeWriterTpcV0 { Service ccdb{}; - ctpRateFetcher mRateFetcher{}; + ctpRateFetcher mRateFetcher; - o2::aod::rctsel::RCTFlagsChecker rctChecker{}; + o2::aod::rctsel::RCTFlagsChecker rctChecker; TRandom3* fRndm = new TRandom3(); + TH2* mHistMomentum{}; + + double mTargetYieldPerBin{}; + using Trks = soa::Join; using TrksWithDEdxCorrection = soa::Join; using Colls = soa::Join; @@ -185,16 +191,36 @@ struct TreeWriterTpcV0 { LOGP(fatal, "One and only one process function should be enabled"); } + if (!(cfgsCommon.saveTrees || cfgsCommon.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); - 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 (cfgsCommon.saveMomentumHistograms) { + 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("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()); + } + } + + 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); + } } template @@ -202,16 +228,16 @@ 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(); + return {}; } } } @@ -220,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 {}; } } } @@ -242,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"); @@ -265,15 +295,16 @@ 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; } 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(); @@ -292,98 +323,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(cfgsCommon.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(cfgsCommon.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 @@ -391,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 @@ -444,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 { @@ -452,14 +483,13 @@ struct TreeWriterTpcV0 { } std::string irSource{}; - float sqrtSNN{}; 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; } @@ -467,7 +497,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, cfgsCommon.ccdbPathGrpLhcIf, bc.timestamp()); } isFirstCollision = false; const int runnumber = bc.runNumber(); @@ -505,17 +535,26 @@ 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 passDownsamplig = downsampleTsalisCharged(fRndm, dauTrack.pt(), daughter.downsamplingTsalis, daughter.mass, sqrtSNN, daughter.maxPt4dwnsmplTsalis); + 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 && passDownsamplig && passNSigmaTofCut && passMatchTofRequirement) { - OccupancyValues occValues{}; - if constexpr (ModeId == ModeWithTrkQA) { - evaluateOccupancyVariables(dauTrack, occValues); + if (passTrackSelection && passNSigmaTofCut && passMatchTofRequirement) { + if (cfgsCommon.saveMomentumHistograms) { + const double log10p = std::log10(dauTrack.tpcInnerParam()); + const int pidShift = isPositive ? 0 : o2::track::PID::NIDs; + registry.fill(HIST("hParticleVsMomentum"), log10p, pidShift + daughter.id); + } + if (cfgsCommon.saveTrees) { + if (cfgsCommon.applyAdaptiveDownsampling && !performAdaptiveDownsampling(fRndm, dauTrack.tpcInnerParam(), daughter.id, mTargetYieldPerBin, mHistMomentum, isPositive)) { + return false; + } + 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, 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; }; @@ -545,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; } @@ -559,7 +598,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()); } @@ -641,87 +680,70 @@ 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"}; 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 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"}; - 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 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"}; - 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"}; // 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"}; + Configurable adaptDwnsplHistoName{"adaptDwnsplHistoName", "tree-writer-tpc-tof/hParticleVsMomentum", "Name of the histogram with expected-momentum of particles"}; HistogramRegistry registry{"registry", {}}; struct TofTrack { - bool isApplyHardCutOnly{false}; double maxMomHardCutOnly{UndefValueDouble}; 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}; }; Service ccdb{}; - ctpRateFetcher mRateFetcher{}; + ctpRateFetcher mRateFetcher; - o2::aod::rctsel::RCTFlagsChecker rctChecker{}; + o2::aod::rctsel::RCTFlagsChecker rctChecker; TRandom3* fRndm = new TRandom3(); + TH2* mHistMomentum{}; + + double mTargetYieldPerBin{}; + using Trks = soa::JoinsetURL("http://alice-ccdb.cern.ch"); 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 (cfgsCommon.saveMomentumHistograms) { + 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("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()); + } + } + + 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); + } } 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(); @@ -770,86 +812,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(cfgsCommon.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(cfgsCommon.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 @@ -881,15 +920,14 @@ struct TreeWriterTpcTof { } std::string irSource{}; - float sqrtSNN{}; 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; } @@ -903,7 +941,7 @@ struct TreeWriterTpcTof { const auto bc = collision.bc_as(); if (isFirstCollision) { - evaluateIrSourceAndSqrtSnn(ccdb, ccdbPathGrpLhcIf, bc.timestamp(), irSource, sqrtSNN); + irSource = evaluateIrSource(ccdb, cfgsCommon.ccdbPathGrpLhcIf, bc.timestamp()); } isFirstCollision = false; const int runnumber = bc.runNumber(); @@ -918,7 +956,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 @@ -931,15 +969,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(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(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(maxMomHardCutOnlyPr, 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(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(maxMomHardCutOnlyPi, maxMomTPCOnlyPi, trk.tpcNSigmaPi(), nSigmaTPCOnlyPi, trk.tofNSigmaPi(), trk.itsNSigmaPi(), trk.tpcExpSignalPi(tpcSignalGeneric(trk)), PidPion, nSigmaTofTpctofPi, nSigmaTpcTpctofPi); OccupancyValues occValues{}; if constexpr (ModeId == ModeWithTrkQA) { @@ -947,12 +985,22 @@ 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; - 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); + const bool isPositive = (trk.signed1Pt() > 0); + if (passMomHardCut && (passMomTpcOnly || passMomTpcTof)) { + if (cfgsCommon.saveMomentumHistograms) { + const double log10p = std::log10(trk.tpcInnerParam()); + const int pidShift = isPositive ? 0 : o2::track::PID::NIDs; + registry.fill(HIST("hParticleVsMomentum"), log10p, pidShift + tofTrack->pid); + } + if (cfgsCommon.saveTrees) { + 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); + } } } } /// Loop tracks @@ -962,7 +1010,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 diff --git a/DPG/Tasks/TPC/tpcSkimsTableCreator.h b/DPG/Tasks/TPC/tpcSkimsTableCreator.h index 9172d8d2447..fcc51c26f0e 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_ 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 a3b3dcddc17..7f959a64e8d 100644 --- a/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h +++ b/DPG/Tasks/TPC/utilsTpcSkimsTableCreator.h @@ -26,15 +26,21 @@ #include "Common/DataModel/OccupancyTables.h" #include +#include #include #include #include #include +#include +#include +#include #include #include #include +#include +#include #include namespace o2::dpg_tpcskimstablecreator @@ -65,34 +71,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) @@ -119,9 +97,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); @@ -130,14 +109,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 { @@ -175,5 +151,54 @@ 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& adaptDwnsplHistoName, TH2*& histo) +{ + o2::ccdb::CcdbApi ccdbApi; + ccdbApi.init("http://alice-ccdb.cern.ch"); + const std::map metadata; + 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()); + 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(); + delete adaptDwsplFile; + adaptDwsplFile = nullptr; +} + +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 yieldExpected = histoExpected->GetBinContent(histoExpected->GetXaxis()->FindBin(std::log10(p)), histoExpected->GetYaxis()->FindBin(pidShift + 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_