From 3d553705bed6fe693bf56051173db2e868a06fa3 Mon Sep 17 00:00:00 2001 From: Somadutta Bhatta Date: Wed, 4 Mar 2026 01:29:00 +0100 Subject: [PATCH 1/6] [PWGCF] DCA cut for global tracks --- .../Tasks/radialFlowDecorr.cxx | 6068 +++++++++-------- 1 file changed, 3121 insertions(+), 2947 deletions(-) diff --git a/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx b/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx index 8a6cf4b5f61..80f8a08bb6e 100644 --- a/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx +++ b/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx @@ -13,18 +13,23 @@ /// \brief Analysis task for event-by-event radial-flow decorrelation measurement. /// \author Somadutta Bhatta -#include "Common/Core/RecoDecay.h" #include "Common/Core/trackUtilities.h" +#include "Common/Core/TrackSelection.h" +#include "Common/DataModel/TrackSelectionTables.h" #include "Common/DataModel/Centrality.h" #include "Common/DataModel/EventSelection.h" +#include "Common/DataModel/FT0Corrected.h" #include "Common/DataModel/Multiplicity.h" #include "Common/DataModel/PIDResponseTOF.h" #include "Common/DataModel/PIDResponseTPC.h" +#include "Common/DataModel/PIDResponseITS.h" #include "Common/DataModel/TrackSelectionTables.h" #include "CCDB/BasicCCDBManager.h" #include "CommonConstants/MathConstants.h" #include "DataFormatsParameters/GRPObject.h" +#include "DetectorsCommonDataFormats/AlignParam.h" +#include "FT0Base/Geometry.h" #include "Framework/ASoAHelpers.h" #include "Framework/AnalysisDataModel.h" #include "Framework/AnalysisTask.h" @@ -37,6 +42,7 @@ #include "ReconstructionDataFormats/DCA.h" #include "ReconstructionDataFormats/Track.h" #include "ReconstructionDataFormats/TrackTPCITS.h" +#include "ReconstructionDataFormats/PID.h" #include "TDirectory.h" #include "TFile.h" @@ -68,44 +74,29 @@ using namespace constants::math; struct RadialFlowDecorr { + static constexpr int KnFt0cCell = 96; static constexpr int KIntM = 3; static constexpr int KIntK = 3; - static constexpr int KNEta = 17; - static constexpr int KNpT = 3; - static constexpr float KFloatEpsilon = 1e-6f; static constexpr int KPiPlus = 211; static constexpr int KKPlus = 321; static constexpr int KProton = 2212; - static constexpr int KNsp = 4; - - static constexpr float KCentTestMin = 10.f; - static constexpr float KCentTestMaxLo = 60.f; - static constexpr float KCentTestMaxHi = 70.f; - static constexpr float KCentCovCut = 1.0f; static constexpr float KBinOffset = 0.5f; - - static constexpr float KHalf = 0.5f; static constexpr float KPhiMin = 0.f; - static constexpr int KNbinsZvtx = 240; static constexpr float KZvtxMin = -12.f; static constexpr float KZvtxMax = 12.f; - static constexpr int KNbinsP = 100; static constexpr float KPMin = 0.f; static constexpr float KPMax = 10.f; static constexpr int KNbinsPt = 200; - static constexpr float KPtMin = 0.f; + static constexpr float KPtMin = 0.15f; static constexpr float KPtMax = 10.f; - static constexpr int KNbinsEta = 120; static constexpr float KEtaMin = -1.2f; static constexpr float KEtaMax = 1.2f; static constexpr int KNbinsPhi = 64; static constexpr float KEtaAxisMin = -0.8f; static constexpr float KEtaAxisMax = 0.8f; - static constexpr int KNbinsPhiFine = 16; - static constexpr int KNbinsPtRes = 50; static constexpr float KPtResMax = 1.f; static constexpr int KNbinsEtaRes = 100; @@ -118,3102 +109,3285 @@ struct RadialFlowDecorr { static constexpr float KEtaFineMax = 1.f; static constexpr int KNbinsDca = 400; static constexpr float KDcaMax = 0.2f; - static constexpr int KNbinsPtCoarse = 50; - static constexpr float KPtMinDefault = 0.2f; - static constexpr float KPtMidMax = 3.0f; - static constexpr float KPtHighMax = 5.0f; - static constexpr float KPtFullMax = 10.0f; static constexpr float KCentMax = 90; - enum PID { - numKInclusive = 0, // Suffix "" - numKPion, // Suffix "_Pi" - numKKaon, // Suffix "_Ka" - numKProton, // Suffix "_Pr" - numKNumPID // Total: 4 + + enum PIDIdx { + kInclusiveIdx = 0, + kPiMinusIdx, kPiPlusIdx, kPiAllIdx, + kKaMinusIdx, kKaPlusIdx, kKaAllIdx, + kAntiPrIdx, kPrIdx, kAllPrIdx, + KNsp }; - const std::vector pidSuffix = {"", "_Pi", "_Ka", "_Pr"}; + const std::vector pidSuffix = {"", "_PiMinus", "_PiPlus", "_PiAll", "_KaMinus", "_KaPlus", "_KaAll", "_AntiPr", "_Pr", "_AllPr"}; enum ECentralityEstimator { - kCentFT0C = 1, - kCentFT0A = 2, - kCentFT0M = 3, - kCentFV0A = 4 + kCentFT0M = 1, + kCentFDDM = 2, + kCentFV0A = 3 }; enum SystemType { kPbPb = 1, - kOO = 2, - kpPb = 3, + kNeNe = 2, + kOO = 3, kpp = 4 }; static constexpr float KinvalidCentrality = -1.0f; const std::vector etaLw = { -0.8, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7}; - const std::vector etaUp = { - 0.8, - -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8}; - - const std::vector pTLw = {KPtMinDefault, KPtMinDefault, KPtMinDefault}; - const std::vector pTUp = {KPtMidMax, KPtHighMax, KPtFullMax}; - - Configurable cfgVtxZCut{"cfgVtxZCut", 10.f, "z-vertex range"}; - Configurable cfgPtMin{"cfgPtMin", 0.2f, "min pT"}; - Configurable cfgPtMax{"cfgPtMax", 10.0f, "max pT"}; - Configurable cfgEtaCut{"cfgEtaCut", 0.8f, "|η| cut"}; - Configurable cfgDCAXY{"cfgDCAXY", 2.4f, "DCAxy cut"}; - Configurable cfgDCAZ{"cfgDCAZ", 3.2f, "DCAz cut"}; - Configurable cfgTPCClsMin{"cfgTPCClsMin", 70.f, "min TPC clusters"}; - Configurable cfgChi2TPCMax{"cfgChi2TPCMax", 4.0f, "max TPC χ²"}; - Configurable cfgPIDnSigmaCut{"cfgPIDnSigmaCut", 3.f, "TPC PID |nσ| cut"}; - - Configurable cfgCutVertex{"cfgCutVertex", 10.0f, "Accepted z-vertex range"}; - Configurable cfgCutTpcChi2NCl{"cfgCutTpcChi2NCl", 2.5f, "Maximum TPCchi2NCl"}; - Configurable cfgCutItsChi2NCl{"cfgCutItsChi2NCl", 36.0f, "Maximum ITSchi2NCl"}; - Configurable cfgCutTracKDcaMaxZ{"cfgCutTracKDcaMaxZ", 2.0f, "Maximum DcaZ"}; - Configurable cfgCutTracKDcaMaxXY{"cfgCutTracKDcaMaxXY", 0.2f, "Maximum DcaZ"}; - - Configurable cfgITScluster{"cfgITScluster", 1, "Minimum Number of ITS cluster"}; - Configurable cfgTPCcluster{"cfgTPCcluster", 80, "Minimum Number of TPC cluster"}; - Configurable cfgTPCnCrossedRows{"cfgTPCnCrossedRows", 70, "Minimum Number of TPC crossed-rows"}; - Configurable cfgCutPtUpperTPC{"cfgCutPtUpperTPC", 0.6f, "Upper pT cut for PID using TPC only"}; - Configurable cfgnSigmaOtherParticles{"cfgnSigmaOtherParticles", 3.0f, "PID nSigma cut to remove other particles (default:3)"}; - Configurable cfgnSigmaCutTPC{"cfgnSigmaCutTPC", 2.0f, "PID nSigma cut for TPC"}; - Configurable cfgnSigmaCutTOF{"cfgnSigmaCutTOF", 2.0f, "PID nSigma cut for TOF"}; - Configurable cfgnSigmaCutCombTPCTOF{"cfgnSigmaCutCombTPCTOF", 2.0f, "PID nSigma combined cut for TPC and TOF"}; - Configurable cfgCutPtLower{"cfgCutPtLower", 0.2f, "Lower pT cut"}; - Configurable cfgCutPtUpper{"cfgCutPtUpper", 10.0f, "Higher pT cut for inclusive hadron analysis"}; - Configurable cfgCutPtUpperPID{"cfgCutPtUpperPID", 6.0f, "Higher pT cut for identified particle analysis"}; - Configurable cfgCutEta{"cfgCutEta", 0.8f, "absolute Eta cut"}; - Configurable cfgCutEtaLeft{"cfgCutEtaLeft", 0.8f, "Left end of eta gap"}; - Configurable cfgCutEtaRight{"cfgCutEtaRight", 0.8f, "Right end of eta gap"}; - Configurable cfgNSubsample{"cfgNSubsample", 10, "Number of subsamples"}; - Configurable cfgCentralityChoice{"cfgCentralityChoice", 1, "Which centrality estimator? 1-->FT0C, 2-->FT0A, 3-->FT0M, 4-->FV0A"}; - Configurable cfgEvSelkNoSameBunchPileup{"cfgEvSelkNoSameBunchPileup", true, "Pileup removal"}; - Configurable cfgUseGoodITSLayerAllCut{"cfgUseGoodITSLayerAllCut", true, "Remove time interval with dead ITS zone"}; - Configurable cfgEvSelkNoITSROFrameBorder{"cfgEvSelkNoITSROFrameBorder", true, "ITSROFrame border event selection cut"}; - Configurable cfgEvSelkNoTimeFrameBorder{"cfgEvSelkNoTimeFrameBorder", true, "TimeFrame border event selection cut"}; - Configurable cfgIsGoodZvtxFT0VsPV{"cfgIsGoodZvtxFT0VsPV", true, "Good Vertexing cut"}; - - Configurable cfgNchPbMax{"cfgNchPbMax", 4000, "Max Nch range for PbPb collisions"}; - Configurable cfgNchOMax{"cfgNchOMax", 600, "Max Nch range for OO collisions"}; - - Configurable cfgSys{"cfgSys", 1, "Efficiency to be used for which system? 1-->PbPb, 2-->OO, 3-->pPb, 4-->pp"}; - Configurable cfgFlat{"cfgFlat", false, "Whether to use flattening weights"}; - Configurable cfgEff{"cfgEff", false, "Whether to use Efficiency weights"}; - Configurable cfgZDC{"cfgZDC", false, "Whether to use ZDC for pileup histograms"}; - - Configurable cfgCCDBurl{"cfgCCDBurl", "https://alice-ccdb.cern.ch", "ccdb url"}; - Configurable cfgCCDBUserPath{"cfgCCDBUserPath", "/Users/s/somadutt", "Base CCDB path"}; - - ConfigurableAxis cfgAxisCent{"cfgAxisCent", {0.0, 1.0, 3.0, 5.0, 10, 20, 30, 40, 50, 60, 70, 80, 100}, "centrality axis (percentile)"}; - - const AxisSpec centAxis{cfgAxisCent, "Centrality (%)"}; - const AxisSpec centAxis1Per{101, -0.5, 100.5, - "Centrality (%)" - "Centrality (%)"}; - AxisSpec nChAxis{1, 0., 1., "Nch", "Nch"}; - AxisSpec nChAxis2{1, 0., 1., "Nch", "Nch"}; - - const AxisSpec vzAxis{5, -12.5, 12.5, "Vz"}; - const AxisSpec chgAxis{3, -1.5, 1.5}; - const AxisSpec pTAxis{{0.0, 0.2, 0.5, 1, 3, 5, 7.5, 10}, "pT Axis"}; - const AxisSpec etaAxis{{-0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}, "Eta"}; - const AxisSpec gapAxis{{-1.55, -1.45, -1.35, -1.25, -1.15, -1.05, -0.95, -0.85, -0.75, -0.65, -0.55, -0.45, -0.35, -0.25, -0.15, -0.05, 0.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 1.05, 1.15, 1.25, 1.35, 1.45, 1.55}, "Gaps"}; - const AxisSpec sumAxis{{-0.775, -0.725, -0.675, -0.625, -0.575, -0.525, -0.475, -0.425, -0.375, -0.325, -0.275, -0.225, -0.175, -0.125, -0.075, -0.025, 0.025, 0.075, 0.125, 0.175, 0.225, 0.275, 0.325, 0.375, 0.425, 0.475, 0.525, 0.575, 0.625, 0.675, 0.725, 0.775}, "Sums"}; - - Configurable cfgRunGetEff{"cfgRunGetEff", false, "Run MC pass to build efficiency/fake maps"}; - Configurable cfgRunGetMCFlat{"cfgRunGetMCFlat", false, "Run MC to Get Flattening Weights"}; - Configurable cfgRunMCMean{"cfgRunMCMean", false, "Run MC mean(pT) & mean(Et)"}; - Configurable cfgRunMCFluc{"cfgRunMCFluc", false, "Run MC fluctuations (C2, subevent)"}; - Configurable cfgRunGetDataFlat{"cfgRunGetDataFlat", false, "Run Data Get Flattening Weights"}; - Configurable cfgRunDataMean{"cfgRunDataMean", false, "Run DATA mean(pT) & mean(Et)"}; - Configurable cfgRunDataFluc{"cfgRunDataFluc", false, "Run DATA fluctuations (C2, subevent)"}; - - Service ccdb; - Service pdg; - HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject}; - - std::array hEff{}; - std::array hFake{}; - std::array hFlatWeight{}; - - std::array pmeanTruNchEtabinPtbinStep2{}; - std::array pmeanRecoNchEtabinPtbinStep2{}; - std::array pmeanRecoEffcorrNchEtabinPtbinStep2{}; - - std::array pmeanMultTruNchEtabinPtbinStep2{}; - std::array pmeanMultRecoNchEtabinPtbinStep2{}; - std::array pmeanMultRecoEffcorrNchEtabinPtbinStep2{}; - - std::array pmeanNchEtabinPtbinStep2{}; - std::array pmeanMultNchEtabinPtbinStep2{}; - - template - static std::tuple getAllCombinedNSigmas(const T& candidate) - { - return { - std::hypot(candidate.tpcNSigmaPr(), candidate.tofNSigmaPr()), // Proton - std::hypot(candidate.tpcNSigmaPi(), candidate.tofNSigmaPi()), // Pion - std::hypot(candidate.tpcNSigmaKa(), candidate.tofNSigmaKa()) // Kaon - }; - } - - template - bool isEventSelected(const T& col) - { - if (!col.sel8()) - return false; - if (std::abs(col.posZ()) > cfgCutVertex) - return false; - if (cfgEvSelkNoSameBunchPileup && !col.selection_bit(o2::aod::evsel::kNoSameBunchPileup)) - return false; - if (cfgIsGoodZvtxFT0VsPV && !col.selection_bit(o2::aod::evsel::kIsGoodZvtxFT0vsPV)) - return false; - - return true; - } - - template - bool isTrackSelected(const T& trk) - { - if (trk.sign() == 0) - return false; - if (!trk.has_collision()) - return false; - if (!trk.isPVContributor()) - return false; - if (!(trk.itsNCls() > cfgITScluster)) - return false; - if (!(trk.tpcNClsFound() >= cfgTPCcluster)) - return false; - if (!(trk.tpcNClsCrossedRows() >= cfgTPCnCrossedRows)) - return false; - - if (trk.pt() < cfgCutPtLower || trk.pt() > cfgCutPtUpper || std::abs(trk.eta()) > cfgCutEta) - return false; - if (std::abs(trk.dcaXY()) > cfgCutTracKDcaMaxXY || std::abs(trk.dcaZ()) > cfgCutTracKDcaMaxZ) - return false; - return true; - } - - template - bool isParticleSelected(const T& particle) - { - auto* pd = pdg->GetParticle(particle.pdgCode()); - if (!pd) - return false; - if (std::abs(pd->Charge()) == 0) - return false; - if (particle.pt() < cfgCutPtLower || particle.pt() > cfgCutPtUpper || std::abs(particle.eta()) > cfgCutEta) - return false; - if (std::abs(particle.vz()) > cfgCutVertex) - return false; - return true; - } - - template - bool selectionProton(const T& candidate) - { - if (!candidate.hasTPC()) - return false; - int flag = 0; - - if (candidate.pt() > cfgCutPtLower && candidate.pt() <= cfgCutPtUpperTPC) { - if (!candidate.hasTOF() && std::abs(candidate.tpcNSigmaPr()) < cfgnSigmaCutTPC) { - flag = 1; - } - if (candidate.hasTOF() && std::abs(candidate.tpcNSigmaPr()) < cfgnSigmaCutTPC && std::abs(candidate.tofNSigmaPr()) < cfgnSigmaCutTOF) { - flag = 1; - } - } - if (candidate.hasTOF() && candidate.pt() > cfgCutPtUpperTPC && candidate.pt() < cfgCutPtUpperPID) { - auto [combNSigmaPr, combNSigmaPi, combNSigmaKa] = getAllCombinedNSigmas(candidate); - int flag2 = 0; - if (combNSigmaPr < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaPi < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaKa < cfgnSigmaOtherParticles) - flag2 += 1; - if (!(flag2 > 1) && !(combNSigmaPr > combNSigmaPi) && !(combNSigmaPr > combNSigmaKa)) { - if (combNSigmaPr < cfgnSigmaCutCombTPCTOF) { - flag = 1; - } - } - } - if (flag == 1) - return true; - else - return false; - } - - template - bool selectionPion(const T& candidate) - { - if (!candidate.hasTPC()) - return false; - int flag = 0; - - if (candidate.pt() > cfgCutPtLower && candidate.pt() <= cfgCutPtUpperTPC) { - if (!candidate.hasTOF() && std::abs(candidate.tpcNSigmaPi()) < cfgnSigmaCutTPC) { - flag = 1; - } - if (candidate.hasTOF() && std::abs(candidate.tpcNSigmaPi()) < cfgnSigmaCutTPC && std::abs(candidate.tofNSigmaPi()) < cfgnSigmaCutTOF) { - flag = 1; - } - } - if (candidate.hasTOF() && candidate.pt() > cfgCutPtUpperTPC && candidate.pt() < cfgCutPtUpperPID) { - auto [combNSigmaPr, combNSigmaPi, combNSigmaKa] = getAllCombinedNSigmas(candidate); - int flag2 = 0; - if (combNSigmaPr < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaPi < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaKa < cfgnSigmaOtherParticles) - flag2 += 1; - if (!(flag2 > 1) && !(combNSigmaPi > combNSigmaPr) && !(combNSigmaPi > combNSigmaKa)) { - if (combNSigmaPi < cfgnSigmaCutCombTPCTOF) { - flag = 1; - } - } - } - if (flag == 1) - return true; - else - return false; - } - - template - bool selectionKaon(const T& candidate) - { - if (!candidate.hasTPC()) - return false; - int flag = 0; - - if (candidate.pt() > cfgCutPtLower && candidate.pt() <= cfgCutPtUpperTPC) { - if (!candidate.hasTOF() && std::abs(candidate.tpcNSigmaKa()) < cfgnSigmaCutTPC) { - flag = 1; - } - if (candidate.hasTOF() && std::abs(candidate.tpcNSigmaKa()) < cfgnSigmaCutTPC && std::abs(candidate.tofNSigmaKa()) < cfgnSigmaCutTOF) { - flag = 1; - } - } - if (candidate.hasTOF() && candidate.pt() > cfgCutPtUpperTPC && candidate.pt() < cfgCutPtUpperPID) { - auto [combNSigmaPr, combNSigmaPi, combNSigmaKa] = getAllCombinedNSigmas(candidate); - int flag2 = 0; - if (combNSigmaPr < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaPi < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaKa < cfgnSigmaOtherParticles) - flag2 += 1; - if (!(flag2 > 1) && !(combNSigmaKa > combNSigmaPi) && !(combNSigmaKa > combNSigmaPr)) { - if (combNSigmaKa < cfgnSigmaCutCombTPCTOF) { - flag = 1; - } - } - } - if (flag == 1) - return true; - else - return false; - } - - float getCentrality(const auto& col) const - { - if (cfgCentralityChoice.value == kCentFT0C) - return col.centFT0C(); - if (cfgCentralityChoice.value == kCentFT0A) - return col.centFT0A(); - if (cfgCentralityChoice.value == kCentFT0M) - return col.centFT0M(); - if (cfgCentralityChoice.value == kCentFV0A) - return col.centFV0A(); - return KinvalidCentrality; - } - - float getEfficiency(float mult, float pt, float eta, PID pidType, int effidx, bool cfgEff) const - { - if (!cfgEff) { - if (effidx == 0) - return 1.0; - if (effidx == 1) - return 0.0; - } - TH3F* h = nullptr; - if (effidx == 0) - h = hEff[pidType]; - if (effidx == 1) - h = hFake[pidType]; - - if (!h) - return -1; - const int ibx = h->GetXaxis()->FindBin(mult); - const int iby = h->GetYaxis()->FindBin(pt); - const int ibz = h->GetZaxis()->FindBin(eta); - float val = h->GetBinContent(ibx, iby, ibz); - return val; - } - - float getFlatteningWeight(float vz, float chg, float pt, float eta, float phi, PID pidType, bool cfgflat) const - { - if (!cfgflat) - return 1.0; - THnSparseF* h = hFlatWeight[pidType]; - - if (!h) - return 0.0; - int bins[5]; - bins[0] = h->GetAxis(0)->FindBin(vz); - bins[1] = h->GetAxis(1)->FindBin(chg); - bins[2] = h->GetAxis(2)->FindBin(pt); - bins[3] = h->GetAxis(3)->FindBin(eta); - bins[4] = h->GetAxis(4)->FindBin(phi); - float val = h->GetBinContent(bins); - - return val; - } - - template - std::pair calculateMeanAndC2FromSums(const double sumpmwk[KIntM][KIntK], const double sumwk[KIntK], float referenceMeanPt) const - { - if (sumwk[1] == 0.) { - return {0.f, 0.f}; - } - - double tau1 = sumwk[2] / (sumwk[1] * sumwk[1]); - double denom2 = 1. - tau1; - - if (std::abs(denom2) < KFloatEpsilon) { - double pmk11safe = sumpmwk[1][1] / sumwk[1]; - return {static_cast(pmk11safe), 0.f}; - } - - double pmk11 = sumpmwk[1][1] / sumwk[1]; - - double pmk12 = 0.f; - if (sumwk[2] != 0.f) { - pmk12 = sumpmwk[1][2] / sumwk[2]; - } - - double pmk22 = 0.f; - if (sumwk[2] != 0.f) { - pmk22 = sumpmwk[2][2] / sumwk[2]; - } - - float calculatedMeanPt = pmk11; - - double p1kBar1 = pmk11 - referenceMeanPt; - double p2kBar2 = pmk22 - 2.0f * pmk12 * referenceMeanPt + referenceMeanPt * referenceMeanPt; - - double p1kBar1sq = p1kBar1 * p1kBar1; - double numerator2 = p1kBar1sq - (tau1 * p2kBar2); - - float twopcorr = numerator2 / denom2; - return {calculatedMeanPt, twopcorr}; - } - - using GeneralCollisions = soa::Join< - aod::Collisions, - aod::EvSels, - aod::Mults, - aod::CentFT0As, aod::CentFT0Cs, aod::CentFT0Ms, aod::CentFV0As, - aod::CentNGlobals>; - Filter collisionFilter = nabs(aod::collision::posZ) < cfgVtxZCut; - using AodCollisionsSel = soa::Filtered; - - using UnfilteredTracks = soa::Join< - aod::Tracks, - aod::TracksExtra, - aod::TrackSelection, - aod::TracksDCA, - aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr, - aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr>; - Filter trackFilter = nabs(aod::track::eta) < cfgEtaCut && - aod::track::pt > cfgPtMin&& - aod::track::pt < cfgPtMax&& - nabs(aod::track::dcaXY) < cfgDCAXY&& nabs(aod::track::dcaZ) < cfgDCAZ; - using AodTracksSel = soa::Filtered; - using TCs = soa::Join; - using FilteredTCs = soa::Filtered; - using BCsRun3 = soa::Join; - - using MyRun3MCCollisions = soa::Join< - aod::Collisions, aod::EvSels, aod::Mults, aod::MultsExtra, - aod::CentFT0As, aod::CentFT0Cs, aod::CentFT0Ms, aod::CentFV0As, - aod::CentNGlobals, aod::McCollisionLabels>; - - using MyMCTracks = soa::Join< - aod::Tracks, aod::TrackSelection, aod::TracksExtra, aod::TracksDCA, - aod::McTrackLabels, - aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr, - aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr>; - - PresliceUnsorted partPerMcCollision = aod::mcparticle::mcCollisionId; - PresliceUnsorted colPerMcCollision = aod::mccollisionlabel::mcCollisionId; - PresliceUnsorted trackPerMcParticle = aod::mctracklabel::mcParticleId; - Preslice perCollision = aod::track::collisionId; - Preslice trackPerCollision = aod::track::collisionId; - - void declareCommonQA() - { - histos.add("hZvtx_after_sel", ";z_{vtx} (cm)", kTH1F, {{KNbinsZvtx, KZvtxMin, KZvtxMax}}); - histos.add("hVtxZ", ";z_{vtx} (cm)", kTH1F, {{KNbinsZvtx, KZvtxMin, KZvtxMax}}); - histos.add("hCentrality", ";centrality (%)", kTH1F, {{centAxis1Per}}); - histos.add("Hist2D_globalTracks_PVTracks", ";N_{global};N_{PV}", kTH2F, {{nChAxis2}, {nChAxis2}}); - histos.add("Hist2D_cent_nch", ";N_{PV};cent (%)", kTH2F, {{nChAxis2}, {centAxis1Per}}); - histos.add("hP", ";p (GeV/c)", kTH1F, {{KNbinsP, KPMin, KPMax}}); - histos.add("hPt", ";p_{T} (GeV/c)", kTH1F, {{KNbinsPt, KPtMin, KPtMax}}); - histos.add("hEta", ";#eta", kTH1F, {{KNbinsEta, KEtaMin, KEtaMax}}); - histos.add("hPhi", ";#phi", kTH1F, {{KNbinsPhi, KPhiMin, TwoPI}}); - } - void declareMCCommonHists() - { - for (const auto& suf : pidSuffix) { - histos.add("h3_AllPrimary" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, cfgPtMin, cfgPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - histos.add("h3_RecoMatchedToPrimary" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, cfgPtMin, cfgPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - histos.add("h3_AllReco" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, cfgPtMin, cfgPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - histos.add("h3_RecoUnMatchedToPrimary_Secondary" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, cfgPtMin, cfgPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - histos.add("h3_RecoUnMatchedToPrimary_Fake" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, cfgPtMin, cfgPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - histos.add("hTruth_ParticleWeight" + suf, ";cent;p_{T};#eta", kTH3F, {{centAxis1Per}, {KNbinsPtRes, cfgPtMin, cfgPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - } - - histos.add("ptResolution", ";p_{T}^{MC};p_{T}^{MC}-p_{T}^{reco}", kTH2F, {{KNbinsPtRes, cfgPtMin, cfgPtMax}, {KNbinsPtRes, -KPtResMax, KPtResMax}}); - histos.add("ptTruthReco", ";p_{T}^{MC};p_{T}^{reco}", kTH2F, {{KNbinsPtRes, cfgPtMin, cfgPtMax}, {KNbinsPtRes, cfgPtMin, cfgPtMax}}); - histos.add("etaResolution", ";#eta^{MC};#eta^{MC}-#eta^{reco}", kTH2F, {{KNbinsEtaRes, -KEtaFineMax, KEtaFineMax}, {KNbinsPtRes, -KEtaResMax, KEtaResMax}}); - histos.add("etaTruthReco", ";#eta^{MC};#eta^{reco}", kTH2F, {{KNbinsPtRes, -KEtaFineMax, KEtaFineMax}, {KNbinsPtRes, -KEtaFineMax, KEtaFineMax}}); - histos.add("TruthTracKVz", ";Vz^{MC};Vz^{Reco}", kTH2F, {{KNbinsVz, KVzMin, KVzMax}, {KNbinsVz, KVzMin, KVzMax}}); - histos.add("vzResolution", ";Vz^{MC};Vz^{MC}-Vz^{Reco}", kTH2F, {{KNbinsVz, KVzMin, KVzMax}, {KNbinsVz, -KVzResMax, KVzResMax}}); - - histos.add("h_AllPrimary", ";p_{T}", kTH1F, {{KNbinsPtRes, cfgPtMin, cfgPtMax}}); - histos.add("h_RecoMatchedToPrimary", ";p_{T}", kTH1F, {{KNbinsPtRes, cfgPtMin, cfgPtMax}}); - histos.add("h_RecoUnMatchedToPrimary", ";p_{T}", kTH1F, {{KNbinsPtRes, cfgPtMin, cfgPtMax}}); - histos.add("h_AllReco", ";p_{T}", kTH1F, {{KNbinsPtRes, cfgPtMin, cfgPtMax}}); - histos.add("h_AllRecoEffCorr", ";p_{T}", kTH1F, {{KNbinsPtRes, cfgPtMin, cfgPtMax}}); - - histos.add("hDCAxy_Unmatched", ";DCA_{xy} (cm)", kTH1F, {{KNbinsDca, -KDcaMax, KDcaMax}}); - histos.add("hDCAz_Unmatched", ";DCA_{z} (cm)", kTH1F, {{KNbinsDca, -KDcaMax, KDcaMax}}); - histos.add("hDCAxy_NotPrimary", ";DCA_{xy} (cm)", kTH1F, {{KNbinsDca, -KDcaMax, KDcaMax}}); - histos.add("hDCAz_NotPrimary", ";DCA_{z} (cm)", kTH1F, {{KNbinsDca, -KDcaMax, KDcaMax}}); - histos.add("hDCAxy_RecoMatched", ";DCA_{xy} (cm)", kTH1F, {{KNbinsDca, -KDcaMax, KDcaMax}}); - histos.add("hDCAz_RecoMatched", ";DCA_{z} (cm)", kTH1F, {{KNbinsDca, -KDcaMax, KDcaMax}}); - histos.add("hDCAxy_Reco", ";DCA_{xy} (cm)", kTH1F, {{KNbinsDca, -KDcaMax, KDcaMax}}); - histos.add("hDCAz_Reco", ";DCA_{z} (cm)", kTH1F, {{KNbinsDca, -KDcaMax, KDcaMax}}); - } - - void declareMCGetFlatHists() - { - for (const auto& suf : pidSuffix) { - std::string nameEff = "hEtaPhiReco" + suf; - std::string nameWtd = "hEtaPhiRecoWtd" + suf; - std::string nameEffWtd = "hEtaPhiRecoEffWtd" + suf; - - histos.add(nameEffWtd, nameEffWtd.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - histos.add(nameEff, nameEff.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - histos.add(nameWtd, nameWtd.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - } - } - - void declareMCMeanHists() - { - histos.add("Eff_cent", ";cent;#epsilon", kTProfile, {centAxis1Per}); - histos.add("Fake_cent", ";cent;f_{fake}", kTProfile, {centAxis1Per}); - histos.add("wgt_cent", ";cent;w", kTProfile, {centAxis1Per}); - histos.add("Eff_Ntrk", ";N_{PV};#epsilon", kTProfile, {nChAxis2}); - histos.add("Fake_Ntrk", ";N_{PV};f_{fake}", kTProfile, {nChAxis2}); - histos.add("wgt_Ntrk", ";N_{PV};w", kTProfile, {nChAxis2}); - histos.add("Eff_pT", ";p_{T};#epsilon", kTProfile, {{KNbinsPtRes, cfgPtMin, cfgPtMax}}); - histos.add("Fake_pT", ";p_{T};f_{fake}", kTProfile, {{KNbinsPtRes, cfgPtMin, cfgPtMax}}); - histos.add("wgt_pT", ";p_{T};w", kTProfile, {{KNbinsPtRes, KPtMin, KPtMax}}); - histos.add("Eff_eta", ";#eta;#epsilon", kTProfile, {{KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - histos.add("Fake_eta", ";#eta;f_{fake}", kTProfile, {{KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - histos.add("wgt_eta", ";#eta;w", kTProfile, {{KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - - for (const auto& suf : pidSuffix) { - // Basic Profiles - histos.add("MCGen/Prof_Cent_Nchrec" + suf, ";cent;#LT N_{PV}#GT", kTProfile, {centAxis1Per}); - histos.add("MCGen/Prof_Mult_Nchrec" + suf, ";N_{PV};#LT N_{PV}#GT", kTProfile, {nChAxis}); - - histos.add("MCGen/Prof_Cent_MeanpT" + suf, ";cent;#LT p_{T}#GT", kTProfile, {centAxis1Per}); - histos.add("MCGen/Prof_Mult_MeanpT" + suf, ";N_{PV};#LT p_{T}#GT", kTProfile, {nChAxis}); - - histos.add("pmeanTruNchEtabinPtbin" + suf, ";N_{PV};#eta bin;p_{T} bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - histos.add("pmeanRecoNchEtabinPtbin" + suf, ";N_{PV};#eta bin;p_{T} bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - histos.add("pmeanRecoEffcorrNchEtabinPtbin" + suf, ";N_{PV};#eta bin;p_{T} bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - - histos.add("pmeanMultTruNchEtabinPtbin" + suf, ";N_{PV};#eta bin;p_{T} bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - histos.add("pmeanMultRecoNchEtabinPtbin" + suf, ";N_{PV};#eta bin;p_{T} bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - histos.add("pmeanMultRecoEffcorrNchEtabinPtbin" + suf, ";N_{PV};#eta bin;p_{T} bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - - for (const int& i : {0, 1, 2}) { - std::string ptTag = "_ipt" + std::to_string(i); - histos.add("Prof2D_MeanpT_Sub" + ptTag + "_Tru" + suf, ";cent;etaA;etaB", kTProfile3D, {{centAxis1Per}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}}); - histos.add("Prof2D_MeanpT_Sub" + ptTag + "_Reco" + suf, ";cent;etaA;etaB", kTProfile3D, {{centAxis1Per}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}}); - histos.add("Prof2D_MeanpT_Sub" + ptTag + "_RecoEffCorr" + suf, ";cent;etaA;etaB", kTProfile3D, {{centAxis1Per}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}}); - } - } - - for (const auto& suf : pidSuffix) { - std::string nameEff = "hEtaPhiReco" + suf; - std::string nameWtd = "hEtaPhiRecoWtd" + suf; - std::string nameEffWtd = "hEtaPhiRecoEffWtd" + suf; - - histos.add(nameEffWtd, nameEffWtd.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - histos.add(nameEff, nameEff.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - histos.add(nameWtd, nameWtd.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - } - } - - void declareMCFlucHists() - { - - for (const auto& suf : pidSuffix) { - // --- 1D Full Event Calc Profiles --- - histos.add("MCGen/Prof_MeanpT_Cent_etabin_ptbin" + suf, ";cent;#eta-bin; p_{T}-bin", kTProfile3D, {{centAxis1Per}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - histos.add("MCGen/Prof_MeanpT_Mult_etabin_ptbin" + suf, ";N_{PV};#eta-bin; p_{T}-bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - - histos.add("MCGen/Prof_C2_Cent_etabin_ptbin" + suf, ";cent;#eta-bin; p_{T}-bin", kTProfile3D, {{centAxis1Per}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - histos.add("MCGen/Prof_C2_Mult_etabin_ptbin" + suf, ";N_{PV};#eta-bin; p_{T}-bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - - // --- 1D Sub-Event Covariances --- - histos.add("MCGen/Prof_C2Sub_Cent_etabin_ptbin" + suf, ";Centrality;#eta-bin; p_{T}-bin", kTProfile3D, {{centAxis1Per}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - histos.add("MCGen/Prof_C2Sub_Mult_etabin_ptbin" + suf, ";N_{PV};#eta-bin; p_{T}-bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - - histos.add("MCGen/Prof_Cov_Cent_etabin_ptbin" + suf, ";Centrality;#eta-bin; p_{T}-bin", kTProfile3D, {{centAxis1Per}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - histos.add("MCGen/Prof_Cov_Mult_etabin_ptbin" + suf, ";N_{PV};#eta-bin; p_{T}-bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - - for (const int& i : {0, 1, 2}) { - std::string ptTag = "_ipt" + std::to_string(i); - histos.add("MCGen/Prof" + ptTag + "_C2Sub2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A};#eta_{B}", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); - histos.add("MCGen/Prof" + ptTag + "_Cov2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A};#eta_{B}", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); - histos.add("MCGen/Prof" + ptTag + "_GapSum2D" + suf, ";cent;#Delta#eta (Gap);#Sigma#eta/2 (Sum)", kTProfile3D, {{centAxis1Per}, {gapAxis}, {sumAxis}}); - } - - std::string nameEff = "hEtaPhiReco" + suf; - std::string nameWtd = "hEtaPhiRecoWtd" + suf; - std::string nameEffWtd = "hEtaPhiRecoEffWtd" + suf; - histos.add(nameEffWtd, nameEffWtd.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - histos.add(nameEff, nameEff.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - histos.add(nameWtd, nameWtd.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - - histos.add("MCGen/Prof_Cent_Nchrec" + suf, ";cent;#LT N_{PV}#GT", kTProfile, {centAxis1Per}); - histos.add("MCGen/Prof_Mult_Nchrec" + suf, ";N_{PV};#LT N_{PV}#GT", kTProfile, {nChAxis}); - histos.add("MCGen/Prof_Cent_MeanpT" + suf, ";cent;#LT p_{T}#GT", kTProfile, {centAxis1Per}); - histos.add("MCGen/Prof_Mult_MeanpT" + suf, ";N_{PV};#LT p_{T}#GT", kTProfile, {nChAxis}); - } - } - - void declareDataGetFlatHists() - { - // 1. Species-dependent Sparse Histograms - for (const auto& suf : pidSuffix) { - std::string nameEff = "hEtaPhiReco" + suf; - std::string nameWtd = "hEtaPhiRecoWtd" + suf; - std::string nameEffWtd = "hEtaPhiRecoEffWtd" + suf; - - histos.add(nameEffWtd, nameEffWtd.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - histos.add(nameEff, nameEff.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - histos.add(nameWtd, nameWtd.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - } - - histos.add("hnTrkPVZDC", ";N_{PV};ZDC_{A+C}", kTH2F, {{nChAxis2}, {200, 0, 3000}}); - histos.add("hNchZDC", ";N_{trk};ZDC_{A+C}", kTH2F, {{nChAxis2}, {200, 0, 30000}}); - - histos.add("hCentnTrk", ";Centrality (%);N_{trk}", kTH2F, {{centAxis1Per}, {nChAxis2}}); - histos.add("hCentnTrkPV", ";Centrality (%);N_{trk, PV}", kTH2F, {{centAxis1Per}, {nChAxis2}}); - } - - void declareDataMeanHists() - { - for (const auto& suf : pidSuffix) { - std::string nameReco = "hEtaPhiReco" + suf; - std::string nameWtd = "hEtaPhiRecoWtd" + suf; - std::string nameEffWtd = "hEtaPhiRecoEffWtd" + suf; - - histos.add(nameReco, nameReco.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - histos.add(nameWtd, nameWtd.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - histos.add(nameEffWtd, nameEffWtd.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - - histos.add("Prof_Cent_Nchrec" + suf, ";cent;#LT N_{PV}#GT", kTProfile, {centAxis1Per}); - histos.add("Prof_Mult_Nchrec" + suf, ";N_{PV};#LT N_{PV}#GT", kTProfile, {nChAxis}); - histos.add("Prof_Cent_MeanpT" + suf, ";cent;#LT p_{T}#GT", kTProfile, {centAxis1Per}); - - histos.add("pmean_nch_etabin_ptbin" + suf, ";N_{PV};#eta-bin;p_{T}-bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - histos.add("pmeanMult_nch_etabin_ptbin" + suf, ";N_{PV};#eta-bin;p_{T}-bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - - histos.add("pmean_cent_etabin_ptbin" + suf, ";Centrality (%) ;#eta-bin;p_{T}-bin", kTProfile3D, {{centAxis1Per}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - histos.add("pmeanMult_cent_etabin_ptbin" + suf, ";Centrality (%) ;#eta-bin;p_{T}-bin", kTProfile3D, {{centAxis1Per}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - - for (const int& i : {0, 1, 2}) { - std::string ptTag = "_ipt" + std::to_string(i); - std::string histName = "Prof2D_MeanpT_Sub" + ptTag + suf; - histos.add(histName, ";cent;#eta_{A} bin;#eta_{B} bin", kTProfile3D, {{centAxis1Per}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}}); - } - } - } - - void declareDataFlucHists() - { - for (const auto& suf : pidSuffix) { - - // --- THnSparse QA Histograms --- - std::string nameReco = "hEtaPhiReco" + suf; - std::string nameEff = "hEtaPhiRecoEffWtd" + suf; - std::string nameWtd = "hEtaPhiRecoWtd" + suf; - - histos.add(nameReco, nameReco.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - histos.add(nameEff, nameEff.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - histos.add(nameWtd, nameWtd.c_str(), kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {(KNEta - 1), KEtaAxisMin, KEtaAxisMax}, {KNbinsPhiFine, KPhiMin, TwoPI}}); - - // --- 1D Full Event Calc Profiles --- - histos.add("Prof_MeanpT_Cent_etabin_ptbin" + suf, ";cent;#eta-bin; p_{T}-bin", kTProfile3D, {{centAxis1Per}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - histos.add("Prof_MeanpT_Mult_etabin_ptbin" + suf, ";N_{PV};#eta-bin; p_{T}-bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - - histos.add("Prof_C2_Cent_etabin_ptbin" + suf, ";cent;#eta-bin; p_{T}-bin", kTProfile3D, {{centAxis1Per}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - histos.add("Prof_C2_Mult_etabin_ptbin" + suf, ";N_{PV};#eta-bin; p_{T}-bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - - // --- 1D Sub-Event Covariances --- - histos.add("Prof_C2Sub_Cent_etabin_ptbin" + suf, ";Centrality;#eta-bin; p_{T}-bin", kTProfile3D, {{centAxis1Per}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - histos.add("Prof_C2Sub_Mult_etabin_ptbin" + suf, ";N_{PV};#eta-bin; p_{T}-bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - - histos.add("Prof_Cov_Cent_etabin_ptbin" + suf, ";Centrality;#eta-bin; p_{T}-bin", kTProfile3D, {{centAxis1Per}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - histos.add("Prof_Cov_Mult_etabin_ptbin" + suf, ";N_{PV};#eta-bin; p_{T}-bin", kTProfile3D, {{nChAxis}, {KNEta + 1, -KBinOffset, KNEta + KBinOffset}, {KNpT + 1, -KBinOffset, KNpT + KBinOffset}}); - - for (const int& i : {0, 1, 2}) { - std::string ptTag = "_ipt" + std::to_string(i); - histos.add("Prof" + ptTag + "_C2Sub2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A};#eta_{C}", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); - histos.add("Prof" + ptTag + "_GapSum2D" + suf, ";cent;#Delta#eta (Gap);#Sigma#eta/2 (Sum)", kTProfile3D, {{centAxis1Per}, {gapAxis}, {sumAxis}}); - histos.add("Prof" + ptTag + "_Cov2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A} bin;#eta_{C} bin", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); - } - } - } - - THnSparseF* buildWeightMapFromRaw(THnSparseF* hRaw, const char* mapName) - { - if (!hRaw) { - LOGF(error, "Raw eta-phi map for '%s' is null; no flattening will be applied.", mapName); - return nullptr; - } - auto hWMap = reinterpret_cast(hRaw->Clone(mapName)); - hWMap->SetTitle(Form("Flattening Weight Map %s (w_{#phi} = / N_{#phi})", mapName)); - hWMap->Reset(); - auto axV = hRaw->GetAxis(0); // Vz - auto axChg = hRaw->GetAxis(1); // Charge - auto axPt = hRaw->GetAxis(2); // Charge - auto axE = hRaw->GetAxis(3); // Eta - auto axP = hRaw->GetAxis(4); // Phi - - int bins[5]; - for (int iv = 1; iv <= axV->GetNbins(); ++iv) { - bins[0] = iv; - for (int ichg = 1; ichg <= axChg->GetNbins(); ++ichg) { - bins[1] = ichg; - for (int ipt = 1; ipt <= axPt->GetNbins(); ++ipt) { - bins[2] = ipt; - for (int ie = 1; ie <= axE->GetNbins(); ++ie) { - bins[3] = ie; - double sum = 0.0; - int nphi = axP->GetNbins(); - for (int ip = 1; ip <= nphi; ++ip) { - bins[4] = ip; - sum += hRaw->GetBinContent(bins); - } - const double avg = (nphi > 0 ? sum / nphi : 0.0); - for (int ip = 1; ip <= nphi; ++ip) { - bins[4] = ip; - const double raw = hRaw->GetBinContent(bins); - const double w = (avg > 0.0 && raw > 0.0) ? (avg / raw) : 1.0; - hWMap->SetBinContent(bins, w); - } + const std::vector etaUp = { + 0.8, + -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8}; + + Configurable cfgVtxZCut{"cfgVtxZCut", 10.f, "z-vertex range"}; + Configurable cfgPtMin{"cfgPtMin", 0.2f, "min pT"}; + Configurable cfgPtMax{"cfgPtMax", 5.0f, "max pT"}; + Configurable cfgEtaCut{"cfgEtaCut", 0.8f, "|η| cut"}; + Configurable cfgTPCClsMin{"cfgTPCClsMin", 70.f, "min TPC clusters"}; + Configurable cfgChi2TPCMax{"cfgChi2TPCMax", 4.0f, "max TPC χ²"}; + Configurable cfgCutTpcChi2NCl{"cfgCutTpcChi2NCl", 2.5f, "Maximum TPCchi2NCl"}; + Configurable cfgCutItsChi2NCl{"cfgCutItsChi2NCl", 36.0f, "Maximum ITSchi2NCl"}; + Configurable cfgCutVertex{"cfgCutVertex", 7.0f, "Accepted z-vertex range"}; + Configurable cfgCutTracKDcaMaxZ{"cfgCutTracKDcaMaxZ", 2.0f, "Maximum DcaZ"}; + Configurable cfgCutTracKDcaMaxXY{"cfgCutTracKDcaMaxXY", 0.2f, "Maximum DcaZ"}; + + Configurable cfgPtDepDCAxy{"cfgPtDepDCAxy", true, "Use pt-dependent DCAxy cut"}; + Configurable cfgDcaXyP0{"cfgDcaXyP0", 0.0026f, "p0 for DCAxy"}; + Configurable cfgDcaXyP1{"cfgDcaXyP1", 0.005f, "p1 for DCAxy"}; + Configurable cfgDcaXyP2{"cfgDcaXyP2", 1.01f, "p2 for DCAxy"}; + + Configurable cfgPtDepDCAz{"cfgPtDepDCAz", true, "Use pt-dependent DCAz cut"}; + Configurable cfgDcaZP0{"cfgDcaZP0", 0.0026f, "p0 for DCAz"}; + Configurable cfgDcaZP1{"cfgDcaZP1", 0.005f, "p1 for DCAz"}; + Configurable cfgDcaZP2{"cfgDcaZP2", 1.01f, "p2 for DCAz"}; + + // Configurable cfgPtDepDCAxy{"cfgPtDepDCAxy", true, "Use pt-dependent DCAxy cut"}; + // Configurable cfgPtDepDCAz{"cfgPtDepDCAz", true, "Use pt-dependent DCAz cut"}; + // Configurable cfgPtDepDCAxyFunc{"cfgPtDepDCAxyFunc", "(0.0026+0.005/(x^1.01))", "Functional form of pt-dependent DCAxy cut"}; + // Configurable cfgPtDepDCAzFunc{"cfgDPtDepCAzFunc", "(0.0026+0.005/(x^1.01))", "Functional form of pt-dependent DCAz cut"}; + + // TF1* fPtDepDCAxy = nullptr; + // TF1* fPtDepDCAz = nullptr; + + Configurable cfgITScluster{"cfgITScluster", 1, "Minimum Number of ITS cluster"}; + Configurable cfgTPCcluster{"cfgTPCcluster", 80, "Minimum Number of TPC cluster"}; + Configurable cfgTPCnCrossedRows{"cfgTPCnCrossedRows", 70, "Minimum Number of TPC crossed-rows"}; + Configurable cfgCutPtUpperTPC{"cfgCutPtUpperTPC", 0.6f, "Upper pT cut for PID using TPC only"}; + Configurable cfgnSigmaOtherParticles{"cfgnSigmaOtherParticles", 3.0f, "PID nSigma cut to remove other particles (default:3)"}; + Configurable cfgnSigmaCutTPC{"cfgnSigmaCutTPC", 2.0f, "PID nSigma cut for TPC"}; + Configurable cfgnSigmaCutTOF{"cfgnSigmaCutTOF", 2.0f, "PID nSigma cut for TOF"}; + Configurable cfgnSigmaCutCombTPCTOF{"cfgnSigmaCutCombTPCTOF", 2.0f, "PID nSigma combined cut for TPC and TOF"}; + Configurable cfgCutPtLower{"cfgCutPtLower", 0.2f, "Lower pT cut"}; + Configurable cfgCutPtUpper{"cfgCutPtUpper", 10.0f, "Higher pT cut for inclusive hadron analysis"}; + Configurable cfgCutPtUpperPID{"cfgCutPtUpperPID", 6.0f, "Higher pT cut for identified particle analysis"}; + Configurable cfgCutEta{"cfgCutEta", 0.8f, "absolute Eta cut"}; + Configurable cfgNsubsample{"cfgNsubsample", 10, "Number of subsamples"}; + Configurable cfgCentralityChoice{"cfgCentralityChoice", 1, "Which centrality estimator? 1-->FT0C, 2-->FV0A"}; + Configurable cfgEvSelNoSameBunchPileup{"cfgEvSelNoSameBunchPileup", true, "Pileup removal"}; + Configurable cfgUseGoodITSLayerAllCut{"cfgUseGoodITSLayerAllCut", true, "Remove time interval with dead ITS zone"}; + Configurable cfgEvSelkNoITSROFrameBorder{"cfgEvSelkNoITSROFrameBorder", true, "ITSROFrame border event selection cut"}; + Configurable cfgEvSelkNoTimeFrameBorder{"cfgEvSelkNoTimeFrameBorder", true, "TimeFrame border event selection cut"}; + Configurable cfgIsGoodZvtxFT0VsPV{"cfgIsGoodZvtxFT0VsPV", true, "Good Vertexing cut"}; + + Configurable cfgNchPbMax{"cfgNchPbMax", 6000, "Max Nch range for PbPb collisions"}; + Configurable cfgNchOMax{"cfgNchOMax", 600, "Max Nch range for OO collisions"}; + + Configurable cfgSys{"cfgSys", 1, "Efficiency to be used for which system? 1-->PbPb, 2-->NeNe, 3-->OO, 4-->pp"}; + Configurable cfgFlat{"cfgFlat", false, "Whether to use flattening weights"}; + Configurable cfgEff{"cfgEff", false, "Whether to use Efficiency weights"}; + Configurable cfgZDC{"cfgZDC", false, "Whether to use ZDC for pileup histograms"}; + + Configurable cfgCCDBurl{"cfgCCDBurl", "https://alice-ccdb.cern.ch", "ccdb url"}; + Configurable cfgCCDBUserPath{"cfgCCDBUserPath", "/Users/s/somadutt", "Base CCDB path"}; + + ConfigurableAxis cfgAxisCent{"cfgAxisCent", {0.0, 1.0, 3.0, 5.0, 10, 20, 30, 40, 50, 60, 70, 80, 100}, "centrality axis (percentile)"}; + + const AxisSpec centAxis{cfgAxisCent, "Centrality (%)"}; + const AxisSpec centAxis1Per{101, -0.5, 100.5, "Centrality (%)"}; + AxisSpec nChAxis{1, 0., 1., "Nch", "Nch"}; + AxisSpec nChAxis2{1, 0., 1., "Nch", "Nch"}; + + const AxisSpec vzAxis{5, -12.5, 12.5, "Vz"}; + const AxisSpec chgAxis{3, -1.5, 1.5}; + const AxisSpec pTAxis{{0.0, 0.2, 0.5, 1, 3, 5, 7.5, 10}, "pT Axis"}; + const AxisSpec etaAxis{{-0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}, "Eta"}; + const AxisSpec phiAxis{KNbinsPhi, KPhiMin, TwoPI, "#phi"}; + const AxisSpec etaBinAxis{KNEta + 1, -0.5, KNEta + 0.5, "#eta bin Number"}; + const AxisSpec spBinAxis{KNsp + 1, -KBinOffset, KNsp + KBinOffset, "species index Number"}; + + const AxisSpec gapAxis{{-1.55, -1.45, -1.35, -1.25, -1.15, -1.05, -0.95, -0.85, + -0.75, -0.65, -0.55, -0.45, -0.35, -0.25, -0.15, -0.05, + 0.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, + 0.85, 0.95, 1.05, 1.15, 1.25, 1.35, 1.45, 1.55}, "Gaps"}; + + const AxisSpec sumAxis{{-0.775, -0.725, -0.675, -0.625, -0.575, -0.525, + -0.475, -0.425, -0.375, -0.325, -0.275, -0.225, + -0.175, -0.125, -0.075, -0.025, + 0.025, 0.075, 0.125, 0.175, 0.225, 0.275, + 0.325, 0.375, 0.425, 0.475, 0.525, 0.575, + 0.625, 0.675, 0.725, 0.775},"Sums"}; + Configurable cfgRunGetEff{"cfgRunGetEff", false, "Run MC pass to build efficiency/fake maps"}; + Configurable cfgRunGetMCFlat{"cfgRunGetMCFlat", false, "Run MC to Get Flattening Weights"}; + Configurable cfgRunMCMean{"cfgRunMCMean", false, "Run MC mean(pT) & mean(Et)"}; + Configurable cfgRunMCFluc{"cfgRunMCFluc", false, "Run MC fluctuations (C2, subevent)"}; + Configurable cfgRunGetDataFlat{"cfgRunGetDataFlat", false, "Run Data Get Flattening Weights"}; + Configurable cfgRunDataMean{"cfgRunDataMean", false, "Run DATA mean(pT) & mean(Et)"}; + Configurable cfgRunDataFluc{"cfgRunDataFluc", false, "Run DATA fluctuations (C2, subevent)"}; + + Service ccdb; + Service pdg; + HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject}; + + struct InternalState { + std::array hEff{}; + std::array hFake{}; + std::array hFlatWeight{}; + + TProfile3D* pmeanTruNchEtabinSpbinStep2 = nullptr; + TProfile3D* pmeanRecoNchEtabinSpbinStep2 = nullptr; + TProfile3D* pmeanRecoEffcorrNchEtabinSpbinStep2 = nullptr; + + TProfile3D* pmeanMultTruNchEtabinSpbinStep2 = nullptr; + TProfile3D* pmeanMultRecoNchEtabinSpbinStep2 = nullptr; + TProfile3D* pmeanMultRecoEffcorrNchEtabinSpbinStep2 = nullptr; + + TProfile3D* pmeanNchEtabinSpbinStep2 = nullptr; + TProfile3D* pmeanMultNchEtabinSpbinStep2 = nullptr; + + TProfile* pmeanFT0AmultpvStep2 = nullptr; + TProfile* pmeanFT0CmultpvStep2 = nullptr; + } state; + o2::ft0::Geometry ft0Det; + + template + static std::tuple getAllCombinedNSigmas(const T& candidate) + { + return { + std::hypot(candidate.tpcNSigmaPr(), candidate.tofNSigmaPr()), // Proton + std::hypot(candidate.tpcNSigmaPi(), candidate.tofNSigmaPi()), // Pion + std::hypot(candidate.tpcNSigmaKa(), candidate.tofNSigmaKa()) // Kaon + }; } - } - } - } - - LOGF(info, "Flattening weight map '%s' built.", mapName); - return hWMap; - } - - inline void loadTProfile3D(TDirectory* dir, const char* name, TProfile3D*& target) - { - if (!dir) { - LOGF(error, "loadTProfile3D: directory is null for object %s", name); - return; - } - auto* obj = dir->Get(name); - if (!obj) { - LOGF(error, "loadTProfile3D: object '%s' not found in directory %s", name, dir->GetName()); - return; - } - auto* prof = dynamic_cast(obj); - if (!prof) { - LOGF(error, "loadTProfile3D: object '%s' is not a TProfile3D (it is %s)", name, obj->ClassName()); - return; - } - target = reinterpret_cast(prof->Clone(Form("%s_clone", name))); - target->SetDirectory(nullptr); - LOGF(info, "Loaded TProfile3D '%s' with entries = %.0f", name, target->GetEntries()); - } - - void init(InitContext&) - { - if (cfgSys == kPbPb) { - nChAxis = {cfgNchPbMax / 4, KBinOffset, cfgNchPbMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; - nChAxis2 = {cfgNchPbMax / 20, KBinOffset, cfgNchPbMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; - } else if (cfgSys == kOO || cfgSys == kpPb) { - nChAxis = {cfgNchOMax / 2, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; - nChAxis2 = {cfgNchOMax / 5, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; - } else { - nChAxis = {cfgNchOMax / 2, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; - nChAxis2 = {cfgNchOMax / 5, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; - } - - ccdb->setURL(cfgCCDBurl.value); - ccdb->setCaching(true); - ccdb->setLocalObjectValidityChecking(); - int64_t now = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - ccdb->setCreatedNotAfter(now); - - std::string sysDir = ""; - switch (cfgSys) { - case kPbPb: - sysDir = "PbPbTest"; - break; - case kOO: - sysDir = "OOTest"; - break; - case kpPb: - sysDir = "pPbTest"; - break; - case kpp: - sysDir = "ppTest"; - break; - default: - LOGF(fatal, "Invalid cfgSys value: %d", cfgSys.value); - } - - std::string pathEff = cfgCCDBUserPath.value + "/" + sysDir + "/Job1_EffMaps"; - std::string pathMCFlat = cfgCCDBUserPath.value + "/" + sysDir + "/Job1_MCFlatMaps"; - std::string pathMCMean = cfgCCDBUserPath.value + "/" + sysDir + "/Job2_MCMean"; - std::string pathDataFlat = cfgCCDBUserPath.value + "/" + sysDir + "/Job1_DataFlatMaps"; - std::string pathDataMean = cfgCCDBUserPath.value + "/" + sysDir + "/Job2_DataMean"; - - declareCommonQA(); - std::string userCcdbPath; - if (cfgSys == kPbPb) { - userCcdbPath = "/Users/s/somadutt/PbPbTest/"; - } - if (cfgSys == kOO) { - userCcdbPath = "/Users/s/somadutt/OOTest/"; - } - if (cfgSys == kpPb) { - userCcdbPath = "/Users/s/somadutt/pPbTest/"; - } - if (cfgSys == kpp) { - userCcdbPath = "/Users/s/somadutt/ppTest/"; - } - - if (cfgRunMCMean || cfgRunMCFluc || cfgRunGetEff) { - declareMCCommonHists(); - } - if (cfgRunMCMean) { - declareMCMeanHists(); - histos.addClone("MCGen/", "MCReco/"); - histos.addClone("MCGen/", "MCRecoEffCorr/"); - } - if (cfgRunMCFluc) { - declareMCFlucHists(); - histos.addClone("MCGen/", "MCReco/"); - histos.addClone("MCGen/", "MCRecoEffCorr/"); - } - if (cfgRunGetDataFlat) { - declareDataGetFlatHists(); - } - if (cfgRunGetMCFlat) { - declareMCGetFlatHists(); - } - if (cfgRunDataMean) { - declareDataMeanHists(); - } - if (cfgRunDataFluc) { - declareDataFlucHists(); - } - - if (!cfgRunGetEff && (cfgEff)) { - TList* lst = ccdb->getForTimeStamp(pathEff, now); - - if (!lst) { - LOGF(fatal, "Efficiency maps required but CCDB list is null at %s!", pathEff.c_str()); - } - - LOGF(info, "Loading Eff/Fake maps from TList for all species..."); - - auto loadEffFakeForPID = [&](PID pidType) { - std::string suffix = pidSuffix[pidType]; - std::string hEffNumName = "h3_RecoMatchedToPrimary" + suffix; - std::string hEffDenName = "h3_AllPrimary" + suffix; - std::string hFakeNumSecName = "h3_RecoUnMatchedToPrimary_Secondary" + suffix; - std::string hFakeNumFakName = "h3_RecoUnMatchedToPrimary_Fake" + suffix; - std::string hFakeDenName = "h3_AllReco" + suffix; - - auto* hNum = reinterpret_cast(lst->FindObject(hEffNumName.c_str())); - auto* hDen = reinterpret_cast(lst->FindObject(hEffDenName.c_str())); - - if (hNum && hDen) { - hEff[pidType] = reinterpret_cast(hNum->Clone(Form("hEff%s", suffix.c_str()))); - hEff[pidType]->SetDirectory(nullptr); - hEff[pidType]->Divide(hDen); - } else { - LOGF(error, "Missing CCDB objects for efficiency. Checked: %s, %s", hEffNumName.c_str(), hEffDenName.c_str()); - } - - auto* hNumS = reinterpret_cast(lst->FindObject(hFakeNumSecName.c_str())); - auto* hNumF = reinterpret_cast(lst->FindObject(hFakeNumFakName.c_str())); - auto* hDenF = reinterpret_cast(lst->FindObject(hFakeDenName.c_str())); - - if (hNumS && hNumF && hDenF) { - hFake[pidType] = reinterpret_cast(hNumS->Clone(Form("hFake%s", suffix.c_str()))); - hFake[pidType]->Add(hNumF); - hFake[pidType]->SetDirectory(nullptr); - hFake[pidType]->Divide(hDenF); - } else { - LOGF(error, "Missing CCDB object(s) for fakes for %s in list.", suffix.c_str()); - } - }; - - // Loop through all PID types: kInclusive, kPion, kKaon, KProton - for (int i = 0; i < PID::numKNumPID; ++i) { - loadEffFakeForPID(static_cast(i)); - } - } - - if (!cfgRunGetEff && (cfgFlat)) { - // --- 1. Load Data Flattening Maps --- - if (cfgRunDataMean || cfgRunDataFluc) { - LOGF(info, "Data Run: Loading flattening maps from %s", pathDataFlat.c_str()); - TList* lstDataFlat = ccdb->getForTimeStamp(pathDataFlat, now); - - if (lstDataFlat) { - // Use a loop to load species-specific flattening weights if they exist in data - for (int i = 0; i < PID::numKNumPID; ++i) { - std::string suffix = pidSuffix[i]; - std::string hName; - - if (cfgEff && cfgFlat) { - hName = "hEtaPhiRecoWtd" + suffix; - } else if (cfgEff) { - hName = "hEtaPhiRecoEffWtd" + suffix; - } else { - hName = "hEtaPhiReco" + suffix; - } - auto* hRaw = reinterpret_cast(lstDataFlat->FindObject(hName.c_str())); - if (hRaw) { - hFlatWeight[i] = buildWeightMapFromRaw(hRaw, Form("hFlatWeight%s", suffix.c_str())); - } else { - LOGF(error, "Data flattening map '%s' not found.", hName.c_str()); - } + template + bool isEventSelected(const T& col) + { + if (!col.sel8()) + return false; + if (std::abs(col.posZ()) > cfgCutVertex) + return false; + if (cfgEvSelNoSameBunchPileup && !col.selection_bit(o2::aod::evsel::kNoSameBunchPileup)) + return false; + if (cfgUseGoodITSLayerAllCut && !col.selection_bit(o2::aod::evsel::kIsGoodITSLayersAll)) + return false; + if (cfgIsGoodZvtxFT0VsPV && !col.selection_bit(o2::aod::evsel::kIsGoodZvtxFT0vsPV)) + return false; + return true; } - } else { - LOGF(error, "Could not retrieve Data Flattening TList from: %s", pathDataFlat.c_str()); - } - } - - // --- 2. Load MC Flattening Maps --- - if (cfgRunMCMean || cfgRunMCFluc) { - LOGF(info, "MC Run: Loading flattening maps from %s", pathMCFlat.c_str()); - TList* lstMCFlat = ccdb->getForTimeStamp(pathMCFlat, now); - - if (lstMCFlat) { - auto loadFlatForPID = [&](PID pidType) { - std::string suffix = pidSuffix[pidType]; - std::string hFlatSrcName; - if (cfgEff && cfgFlat) { - hFlatSrcName = "hEtaPhiRecoWtd" + suffix; - } else if (cfgEff) { - hFlatSrcName = "hEtaPhiRecoEffWtd" + suffix; + + template + bool isTrackSelected(const T& trk) + { + if (trk.sign() == 0) + return false; + if (!trk.has_collision()) + return false; + if (!trk.isPVContributor()) + return false; + if (!(trk.itsNCls() > cfgITScluster)) + return false; + if (!(trk.tpcNClsFound() >= cfgTPCcluster)) + return false; + if (!(trk.tpcNClsCrossedRows() >= cfgTPCnCrossedRows)) + return false; + if (trk.pt() < cfgCutPtLower || trk.pt() > cfgCutPtUpper || std::abs(trk.eta()) > cfgCutEta) + return false; + // --- DCAxy Cut --- + if (cfgPtDepDCAxy) { + // Evaluates: 0.0026 + 0.005 / (pt^1.01) + float maxDcaXY = cfgDcaXyP0 + cfgDcaXyP1 / std::pow(trk.pt(), cfgDcaXyP2); + if (std::abs(trk.dcaXY()) > maxDcaXY) { + return false; // Reject track if DCA is too large + } } else { - hFlatSrcName = "hEtaPhiReco" + suffix; + if (std::abs(trk.dcaXY()) > cfgCutTracKDcaMaxXY) { + return false; + } } - - auto* hRaw = reinterpret_cast(lstMCFlat->FindObject(hFlatSrcName.c_str())); - - if (hRaw) { - hFlatWeight[pidType] = buildWeightMapFromRaw(hRaw, Form("hFlatWeight%s", suffix.c_str())); + // --- DCAz Cut --- + if (cfgPtDepDCAz) { + // Evaluates: 0.0026 + 0.005 / (pt^1.01) + float maxDcaZ = cfgDcaZP0 + cfgDcaZP1 / std::pow(trk.pt(), cfgDcaZP2); + if (std::abs(trk.dcaZ()) > maxDcaZ) { + return false; // Reject track if DCA is too large + } } else { - LOGF(warning, "MC flattening source '%s' not found in list.", hFlatSrcName.c_str()); + if (std::abs(trk.dcaZ()) > cfgCutTracKDcaMaxZ) { + return false; + } } - }; - - for (int i = 0; i < PID::numKNumPID; ++i) { - loadFlatForPID(static_cast(i)); - } - } else { - LOGF(error, "Could not retrieve MC Flattening TList from: %s", pathMCFlat.c_str()); - } - } - } - - auto loadTProfile3DFromList = [&](TList* sourceList, const char* objName, TProfile3D*& target) { - if (!sourceList) - return; - - auto* tp = reinterpret_cast(sourceList->FindObject(objName)); - if (tp) { - target = reinterpret_cast(tp->Clone()); - target->SetDirectory(nullptr); - LOGF(info, "Loaded %s from list", objName); - } else { - LOGF(error, "Histogram %s missing in CCDB TList", objName); - } - }; - - if (cfgRunMCFluc) { - LOGF(info, "Loading MC Mean profiles from CCDB path: %s", pathMCMean.c_str()); - TList* lstMCMean = ccdb->getForTimeStamp(pathMCMean, now); - - if (lstMCMean) { - for (int isp = 0; isp < KNsp; ++isp) { - std::string suf = pidSuffix[isp]; - loadTProfile3DFromList(lstMCMean, ("pmeanTruNchEtabinPtbin" + suf).c_str(), pmeanTruNchEtabinPtbinStep2[isp]); - loadTProfile3DFromList(lstMCMean, ("pmeanRecoNchEtabinPtbin" + suf).c_str(), pmeanRecoNchEtabinPtbinStep2[isp]); - loadTProfile3DFromList(lstMCMean, ("pmeanRecoEffcorrNchEtabinPtbin" + suf).c_str(), pmeanRecoEffcorrNchEtabinPtbinStep2[isp]); - - loadTProfile3DFromList(lstMCMean, ("pmeanMultTruNchEtabinPtbin" + suf).c_str(), pmeanMultTruNchEtabinPtbinStep2[isp]); - loadTProfile3DFromList(lstMCMean, ("pmeanMultRecoNchEtabinPtbin" + suf).c_str(), pmeanMultRecoNchEtabinPtbinStep2[isp]); - loadTProfile3DFromList(lstMCMean, ("pmeanMultRecoEffcorrNchEtabinPtbin" + suf).c_str(), pmeanMultRecoEffcorrNchEtabinPtbinStep2[isp]); - } - } else { - LOGF(error, "Could not retrieve TList for MC Mean from: %s", pathMCMean.c_str()); - } - } - - if (cfgRunDataFluc) { - LOGF(info, "Loading Data Mean profiles from CCDB path: %s", pathDataMean.c_str()); - TList* lstDataMean = ccdb->getForTimeStamp(pathDataMean, now); - - if (lstDataMean) { - for (int isp = 0; isp < KNsp; ++isp) { - std::string suf = pidSuffix[isp]; - loadTProfile3DFromList(lstDataMean, ("pmean_nch_etabin_ptbin" + suf).c_str(), pmeanNchEtabinPtbinStep2[isp]); - loadTProfile3DFromList(lstDataMean, ("pmeanMult_nch_etabin_ptbin" + suf).c_str(), pmeanMultNchEtabinPtbinStep2[isp]); - } - } else { - LOGF(error, "Could not retrieve TList for Data Mean from: %s", pathDataMean.c_str()); - } - } - LOGF(info, "CCDB initialization complete for RadialFlowDecorr."); - } - - void processGetEffHists(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, /*soa::SmallGroups const& collisions,*/ TCs const& tracks, FilteredTCs const& /*filteredTracks*/, aod::McParticles const& mcParticles) - { - for (const auto& mcCollision : mcColl) { - auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); - if (colSlice.size() != 1) - continue; - - for (const auto& col : colSlice) { - if (!col.has_mcCollision()) - continue; - histos.fill(HIST("hVtxZ"), col.posZ()); - if (!isEventSelected(col)) - continue; - - auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); - auto partSlice = mcParticles.sliceBy(partPerMcCollision, mcCollision.globalIndex()); - if (trackSlice.size() < 1 || partSlice.size() < 1) - continue; - - float cent = getCentrality(col); - if (cent > KCentMax) - continue; - float multPV = col.multNTracksPV(); - - histos.fill(HIST("hZvtx_after_sel"), col.posZ()); - histos.fill(HIST("hCentrality"), cent); - histos.fill(HIST("Hist2D_globalTracks_PVTracks"), multPV, tracks.size()); - histos.fill(HIST("Hist2D_cent_nch"), multPV, cent); - - // --- Denominator: Truth Particles --- - for (const auto& particle : partSlice) { - if (!isParticleSelected(particle) || !particle.isPhysicalPrimary()) - continue; - - const int absPdgId = std::abs(particle.pdgCode()); - float pt = particle.pt(); - float eta = particle.eta(); - float w = particle.weight(); - - // Inclusive (Denominator) - histos.fill(HIST("hTruth_ParticleWeight"), cent, pt, eta, w); - histos.fill(HIST("h3_AllPrimary"), multPV, pt, eta); - histos.fill(HIST("h_AllPrimary"), pt); - - // Species Specific Denominators - if (absPdgId == KPiPlus) { - histos.fill(HIST("hTruth_ParticleWeight_Pi"), cent, pt, eta, w); - histos.fill(HIST("h3_AllPrimary_Pi"), multPV, pt, eta); - } else if (absPdgId == KKPlus) { - histos.fill(HIST("hTruth_ParticleWeight_Ka"), cent, pt, eta, w); - histos.fill(HIST("h3_AllPrimary_Ka"), multPV, pt, eta); - } else if (absPdgId == KProton) { - histos.fill(HIST("hTruth_ParticleWeight_Pr"), cent, pt, eta, w); - histos.fill(HIST("h3_AllPrimary_Pr"), multPV, pt, eta); + return true; } - } - - // --- Numerator and Fakes: Reconstructed Tracks --- - for (const auto& track : trackSlice) { - if (!isTrackSelected(track)) - continue; - - float pt = track.pt(); - float eta = track.eta(); - float phi = track.phi(); - - bool isPi = selectionPion(track); - bool isKa = selectionKaon(track); - bool isPr = selectionProton(track); - // Inclusive QA - histos.fill(HIST("h_AllReco"), pt); - histos.fill(HIST("h3_AllReco"), multPV, pt, eta); - histos.fill(HIST("hEtaPhiReco"), col.posZ(), track.sign(), pt, eta, phi); - - // Species QA (Fills based on your PID selection) - if (isPi) { - histos.fill(HIST("h3_AllReco_Pi"), multPV, pt, eta); - } - if (isKa) { - histos.fill(HIST("h3_AllReco_Ka"), multPV, pt, eta); + template + bool isParticleSelected(const T& particle) + { + auto* pd = pdg->GetParticle(particle.pdgCode()); + if (!pd) + return false; + if (std::abs(pd->Charge()) == 0) + return false; + if (particle.pt() < cfgCutPtLower || particle.pt() > cfgCutPtUpper || std::abs(particle.eta()) > cfgCutEta) + return false; + if (std::abs(particle.vz()) > cfgCutVertex) + return false; + return true; } - if (isPr) { - histos.fill(HIST("h3_AllReco_Pr"), multPV, pt, eta); - } - - if (track.has_mcParticle()) { - auto mcPart2 = track.mcParticle(); - const int absPdgId = std::abs(mcPart2.pdgCode()); - if (mcPart2.isPhysicalPrimary()) { + template + bool selectionProton(const T& candidate) + { + if (!candidate.hasTPC()) + return false; + int flag = 0; + if (candidate.pt() > cfgCutPtLower && candidate.pt() <= cfgCutPtUpperTPC) { + if (!candidate.hasTOF() && std::abs(candidate.tpcNSigmaPr()) < cfgnSigmaCutTPC) { + flag = 1; + } + if (candidate.hasTOF() && std::abs(candidate.tpcNSigmaPr()) < cfgnSigmaCutTPC && std::abs(candidate.tofNSigmaPr()) < cfgnSigmaCutTOF) { + flag = 1; + } + } + if (candidate.hasTOF() && candidate.pt() > cfgCutPtUpperTPC && candidate.pt() < cfgCutPtUpperPID) { + auto [combNSigmaPr, combNSigmaPi, combNSigmaKa] = getAllCombinedNSigmas(candidate); + int flag2 = 0; + if (combNSigmaPr < cfgnSigmaOtherParticles) + flag2 += 1; + if (combNSigmaPi < cfgnSigmaOtherParticles) + flag2 += 1; + if (combNSigmaKa < cfgnSigmaOtherParticles) + flag2 += 1; + if (!(flag2 > 1) && !(combNSigmaPr > combNSigmaPi) && !(combNSigmaPr > combNSigmaKa)) { + if (combNSigmaPr < cfgnSigmaCutCombTPCTOF) { + flag = 1; + } + } + } + if (flag == 1) + return true; + else + return false; + } - histos.fill(HIST("ptResolution"), mcPart2.pt(), (pt - mcPart2.pt()) / mcPart2.pt()); - histos.fill(HIST("etaResolution"), mcPart2.eta(), eta - mcPart2.eta()); - histos.fill(HIST("etaTruthReco"), mcPart2.eta(), eta); - histos.fill(HIST("vzResolution"), mcPart2.vz(), (col.posZ() - mcPart2.vz()) / mcPart2.vz()); - histos.fill(HIST("TruthTracKVz"), mcPart2.vz(), col.posZ()); + template + bool selectionPion(const T& candidate) + { + if (!candidate.hasTPC()) + return false; + int flag = 0; - // Reconstructed Numerator (Inclusive) - histos.fill(HIST("h3_RecoMatchedToPrimary"), multPV, mcPart2.pt(), mcPart2.eta()); - histos.fill(HIST("h_RecoMatchedToPrimary"), pt); + if (candidate.pt() > cfgCutPtLower && candidate.pt() <= cfgCutPtUpperTPC) { + if (!candidate.hasTOF() && std::abs(candidate.tpcNSigmaPi()) < cfgnSigmaCutTPC) { + flag = 1; + } + if (candidate.hasTOF() && std::abs(candidate.tpcNSigmaPi()) < cfgnSigmaCutTPC && std::abs(candidate.tofNSigmaPi()) < cfgnSigmaCutTOF) { + flag = 1; + } + } + if (candidate.hasTOF() && candidate.pt() > cfgCutPtUpperTPC && candidate.pt() < cfgCutPtUpperPID) { + auto [combNSigmaPr, combNSigmaPi, combNSigmaKa] = getAllCombinedNSigmas(candidate); + int flag2 = 0; + if (combNSigmaPr < cfgnSigmaOtherParticles) + flag2 += 1; + if (combNSigmaPi < cfgnSigmaOtherParticles) + flag2 += 1; + if (combNSigmaKa < cfgnSigmaOtherParticles) + flag2 += 1; + if (!(flag2 > 1) && !(combNSigmaPi > combNSigmaPr) && !(combNSigmaPi > combNSigmaKa)) { + if (combNSigmaPi < cfgnSigmaCutCombTPCTOF) { + flag = 1; + } + } + } + if (flag == 1) + return true; + else + return false; + } - // Species Matching (Efficiency Numerator) - // We fill ONLY if the reconstructed PID matches the Truth PDG - if (isPi && absPdgId == KPiPlus) - histos.fill(HIST("h3_RecoMatchedToPrimary_Pi"), multPV, mcPart2.pt(), mcPart2.eta()); - if (isKa && absPdgId == KKPlus) - histos.fill(HIST("h3_RecoMatchedToPrimary_Ka"), multPV, mcPart2.pt(), mcPart2.eta()); - if (isPr && absPdgId == KProton) - histos.fill(HIST("h3_RecoMatchedToPrimary_Pr"), multPV, mcPart2.pt(), mcPart2.eta()); + template + bool selectionKaon(const T& candidate) + { + if (!candidate.hasTPC()) + return false; + int flag = 0; - } else { - // Secondary (Contamination) - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary"), multPV, pt, eta); - histos.fill(HIST("h_RecoUnMatchedToPrimary"), pt); - if (isPi) - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_Pi"), multPV, pt, eta); - if (isKa) - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_Ka"), multPV, pt, eta); - if (isPr) - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_Pr"), multPV, pt, eta); + if (candidate.pt() > cfgCutPtLower && candidate.pt() <= cfgCutPtUpperTPC) { + if (!candidate.hasTOF() && std::abs(candidate.tpcNSigmaKa()) < cfgnSigmaCutTPC) { + flag = 1; + } + if (candidate.hasTOF() && std::abs(candidate.tpcNSigmaKa()) < cfgnSigmaCutTPC && std::abs(candidate.tofNSigmaKa()) < cfgnSigmaCutTOF) { + flag = 1; + } } - } else { - // Fake Tracks (No MC matching) - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake"), multPV, pt, eta); - if (isPi) - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_Pi"), multPV, pt, eta); - if (isKa) - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_Ka"), multPV, pt, eta); - if (isPr) - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_Pr"), multPV, pt, eta); + if (candidate.hasTOF() && candidate.pt() > cfgCutPtUpperTPC && candidate.pt() < cfgCutPtUpperPID) { + auto [combNSigmaPr, combNSigmaPi, combNSigmaKa] = getAllCombinedNSigmas(candidate); + int flag2 = 0; + if (combNSigmaPr < cfgnSigmaOtherParticles) + flag2 += 1; + if (combNSigmaPi < cfgnSigmaOtherParticles) + flag2 += 1; + if (combNSigmaKa < cfgnSigmaOtherParticles) + flag2 += 1; + if (!(flag2 > 1) && !(combNSigmaKa > combNSigmaPi) && !(combNSigmaKa > combNSigmaPr)) { + if (combNSigmaKa < cfgnSigmaCutCombTPCTOF) { + flag = 1; + } + } + } + if (flag == 1) + return true; + else + return false; } - } - } - } - LOGF(info, "FINISHED RUNNING processGetEffHists"); - } - PROCESS_SWITCH(RadialFlowDecorr, processGetEffHists, "process MC to calculate Eff and Fakes", cfgRunGetEff); - - void processMCFlat(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, /*soa::SmallGroups const& collisions,*/ TCs const& tracks, FilteredTCs const& /*filteredTracks*/, aod::McParticles const& mcParticles) - { - for (const auto& mcCollision : mcColl) { - auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); - if (colSlice.size() != 1) - continue; - - for (const auto& col : colSlice) { - if (!col.has_mcCollision() || !isEventSelected(col)) - continue; - auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); - auto partSlice = mcParticles.sliceBy(partPerMcCollision, mcCollision.globalIndex()); - if (trackSlice.size() < 1 || partSlice.size() < 1) - continue; - - float multPV = col.multNTracksPV(); - float vz = col.posZ(); - - for (const auto& track : trackSlice) { - if (!isTrackSelected(track)) - continue; - - float pt = track.pt(); - float eta = track.eta(); - float phi = track.phi(); - auto sign = track.sign(); - - // 1. Inclusive Weighting (Always filled for selected tracks) - float effIncl = getEfficiency(multPV, pt, eta, numKInclusive, 0, cfgEff); - float fakeIncl = getEfficiency(multPV, pt, eta, numKInclusive, 1, cfgEff); - float wIncl = (1.0 - fakeIncl) / effIncl; - - if (std::isfinite(wIncl) && wIncl > 0.f && effIncl > KFloatEpsilon) { - histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, wIncl); - histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi, 1.0); + + float getCentrality(const auto& col) const + { + if (cfgCentralityChoice.value == kCentFT0M) + return col.centFT0M(); + if (cfgCentralityChoice.value == kCentFDDM) + return col.centFDDM(); + if (cfgCentralityChoice.value == kCentFV0A) + return col.centFV0A(); + return KinvalidCentrality; } - // 2. Pion Weighting - if (selectionPion(track)) { - float effPi = getEfficiency(multPV, pt, eta, numKPion, 0, cfgEff); - float fakePi = getEfficiency(multPV, pt, eta, numKPion, 1, cfgEff); - float wPi = (1.0 - fakePi) / effPi; - if (std::isfinite(wPi) && wPi > 0.f && effPi > KFloatEpsilon) { - histos.fill(HIST("hEtaPhiRecoEffWtd_Pi"), vz, sign, pt, eta, phi, wPi); - histos.fill(HIST("hEtaPhiReco_Pi"), vz, sign, pt, eta, phi, 1.0); - } + float getEfficiency(float mult, float pt, float eta, PIDIdx pidType, int effidx, bool cfgEff) const + { + if (!cfgEff) { + if (effidx == 0) + return 1.0; + if (effidx == 1) + return 0.0; + } + TH3F* h = nullptr; + if (effidx == 0) + h = state.hEff[pidType]; + if (effidx == 1) + h = state.hFake[pidType]; + + if (!h) + return -1; + const int ibx = h->GetXaxis()->FindBin(mult); + const int iby = h->GetYaxis()->FindBin(pt); + const int ibz = h->GetZaxis()->FindBin(eta); + float val = h->GetBinContent(ibx, iby, ibz); + return val; } - // 3. Kaon Weighting - if (selectionKaon(track)) { - float effKa = getEfficiency(multPV, pt, eta, numKKaon, 0, cfgEff); - float fakeKa = getEfficiency(multPV, pt, eta, numKKaon, 1, cfgEff); - float wKa = (1.0 - fakeKa) / effKa; - if (std::isfinite(wKa) && wKa > 0.f && effKa > KFloatEpsilon) { - histos.fill(HIST("hEtaPhiRecoEffWtd_Ka"), vz, sign, pt, eta, phi, wKa); - histos.fill(HIST("hEtaPhiReco_Ka"), vz, sign, pt, eta, phi, 1.0); - } + float getFlatteningWeight(float vz, float chg, float pt, float eta, float phi, PIDIdx pidType, bool cfgflat) const + { + if (!cfgflat) + return 1.0; + THnSparseF* h = state.hFlatWeight[pidType]; + + if (!h) + return 0.0; + int bins[5]; + bins[0] = h->GetAxis(0)->FindBin(vz); + bins[1] = h->GetAxis(1)->FindBin(chg); + bins[2] = h->GetAxis(2)->FindBin(pt); + bins[3] = h->GetAxis(3)->FindBin(eta); + bins[4] = h->GetAxis(4)->FindBin(phi); + float val = h->GetBinContent(bins); + + return val; } - // 4. Proton Weighting - if (selectionProton(track)) { - float effPr = getEfficiency(multPV, pt, eta, numKProton, 0, cfgEff); - float fakePr = getEfficiency(multPV, pt, eta, numKProton, 1, cfgEff); - float wPr = (1.0 - fakePr) / effPr; - if (std::isfinite(wPr) && wPr > 0.f && effPr > KFloatEpsilon) { - histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, wPr); - histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi, 1.0); - } + std::vector* offsetFT0 = nullptr; + uint64_t mLastTimestamp = 0; + double getEtaFT0(uint64_t globalChno, int i) + { + if (i > 1 || i < 0) { + LOGF(fatal, "kFIT Index %d out of range", i); + } + auto chPos = ft0Det.getChannelCenter(globalChno); + auto x = chPos.X() + (*offsetFT0)[i].getX(); + auto y = chPos.Y() + (*offsetFT0)[i].getY(); + auto z = chPos.Z() + (*offsetFT0)[i].getZ(); + // i == 0 is FT0A (A-side, positive Z) + // i == 1 is FT0C (C-side, negative Z) + if (i == 1) { + z = -std::abs(z); + } else if (i == 0) { + z = std::abs(z); + } + auto r = std::sqrt(x * x + y * y); + auto theta = std::atan2(r, z); + return -std::log(std::tan(0.5 * theta)); } - } // end track loop - } // end col loop - } // end mcColl loop - LOGF(info, "FINISHED RUNNING processMCFlat"); - } - PROCESS_SWITCH(RadialFlowDecorr, processMCFlat, "process MC to calculate FlatWeights", cfgRunGetMCFlat); - - void processMCMean(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/, aod::McParticles const& mcParticles) - { - // Track-sum arrays using KNsp index (isp=0: Incl, 1: Pi, 2: Ka, 3: Pr) - double sumWiTruth[KNsp][KNEta][KNpT]{}, sumWiptiTruth[KNsp][KNEta][KNpT]{}; - double sumWiReco[KNsp][KNEta][KNpT]{}, sumWiptiReco[KNsp][KNEta][KNpT]{}; - double sumWiRecoEffCorr[KNsp][KNEta][KNpT]{}, sumWiptiRecoEffCorr[KNsp][KNEta][KNpT]{}; - - for (const auto& mcCollision : mcColl) { - auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); - if (colSlice.size() != 1) - continue; - - for (const auto& col : colSlice) { - if (!col.has_mcCollision() || !isEventSelected(col)) - continue; - - auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); - auto partSlice = mcParticles.sliceBy(partPerMcCollision, mcCollision.globalIndex()); - if (trackSlice.size() < 1 || partSlice.size() < 1) - continue; - - float cent = getCentrality(col); - if (cent > KCentMax) - continue; - float multPV = col.multNTracksPV(); - float vz = col.posZ(); - - // Reset local event sum - memset(sumWiTruth, 0, sizeof(sumWiTruth)); - memset(sumWiptiTruth, 0, sizeof(sumWiptiTruth)); - memset(sumWiReco, 0, sizeof(sumWiReco)); - memset(sumWiptiReco, 0, sizeof(sumWiptiReco)); - memset(sumWiRecoEffCorr, 0, sizeof(sumWiRecoEffCorr)); - memset(sumWiptiRecoEffCorr, 0, sizeof(sumWiptiRecoEffCorr)); - - // --- 1. Truth Loop --- - for (const auto& particle : partSlice) { - if (!isParticleSelected(particle) || !particle.isPhysicalPrimary()) - continue; - float pt = particle.pt(), eta = particle.eta(); - const int absPdgId = std::abs(particle.pdgCode()); - bool isSpecies[KNsp] = {true, (absPdgId == KPiPlus), (absPdgId == KKPlus), (absPdgId == KProton)}; - for (int ieta = 0; ieta < KNEta; ++ieta) { - if (eta <= etaLw[ieta] || eta > etaUp[ieta]) - continue; - for (int ipt = 0; ipt < KNpT; ++ipt) { - if (pt <= pTLw[ipt] || pt > pTUp[ipt]) - continue; - for (int isp = 0; isp < KNsp; ++isp) { - if (isSpecies[isp]) { - sumWiTruth[isp][ieta][ipt]++; - sumWiptiTruth[isp][ieta][ipt] += pt; - } - } + + void loadAlignParam(uint64_t timestamp) + { + if (timestamp == mLastTimestamp && offsetFT0 != nullptr) { + return; } + offsetFT0 = ccdb->getForTimeStamp>("FT0/Calib/Align", timestamp); + mLastTimestamp = timestamp; + LOGF(info, "Successfully loaded new alignment parameters for timestamp %llu", timestamp); + LOGF(info, "Offset for FT0A: x = %.3f y = %.3f z = %.3f\n", (*offsetFT0)[0].getX(), (*offsetFT0)[0].getY(), (*offsetFT0)[0].getZ()); + LOGF(info, "Offset for FT0C: x = %.3f y = %.3f z = %.3f\n", (*offsetFT0)[1].getX(), (*offsetFT0)[1].getY(), (*offsetFT0)[1].getZ()); } - } - - for (int isp = 0; isp < KNsp; ++isp) { - if (isp == numKInclusive) { - histos.fill(HIST("MCGen/Prof_Cent_Nchrec"), cent, sumWiTruth[0][0][0]); - histos.fill(HIST("MCGen/Prof_Mult_Nchrec"), multPV, sumWiTruth[0][0][0]); - if (sumWiTruth[0][0][0] > 1.0f) { - histos.fill(HIST("MCGen/Prof_Cent_MeanpT"), cent, sumWiptiTruth[0][0][0] / sumWiTruth[0][0][0]); - histos.fill(HIST("MCGen/Prof_Mult_MeanpT"), multPV, sumWiptiTruth[0][0][0] / sumWiTruth[0][0][0]); - } - - } else if (isp == numKPion) { - histos.fill(HIST("MCGen/Prof_Cent_Nchrec_Pi"), cent, sumWiTruth[1][0][0]); - histos.fill(HIST("MCGen/Prof_Mult_Nchrec_Pi"), multPV, sumWiTruth[1][0][0]); - if (sumWiTruth[1][0][0] > 1.0f) { - histos.fill(HIST("MCGen/Prof_Cent_MeanpT_Pi"), cent, sumWiptiTruth[1][0][0] / sumWiTruth[1][0][0]); - histos.fill(HIST("MCGen/Prof_Mult_MeanpT_Pi"), multPV, sumWiptiTruth[1][0][0] / sumWiTruth[1][0][0]); + template + std::pair calculateMeanAndC2FromSums(const double sumpmwk[KIntM][KIntK], const double sumwk[KIntK], float referenceMeanPt) const + { + if (sumwk[1] == 0.) { + return {0.f, 0.f}; } - } else if (isp == numKKaon) { - histos.fill(HIST("MCGen/Prof_Cent_Nchrec_Ka"), cent, sumWiTruth[2][0][0]); - histos.fill(HIST("MCGen/Prof_Mult_Nchrec_Ka"), multPV, sumWiTruth[2][0][0]); + double tau1 = sumwk[2] / (sumwk[1] * sumwk[1]); + double denom2 = 1. - tau1; - if (sumWiTruth[2][0][0] > 1.0f) { - histos.fill(HIST("MCGen/Prof_Cent_MeanpT_Ka"), cent, sumWiptiTruth[2][0][0] / sumWiTruth[2][0][0]); - histos.fill(HIST("MCGen/Prof_Mult_MeanpT_Ka"), multPV, sumWiptiTruth[2][0][0] / sumWiTruth[2][0][0]); + if (std::abs(denom2) < KFloatEpsilon) { + double pmk11safe = sumpmwk[1][1] / sumwk[1]; + return {static_cast(pmk11safe), 0.f}; } - } else if (isp == numKProton) { - histos.fill(HIST("MCGen/Prof_Cent_Nchrec_Pr"), cent, sumWiTruth[3][0][0]); - histos.fill(HIST("MCGen/Prof_Mult_Nchrec_Pr"), multPV, sumWiTruth[3][0][0]); - if (sumWiTruth[3][0][0] > 1.0f) { - histos.fill(HIST("MCGen/Prof_Cent_MeanpT_Pr"), cent, sumWiptiTruth[3][0][0] / sumWiTruth[3][0][0]); - histos.fill(HIST("MCGen/Prof_Mult_MeanpT_Pr"), multPV, sumWiptiTruth[3][0][0] / sumWiTruth[3][0][0]); - } - } - } - - // --- 2. Reco Loop --- - for (const auto& track : trackSlice) { - if (!isTrackSelected(track)) - continue; - float pt = track.pt(), eta = track.eta(), phi = track.phi(); - auto sign = track.sign(); - bool isSpecies[KNsp] = {true, selectionPion(track), selectionKaon(track), selectionProton(track)}; - for (int isp = 0; isp < KNsp; ++isp) { - if (!isSpecies[isp]) - continue; - float eff = getEfficiency(multPV, pt, eta, static_cast(isp), 0, cfgEff); - float fake = getEfficiency(multPV, pt, eta, static_cast(isp), 1, cfgEff); - float flatW = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); - float w = flatW * (1.0 - fake) / eff; - if (!std::isfinite(w) || w <= 0.f || eff <= KFloatEpsilon) - continue; + double pmk11 = sumpmwk[1][1] / sumwk[1]; - for (int ieta = 0; ieta < KNEta; ++ieta) { - if (eta <= etaLw[ieta] || eta > etaUp[ieta]) - continue; - for (int ipt = 0; ipt < KNpT; ++ipt) { - if (pt <= pTLw[ipt] || pt > pTUp[ipt]) - continue; - sumWiReco[isp][ieta][ipt]++; - sumWiptiReco[isp][ieta][ipt] += pt; - sumWiRecoEffCorr[isp][ieta][ipt] += w; - sumWiptiRecoEffCorr[isp][ieta][ipt] += w * pt; - - if (ipt == 0) { - // Fill profiles vs. Centrality - histos.fill(HIST("Eff_cent"), cent, eff); - histos.fill(HIST("Fake_cent"), cent, fake); - histos.fill(HIST("wgt_cent"), cent, w); - - // Fill profiles vs. Multiplicity (Ntrk) - histos.fill(HIST("Eff_Ntrk"), multPV, eff); - histos.fill(HIST("Fake_Ntrk"), multPV, fake); - histos.fill(HIST("wgt_Ntrk"), multPV, w); - - // Fill profiles vs. pT - histos.fill(HIST("Eff_pT"), pt, eff); - histos.fill(HIST("Fake_pT"), pt, fake); - histos.fill(HIST("wgt_pT"), pt, w); - - // Fill profiles vs. Eta - histos.fill(HIST("Eff_eta"), eta, eff); - histos.fill(HIST("Fake_eta"), eta, fake); - histos.fill(HIST("wgt_eta"), eta, w); - } - } + double pmk12 = 0.f; + if (sumwk[2] != 0.f) { + pmk12 = sumpmwk[1][2] / sumwk[2]; } - if (isp == numKInclusive) { + double pmk22 = 0.f; + if (sumwk[2] != 0.f) { + pmk22 = sumpmwk[2][2] / sumwk[2]; + } - histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + float calculatedMeanPt = pmk11; - } else if (isp == numKPion) { // Pion - histos.fill(HIST("hEtaPhiReco_Pi"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_Pi"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_Pi"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + double p1kBar1 = pmk11 - referenceMeanPt; + double p2kBar2 = pmk22 - 2.0f * pmk12 * referenceMeanPt + referenceMeanPt * referenceMeanPt; - } else if (isp == numKKaon) { // Kaon - histos.fill(HIST("hEtaPhiReco_Ka"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_Ka"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_Ka"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + double p1kBar1sq = p1kBar1 * p1kBar1; + double numerator2 = p1kBar1sq - (tau1 * p2kBar2); - } else if (isp == numKProton) { // Proton - histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } + float twopcorr = numerator2 / denom2; + return {calculatedMeanPt, twopcorr}; } - } - - for (int isp = 0; isp < KNsp; ++isp) { - if (isp == numKInclusive) { - histos.fill(HIST("MCReco/Prof_Cent_Nchrec"), cent, sumWiReco[0][0][0]); - histos.fill(HIST("MCReco/Prof_Mult_Nchrec"), multPV, sumWiReco[0][0][0]); - if (sumWiReco[0][0][0] > 1.0f) { - histos.fill(HIST("MCReco/Prof_Cent_MeanpT"), cent, sumWiptiReco[0][0][0] / sumWiReco[0][0][0]); - histos.fill(HIST("MCReco/Prof_Mult_MeanpT"), multPV, sumWiptiReco[0][0][0] / sumWiReco[0][0][0]); - } - } else if (isp == numKPion) { - histos.fill(HIST("MCReco/Prof_Cent_Nchrec_Pi"), cent, sumWiReco[1][0][0]); - histos.fill(HIST("MCReco/Prof_Mult_Nchrec_Pi"), multPV, sumWiReco[1][0][0]); + using GeneralCollisions = soa::Join; + + Filter collisionFilter = nabs(aod::collision::posZ) < cfgVtxZCut; + using AodCollisionsSel = soa::Filtered; + + using UnfilteredTracks = soa::Join< + aod::Tracks, + aod::TracksExtra, + aod::TrackSelection, + aod::TracksDCA, + aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr, + aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr>; + Filter trackFilter = aod::track::pt > KPtMin&& + aod::track::pt < KPtMax&& + requireGlobalTrackInFilter(); + using AodTracksSel = soa::Filtered; + using TCs = soa::Join; + using FilteredTCs = soa::Filtered; + using BCsRun3 = soa::Join; + + using MyRun3MCCollisions = soa::Join< + aod::Collisions, aod::EvSels, aod::Mults, aod::MultsExtra, + aod::CentFT0Ms,aod::CentFDDMs,aod::CentFV0As, + aod::CentNGlobals, aod::McCollisionLabels>; + + using MyMCTracks = soa::Join< + aod::Tracks, aod::TrackSelection, aod::TracksExtra, aod::TracksDCA, + aod::McTrackLabels, + aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr, + aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr>; + + PresliceUnsorted partPerMcCollision = aod::mcparticle::mcCollisionId; + PresliceUnsorted colPerMcCollision = aod::mccollisionlabel::mcCollisionId; + PresliceUnsorted trackPerMcParticle = aod::mctracklabel::mcParticleId; + Preslice perCollision = aod::track::collisionId; + Preslice trackPerCollision = aod::track::collisionId; + + void declareCommonQA() + { + histos.add("hZvtx_after_sel", ";z_{vtx} (cm)", kTH1F, {{KNbinsZvtx, KZvtxMin, KZvtxMax}}); + histos.add("hVtxZ", ";z_{vtx} (cm)", kTH1F, {{KNbinsZvtx, KZvtxMin, KZvtxMax}}); + histos.add("hCentrality", ";centrality (%)", kTH1F, {{centAxis1Per}}); + histos.add("Hist2D_globalTracks_PVTracks", ";N_{global};N_{PV}", kTH2F, {{nChAxis2}, {nChAxis2}}); + histos.add("Hist2D_cent_nch", ";N_{PV};cent (%)", kTH2F, {{nChAxis2}, {centAxis1Per}}); + histos.add("hP", ";p (GeV/c)", kTH1F, {{KNbinsPt, KPMin, KPMax}}); + histos.add("hPt", ";p_{T} (GeV/c)", kTH1F, {{KNbinsPt, KPtMin, KPtMax}}); + histos.add("hEta", ";#eta", kTH1F, {{KNbinsEtaFine, KEtaMin, KEtaMax}}); + histos.add("hPhi", ";#phi", kTH1F, {{KNbinsPhi, KPhiMin, TwoPI}}); + } - if (sumWiReco[1][0][0] > 1.0f) { - histos.fill(HIST("MCReco/Prof_Cent_MeanpT_Pi"), cent, sumWiptiReco[1][0][0] / sumWiReco[1][0][0]); - histos.fill(HIST("MCReco/Prof_Mult_MeanpT_Pi"), multPV, sumWiptiReco[1][0][0] / sumWiReco[1][0][0]); - } + void declareMCCommonHists() + { + for (const auto& suf : pidSuffix) { + histos.add("h3_AllPrimary" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + histos.add("h3_RecoMatchedToPrimary" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + histos.add("h3_AllReco" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + histos.add("h3_RecoUnMatchedToPrimary_Secondary" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + histos.add("h3_RecoUnMatchedToPrimary_Fake" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + histos.add("h3_RecoMatchedToPrimary_MisID" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + } + + histos.add("ptResolution", ";p_{T}^{MC};(p_{T}^{reco}-p_{T}^{MC})/p_{T}^{MC}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {100, -0.2, 0.2}}); + histos.add("etaResolution", ";#eta^{MC};#eta^{reco}-#eta^{MC}", kTH2F, {{KNbinsEtaRes, -KEtaFineMax, KEtaFineMax}, {100, -0.02, 0.02}}); + histos.add("etaTruthReco", ";#eta^{MC};#eta^{reco}", kTH2F, {{KNbinsEtaRes, -KEtaFineMax, KEtaFineMax}, {KNbinsEtaRes, -KEtaFineMax, KEtaFineMax}}); + histos.add("TruthTracKVz", ";Vz^{MC};Vz^{Reco}", kTH2F, {{KNbinsVz, KVzMin, KVzMax}, {KNbinsVz, KVzMin, KVzMax}}); + histos.add("vzResolution", ";Vz^{MC};(Vz^{reco}-Vz^{MC})/Vz^{MC}", kTH2F, {{KNbinsVz, KVzMin, KVzMax}, {100, -0.1, 0.1}}); + } - } else if (isp == numKKaon) { - histos.fill(HIST("MCReco/Prof_Cent_Nchrec_Ka"), cent, sumWiReco[2][0][0]); - histos.fill(HIST("MCReco/Prof_Mult_Nchrec_Ka"), multPV, sumWiReco[2][0][0]); + void declarenSigHists() + { + for (const auto& suf : pidSuffix) { + // Before Cuts + histos.add("h2DnsigmaTpcVsPtBeforeCut" + suf, "TPC nSigma vs pT Before Cut;p_{T} (GeV/c);n#sigma_{TPC}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); + histos.add("h2DnsigmaTofVsPtBeforeCut" + suf, "TOF nSigma vs pT Before Cut;p_{T} (GeV/c);n#sigma_{TOF}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); + histos.add("h2DnsigmaTpcVsTofBeforeCut" + suf, "TPC vs TOF nSigma Before Cut;n#sigma_{TOF};n#sigma_{TPC}", kTH2F, {{200, -10.f, 10.f}, {200, -10.f, 10.f}}); - if (sumWiReco[2][0][0] > 1.0f) { - histos.fill(HIST("MCReco/Prof_Cent_MeanpT_Ka"), cent, sumWiptiReco[2][0][0] / sumWiReco[2][0][0]); - histos.fill(HIST("MCReco/Prof_Mult_MeanpT_Ka"), multPV, sumWiptiReco[2][0][0] / sumWiReco[2][0][0]); - } - } else if (isp == numKProton) { - histos.fill(HIST("MCReco/Prof_Cent_Nchrec_Pr"), cent, sumWiReco[3][0][0]); - histos.fill(HIST("MCReco/Prof_Mult_Nchrec_Pr"), multPV, sumWiReco[3][0][0]); - if (sumWiReco[3][0][0] > 1.0f) { - histos.fill(HIST("MCReco/Prof_Cent_MeanpT_Pr"), cent, sumWiptiReco[3][0][0] / sumWiReco[3][0][0]); - histos.fill(HIST("MCReco/Prof_Mult_MeanpT_Pr"), multPV, sumWiptiReco[3][0][0] / sumWiReco[3][0][0]); + // After Cuts + histos.add("h2DnsigmaTpcVsPtAfterCut" + suf, "TPC nSigma vs pT After Cut;p_{T} (GeV/c);n#sigma_{TPC}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); + histos.add("h2DnsigmaTofVsPtAfterCut" + suf, "TOF nSigma vs pT After Cut;p_{T} (GeV/c);n#sigma_{TOF}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); + histos.add("h2DnsigmaTpcVsTofAfterCut" + suf, "TPC vs TOF nSigma After Cut;n#sigma_{TOF};n#sigma_{TPC}", kTH2F, {{200, -10.f, 10.f}, {200, -10.f, 10.f}}); } } - if (isp == numKInclusive) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_Nchrec"), cent, sumWiRecoEffCorr[0][0][0]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_Nchrec"), multPV, sumWiRecoEffCorr[0][0][0]); - if (sumWiRecoEffCorr[0][0][0] > 1.0f) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_MeanpT"), cent, sumWiptiRecoEffCorr[0][0][0] / sumWiRecoEffCorr[0][0][0]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_MeanpT"), multPV, sumWiptiRecoEffCorr[0][0][0] / sumWiRecoEffCorr[0][0][0]); + void declareMCGetFlatHists() + { + for (const auto& suf : pidSuffix) { + histos.add("MCGen/hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("MCGen/hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("MCGen/hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); } + } - } else if (isp == numKPion) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_Nchrec_Pi"), cent, sumWiRecoEffCorr[1][0][0]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_Nchrec_Pi"), multPV, sumWiRecoEffCorr[1][0][0]); - if (sumWiRecoEffCorr[1][0][0] > 1.0f) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_MeanpT_Pi"), cent, sumWiptiRecoEffCorr[1][0][0] / sumWiRecoEffCorr[1][0][0]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_MeanpT_Pi"), multPV, sumWiptiRecoEffCorr[1][0][0] / sumWiRecoEffCorr[1][0][0]); + void declareMCMeanHists() + { + histos.add("Eff_cent", ";cent", kTProfile, {centAxis1Per}); + histos.add("Eff_Ntrk", ";N_{PV}", kTProfile, {nChAxis2}); + histos.add("Eff_pT", ";p_{T}", kTProfile, {{KNbinsPtRes, KPtMin, KPtMax}}); + histos.add("Eff_eta", ";#eta", kTProfile, {{KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + + histos.add("Fake_cent", ";cent", kTProfile, {centAxis1Per}); + histos.add("Fake_Ntrk", ";N_{PV}", kTProfile, {nChAxis2}); + histos.add("Fake_pT", ";p_{T}", kTProfile, {{KNbinsPtRes, KPtMin, KPtMax}}); + histos.add("Fake_eta", ";#eta", kTProfile, {{KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + + histos.add("wgt_cent", ";cent", kTProfile, {centAxis1Per}); + histos.add("wgt_Ntrk", ";N_{PV}", kTProfile, {nChAxis2}); + histos.add("wgt_pT", ";p_{T}", kTProfile, {{KNbinsPtRes, KPtMin, KPtMax}}); + histos.add("wgt_eta", ";#eta", kTProfile, {{KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + + histos.add("pmeanFT0Amultpv", ";N_{PV};Ampl", kTProfile, {nChAxis}); + histos.add("pmeanFT0Cmultpv", ";N_{PV};Ampl", kTProfile, {nChAxis}); + histos.add("pmeanFT0A_cent", ";cent;Ampl", kTProfile, {centAxis1Per}); + histos.add("pmeanFT0C_cent", ";cent;Ampl", kTProfile, {centAxis1Per}); + histos.add("pmean_cent_id_eta_FT0", ";cent;id;#eta", kTProfile3D, {{centAxis1Per}, {200, -0.5, 199.5}, {100, -5.0, 5.0}}); + histos.add("h3_cent_id_eta_FT0", ";cent;id;#eta", kTH3F, {{centAxis1Per}, {200, -0.5, 199.5}, {100, -5.0, 5.0}}); + + histos.add("MCGen/Prof_Cent_Nsp_Nchrec", ";cent;isp", kTProfile2D, {{centAxis1Per}, {spBinAxis}}); + histos.add("MCGen/Prof_Mult_Nsp_Nchrec", ";mult;isp", kTProfile2D, {{nChAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_Cent_Nsp_MeanpT", ";cent;isp", kTProfile2D, {{centAxis1Per}, {spBinAxis}}); + histos.add("MCGen/Prof_Mult_Nsp_MeanpT", ";mult;isp", kTProfile2D, {{nChAxis}, {spBinAxis}}); + + histos.add("pmeanTru_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("pmeanReco_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("pmeanRecoEffcorr_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + + histos.add("pmeanMultTru_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("pmeanMultReco_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("pmeanMultRecoEffcorr_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + + for (const auto& suf : pidSuffix) { + histos.add("hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + + histos.add("Prof2D_MeanpTSub_Tru" + suf, ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {etaBinAxis}}); + histos.add("Prof2D_MeanpTSub_Reco" + suf, ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {etaBinAxis}}); + histos.add("Prof2D_MeanpTSub_RecoEffCorr" + suf, ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {etaBinAxis}}); } + } - } else if (isp == numKKaon) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_Nchrec_Ka"), cent, sumWiRecoEffCorr[2][0][0]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_Nchrec_Ka"), multPV, sumWiRecoEffCorr[2][0][0]); - if (sumWiRecoEffCorr[2][0][0] > 1.0f) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_MeanpT_Ka"), cent, sumWiptiRecoEffCorr[2][0][0] / sumWiRecoEffCorr[2][0][0]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_MeanpT_Ka"), multPV, sumWiptiRecoEffCorr[2][0][0] / sumWiRecoEffCorr[2][0][0]); - } - } else if (isp == numKProton) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_Nchrec_Pr"), cent, sumWiRecoEffCorr[3][0][0]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_Nchrec_Pr"), multPV, sumWiRecoEffCorr[3][0][0]); - if (sumWiRecoEffCorr[3][0][0] > 1.0f) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_MeanpT_Pr"), cent, sumWiptiRecoEffCorr[3][0][0] / sumWiRecoEffCorr[3][0][0]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_MeanpT_Pr"), multPV, sumWiptiRecoEffCorr[3][0][0] / sumWiRecoEffCorr[3][0][0]); + void declareMCFlucHists() + { + histos.add("MCGen/Prof_Cent_NEta_Nsp_Nchrec", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_Mult_NEta_Nsp_Nchrec", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_Cent_NEta_Nsp_MeanpT", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_Mult_NEta_Nsp_MeanpT", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + + histos.add("MCGen/Prof_MeanpT_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_C2_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_C2Sub_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_Cov_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_CovFT0A_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_CovFT0C_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + + histos.add("MCGen/Prof_MeanpT_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_C2_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_C2Sub_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_Cov_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_CovFT0A_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_CovFT0C_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + + for (const auto& suf : pidSuffix) { + histos.add("hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + + histos.add(Form("MCGen/Prof_C2Sub2D_Cent_etaA_etaC%s", suf.c_str()), ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + histos.add(Form("MCGen/Prof_GapSum2D%s", suf.c_str()), ";cent;gap;sum", kTProfile3D, {{centAxis1Per}, {gapAxis}, {sumAxis}}); + histos.add(Form("MCGen/Prof_Cov2D_Cent_etaA_etaC%s", suf.c_str()), ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + histos.add(Form("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC%s", suf.c_str()), ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + histos.add(Form("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC%s", suf.c_str()), ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); } } - } - for (int ietaA = 0; ietaA < KNEta; ++ietaA) { - for (int ietaB = 0; ietaB < KNEta; ++ietaB) { - for (int ipt = 0; ipt < KNpT; ++ipt) { - for (int isp = 0; isp < KNsp; ++isp) { - - // 1. Truth Sub-event Mean - double nTruAB = sumWiTruth[isp][ietaA][ipt] + sumWiTruth[isp][ietaB][ipt]; - if (nTruAB > 0) { - float mptsubTru = (sumWiptiTruth[isp][ietaA][ipt] + sumWiptiTruth[isp][ietaB][ipt]) / nTruAB; - if (isp == numKInclusive) { // Inclusive - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0_Tru"), cent, ietaA, ietaB, mptsubTru); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1_Tru"), cent, ietaA, ietaB, mptsubTru); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2_Tru"), cent, ietaA, ietaB, mptsubTru); - } else if (isp == numKPion) { // Pion - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0_Tru_Pi"), cent, ietaA, ietaB, mptsubTru); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1_Tru_Pi"), cent, ietaA, ietaB, mptsubTru); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2_Tru_Pi"), cent, ietaA, ietaB, mptsubTru); - } else if (isp == numKKaon) { // Kaon - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0_Tru_Ka"), cent, ietaA, ietaB, mptsubTru); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1_Tru_Ka"), cent, ietaA, ietaB, mptsubTru); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2_Tru_Ka"), cent, ietaA, ietaB, mptsubTru); - } else if (isp == numKProton) { // Proton - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0_Tru_Pr"), cent, ietaA, ietaB, mptsubTru); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1_Tru_Pr"), cent, ietaA, ietaB, mptsubTru); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2_Tru_Pr"), cent, ietaA, ietaB, mptsubTru); - } - } - - // 2. Reco Raw Sub-event Mean - double nRecAB = sumWiReco[isp][ietaA][ipt] + sumWiReco[isp][ietaB][ipt]; - if (nRecAB > 0) { - float mptsubReco = (sumWiptiReco[isp][ietaA][ipt] + sumWiptiReco[isp][ietaB][ipt]) / nRecAB; - if (isp == numKInclusive) { - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0_Reco"), cent, ietaA, ietaB, mptsubReco); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1_Reco"), cent, ietaA, ietaB, mptsubReco); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2_Reco"), cent, ietaA, ietaB, mptsubReco); - } else if (isp == numKPion) { - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0_Reco_Pi"), cent, ietaA, ietaB, mptsubReco); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1_Reco_Pi"), cent, ietaA, ietaB, mptsubReco); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2_Reco_Pi"), cent, ietaA, ietaB, mptsubReco); - } else if (isp == numKKaon) { - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0_Reco_Ka"), cent, ietaA, ietaB, mptsubReco); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1_Reco_Ka"), cent, ietaA, ietaB, mptsubReco); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2_Reco_Ka"), cent, ietaA, ietaB, mptsubReco); - } else if (isp == numKProton) { - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0_Reco_Pr"), cent, ietaA, ietaB, mptsubReco); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1_Reco_Pr"), cent, ietaA, ietaB, mptsubReco); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2_Reco_Pr"), cent, ietaA, ietaB, mptsubReco); - } - } + void declareDataGetFlatHists() + { + for (const auto& suf : pidSuffix) { + histos.add("hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + } + histos.add("hnTrkPVZDC", ";N_{PV};ZDC_{A+C}", kTH2F, {{nChAxis2}, {200, 0, 3000}}); + histos.add("hNchZDC", ";N_{trk};ZDC_{A+C}", kTH2F, {{nChAxis2}, {200, 0, 30000}}); + histos.add("hCentnTrk", ";Centrality (%);N_{trk}", kTH2F, {{centAxis1Per}, {nChAxis2}}); + histos.add("hCentnTrkPV", ";Centrality (%);N_{trk, PV}", kTH2F, {{centAxis1Per}, {nChAxis2}}); + } - // 3. Reco Efficiency Corrected Sub-event Mean - double wCorrAB = sumWiRecoEffCorr[isp][ietaA][ipt] + sumWiRecoEffCorr[isp][ietaB][ipt]; - if (wCorrAB > 0) { - float mptsubRecoEffCorr = (sumWiptiRecoEffCorr[isp][ietaA][ipt] + sumWiptiRecoEffCorr[isp][ietaB][ipt]) / wCorrAB; - if (isp == numKInclusive) { - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0_RecoEffCorr"), cent, ietaA, ietaB, mptsubRecoEffCorr); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1_RecoEffCorr"), cent, ietaA, ietaB, mptsubRecoEffCorr); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2_RecoEffCorr"), cent, ietaA, ietaB, mptsubRecoEffCorr); - } else if (isp == numKPion) { - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0_RecoEffCorr_Pi"), cent, ietaA, ietaB, mptsubRecoEffCorr); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1_RecoEffCorr_Pi"), cent, ietaA, ietaB, mptsubRecoEffCorr); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2_RecoEffCorr_Pi"), cent, ietaA, ietaB, mptsubRecoEffCorr); - } else if (isp == numKKaon) { - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0_RecoEffCorr_Ka"), cent, ietaA, ietaB, mptsubRecoEffCorr); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1_RecoEffCorr_Ka"), cent, ietaA, ietaB, mptsubRecoEffCorr); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2_RecoEffCorr_Ka"), cent, ietaA, ietaB, mptsubRecoEffCorr); - } else if (isp == numKProton) { - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0_RecoEffCorr_Pr"), cent, ietaA, ietaB, mptsubRecoEffCorr); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1_RecoEffCorr_Pr"), cent, ietaA, ietaB, mptsubRecoEffCorr); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2_RecoEffCorr_Pr"), cent, ietaA, ietaB, mptsubRecoEffCorr); - } - } + void declareDataMeanHists() + { + histos.add("pmeanFT0Amultpv", "N_{PV}; AmplitudeA", kTProfile, {nChAxis}); + histos.add("pmeanFT0A_cent", "cent; AmplitudeA", kTProfile, {centAxis1Per}); + histos.add("pmeanFT0Cmultpv", "N_{PV}; AmplitudeA", kTProfile, {nChAxis}); + histos.add("pmeanFT0C_cent", "cent; AmplitudeA", kTProfile, {centAxis1Per}); - // 4. pmean Profiles (Individual Bins) - if (ietaA == ietaB) { // only fill once per eta bin - if (sumWiTruth[isp][ietaA][ipt] > 0) { - float val = sumWiptiTruth[isp][ietaA][ipt] / sumWiTruth[isp][ietaA][ipt]; - if (isp == numKInclusive) - histos.fill(HIST("pmeanTruNchEtabinPtbin"), multPV, ietaA, ipt, val); - else if (isp == numKPion) - histos.fill(HIST("pmeanTruNchEtabinPtbin_Pi"), multPV, ietaA, ipt, val); - else if (isp == numKKaon) - histos.fill(HIST("pmeanTruNchEtabinPtbin_Ka"), multPV, ietaA, ipt, val); - else if (isp == numKProton) - histos.fill(HIST("pmeanTruNchEtabinPtbin_Pr"), multPV, ietaA, ipt, val); - } + histos.add("pmean_cent_id_eta_FT0", ";cent;channel id; #eta;amplitude", kTProfile3D, {{centAxis1Per}, {100, -0.5, 99.5}, {100, -5.0, 5.0}}); + histos.add("h3_cent_id_eta_FT0", ";cent;channel id; #eta", kTH3F, {{centAxis1Per}, {100, -0.5, 99.5}, {100, -5.0, 5.0}}); - if (sumWiReco[isp][ietaA][ipt] > 0) { - float val = sumWiptiReco[isp][ietaA][ipt] / sumWiReco[isp][ietaA][ipt]; - if (isp == numKInclusive) - histos.fill(HIST("pmeanRecoNchEtabinPtbin"), multPV, ietaA, ipt, val); - else if (isp == numKPion) - histos.fill(HIST("pmeanRecoNchEtabinPtbin_Pi"), multPV, ietaA, ipt, val); - else if (isp == numKKaon) - histos.fill(HIST("pmeanRecoNchEtabinPtbin_Ka"), multPV, ietaA, ipt, val); - else if (isp == numKProton) - histos.fill(HIST("pmeanRecoNchEtabinPtbin_Pr"), multPV, ietaA, ipt, val); - } - if (sumWiRecoEffCorr[isp][ietaA][ipt] > 0) { - float val = sumWiptiRecoEffCorr[isp][ietaA][ipt] / sumWiRecoEffCorr[isp][ietaA][ipt]; - if (isp == numKInclusive) - histos.fill(HIST("pmeanRecoEffcorrNchEtabinPtbin"), multPV, ietaA, ipt, val); - else if (isp == numKPion) - histos.fill(HIST("pmeanRecoEffcorrNchEtabinPtbin_Pi"), multPV, ietaA, ipt, val); - else if (isp == numKKaon) - histos.fill(HIST("pmeanRecoEffcorrNchEtabinPtbin_Ka"), multPV, ietaA, ipt, val); - else if (isp == numKProton) - histos.fill(HIST("pmeanRecoEffcorrNchEtabinPtbin_Pr"), multPV, ietaA, ipt, val); - } + histos.add("Prof_Cent_Nsp_Nchrec", ";cent;Species;#LT N_{PV}#GT", kTProfile2D, {{centAxis1Per}, {spBinAxis}}); + histos.add("Prof_Mult_Nsp_Nchrec", ";N_{PV};Species;#LT N_{PV}#GT", kTProfile2D, {{nChAxis}, {spBinAxis}}); + histos.add("Prof_Cent_Nsp_MeanpT", ";cent;Species;#LT p_{T}#GT", kTProfile2D, {{centAxis1Per}, {spBinAxis}}); + histos.add("Prof_Mult_Nsp_MeanpT", ";N_{PV};Species;#LT p_{T}#GT", kTProfile2D, {{nChAxis}, {spBinAxis}}); - if (sumWiTruth[isp][ietaA][ipt] > 0) { - if (isp == numKInclusive) - histos.fill(HIST("pmeanMultTruNchEtabinPtbin"), multPV, ietaA, ipt, sumWiTruth[isp][ietaA][ipt]); - else if (isp == numKPion) - histos.fill(HIST("pmeanMultTruNchEtabinPtbin_Pi"), multPV, ietaA, ipt, sumWiTruth[isp][ietaA][ipt]); - else if (isp == numKKaon) - histos.fill(HIST("pmeanMultTruNchEtabinPtbin_Ka"), multPV, ietaA, ipt, sumWiTruth[isp][ietaA][ipt]); - else if (isp == numKProton) - histos.fill(HIST("pmeanMultTruNchEtabinPtbin_Pr"), multPV, ietaA, ipt, sumWiTruth[isp][ietaA][ipt]); - } + histos.add("pmean_nch_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("pmeanMult_nch_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("pmean_cent_etabin_spbin", ";Centrality (%) ;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("pmeanMult_cent_etabin_spbin", ";Centrality (%) ;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); - if (sumWiReco[isp][ietaA][ipt] > 0) { - if (isp == numKInclusive) - histos.fill(HIST("pmeanMultRecoNchEtabinPtbin"), multPV, ietaA, ipt, sumWiReco[isp][ietaA][ipt]); - else if (isp == numKPion) - histos.fill(HIST("pmeanMultRecoNchEtabinPtbin_Pi"), multPV, ietaA, ipt, sumWiReco[isp][ietaA][ipt]); - else if (isp == numKKaon) - histos.fill(HIST("pmeanMultRecoNchEtabinPtbin_Ka"), multPV, ietaA, ipt, sumWiReco[isp][ietaA][ipt]); - else if (isp == numKProton) - histos.fill(HIST("pmeanMultRecoNchEtabinPtbin_Pr"), multPV, ietaA, ipt, sumWiReco[isp][ietaA][ipt]); - } - if (sumWiRecoEffCorr[isp][ietaA][ipt] > 0) { - if (isp == numKInclusive) - histos.fill(HIST("pmeanMultRecoEffcorrNchEtabinPtbin"), multPV, ietaA, ipt, sumWiRecoEffCorr[isp][ietaA][ipt]); - else if (isp == numKPion) - histos.fill(HIST("pmeanMultRecoEffcorrNchEtabinPtbin_Pi"), multPV, ietaA, ipt, sumWiRecoEffCorr[isp][ietaA][ipt]); - else if (isp == numKKaon) - histos.fill(HIST("pmeanMultRecoEffcorrNchEtabinPtbin_Ka"), multPV, ietaA, ipt, sumWiRecoEffCorr[isp][ietaA][ipt]); - else if (isp == numKProton) - histos.fill(HIST("pmeanMultRecoEffcorrNchEtabinPtbin_Pr"), multPV, ietaA, ipt, sumWiRecoEffCorr[isp][ietaA][ipt]); - } - } - } // end isp - } // end ipt - } // end ietaB - } // end ietaA - } - } - } - PROCESS_SWITCH(RadialFlowDecorr, processMCMean, "process MC to calculate mean pt/Et and Eff Hists", cfgRunMCMean); - - void processMCFluc(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/, aod::McParticles const& mcParticles) - { - // 1. Safety Check: Step 2 Mean Maps - for (int isp = 0; isp < KNsp; ++isp) { - if (!pmeanTruNchEtabinPtbinStep2[isp] || !pmeanRecoNchEtabinPtbinStep2[isp] || !pmeanRecoEffcorrNchEtabinPtbinStep2[isp] || - !pmeanMultTruNchEtabinPtbinStep2[isp] || !pmeanMultRecoNchEtabinPtbinStep2[isp] || !pmeanMultRecoEffcorrNchEtabinPtbinStep2[isp]) { - LOGF(warning, "MC fluc: Mean pT or Mult map missing for species index %d", isp); - return; - } - } - - // Expanded with KNsp index (isp=0: Incl, 1: Pi, 2: Ka, 3: Pr) - double sumPmwkTru[KNsp][KNEta][KNpT][KIntM][KIntK]{}; - double sumWkTru[KNsp][KNEta][KNpT][KIntK]{}; - double sumPmwkReco[KNsp][KNEta][KNpT][KIntM][KIntK]{}; - double sumWkReco[KNsp][KNEta][KNpT][KIntK]{}; - double sumPmwkRecoEffCor[KNsp][KNEta][KNpT][KIntM][KIntK]{}; - double sumWkRecoEffCor[KNsp][KNEta][KNpT][KIntK]{}; - - double meanTru[KNsp][KNEta][KNpT]{}, c2Tru[KNsp][KNEta][KNpT]{}; - double meanReco[KNsp][KNEta][KNpT]{}, c2Reco[KNsp][KNEta][KNpT]{}; - double meanRecoEffCor[KNsp][KNEta][KNpT]{}, c2RecoEffCor[KNsp][KNEta][KNpT]{}; - - double meanTruMult[KNsp][KNEta][KNpT]{}; - double meanRecoMult[KNsp][KNEta][KNpT]{}; - double meanRecoEffCorMult[KNsp][KNEta][KNpT]{}; - - double p1kBarTru[KNsp][KNEta][KNpT]{}, p1kBarReco[KNsp][KNEta][KNpT]{}, p1kBarRecoEffCor[KNsp][KNEta][KNpT]{}; - double p1kBarTruMult[KNsp][KNEta][KNpT]{}, p1kBarRecoMult[KNsp][KNEta][KNpT]{}, p1kBarRecoEffCorMult[KNsp][KNEta][KNpT]{}; - - for (const auto& mcCollision : mcColl) { - auto partSlice = mcParticles.sliceBy(partPerMcCollision, mcCollision.globalIndex()); - auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); - if (colSlice.size() != 1) - continue; - - for (const auto& col : colSlice) { - if (!col.has_mcCollision() || !isEventSelected(col)) - continue; - - auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); - if (trackSlice.size() < 1) - continue; - - float cent = getCentrality(col); - if (cent > KCentMax) - continue; - float multPV = col.multNTracksPV(); - // Reset local arrays - memset(sumPmwkTru, 0, sizeof(sumPmwkTru)); - memset(sumWkTru, 0, sizeof(sumWkTru)); - memset(sumPmwkReco, 0, sizeof(sumPmwkReco)); - memset(sumWkReco, 0, sizeof(sumWkReco)); - memset(sumPmwkRecoEffCor, 0, sizeof(sumPmwkRecoEffCor)); - memset(sumWkRecoEffCor, 0, sizeof(sumWkRecoEffCor)); - - memset(meanTru, 0, sizeof(meanTru)); - memset(c2Tru, 0, sizeof(c2Tru)); - memset(meanReco, 0, sizeof(meanReco)); - memset(c2Reco, 0, sizeof(c2Reco)); - memset(meanRecoEffCor, 0, sizeof(meanRecoEffCor)); - memset(c2RecoEffCor, 0, sizeof(c2RecoEffCor)); - - memset(meanTruMult, 0, sizeof(meanTruMult)); - memset(meanRecoMult, 0, sizeof(meanRecoMult)); - memset(meanRecoEffCorMult, 0, sizeof(meanRecoEffCorMult)); - - memset(p1kBarTru, 0, sizeof(p1kBarTru)); - memset(p1kBarReco, 0, sizeof(p1kBarReco)); - memset(p1kBarRecoEffCor, 0, sizeof(p1kBarRecoEffCor)); - - memset(p1kBarTruMult, 0, sizeof(p1kBarTruMult)); - memset(p1kBarRecoMult, 0, sizeof(p1kBarRecoMult)); - memset(p1kBarRecoEffCorMult, 0, sizeof(p1kBarRecoEffCorMult)); - - // --- 1. Truth Loop --- - for (const auto& particle : partSlice) { - if (!isParticleSelected(particle) || !particle.isPhysicalPrimary()) - continue; - - float pt = particle.pt(); - float eta = particle.eta(); - const int absPdgId = std::abs(particle.pdgCode()); - bool isSpecies[KNsp] = {true, (absPdgId == KPiPlus), (absPdgId == KKPlus), (absPdgId == KProton)}; - - for (int ieta = 0; ieta < KNEta; ++ieta) { - if (eta <= etaLw[ieta] || eta > etaUp[ieta]) - continue; - for (int ipt = 0; ipt < KNpT; ++ipt) { - if (pt <= pTLw[ipt] || pt > pTUp[ipt]) - continue; + for (const auto& suf : pidSuffix) { + histos.add("hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - for (int isp = 0; isp < KNsp; ++isp) { - if (isSpecies[isp]) { - for (int k = 0; k < KIntK; ++k) { - for (int m = 0; m < KIntM; ++m) { - sumPmwkTru[isp][ieta][ipt][m][k] += std::pow(pt, m); - } - sumWkTru[isp][ieta][ipt][k]++; - } - } - } + histos.add("Prof2D_MeanpTSub" + suf, ";cent;#eta_{A} bin;#eta_{C} bin", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {{etaBinAxis}}}); } } - } // end truth loop - - // --- 2. Reco Loop --- - float vz = col.posZ(); - for (const auto& track : trackSlice) { - if (!isTrackSelected(track)) - continue; - - float pt = track.pt(); - float eta = track.eta(); - float phi = track.phi(); - float sign = track.sign(); - bool isSpecies[KNsp] = {true, selectionPion(track), selectionKaon(track), selectionProton(track)}; - - for (int isp = 0; isp < KNsp; ++isp) { - if (!isSpecies[isp]) - continue; - - float eff = getEfficiency(col.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); - float fake = getEfficiency(col.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); - float flatW = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); - float w = flatW * (1.0 - fake) / eff; - if (!std::isfinite(w) || w <= 0.f || eff <= KFloatEpsilon) - continue; + void declareDataFlucHists() + { + histos.add("Prof_MeanpT_Cent_etabin_spbin", ";cent;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_MeanpT_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_C2_Cent_etabin_spbin", ";cent;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_C2_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + + histos.add("Prof_C2Sub_Cent_etabin_spbin", ";Centrality;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_C2Sub_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_Cov_Cent_etabin_spbin", ";Centrality;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_Cov_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + + histos.add("Prof_CovFT0A_Cent_etabin_spbin", ";Centrality;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_CovFT0A_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_CovFT0C_Cent_etabin_spbin", ";Centrality;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_CovFT0C_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + + for (const auto& suf : pidSuffix) { + histos.add("hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("Prof_C2Sub2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A};#eta_{C}", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + histos.add("Prof_GapSum2D" + suf, ";cent;#Delta#eta (Gap);#Sigma#eta/2 (Sum)", kTProfile3D, {{centAxis1Per}, {gapAxis}, {sumAxis}}); + histos.add("Prof_Cov2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A} bin;#eta_{C} bin", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + histos.add("Prof_CovFT0A2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A};#eta_{B}", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + histos.add("Prof_CovFT0C2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A};#eta_{B}", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + } + } - for (int ieta = 0; ieta < KNEta; ++ieta) { - if (eta <= etaLw[ieta] || eta > etaUp[ieta]) - continue; - for (int ipt = 0; ipt < KNpT; ++ipt) { - if (pt <= pTLw[ipt] || pt > pTUp[ipt]) - continue; - for (int k = 0; k < KIntK; ++k) { - for (int m = 0; m < KIntM; ++m) { - sumPmwkReco[isp][ieta][ipt][m][k] += std::pow(1.0, k) * std::pow(pt, m); - sumPmwkRecoEffCor[isp][ieta][ipt][m][k] += std::pow(w, k) * std::pow(pt, m); + THnSparseF* buildWeightMapFromRaw(THnSparseF* hRaw, const char* mapName) + { + if (!hRaw) { + LOGF(error, "Raw eta-phi map for '%s' is null; no flattening will be applied.", mapName); + return nullptr; + } + auto hWMap = reinterpret_cast(hRaw->Clone(mapName)); + hWMap->SetTitle(Form("Flattening Weight Map %s (w_{#phi} = / N_{#phi})", mapName)); + hWMap->Reset(); + auto axV = hRaw->GetAxis(0); // Vz + auto axChg = hRaw->GetAxis(1); // Charge + auto axPt = hRaw->GetAxis(2); // Pt + auto axE = hRaw->GetAxis(3); // Eta + auto axP = hRaw->GetAxis(4); // Phi + + int bins[5]; + for (int iv = 1; iv <= axV->GetNbins(); ++iv) { + bins[0] = iv; + for (int ichg = 1; ichg <= axChg->GetNbins(); ++ichg) { + bins[1] = ichg; + for (int ipt = 1; ipt <= axPt->GetNbins(); ++ipt) { + bins[2] = ipt; + for (int ie = 1; ie <= axE->GetNbins(); ++ie) { + bins[3] = ie; + double sum = 0.0; + int nphi = axP->GetNbins(); + for (int ip = 1; ip <= nphi; ++ip) { + bins[4] = ip; + sum += hRaw->GetBinContent(bins); + } + const double avg = (nphi > 0 ? sum / nphi : 0.0); + for (int ip = 1; ip <= nphi; ++ip) { + bins[4] = ip; + const double raw = hRaw->GetBinContent(bins); + const double w = (avg > 0.0 && raw > 0.0) ? (avg / raw) : 1.0; + hWMap->SetBinContent(bins, w); + } } - sumWkReco[isp][ieta][ipt][k] += std::pow(1.0, k); - sumWkRecoEffCor[isp][ieta][ipt][k] += std::pow(w, k); } } } - if (isp == numKInclusive) { - histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - - } else if (isp == numKPion) { // Pion - histos.fill(HIST("hEtaPhiReco_Pi"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_Pi"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_Pi"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - - } else if (isp == numKKaon) { // Kaon - histos.fill(HIST("hEtaPhiReco_Ka"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_Ka"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_Ka"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - - } else if (isp == numKProton) { // Proton - histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } + LOGF(info, "Flattening weight map '%s' built.", mapName); + return hWMap; } - } // trkslice - - // --- 3. FullEvent calculation & Covariances --- - for (int ieta = 0; ieta < KNEta; ++ieta) { - for (int ipt = 0; ipt < KNpT; ++ipt) { - - // Safely get the X-axis bin using the Inclusive map [0] - const int ibx = pmeanTruNchEtabinPtbinStep2[0]->GetXaxis()->FindBin(col.multNTracksPV()); - const int iby = ieta + 1; - const int ibz = ipt + 1; - - for (int isp = 0; isp < KNsp; ++isp) { - meanTruMult[isp][ieta][ipt] = sumWkTru[isp][ieta][ipt][1]; - meanRecoMult[isp][ieta][ipt] = sumWkReco[isp][ieta][ipt][1]; - meanRecoEffCorMult[isp][ieta][ipt] = sumWkRecoEffCor[isp][ieta][ipt][1]; - - // Dynamically fetch from the arrays using the 'isp' index! - float mmptTru = pmeanTruNchEtabinPtbinStep2[isp]->GetBinContent(ibx, iby, ibz); - float mmptReco = pmeanRecoNchEtabinPtbinStep2[isp]->GetBinContent(ibx, iby, ibz); - float mmptRecoEffCor = pmeanRecoEffcorrNchEtabinPtbinStep2[isp]->GetBinContent(ibx, iby, ibz); - - float mmMultTru = pmeanMultTruNchEtabinPtbinStep2[isp]->GetBinContent(ibx, iby, ibz); - float mmMultReco = pmeanMultRecoNchEtabinPtbinStep2[isp]->GetBinContent(ibx, iby, ibz); - float mmMultRecoEffCor = pmeanMultRecoEffcorrNchEtabinPtbinStep2[isp]->GetBinContent(ibx, iby, ibz); - - if (std::isfinite(mmptTru)) - std::tie(meanTru[isp][ieta][ipt], c2Tru[isp][ieta][ipt]) = calculateMeanAndC2FromSums(sumPmwkTru[isp][ieta][ipt], sumWkTru[isp][ieta][ipt], mmptTru); - if (std::isfinite(mmptReco)) - std::tie(meanReco[isp][ieta][ipt], c2Reco[isp][ieta][ipt]) = calculateMeanAndC2FromSums(sumPmwkReco[isp][ieta][ipt], sumWkReco[isp][ieta][ipt], mmptReco); - if (std::isfinite(mmptRecoEffCor)) - std::tie(meanRecoEffCor[isp][ieta][ipt], c2RecoEffCor[isp][ieta][ipt]) = calculateMeanAndC2FromSums(sumPmwkRecoEffCor[isp][ieta][ipt], sumWkRecoEffCor[isp][ieta][ipt], mmptRecoEffCor); - - if (mmptTru != 0.0f) - p1kBarTru[isp][ieta][ipt] = meanTru[isp][ieta][ipt] - mmptTru; - if (mmptReco != 0.0f) - p1kBarReco[isp][ieta][ipt] = meanReco[isp][ieta][ipt] - mmptReco; - if (mmptRecoEffCor != 0.0f) - p1kBarRecoEffCor[isp][ieta][ipt] = meanRecoEffCor[isp][ieta][ipt] - mmptRecoEffCor; - - if (mmMultTru != 0.0f) - p1kBarTruMult[isp][ieta][ipt] = meanTruMult[isp][ieta][ipt] - mmMultTru; - if (mmMultReco != 0.0f) - p1kBarRecoMult[isp][ieta][ipt] = meanRecoMult[isp][ieta][ipt] - mmMultReco; - if (mmMultRecoEffCor != 0.0f) - p1kBarRecoEffCorMult[isp][ieta][ipt] = meanRecoEffCorMult[isp][ieta][ipt] - mmMultRecoEffCor; - } + + inline void loadTProfile3D(TDirectory* dir, const char* name, TProfile3D*& target) + { + if (!dir) { + LOGF(error, "loadTProfile3D: directory is null for object %s", name); + return; + } + auto* obj = dir->Get(name); + if (!obj) { + LOGF(error, "loadTProfile3D: object '%s' not found in directory %s", name, dir->GetName()); + return; + } + auto* prof = dynamic_cast(obj); + if (!prof) { + LOGF(error, "loadTProfile3D: object '%s' is not a TProfile3D (it is %s)", name, obj->ClassName()); + return; + } + target = reinterpret_cast(prof->Clone(Form("%s_clone", name))); + target->SetDirectory(nullptr); + LOGF(info, "Loaded TProfile3D '%s' with entries = %.0f", name, target->GetEntries()); } - } - - for (int isp = 0; isp < KNsp; ++isp) { - if (isp == numKInclusive) { - histos.fill(HIST("MCGen/Prof_Cent_Nchrec"), cent, sumWkTru[isp][0][0][1]); - histos.fill(HIST("MCGen/Prof_Mult_Nchrec"), multPV, sumWkTru[isp][0][0][1]); - if (sumWkTru[isp][0][0][1] > 1.0f) { - histos.fill(HIST("MCGen/Prof_Cent_MeanpT"), cent, meanTru[isp][0][0]); - histos.fill(HIST("MCGen/Prof_Mult_MeanpT"), multPV, meanTru[isp][0][0]); - } - } else if (isp == numKPion) { - histos.fill(HIST("MCGen/Prof_Cent_Nchrec_Pi"), cent, sumWkTru[isp][0][0][1]); - histos.fill(HIST("MCGen/Prof_Mult_Nchrec_Pi"), multPV, sumWkTru[isp][0][0][1]); + void init(InitContext&) + { + if (cfgSys == kPbPb) { + nChAxis = {cfgNchPbMax / 4, KBinOffset, cfgNchPbMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; + nChAxis2 = {cfgNchPbMax / 20, KBinOffset, cfgNchPbMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; + } else if (cfgSys == kNeNe || cfgSys == kOO) { + nChAxis = {cfgNchOMax / 2, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; + nChAxis2 = {cfgNchOMax / 5, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; + } else { + nChAxis = {cfgNchOMax / 2, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; + nChAxis2 = {cfgNchOMax / 5, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; + } + + ccdb->setURL(cfgCCDBurl.value); + ccdb->setCaching(true); + ccdb->setLocalObjectValidityChecking(); + int64_t now = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + ccdb->setCreatedNotAfter(now); + + loadAlignParam(now); + ft0Det.calculateChannelCenter(); + + std::string sysDir = ""; + switch (cfgSys) { + case kPbPb: + sysDir = "PbPbTest"; + break; + case kNeNe: + sysDir = "NeNeTest"; + break; + case kOO: + sysDir = "OOTest"; + break; + case kpp: + sysDir = "ppTest"; + break; + default: + LOGF(fatal, "Invalid cfgSys value: %d", cfgSys.value); + } + + std::string pathEff = cfgCCDBUserPath.value + "/" + sysDir + "/Job1_EffMaps"; + std::string pathMCFlat = cfgCCDBUserPath.value + "/" + sysDir + "/Job1_MCFlatMaps"; + std::string pathMCMean = cfgCCDBUserPath.value + "/" + sysDir + "/Job2_MCMean"; + std::string pathDataFlat = cfgCCDBUserPath.value + "/" + sysDir + "/Job1_DataFlatMaps"; + std::string pathDataMean = cfgCCDBUserPath.value + "/" + sysDir + "/Job2_DataMean"; + + declareCommonQA(); + if (cfgRunGetEff || cfgRunGetDataFlat) { + declarenSigHists(); + } + if (cfgRunMCMean || cfgRunMCFluc || cfgRunGetEff) { + declareMCCommonHists(); + } + if (cfgRunMCMean) { + declareMCMeanHists(); + histos.addClone("MCGen/", "MCReco/"); + histos.addClone("MCGen/", "MCRecoEffCorr/"); + } + if (cfgRunMCFluc) { + declareMCFlucHists(); + histos.addClone("MCGen/", "MCReco/"); + histos.addClone("MCGen/", "MCRecoEffCorr/"); + } + if (cfgRunGetDataFlat) { + declareDataGetFlatHists(); + } + if (cfgRunGetMCFlat) { + declareMCGetFlatHists(); + histos.addClone("MCGen/", "MCReco/"); + histos.addClone("MCGen/", "MCRecoEffCorr/"); + } + if (cfgRunDataMean) { + declareDataMeanHists(); + } + if (cfgRunDataFluc) { + declareDataFlucHists(); + } + + if (!cfgRunGetEff && (cfgEff)) { + TList* lst = ccdb->getForTimeStamp(pathEff, now); + + if (!lst) { + LOGF(fatal, "Efficiency maps required but CCDB list is null at %s!", pathEff.c_str()); + } - if (sumWkTru[isp][0][0][1] > 1.0f) { - histos.fill(HIST("MCGen/Prof_Cent_MeanpT_Pi"), cent, meanTru[isp][0][0]); - histos.fill(HIST("MCGen/Prof_Mult_MeanpT_Pi"), multPV, meanTru[isp][0][0]); + LOGF(info, "Loading Eff/Fake maps from TList for all species..."); + + auto loadEffFakeForPID = [&](PIDIdx pidType) { + std::string suffix = pidSuffix[pidType]; + std::string hEffNumName = "h3_RecoMatchedToPrimary" + suffix; + std::string hEffDenName = "h3_AllPrimary" + suffix; + std::string hFakeNumSecName = "h3_RecoUnMatchedToPrimary_Secondary" + suffix; + std::string hFakeNumFakName = "h3_RecoUnMatchedToPrimary_Fake" + suffix; + std::string hFakeNumFakName2 = "h3_RecoMatchedToPrimary_MisID" + suffix; + std::string hFakeDenName = "h3_AllReco" + suffix; + + auto* hNum = reinterpret_cast(lst->FindObject(hEffNumName.c_str())); + auto* hDen = reinterpret_cast(lst->FindObject(hEffDenName.c_str())); + + if (hNum && hDen) { + state.hEff[pidType] = reinterpret_cast(hNum->Clone(Form("hEff%s", suffix.c_str()))); + state.hEff[pidType]->SetDirectory(nullptr); + state.hEff[pidType]->Divide(hDen); + } else { + LOGF(error, "Missing CCDB objects for efficiency. Checked: %s, %s", hEffNumName.c_str(), hEffDenName.c_str()); + } + + auto* hNumS = reinterpret_cast(lst->FindObject(hFakeNumSecName.c_str())); + auto* hNumF = reinterpret_cast(lst->FindObject(hFakeNumFakName.c_str())); + auto* hNumF2 = reinterpret_cast(lst->FindObject(hFakeNumFakName2.c_str())); + auto* hDenF = reinterpret_cast(lst->FindObject(hFakeDenName.c_str())); + + if (hNumS && hNumF && hDenF) { + state.hFake[pidType] = reinterpret_cast(hNumS->Clone(Form("hFake%s", suffix.c_str()))); + state.hFake[pidType]->Add(hNumF); + // state.hFake[pidType]->Add(hNumF2); + state.hFake[pidType]->SetDirectory(nullptr); + state.hFake[pidType]->Divide(hDenF); + } else { + LOGF(error, "Missing CCDB object(s) for fakes for %s in list.", suffix.c_str()); + } + }; + + for (int i = 0; i < KNsp; ++i) { + loadEffFakeForPID(static_cast(i)); + } } - } else if (isp == numKKaon) { - histos.fill(HIST("MCGen/Prof_Cent_Nchrec_Ka"), cent, sumWkTru[isp][0][0][1]); - histos.fill(HIST("MCGen/Prof_Mult_Nchrec_Ka"), multPV, sumWkTru[isp][0][0][1]); + if (!cfgRunGetEff && (cfgFlat)) { + if (cfgRunDataMean || cfgRunDataFluc) { + LOGF(info, "Data Run: Loading flattening maps from %s", pathDataFlat.c_str()); + TList* lstDataFlat = ccdb->getForTimeStamp(pathDataFlat, now); - if (sumWkTru[isp][0][0][1] > 1.0f) { - histos.fill(HIST("MCGen/Prof_Cent_MeanpT_Ka"), cent, meanTru[isp][0][0]); - histos.fill(HIST("MCGen/Prof_Mult_MeanpT_Ka"), multPV, meanTru[isp][0][0]); - } - } else if (isp == numKProton) { - histos.fill(HIST("MCGen/Prof_Cent_Nchrec_Pr"), cent, sumWkTru[isp][0][0][1]); - histos.fill(HIST("MCGen/Prof_Mult_Nchrec_Pr"), multPV, sumWkTru[isp][0][0][1]); + if (lstDataFlat) { + for (int i = 0; i < KNsp; ++i) { + std::string suffix = pidSuffix[i]; + std::string hName; - if (sumWkTru[isp][0][0][1] > 1.0f) { - histos.fill(HIST("MCGen/Prof_Cent_MeanpT_Pr"), cent, meanTru[isp][0][0]); - histos.fill(HIST("MCGen/Prof_Mult_MeanpT_Pr"), multPV, meanTru[isp][0][0]); - } - } - } - - for (int isp = 0; isp < KNsp; ++isp) { - if (isp == numKInclusive) { - histos.fill(HIST("MCReco/Prof_Cent_Nchrec"), cent, sumWkReco[isp][0][0][1]); - histos.fill(HIST("MCReco/Prof_Mult_Nchrec"), multPV, sumWkReco[isp][0][0][1]); - if (sumWkReco[isp][0][0][1] > 1.0f) { - histos.fill(HIST("MCReco/Prof_Cent_MeanpT"), cent, meanReco[isp][0][0]); - histos.fill(HIST("MCReco/Prof_Mult_MeanpT"), multPV, meanReco[isp][0][0]); - } + if (cfgEff && cfgFlat) { + hName = "hEtaPhiRecoWtd" + suffix; + } else if (cfgEff) { + hName = "hEtaPhiRecoEffWtd" + suffix; + } else { + hName = "hEtaPhiReco" + suffix; + } + auto* hRaw = reinterpret_cast(lstDataFlat->FindObject(hName.c_str())); - } else if (isp == numKPion) { - histos.fill(HIST("MCReco/Prof_Cent_Nchrec_Pi"), cent, sumWkReco[isp][0][0][1]); - histos.fill(HIST("MCReco/Prof_Mult_Nchrec_Pi"), multPV, sumWkReco[isp][0][0][1]); + if (hRaw) { + state.hFlatWeight[i] = buildWeightMapFromRaw(hRaw, Form("hFlatWeight%s", suffix.c_str())); + } else { + LOGF(error, "Data flattening map '%s' not found.", hName.c_str()); + } + } + } else { + LOGF(error, "Could not retrieve Data Flattening TList from: %s", pathDataFlat.c_str()); + } + } - if (sumWkReco[isp][0][0][1] > 1.0f) { - histos.fill(HIST("MCReco/Prof_Cent_MeanpT_Pi"), cent, meanReco[isp][0][0]); - histos.fill(HIST("MCReco/Prof_Mult_MeanpT_Pi"), multPV, meanReco[isp][0][0]); - } + if (cfgRunMCMean || cfgRunMCFluc) { + LOGF(info, "MC Run: Loading flattening maps from %s", pathMCFlat.c_str()); + TList* lstMCFlat = ccdb->getForTimeStamp(pathMCFlat, now); + + if (lstMCFlat) { + auto loadFlatForPID = [&](PIDIdx pidType) { + std::string suffix = pidSuffix[pidType]; + std::string hFlatSrcName; + if (cfgEff && cfgFlat) { + hFlatSrcName = "MCReco/hEtaPhiRecoWtd" + suffix; + } else if (cfgEff) { + hFlatSrcName = "MCReco/hEtaPhiRecoEffWtd" + suffix; + } else { + hFlatSrcName = "MCReco/hEtaPhiReco" + suffix; + } - } else if (isp == numKKaon) { - histos.fill(HIST("MCReco/Prof_Cent_Nchrec_Ka"), cent, sumWkReco[isp][0][0][1]); - histos.fill(HIST("MCReco/Prof_Mult_Nchrec_Ka"), multPV, sumWkReco[isp][0][0][1]); + auto* hRaw = reinterpret_cast(lstMCFlat->FindObject(hFlatSrcName.c_str())); - if (sumWkReco[isp][0][0][1] > 1.0f) { - histos.fill(HIST("MCReco/Prof_Cent_MeanpT_Ka"), cent, meanReco[isp][0][0]); - histos.fill(HIST("MCReco/Prof_Mult_MeanpT_Ka"), multPV, meanReco[isp][0][0]); - } - } else if (isp == numKProton) { - histos.fill(HIST("MCReco/Prof_Cent_Nchrec_Pr"), cent, sumWkReco[isp][0][0][1]); - histos.fill(HIST("MCReco/Prof_Mult_Nchrec_Pr"), multPV, sumWkReco[isp][0][0][1]); - if (sumWkReco[isp][0][0][1] > 1.0f) { - histos.fill(HIST("MCReco/Prof_Cent_MeanpT_Pr"), cent, meanReco[isp][0][0]); - histos.fill(HIST("MCReco/Prof_Mult_MeanpT_Pr"), multPV, meanReco[isp][0][0]); - } - } + if (hRaw) { + state.hFlatWeight[pidType] = buildWeightMapFromRaw(hRaw, Form("hFlatWeight%s", suffix.c_str())); + } else { + LOGF(warning, "MC flattening source '%s' not found in list.", hFlatSrcName.c_str()); + } + }; - if (isp == numKInclusive) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_Nchrec"), cent, sumWkRecoEffCor[isp][0][0][1]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_Nchrec"), multPV, sumWkRecoEffCor[isp][0][0][1]); - if (sumWkRecoEffCor[isp][0][0][1] > 1.0f) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_MeanpT"), cent, meanRecoEffCor[isp][0][0]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_MeanpT"), multPV, meanRecoEffCor[isp][0][0]); + for (int i = 0; i < KNsp; ++i) { + loadFlatForPID(static_cast(i)); + } + } else { + LOGF(error, "Could not retrieve MC Flattening TList from: %s", pathMCFlat.c_str()); + } + } } - } else if (isp == numKPion) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_Nchrec_Pi"), cent, sumWkRecoEffCor[isp][0][0][1]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_Nchrec_Pi"), multPV, sumWkRecoEffCor[isp][0][0][1]); - if (sumWkRecoEffCor[isp][0][0][1] > 1.0f) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_MeanpT_Pi"), cent, meanRecoEffCor[isp][0][0]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_MeanpT_Pi"), multPV, meanRecoEffCor[isp][0][0]); - } + auto loadTProfile3DFromList = [&](TList* sourceList, const char* objName, TProfile3D*& target) { + if (!sourceList) + return; + auto* tp = reinterpret_cast(sourceList->FindObject(objName)); + if (tp) { + target = reinterpret_cast(tp->Clone()); + target->SetDirectory(nullptr); + LOGF(info, "Loaded %s from list", objName); + } else { + LOGF(error, "Histogram %s missing in CCDB TList", objName); + } + }; + + auto loadTProfileFromList = [&](TList* sourceList, const char* objName, TProfile*& target) { + if (!sourceList) + return; + auto* tp = reinterpret_cast(sourceList->FindObject(objName)); + if (tp) { + target = reinterpret_cast(tp->Clone()); + target->SetDirectory(nullptr); + LOGF(info, "Loaded %s from list", objName); + } else { + LOGF(error, "Histogram %s missing in CCDB TList", objName); + } + }; - } else if (isp == numKKaon) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_Nchrec_Ka"), cent, sumWkRecoEffCor[isp][0][0][1]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_Nchrec_Ka"), multPV, sumWkRecoEffCor[isp][0][0][1]); - if (sumWkRecoEffCor[isp][0][0][1] > 1.0f) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_MeanpT_Ka"), cent, meanRecoEffCor[isp][0][0]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_MeanpT_Ka"), multPV, meanRecoEffCor[isp][0][0]); - } - } else if (isp == numKProton) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_Nchrec_Pr"), cent, sumWkRecoEffCor[isp][0][0][1]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_Nchrec_Pr"), multPV, sumWkRecoEffCor[isp][0][0][1]); - if (sumWkRecoEffCor[isp][0][0][1] > 1.0f) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_MeanpT_Pr"), cent, meanRecoEffCor[isp][0][0]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_MeanpT_Pr"), multPV, meanRecoEffCor[isp][0][0]); - } - } - } - - // --- 3. Fill 1D Profiles: Gen, Reco, and EffCorr Levels --- - for (int ieta = 0; ieta < KNEta; ++ieta) { - for (int ipt = 0; ipt < KNpT; ++ipt) { - for (int isp = 0; isp < KNsp; ++isp) { - - if (isp == numKInclusive) { // Inclusive (No suffix) - // --- MCGen (Truth) --- - if (std::isfinite(meanTru[0][ieta][ipt])) { - histos.fill(HIST("MCGen/Prof_MeanpT_Cent_etabin_ptbin"), cent, ieta, ipt, meanTru[0][ieta][ipt]); - histos.fill(HIST("MCGen/Prof_MeanpT_Mult_etabin_ptbin"), col.multNTracksPV(), ieta, ipt, meanTru[0][ieta][ipt]); - } - if (std::isfinite(c2Tru[0][ieta][ipt])) { - histos.fill(HIST("MCGen/Prof_C2_Cent_etabin_ptbin"), cent, ieta, ipt, c2Tru[0][ieta][ipt]); - histos.fill(HIST("MCGen/Prof_C2_Mult_etabin_ptbin"), col.multNTracksPV(), ieta, ipt, c2Tru[0][ieta][ipt]); - } - // --- MCReco --- - if (std::isfinite(meanReco[0][ieta][ipt])) { - histos.fill(HIST("MCReco/Prof_MeanpT_Cent_etabin_ptbin"), cent, ieta, ipt, meanReco[0][ieta][ipt]); - histos.fill(HIST("MCReco/Prof_MeanpT_Mult_etabin_ptbin"), col.multNTracksPV(), ieta, ipt, meanReco[0][ieta][ipt]); - } - if (std::isfinite(c2Reco[0][ieta][ipt])) { - histos.fill(HIST("MCReco/Prof_C2_Cent_etabin_ptbin"), cent, ieta, ipt, c2Reco[0][ieta][ipt]); - histos.fill(HIST("MCReco/Prof_C2_Mult_etabin_ptbin"), col.multNTracksPV(), ieta, ipt, c2Reco[0][ieta][ipt]); - } - // --- MCRecoEffCorr --- - if (std::isfinite(meanRecoEffCor[0][ieta][ipt])) { - histos.fill(HIST("MCRecoEffCorr/Prof_MeanpT_Cent_etabin_ptbin"), cent, ieta, ipt, meanRecoEffCor[0][ieta][ipt]); - histos.fill(HIST("MCRecoEffCorr/Prof_MeanpT_Mult_etabin_ptbin"), col.multNTracksPV(), ieta, ipt, meanRecoEffCor[0][ieta][ipt]); - } - if (std::isfinite(c2RecoEffCor[0][ieta][ipt])) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2_Cent_etabin_ptbin"), cent, ieta, ipt, c2RecoEffCor[0][ieta][ipt]); - histos.fill(HIST("MCRecoEffCorr/Prof_C2_Mult_etabin_ptbin"), col.multNTracksPV(), ieta, ipt, c2RecoEffCor[0][ieta][ipt]); - } + if (cfgRunMCFluc) { + LOGF(info, "Loading MC Mean profiles from CCDB path: %s", pathMCMean.c_str()); + TList* lstMCMean = ccdb->getForTimeStamp(pathMCMean, now); - } else if (isp == numKPion) { // Pions (_Pi) - // --- MCGen (Truth) --- - if (std::isfinite(meanTru[1][ieta][ipt])) { - histos.fill(HIST("MCGen/Prof_MeanpT_Cent_etabin_ptbin_Pi"), cent, ieta, ipt, meanTru[1][ieta][ipt]); - histos.fill(HIST("MCGen/Prof_MeanpT_Mult_etabin_ptbin_Pi"), col.multNTracksPV(), ieta, ipt, meanTru[1][ieta][ipt]); - } - if (std::isfinite(c2Tru[1][ieta][ipt])) { - histos.fill(HIST("MCGen/Prof_C2_Cent_etabin_ptbin_Pi"), cent, ieta, ipt, c2Tru[1][ieta][ipt]); - histos.fill(HIST("MCGen/Prof_C2_Mult_etabin_ptbin_Pi"), col.multNTracksPV(), ieta, ipt, c2Tru[1][ieta][ipt]); - } - // --- MCReco --- - if (std::isfinite(meanReco[1][ieta][ipt])) { - histos.fill(HIST("MCReco/Prof_MeanpT_Cent_etabin_ptbin_Pi"), cent, ieta, ipt, meanReco[1][ieta][ipt]); - histos.fill(HIST("MCReco/Prof_MeanpT_Mult_etabin_ptbin_Pi"), col.multNTracksPV(), ieta, ipt, meanReco[1][ieta][ipt]); - } - if (std::isfinite(c2Reco[1][ieta][ipt])) { - histos.fill(HIST("MCReco/Prof_C2_Cent_etabin_ptbin_Pi"), cent, ieta, ipt, c2Reco[1][ieta][ipt]); - histos.fill(HIST("MCReco/Prof_C2_Mult_etabin_ptbin_Pi"), col.multNTracksPV(), ieta, ipt, c2Reco[1][ieta][ipt]); - } - // --- MCRecoEffCorr --- - if (std::isfinite(meanRecoEffCor[1][ieta][ipt])) { - histos.fill(HIST("MCRecoEffCorr/Prof_MeanpT_Cent_etabin_ptbin_Pi"), cent, ieta, ipt, meanRecoEffCor[1][ieta][ipt]); - histos.fill(HIST("MCRecoEffCorr/Prof_MeanpT_Mult_etabin_ptbin_Pi"), col.multNTracksPV(), ieta, ipt, meanRecoEffCor[1][ieta][ipt]); - } - if (std::isfinite(c2RecoEffCor[1][ieta][ipt])) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2_Cent_etabin_ptbin_Pi"), cent, ieta, ipt, c2RecoEffCor[1][ieta][ipt]); - histos.fill(HIST("MCRecoEffCorr/Prof_C2_Mult_etabin_ptbin_Pi"), col.multNTracksPV(), ieta, ipt, c2RecoEffCor[1][ieta][ipt]); - } + if (lstMCMean) { + loadTProfileFromList(lstMCMean, "pmeanFT0Amultpv", state.pmeanFT0AmultpvStep2); + loadTProfileFromList(lstMCMean, "pmeanFT0Cmultpv", state.pmeanFT0CmultpvStep2); - } else if (isp == numKKaon) { // Kaons (_Ka) - // --- MCGen (Truth) --- - if (std::isfinite(meanTru[2][ieta][ipt])) { - histos.fill(HIST("MCGen/Prof_MeanpT_Cent_etabin_ptbin_Ka"), cent, ieta, ipt, meanTru[2][ieta][ipt]); - histos.fill(HIST("MCGen/Prof_MeanpT_Mult_etabin_ptbin_Ka"), col.multNTracksPV(), ieta, ipt, meanTru[2][ieta][ipt]); - } - if (std::isfinite(c2Tru[2][ieta][ipt])) { - histos.fill(HIST("MCGen/Prof_C2_Cent_etabin_ptbin_Ka"), cent, ieta, ipt, c2Tru[2][ieta][ipt]); - histos.fill(HIST("MCGen/Prof_C2_Mult_etabin_ptbin_Ka"), col.multNTracksPV(), ieta, ipt, c2Tru[2][ieta][ipt]); - } - // --- MCReco --- - if (std::isfinite(meanReco[2][ieta][ipt])) { - histos.fill(HIST("MCReco/Prof_MeanpT_Cent_etabin_ptbin_Ka"), cent, ieta, ipt, meanReco[2][ieta][ipt]); - histos.fill(HIST("MCReco/Prof_MeanpT_Mult_etabin_ptbin_Ka"), col.multNTracksPV(), ieta, ipt, meanReco[2][ieta][ipt]); - } - if (std::isfinite(c2Reco[2][ieta][ipt])) { - histos.fill(HIST("MCReco/Prof_C2_Cent_etabin_ptbin_Ka"), cent, ieta, ipt, c2Reco[2][ieta][ipt]); - histos.fill(HIST("MCReco/Prof_C2_Mult_etabin_ptbin_Ka"), col.multNTracksPV(), ieta, ipt, c2Reco[2][ieta][ipt]); - } - // --- MCRecoEffCorr --- - if (std::isfinite(meanRecoEffCor[2][ieta][ipt])) { - histos.fill(HIST("MCRecoEffCorr/Prof_MeanpT_Cent_etabin_ptbin_Ka"), cent, ieta, ipt, meanRecoEffCor[2][ieta][ipt]); - histos.fill(HIST("MCRecoEffCorr/Prof_MeanpT_Mult_etabin_ptbin_Ka"), col.multNTracksPV(), ieta, ipt, meanRecoEffCor[2][ieta][ipt]); - } - if (std::isfinite(c2RecoEffCor[2][ieta][ipt])) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2_Cent_etabin_ptbin_Ka"), cent, ieta, ipt, c2RecoEffCor[2][ieta][ipt]); - histos.fill(HIST("MCRecoEffCorr/Prof_C2_Mult_etabin_ptbin_Ka"), col.multNTracksPV(), ieta, ipt, c2RecoEffCor[2][ieta][ipt]); - } + loadTProfile3DFromList(lstMCMean, "pmeanTru_nch_etabin_spbin", state.pmeanTruNchEtabinSpbinStep2); + loadTProfile3DFromList(lstMCMean, "pmeanReco_nch_etabin_spbin", state.pmeanRecoNchEtabinSpbinStep2); + loadTProfile3DFromList(lstMCMean, "pmeanRecoEffcorr_nch_etabin_spbin", state.pmeanRecoEffcorrNchEtabinSpbinStep2); - } else if (isp == numKProton) { // Protons (_Pr) - // --- MCGen (Truth) --- - if (std::isfinite(meanTru[3][ieta][ipt])) { - histos.fill(HIST("MCGen/Prof_MeanpT_Cent_etabin_ptbin_Pr"), cent, ieta, ipt, meanTru[3][ieta][ipt]); - histos.fill(HIST("MCGen/Prof_MeanpT_Mult_etabin_ptbin_Pr"), col.multNTracksPV(), ieta, ipt, meanTru[3][ieta][ipt]); - } - if (std::isfinite(c2Tru[3][ieta][ipt])) { - histos.fill(HIST("MCGen/Prof_C2_Cent_etabin_ptbin_Pr"), cent, ieta, ipt, c2Tru[3][ieta][ipt]); - histos.fill(HIST("MCGen/Prof_C2_Mult_etabin_ptbin_Pr"), col.multNTracksPV(), ieta, ipt, c2Tru[3][ieta][ipt]); - } - // --- MCReco --- - if (std::isfinite(meanReco[3][ieta][ipt])) { - histos.fill(HIST("MCReco/Prof_MeanpT_Cent_etabin_ptbin_Pr"), cent, ieta, ipt, meanReco[3][ieta][ipt]); - histos.fill(HIST("MCReco/Prof_MeanpT_Mult_etabin_ptbin_Pr"), col.multNTracksPV(), ieta, ipt, meanReco[3][ieta][ipt]); - } - if (std::isfinite(c2Reco[3][ieta][ipt])) { - histos.fill(HIST("MCReco/Prof_C2_Cent_etabin_ptbin_Pr"), cent, ieta, ipt, c2Reco[3][ieta][ipt]); - histos.fill(HIST("MCReco/Prof_C2_Mult_etabin_ptbin_Pr"), col.multNTracksPV(), ieta, ipt, c2Reco[3][ieta][ipt]); - } - // --- MCRecoEffCorr --- - if (std::isfinite(meanRecoEffCor[3][ieta][ipt])) { - histos.fill(HIST("MCRecoEffCorr/Prof_MeanpT_Cent_etabin_ptbin_Pr"), cent, ieta, ipt, meanRecoEffCor[3][ieta][ipt]); - histos.fill(HIST("MCRecoEffCorr/Prof_MeanpT_Mult_etabin_ptbin_Pr"), col.multNTracksPV(), ieta, ipt, meanRecoEffCor[3][ieta][ipt]); - } - if (std::isfinite(c2RecoEffCor[3][ieta][ipt])) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2_Cent_etabin_ptbin_Pr"), cent, ieta, ipt, c2RecoEffCor[3][ieta][ipt]); - histos.fill(HIST("MCRecoEffCorr/Prof_C2_Mult_etabin_ptbin_Pr"), col.multNTracksPV(), ieta, ipt, c2RecoEffCor[3][ieta][ipt]); - } + loadTProfile3DFromList(lstMCMean, "pmeanMultTru_nch_etabin_spbin", state.pmeanMultTruNchEtabinSpbinStep2); + loadTProfile3DFromList(lstMCMean, "pmeanMultReco_nch_etabin_spbin", state.pmeanMultRecoNchEtabinSpbinStep2); + loadTProfile3DFromList(lstMCMean, "pmeanMultRecoEffcorr_nch_etabin_spbin", state.pmeanMultRecoEffcorrNchEtabinSpbinStep2); + } else { + LOGF(error, "Could not retrieve TList for MC Mean from: %s", pathMCMean.c_str()); } } - } - } - - // --- 4. Symmetric Sub-Event (1D) Covariances --- - for (int ietaA = 1; ietaA <= (KNEta - 1) / 2; ++ietaA) { - int ietaC = KNEta - ietaA; - for (int ipt = 0; ipt < KNpT; ++ipt) { - for (int isp = 0; isp < KNsp; ++isp) { - float c2SubTru = p1kBarTru[isp][ietaA][ipt] * p1kBarTru[isp][ietaC][ipt]; - float c2SubReco = p1kBarReco[isp][ietaA][ipt] * p1kBarReco[isp][ietaC][ipt]; - float c2SubRecoEffCor = p1kBarRecoEffCor[isp][ietaA][ipt] * p1kBarRecoEffCor[isp][ietaC][ipt]; - - float covTru = p1kBarTruMult[isp][ietaA][ipt] * p1kBarTru[isp][ietaC][ipt]; - float covReco = p1kBarRecoMult[isp][ietaA][ipt] * p1kBarReco[isp][ietaC][ipt]; - float covRecoEffCor = p1kBarRecoEffCorMult[isp][ietaA][ipt] * p1kBarRecoEffCor[isp][ietaC][ipt]; - - if (isp == numKInclusive) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub_Cent_etabin_ptbin"), cent, ietaA, ipt, c2SubTru); - histos.fill(HIST("MCGen/Prof_C2Sub_Mult_etabin_ptbin"), col.multNTracksPV(), ietaA, ipt, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub_Cent_etabin_ptbin"), cent, ietaA, ipt, c2SubReco); - histos.fill(HIST("MCReco/Prof_C2Sub_Mult_etabin_ptbin"), col.multNTracksPV(), ietaA, ipt, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub_Cent_etabin_ptbin"), cent, ietaA, ipt, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub_Mult_etabin_ptbin"), col.multNTracksPV(), ietaA, ipt, c2SubRecoEffCor); - } - if (std::isfinite(covTru)) { - histos.fill(HIST("MCGen/Prof_Cov_Cent_etabin_ptbin"), cent, ietaA, ipt, covTru); - histos.fill(HIST("MCGen/Prof_Cov_Mult_etabin_ptbin"), col.multNTracksPV(), ietaA, ipt, covTru); - } - if (std::isfinite(covReco)) { - histos.fill(HIST("MCReco/Prof_Cov_Cent_etabin_ptbin"), cent, ietaA, ipt, covReco); - histos.fill(HIST("MCReco/Prof_Cov_Mult_etabin_ptbin"), col.multNTracksPV(), ietaA, ipt, covReco); - } - if (std::isfinite(covRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cov_Cent_etabin_ptbin"), cent, ietaA, ipt, covRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_Cov_Mult_etabin_ptbin"), col.multNTracksPV(), ietaA, ipt, covRecoEffCor); - } - } else if (isp == numKPion) { // Pion - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub_Cent_etabin_ptbin_Pi"), cent, ietaA, ipt, c2SubTru); - histos.fill(HIST("MCGen/Prof_C2Sub_Mult_etabin_ptbin_Pi"), col.multNTracksPV(), ietaA, ipt, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub_Cent_etabin_ptbin_Pi"), cent, ietaA, ipt, c2SubReco); - histos.fill(HIST("MCReco/Prof_C2Sub_Mult_etabin_ptbin_Pi"), col.multNTracksPV(), ietaA, ipt, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub_Cent_etabin_ptbin_Pi"), cent, ietaA, ipt, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub_Mult_etabin_ptbin_Pi"), col.multNTracksPV(), ietaA, ipt, c2SubRecoEffCor); - } - if (std::isfinite(covTru)) { - histos.fill(HIST("MCGen/Prof_Cov_Cent_etabin_ptbin_Pi"), cent, ietaA, ipt, covTru); - histos.fill(HIST("MCGen/Prof_Cov_Mult_etabin_ptbin_Pi"), col.multNTracksPV(), ietaA, ipt, covTru); - } - if (std::isfinite(covReco)) { - histos.fill(HIST("MCReco/Prof_Cov_Cent_etabin_ptbin_Pi"), cent, ietaA, ipt, covReco); - histos.fill(HIST("MCReco/Prof_Cov_Mult_etabin_ptbin_Pi"), col.multNTracksPV(), ietaA, ipt, covReco); - } - if (std::isfinite(covRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cov_Cent_etabin_ptbin_Pi"), cent, ietaA, ipt, covRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_Cov_Mult_etabin_ptbin_Pi"), col.multNTracksPV(), ietaA, ipt, covRecoEffCor); - } + if (cfgRunDataFluc) { + LOGF(info, "Loading Data Mean profiles from CCDB path: %s", pathDataMean.c_str()); + TList* lstDataMean = ccdb->getForTimeStamp(pathDataMean, now); - } else if (isp == numKKaon) { // Kaon - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub_Cent_etabin_ptbin_Ka"), cent, ietaA, ipt, c2SubTru); - histos.fill(HIST("MCGen/Prof_C2Sub_Mult_etabin_ptbin_Ka"), col.multNTracksPV(), ietaA, ipt, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub_Cent_etabin_ptbin_Ka"), cent, ietaA, ipt, c2SubReco); - histos.fill(HIST("MCReco/Prof_C2Sub_Mult_etabin_ptbin_Ka"), col.multNTracksPV(), ietaA, ipt, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub_Cent_etabin_ptbin_Ka"), cent, ietaA, ipt, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub_Mult_etabin_ptbin_Ka"), col.multNTracksPV(), ietaA, ipt, c2SubRecoEffCor); - } - if (std::isfinite(covTru)) { - histos.fill(HIST("MCGen/Prof_Cov_Cent_etabin_ptbin_Ka"), cent, ietaA, ipt, covTru); - histos.fill(HIST("MCGen/Prof_Cov_Mult_etabin_ptbin_Ka"), col.multNTracksPV(), ietaA, ipt, covTru); - } - if (std::isfinite(covReco)) { - histos.fill(HIST("MCReco/Prof_Cov_Cent_etabin_ptbin_Ka"), cent, ietaA, ipt, covReco); - histos.fill(HIST("MCReco/Prof_Cov_Mult_etabin_ptbin_Ka"), col.multNTracksPV(), ietaA, ipt, covReco); - } - if (std::isfinite(covRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cov_Cent_etabin_ptbin_Ka"), cent, ietaA, ipt, covRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_Cov_Mult_etabin_ptbin_Ka"), col.multNTracksPV(), ietaA, ipt, covRecoEffCor); - } - } else if (isp == numKProton) { // Proton - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub_Cent_etabin_ptbin_Pr"), cent, ietaA, ipt, c2SubTru); - histos.fill(HIST("MCGen/Prof_C2Sub_Mult_etabin_ptbin_Pr"), col.multNTracksPV(), ietaA, ipt, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub_Cent_etabin_ptbin_Pr"), cent, ietaA, ipt, c2SubReco); - histos.fill(HIST("MCReco/Prof_C2Sub_Mult_etabin_ptbin_Pr"), col.multNTracksPV(), ietaA, ipt, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub_Cent_etabin_ptbin_Pr"), cent, ietaA, ipt, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub_Mult_etabin_ptbin_Pr"), col.multNTracksPV(), ietaA, ipt, c2SubRecoEffCor); - } - if (std::isfinite(covTru)) { - histos.fill(HIST("MCGen/Prof_Cov_Cent_etabin_ptbin_Pr"), cent, ietaA, ipt, covTru); - histos.fill(HIST("MCGen/Prof_Cov_Mult_etabin_ptbin_Pr"), col.multNTracksPV(), ietaA, ipt, covTru); - } - if (std::isfinite(covReco)) { - histos.fill(HIST("MCReco/Prof_Cov_Cent_etabin_ptbin_Pr"), cent, ietaA, ipt, covReco); - histos.fill(HIST("MCReco/Prof_Cov_Mult_etabin_ptbin_Pr"), col.multNTracksPV(), ietaA, ipt, covReco); - } - if (std::isfinite(covRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cov_Cent_etabin_ptbin_Pr"), cent, ietaA, ipt, covRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_Cov_Mult_etabin_ptbin_Pr"), col.multNTracksPV(), ietaA, ipt, covRecoEffCor); - } + if (lstDataMean) { + loadTProfileFromList(lstDataMean, "pmeanFT0Amultpv", state.pmeanFT0AmultpvStep2); + loadTProfileFromList(lstDataMean, "pmeanFT0Cmultpv", state.pmeanFT0CmultpvStep2); + + loadTProfile3DFromList(lstDataMean, "pmean_nch_etabin_spbin", state.pmeanNchEtabinSpbinStep2); + loadTProfile3DFromList(lstDataMean, "pmeanMult_nch_etabin_spbin", state.pmeanMultNchEtabinSpbinStep2); + } else { + LOGF(error, "Could not retrieve TList for Data Mean from: %s", pathDataMean.c_str()); } } + LOGF(info, "CCDB initialization complete for RadialFlowDecorr."); } - } - // --- 5. Full 2D Covariances & GapSum2D Profiles --- - for (int ietaA = 1; ietaA < KNEta; ++ietaA) { - for (int ietaB = 1; ietaB < KNEta; ++ietaB) { - - // Gap and Sum calculations - float etaValA = (etaLw[ietaA] + etaUp[ietaA]) / 2.0f; - float etaValB = (etaLw[ietaB] + etaUp[ietaB]) / 2.0f; - float gap = etaValA - etaValB; - float sum = (etaValA + etaValB) / 2.0f; + void processGetEffHists(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/, aod::McParticles const& mcParticles) + { + for (const auto& mcCollision : mcColl) { + auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); + if (colSlice.size() != 1) continue; + + for (const auto& col : colSlice) { + if (!col.has_mcCollision() || !isEventSelected(col)) continue; + + auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); + auto partSlice = mcParticles.sliceBy(partPerMcCollision, mcCollision.globalIndex()); + if (trackSlice.size() < 1 || partSlice.size() < 1) continue; + + float cent = getCentrality(col); + if (cent > KCentMax) continue; + float multPV = col.multNTracksPV(); + float vz = col.posZ(); + + for (const auto& particle : partSlice) { + if (!isParticleSelected(particle) || !particle.isPhysicalPrimary()) continue; + + const int pdg = particle.pdgCode(); + const int absPdg = std::abs(pdg); + float pt = particle.pt(), eta = particle.eta(); + + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + pdg == -KPiPlus, // kPiMinusIdx + pdg == KPiPlus, // kPiPlusIdx + absPdg == KPiPlus, // kPiAllIdx + pdg == -KKPlus, // kKaMinusIdx + pdg == KKPlus, // kKaPlusIdx + absPdg == KKPlus, // kKaAllIdx + pdg == -KProton, // kAntiPrIdx + pdg == KProton, // kPrIdx + absPdg == KProton // kAllPrIdx + }; + + histos.fill(HIST("h3_AllPrimary"), multPV, pt, eta); + if (isSpecies[kPiMinusIdx]) histos.fill(HIST("h3_AllPrimary_PiMinus"), multPV, pt, eta); + else if (isSpecies[kPiPlusIdx]) histos.fill(HIST("h3_AllPrimary_PiPlus"), multPV, pt, eta); + if (isSpecies[kPiAllIdx]) histos.fill(HIST("h3_AllPrimary_PiAll"), multPV, pt, eta); + + if (isSpecies[kKaMinusIdx]) histos.fill(HIST("h3_AllPrimary_KaMinus"), multPV, pt, eta); + else if (isSpecies[kKaPlusIdx]) histos.fill(HIST("h3_AllPrimary_KaPlus"), multPV, pt, eta); + if (isSpecies[kKaAllIdx]) histos.fill(HIST("h3_AllPrimary_KaAll"), multPV, pt, eta); + + if (isSpecies[kAntiPrIdx]) histos.fill(HIST("h3_AllPrimary_AntiPr"), multPV, pt, eta); + else if (isSpecies[kPrIdx]) histos.fill(HIST("h3_AllPrimary_Pr"), multPV, pt, eta); + if (isSpecies[kAllPrIdx]) histos.fill(HIST("h3_AllPrimary_AllPr"), multPV, pt, eta); + } + + histos.fill(HIST("hZvtx_after_sel"), col.posZ()); + histos.fill(HIST("hCentrality"), cent); + + histos.fill(HIST("Hist2D_globalTracks_PVTracks"), multPV, trackSlice.size()); + histos.fill(HIST("Hist2D_cent_nch"), trackSlice.size(), cent); + + for (const auto& track : trackSlice) { + if (!isTrackSelected(track)) continue; + + float pt = track.pt(), eta = track.eta(); + auto sign = track.sign(); + if (sign > 0) { + // PiPlus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiPlus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiPlus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + // KaPlus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaPlus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaPlus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + // Pr + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_Pr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_Pr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + } else if (sign < 0) { + // PiMinus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiMinus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiMinus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + // KaMinus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaMinus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaMinus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + // AntiPr + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_AntiPr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_AntiPr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + } - for (int ipt = 0; ipt < KNpT; ++ipt) { - for (int isp = 0; isp < KNsp; ++isp) { + bool isPi = selectionPion(track); + bool isKa = selectionKaon(track); + bool isPr = selectionProton(track); + + bool isSpecies[KNsp] = { + true, + isPi && sign < 0, isPi && sign > 0, isPi, + isKa && sign < 0, isKa && sign > 0, isKa, + isPr && sign < 0, isPr && sign > 0, isPr + }; + + if (isSpecies[kPiPlusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiPlus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiPlus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + } else if (isSpecies[kPiMinusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiMinus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiMinus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + } - float c2SubTru = p1kBarTru[isp][ietaA][ipt] * p1kBarTru[isp][ietaB][ipt]; - float c2SubReco = p1kBarReco[isp][ietaA][ipt] * p1kBarReco[isp][ietaB][ipt]; - float c2SubRecoEffCor = p1kBarRecoEffCor[isp][ietaA][ipt] * p1kBarRecoEffCor[isp][ietaB][ipt]; + if (isSpecies[kKaPlusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaPlus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaPlus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + } else if (isSpecies[kKaMinusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaMinus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaMinus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + } - float covTru = p1kBarTruMult[isp][ietaA][ipt] * p1kBarTru[isp][ietaB][ipt]; - float covReco = p1kBarRecoMult[isp][ietaA][ipt] * p1kBarReco[isp][ietaB][ipt]; - float covRecoEffCor = p1kBarRecoEffCorMult[isp][ietaA][ipt] * p1kBarRecoEffCor[isp][ietaB][ipt]; + if (isSpecies[kPrIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_Pr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_Pr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + } else if (isSpecies[kAntiPrIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_AntiPr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_AntiPr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + } - if (isp == numKInclusive) { // Inclusive - if (ipt == 0) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_ipt0_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_ipt0_GapSum2D"), cent, gap, sum, c2SubTru); + for (int isp = 0; isp < KNsp; ++isp) { + if (!isSpecies[isp]) continue; + + if (isp == kInclusiveIdx) { + histos.fill(HIST("h3_AllReco"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + int mcPdg = std::abs(mcP.pdgCode()); + if (mcPdg == KPiPlus || mcPdg == KKPlus || mcPdg == KProton) { + histos.fill(HIST("ptResolution"), mcP.pt(), (pt - mcP.pt()) / mcP.pt()); + histos.fill(HIST("etaResolution"), mcP.eta(), eta - mcP.eta()); + histos.fill(HIST("etaTruthReco"), mcP.eta(), eta); + histos.fill(HIST("vzResolution"), mcP.vz(), (vz - mcP.vz()) / mcP.vz()); + histos.fill(HIST("TruthTracKVz"), mcP.vz(), vz); + histos.fill(HIST("h3_RecoMatchedToPrimary"), multPV, mcP.pt(), mcP.eta()); + } else { + // Misidentified! Reconstructed track, but true particle is not pi/K/P + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake"), multPV, pt, eta); + } } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_ipt0_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_ipt0_GapSum2D"), cent, gap, sum, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_ipt0_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_ipt0_GapSum2D"), cent, gap, sum, c2SubRecoEffCor); - } - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_ipt0_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_ipt0_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_ipt0_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covRecoEffCor); - } else if (ipt == KNpT - 2) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_ipt1_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_ipt1_GapSum2D"), cent, gap, sum, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_ipt1_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_ipt1_GapSum2D"), cent, gap, sum, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_ipt1_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_ipt1_GapSum2D"), cent, gap, sum, c2SubRecoEffCor); - } - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_ipt1_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_ipt1_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_ipt1_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covRecoEffCor); - } else if (ipt == KNpT - 1) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_ipt2_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_ipt2_GapSum2D"), cent, gap, sum, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_ipt2_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_ipt2_GapSum2D"), cent, gap, sum, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_ipt2_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_ipt2_GapSum2D"), cent, gap, sum, c2SubRecoEffCor); - } - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_ipt2_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_ipt2_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_ipt2_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covRecoEffCor); - } - } else if (isp == numKPion) { // Pion - if (ipt == 0) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_ipt0_C2Sub2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_ipt0_GapSum2D_Pi"), cent, gap, sum, c2SubTru); + else if (isp == kPiMinusIdx) { + histos.fill(HIST("h3_AllReco_PiMinus"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (mcP.pdgCode() == -KPiPlus) { + histos.fill(HIST("h3_RecoMatchedToPrimary_PiMinus"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_PiMinus"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_PiMinus"), multPV, pt, eta); + } + } else { // No MC + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_PiMinus"), multPV, pt, eta); + } } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_ipt0_C2Sub2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_ipt0_GapSum2D_Pi"), cent, gap, sum, c2SubReco); + + else if (isp == kPiPlusIdx) { + histos.fill(HIST("h3_AllReco_PiPlus"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (mcP.pdgCode() == KPiPlus) { + histos.fill(HIST("h3_RecoMatchedToPrimary_PiPlus"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_PiPlus"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_PiPlus"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_PiPlus"), multPV, pt, eta); + } } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_ipt0_C2Sub2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_ipt0_GapSum2D_Pi"), cent, gap, sum, c2SubRecoEffCor); + + else if (isp == kPiAllIdx) { + histos.fill(HIST("h3_AllReco_PiAll"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (std::abs(mcP.pdgCode()) == KPiPlus) { + histos.fill(HIST("h3_RecoMatchedToPrimary_PiAll"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_PiAll"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_PiAll"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_PiAll"), multPV, pt, eta); + } } - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_ipt0_Cov2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_ipt0_Cov2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_ipt0_Cov2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, covRecoEffCor); - } else if (ipt == KNpT - 2) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_ipt1_C2Sub2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_ipt1_GapSum2D_Pi"), cent, gap, sum, c2SubTru); + + else if (isp == kKaMinusIdx) { + histos.fill(HIST("h3_AllReco_KaMinus"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (mcP.pdgCode() == -KKPlus) { + histos.fill(HIST("h3_RecoMatchedToPrimary_KaMinus"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_KaMinus"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_KaMinus"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_KaMinus"), multPV, pt, eta); + } } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_ipt1_C2Sub2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_ipt1_GapSum2D_Pi"), cent, gap, sum, c2SubReco); + + else if (isp == kKaPlusIdx) { + histos.fill(HIST("h3_AllReco_KaPlus"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (mcP.pdgCode() == KKPlus) { + histos.fill(HIST("h3_RecoMatchedToPrimary_KaPlus"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_KaPlus"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_KaPlus"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_KaPlus"), multPV, pt, eta); + } } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_ipt1_C2Sub2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_ipt1_GapSum2D_Pi"), cent, gap, sum, c2SubRecoEffCor); + + else if (isp == kKaAllIdx) { + histos.fill(HIST("h3_AllReco_KaAll"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (std::abs(mcP.pdgCode()) == KKPlus) { + histos.fill(HIST("h3_RecoMatchedToPrimary_KaAll"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_KaAll"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_KaAll"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_KaAll"), multPV, pt, eta); + } } - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_ipt1_Cov2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_ipt1_Cov2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_ipt1_Cov2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, covRecoEffCor); - } else if (ipt == KNpT - 1) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_ipt2_C2Sub2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_ipt2_GapSum2D_Pi"), cent, gap, sum, c2SubTru); + + else if (isp == kAntiPrIdx) { + histos.fill(HIST("h3_AllReco_AntiPr"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (mcP.pdgCode() == -KProton) { + histos.fill(HIST("h3_RecoMatchedToPrimary_AntiPr"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_AntiPr"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_AntiPr"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_AntiPr"), multPV, pt, eta); + } } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_ipt2_C2Sub2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_ipt2_GapSum2D_Pi"), cent, gap, sum, c2SubReco); + + else if (isp == kPrIdx) { + histos.fill(HIST("h3_AllReco_Pr"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (mcP.pdgCode() == KProton) { + histos.fill(HIST("h3_RecoMatchedToPrimary_Pr"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_Pr"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_Pr"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_Pr"), multPV, pt, eta); + } } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_ipt2_C2Sub2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_ipt2_GapSum2D_Pi"), cent, gap, sum, c2SubRecoEffCor); + + else if (isp == kAllPrIdx) { + histos.fill(HIST("h3_AllReco_AllPr"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (std::abs(mcP.pdgCode()) == KProton) { + histos.fill(HIST("h3_RecoMatchedToPrimary_AllPr"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_AllPr"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_AllPr"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_AllPr"), multPV, pt, eta); + } } - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_ipt2_Cov2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_ipt2_Cov2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_ipt2_Cov2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, covRecoEffCor); } - } else if (isp == numKKaon) { // Kaon - if (ipt == 0) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_ipt0_C2Sub2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_ipt0_GapSum2D_Ka"), cent, gap, sum, c2SubTru); + } + } + } + } + PROCESS_SWITCH(RadialFlowDecorr, processGetEffHists, "process MC to calculate EffWeights", cfgRunGetEff); + + void processMCFlat(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/) + { + for (const auto& mcCollision : mcColl) { + auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); + if (colSlice.size() != 1) continue; + + for (const auto& col : colSlice) { + if (!col.has_mcCollision() || !isEventSelected(col)) continue; + + float cent = getCentrality(col); + if (cent > KCentMax) continue; + + auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); + if (trackSlice.size() < 1) continue; + + float multPV = col.multNTracksPV(); + float vz = col.posZ(); + + histos.fill(HIST("hZvtx_after_sel"), col.posZ()); + histos.fill(HIST("hCentrality"), cent); + + histos.fill(HIST("Hist2D_globalTracks_PVTracks"), col.multNTracksPV(), trackSlice.size()); + histos.fill(HIST("Hist2D_cent_nch"), trackSlice.size(), cent); + for (const auto& track : trackSlice) { + if (!isTrackSelected(track)) continue; + + float pt = track.pt(), eta = track.eta(), phi = track.phi(); + auto sign = track.sign(); + bool isPi = selectionPion(track); + bool isKa = selectionKaon(track); + bool isPr = selectionProton(track); + + bool isSpecies[KNsp] = { + true, + isPi && sign < 0, isPi && sign > 0, isPi, + isKa && sign < 0, isKa && sign > 0, isKa, + isPr && sign < 0, isPr && sign > 0, isPr + }; + + for (int isp = 0; isp < KNsp; ++isp) { + if (!isSpecies[isp]) continue; + + float eff = getEfficiency(multPV, pt, eta, static_cast(isp), 0, cfgEff); + float fake = getEfficiency(multPV, pt, eta, static_cast(isp), 1, cfgEff); + float w = (eff > KFloatEpsilon) ? (1.0f - fake) / eff : 0.0f; + + if (std::isfinite(w) && w > 0.f) { + if (isp == kInclusiveIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiMinusIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_PiMinus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_PiMinus"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_PiMinus"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiPlusIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_PiPlus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_PiPlus"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_PiPlus"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiAllIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_PiAll"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_PiAll"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_PiAll"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaMinusIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_KaMinus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_KaMinus"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_KaMinus"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaPlusIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_KaPlus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_KaPlus"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_KaPlus"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaAllIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_KaAll"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_KaAll"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_KaAll"), vz, sign, pt, eta, phi, w); + } else if (isp == kAntiPrIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); + } else if (isp == kPrIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_Pr"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); + } else if (isp == kAllPrIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); + } } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_ipt0_C2Sub2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_ipt0_GapSum2D_Ka"), cent, gap, sum, c2SubReco); + } + } + } + } + } + PROCESS_SWITCH(RadialFlowDecorr, processMCFlat, "process MC to calculate FlatWeights", cfgRunGetMCFlat); + + void processMCMean(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/, aod::FT0s const&, aod::McParticles const& mcParticles) + { + double sumWiTruth[KNsp][KNEta]{}, sumWiptiTruth[KNsp][KNEta]{}; + double sumWiReco[KNsp][KNEta]{}, sumWiptiReco[KNsp][KNEta]{}; + double sumWiRecoEffCorr[KNsp][KNEta]{}, sumWiptiRecoEffCorr[KNsp][KNEta]{}; + + for (const auto& mcCollision : mcColl) { + auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); + if (colSlice.size() != 1) + continue; + + for (const auto& col : colSlice) { + if (!col.has_mcCollision() || !isEventSelected(col)) + continue; + + auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); + auto partSlice = mcParticles.sliceBy(partPerMcCollision, mcCollision.globalIndex()); + if (trackSlice.size() < 1 || partSlice.size() < 1) + continue; + + float cent = getCentrality(col); + if (cent > KCentMax) + continue; + float multPV = col.multNTracksPV(); + float vz = col.posZ(); + + memset(sumWiTruth, 0, sizeof(sumWiTruth)); + memset(sumWiptiTruth, 0, sizeof(sumWiptiTruth)); + memset(sumWiReco, 0, sizeof(sumWiReco)); + memset(sumWiptiReco, 0, sizeof(sumWiptiReco)); + memset(sumWiRecoEffCorr, 0, sizeof(sumWiRecoEffCorr)); + memset(sumWiptiRecoEffCorr, 0, sizeof(sumWiptiRecoEffCorr)); + + for (const auto& particle : partSlice) { + if (!isParticleSelected(particle) || !particle.isPhysicalPrimary()) + continue; + float pt = particle.pt(), eta = particle.eta(); + if (pt <= cfgPtMin || pt > cfgPtMax) + continue; + int pdgCode = particle.pdgCode(); + int absPdg = std::abs(pdgCode); + + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + pdgCode == -KPiPlus, // kPiMinusIdx + pdgCode == KPiPlus, // kPiPlusIdx + absPdg == KPiPlus, // kPiAllIdx + pdgCode == -KKPlus, // kKaMinusIdx + pdgCode == KKPlus, // kKaPlusIdx + absPdg == KKPlus, // kKaAllIdx + pdgCode == -KProton, // kAntiPrIdx + pdgCode == KProton, // kPrIdx + absPdg == KProton // kAllPrIdx + }; + + for (int ieta = 0; ieta < KNEta; ++ieta) { + if (eta <= etaLw[ieta] || eta > etaUp[ieta]) + continue; + + for (int isp = 0; isp < KNsp; ++isp) { + if (isSpecies[isp]) { + sumWiTruth[isp][ieta]++; + sumWiptiTruth[isp][ieta] += pt; + } } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_ipt0_C2Sub2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_ipt0_GapSum2D_Ka"), cent, gap, sum, c2SubRecoEffCor); + } + } + + for (int isp = 0; isp < KNsp; ++isp) { + histos.fill(HIST("MCGen/Prof_Cent_Nsp_Nchrec"), cent, isp, sumWiTruth[isp][0]); + histos.fill(HIST("MCGen/Prof_Mult_Nsp_Nchrec"), multPV, isp, sumWiTruth[isp][0]); + if (sumWiTruth[isp][0] > 1.0f) { + histos.fill(HIST("MCGen/Prof_Cent_Nsp_MeanpT"), cent, isp, sumWiptiTruth[isp][0] / sumWiTruth[isp][0]); + histos.fill(HIST("MCGen/Prof_Mult_Nsp_MeanpT"), multPV, isp, sumWiptiTruth[isp][0] / sumWiTruth[isp][0]); + } + } + + histos.fill(HIST("hZvtx_after_sel"), col.posZ()); + histos.fill(HIST("hCentrality"), cent); + + histos.fill(HIST("Hist2D_globalTracks_PVTracks"), col.multNTracksPV(), trackSlice.size()); + histos.fill(HIST("Hist2D_cent_nch"), trackSlice.size(), cent); + + for (const auto& track : trackSlice) { + if (!isTrackSelected(track)) + continue; + float pt = track.pt(), eta = track.eta(), phi = track.phi(); + if (pt <= cfgPtMin || pt > cfgPtMax) + continue; + auto sign = track.sign(); + bool isPi = selectionPion(track); + bool isKa = selectionKaon(track); + bool isPr = selectionProton(track); + + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + isPi && sign < 0, // kPiMinusIdx + isPi && sign > 0, // kPiPlusIdx + isPi, // kPiAllIdx + isKa && sign < 0, // kKaMinusIdx + isKa && sign > 0, // kKaPlusIdx + isKa, // kKaAllIdx + isPr && sign < 0, // kAntiPrIdx (Negative) + isPr && sign > 0, // kPrIdx (Positive) + isPr // kAllPrIdx + }; + + for (int isp = 0; isp < KNsp; ++isp) { + if (!isSpecies[isp]) + continue; + float eff = getEfficiency(multPV, pt, eta, static_cast(isp), 0, cfgEff); + float fake = getEfficiency(multPV, pt, eta, static_cast(isp), 1, cfgEff); + float flatW = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); + float w = flatW * (1.0 - fake) / eff; + if (!std::isfinite(w) || w <= 0.f || eff <= KFloatEpsilon) + continue; + + for (int ieta = 0; ieta < KNEta; ++ieta) { + if (eta <= etaLw[ieta] || eta > etaUp[ieta]) + continue; + sumWiReco[isp][ieta]++; + sumWiptiReco[isp][ieta] += pt; + sumWiRecoEffCorr[isp][ieta] += w; + sumWiptiRecoEffCorr[isp][ieta] += w * pt; } - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_ipt0_Cov2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_ipt0_Cov2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_ipt0_Cov2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, covRecoEffCor); - } else if (ipt == KNpT - 2) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_ipt1_C2Sub2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_ipt1_GapSum2D_Ka"), cent, gap, sum, c2SubTru); + + if (isp == kInclusiveIdx) { + histos.fill(HIST("Eff_cent"), cent, eff); + histos.fill(HIST("Fake_cent"), cent, fake); + histos.fill(HIST("wgt_cent"), cent, w); + + histos.fill(HIST("Eff_Ntrk"), multPV, eff); + histos.fill(HIST("Fake_Ntrk"), multPV, fake); + histos.fill(HIST("wgt_Ntrk"), multPV, w); + + histos.fill(HIST("Eff_pT"), pt, eff); + histos.fill(HIST("Fake_pT"), pt, fake); + histos.fill(HIST("wgt_pT"), pt, w); + + histos.fill(HIST("Eff_eta"), eta, eff); + histos.fill(HIST("Fake_eta"), eta, fake); + histos.fill(HIST("wgt_eta"), eta, w); } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_ipt1_C2Sub2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_ipt1_GapSum2D_Ka"), cent, gap, sum, c2SubReco); + + if (isp == kInclusiveIdx) { + histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPiMinusIdx) { + histos.fill(HIST("hEtaPhiReco_PiMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_PiMinus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiMinus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPiPlusIdx) { + histos.fill(HIST("hEtaPhiReco_PiPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_PiPlus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiPlus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPiAllIdx) { + histos.fill(HIST("hEtaPhiReco_PiAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_PiAll"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiAll"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kKaMinusIdx) { + histos.fill(HIST("hEtaPhiReco_KaMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_KaMinus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaMinus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kKaPlusIdx) { + histos.fill(HIST("hEtaPhiReco_KaPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_KaPlus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaPlus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kKaAllIdx) { + histos.fill(HIST("hEtaPhiReco_KaAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_KaAll"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaAll"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPrIdx) { + histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kAntiPrIdx) { + histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kAllPrIdx) { + histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_ipt1_C2Sub2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_ipt1_GapSum2D_Ka"), cent, gap, sum, c2SubRecoEffCor); + } + } + + for (int isp = 0; isp < KNsp; ++isp) { + histos.fill(HIST("MCReco/Prof_Cent_Nsp_Nchrec"), cent, isp, sumWiReco[isp][0]); + histos.fill(HIST("MCReco/Prof_Mult_Nsp_Nchrec"), multPV, isp, sumWiReco[isp][0]); + + histos.fill(HIST("MCRecoEffCorr/Prof_Cent_Nsp_Nchrec"), cent, isp, sumWiRecoEffCorr[isp][0]); + histos.fill(HIST("MCRecoEffCorr/Prof_Mult_Nsp_Nchrec"), multPV, isp, sumWiRecoEffCorr[isp][0]); + + if (sumWiReco[isp][0] > 1.0f) { + histos.fill(HIST("MCReco/Prof_Cent_Nsp_MeanpT"), cent, isp, sumWiptiReco[isp][0] / sumWiReco[isp][0]); + histos.fill(HIST("MCReco/Prof_Mult_Nsp_MeanpT"), multPV, isp, sumWiptiReco[isp][0] / sumWiReco[isp][0]); + } + if (sumWiRecoEffCorr[isp][0] > 1.0f) { + histos.fill(HIST("MCRecoEffCorr/Prof_Cent_Nsp_MeanpT"), cent, isp, sumWiptiRecoEffCorr[isp][0] / sumWiRecoEffCorr[isp][0]); + histos.fill(HIST("MCRecoEffCorr/Prof_Mult_Nsp_MeanpT"), multPV, isp, sumWiptiRecoEffCorr[isp][0] / sumWiRecoEffCorr[isp][0]); + } + } + + for (int ietaA = 0; ietaA < KNEta; ++ietaA) { + for (int ietaC = 0; ietaC < KNEta; ++ietaC) { + for (int isp = 0; isp < KNsp; ++isp) { + float nTruAB = sumWiTruth[isp][ietaA] + sumWiTruth[isp][ietaC]; + float nRecoAB = sumWiReco[isp][ietaA] + sumWiReco[isp][ietaC]; + float nCorrAB = sumWiRecoEffCorr[isp][ietaA] + sumWiRecoEffCorr[isp][ietaC]; + + float mptsubTru = (sumWiptiTruth[isp][ietaA] + sumWiptiTruth[isp][ietaC]) / nTruAB; + float mptsubReco = (sumWiptiReco[isp][ietaA] + sumWiptiReco[isp][ietaC]) / nRecoAB; + float mptsubRecoEffCorr = (sumWiptiRecoEffCorr[isp][ietaA] + sumWiptiRecoEffCorr[isp][ietaC]) / nCorrAB; + + if (nTruAB > 0) { + if (isp == kInclusiveIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kPiMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_PiMinus"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kPiPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_PiPlus"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kPiAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_PiAll"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kKaMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_KaMinus"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kKaPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_KaPlus"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kKaAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_KaAll"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_Pr"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kAntiPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_AntiPr"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kAllPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_AllPr"), cent, ietaA, ietaC, mptsubTru); + } + + if (nRecoAB > 0) { + if (isp == kInclusiveIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kPiMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_PiMinus"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kPiPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_PiPlus"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kPiAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_PiAll"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kKaMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_KaMinus"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kKaPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_KaPlus"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kKaAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_KaAll"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_Pr"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kAntiPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_AntiPr"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kAllPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_AllPr"), cent, ietaA, ietaC, mptsubReco); + } + + if (nCorrAB > 0) { + if (isp == kInclusiveIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kPiMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_PiMinus"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kPiPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_PiPlus"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kPiAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_PiAll"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kKaMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_KaMinus"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kKaPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_KaPlus"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kKaAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_KaAll"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_Pr"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kAntiPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_AntiPr"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kAllPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_AllPr"), cent, ietaA, ietaC, mptsubRecoEffCorr); + } } - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_ipt1_Cov2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_ipt1_Cov2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_ipt1_Cov2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, covRecoEffCor); - } else if (ipt == KNpT - 1) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_ipt2_C2Sub2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_ipt2_GapSum2D_Ka"), cent, gap, sum, c2SubTru); + } + + for (int isp = 0; isp < KNsp; ++isp) { + if (sumWiTruth[isp][ietaA] > 0) { + float val = sumWiptiTruth[isp][ietaA] / sumWiTruth[isp][ietaA]; + histos.fill(HIST("pmeanTru_nch_etabin_spbin"), multPV, ietaA, isp, val); + histos.fill(HIST("pmeanMultTru_nch_etabin_spbin"), multPV, ietaA, isp, sumWiTruth[isp][ietaA]); } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_ipt2_C2Sub2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_ipt2_GapSum2D_Ka"), cent, gap, sum, c2SubReco); + if (sumWiReco[isp][ietaA] > 0) { + float val = sumWiptiReco[isp][ietaA] / sumWiReco[isp][ietaA]; + histos.fill(HIST("pmeanReco_nch_etabin_spbin"), multPV, ietaA, isp, val); + histos.fill(HIST("pmeanMultReco_nch_etabin_spbin"), multPV, ietaA, isp, sumWiReco[isp][ietaA]); } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_ipt2_C2Sub2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_ipt2_GapSum2D_Ka"), cent, gap, sum, c2SubRecoEffCor); + if (sumWiRecoEffCorr[isp][ietaA] > 0) { + float val = sumWiptiRecoEffCorr[isp][ietaA] / sumWiRecoEffCorr[isp][ietaA]; + histos.fill(HIST("pmeanRecoEffcorr_nch_etabin_spbin"), multPV, ietaA, isp, val); + histos.fill(HIST("pmeanMultRecoEffcorr_nch_etabin_spbin"), multPV, ietaA, isp, sumWiRecoEffCorr[isp][ietaA]); } - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_ipt2_Cov2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_ipt2_Cov2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_ipt2_Cov2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, covRecoEffCor); } - } else if (isp == numKProton) { // Proton - if (ipt == 0) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_ipt0_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_ipt0_GapSum2D_Pr"), cent, gap, sum, c2SubTru); + } // end ietaA + + double amplFT0A = 0, amplFT0C = 0; + if (col.has_foundFT0()) { + const auto& ft0 = col.foundFT0(); + for (std::size_t iCh = 0; iCh < ft0.channelA().size(); iCh++) { + auto chanelid = ft0.channelA()[iCh]; + float ampl = ft0.amplitudeA()[iCh]; + amplFT0A += ampl; + auto eta = getEtaFT0(chanelid, 0); + histos.fill(HIST("pmean_cent_id_eta_FT0"), cent, chanelid, eta, ampl); + histos.fill(HIST("h3_cent_id_eta_FT0"), cent, chanelid, eta, ampl); + } + for (std::size_t iCh = 0; iCh < ft0.channelC().size(); iCh++) { + auto chanelid = ft0.channelC()[iCh]; + auto globalId = chanelid + KnFt0cCell; + float ampl = ft0.amplitudeC()[iCh]; + auto eta = getEtaFT0(globalId, 1); + amplFT0C += ampl; + histos.fill(HIST("pmean_cent_id_eta_FT0"), cent, globalId, eta, ampl); + histos.fill(HIST("h3_cent_id_eta_FT0"), cent, globalId, eta, ampl); + } + } + + histos.fill(HIST("pmeanFT0Amultpv"), multPV, amplFT0A); + histos.fill(HIST("pmeanFT0A_cent"), cent, amplFT0A); + histos.fill(HIST("pmeanFT0Cmultpv"), multPV, amplFT0C); + histos.fill(HIST("pmeanFT0C_cent"), cent, amplFT0C); + } + } + } + PROCESS_SWITCH(RadialFlowDecorr, processMCMean, "process MC to calculate mean pt and Eff Hists", cfgRunMCMean); + + void processMCFluc(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/, aod::FT0s const&, aod::McParticles const& mcParticles) + { + if (!state.pmeanTruNchEtabinSpbinStep2 || !state.pmeanRecoNchEtabinSpbinStep2 || !state.pmeanRecoEffcorrNchEtabinSpbinStep2 || + !state.pmeanMultTruNchEtabinSpbinStep2 || !state.pmeanMultRecoNchEtabinSpbinStep2 || !state.pmeanMultRecoEffcorrNchEtabinSpbinStep2) { + LOGF(warning, "MC fluc: Unified Mean pT or Mult map missing"); + return; + } + double sumPmwkTru[KNsp][KNEta][KIntM][KIntK]{}; + double sumWkTru[KNsp][KNEta][KIntK]{}; + double sumPmwkReco[KNsp][KNEta][KIntM][KIntK]{}; + double sumWkReco[KNsp][KNEta][KIntK]{}; + double sumPmwkRecoEffCor[KNsp][KNEta][KIntM][KIntK]{}; + double sumWkRecoEffCor[KNsp][KNEta][KIntK]{}; + + double meanTru[KNsp][KNEta]{}, c2Tru[KNsp][KNEta]{}; + double meanReco[KNsp][KNEta]{}, c2Reco[KNsp][KNEta]{}; + double meanRecoEffCor[KNsp][KNEta]{}, c2RecoEffCor[KNsp][KNEta]{}; + + double meanTruMult[KNsp][KNEta]{}; + double meanRecoMult[KNsp][KNEta]{}; + double meanRecoEffCorMult[KNsp][KNEta]{}; + + double p1kBarTru[KNsp][KNEta]{}, p1kBarReco[KNsp][KNEta]{}, p1kBarRecoEffCor[KNsp][KNEta]{}; + double p1kBarTruMult[KNsp][KNEta]{}, p1kBarRecoMult[KNsp][KNEta]{}, p1kBarRecoEffCorMult[KNsp][KNEta]{}; + + for (const auto& mcCollision : mcColl) { + auto partSlice = mcParticles.sliceBy(partPerMcCollision, mcCollision.globalIndex()); + auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); + if (colSlice.size() != 1) + continue; + + for (const auto& col : colSlice) { + if (!col.has_mcCollision() || !isEventSelected(col)) + continue; + + auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); + if (trackSlice.size() < 1) + continue; + + float cent = getCentrality(col); + if (cent > KCentMax) + continue; + float multPV = col.multNTracksPV(); + + memset(sumPmwkTru, 0, sizeof(sumPmwkTru)); + memset(sumWkTru, 0, sizeof(sumWkTru)); + memset(sumPmwkReco, 0, sizeof(sumPmwkReco)); + memset(sumWkReco, 0, sizeof(sumWkReco)); + memset(sumPmwkRecoEffCor, 0, sizeof(sumPmwkRecoEffCor)); + memset(sumWkRecoEffCor, 0, sizeof(sumWkRecoEffCor)); + + memset(meanTru, 0, sizeof(meanTru)); + memset(c2Tru, 0, sizeof(c2Tru)); + memset(meanReco, 0, sizeof(meanReco)); + memset(c2Reco, 0, sizeof(c2Reco)); + memset(meanRecoEffCor, 0, sizeof(meanRecoEffCor)); + memset(c2RecoEffCor, 0, sizeof(c2RecoEffCor)); + + memset(meanTruMult, 0, sizeof(meanTruMult)); + memset(meanRecoMult, 0, sizeof(meanRecoMult)); + memset(meanRecoEffCorMult, 0, sizeof(meanRecoEffCorMult)); + + memset(p1kBarTru, 0, sizeof(p1kBarTru)); + memset(p1kBarReco, 0, sizeof(p1kBarReco)); + memset(p1kBarRecoEffCor, 0, sizeof(p1kBarRecoEffCor)); + + memset(p1kBarTruMult, 0, sizeof(p1kBarTruMult)); + memset(p1kBarRecoMult, 0, sizeof(p1kBarRecoMult)); + memset(p1kBarRecoEffCorMult, 0, sizeof(p1kBarRecoEffCorMult)); + + double p1kBarFt0A = 0.0, p1kBarFt0C = 0.0; + + for (const auto& particle : partSlice) { + if (!isParticleSelected(particle) || !particle.isPhysicalPrimary()) + continue; + + float pt = particle.pt(); + if (pt <= cfgPtMin || pt > cfgPtMax) + continue; + float eta = particle.eta(); + int pdgCode = particle.pdgCode(); + int absPdg = std::abs(pdgCode); + + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + pdgCode == -KPiPlus, // kPiMinusIdx + pdgCode == KPiPlus, // kPiPlusIdx + absPdg == KPiPlus, // kPiAllIdx + pdgCode == -KKPlus, // kKaMinusIdx + pdgCode == KKPlus, // kKaPlusIdx + absPdg == KKPlus, // kKaAllIdx + pdgCode == -KProton, // kAntiPrIdx + pdgCode == KProton, // kPrIdx + absPdg == KProton // kAllPrIdx + }; + + for (int ieta = 0; ieta < KNEta; ++ieta) { + if (eta <= etaLw[ieta] || eta > etaUp[ieta]) + continue; + for (int isp = 0; isp < KNsp; ++isp) { + if (isSpecies[isp]) { + for (int k = 0; k < KIntK; ++k) { + for (int m = 0; m < KIntM; ++m) { + sumPmwkTru[isp][ieta][m][k] += std::pow(pt, m); + } + sumWkTru[isp][ieta][k]++; + } + } + } } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_ipt0_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_ipt0_GapSum2D_Pr"), cent, gap, sum, c2SubReco); + } // end truth loop + float vz = col.posZ(); + + histos.fill(HIST("hZvtx_after_sel"), col.posZ()); + histos.fill(HIST("hCentrality"), cent); + + histos.fill(HIST("Hist2D_globalTracks_PVTracks"), col.multNTracksPV(), trackSlice.size()); + histos.fill(HIST("Hist2D_cent_nch"), trackSlice.size(), cent); + + + for (const auto& track : trackSlice) { + if (!isTrackSelected(track)) + continue; + + float pt = track.pt(); + if (pt <= cfgPtMin || pt > cfgPtMax) + continue; + float eta = track.eta(); + float phi = track.phi(); + auto sign = track.sign(); + bool isPi = selectionPion(track); + bool isKa = selectionKaon(track); + bool isPr = selectionProton(track); + + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + isPi && sign < 0, // kPiMinusIdx + isPi && sign > 0, // kPiPlusIdx + isPi, // kPiAllIdx + isKa && sign < 0, // kKaMinusIdx + isKa && sign > 0, // kKaPlusIdx + isKa, // kKaAllIdx + isPr && sign < 0, // kAntiPrIdx (Negative) + isPr && sign > 0, // kPrIdx (Positive) + isPr // kAllPrIdx + }; + + for (int isp = 0; isp < KNsp; ++isp) { + if (!isSpecies[isp]) + continue; + + float eff = getEfficiency(col.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); + float fake = getEfficiency(col.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); + float flatW = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); + float w = flatW * (1.0 - fake) / eff; + + if (!std::isfinite(w) || w <= 0.f || eff <= KFloatEpsilon) + continue; + + for (int ieta = 0; ieta < KNEta; ++ieta) { + if (eta <= etaLw[ieta] || eta > etaUp[ieta]) + continue; + for (int k = 0; k < KIntK; ++k) { + for (int m = 0; m < KIntM; ++m) { + sumPmwkReco[isp][ieta][m][k] += std::pow(1.0, k) * std::pow(pt, m); + sumPmwkRecoEffCor[isp][ieta][m][k] += std::pow(w, k) * std::pow(pt, m); + } + sumWkReco[isp][ieta][k] += std::pow(1.0, k); + sumWkRecoEffCor[isp][ieta][k] += std::pow(w, k); + } + } + + if (isp == kInclusiveIdx) { + histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPiMinusIdx) { + histos.fill(HIST("hEtaPhiReco_PiMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_PiMinus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiMinus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPiPlusIdx) { + histos.fill(HIST("hEtaPhiReco_PiPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_PiPlus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiPlus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPiAllIdx) { + histos.fill(HIST("hEtaPhiReco_PiAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_PiAll"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiAll"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kKaMinusIdx) { + histos.fill(HIST("hEtaPhiReco_KaMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_KaMinus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaMinus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kKaPlusIdx) { + histos.fill(HIST("hEtaPhiReco_KaPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_KaPlus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaPlus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kKaAllIdx) { + histos.fill(HIST("hEtaPhiReco_KaAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_KaAll"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaAll"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPrIdx) { + histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kAntiPrIdx) { + histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kAllPrIdx) { + histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_ipt0_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_ipt0_GapSum2D_Pr"), cent, gap, sum, c2SubRecoEffCor); + } // trkslice + + for (int ieta = 0; ieta < KNEta; ++ieta) { + const int ibx = state.pmeanTruNchEtabinSpbinStep2->GetXaxis()->FindBin(col.multNTracksPV()); + const int iby = ieta + 1; + + for (int isp = 0; isp < KNsp; ++isp) { + const int ibz = isp + 1; + + meanTruMult[isp][ieta] = sumWkTru[isp][ieta][1]; + meanRecoMult[isp][ieta] = sumWkReco[isp][ieta][1]; + meanRecoEffCorMult[isp][ieta] = sumWkRecoEffCor[isp][ieta][1]; + + float mmptTru = state.pmeanTruNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + float mmptReco = state.pmeanRecoNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + float mmptRecoEffCor = state.pmeanRecoEffcorrNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + + float mmMultTru = state.pmeanMultTruNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + float mmMultReco = state.pmeanMultRecoNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + float mmMultRecoEffCor = state.pmeanMultRecoEffcorrNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + + if (std::isfinite(mmptTru)) + std::tie(meanTru[isp][ieta], c2Tru[isp][ieta]) = calculateMeanAndC2FromSums(sumPmwkTru[isp][ieta], sumWkTru[isp][ieta], mmptTru); + if (std::isfinite(mmptReco)) + std::tie(meanReco[isp][ieta], c2Reco[isp][ieta]) = calculateMeanAndC2FromSums(sumPmwkReco[isp][ieta], sumWkReco[isp][ieta], mmptReco); + if (std::isfinite(mmptRecoEffCor)) + std::tie(meanRecoEffCor[isp][ieta], c2RecoEffCor[isp][ieta]) = calculateMeanAndC2FromSums(sumPmwkRecoEffCor[isp][ieta], sumWkRecoEffCor[isp][ieta], mmptRecoEffCor); + + if (mmptTru != 0.0f) + p1kBarTru[isp][ieta] = meanTru[isp][ieta] - mmptTru; + if (mmptReco != 0.0f) + p1kBarReco[isp][ieta] = meanReco[isp][ieta] - mmptReco; + if (mmptRecoEffCor != 0.0f) + p1kBarRecoEffCor[isp][ieta] = meanRecoEffCor[isp][ieta] - mmptRecoEffCor; + + if (mmMultTru != 0.0f) + p1kBarTruMult[isp][ieta] = meanTruMult[isp][ieta] - mmMultTru; + if (mmMultReco != 0.0f) + p1kBarRecoMult[isp][ieta] = meanRecoMult[isp][ieta] - mmMultReco; + if (mmMultRecoEffCor != 0.0f) + p1kBarRecoEffCorMult[isp][ieta] = meanRecoEffCorMult[isp][ieta] - mmMultRecoEffCor; } - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_ipt0_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_ipt0_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_ipt0_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covRecoEffCor); - } else if (ipt == KNpT - 2) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_ipt1_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_ipt1_GapSum2D_Pr"), cent, gap, sum, c2SubTru); + } + + double amplFT0A = 0, amplFT0C = 0; + if (col.has_foundFT0()) { + const auto& ft0 = col.foundFT0(); + for (std::size_t iCh = 0; iCh < ft0.channelA().size(); iCh++) { + float ampl = ft0.amplitudeA()[iCh]; + amplFT0A += ampl; } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_ipt1_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_ipt1_GapSum2D_Pr"), cent, gap, sum, c2SubReco); + for (std::size_t iCh = 0; iCh < ft0.channelC().size(); iCh++) { + float ampl = ft0.amplitudeC()[iCh]; + amplFT0C += ampl; } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_ipt1_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_ipt1_GapSum2D_Pr"), cent, gap, sum, c2SubRecoEffCor); + } + + for (int isp = 0; isp < KNsp; ++isp) { + for (int ieta = 0; ieta < KNEta; ++ieta) { + histos.fill(HIST("MCGen/Prof_Cent_NEta_Nsp_Nchrec"), cent, ieta, isp, sumWkTru[isp][ieta][1]); + histos.fill(HIST("MCGen/Prof_Mult_NEta_Nsp_Nchrec"), multPV, ieta, isp, sumWkTru[isp][ieta][1]); + + histos.fill(HIST("MCReco/Prof_Cent_NEta_Nsp_Nchrec"), cent, ieta, isp, sumWkReco[isp][ieta][1]); + histos.fill(HIST("MCReco/Prof_Mult_NEta_Nsp_Nchrec"), multPV, ieta, isp, sumWkReco[isp][ieta][1]); + + histos.fill(HIST("MCRecoEffCorr/Prof_Cent_NEta_Nsp_Nchrec"), cent, ieta, isp, sumWkRecoEffCor[isp][ieta][1]); + histos.fill(HIST("MCRecoEffCorr/Prof_Mult_NEta_Nsp_Nchrec"), multPV, ieta, isp, sumWkRecoEffCor[isp][ieta][1]); + + if (sumWkTru[isp][ieta][1] > 1.0f) { + histos.fill(HIST("MCGen/Prof_Cent_NEta_Nsp_MeanpT"), cent, ieta, isp, meanTru[isp][ieta]); + histos.fill(HIST("MCGen/Prof_Mult_NEta_Nsp_MeanpT"), multPV, ieta, isp, meanTru[isp][ieta]); + } + if (sumWkReco[isp][ieta][1] > 1.0f) { + histos.fill(HIST("MCReco/Prof_Cent_NEta_Nsp_MeanpT"), cent, ieta, isp, meanReco[isp][ieta]); + histos.fill(HIST("MCReco/Prof_Mult_NEta_Nsp_MeanpT"), multPV, ieta, isp, meanReco[isp][ieta]); + } + if (sumWkRecoEffCor[isp][ieta][1] > 1.0f) { + histos.fill(HIST("MCReco/Prof_Cent_NEta_Nsp_MeanpT"), cent, ieta, isp, meanRecoEffCor[isp][ieta]); + histos.fill(HIST("MCReco/Prof_Mult_NEta_Nsp_MeanpT"), multPV, ieta, isp, meanRecoEffCor[isp][ieta]); + } } - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_ipt1_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_ipt1_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_ipt1_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covRecoEffCor); - } else if (ipt == KNpT - 1) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_ipt2_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_ipt2_GapSum2D_Pr"), cent, gap, sum, c2SubTru); + } + + for (int ieta = 0; ieta < KNEta; ++ieta) { + for (int isp = 0; isp < KNsp; ++isp) { + if (std::isfinite(meanTru[isp][ieta])) { + histos.fill(HIST("MCGen/Prof_MeanpT_Cent_etabin_spbin"), cent, ieta, isp, meanTru[isp][ieta]); + histos.fill(HIST("MCGen/Prof_MeanpT_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, meanTru[isp][ieta]); + } + if (std::isfinite(c2Tru[isp][ieta])) { + histos.fill(HIST("MCGen/Prof_C2_Cent_etabin_spbin"), cent, ieta, isp, c2Tru[isp][ieta]); + histos.fill(HIST("MCGen/Prof_C2_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, c2Tru[isp][ieta]); + } + if (std::isfinite(meanReco[isp][ieta])) { + histos.fill(HIST("MCReco/Prof_MeanpT_Cent_etabin_spbin"), cent, ieta, isp, meanReco[isp][ieta]); + histos.fill(HIST("MCReco/Prof_MeanpT_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, meanReco[isp][ieta]); + } + if (std::isfinite(c2Reco[isp][ieta])) { + histos.fill(HIST("MCReco/Prof_C2_Cent_etabin_spbin"), cent, ieta, isp, c2Reco[isp][ieta]); + histos.fill(HIST("MCReco/Prof_C2_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, c2Reco[isp][ieta]); + } + if (std::isfinite(meanRecoEffCor[isp][ieta])) { + histos.fill(HIST("MCRecoEffCorr/Prof_MeanpT_Cent_etabin_spbin"), cent, ieta, isp, meanRecoEffCor[isp][ieta]); + histos.fill(HIST("MCRecoEffCorr/Prof_MeanpT_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, meanRecoEffCor[isp][ieta]); + } + if (std::isfinite(c2RecoEffCor[isp][ieta])) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2_Cent_etabin_spbin"), cent, ieta, isp, c2RecoEffCor[isp][ieta]); + histos.fill(HIST("MCRecoEffCorr/Prof_C2_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, c2RecoEffCor[isp][ieta]); + } } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_ipt2_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_ipt2_GapSum2D_Pr"), cent, gap, sum, c2SubReco); + } + + p1kBarFt0A = amplFT0A - state.pmeanFT0AmultpvStep2->GetBinContent(state.pmeanFT0AmultpvStep2->GetXaxis()->FindBin(col.multNTracksPV())); + p1kBarFt0C = amplFT0C - state.pmeanFT0CmultpvStep2->GetBinContent(state.pmeanFT0CmultpvStep2->GetXaxis()->FindBin(col.multNTracksPV())); + + for (int ietaA = 1; ietaA <= (KNEta - 1) / 2; ++ietaA) { + int ietaC = KNEta - ietaA; + for (int isp = 0; isp < KNsp; ++isp) { + float c2SubTru = p1kBarTru[isp][ietaA] * p1kBarTru[isp][ietaC]; + float c2SubReco = p1kBarReco[isp][ietaA] * p1kBarReco[isp][ietaC]; + float c2SubRecoEffCor = p1kBarRecoEffCor[isp][ietaA] * p1kBarRecoEffCor[isp][ietaC]; + + float covTru = p1kBarTruMult[isp][ietaA] * p1kBarTru[isp][ietaC]; + float covReco = p1kBarRecoMult[isp][ietaA] * p1kBarReco[isp][ietaC]; + float covRecoEffCor = p1kBarRecoEffCorMult[isp][ietaA] * p1kBarRecoEffCor[isp][ietaC]; + + float covFT0ATru = p1kBarFt0A * p1kBarTru[isp][ietaC]; + float covFT0AReco = p1kBarFt0A * p1kBarReco[isp][ietaC]; + float covFT0ARecoEffCor = p1kBarFt0A * p1kBarRecoEffCor[isp][ietaC]; + + float covFT0CTru = p1kBarFt0C * p1kBarTru[isp][ietaA]; + float covFT0CReco = p1kBarFt0C * p1kBarReco[isp][ietaA]; + float covFT0CRecoEffCor = p1kBarFt0C * p1kBarRecoEffCor[isp][ietaA]; + + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub_Cent_etabin_spbin"), cent, ietaA, isp, c2SubTru); + histos.fill(HIST("MCGen/Prof_C2Sub_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, c2SubTru); + } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub_Cent_etabin_spbin"), cent, ietaA, isp, c2SubReco); + histos.fill(HIST("MCReco/Prof_C2Sub_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, c2SubReco); + } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub_Cent_etabin_spbin"), cent, ietaA, isp, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, c2SubRecoEffCor); + } + if (std::isfinite(covTru)) { + histos.fill(HIST("MCGen/Prof_Cov_Cent_etabin_spbin"), cent, ietaA, isp, covTru); + histos.fill(HIST("MCGen/Prof_Cov_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covTru); + } + if (std::isfinite(covReco)) { + histos.fill(HIST("MCReco/Prof_Cov_Cent_etabin_spbin"), cent, ietaA, isp, covReco); + histos.fill(HIST("MCReco/Prof_Cov_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covReco); + } + if (std::isfinite(covRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_Cov_Cent_etabin_spbin"), cent, ietaA, isp, covRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_Cov_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covRecoEffCor); + } + + if (std::isfinite(covFT0ATru)) { + histos.fill(HIST("MCGen/Prof_CovFT0A_Cent_etabin_spbin"), cent, ietaA, isp, covFT0ATru); + histos.fill(HIST("MCGen/Prof_CovFT0A_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0ATru); + } + if (std::isfinite(covFT0AReco)) { + histos.fill(HIST("MCReco/Prof_CovFT0A_Cent_etabin_spbin"), cent, ietaA, isp, covFT0AReco); + histos.fill(HIST("MCReco/Prof_CovFT0A_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0AReco); + } + if (std::isfinite(covFT0ARecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A_Cent_etabin_spbin"), cent, ietaA, isp, covFT0ARecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0ARecoEffCor); + } + + if (std::isfinite(covFT0CTru)) { + histos.fill(HIST("MCGen/Prof_CovFT0C_Cent_etabin_spbin"), cent, ietaA, isp, covFT0CTru); + histos.fill(HIST("MCGen/Prof_CovFT0C_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0CTru); + } + if (std::isfinite(covFT0CReco)) { + histos.fill(HIST("MCReco/Prof_CovFT0C_Cent_etabin_spbin"), cent, ietaA, isp, covFT0CReco); + histos.fill(HIST("MCReco/Prof_CovFT0C_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0CReco); + } + if (std::isfinite(covFT0CRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C_Cent_etabin_spbin"), cent, ietaA, isp, covFT0CRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0CRecoEffCor); + } } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_ipt2_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_ipt2_GapSum2D_Pr"), cent, gap, sum, c2SubRecoEffCor); + } + + for (int ietaA = 1; ietaA < KNEta; ++ietaA) { + for (int ietaC = 1; ietaC < KNEta; ++ietaC) { + + float etaValA = (etaLw[ietaA] + etaUp[ietaA]) / 2.0f; + float etaValB = (etaLw[ietaC] + etaUp[ietaC]) / 2.0f; + float gap = etaValA - etaValB; + float sum = (etaValA + etaValB) / 2.0f; + for (int isp = 0; isp < KNsp; ++isp) { + + float c2SubTru = p1kBarTru[isp][ietaA] * p1kBarTru[isp][ietaC]; + float c2SubReco = p1kBarReco[isp][ietaA] * p1kBarReco[isp][ietaC]; + float c2SubRecoEffCor = p1kBarRecoEffCor[isp][ietaA] * p1kBarRecoEffCor[isp][ietaC]; + + float covTru = p1kBarTruMult[isp][ietaA] * p1kBarTru[isp][ietaC]; + float covReco = p1kBarRecoMult[isp][ietaA] * p1kBarReco[isp][ietaC]; + float covRecoEffCor = p1kBarRecoEffCorMult[isp][ietaA] * p1kBarRecoEffCor[isp][ietaC]; + + float covFT0ATru = p1kBarFt0A * p1kBarTru[isp][ietaC]; + float covFT0AReco = p1kBarFt0A * p1kBarReco[isp][ietaC]; + float covFT0ARecoEffCor = p1kBarFt0A * p1kBarRecoEffCor[isp][ietaC]; + + float covFT0CTru = p1kBarFt0C * p1kBarTru[isp][ietaA]; + float covFT0CReco = p1kBarFt0C * p1kBarReco[isp][ietaA]; + float covFT0CRecoEffCor = p1kBarFt0C * p1kBarRecoEffCor[isp][ietaA]; + + if (isp == kInclusiveIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D"), cent, gap, sum, c2SubTru); + } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D"), cent, gap, sum, c2SubReco); + } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D"), cent, gap, sum, c2SubRecoEffCor); + } + + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kPiMinusIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_PiMinus"), cent, gap, sum, c2SubTru); + } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_PiMinus"), cent, gap, sum, c2SubReco); + } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_PiMinus"), cent, gap, sum, c2SubRecoEffCor); + } + + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kPiPlusIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_PiPlus"), cent, gap, sum, c2SubTru); + } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_PiPlus"), cent, gap, sum, c2SubReco); + } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_PiPlus"), cent, gap, sum, c2SubRecoEffCor); + } + + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kPiAllIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_PiAll"), cent, gap, sum, c2SubTru); + } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_PiAll"), cent, gap, sum, c2SubReco); + } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_PiAll"), cent, gap, sum, c2SubRecoEffCor); + } + + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kKaMinusIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_KaMinus"), cent, gap, sum, c2SubTru); + } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_KaMinus"), cent, gap, sum, c2SubReco); + } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_KaMinus"), cent, gap, sum, c2SubRecoEffCor); + } + + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kKaPlusIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_KaPlus"), cent, gap, sum, c2SubTru); + } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_KaPlus"), cent, gap, sum, c2SubReco); + } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_KaPlus"), cent, gap, sum, c2SubRecoEffCor); + } + + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kKaAllIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_KaAll"), cent, gap, sum, c2SubTru); + } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_KaAll"), cent, gap, sum, c2SubReco); + } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_KaAll"), cent, gap, sum, c2SubRecoEffCor); + } + + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kPrIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_Pr"), cent, gap, sum, c2SubTru); + } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_Pr"), cent, gap, sum, c2SubReco); + } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_Pr"), cent, gap, sum, c2SubRecoEffCor); + } + + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kAntiPrIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_AntiPr"), cent, gap, sum, c2SubTru); + } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_AntiPr"), cent, gap, sum, c2SubReco); + } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_AntiPr"), cent, gap, sum, c2SubRecoEffCor); + } + + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kAllPrIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_AllPr"), cent, gap, sum, c2SubTru); + } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_AllPr"), cent, gap, sum, c2SubReco); + } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_AllPr"), cent, gap, sum, c2SubRecoEffCor); + } + + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0CRecoEffCor); + } + } } - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_ipt2_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_ipt2_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_ipt2_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covRecoEffCor); + } + } // colSlice + } // mcColl + LOGF(info, "FINISHED RUNNING processMCFluc"); + } + PROCESS_SWITCH(RadialFlowDecorr, processMCFluc, "process MC to calculate pt fluc", cfgRunMCFluc); + + void processGetDataFlat(AodCollisionsSel::iterator const& coll, BCsRun3 const& /*bcs*/, aod::Zdcs const& /*zdcsData*/, AodTracksSel const& tracks) + { + histos.fill(HIST("hVtxZ"), coll.posZ()); + if (!isEventSelected(coll)) + return; + float cent = getCentrality(coll); + if (cent > KCentMax) + return; + + histos.fill(HIST("hZvtx_after_sel"), coll.posZ()); + histos.fill(HIST("hCentrality"), cent); + + histos.fill(HIST("Hist2D_globalTracks_PVTracks"), coll.multNTracksPV(), tracks.size()); + histos.fill(HIST("Hist2D_cent_nch"), tracks.size(), cent); + + int ntrk = 0; + float vz = coll.posZ(); + + for (const auto& track : tracks) { + if (!isTrackSelected(track)) + continue; + float pt = track.pt(); + if (pt <= cfgPtMin || pt > cfgPtMax) + continue; + float eta = track.eta(); + float phi = track.phi(); + auto sign = track.sign(); + + if (eta > etaLw[0] && eta < etaUp[0]) + ntrk++; + + if (sign > 0) { + // PiPlus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiPlus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiPlus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + // KaPlus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaPlus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaPlus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + // Pr + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_Pr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_Pr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + } else if (sign < 0) { + // PiMinus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiMinus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiMinus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + // KaMinus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaMinus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaMinus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + // AntiPr + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_AntiPr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_AntiPr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + } + + bool isPi = selectionPion(track); + bool isKa = selectionKaon(track); + bool isPr = selectionProton(track); + + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + isPi && sign < 0, // kPiMinusIdx + isPi && sign > 0, // kPiPlusIdx + isPi, // kPiAllIdx + isKa && sign < 0, // kKaMinusIdx + isKa && sign > 0, // kKaPlusIdx + isKa, // kKaAllIdx + isPr && sign < 0, // kAntiPrIdx (Negative) + isPr && sign > 0, // kPrIdx (Positive) + isPr // kAllPrIdx + }; + + if (isSpecies[kPiPlusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiPlus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiPlus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + } else if (isSpecies[kPiMinusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiMinus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiMinus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + } + + if (isSpecies[kKaPlusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaPlus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaPlus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + } else if (isSpecies[kKaMinusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaMinus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaMinus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + } + + if (isSpecies[kPrIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_Pr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_Pr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + } else if (isSpecies[kAntiPrIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_AntiPr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_AntiPr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + } + + for (int isp = 0; isp < KNsp; ++isp) { + if (!isSpecies[isp]) + continue; + float eff = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); + if (eff <= KFloatEpsilon) + continue; + + float fake = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); + float w = (1.0f - fake) / eff; + + if (!std::isfinite(w) || w <= 0.f) + continue; + + if (isp == kInclusiveIdx) { + histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiMinusIdx) { + histos.fill(HIST("hEtaPhiReco_PiMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiMinus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_PiMinus"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiPlusIdx) { + histos.fill(HIST("hEtaPhiReco_PiPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiPlus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_PiPlus"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiAllIdx) { + histos.fill(HIST("hEtaPhiReco_PiAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiAll"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_PiAll"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaMinusIdx) { + histos.fill(HIST("hEtaPhiReco_KaMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaMinus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_KaMinus"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaPlusIdx) { + histos.fill(HIST("hEtaPhiReco_KaPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaPlus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_KaPlus"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaAllIdx) { + histos.fill(HIST("hEtaPhiReco_KaAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaAll"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_KaAll"), vz, sign, pt, eta, phi, w); + } else if (isp == kPrIdx) { + histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); + } else if (isp == kAntiPrIdx) { + histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); + } else if (isp == kAllPrIdx) { + histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); } } } - } - } - } - } // colSlice - } // mcColl - LOGF(info, "FINISHED RUNNING processMCFluc"); - } - PROCESS_SWITCH(RadialFlowDecorr, processMCFluc, "process MC to calculate pt fluc", cfgRunMCFluc); - - void processGetDataFlat(AodCollisionsSel::iterator const& coll, BCsRun3 const& /*bcs*/, aod::Zdcs const& /*zdcsData*/, AodTracksSel const& tracks) - { - histos.fill(HIST("hVtxZ"), coll.posZ()); - if (!isEventSelected(coll)) - return; - float cent = getCentrality(coll); - if (cent > KCentMax) - return; - - histos.fill(HIST("hZvtx_after_sel"), coll.posZ()); - histos.fill(HIST("hCentrality"), cent); - - histos.fill(HIST("Hist2D_globalTracks_PVTracks"), coll.multNTracksPV(), tracks.size()); - histos.fill(HIST("Hist2D_cent_nch"), tracks.size(), cent); - - int ntrk = 0; - float vz = coll.posZ(); - - for (const auto& track : tracks) { - if (!isTrackSelected(track)) - continue; - - float p = track.p(); - float pt = track.pt(); - float eta = track.eta(); - float phi = track.phi(); - auto sign = track.sign(); - - if (p < KFloatEpsilon) - continue; - - // Count tracks in the primary eta acceptance - if (eta > etaLw[0] && eta < etaUp[0]) - ntrk++; - - // Define species array (0: Inclusive, 1: Pion, 2: Kaon, 3: Proton) - bool isSpecies[KNsp] = {true, selectionPion(track), selectionKaon(track), selectionProton(track)}; - - for (int isp = 0; isp < KNsp; ++isp) { - if (!isSpecies[isp]) - continue; - - // Fetch efficiency specifically for this particle species - float eff = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); - float fake = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); - float w = (1.0 - fake) / eff; - - if (!std::isfinite(w) || w <= KFloatEpsilon || eff <= KFloatEpsilon) - continue; - - // Unrolled THnSparse / QA Fills - if (isp == numKInclusive) { - histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); - } else if (isp == numKPion) { // Pion - histos.fill(HIST("hEtaPhiReco_Pi"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_Pi"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_Pi"), vz, sign, pt, eta, phi, w); - } else if (isp == numKKaon) { // Kaon - histos.fill(HIST("hEtaPhiReco_Ka"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_Ka"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_Ka"), vz, sign, pt, eta, phi, w); - } else if (isp == numKProton) { // Proton - histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); - } - } - } - - histos.fill(HIST("hCentnTrk"), cent, ntrk); - histos.fill(HIST("hCentnTrkPV"), cent, coll.multNTracksPV()); - - if (cfgZDC) { - const auto& foundBC = coll.foundBC_as(); - if (!foundBC.has_zdc()) { - return; - } - auto zdc = foundBC.zdc(); - auto zdcAmp = zdc.energyCommonZNA() + zdc.energyCommonZNC(); - histos.fill(HIST("hnTrkPVZDC"), coll.multNTracksPV(), zdcAmp); - histos.fill(HIST("hNchZDC"), ntrk, zdcAmp); - } - } - PROCESS_SWITCH(RadialFlowDecorr, processGetDataFlat, "process data to calculate Flattening maps", cfgRunGetDataFlat); - - void processDataMean(AodCollisionsSel::iterator const& coll, BCsRun3 const& /*bcs*/, aod::Zdcs const& /*zdcsData*/, AodTracksSel const& tracks) - { - // Expanded to 4 species (isp = 0: Incl, 1: Pi, 2: Ka, 3: Pr) - double sumWi[KNsp][KNEta][KNpT]{}, sumWipti[KNsp][KNEta][KNpT]{}; - - if (!isEventSelected(coll)) - return; - - float cent = getCentrality(coll); - if (cent > KCentMax) - return; - - histos.fill(HIST("hZvtx_after_sel"), coll.posZ()); - histos.fill(HIST("hCentrality"), cent); - - histos.fill(HIST("Hist2D_globalTracks_PVTracks"), coll.multNTracksPV(), tracks.size()); - histos.fill(HIST("Hist2D_cent_nch"), tracks.size(), cent); - - float vz = coll.posZ(); - - for (const auto& track : tracks) { - if (!isTrackSelected(track)) - continue; - - float pt = track.pt(); - float eta = track.eta(); - float p = track.p(); - float phi = track.phi(); - auto sign = track.sign(); - - if (p < KFloatEpsilon) - continue; - - histos.fill(HIST("hP"), p); - histos.fill(HIST("hPt"), pt); - histos.fill(HIST("hEta"), eta); - histos.fill(HIST("hPhi"), phi); - - // Define species array - bool isSpecies[KNsp] = {true, selectionPion(track), selectionKaon(track), selectionProton(track)}; - - for (int isp = 0; isp < KNsp; ++isp) { - if (!isSpecies[isp]) - continue; - - float eff = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); - float fake = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); - float flatWeight = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); - float w = flatWeight * (1.0 - fake) / eff; - - if (!std::isfinite(w) || w <= KFloatEpsilon || eff <= KFloatEpsilon) - continue; - - // Unrolled THnSparse / QA Fills - if (isp == numKInclusive) { - histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); - } else if (isp == numKPion) { // Pion - histos.fill(HIST("hEtaPhiReco_Pi"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_Pi"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_Pi"), vz, sign, pt, eta, phi, w); - } else if (isp == numKKaon) { // Kaon - histos.fill(HIST("hEtaPhiReco_Ka"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_Ka"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_Ka"), vz, sign, pt, eta, phi, w); - } else if (isp == numKProton) { // Proton - histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); - } - - // Accumulate sum - for (int ieta = 0; ieta < KNEta; ++ieta) { - if (eta <= etaLw[ieta] || eta > etaUp[ieta]) - continue; - for (int ipt = 0; ipt < KNpT; ++ipt) { - if (pt <= pTLw[ipt] || pt > pTUp[ipt]) - continue; - sumWi[isp][ieta][ipt] += w; - sumWipti[isp][ieta][ipt] += w * pt; - } - } - } - } - - // Full Event Means - for (int isp = 0; isp < KNsp; ++isp) { - if (isp == numKInclusive) { - histos.fill(HIST("Prof_Cent_Nchrec"), cent, sumWi[0][0][0]); - histos.fill(HIST("Prof_Mult_Nchrec"), coll.multNTracksPV(), sumWi[0][0][0]); - if (sumWi[0][0][0] > 1.0f) - histos.fill(HIST("Prof_Cent_MeanpT"), cent, sumWipti[0][0][0] / sumWi[0][0][0]); - } else if (isp == numKPion) { - histos.fill(HIST("Prof_Cent_Nchrec_Pi"), cent, sumWi[1][0][0]); - histos.fill(HIST("Prof_Mult_Nchrec_Pi"), coll.multNTracksPV(), sumWi[1][0][0]); - - if (sumWi[1][0][0] > 1.0f) - histos.fill(HIST("Prof_Cent_MeanpT_Pi"), cent, sumWipti[1][0][0] / sumWi[1][0][0]); - } else if (isp == numKKaon) { - histos.fill(HIST("Prof_Cent_Nchrec_Ka"), cent, sumWi[2][0][0]); - histos.fill(HIST("Prof_Mult_Nchrec_Ka"), coll.multNTracksPV(), sumWi[2][0][0]); - - if (sumWi[2][0][0] > 1.0f) - histos.fill(HIST("Prof_Cent_MeanpT_Ka"), cent, sumWipti[2][0][0] / sumWi[2][0][0]); - } else if (isp == numKProton) { - histos.fill(HIST("Prof_Cent_Nchrec_Pr"), cent, sumWi[3][0][0]); - histos.fill(HIST("Prof_Mult_Nchrec_Pr"), coll.multNTracksPV(), sumWi[3][0][0]); - - if (sumWi[3][0][0] > 1.0f) - histos.fill(HIST("Prof_Cent_MeanpT_Pr"), cent, sumWipti[3][0][0] / sumWi[3][0][0]); - } - } - - // Kinematic Bin Means (1D and 2D Sub-event) - for (int ietaA = 0; ietaA < KNEta; ++ietaA) { - for (int ietaB = 0; ietaB < KNEta; ++ietaB) { - for (int ipt = 0; ipt < KNpT; ++ipt) { - for (int isp = 0; isp < KNsp; ++isp) { - - // --- 2D Sub-Event Calculations --- - double wCorrAB = sumWi[isp][ietaA][ipt] + sumWi[isp][ietaB][ipt]; - if (wCorrAB > 0) { - float mptsub = (sumWipti[isp][ietaA][ipt] + sumWipti[isp][ietaB][ipt]) / wCorrAB; - if (isp == numKInclusive) { - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0"), cent, ietaA, ietaB, mptsub); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1"), cent, ietaA, ietaB, mptsub); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2"), cent, ietaA, ietaB, mptsub); - } else if (isp == numKPion) { - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0_Pi"), cent, ietaA, ietaB, mptsub); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1_Pi"), cent, ietaA, ietaB, mptsub); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2_Pi"), cent, ietaA, ietaB, mptsub); - } else if (isp == numKKaon) { - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0_Ka"), cent, ietaA, ietaB, mptsub); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1_Ka"), cent, ietaA, ietaB, mptsub); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2_Ka"), cent, ietaA, ietaB, mptsub); - } else if (isp == numKProton) { - if (ipt == 0) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt0_Pr"), cent, ietaA, ietaB, mptsub); - if (ipt == KNpT - 2) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt1_Pr"), cent, ietaA, ietaB, mptsub); - if (ipt == KNpT - 1) - histos.fill(HIST("Prof2D_MeanpT_Sub_ipt2_Pr"), cent, ietaA, ietaB, mptsub); + + histos.fill(HIST("hCentnTrk"), cent, ntrk); + histos.fill(HIST("hCentnTrkPV"), cent, coll.multNTracksPV()); + + if (cfgZDC) { + const auto& foundBC = coll.foundBC_as(); + if (!foundBC.has_zdc()) { + return; + } + auto zdc = foundBC.zdc(); + auto zdcAmp = zdc.energyCommonZNA() + zdc.energyCommonZNC(); + histos.fill(HIST("hnTrkPVZDC"), coll.multNTracksPV(), zdcAmp); + histos.fill(HIST("hNchZDC"), ntrk, zdcAmp); } } + PROCESS_SWITCH(RadialFlowDecorr, processGetDataFlat, "process data to calculate Flattening maps", cfgRunGetDataFlat); + + void processDataMean(AodCollisionsSel::iterator const& coll, BCsRun3 const& /*bcs*/, aod::Zdcs const& /*zdcsData*/, aod::FT0s const&, AodTracksSel const& tracks) + { + double sumWi[KNsp][KNEta]{}, sumWipti[KNsp][KNEta]{}; + + if (!isEventSelected(coll)) + return; + + float cent = getCentrality(coll); + if (cent > KCentMax) + return; + + histos.fill(HIST("hZvtx_after_sel"), coll.posZ()); + histos.fill(HIST("hCentrality"), cent); - // --- 1D Individual Bin Calculations (Only do when A == B to avoid overfilling) --- - if (ietaA == ietaB) { - double mpt = sumWipti[isp][ietaA][ipt] / sumWi[isp][ietaA][ipt]; - if (sumWi[isp][ietaA][ipt] >= 1.0f && std::isfinite(mpt)) { - if (isp == numKInclusive) { - histos.fill(HIST("pmean_nch_etabin_ptbin"), coll.multNTracksPV(), ietaA, ipt, mpt); - histos.fill(HIST("pmeanMult_nch_etabin_ptbin"), coll.multNTracksPV(), ietaA, ipt, sumWi[0][ietaA][ipt]); - histos.fill(HIST("pmean_cent_etabin_ptbin"), cent, ietaA, ipt, mpt); - histos.fill(HIST("pmeanMult_cent_etabin_ptbin"), cent, ietaA, ipt, sumWi[0][ietaA][ipt]); - } else if (isp == numKPion) { - histos.fill(HIST("pmean_nch_etabin_ptbin_Pi"), coll.multNTracksPV(), ietaA, ipt, mpt); - histos.fill(HIST("pmeanMult_nch_etabin_ptbin_Pi"), coll.multNTracksPV(), ietaA, ipt, sumWi[1][ietaA][ipt]); - histos.fill(HIST("pmean_cent_etabin_ptbin_Pi"), cent, ietaA, ipt, mpt); - histos.fill(HIST("pmeanMult_cent_etabin_ptbin_Pi"), cent, ietaA, ipt, sumWi[1][ietaA][ipt]); - } else if (isp == numKKaon) { - histos.fill(HIST("pmean_nch_etabin_ptbin_Ka"), coll.multNTracksPV(), ietaA, ipt, mpt); - histos.fill(HIST("pmeanMult_nch_etabin_ptbin_Ka"), coll.multNTracksPV(), ietaA, ipt, sumWi[2][ietaA][ipt]); - histos.fill(HIST("pmean_cent_etabin_ptbin_Ka"), cent, ietaA, ipt, mpt); - histos.fill(HIST("pmeanMult_cent_etabin_ptbin_Ka"), cent, ietaA, ipt, sumWi[2][ietaA][ipt]); - } else if (isp == numKProton) { - histos.fill(HIST("pmean_nch_etabin_ptbin_Pr"), coll.multNTracksPV(), ietaA, ipt, mpt); - histos.fill(HIST("pmeanMult_nch_etabin_ptbin_Pr"), coll.multNTracksPV(), ietaA, ipt, sumWi[3][ietaA][ipt]); - histos.fill(HIST("pmean_cent_etabin_ptbin_Pr"), cent, ietaA, ipt, mpt); - histos.fill(HIST("pmeanMult_cent_etabin_ptbin_Pr"), cent, ietaA, ipt, sumWi[3][ietaA][ipt]); + histos.fill(HIST("Hist2D_globalTracks_PVTracks"), coll.multNTracksPV(), tracks.size()); + histos.fill(HIST("Hist2D_cent_nch"), tracks.size(), cent); + + float vz = coll.posZ(); + + for (const auto& track : tracks) { + if (!isTrackSelected(track)) + continue; + + float p = track.p(); + float pt = track.pt(); + float eta = track.eta(); + float phi = track.phi(); + auto sign = track.sign(); + + if (p < KFloatEpsilon) + continue; + + if (pt <= cfgPtMin || pt > cfgPtMax) + continue; + + histos.fill(HIST("hP"), p); + histos.fill(HIST("hPt"), pt); + histos.fill(HIST("hEta"), eta); + histos.fill(HIST("hPhi"), phi); + + bool isPi = selectionPion(track); + bool isKa = selectionKaon(track); + bool isPr = selectionProton(track); + + // Updated to use the correct PIDIdx enum names + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + isPi && sign < 0, // kPiMinusIdx + isPi && sign > 0, // kPiPlusIdx + isPi, // kPiAllIdx + isKa && sign < 0, // kKaMinusIdx + isKa && sign > 0, // kKaPlusIdx + isKa, // kKaAllIdx + isPr && sign < 0, // kAntiPrIdx (Negative) + isPr && sign > 0, // kPrIdx (Positive) + isPr // kAllPrIdx + }; + + for (int isp = 0; isp < KNsp; ++isp) { + if (!isSpecies[isp]) + continue; + + float eff = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); + + // Safety check BEFORE dividing + if (eff <= KFloatEpsilon) + continue; + + float fake = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); + float flatWeight = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); + float w = flatWeight * (1.0f - fake) / eff; + + if (!std::isfinite(w) || w <= 0.f) + continue; + + if (isp == kInclusiveIdx) { + histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiMinusIdx) { + histos.fill(HIST("hEtaPhiReco_PiMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiMinus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_PiMinus"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiPlusIdx) { + histos.fill(HIST("hEtaPhiReco_PiPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiPlus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_PiPlus"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiAllIdx) { + histos.fill(HIST("hEtaPhiReco_PiAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiAll"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_PiAll"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaMinusIdx) { + histos.fill(HIST("hEtaPhiReco_KaMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaMinus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_KaMinus"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaPlusIdx) { + histos.fill(HIST("hEtaPhiReco_KaPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaPlus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_KaPlus"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaAllIdx) { + histos.fill(HIST("hEtaPhiReco_KaAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaAll"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_KaAll"), vz, sign, pt, eta, phi, w); + } else if (isp == kPrIdx) { + histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); + } else if (isp == kAntiPrIdx) { + histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); + } else if (isp == kAllPrIdx) { + histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); + } + + for (int ieta = 0; ieta < KNEta; ++ieta) { + if (eta <= etaLw[ieta] || eta > etaUp[ieta]) + continue; + sumWi[isp][ieta] += w; + sumWipti[isp][ieta] += w * pt; + } } } - } - } - } - } - } - } - PROCESS_SWITCH(RadialFlowDecorr, processDataMean, "process data to calculate mean pT", cfgRunDataMean); - - void processDataFluc(AodCollisionsSel::iterator const& coll, BCsRun3 const& /*bcs*/, aod::Zdcs const& /*zdcsData*/, AodTracksSel const& tracks) - { - if (!isEventSelected(coll)) - return; - float cent = getCentrality(coll); - if (cent > KCentMax) - return; - - // 1. Safety Check: Step 2 Mean Maps - for (int isp = 0; isp < KNsp; ++isp) { - if (!pmeanNchEtabinPtbinStep2[isp] || !pmeanMultNchEtabinPtbinStep2[isp]) { - LOGF(warning, "Data fluc: Mean pT or Mult map missing for species index %d", isp); - return; - } - } - - // 2. Safety Check: Correction Maps (Looping over Inclusive, Pi, Ka, Pr) - for (int isp = 0; isp < KNsp; ++isp) { - auto pid = static_cast(isp); - if (!hEff[pid] || !hFake[pid] || !hFlatWeight[pid]) { - LOGF(warning, "Data fluc: Correction maps (Eff, Fake, or Flat) are null for species index %d", isp); - return; - } - } - - // Expanded arrays to handle KNsp species (0: Incl, 1: Pi, 2: Ka, 3: Pr) - double sumpmwk[KNsp][KNEta][KNpT][KIntM][KIntK]{}; - double sumwk[KNsp][KNEta][KNpT][KIntK]{}; - - double mean[KNsp][KNEta][KNpT]{}, c2[KNsp][KNEta][KNpT]{}; - double p1kBar[KNsp][KNEta][KNpT]{}; - double meanMult[KNsp][KNEta][KNpT]{}, p1kBarMult[KNsp][KNEta][KNpT]{}; - - float vz = coll.posZ(); - - // --- 1. Track Loop: Accumulate sum --- - for (const auto& track : tracks) { - if (!isTrackSelected(track)) - continue; - - float pt = track.pt(); - float eta = track.eta(); - float p = track.p(); - float phi = track.phi(); - auto sign = track.sign(); - - if (p < KFloatEpsilon) - continue; - - bool isSpecies[KNsp] = {true, selectionPion(track), selectionKaon(track), selectionProton(track)}; - - for (int isp = 0; isp < KNsp; ++isp) { - if (!isSpecies[isp]) - continue; - - float eff = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); - float fake = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); - float flatWeight = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); - float w = flatWeight * (1.0 - fake) / eff; - - if (!std::isfinite(w) || w <= KFloatEpsilon || eff <= KFloatEpsilon) - continue; - - // QA Fills - if (isp == numKInclusive) { - histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); - } else if (isp == numKPion) { // Pion - histos.fill(HIST("hEtaPhiReco_Pi"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_Pi"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_Pi"), vz, sign, pt, eta, phi, w); - } else if (isp == numKKaon) { // Kaon - histos.fill(HIST("hEtaPhiReco_Ka"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_Ka"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_Ka"), vz, sign, pt, eta, phi, w); - } else if (isp == numKProton) { // Proton - histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); - } - - // Kinematic Bin sum - for (int ieta = 0; ieta < KNEta; ++ieta) { - if (eta <= etaLw[ieta] || eta > etaUp[ieta]) - continue; - for (int ipt = 0; ipt < KNpT; ++ipt) { - if (pt <= pTLw[ipt] || pt > pTUp[ipt]) - continue; - for (int k = 0; k < KIntK; ++k) { - for (int m = 0; m < KIntM; ++m) { - sumpmwk[isp][ieta][ipt][m][k] += std::pow(w, k) * std::pow(pt, m); + + for (int isp = 0; isp < KNsp; ++isp) { + histos.fill(HIST("Prof_Cent_Nsp_Nchrec"), cent, isp, sumWi[isp][0]); + histos.fill(HIST("Prof_Mult_Nsp_Nchrec"), coll.multNTracksPV(), isp, sumWi[isp][0]); + if (sumWi[isp][0] > 1.0f) + histos.fill(HIST("Prof_Cent_Nsp_MeanpT"), cent, isp, sumWipti[isp][0] / sumWi[isp][0]); + histos.fill(HIST("Prof_Mult_Nsp_MeanpT"), coll.multNTracksPV(), isp, sumWipti[isp][0] / sumWi[isp][0]); } - sumwk[isp][ieta][ipt][k] += std::pow(w, k); - } - } - } - } - } - - // --- 2. Step 2 Means and 1D Fluc Variables --- - for (int ieta = 0; ieta < KNEta; ++ieta) { - for (int ipt = 0; ipt < KNpT; ++ipt) { - - // Use [0] to safely grab the X-axis from the array! - const int ibx = pmeanNchEtabinPtbinStep2[0]->GetXaxis()->FindBin(coll.multNTracksPV()); - const int iby = ieta + 1; - const int ibz = ipt + 1; - - for (int isp = 0; isp < KNsp; ++isp) { - // Dynamically fetch from the array - float mmpt = pmeanNchEtabinPtbinStep2[isp]->GetBinContent(ibx, iby, ibz); - float mmMult = pmeanMultNchEtabinPtbinStep2[isp]->GetBinContent(ibx, iby, ibz); - - mean[isp][ieta][ipt] = sumpmwk[isp][ieta][ipt][1][1] / sumwk[isp][ieta][ipt][1]; - meanMult[isp][ieta][ipt] = sumwk[isp][ieta][ipt][1]; - - if (std::isfinite(mmpt)) { - std::tie(mean[isp][ieta][ipt], c2[isp][ieta][ipt]) = calculateMeanAndC2FromSums(sumpmwk[isp][ieta][ipt], sumwk[isp][ieta][ipt], mmpt); - p1kBar[isp][ieta][ipt] = mean[isp][ieta][ipt] - mmpt; - } - p1kBarMult[isp][ieta][ipt] = meanMult[isp][ieta][ipt] - mmMult; - } - } - } - - // --- 3. Fill 1D Profiles --- - for (int ieta = 0; ieta < KNEta; ++ieta) { - for (int ipt = 0; ipt < KNpT; ++ipt) { - for (int isp = 0; isp < KNsp; ++isp) { - if (isp == numKInclusive) { - if (std::isfinite(mean[0][ieta][ipt])) { - histos.fill(HIST("Prof_MeanpT_Cent_etabin_ptbin"), cent, ieta, ipt, mean[0][ieta][ipt]); - histos.fill(HIST("Prof_MeanpT_Mult_etabin_ptbin"), coll.multNTracksPV(), ieta, ipt, mean[0][ieta][ipt]); - } - if (std::isfinite(c2[0][ieta][ipt])) { - histos.fill(HIST("Prof_C2_Cent_etabin_ptbin"), cent, ieta, ipt, c2[0][ieta][ipt]); - histos.fill(HIST("Prof_C2_Mult_etabin_ptbin"), coll.multNTracksPV(), ieta, ipt, c2[0][ieta][ipt]); - } - } else if (isp == numKPion) { // Pi - if (std::isfinite(mean[1][ieta][ipt])) { - histos.fill(HIST("Prof_MeanpT_Cent_etabin_ptbin_Pi"), cent, ieta, ipt, mean[1][ieta][ipt]); - histos.fill(HIST("Prof_MeanpT_Mult_etabin_ptbin_Pi"), coll.multNTracksPV(), ieta, ipt, mean[1][ieta][ipt]); - } - if (std::isfinite(c2[1][ieta][ipt])) { - histos.fill(HIST("Prof_C2_Cent_etabin_ptbin_Pi"), cent, ieta, ipt, c2[1][ieta][ipt]); - histos.fill(HIST("Prof_C2_Mult_etabin_ptbin_Pi"), coll.multNTracksPV(), ieta, ipt, c2[1][ieta][ipt]); - } - } else if (isp == numKKaon) { // Ka - if (std::isfinite(mean[2][ieta][ipt])) { - histos.fill(HIST("Prof_MeanpT_Cent_etabin_ptbin_Ka"), cent, ieta, ipt, mean[2][ieta][ipt]); - histos.fill(HIST("Prof_MeanpT_Mult_etabin_ptbin_Ka"), coll.multNTracksPV(), ieta, ipt, mean[2][ieta][ipt]); - } - if (std::isfinite(c2[2][ieta][ipt])) { - histos.fill(HIST("Prof_C2_Cent_etabin_ptbin_Ka"), cent, ieta, ipt, c2[2][ieta][ipt]); - histos.fill(HIST("Prof_C2_Mult_etabin_ptbin_Ka"), coll.multNTracksPV(), ieta, ipt, c2[2][ieta][ipt]); - } - } else if (isp == numKProton) { // Pr - if (std::isfinite(mean[3][ieta][ipt])) { - histos.fill(HIST("Prof_MeanpT_Cent_etabin_ptbin_Pr"), cent, ieta, ipt, mean[3][ieta][ipt]); - histos.fill(HIST("Prof_MeanpT_Mult_etabin_ptbin_Pr"), coll.multNTracksPV(), ieta, ipt, mean[3][ieta][ipt]); - } - if (std::isfinite(c2[3][ieta][ipt])) { - histos.fill(HIST("Prof_C2_Cent_etabin_ptbin_Pr"), cent, ieta, ipt, c2[3][ieta][ipt]); - histos.fill(HIST("Prof_C2_Mult_etabin_ptbin_Pr"), coll.multNTracksPV(), ieta, ipt, c2[3][ieta][ipt]); - } - } - } - } - } - - for (int ietaA = 1; ietaA <= (KNEta - 1) / 2; ++ietaA) { - int ietaC = KNEta - ietaA; - for (int ipt = 0; ipt < KNpT; ++ipt) { - for (int isp = 0; isp < KNsp; ++isp) { - float c2Sub = p1kBar[isp][ietaA][ipt] * p1kBar[isp][ietaC][ipt]; - float covAC = p1kBarMult[isp][ietaA][ipt] * p1kBar[isp][ietaC][ipt]; - float covCA = p1kBar[isp][ietaA][ipt] * p1kBarMult[isp][ietaC][ipt]; - - if (isp == numKInclusive) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub_Cent_etabin_ptbin"), cent, ietaA, ipt, c2Sub); - histos.fill(HIST("Prof_C2Sub_Mult_etabin_ptbin"), coll.multNTracksPV(), ietaA, ipt, c2Sub); - } - if (std::isfinite(covAC)) { - histos.fill(HIST("Prof_Cov_Cent_etabin_ptbin"), cent, ietaA, ipt, covAC); - histos.fill(HIST("Prof_Cov_Mult_etabin_ptbin"), coll.multNTracksPV(), ietaA, ipt, covAC); - } - if (std::isfinite(covCA)) { - histos.fill(HIST("Prof_Cov_Cent_etabin_ptbin"), cent, ietaA, ipt, covCA); - histos.fill(HIST("Prof_Cov_Mult_etabin_ptbin"), coll.multNTracksPV(), ietaA, ipt, covCA); - } - } else if (isp == numKPion) { // Pi - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub_Cent_etabin_ptbin_Pi"), cent, ietaA, ipt, c2Sub); - histos.fill(HIST("Prof_C2Sub_Mult_etabin_ptbin_Pi"), coll.multNTracksPV(), ietaA, ipt, c2Sub); - } - if (std::isfinite(covAC)) { - histos.fill(HIST("Prof_Cov_Cent_etabin_ptbin_Pi"), cent, ietaA, ipt, covAC); - histos.fill(HIST("Prof_Cov_Mult_etabin_ptbin_Pi"), coll.multNTracksPV(), ietaA, ipt, covAC); - } - if (std::isfinite(covCA)) { - histos.fill(HIST("Prof_Cov_Cent_etabin_ptbin_Pi"), cent, ietaA, ipt, covCA); - histos.fill(HIST("Prof_Cov_Mult_etabin_ptbin_Pi"), coll.multNTracksPV(), ietaA, ipt, covCA); - } - } else if (isp == numKKaon) { // Ka - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub_Cent_etabin_ptbin_Ka"), cent, ietaA, ipt, c2Sub); - histos.fill(HIST("Prof_C2Sub_Mult_etabin_ptbin_Ka"), coll.multNTracksPV(), ietaA, ipt, c2Sub); - } - if (std::isfinite(covAC)) { - histos.fill(HIST("Prof_Cov_Cent_etabin_ptbin_Ka"), cent, ietaA, ipt, covAC); - histos.fill(HIST("Prof_Cov_Mult_etabin_ptbin_Ka"), coll.multNTracksPV(), ietaA, ipt, covAC); - } - if (std::isfinite(covCA)) { - histos.fill(HIST("Prof_Cov_Cent_etabin_ptbin_Ka"), cent, ietaA, ipt, covCA); - histos.fill(HIST("Prof_Cov_Mult_etabin_ptbin_Ka"), coll.multNTracksPV(), ietaA, ipt, covCA); - } - } else if (isp == numKProton) { // Pr - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub_Cent_etabin_ptbin_Pr"), cent, ietaA, ipt, c2Sub); - histos.fill(HIST("Prof_C2Sub_Mult_etabin_ptbin_Pr"), coll.multNTracksPV(), ietaA, ipt, c2Sub); - } - if (std::isfinite(covAC)) { - histos.fill(HIST("Prof_Cov_Cent_etabin_ptbin_Pr"), cent, ietaA, ipt, covAC); - histos.fill(HIST("Prof_Cov_Mult_etabin_ptbin_Pr"), coll.multNTracksPV(), ietaA, ipt, covAC); - } - if (std::isfinite(covCA)) { - histos.fill(HIST("Prof_Cov_Cent_etabin_ptbin_Pr"), cent, ietaA, ipt, covCA); - histos.fill(HIST("Prof_Cov_Mult_etabin_ptbin_Pr"), coll.multNTracksPV(), ietaA, ipt, covCA); - } - } - } - } - } - - // --- 5. Full 2D Covariances & GapSum Profiles --- - for (int ietaA = 1; ietaA < KNEta; ++ietaA) { - for (int ietaB = 1; ietaB < KNEta; ++ietaB) { - - float etaValA = (etaLw[ietaA] + etaUp[ietaA]) / 2.0f; - float etaValB = (etaLw[ietaB] + etaUp[ietaB]) / 2.0f; - float gap = etaValA - etaValB; - float sum = (etaValA + etaValB) / 2.0f; - - for (int ipt = 0; ipt < KNpT; ++ipt) { - for (int isp = 0; isp < KNsp; ++isp) { - - float c2Sub = p1kBar[isp][ietaA][ipt] * p1kBar[isp][ietaB][ipt]; - float cov = p1kBarMult[isp][ietaA][ipt] * p1kBar[isp][ietaB][ipt]; - - if (isp == numKInclusive) { // Inclusive - if (ipt == 0) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_ipt0_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_ipt0_GapSum2D"), cent, gap, sum, c2Sub); - } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_ipt0_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, cov); - } else if (ipt == KNpT - 2) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_ipt1_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_ipt1_GapSum2D"), cent, gap, sum, c2Sub); - } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_ipt1_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, cov); - } else if (ipt == KNpT - 1) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_ipt2_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_ipt2_GapSum2D"), cent, gap, sum, c2Sub); + + for (int ietaA = 0; ietaA < KNEta; ++ietaA) { + for (int ietaC = 0; ietaC < KNEta; ++ietaC) { + for (int isp = 0; isp < KNsp; ++isp) { + double wCorrAB = sumWi[isp][ietaA] + sumWi[isp][ietaC]; + if (wCorrAB > 0) { + float mptsub = (sumWipti[isp][ietaA] + sumWipti[isp][ietaC]) / wCorrAB; + if (isp == kInclusiveIdx) + histos.fill(HIST("Prof2D_MeanpTSub"), cent, ietaA, ietaC, mptsub); + else if (isp == kPiMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_PiMinus"), cent, ietaA, ietaC, mptsub); + else if (isp == kPiPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_PiPlus"), cent, ietaA, ietaC, mptsub); + else if (isp == kPiAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_PiAll"), cent, ietaA, ietaC, mptsub); + else if (isp == kKaMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_KaMinus"), cent, ietaA, ietaC, mptsub); + else if (isp == kKaPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_KaPlus"), cent, ietaA, ietaC, mptsub); + else if (isp == kKaAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_KaAll"), cent, ietaA, ietaC, mptsub); + else if (isp == kPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Pr"), cent, ietaA, ietaC, mptsub); + else if (isp == kAntiPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_AntiPr"), cent, ietaA, ietaC, mptsub); + else if (isp == kAllPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_AllPr"), cent, ietaA, ietaC, mptsub); + } + if (ietaA == ietaC) { + double mpt = sumWipti[isp][ietaA] / sumWi[isp][ietaA]; + if (sumWi[isp][ietaA] >= 1.0f && std::isfinite(mpt)) { + histos.fill(HIST("pmean_nch_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, mpt); + histos.fill(HIST("pmeanMult_nch_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, sumWi[isp][ietaA]); + histos.fill(HIST("pmean_cent_etabin_spbin"), cent, ietaA, isp, mpt); + histos.fill(HIST("pmeanMult_cent_etabin_spbin"), cent, ietaA, isp, sumWi[isp][ietaA]); + } + } + } } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_ipt2_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, cov); } - } else if (isp == numKPion) { // Pi - if (ipt == 0) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_ipt0_C2Sub2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_ipt0_GapSum2D_Pi"), cent, gap, sum, c2Sub); + + double amplFT0A = 0, amplFT0C = 0; + if (coll.has_foundFT0()) { + const auto& ft0 = coll.foundFT0(); + for (std::size_t iCh = 0; iCh < ft0.channelA().size(); iCh++) { + auto chanelid = ft0.channelA()[iCh]; + float ampl = ft0.amplitudeA()[iCh]; + amplFT0A += ampl; + auto eta = getEtaFT0(chanelid, 0); + histos.fill(HIST("pmean_cent_id_eta_FT0"), cent, chanelid, eta, ampl); + histos.fill(HIST("h3_cent_id_eta_FT0"), cent, chanelid, eta, ampl); + } + for (std::size_t iCh = 0; iCh < ft0.channelC().size(); iCh++) { + auto chanelid = ft0.channelC()[iCh]; + auto globalId = chanelid + KnFt0cCell; + float ampl = ft0.amplitudeC()[iCh]; + auto eta = getEtaFT0(globalId, 1); + amplFT0C += ampl; + histos.fill(HIST("pmean_cent_id_eta_FT0"), cent, globalId, eta, ampl); + histos.fill(HIST("h3_cent_id_eta_FT0"), cent, globalId, eta, ampl); } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_ipt0_Cov2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, cov); - } else if (ipt == KNpT - 2) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_ipt1_C2Sub2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_ipt1_GapSum2D_Pi"), cent, gap, sum, c2Sub); + } + + histos.fill(HIST("pmeanFT0Amultpv"), coll.multNTracksPV(), amplFT0A); + histos.fill(HIST("pmeanFT0A_cent"), cent, amplFT0A); + histos.fill(HIST("pmeanFT0Cmultpv"), coll.multNTracksPV(), amplFT0C); + histos.fill(HIST("pmeanFT0C_cent"), cent, amplFT0C); + } + PROCESS_SWITCH(RadialFlowDecorr, processDataMean, "process data to calculate mean pT", cfgRunDataMean); + + void processDataFluc(AodCollisionsSel::iterator const& coll, BCsRun3 const& /*bcs*/, aod::Zdcs const& /*zdcsData*/, aod::FT0s const&, AodTracksSel const& tracks) + { + if (!isEventSelected(coll)) + return; + float cent = getCentrality(coll); + if (cent > KCentMax) + return; + + if (!state.pmeanNchEtabinSpbinStep2 || !state.pmeanMultNchEtabinSpbinStep2) { + LOGF(warning, "Data fluc: Mean pT or Mult map missing"); + return; + } + + for (int isp = 0; isp < KNsp; ++isp) { + auto pid = static_cast(isp); + if (!state.hEff[pid] || !state.hFake[pid] || !state.hFlatWeight[pid]) { + LOGF(warning, "Data fluc: Correction maps (Eff, Fake, or Flat) are null for species index %d", isp); + return; } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_ipt1_Cov2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, cov); - } else if (ipt == KNpT - 1) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_ipt2_C2Sub2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_ipt2_GapSum2D_Pi"), cent, gap, sum, c2Sub); + } + + double sumpmwk[KNsp][KNEta][KIntM][KIntK]{}; + double sumwk[KNsp][KNEta][KIntK]{}; + + double mean[KNsp][KNEta]{}, c2[KNsp][KNEta]{}; + double p1kBar[KNsp][KNEta]{}; + double meanMult[KNsp][KNEta]{}, p1kBarMult[KNsp][KNEta]{}; + + float vz = coll.posZ(); + + for (const auto& track : tracks) { + if (!isTrackSelected(track)) + continue; + + float p = track.p(); + float pt = track.pt(); + float eta = track.eta(); + float phi = track.phi(); + auto sign = track.sign(); + + if (p < KFloatEpsilon) + continue; + + if (pt <= cfgPtMin || pt > cfgPtMax) + continue; + + bool isPi = selectionPion(track); + bool isKa = selectionKaon(track); + bool isPr = selectionProton(track); + + // Updated to use the correct PIDIdx enum names + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + isPi && sign < 0, // kPiMinusIdx + isPi && sign > 0, // kPiPlusIdx + isPi, // kPiAllIdx + isKa && sign < 0, // kKaMinusIdx + isKa && sign > 0, // kKaPlusIdx + isKa, // kKaAllIdx + isPr && sign < 0, // kAntiPrIdx (Negative) + isPr && sign > 0, // kPrIdx (Positive) + isPr // kAllPrIdx + }; + + for (int isp = 0; isp < KNsp; ++isp) { + if (!isSpecies[isp]) + continue; + + float eff = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); + + // Safety check BEFORE dividing + if (eff <= KFloatEpsilon) + continue; + + float fake = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); + float flatWeight = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); + float w = flatWeight * (1.0f - fake) / eff; + + if (!std::isfinite(w) || w <= 0.f) + continue; + + for (int ieta = 0; ieta < KNEta; ++ieta) { + if (eta <= etaLw[ieta] || eta > etaUp[ieta]) + continue; + for (int k = 0; k < KIntK; ++k) { + for (int m = 0; m < KIntM; ++m) { + sumpmwk[isp][ieta][m][k] += std::pow(w, k) * std::pow(pt, m); + } + sumwk[isp][ieta][k] += std::pow(w, k); + } + } } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_ipt2_Cov2D_Cent_etaA_etaC_Pi"), cent, etaValA, etaValB, cov); } - } else if (isp == numKKaon) { // Ka - if (ipt == 0) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_ipt0_C2Sub2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_ipt0_GapSum2D_Ka"), cent, gap, sum, c2Sub); + + double amplFT0A = 0, amplFT0C = 0; + if (coll.has_foundFT0()) { + const auto& ft0 = coll.foundFT0(); + for (std::size_t iCh = 0; iCh < ft0.channelA().size(); iCh++) { + float ampl = ft0.amplitudeA()[iCh]; + amplFT0A += ampl; } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_ipt0_Cov2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, cov); - } else if (ipt == KNpT - 2) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_ipt1_C2Sub2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_ipt1_GapSum2D_Ka"), cent, gap, sum, c2Sub); + for (std::size_t iCh = 0; iCh < ft0.channelC().size(); iCh++) { + float ampl = ft0.amplitudeC()[iCh]; + amplFT0C += ampl; } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_ipt1_Cov2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, cov); - } else if (ipt == KNpT - 1) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_ipt2_C2Sub2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_ipt2_GapSum2D_Ka"), cent, gap, sum, c2Sub); + } + double p1kBarFt0A = amplFT0A - state.pmeanFT0AmultpvStep2->GetBinContent(state.pmeanFT0AmultpvStep2->GetXaxis()->FindBin(coll.multNTracksPV())); + double p1kBarFt0C = amplFT0C - state.pmeanFT0CmultpvStep2->GetBinContent(state.pmeanFT0CmultpvStep2->GetXaxis()->FindBin(coll.multNTracksPV())); + + for (int ieta = 0; ieta < KNEta; ++ieta) { + const int ibx = state.pmeanNchEtabinSpbinStep2->GetXaxis()->FindBin(coll.multNTracksPV()); + const int iby = ieta + 1; + + for (int isp = 0; isp < KNsp; ++isp) { + const int ibz = isp + 1; + + float mmpt = state.pmeanNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + float mmMult = state.pmeanMultNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + + mean[isp][ieta] = sumpmwk[isp][ieta][1][1] / sumwk[isp][ieta][1]; + meanMult[isp][ieta] = sumwk[isp][ieta][1]; + + if (std::isfinite(mmpt)) { + std::tie(mean[isp][ieta], c2[isp][ieta]) = calculateMeanAndC2FromSums(sumpmwk[isp][ieta], sumwk[isp][ieta], mmpt); + p1kBar[isp][ieta] = mean[isp][ieta] - mmpt; + } + p1kBarMult[isp][ieta] = meanMult[isp][ieta] - mmMult; } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_ipt2_Cov2D_Cent_etaA_etaC_Ka"), cent, etaValA, etaValB, cov); } - } else if (isp == numKProton) { // Pr - if (ipt == 0) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_ipt0_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_ipt0_GapSum2D_Pr"), cent, gap, sum, c2Sub); + for (int ieta = 0; ieta < KNEta; ++ieta) { + for (int isp = 0; isp < KNsp; ++isp) { + if (std::isfinite(mean[isp][ieta])) { + histos.fill(HIST("Prof_MeanpT_Cent_etabin_spbin"), cent, ieta, isp, mean[isp][ieta]); + histos.fill(HIST("Prof_MeanpT_Mult_etabin_spbin"), coll.multNTracksPV(), ieta, isp, mean[isp][ieta]); + } + if (std::isfinite(c2[isp][ieta])) { + histos.fill(HIST("Prof_C2_Cent_etabin_spbin"), cent, ieta, isp, c2[isp][ieta]); + histos.fill(HIST("Prof_C2_Mult_etabin_spbin"), coll.multNTracksPV(), ieta, isp, c2[isp][ieta]); + } } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_ipt0_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, cov); - } else if (ipt == KNpT - 2) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_ipt1_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_ipt1_GapSum2D_Pr"), cent, gap, sum, c2Sub); + } + + for (int ietaA = 1; ietaA <= (KNEta - 1) / 2; ++ietaA) { + int ietaC = KNEta - ietaA; + for (int isp = 0; isp < KNsp; ++isp) { + float c2Sub = p1kBar[isp][ietaA] * p1kBar[isp][ietaC]; + float covAC = p1kBarMult[isp][ietaA] * p1kBar[isp][ietaC]; + float covCA = p1kBar[isp][ietaA] * p1kBarMult[isp][ietaC]; + + float covFT0A = p1kBarFt0A * p1kBar[isp][ietaC]; + float covFT0C = p1kBarFt0C * p1kBar[isp][ietaA]; + + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub_Cent_etabin_spbin"), cent, ietaA, isp, c2Sub); + histos.fill(HIST("Prof_C2Sub_Mult_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, c2Sub); + } + if (std::isfinite(covAC)) { + histos.fill(HIST("Prof_Cov_Cent_etabin_spbin"), cent, ietaA, isp, covAC); + histos.fill(HIST("Prof_Cov_Mult_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, covAC); + } + if (std::isfinite(covCA)) { + histos.fill(HIST("Prof_Cov_Cent_etabin_spbin"), cent, ietaA, isp, covCA); + histos.fill(HIST("Prof_Cov_Mult_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, covCA); + } + if (std::isfinite(covFT0A)) { + histos.fill(HIST("Prof_CovFT0A_Cent_etabin_spbin"), cent, ietaA, isp, covFT0A); + histos.fill(HIST("Prof_CovFT0A_Mult_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, covFT0A); + } + if (std::isfinite(covFT0C)) { + histos.fill(HIST("Prof_CovFT0C_Cent_etabin_spbin"), cent, ietaA, isp, covFT0C); + histos.fill(HIST("Prof_CovFT0C_Mult_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, covFT0C); + } } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_ipt1_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, cov); - } else if (ipt == KNpT - 1) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_ipt2_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_ipt2_GapSum2D_Pr"), cent, gap, sum, c2Sub); + } + + for (int ietaA = 1; ietaA < KNEta; ++ietaA) { + for (int ietaC = 1; ietaC < KNEta; ++ietaC) { + + float etaValA = (etaLw[ietaA] + etaUp[ietaA]) / 2.0f; + float etaValB = (etaLw[ietaC] + etaUp[ietaC]) / 2.0f; + float gap = etaValA - etaValB; + float sum = (etaValA + etaValB) / 2.0f; + + for (int isp = 0; isp < KNsp; ++isp) { + + float c2Sub = p1kBar[isp][ietaA] * p1kBar[isp][ietaC]; + float cov = p1kBarMult[isp][ietaA] * p1kBar[isp][ietaC]; + float covFT0A = p1kBarFt0A * p1kBar[isp][ietaC]; + float covFT0C = p1kBarFt0C * p1kBar[isp][ietaA]; + + // Updated enum checks here + if (isp == kInclusiveIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kPiMinusIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_PiMinus"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kPiPlusIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_PiPlus"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kPiAllIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_PiAll"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kKaMinusIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_KaMinus"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kKaPlusIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_KaPlus"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kKaAllIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_KaAll"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kPrIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_Pr"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kAntiPrIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_AntiPr"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kAllPrIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_AllPr"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0C); + } + } } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_ipt2_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, cov); } } + PROCESS_SWITCH(RadialFlowDecorr, processDataFluc, "process data to calculate fluc pT", cfgRunDataFluc); + }; + + WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) + { + WorkflowSpec workflow{adaptAnalysisTask(cfgc)}; + return workflow; } - } - } - } - } - PROCESS_SWITCH(RadialFlowDecorr, processDataFluc, "process data to calculate fluc pT and Et", cfgRunDataFluc); -}; - -WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) -{ - WorkflowSpec workflow{adaptAnalysisTask(cfgc)}; - return workflow; -} From f29e9e4d28c3afb619c75d84c735f40ccc017c9d Mon Sep 17 00:00:00 2001 From: Somadutta Bhatta Date: Wed, 4 Mar 2026 08:16:13 +0100 Subject: [PATCH 2/6] Fix linter issues --- .../Tasks/radialFlowDecorr.cxx | 6258 +++++++++-------- 1 file changed, 3133 insertions(+), 3125 deletions(-) diff --git a/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx b/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx index 80f8a08bb6e..bf6eb8cd8a7 100644 --- a/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx +++ b/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx @@ -13,16 +13,15 @@ /// \brief Analysis task for event-by-event radial-flow decorrelation measurement. /// \author Somadutta Bhatta -#include "Common/Core/trackUtilities.h" #include "Common/Core/TrackSelection.h" -#include "Common/DataModel/TrackSelectionTables.h" +#include "Common/Core/trackUtilities.h" #include "Common/DataModel/Centrality.h" #include "Common/DataModel/EventSelection.h" #include "Common/DataModel/FT0Corrected.h" #include "Common/DataModel/Multiplicity.h" +#include "Common/DataModel/PIDResponseITS.h" #include "Common/DataModel/PIDResponseTOF.h" #include "Common/DataModel/PIDResponseTPC.h" -#include "Common/DataModel/PIDResponseITS.h" #include "Common/DataModel/TrackSelectionTables.h" #include "CCDB/BasicCCDBManager.h" @@ -40,9 +39,9 @@ #include "Framework/runDataProcessing.h" #include "MathUtils/Utils.h" #include "ReconstructionDataFormats/DCA.h" +#include "ReconstructionDataFormats/PID.h" #include "ReconstructionDataFormats/Track.h" #include "ReconstructionDataFormats/TrackTPCITS.h" -#include "ReconstructionDataFormats/PID.h" #include "TDirectory.h" #include "TFile.h" @@ -113,9 +112,15 @@ struct RadialFlowDecorr { enum PIDIdx { kInclusiveIdx = 0, - kPiMinusIdx, kPiPlusIdx, kPiAllIdx, - kKaMinusIdx, kKaPlusIdx, kKaAllIdx, - kAntiPrIdx, kPrIdx, kAllPrIdx, + kPiMinusIdx, + kPiPlusIdx, + kPiAllIdx, + kKaMinusIdx, + kKaPlusIdx, + kKaAllIdx, + kAntiPrIdx, + kPrIdx, + kAllPrIdx, KNsp }; @@ -136,3258 +141,3261 @@ struct RadialFlowDecorr { const std::vector etaLw = { -0.8, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7}; - const std::vector etaUp = { - 0.8, - -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8}; - - Configurable cfgVtxZCut{"cfgVtxZCut", 10.f, "z-vertex range"}; - Configurable cfgPtMin{"cfgPtMin", 0.2f, "min pT"}; - Configurable cfgPtMax{"cfgPtMax", 5.0f, "max pT"}; - Configurable cfgEtaCut{"cfgEtaCut", 0.8f, "|η| cut"}; - Configurable cfgTPCClsMin{"cfgTPCClsMin", 70.f, "min TPC clusters"}; - Configurable cfgChi2TPCMax{"cfgChi2TPCMax", 4.0f, "max TPC χ²"}; - Configurable cfgCutTpcChi2NCl{"cfgCutTpcChi2NCl", 2.5f, "Maximum TPCchi2NCl"}; - Configurable cfgCutItsChi2NCl{"cfgCutItsChi2NCl", 36.0f, "Maximum ITSchi2NCl"}; - Configurable cfgCutVertex{"cfgCutVertex", 7.0f, "Accepted z-vertex range"}; - Configurable cfgCutTracKDcaMaxZ{"cfgCutTracKDcaMaxZ", 2.0f, "Maximum DcaZ"}; - Configurable cfgCutTracKDcaMaxXY{"cfgCutTracKDcaMaxXY", 0.2f, "Maximum DcaZ"}; - - Configurable cfgPtDepDCAxy{"cfgPtDepDCAxy", true, "Use pt-dependent DCAxy cut"}; - Configurable cfgDcaXyP0{"cfgDcaXyP0", 0.0026f, "p0 for DCAxy"}; - Configurable cfgDcaXyP1{"cfgDcaXyP1", 0.005f, "p1 for DCAxy"}; - Configurable cfgDcaXyP2{"cfgDcaXyP2", 1.01f, "p2 for DCAxy"}; - - Configurable cfgPtDepDCAz{"cfgPtDepDCAz", true, "Use pt-dependent DCAz cut"}; - Configurable cfgDcaZP0{"cfgDcaZP0", 0.0026f, "p0 for DCAz"}; - Configurable cfgDcaZP1{"cfgDcaZP1", 0.005f, "p1 for DCAz"}; - Configurable cfgDcaZP2{"cfgDcaZP2", 1.01f, "p2 for DCAz"}; - - // Configurable cfgPtDepDCAxy{"cfgPtDepDCAxy", true, "Use pt-dependent DCAxy cut"}; - // Configurable cfgPtDepDCAz{"cfgPtDepDCAz", true, "Use pt-dependent DCAz cut"}; - // Configurable cfgPtDepDCAxyFunc{"cfgPtDepDCAxyFunc", "(0.0026+0.005/(x^1.01))", "Functional form of pt-dependent DCAxy cut"}; - // Configurable cfgPtDepDCAzFunc{"cfgDPtDepCAzFunc", "(0.0026+0.005/(x^1.01))", "Functional form of pt-dependent DCAz cut"}; - - // TF1* fPtDepDCAxy = nullptr; - // TF1* fPtDepDCAz = nullptr; - - Configurable cfgITScluster{"cfgITScluster", 1, "Minimum Number of ITS cluster"}; - Configurable cfgTPCcluster{"cfgTPCcluster", 80, "Minimum Number of TPC cluster"}; - Configurable cfgTPCnCrossedRows{"cfgTPCnCrossedRows", 70, "Minimum Number of TPC crossed-rows"}; - Configurable cfgCutPtUpperTPC{"cfgCutPtUpperTPC", 0.6f, "Upper pT cut for PID using TPC only"}; - Configurable cfgnSigmaOtherParticles{"cfgnSigmaOtherParticles", 3.0f, "PID nSigma cut to remove other particles (default:3)"}; - Configurable cfgnSigmaCutTPC{"cfgnSigmaCutTPC", 2.0f, "PID nSigma cut for TPC"}; - Configurable cfgnSigmaCutTOF{"cfgnSigmaCutTOF", 2.0f, "PID nSigma cut for TOF"}; - Configurable cfgnSigmaCutCombTPCTOF{"cfgnSigmaCutCombTPCTOF", 2.0f, "PID nSigma combined cut for TPC and TOF"}; - Configurable cfgCutPtLower{"cfgCutPtLower", 0.2f, "Lower pT cut"}; - Configurable cfgCutPtUpper{"cfgCutPtUpper", 10.0f, "Higher pT cut for inclusive hadron analysis"}; - Configurable cfgCutPtUpperPID{"cfgCutPtUpperPID", 6.0f, "Higher pT cut for identified particle analysis"}; - Configurable cfgCutEta{"cfgCutEta", 0.8f, "absolute Eta cut"}; - Configurable cfgNsubsample{"cfgNsubsample", 10, "Number of subsamples"}; - Configurable cfgCentralityChoice{"cfgCentralityChoice", 1, "Which centrality estimator? 1-->FT0C, 2-->FV0A"}; - Configurable cfgEvSelNoSameBunchPileup{"cfgEvSelNoSameBunchPileup", true, "Pileup removal"}; - Configurable cfgUseGoodITSLayerAllCut{"cfgUseGoodITSLayerAllCut", true, "Remove time interval with dead ITS zone"}; - Configurable cfgEvSelkNoITSROFrameBorder{"cfgEvSelkNoITSROFrameBorder", true, "ITSROFrame border event selection cut"}; - Configurable cfgEvSelkNoTimeFrameBorder{"cfgEvSelkNoTimeFrameBorder", true, "TimeFrame border event selection cut"}; - Configurable cfgIsGoodZvtxFT0VsPV{"cfgIsGoodZvtxFT0VsPV", true, "Good Vertexing cut"}; - - Configurable cfgNchPbMax{"cfgNchPbMax", 6000, "Max Nch range for PbPb collisions"}; - Configurable cfgNchOMax{"cfgNchOMax", 600, "Max Nch range for OO collisions"}; - - Configurable cfgSys{"cfgSys", 1, "Efficiency to be used for which system? 1-->PbPb, 2-->NeNe, 3-->OO, 4-->pp"}; - Configurable cfgFlat{"cfgFlat", false, "Whether to use flattening weights"}; - Configurable cfgEff{"cfgEff", false, "Whether to use Efficiency weights"}; - Configurable cfgZDC{"cfgZDC", false, "Whether to use ZDC for pileup histograms"}; - - Configurable cfgCCDBurl{"cfgCCDBurl", "https://alice-ccdb.cern.ch", "ccdb url"}; - Configurable cfgCCDBUserPath{"cfgCCDBUserPath", "/Users/s/somadutt", "Base CCDB path"}; - - ConfigurableAxis cfgAxisCent{"cfgAxisCent", {0.0, 1.0, 3.0, 5.0, 10, 20, 30, 40, 50, 60, 70, 80, 100}, "centrality axis (percentile)"}; - - const AxisSpec centAxis{cfgAxisCent, "Centrality (%)"}; - const AxisSpec centAxis1Per{101, -0.5, 100.5, "Centrality (%)"}; - AxisSpec nChAxis{1, 0., 1., "Nch", "Nch"}; - AxisSpec nChAxis2{1, 0., 1., "Nch", "Nch"}; - - const AxisSpec vzAxis{5, -12.5, 12.5, "Vz"}; - const AxisSpec chgAxis{3, -1.5, 1.5}; - const AxisSpec pTAxis{{0.0, 0.2, 0.5, 1, 3, 5, 7.5, 10}, "pT Axis"}; - const AxisSpec etaAxis{{-0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}, "Eta"}; - const AxisSpec phiAxis{KNbinsPhi, KPhiMin, TwoPI, "#phi"}; - const AxisSpec etaBinAxis{KNEta + 1, -0.5, KNEta + 0.5, "#eta bin Number"}; - const AxisSpec spBinAxis{KNsp + 1, -KBinOffset, KNsp + KBinOffset, "species index Number"}; - - const AxisSpec gapAxis{{-1.55, -1.45, -1.35, -1.25, -1.15, -1.05, -0.95, -0.85, - -0.75, -0.65, -0.55, -0.45, -0.35, -0.25, -0.15, -0.05, - 0.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, - 0.85, 0.95, 1.05, 1.15, 1.25, 1.35, 1.45, 1.55}, "Gaps"}; - - const AxisSpec sumAxis{{-0.775, -0.725, -0.675, -0.625, -0.575, -0.525, - -0.475, -0.425, -0.375, -0.325, -0.275, -0.225, - -0.175, -0.125, -0.075, -0.025, - 0.025, 0.075, 0.125, 0.175, 0.225, 0.275, - 0.325, 0.375, 0.425, 0.475, 0.525, 0.575, - 0.625, 0.675, 0.725, 0.775},"Sums"}; - Configurable cfgRunGetEff{"cfgRunGetEff", false, "Run MC pass to build efficiency/fake maps"}; - Configurable cfgRunGetMCFlat{"cfgRunGetMCFlat", false, "Run MC to Get Flattening Weights"}; - Configurable cfgRunMCMean{"cfgRunMCMean", false, "Run MC mean(pT) & mean(Et)"}; - Configurable cfgRunMCFluc{"cfgRunMCFluc", false, "Run MC fluctuations (C2, subevent)"}; - Configurable cfgRunGetDataFlat{"cfgRunGetDataFlat", false, "Run Data Get Flattening Weights"}; - Configurable cfgRunDataMean{"cfgRunDataMean", false, "Run DATA mean(pT) & mean(Et)"}; - Configurable cfgRunDataFluc{"cfgRunDataFluc", false, "Run DATA fluctuations (C2, subevent)"}; - - Service ccdb; - Service pdg; - HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject}; - - struct InternalState { - std::array hEff{}; - std::array hFake{}; - std::array hFlatWeight{}; - - TProfile3D* pmeanTruNchEtabinSpbinStep2 = nullptr; - TProfile3D* pmeanRecoNchEtabinSpbinStep2 = nullptr; - TProfile3D* pmeanRecoEffcorrNchEtabinSpbinStep2 = nullptr; - - TProfile3D* pmeanMultTruNchEtabinSpbinStep2 = nullptr; - TProfile3D* pmeanMultRecoNchEtabinSpbinStep2 = nullptr; - TProfile3D* pmeanMultRecoEffcorrNchEtabinSpbinStep2 = nullptr; - - TProfile3D* pmeanNchEtabinSpbinStep2 = nullptr; - TProfile3D* pmeanMultNchEtabinSpbinStep2 = nullptr; - - TProfile* pmeanFT0AmultpvStep2 = nullptr; - TProfile* pmeanFT0CmultpvStep2 = nullptr; - } state; - o2::ft0::Geometry ft0Det; - - template - static std::tuple getAllCombinedNSigmas(const T& candidate) - { - return { - std::hypot(candidate.tpcNSigmaPr(), candidate.tofNSigmaPr()), // Proton - std::hypot(candidate.tpcNSigmaPi(), candidate.tofNSigmaPi()), // Pion - std::hypot(candidate.tpcNSigmaKa(), candidate.tofNSigmaKa()) // Kaon - }; + const std::vector etaUp = { + 0.8, + -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8}; + + Configurable cfgVtxZCut{"cfgVtxZCut", 10.f, "z-vertex range"}; + Configurable cfgPtMin{"cfgPtMin", 0.2f, "min pT"}; + Configurable cfgPtMax{"cfgPtMax", 5.0f, "max pT"}; + Configurable cfgEtaCut{"cfgEtaCut", 0.8f, "|η| cut"}; + Configurable cfgTPCClsMin{"cfgTPCClsMin", 70.f, "min TPC clusters"}; + Configurable cfgChi2TPCMax{"cfgChi2TPCMax", 4.0f, "max TPC χ²"}; + Configurable cfgCutTpcChi2NCl{"cfgCutTpcChi2NCl", 2.5f, "Maximum TPCchi2NCl"}; + Configurable cfgCutItsChi2NCl{"cfgCutItsChi2NCl", 36.0f, "Maximum ITSchi2NCl"}; + Configurable cfgCutVertex{"cfgCutVertex", 7.0f, "Accepted z-vertex range"}; + Configurable cfgCutTracKDcaMaxZ{"cfgCutTracKDcaMaxZ", 2.0f, "Maximum DcaZ"}; + Configurable cfgCutTracKDcaMaxXY{"cfgCutTracKDcaMaxXY", 0.2f, "Maximum DcaZ"}; + + Configurable cfgPtDepDCAxy{"cfgPtDepDCAxy", true, "Use pt-dependent DCAxy cut"}; + Configurable cfgDcaXyP0{"cfgDcaXyP0", 0.0026f, "p0 for DCAxy"}; + Configurable cfgDcaXyP1{"cfgDcaXyP1", 0.005f, "p1 for DCAxy"}; + Configurable cfgDcaXyP2{"cfgDcaXyP2", 1.01f, "p2 for DCAxy"}; + + Configurable cfgPtDepDCAz{"cfgPtDepDCAz", true, "Use pt-dependent DCAz cut"}; + Configurable cfgDcaZP0{"cfgDcaZP0", 0.0026f, "p0 for DCAz"}; + Configurable cfgDcaZP1{"cfgDcaZP1", 0.005f, "p1 for DCAz"}; + Configurable cfgDcaZP2{"cfgDcaZP2", 1.01f, "p2 for DCAz"}; + + // Configurable cfgPtDepDCAxy{"cfgPtDepDCAxy", true, "Use pt-dependent DCAxy cut"}; + // Configurable cfgPtDepDCAz{"cfgPtDepDCAz", true, "Use pt-dependent DCAz cut"}; + // Configurable cfgPtDepDCAxyFunc{"cfgPtDepDCAxyFunc", "(0.0026+0.005/(x^1.01))", "Functional form of pt-dependent DCAxy cut"}; + // Configurable cfgPtDepDCAzFunc{"cfgDPtDepCAzFunc", "(0.0026+0.005/(x^1.01))", "Functional form of pt-dependent DCAz cut"}; + + // TF1* fPtDepDCAxy = nullptr; + // TF1* fPtDepDCAz = nullptr; + + Configurable cfgITScluster{"cfgITScluster", 1, "Minimum Number of ITS cluster"}; + Configurable cfgTPCcluster{"cfgTPCcluster", 80, "Minimum Number of TPC cluster"}; + Configurable cfgTPCnCrossedRows{"cfgTPCnCrossedRows", 70, "Minimum Number of TPC crossed-rows"}; + Configurable cfgCutPtUpperTPC{"cfgCutPtUpperTPC", 0.6f, "Upper pT cut for PID using TPC only"}; + Configurable cfgnSigmaOtherParticles{"cfgnSigmaOtherParticles", 3.0f, "PID nSigma cut to remove other particles (default:3)"}; + Configurable cfgnSigmaCutTPC{"cfgnSigmaCutTPC", 2.0f, "PID nSigma cut for TPC"}; + Configurable cfgnSigmaCutTOF{"cfgnSigmaCutTOF", 2.0f, "PID nSigma cut for TOF"}; + Configurable cfgnSigmaCutCombTPCTOF{"cfgnSigmaCutCombTPCTOF", 2.0f, "PID nSigma combined cut for TPC and TOF"}; + Configurable cfgCutPtLower{"cfgCutPtLower", 0.2f, "Lower pT cut"}; + Configurable cfgCutPtUpper{"cfgCutPtUpper", 10.0f, "Higher pT cut for inclusive hadron analysis"}; + Configurable cfgCutPtUpperPID{"cfgCutPtUpperPID", 6.0f, "Higher pT cut for identified particle analysis"}; + Configurable cfgCutEta{"cfgCutEta", 0.8f, "absolute Eta cut"}; + Configurable cfgNsubsample{"cfgNsubsample", 10, "Number of subsamples"}; + Configurable cfgCentralityChoice{"cfgCentralityChoice", 1, "Which centrality estimator? 1-->FT0C, 2-->FV0A"}; + Configurable cfgEvSelNoSameBunchPileup{"cfgEvSelNoSameBunchPileup", true, "Pileup removal"}; + Configurable cfgUseGoodITSLayerAllCut{"cfgUseGoodITSLayerAllCut", true, "Remove time interval with dead ITS zone"}; + Configurable cfgEvSelkNoITSROFrameBorder{"cfgEvSelkNoITSROFrameBorder", true, "ITSROFrame border event selection cut"}; + Configurable cfgEvSelkNoTimeFrameBorder{"cfgEvSelkNoTimeFrameBorder", true, "TimeFrame border event selection cut"}; + Configurable cfgIsGoodZvtxFT0VsPV{"cfgIsGoodZvtxFT0VsPV", true, "Good Vertexing cut"}; + + Configurable cfgNchPbMax{"cfgNchPbMax", 6000, "Max Nch range for PbPb collisions"}; + Configurable cfgNchOMax{"cfgNchOMax", 600, "Max Nch range for OO collisions"}; + + Configurable cfgSys{"cfgSys", 1, "Efficiency to be used for which system? 1-->PbPb, 2-->NeNe, 3-->OO, 4-->pp"}; + Configurable cfgFlat{"cfgFlat", false, "Whether to use flattening weights"}; + Configurable cfgEff{"cfgEff", false, "Whether to use Efficiency weights"}; + Configurable cfgZDC{"cfgZDC", false, "Whether to use ZDC for pileup histograms"}; + + Configurable cfgCCDBurl{"cfgCCDBurl", "https://alice-ccdb.cern.ch", "ccdb url"}; + Configurable cfgCCDBUserPath{"cfgCCDBUserPath", "/Users/s/somadutt", "Base CCDB path"}; + + ConfigurableAxis cfgAxisCent{"cfgAxisCent", {0.0, 1.0, 3.0, 5.0, 10, 20, 30, 40, 50, 60, 70, 80, 100}, "centrality axis (percentile)"}; + + const AxisSpec centAxis{cfgAxisCent, "Centrality (%)"}; + const AxisSpec centAxis1Per{101, -0.5, 100.5, "Centrality (%)"}; + AxisSpec nChAxis{1, 0., 1., "Nch", "Nch"}; + AxisSpec nChAxis2{1, 0., 1., "Nch", "Nch"}; + + const AxisSpec vzAxis{5, -12.5, 12.5, "Vz"}; + const AxisSpec chgAxis{3, -1.5, 1.5}; + const AxisSpec pTAxis{{0.0, 0.2, 0.5, 1, 3, 5, 7.5, 10}, "pT Axis"}; + const AxisSpec etaAxis{{-0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}, "Eta"}; + const AxisSpec phiAxis{KNbinsPhi, KPhiMin, TwoPI, "#phi"}; + const AxisSpec etaBinAxis{KNEta + 1, -0.5, KNEta + 0.5, "#eta bin Number"}; + const AxisSpec spBinAxis{KNsp + 1, -KBinOffset, KNsp + KBinOffset, "species index Number"}; + + const AxisSpec gapAxis{{-1.55, -1.45, -1.35, -1.25, -1.15, -1.05, -0.95, -0.85, + -0.75, -0.65, -0.55, -0.45, -0.35, -0.25, -0.15, -0.05, + 0.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, + 0.85, 0.95, 1.05, 1.15, 1.25, 1.35, 1.45, 1.55}, + "Gaps"}; + + const AxisSpec sumAxis{{-0.775, -0.725, -0.675, -0.625, -0.575, -0.525, + -0.475, -0.425, -0.375, -0.325, -0.275, -0.225, + -0.175, -0.125, -0.075, -0.025, + 0.025, 0.075, 0.125, 0.175, 0.225, 0.275, + 0.325, 0.375, 0.425, 0.475, 0.525, 0.575, + 0.625, 0.675, 0.725, 0.775}, + "Sums"}; + Configurable cfgRunGetEff{"cfgRunGetEff", false, "Run MC pass to build efficiency/fake maps"}; + Configurable cfgRunGetMCFlat{"cfgRunGetMCFlat", false, "Run MC to Get Flattening Weights"}; + Configurable cfgRunMCMean{"cfgRunMCMean", false, "Run MC mean(pT) & mean(Et)"}; + Configurable cfgRunMCFluc{"cfgRunMCFluc", false, "Run MC fluctuations (C2, subevent)"}; + Configurable cfgRunGetDataFlat{"cfgRunGetDataFlat", false, "Run Data Get Flattening Weights"}; + Configurable cfgRunDataMean{"cfgRunDataMean", false, "Run DATA mean(pT) & mean(Et)"}; + Configurable cfgRunDataFluc{"cfgRunDataFluc", false, "Run DATA fluctuations (C2, subevent)"}; + + Service ccdb; + Service pdg; + HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject}; + + struct InternalState { + std::array hEff{}; + std::array hFake{}; + std::array hFlatWeight{}; + + TProfile3D* pmeanTruNchEtabinSpbinStep2 = nullptr; + TProfile3D* pmeanRecoNchEtabinSpbinStep2 = nullptr; + TProfile3D* pmeanRecoEffcorrNchEtabinSpbinStep2 = nullptr; + + TProfile3D* pmeanMultTruNchEtabinSpbinStep2 = nullptr; + TProfile3D* pmeanMultRecoNchEtabinSpbinStep2 = nullptr; + TProfile3D* pmeanMultRecoEffcorrNchEtabinSpbinStep2 = nullptr; + + TProfile3D* pmeanNchEtabinSpbinStep2 = nullptr; + TProfile3D* pmeanMultNchEtabinSpbinStep2 = nullptr; + + TProfile* pmeanFT0AmultpvStep2 = nullptr; + TProfile* pmeanFT0CmultpvStep2 = nullptr; + } state; + o2::ft0::Geometry ft0Det; + + template + static std::tuple getAllCombinedNSigmas(const T& candidate) + { + return { + std::hypot(candidate.tpcNSigmaPr(), candidate.tofNSigmaPr()), // Proton + std::hypot(candidate.tpcNSigmaPi(), candidate.tofNSigmaPi()), // Pion + std::hypot(candidate.tpcNSigmaKa(), candidate.tofNSigmaKa()) // Kaon + }; + } + + template + bool isEventSelected(const T& col) + { + if (!col.sel8()) + return false; + if (std::abs(col.posZ()) > cfgCutVertex) + return false; + if (cfgEvSelNoSameBunchPileup && !col.selection_bit(o2::aod::evsel::kNoSameBunchPileup)) + return false; + if (cfgUseGoodITSLayerAllCut && !col.selection_bit(o2::aod::evsel::kIsGoodITSLayersAll)) + return false; + if (cfgIsGoodZvtxFT0VsPV && !col.selection_bit(o2::aod::evsel::kIsGoodZvtxFT0vsPV)) + return false; + return true; + } + + template + bool isTrackSelected(const T& trk) + { + if (trk.sign() == 0) + return false; + if (!trk.has_collision()) + return false; + if (!trk.isPVContributor()) + return false; + if (!(trk.itsNCls() > cfgITScluster)) + return false; + if (!(trk.tpcNClsFound() >= cfgTPCcluster)) + return false; + if (!(trk.tpcNClsCrossedRows() >= cfgTPCnCrossedRows)) + return false; + if (trk.pt() < cfgCutPtLower || trk.pt() > cfgCutPtUpper || std::abs(trk.eta()) > cfgCutEta) + return false; + // --- DCAxy Cut --- + if (cfgPtDepDCAxy) { + // Evaluates: 0.0026 + 0.005 / (pt^1.01) + float maxDcaXY = cfgDcaXyP0 + cfgDcaXyP1 / std::pow(trk.pt(), cfgDcaXyP2); + if (std::abs(trk.dcaXY()) > maxDcaXY) { + return false; // Reject track if DCA is too large + } + } else { + if (std::abs(trk.dcaXY()) > cfgCutTracKDcaMaxXY) { + return false; + } + } + // --- DCAz Cut --- + if (cfgPtDepDCAz) { + // Evaluates: 0.0026 + 0.005 / (pt^1.01) + float maxDcaZ = cfgDcaZP0 + cfgDcaZP1 / std::pow(trk.pt(), cfgDcaZP2); + if (std::abs(trk.dcaZ()) > maxDcaZ) { + return false; // Reject track if DCA is too large + } + } else { + if (std::abs(trk.dcaZ()) > cfgCutTracKDcaMaxZ) { + return false; + } + } + return true; + } + + template + bool isParticleSelected(const T& particle) + { + auto* pd = pdg->GetParticle(particle.pdgCode()); + if (!pd) + return false; + if (std::abs(pd->Charge()) == 0) + return false; + if (particle.pt() < cfgCutPtLower || particle.pt() > cfgCutPtUpper || std::abs(particle.eta()) > cfgCutEta) + return false; + if (std::abs(particle.vz()) > cfgCutVertex) + return false; + return true; + } + + template + bool selectionProton(const T& candidate) + { + if (!candidate.hasTPC()) + return false; + int flag = 0; + if (candidate.pt() > cfgCutPtLower && candidate.pt() <= cfgCutPtUpperTPC) { + if (!candidate.hasTOF() && std::abs(candidate.tpcNSigmaPr()) < cfgnSigmaCutTPC) { + flag = 1; + } + if (candidate.hasTOF() && std::abs(candidate.tpcNSigmaPr()) < cfgnSigmaCutTPC && std::abs(candidate.tofNSigmaPr()) < cfgnSigmaCutTOF) { + flag = 1; + } + } + if (candidate.hasTOF() && candidate.pt() > cfgCutPtUpperTPC && candidate.pt() < cfgCutPtUpperPID) { + auto [combNSigmaPr, combNSigmaPi, combNSigmaKa] = getAllCombinedNSigmas(candidate); + int flag2 = 0; + if (combNSigmaPr < cfgnSigmaOtherParticles) + flag2 += 1; + if (combNSigmaPi < cfgnSigmaOtherParticles) + flag2 += 1; + if (combNSigmaKa < cfgnSigmaOtherParticles) + flag2 += 1; + if (!(flag2 > 1) && !(combNSigmaPr > combNSigmaPi) && !(combNSigmaPr > combNSigmaKa)) { + if (combNSigmaPr < cfgnSigmaCutCombTPCTOF) { + flag = 1; + } + } + } + if (flag == 1) + return true; + else + return false; + } + + template + bool selectionPion(const T& candidate) + { + if (!candidate.hasTPC()) + return false; + int flag = 0; + + if (candidate.pt() > cfgCutPtLower && candidate.pt() <= cfgCutPtUpperTPC) { + if (!candidate.hasTOF() && std::abs(candidate.tpcNSigmaPi()) < cfgnSigmaCutTPC) { + flag = 1; + } + if (candidate.hasTOF() && std::abs(candidate.tpcNSigmaPi()) < cfgnSigmaCutTPC && std::abs(candidate.tofNSigmaPi()) < cfgnSigmaCutTOF) { + flag = 1; + } + } + if (candidate.hasTOF() && candidate.pt() > cfgCutPtUpperTPC && candidate.pt() < cfgCutPtUpperPID) { + auto [combNSigmaPr, combNSigmaPi, combNSigmaKa] = getAllCombinedNSigmas(candidate); + int flag2 = 0; + if (combNSigmaPr < cfgnSigmaOtherParticles) + flag2 += 1; + if (combNSigmaPi < cfgnSigmaOtherParticles) + flag2 += 1; + if (combNSigmaKa < cfgnSigmaOtherParticles) + flag2 += 1; + if (!(flag2 > 1) && !(combNSigmaPi > combNSigmaPr) && !(combNSigmaPi > combNSigmaKa)) { + if (combNSigmaPi < cfgnSigmaCutCombTPCTOF) { + flag = 1; + } + } + } + if (flag == 1) + return true; + else + return false; + } + + template + bool selectionKaon(const T& candidate) + { + if (!candidate.hasTPC()) + return false; + int flag = 0; + + if (candidate.pt() > cfgCutPtLower && candidate.pt() <= cfgCutPtUpperTPC) { + if (!candidate.hasTOF() && std::abs(candidate.tpcNSigmaKa()) < cfgnSigmaCutTPC) { + flag = 1; + } + if (candidate.hasTOF() && std::abs(candidate.tpcNSigmaKa()) < cfgnSigmaCutTPC && std::abs(candidate.tofNSigmaKa()) < cfgnSigmaCutTOF) { + flag = 1; + } + } + if (candidate.hasTOF() && candidate.pt() > cfgCutPtUpperTPC && candidate.pt() < cfgCutPtUpperPID) { + auto [combNSigmaPr, combNSigmaPi, combNSigmaKa] = getAllCombinedNSigmas(candidate); + int flag2 = 0; + if (combNSigmaPr < cfgnSigmaOtherParticles) + flag2 += 1; + if (combNSigmaPi < cfgnSigmaOtherParticles) + flag2 += 1; + if (combNSigmaKa < cfgnSigmaOtherParticles) + flag2 += 1; + if (!(flag2 > 1) && !(combNSigmaKa > combNSigmaPi) && !(combNSigmaKa > combNSigmaPr)) { + if (combNSigmaKa < cfgnSigmaCutCombTPCTOF) { + flag = 1; + } + } + } + if (flag == 1) + return true; + else + return false; + } + + float getCentrality(const auto& col) const + { + if (cfgCentralityChoice.value == kCentFT0M) + return col.centFT0M(); + if (cfgCentralityChoice.value == kCentFDDM) + return col.centFDDM(); + if (cfgCentralityChoice.value == kCentFV0A) + return col.centFV0A(); + return KinvalidCentrality; + } + + float getEfficiency(float mult, float pt, float eta, PIDIdx pidType, int effidx, bool cfgEff) const + { + if (!cfgEff) { + if (effidx == 0) + return 1.0; + if (effidx == 1) + return 0.0; + } + TH3F* h = nullptr; + if (effidx == 0) + h = state.hEff[pidType]; + if (effidx == 1) + h = state.hFake[pidType]; + + if (!h) + return -1; + const int ibx = h->GetXaxis()->FindBin(mult); + const int iby = h->GetYaxis()->FindBin(pt); + const int ibz = h->GetZaxis()->FindBin(eta); + float val = h->GetBinContent(ibx, iby, ibz); + return val; + } + + float getFlatteningWeight(float vz, float chg, float pt, float eta, float phi, PIDIdx pidType, bool cfgflat) const + { + if (!cfgflat) + return 1.0; + THnSparseF* h = state.hFlatWeight[pidType]; + + if (!h) + return 0.0; + int bins[5]; + bins[0] = h->GetAxis(0)->FindBin(vz); + bins[1] = h->GetAxis(1)->FindBin(chg); + bins[2] = h->GetAxis(2)->FindBin(pt); + bins[3] = h->GetAxis(3)->FindBin(eta); + bins[4] = h->GetAxis(4)->FindBin(phi); + float val = h->GetBinContent(bins); + + return val; + } + + std::vector* offsetFT0 = nullptr; + uint64_t mLastTimestamp = 0; + double getEtaFT0(uint64_t globalChno, int i) + { + if (i > 1 || i < 0) { + LOGF(fatal, "kFIT Index %d out of range", i); + } + auto chPos = ft0Det.getChannelCenter(globalChno); + auto x = chPos.X() + (*offsetFT0)[i].getX(); + auto y = chPos.Y() + (*offsetFT0)[i].getY(); + auto z = chPos.Z() + (*offsetFT0)[i].getZ(); + // i == 0 is FT0A (A-side, positive Z) + // i == 1 is FT0C (C-side, negative Z) + if (i == 1) { + z = -std::abs(z); + } else if (i == 0) { + z = std::abs(z); + } + auto r = std::sqrt(x * x + y * y); + auto theta = std::atan2(r, z); + return -std::log(std::tan(0.5 * theta)); + } + + void loadAlignParam(uint64_t timestamp) + { + if (timestamp == mLastTimestamp && offsetFT0 != nullptr) { + return; + } + offsetFT0 = ccdb->getForTimeStamp>("FT0/Calib/Align", timestamp); + mLastTimestamp = timestamp; + LOGF(info, "Successfully loaded new alignment parameters for timestamp %llu", timestamp); + LOGF(info, "Offset for FT0A: x = %.3f y = %.3f z = %.3f\n", (*offsetFT0)[0].getX(), (*offsetFT0)[0].getY(), (*offsetFT0)[0].getZ()); + LOGF(info, "Offset for FT0C: x = %.3f y = %.3f z = %.3f\n", (*offsetFT0)[1].getX(), (*offsetFT0)[1].getY(), (*offsetFT0)[1].getZ()); + } + + template + std::pair calculateMeanAndC2FromSums(const double sumpmwk[KIntM][KIntK], const double sumwk[KIntK], float referenceMeanPt) const + { + if (sumwk[1] == 0.) { + return {0.f, 0.f}; + } + + double tau1 = sumwk[2] / (sumwk[1] * sumwk[1]); + double denom2 = 1. - tau1; + + if (std::abs(denom2) < KFloatEpsilon) { + double pmk11safe = sumpmwk[1][1] / sumwk[1]; + return {static_cast(pmk11safe), 0.f}; + } + + double pmk11 = sumpmwk[1][1] / sumwk[1]; + + double pmk12 = 0.f; + if (sumwk[2] != 0.f) { + pmk12 = sumpmwk[1][2] / sumwk[2]; + } + + double pmk22 = 0.f; + if (sumwk[2] != 0.f) { + pmk22 = sumpmwk[2][2] / sumwk[2]; + } + + float calculatedMeanPt = pmk11; + + double p1kBar1 = pmk11 - referenceMeanPt; + double p2kBar2 = pmk22 - 2.0f * pmk12 * referenceMeanPt + referenceMeanPt * referenceMeanPt; + + double p1kBar1sq = p1kBar1 * p1kBar1; + double numerator2 = p1kBar1sq - (tau1 * p2kBar2); + + float twopcorr = numerator2 / denom2; + return {calculatedMeanPt, twopcorr}; + } + + using GeneralCollisions = soa::Join; + + Filter collisionFilter = nabs(aod::collision::posZ) < cfgVtxZCut; + using AodCollisionsSel = soa::Filtered; + + using UnfilteredTracks = soa::Join< + aod::Tracks, + aod::TracksExtra, + aod::TrackSelection, + aod::TracksDCA, + aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr, + aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr>; + Filter trackFilter = aod::track::pt > KPtMin&& + aod::track::pt < KPtMax&& + requireGlobalTrackInFilter(); + using AodTracksSel = soa::Filtered; + using TCs = soa::Join; + using FilteredTCs = soa::Filtered; + using BCsRun3 = soa::Join; + + using MyRun3MCCollisions = soa::Join< + aod::Collisions, aod::EvSels, aod::Mults, aod::MultsExtra, + aod::CentFT0Ms, aod::CentFDDMs, aod::CentFV0As, + aod::CentNGlobals, aod::McCollisionLabels>; + + using MyMCTracks = soa::Join< + aod::Tracks, aod::TrackSelection, aod::TracksExtra, aod::TracksDCA, + aod::McTrackLabels, + aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr, + aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr>; + + PresliceUnsorted partPerMcCollision = aod::mcparticle::mcCollisionId; + PresliceUnsorted colPerMcCollision = aod::mccollisionlabel::mcCollisionId; + PresliceUnsorted trackPerMcParticle = aod::mctracklabel::mcParticleId; + Preslice perCollision = aod::track::collisionId; + Preslice trackPerCollision = aod::track::collisionId; + + void declareCommonQA() + { + histos.add("hZvtx_after_sel", ";z_{vtx} (cm)", kTH1F, {{KNbinsZvtx, KZvtxMin, KZvtxMax}}); + histos.add("hVtxZ", ";z_{vtx} (cm)", kTH1F, {{KNbinsZvtx, KZvtxMin, KZvtxMax}}); + histos.add("hCentrality", ";centrality (%)", kTH1F, {{centAxis1Per}}); + histos.add("Hist2D_globalTracks_PVTracks", ";N_{global};N_{PV}", kTH2F, {{nChAxis2}, {nChAxis2}}); + histos.add("Hist2D_cent_nch", ";N_{PV};cent (%)", kTH2F, {{nChAxis2}, {centAxis1Per}}); + histos.add("hP", ";p (GeV/c)", kTH1F, {{KNbinsPt, KPMin, KPMax}}); + histos.add("hPt", ";p_{T} (GeV/c)", kTH1F, {{KNbinsPt, KPtMin, KPtMax}}); + histos.add("hEta", ";#eta", kTH1F, {{KNbinsEtaFine, KEtaMin, KEtaMax}}); + histos.add("hPhi", ";#phi", kTH1F, {{KNbinsPhi, KPhiMin, TwoPI}}); + } + + void declareMCCommonHists() + { + for (const auto& suf : pidSuffix) { + histos.add("h3_AllPrimary" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + histos.add("h3_RecoMatchedToPrimary" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + histos.add("h3_AllReco" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + histos.add("h3_RecoUnMatchedToPrimary_Secondary" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + histos.add("h3_RecoUnMatchedToPrimary_Fake" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + histos.add("h3_RecoMatchedToPrimary_MisID" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + } + + histos.add("ptResolution", ";p_{T}^{MC};(p_{T}^{reco}-p_{T}^{MC})/p_{T}^{MC}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {100, -0.2, 0.2}}); + histos.add("etaResolution", ";#eta^{MC};#eta^{reco}-#eta^{MC}", kTH2F, {{KNbinsEtaRes, -KEtaFineMax, KEtaFineMax}, {100, -0.02, 0.02}}); + histos.add("etaTruthReco", ";#eta^{MC};#eta^{reco}", kTH2F, {{KNbinsEtaRes, -KEtaFineMax, KEtaFineMax}, {KNbinsEtaRes, -KEtaFineMax, KEtaFineMax}}); + histos.add("TruthTracKVz", ";Vz^{MC};Vz^{Reco}", kTH2F, {{KNbinsVz, KVzMin, KVzMax}, {KNbinsVz, KVzMin, KVzMax}}); + histos.add("vzResolution", ";Vz^{MC};(Vz^{reco}-Vz^{MC})/Vz^{MC}", kTH2F, {{KNbinsVz, KVzMin, KVzMax}, {100, -0.1, 0.1}}); + } + + void declarenSigHists() + { + for (const auto& suf : pidSuffix) { + // Before Cuts + histos.add("h2DnsigmaTpcVsPtBeforeCut" + suf, "TPC nSigma vs pT Before Cut;p_{T} (GeV/c);n#sigma_{TPC}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); + histos.add("h2DnsigmaTofVsPtBeforeCut" + suf, "TOF nSigma vs pT Before Cut;p_{T} (GeV/c);n#sigma_{TOF}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); + histos.add("h2DnsigmaTpcVsTofBeforeCut" + suf, "TPC vs TOF nSigma Before Cut;n#sigma_{TOF};n#sigma_{TPC}", kTH2F, {{200, -10.f, 10.f}, {200, -10.f, 10.f}}); + + // After Cuts + histos.add("h2DnsigmaTpcVsPtAfterCut" + suf, "TPC nSigma vs pT After Cut;p_{T} (GeV/c);n#sigma_{TPC}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); + histos.add("h2DnsigmaTofVsPtAfterCut" + suf, "TOF nSigma vs pT After Cut;p_{T} (GeV/c);n#sigma_{TOF}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); + histos.add("h2DnsigmaTpcVsTofAfterCut" + suf, "TPC vs TOF nSigma After Cut;n#sigma_{TOF};n#sigma_{TPC}", kTH2F, {{200, -10.f, 10.f}, {200, -10.f, 10.f}}); + } + } + + void declareMCGetFlatHists() + { + for (const auto& suf : pidSuffix) { + histos.add("MCGen/hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("MCGen/hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("MCGen/hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + } + } + + void declareMCMeanHists() + { + histos.add("Eff_cent", ";cent", kTProfile, {centAxis1Per}); + histos.add("Eff_Ntrk", ";N_{PV}", kTProfile, {nChAxis2}); + histos.add("Eff_pT", ";p_{T}", kTProfile, {{KNbinsPtRes, KPtMin, KPtMax}}); + histos.add("Eff_eta", ";#eta", kTProfile, {{KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + + histos.add("Fake_cent", ";cent", kTProfile, {centAxis1Per}); + histos.add("Fake_Ntrk", ";N_{PV}", kTProfile, {nChAxis2}); + histos.add("Fake_pT", ";p_{T}", kTProfile, {{KNbinsPtRes, KPtMin, KPtMax}}); + histos.add("Fake_eta", ";#eta", kTProfile, {{KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + + histos.add("wgt_cent", ";cent", kTProfile, {centAxis1Per}); + histos.add("wgt_Ntrk", ";N_{PV}", kTProfile, {nChAxis2}); + histos.add("wgt_pT", ";p_{T}", kTProfile, {{KNbinsPtRes, KPtMin, KPtMax}}); + histos.add("wgt_eta", ";#eta", kTProfile, {{KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); + + histos.add("pmeanFT0Amultpv", ";N_{PV};Ampl", kTProfile, {nChAxis}); + histos.add("pmeanFT0Cmultpv", ";N_{PV};Ampl", kTProfile, {nChAxis}); + histos.add("pmeanFT0A_cent", ";cent;Ampl", kTProfile, {centAxis1Per}); + histos.add("pmeanFT0C_cent", ";cent;Ampl", kTProfile, {centAxis1Per}); + histos.add("pmean_cent_id_eta_FT0", ";cent;id;#eta", kTProfile3D, {{centAxis1Per}, {200, -0.5, 199.5}, {100, -5.0, 5.0}}); + histos.add("h3_cent_id_eta_FT0", ";cent;id;#eta", kTH3F, {{centAxis1Per}, {200, -0.5, 199.5}, {100, -5.0, 5.0}}); + + histos.add("MCGen/Prof_Cent_Nsp_Nchrec", ";cent;isp", kTProfile2D, {{centAxis1Per}, {spBinAxis}}); + histos.add("MCGen/Prof_Mult_Nsp_Nchrec", ";mult;isp", kTProfile2D, {{nChAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_Cent_Nsp_MeanpT", ";cent;isp", kTProfile2D, {{centAxis1Per}, {spBinAxis}}); + histos.add("MCGen/Prof_Mult_Nsp_MeanpT", ";mult;isp", kTProfile2D, {{nChAxis}, {spBinAxis}}); + + histos.add("pmeanTru_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("pmeanReco_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("pmeanRecoEffcorr_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + + histos.add("pmeanMultTru_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("pmeanMultReco_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("pmeanMultRecoEffcorr_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + + for (const auto& suf : pidSuffix) { + histos.add("hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + + histos.add("Prof2D_MeanpTSub_Tru" + suf, ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {etaBinAxis}}); + histos.add("Prof2D_MeanpTSub_Reco" + suf, ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {etaBinAxis}}); + histos.add("Prof2D_MeanpTSub_RecoEffCorr" + suf, ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {etaBinAxis}}); + } + } + + void declareMCFlucHists() + { + histos.add("MCGen/Prof_Cent_NEta_Nsp_Nchrec", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_Mult_NEta_Nsp_Nchrec", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_Cent_NEta_Nsp_MeanpT", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_Mult_NEta_Nsp_MeanpT", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + + histos.add("MCGen/Prof_MeanpT_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_C2_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_C2Sub_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_Cov_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_CovFT0A_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_CovFT0C_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); + + histos.add("MCGen/Prof_MeanpT_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_C2_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_C2Sub_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_Cov_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_CovFT0A_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + histos.add("MCGen/Prof_CovFT0C_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); + + for (const auto& suf : pidSuffix) { + histos.add("hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + + histos.add(Form("MCGen/Prof_C2Sub2D_Cent_etaA_etaC%s", suf.c_str()), ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + histos.add(Form("MCGen/Prof_GapSum2D%s", suf.c_str()), ";cent;gap;sum", kTProfile3D, {{centAxis1Per}, {gapAxis}, {sumAxis}}); + histos.add(Form("MCGen/Prof_Cov2D_Cent_etaA_etaC%s", suf.c_str()), ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + histos.add(Form("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC%s", suf.c_str()), ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + histos.add(Form("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC%s", suf.c_str()), ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + } + } + + void declareDataGetFlatHists() + { + for (const auto& suf : pidSuffix) { + histos.add("hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + } + histos.add("hnTrkPVZDC", ";N_{PV};ZDC_{A+C}", kTH2F, {{nChAxis2}, {200, 0, 3000}}); + histos.add("hNchZDC", ";N_{trk};ZDC_{A+C}", kTH2F, {{nChAxis2}, {200, 0, 30000}}); + histos.add("hCentnTrk", ";Centrality (%);N_{trk}", kTH2F, {{centAxis1Per}, {nChAxis2}}); + histos.add("hCentnTrkPV", ";Centrality (%);N_{trk, PV}", kTH2F, {{centAxis1Per}, {nChAxis2}}); + } + + void declareDataMeanHists() + { + histos.add("pmeanFT0Amultpv", "N_{PV}; AmplitudeA", kTProfile, {nChAxis}); + histos.add("pmeanFT0A_cent", "cent; AmplitudeA", kTProfile, {centAxis1Per}); + histos.add("pmeanFT0Cmultpv", "N_{PV}; AmplitudeA", kTProfile, {nChAxis}); + histos.add("pmeanFT0C_cent", "cent; AmplitudeA", kTProfile, {centAxis1Per}); + + histos.add("pmean_cent_id_eta_FT0", ";cent;channel id; #eta;amplitude", kTProfile3D, {{centAxis1Per}, {100, -0.5, 99.5}, {100, -5.0, 5.0}}); + histos.add("h3_cent_id_eta_FT0", ";cent;channel id; #eta", kTH3F, {{centAxis1Per}, {100, -0.5, 99.5}, {100, -5.0, 5.0}}); + + histos.add("Prof_Cent_Nsp_Nchrec", ";cent;Species;#LT N_{PV}#GT", kTProfile2D, {{centAxis1Per}, {spBinAxis}}); + histos.add("Prof_Mult_Nsp_Nchrec", ";N_{PV};Species;#LT N_{PV}#GT", kTProfile2D, {{nChAxis}, {spBinAxis}}); + histos.add("Prof_Cent_Nsp_MeanpT", ";cent;Species;#LT p_{T}#GT", kTProfile2D, {{centAxis1Per}, {spBinAxis}}); + histos.add("Prof_Mult_Nsp_MeanpT", ";N_{PV};Species;#LT p_{T}#GT", kTProfile2D, {{nChAxis}, {spBinAxis}}); + + histos.add("pmean_nch_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("pmeanMult_nch_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("pmean_cent_etabin_spbin", ";Centrality (%) ;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("pmeanMult_cent_etabin_spbin", ";Centrality (%) ;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); + + for (const auto& suf : pidSuffix) { + histos.add("hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + + histos.add("Prof2D_MeanpTSub" + suf, ";cent;#eta_{A} bin;#eta_{C} bin", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {{etaBinAxis}}}); + } + } + + void declareDataFlucHists() + { + histos.add("Prof_MeanpT_Cent_etabin_spbin", ";cent;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_MeanpT_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_C2_Cent_etabin_spbin", ";cent;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_C2_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + + histos.add("Prof_C2Sub_Cent_etabin_spbin", ";Centrality;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_C2Sub_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_Cov_Cent_etabin_spbin", ";Centrality;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_Cov_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + + histos.add("Prof_CovFT0A_Cent_etabin_spbin", ";Centrality;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_CovFT0A_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_CovFT0C_Cent_etabin_spbin", ";Centrality;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); + histos.add("Prof_CovFT0C_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); + + for (const auto& suf : pidSuffix) { + histos.add("hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + histos.add("Prof_C2Sub2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A};#eta_{C}", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + histos.add("Prof_GapSum2D" + suf, ";cent;#Delta#eta (Gap);#Sigma#eta/2 (Sum)", kTProfile3D, {{centAxis1Per}, {gapAxis}, {sumAxis}}); + histos.add("Prof_Cov2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A} bin;#eta_{C} bin", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + histos.add("Prof_CovFT0A2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A};#eta_{B}", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + histos.add("Prof_CovFT0C2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A};#eta_{B}", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + } + } + + THnSparseF* buildWeightMapFromRaw(THnSparseF* hRaw, const char* mapName) + { + if (!hRaw) { + LOGF(error, "Raw eta-phi map for '%s' is null; no flattening will be applied.", mapName); + return nullptr; + } + auto hWMap = reinterpret_cast(hRaw->Clone(mapName)); + hWMap->SetTitle(Form("Flattening Weight Map %s (w_{#phi} = / N_{#phi})", mapName)); + hWMap->Reset(); + auto axV = hRaw->GetAxis(0); // Vz + auto axChg = hRaw->GetAxis(1); // Charge + auto axPt = hRaw->GetAxis(2); // Pt + auto axE = hRaw->GetAxis(3); // Eta + auto axP = hRaw->GetAxis(4); // Phi + + int bins[5]; + for (int iv = 1; iv <= axV->GetNbins(); ++iv) { + bins[0] = iv; + for (int ichg = 1; ichg <= axChg->GetNbins(); ++ichg) { + bins[1] = ichg; + for (int ipt = 1; ipt <= axPt->GetNbins(); ++ipt) { + bins[2] = ipt; + for (int ie = 1; ie <= axE->GetNbins(); ++ie) { + bins[3] = ie; + double sum = 0.0; + int nphi = axP->GetNbins(); + for (int ip = 1; ip <= nphi; ++ip) { + bins[4] = ip; + sum += hRaw->GetBinContent(bins); + } + const double avg = (nphi > 0 ? sum / nphi : 0.0); + for (int ip = 1; ip <= nphi; ++ip) { + bins[4] = ip; + const double raw = hRaw->GetBinContent(bins); + const double w = (avg > 0.0 && raw > 0.0) ? (avg / raw) : 1.0; + hWMap->SetBinContent(bins, w); + } } + } + } + } + + LOGF(info, "Flattening weight map '%s' built.", mapName); + return hWMap; + } + + inline void loadTProfile3D(TDirectory* dir, const char* name, TProfile3D*& target) + { + if (!dir) { + LOGF(error, "loadTProfile3D: directory is null for object %s", name); + return; + } + auto* obj = dir->Get(name); + if (!obj) { + LOGF(error, "loadTProfile3D: object '%s' not found in directory %s", name, dir->GetName()); + return; + } + auto* prof = dynamic_cast(obj); + if (!prof) { + LOGF(error, "loadTProfile3D: object '%s' is not a TProfile3D (it is %s)", name, obj->ClassName()); + return; + } + target = reinterpret_cast(prof->Clone(Form("%s_clone", name))); + target->SetDirectory(nullptr); + LOGF(info, "Loaded TProfile3D '%s' with entries = %.0f", name, target->GetEntries()); + } + + void init(InitContext&) + { + if (cfgSys == kPbPb) { + nChAxis = {cfgNchPbMax / 4, KBinOffset, cfgNchPbMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; + nChAxis2 = {cfgNchPbMax / 20, KBinOffset, cfgNchPbMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; + } else if (cfgSys == kNeNe || cfgSys == kOO) { + nChAxis = {cfgNchOMax / 2, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; + nChAxis2 = {cfgNchOMax / 5, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; + } else { + nChAxis = {cfgNchOMax / 2, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; + nChAxis2 = {cfgNchOMax / 5, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; + } + + ccdb->setURL(cfgCCDBurl.value); + ccdb->setCaching(true); + ccdb->setLocalObjectValidityChecking(); + int64_t now = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + ccdb->setCreatedNotAfter(now); + + loadAlignParam(now); + ft0Det.calculateChannelCenter(); + + std::string sysDir = ""; + switch (cfgSys) { + case kPbPb: + sysDir = "PbPbTest"; + break; + case kNeNe: + sysDir = "NeNeTest"; + break; + case kOO: + sysDir = "OOTest"; + break; + case kpp: + sysDir = "ppTest"; + break; + default: + LOGF(fatal, "Invalid cfgSys value: %d", cfgSys.value); + } + + std::string pathEff = cfgCCDBUserPath.value + "/" + sysDir + "/Job1_EffMaps"; + std::string pathMCFlat = cfgCCDBUserPath.value + "/" + sysDir + "/Job1_MCFlatMaps"; + std::string pathMCMean = cfgCCDBUserPath.value + "/" + sysDir + "/Job2_MCMean"; + std::string pathDataFlat = cfgCCDBUserPath.value + "/" + sysDir + "/Job1_DataFlatMaps"; + std::string pathDataMean = cfgCCDBUserPath.value + "/" + sysDir + "/Job2_DataMean"; + + declareCommonQA(); + if (cfgRunGetEff || cfgRunGetDataFlat) { + declarenSigHists(); + } + if (cfgRunMCMean || cfgRunMCFluc || cfgRunGetEff) { + declareMCCommonHists(); + } + if (cfgRunMCMean) { + declareMCMeanHists(); + histos.addClone("MCGen/", "MCReco/"); + histos.addClone("MCGen/", "MCRecoEffCorr/"); + } + if (cfgRunMCFluc) { + declareMCFlucHists(); + histos.addClone("MCGen/", "MCReco/"); + histos.addClone("MCGen/", "MCRecoEffCorr/"); + } + if (cfgRunGetDataFlat) { + declareDataGetFlatHists(); + } + if (cfgRunGetMCFlat) { + declareMCGetFlatHists(); + histos.addClone("MCGen/", "MCReco/"); + histos.addClone("MCGen/", "MCRecoEffCorr/"); + } + if (cfgRunDataMean) { + declareDataMeanHists(); + } + if (cfgRunDataFluc) { + declareDataFlucHists(); + } + + if (!cfgRunGetEff && (cfgEff)) { + TList* lst = ccdb->getForTimeStamp(pathEff, now); + + if (!lst) { + LOGF(fatal, "Efficiency maps required but CCDB list is null at %s!", pathEff.c_str()); + } + + LOGF(info, "Loading Eff/Fake maps from TList for all species..."); + + auto loadEffFakeForPID = [&](PIDIdx pidType) { + std::string suffix = pidSuffix[pidType]; + std::string hEffNumName = "h3_RecoMatchedToPrimary" + suffix; + std::string hEffDenName = "h3_AllPrimary" + suffix; + std::string hFakeNumSecName = "h3_RecoUnMatchedToPrimary_Secondary" + suffix; + std::string hFakeNumFakName = "h3_RecoUnMatchedToPrimary_Fake" + suffix; + std::string hFakeNumFakName2 = "h3_RecoMatchedToPrimary_MisID" + suffix; + std::string hFakeDenName = "h3_AllReco" + suffix; + + auto* hNum = reinterpret_cast(lst->FindObject(hEffNumName.c_str())); + auto* hDen = reinterpret_cast(lst->FindObject(hEffDenName.c_str())); + + if (hNum && hDen) { + state.hEff[pidType] = reinterpret_cast(hNum->Clone(Form("hEff%s", suffix.c_str()))); + state.hEff[pidType]->SetDirectory(nullptr); + state.hEff[pidType]->Divide(hDen); + } else { + LOGF(error, "Missing CCDB objects for efficiency. Checked: %s, %s", hEffNumName.c_str(), hEffDenName.c_str()); + } + + auto* hNumS = reinterpret_cast(lst->FindObject(hFakeNumSecName.c_str())); + auto* hNumF = reinterpret_cast(lst->FindObject(hFakeNumFakName.c_str())); + auto* hNumF2 = reinterpret_cast(lst->FindObject(hFakeNumFakName2.c_str())); + auto* hDenF = reinterpret_cast(lst->FindObject(hFakeDenName.c_str())); + + if (hNumS && hNumF && hDenF) { + state.hFake[pidType] = reinterpret_cast(hNumS->Clone(Form("hFake%s", suffix.c_str()))); + state.hFake[pidType]->Add(hNumF); + // state.hFake[pidType]->Add(hNumF2); + state.hFake[pidType]->SetDirectory(nullptr); + state.hFake[pidType]->Divide(hDenF); + } else { + LOGF(error, "Missing CCDB object(s) for fakes for %s in list.", suffix.c_str()); + } + }; + + for (int i = 0; i < KNsp; ++i) { + loadEffFakeForPID(static_cast(i)); + } + } + + if (!cfgRunGetEff && (cfgFlat)) { + if (cfgRunDataMean || cfgRunDataFluc) { + LOGF(info, "Data Run: Loading flattening maps from %s", pathDataFlat.c_str()); + TList* lstDataFlat = ccdb->getForTimeStamp(pathDataFlat, now); + + if (lstDataFlat) { + for (int i = 0; i < KNsp; ++i) { + std::string suffix = pidSuffix[i]; + std::string hName; + + if (cfgEff && cfgFlat) { + hName = "hEtaPhiRecoWtd" + suffix; + } else if (cfgEff) { + hName = "hEtaPhiRecoEffWtd" + suffix; + } else { + hName = "hEtaPhiReco" + suffix; + } + auto* hRaw = reinterpret_cast(lstDataFlat->FindObject(hName.c_str())); - template - bool isEventSelected(const T& col) - { - if (!col.sel8()) - return false; - if (std::abs(col.posZ()) > cfgCutVertex) - return false; - if (cfgEvSelNoSameBunchPileup && !col.selection_bit(o2::aod::evsel::kNoSameBunchPileup)) - return false; - if (cfgUseGoodITSLayerAllCut && !col.selection_bit(o2::aod::evsel::kIsGoodITSLayersAll)) - return false; - if (cfgIsGoodZvtxFT0VsPV && !col.selection_bit(o2::aod::evsel::kIsGoodZvtxFT0vsPV)) - return false; - return true; + if (hRaw) { + state.hFlatWeight[i] = buildWeightMapFromRaw(hRaw, Form("hFlatWeight%s", suffix.c_str())); + } else { + LOGF(error, "Data flattening map '%s' not found.", hName.c_str()); + } } - - template - bool isTrackSelected(const T& trk) - { - if (trk.sign() == 0) - return false; - if (!trk.has_collision()) - return false; - if (!trk.isPVContributor()) - return false; - if (!(trk.itsNCls() > cfgITScluster)) - return false; - if (!(trk.tpcNClsFound() >= cfgTPCcluster)) - return false; - if (!(trk.tpcNClsCrossedRows() >= cfgTPCnCrossedRows)) - return false; - if (trk.pt() < cfgCutPtLower || trk.pt() > cfgCutPtUpper || std::abs(trk.eta()) > cfgCutEta) - return false; - // --- DCAxy Cut --- - if (cfgPtDepDCAxy) { - // Evaluates: 0.0026 + 0.005 / (pt^1.01) - float maxDcaXY = cfgDcaXyP0 + cfgDcaXyP1 / std::pow(trk.pt(), cfgDcaXyP2); - if (std::abs(trk.dcaXY()) > maxDcaXY) { - return false; // Reject track if DCA is too large - } + } else { + LOGF(error, "Could not retrieve Data Flattening TList from: %s", pathDataFlat.c_str()); + } + } + + if (cfgRunMCMean || cfgRunMCFluc) { + LOGF(info, "MC Run: Loading flattening maps from %s", pathMCFlat.c_str()); + TList* lstMCFlat = ccdb->getForTimeStamp(pathMCFlat, now); + + if (lstMCFlat) { + auto loadFlatForPID = [&](PIDIdx pidType) { + std::string suffix = pidSuffix[pidType]; + std::string hFlatSrcName; + if (cfgEff && cfgFlat) { + hFlatSrcName = "MCReco/hEtaPhiRecoWtd" + suffix; + } else if (cfgEff) { + hFlatSrcName = "MCReco/hEtaPhiRecoEffWtd" + suffix; } else { - if (std::abs(trk.dcaXY()) > cfgCutTracKDcaMaxXY) { - return false; - } + hFlatSrcName = "MCReco/hEtaPhiReco" + suffix; } - // --- DCAz Cut --- - if (cfgPtDepDCAz) { - // Evaluates: 0.0026 + 0.005 / (pt^1.01) - float maxDcaZ = cfgDcaZP0 + cfgDcaZP1 / std::pow(trk.pt(), cfgDcaZP2); - if (std::abs(trk.dcaZ()) > maxDcaZ) { - return false; // Reject track if DCA is too large - } + + auto* hRaw = reinterpret_cast(lstMCFlat->FindObject(hFlatSrcName.c_str())); + + if (hRaw) { + state.hFlatWeight[pidType] = buildWeightMapFromRaw(hRaw, Form("hFlatWeight%s", suffix.c_str())); } else { - if (std::abs(trk.dcaZ()) > cfgCutTracKDcaMaxZ) { - return false; - } + LOGF(warning, "MC flattening source '%s' not found in list.", hFlatSrcName.c_str()); } - return true; + }; + + for (int i = 0; i < KNsp; ++i) { + loadFlatForPID(static_cast(i)); + } + } else { + LOGF(error, "Could not retrieve MC Flattening TList from: %s", pathMCFlat.c_str()); + } + } + } + + auto loadTProfile3DFromList = [&](TList* sourceList, const char* objName, TProfile3D*& target) { + if (!sourceList) + return; + auto* tp = reinterpret_cast(sourceList->FindObject(objName)); + if (tp) { + target = reinterpret_cast(tp->Clone()); + target->SetDirectory(nullptr); + LOGF(info, "Loaded %s from list", objName); + } else { + LOGF(error, "Histogram %s missing in CCDB TList", objName); + } + }; + + auto loadTProfileFromList = [&](TList* sourceList, const char* objName, TProfile*& target) { + if (!sourceList) + return; + auto* tp = reinterpret_cast(sourceList->FindObject(objName)); + if (tp) { + target = reinterpret_cast(tp->Clone()); + target->SetDirectory(nullptr); + LOGF(info, "Loaded %s from list", objName); + } else { + LOGF(error, "Histogram %s missing in CCDB TList", objName); + } + }; + + if (cfgRunMCFluc) { + LOGF(info, "Loading MC Mean profiles from CCDB path: %s", pathMCMean.c_str()); + TList* lstMCMean = ccdb->getForTimeStamp(pathMCMean, now); + + if (lstMCMean) { + loadTProfileFromList(lstMCMean, "pmeanFT0Amultpv", state.pmeanFT0AmultpvStep2); + loadTProfileFromList(lstMCMean, "pmeanFT0Cmultpv", state.pmeanFT0CmultpvStep2); + + loadTProfile3DFromList(lstMCMean, "pmeanTru_nch_etabin_spbin", state.pmeanTruNchEtabinSpbinStep2); + loadTProfile3DFromList(lstMCMean, "pmeanReco_nch_etabin_spbin", state.pmeanRecoNchEtabinSpbinStep2); + loadTProfile3DFromList(lstMCMean, "pmeanRecoEffcorr_nch_etabin_spbin", state.pmeanRecoEffcorrNchEtabinSpbinStep2); + + loadTProfile3DFromList(lstMCMean, "pmeanMultTru_nch_etabin_spbin", state.pmeanMultTruNchEtabinSpbinStep2); + loadTProfile3DFromList(lstMCMean, "pmeanMultReco_nch_etabin_spbin", state.pmeanMultRecoNchEtabinSpbinStep2); + loadTProfile3DFromList(lstMCMean, "pmeanMultRecoEffcorr_nch_etabin_spbin", state.pmeanMultRecoEffcorrNchEtabinSpbinStep2); + } else { + LOGF(error, "Could not retrieve TList for MC Mean from: %s", pathMCMean.c_str()); + } + } + + if (cfgRunDataFluc) { + LOGF(info, "Loading Data Mean profiles from CCDB path: %s", pathDataMean.c_str()); + TList* lstDataMean = ccdb->getForTimeStamp(pathDataMean, now); + + if (lstDataMean) { + loadTProfileFromList(lstDataMean, "pmeanFT0Amultpv", state.pmeanFT0AmultpvStep2); + loadTProfileFromList(lstDataMean, "pmeanFT0Cmultpv", state.pmeanFT0CmultpvStep2); + + loadTProfile3DFromList(lstDataMean, "pmean_nch_etabin_spbin", state.pmeanNchEtabinSpbinStep2); + loadTProfile3DFromList(lstDataMean, "pmeanMult_nch_etabin_spbin", state.pmeanMultNchEtabinSpbinStep2); + } else { + LOGF(error, "Could not retrieve TList for Data Mean from: %s", pathDataMean.c_str()); + } + } + LOGF(info, "CCDB initialization complete for RadialFlowDecorr."); + } + + void processGetEffHists(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/, aod::McParticles const& mcParticles) + { + for (const auto& mcCollision : mcColl) { + auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); + if (colSlice.size() != 1) + continue; + + for (const auto& col : colSlice) { + if (!col.has_mcCollision() || !isEventSelected(col)) + continue; + + auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); + auto partSlice = mcParticles.sliceBy(partPerMcCollision, mcCollision.globalIndex()); + if (trackSlice.size() < 1 || partSlice.size() < 1) + continue; + + float cent = getCentrality(col); + if (cent > KCentMax) + continue; + float multPV = col.multNTracksPV(); + float vz = col.posZ(); + + for (const auto& particle : partSlice) { + if (!isParticleSelected(particle) || !particle.isPhysicalPrimary()) + continue; + + const int pdg = particle.pdgCode(); + const int absPdg = std::abs(pdg); + float pt = particle.pt(), eta = particle.eta(); + + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + pdg == -KPiPlus, // kPiMinusIdx + pdg == KPiPlus, // kPiPlusIdx + absPdg == KPiPlus, // kPiAllIdx + pdg == -KKPlus, // kKaMinusIdx + pdg == KKPlus, // kKaPlusIdx + absPdg == KKPlus, // kKaAllIdx + pdg == -KProton, // kAntiPrIdx + pdg == KProton, // kPrIdx + absPdg == KProton // kAllPrIdx + }; + + histos.fill(HIST("h3_AllPrimary"), multPV, pt, eta); + if (isSpecies[kPiMinusIdx]) + histos.fill(HIST("h3_AllPrimary_PiMinus"), multPV, pt, eta); + else if (isSpecies[kPiPlusIdx]) + histos.fill(HIST("h3_AllPrimary_PiPlus"), multPV, pt, eta); + if (isSpecies[kPiAllIdx]) + histos.fill(HIST("h3_AllPrimary_PiAll"), multPV, pt, eta); + + if (isSpecies[kKaMinusIdx]) + histos.fill(HIST("h3_AllPrimary_KaMinus"), multPV, pt, eta); + else if (isSpecies[kKaPlusIdx]) + histos.fill(HIST("h3_AllPrimary_KaPlus"), multPV, pt, eta); + if (isSpecies[kKaAllIdx]) + histos.fill(HIST("h3_AllPrimary_KaAll"), multPV, pt, eta); + + if (isSpecies[kAntiPrIdx]) + histos.fill(HIST("h3_AllPrimary_AntiPr"), multPV, pt, eta); + else if (isSpecies[kPrIdx]) + histos.fill(HIST("h3_AllPrimary_Pr"), multPV, pt, eta); + if (isSpecies[kAllPrIdx]) + histos.fill(HIST("h3_AllPrimary_AllPr"), multPV, pt, eta); + } + + histos.fill(HIST("hZvtx_after_sel"), col.posZ()); + histos.fill(HIST("hCentrality"), cent); + + histos.fill(HIST("Hist2D_globalTracks_PVTracks"), multPV, trackSlice.size()); + histos.fill(HIST("Hist2D_cent_nch"), trackSlice.size(), cent); + + for (const auto& track : trackSlice) { + if (!isTrackSelected(track)) + continue; + + float pt = track.pt(), eta = track.eta(); + auto sign = track.sign(); + if (sign > 0) { + // PiPlus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiPlus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiPlus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + // KaPlus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaPlus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaPlus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + // Pr + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_Pr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_Pr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + } else if (sign < 0) { + // PiMinus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiMinus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiMinus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + // KaMinus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaMinus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaMinus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + // AntiPr + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_AntiPr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_AntiPr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); } - template - bool isParticleSelected(const T& particle) - { - auto* pd = pdg->GetParticle(particle.pdgCode()); - if (!pd) - return false; - if (std::abs(pd->Charge()) == 0) - return false; - if (particle.pt() < cfgCutPtLower || particle.pt() > cfgCutPtUpper || std::abs(particle.eta()) > cfgCutEta) - return false; - if (std::abs(particle.vz()) > cfgCutVertex) - return false; - return true; + bool isPi = selectionPion(track); + bool isKa = selectionKaon(track); + bool isPr = selectionProton(track); + + bool isSpecies[KNsp] = { + true, + isPi && sign < 0, isPi && sign > 0, isPi, + isKa && sign < 0, isKa && sign > 0, isKa, + isPr && sign < 0, isPr && sign > 0, isPr}; + + if (isSpecies[kPiPlusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiPlus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiPlus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + } else if (isSpecies[kPiMinusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiMinus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiMinus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); } - template - bool selectionProton(const T& candidate) - { - if (!candidate.hasTPC()) - return false; - int flag = 0; - if (candidate.pt() > cfgCutPtLower && candidate.pt() <= cfgCutPtUpperTPC) { - if (!candidate.hasTOF() && std::abs(candidate.tpcNSigmaPr()) < cfgnSigmaCutTPC) { - flag = 1; + if (isSpecies[kKaPlusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaPlus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaPlus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + } else if (isSpecies[kKaMinusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaMinus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaMinus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + } + + if (isSpecies[kPrIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_Pr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_Pr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + } else if (isSpecies[kAntiPrIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_AntiPr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_AntiPr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + } + + for (int isp = 0; isp < KNsp; ++isp) { + if (!isSpecies[isp]) + continue; + + if (isp == kInclusiveIdx) { + histos.fill(HIST("h3_AllReco"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + int mcPdg = std::abs(mcP.pdgCode()); + if (mcPdg == KPiPlus || mcPdg == KKPlus || mcPdg == KProton) { + histos.fill(HIST("ptResolution"), mcP.pt(), (pt - mcP.pt()) / mcP.pt()); + histos.fill(HIST("etaResolution"), mcP.eta(), eta - mcP.eta()); + histos.fill(HIST("etaTruthReco"), mcP.eta(), eta); + histos.fill(HIST("vzResolution"), mcP.vz(), (vz - mcP.vz()) / mcP.vz()); + histos.fill(HIST("TruthTracKVz"), mcP.vz(), vz); + histos.fill(HIST("h3_RecoMatchedToPrimary"), multPV, mcP.pt(), mcP.eta()); + } else { + // Misidentified! Reconstructed track, but true particle is not pi/K/P + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake"), multPV, pt, eta); } - if (candidate.hasTOF() && std::abs(candidate.tpcNSigmaPr()) < cfgnSigmaCutTPC && std::abs(candidate.tofNSigmaPr()) < cfgnSigmaCutTOF) { - flag = 1; + }else if (isp == kPiMinusIdx) { + histos.fill(HIST("h3_AllReco_PiMinus"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (mcP.pdgCode() == -KPiPlus) { + histos.fill(HIST("h3_RecoMatchedToPrimary_PiMinus"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_PiMinus"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_PiMinus"), multPV, pt, eta); + } + } else { // No MC + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_PiMinus"), multPV, pt, eta); } - } - if (candidate.hasTOF() && candidate.pt() > cfgCutPtUpperTPC && candidate.pt() < cfgCutPtUpperPID) { - auto [combNSigmaPr, combNSigmaPi, combNSigmaKa] = getAllCombinedNSigmas(candidate); - int flag2 = 0; - if (combNSigmaPr < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaPi < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaKa < cfgnSigmaOtherParticles) - flag2 += 1; - if (!(flag2 > 1) && !(combNSigmaPr > combNSigmaPi) && !(combNSigmaPr > combNSigmaKa)) { - if (combNSigmaPr < cfgnSigmaCutCombTPCTOF) { - flag = 1; + }else if (isp == kPiPlusIdx) { + histos.fill(HIST("h3_AllReco_PiPlus"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (mcP.pdgCode() == KPiPlus) { + histos.fill(HIST("h3_RecoMatchedToPrimary_PiPlus"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_PiPlus"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_PiPlus"), multPV, pt, eta); } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_PiPlus"), multPV, pt, eta); } - } - if (flag == 1) - return true; - else - return false; - } - - template - bool selectionPion(const T& candidate) - { - if (!candidate.hasTPC()) - return false; - int flag = 0; - - if (candidate.pt() > cfgCutPtLower && candidate.pt() <= cfgCutPtUpperTPC) { - if (!candidate.hasTOF() && std::abs(candidate.tpcNSigmaPi()) < cfgnSigmaCutTPC) { - flag = 1; + }else if (isp == kPiAllIdx) { + histos.fill(HIST("h3_AllReco_PiAll"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (std::abs(mcP.pdgCode()) == KPiPlus) { + histos.fill(HIST("h3_RecoMatchedToPrimary_PiAll"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_PiAll"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_PiAll"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_PiAll"), multPV, pt, eta); } - if (candidate.hasTOF() && std::abs(candidate.tpcNSigmaPi()) < cfgnSigmaCutTPC && std::abs(candidate.tofNSigmaPi()) < cfgnSigmaCutTOF) { - flag = 1; + }else if (isp == kKaMinusIdx) { + histos.fill(HIST("h3_AllReco_KaMinus"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (mcP.pdgCode() == -KKPlus) { + histos.fill(HIST("h3_RecoMatchedToPrimary_KaMinus"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_KaMinus"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_KaMinus"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_KaMinus"), multPV, pt, eta); } - } - if (candidate.hasTOF() && candidate.pt() > cfgCutPtUpperTPC && candidate.pt() < cfgCutPtUpperPID) { - auto [combNSigmaPr, combNSigmaPi, combNSigmaKa] = getAllCombinedNSigmas(candidate); - int flag2 = 0; - if (combNSigmaPr < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaPi < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaKa < cfgnSigmaOtherParticles) - flag2 += 1; - if (!(flag2 > 1) && !(combNSigmaPi > combNSigmaPr) && !(combNSigmaPi > combNSigmaKa)) { - if (combNSigmaPi < cfgnSigmaCutCombTPCTOF) { - flag = 1; + }else if (isp == kKaPlusIdx) { + histos.fill(HIST("h3_AllReco_KaPlus"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (mcP.pdgCode() == KKPlus) { + histos.fill(HIST("h3_RecoMatchedToPrimary_KaPlus"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_KaPlus"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_KaPlus"), multPV, pt, eta); } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_KaPlus"), multPV, pt, eta); } - } - if (flag == 1) - return true; - else - return false; - } - - template - bool selectionKaon(const T& candidate) - { - if (!candidate.hasTPC()) - return false; - int flag = 0; - - if (candidate.pt() > cfgCutPtLower && candidate.pt() <= cfgCutPtUpperTPC) { - if (!candidate.hasTOF() && std::abs(candidate.tpcNSigmaKa()) < cfgnSigmaCutTPC) { - flag = 1; + }else if (isp == kKaAllIdx) { + histos.fill(HIST("h3_AllReco_KaAll"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (std::abs(mcP.pdgCode()) == KKPlus) { + histos.fill(HIST("h3_RecoMatchedToPrimary_KaAll"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_KaAll"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_KaAll"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_KaAll"), multPV, pt, eta); } - if (candidate.hasTOF() && std::abs(candidate.tpcNSigmaKa()) < cfgnSigmaCutTPC && std::abs(candidate.tofNSigmaKa()) < cfgnSigmaCutTOF) { - flag = 1; + }else if (isp == kAntiPrIdx) { + histos.fill(HIST("h3_AllReco_AntiPr"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (mcP.pdgCode() == -KProton) { + histos.fill(HIST("h3_RecoMatchedToPrimary_AntiPr"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_AntiPr"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_AntiPr"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_AntiPr"), multPV, pt, eta); } - } - if (candidate.hasTOF() && candidate.pt() > cfgCutPtUpperTPC && candidate.pt() < cfgCutPtUpperPID) { - auto [combNSigmaPr, combNSigmaPi, combNSigmaKa] = getAllCombinedNSigmas(candidate); - int flag2 = 0; - if (combNSigmaPr < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaPi < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaKa < cfgnSigmaOtherParticles) - flag2 += 1; - if (!(flag2 > 1) && !(combNSigmaKa > combNSigmaPi) && !(combNSigmaKa > combNSigmaPr)) { - if (combNSigmaKa < cfgnSigmaCutCombTPCTOF) { - flag = 1; + }else if (isp == kPrIdx) { + histos.fill(HIST("h3_AllReco_Pr"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (mcP.pdgCode() == KProton) { + histos.fill(HIST("h3_RecoMatchedToPrimary_Pr"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_Pr"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_Pr"), multPV, pt, eta); } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_Pr"), multPV, pt, eta); + } + }else if (isp == kAllPrIdx) { + histos.fill(HIST("h3_AllReco_AllPr"), multPV, pt, eta); + if (track.has_mcParticle()) { + auto mcP = track.mcParticle(); + if (mcP.isPhysicalPrimary()) { + if (std::abs(mcP.pdgCode()) == KProton) { + histos.fill(HIST("h3_RecoMatchedToPrimary_AllPr"), multPV, mcP.pt(), mcP.eta()); + } else { // Misidentified + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_AllPr"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_AllPr"), multPV, pt, eta); + } + } else { + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_AllPr"), multPV, pt, eta); } } - if (flag == 1) - return true; - else - return false; - } - - float getCentrality(const auto& col) const - { - if (cfgCentralityChoice.value == kCentFT0M) - return col.centFT0M(); - if (cfgCentralityChoice.value == kCentFDDM) - return col.centFDDM(); - if (cfgCentralityChoice.value == kCentFV0A) - return col.centFV0A(); - return KinvalidCentrality; } + } + } + } + } + PROCESS_SWITCH(RadialFlowDecorr, processGetEffHists, "process MC to calculate EffWeights", cfgRunGetEff); + + void processMCFlat(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/) + { + for (const auto& mcCollision : mcColl) { + auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); + if (colSlice.size() != 1) + continue; + + for (const auto& col : colSlice) { + if (!col.has_mcCollision() || !isEventSelected(col)) + continue; + + float cent = getCentrality(col); + if (cent > KCentMax) + continue; + + auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); + if (trackSlice.size() < 1) + continue; + + float multPV = col.multNTracksPV(); + float vz = col.posZ(); + + histos.fill(HIST("hZvtx_after_sel"), col.posZ()); + histos.fill(HIST("hCentrality"), cent); + + histos.fill(HIST("Hist2D_globalTracks_PVTracks"), col.multNTracksPV(), trackSlice.size()); + histos.fill(HIST("Hist2D_cent_nch"), trackSlice.size(), cent); + for (const auto& track : trackSlice) { + if (!isTrackSelected(track)) + continue; + + float pt = track.pt(), eta = track.eta(), phi = track.phi(); + auto sign = track.sign(); + bool isPi = selectionPion(track); + bool isKa = selectionKaon(track); + bool isPr = selectionProton(track); + + bool isSpecies[KNsp] = { + true, + isPi && sign < 0, isPi && sign > 0, isPi, + isKa && sign < 0, isKa && sign > 0, isKa, + isPr && sign < 0, isPr && sign > 0, isPr}; + + for (int isp = 0; isp < KNsp; ++isp) { + if (!isSpecies[isp]) + continue; - float getEfficiency(float mult, float pt, float eta, PIDIdx pidType, int effidx, bool cfgEff) const - { - if (!cfgEff) { - if (effidx == 0) - return 1.0; - if (effidx == 1) - return 0.0; + float eff = getEfficiency(multPV, pt, eta, static_cast(isp), 0, cfgEff); + float fake = getEfficiency(multPV, pt, eta, static_cast(isp), 1, cfgEff); + float w = (eff > KFloatEpsilon) ? (1.0f - fake) / eff : 0.0f; + + if (std::isfinite(w) && w > 0.f) { + if (isp == kInclusiveIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiMinusIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_PiMinus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_PiMinus"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_PiMinus"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiPlusIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_PiPlus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_PiPlus"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_PiPlus"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiAllIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_PiAll"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_PiAll"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_PiAll"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaMinusIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_KaMinus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_KaMinus"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_KaMinus"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaPlusIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_KaPlus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_KaPlus"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_KaPlus"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaAllIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_KaAll"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_KaAll"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_KaAll"), vz, sign, pt, eta, phi, w); + } else if (isp == kAntiPrIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); + } else if (isp == kPrIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_Pr"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); + } else if (isp == kAllPrIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); + } } - TH3F* h = nullptr; - if (effidx == 0) - h = state.hEff[pidType]; - if (effidx == 1) - h = state.hFake[pidType]; - - if (!h) - return -1; - const int ibx = h->GetXaxis()->FindBin(mult); - const int iby = h->GetYaxis()->FindBin(pt); - const int ibz = h->GetZaxis()->FindBin(eta); - float val = h->GetBinContent(ibx, iby, ibz); - return val; } + } + } + } + } + PROCESS_SWITCH(RadialFlowDecorr, processMCFlat, "process MC to calculate FlatWeights", cfgRunGetMCFlat); + + void processMCMean(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/, aod::FT0s const&, aod::McParticles const& mcParticles) + { + double sumWiTruth[KNsp][KNEta]{}, sumWiptiTruth[KNsp][KNEta]{}; + double sumWiReco[KNsp][KNEta]{}, sumWiptiReco[KNsp][KNEta]{}; + double sumWiRecoEffCorr[KNsp][KNEta]{}, sumWiptiRecoEffCorr[KNsp][KNEta]{}; + + for (const auto& mcCollision : mcColl) { + auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); + if (colSlice.size() != 1) + continue; + + for (const auto& col : colSlice) { + if (!col.has_mcCollision() || !isEventSelected(col)) + continue; + + auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); + auto partSlice = mcParticles.sliceBy(partPerMcCollision, mcCollision.globalIndex()); + if (trackSlice.size() < 1 || partSlice.size() < 1) + continue; + + float cent = getCentrality(col); + if (cent > KCentMax) + continue; + float multPV = col.multNTracksPV(); + float vz = col.posZ(); + + memset(sumWiTruth, 0, sizeof(sumWiTruth)); + memset(sumWiptiTruth, 0, sizeof(sumWiptiTruth)); + memset(sumWiReco, 0, sizeof(sumWiReco)); + memset(sumWiptiReco, 0, sizeof(sumWiptiReco)); + memset(sumWiRecoEffCorr, 0, sizeof(sumWiRecoEffCorr)); + memset(sumWiptiRecoEffCorr, 0, sizeof(sumWiptiRecoEffCorr)); + + for (const auto& particle : partSlice) { + if (!isParticleSelected(particle) || !particle.isPhysicalPrimary()) + continue; + float pt = particle.pt(), eta = particle.eta(); + if (pt <= cfgPtMin || pt > cfgPtMax) + continue; + int pdgCode = particle.pdgCode(); + int absPdg = std::abs(pdgCode); + + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + pdgCode == -KPiPlus, // kPiMinusIdx + pdgCode == KPiPlus, // kPiPlusIdx + absPdg == KPiPlus, // kPiAllIdx + pdgCode == -KKPlus, // kKaMinusIdx + pdgCode == KKPlus, // kKaPlusIdx + absPdg == KKPlus, // kKaAllIdx + pdgCode == -KProton, // kAntiPrIdx + pdgCode == KProton, // kPrIdx + absPdg == KProton // kAllPrIdx + }; - float getFlatteningWeight(float vz, float chg, float pt, float eta, float phi, PIDIdx pidType, bool cfgflat) const - { - if (!cfgflat) - return 1.0; - THnSparseF* h = state.hFlatWeight[pidType]; - - if (!h) - return 0.0; - int bins[5]; - bins[0] = h->GetAxis(0)->FindBin(vz); - bins[1] = h->GetAxis(1)->FindBin(chg); - bins[2] = h->GetAxis(2)->FindBin(pt); - bins[3] = h->GetAxis(3)->FindBin(eta); - bins[4] = h->GetAxis(4)->FindBin(phi); - float val = h->GetBinContent(bins); - - return val; - } + for (int ieta = 0; ieta < KNEta; ++ieta) { + if (eta <= etaLw[ieta] || eta > etaUp[ieta]) + continue; - std::vector* offsetFT0 = nullptr; - uint64_t mLastTimestamp = 0; - double getEtaFT0(uint64_t globalChno, int i) - { - if (i > 1 || i < 0) { - LOGF(fatal, "kFIT Index %d out of range", i); - } - auto chPos = ft0Det.getChannelCenter(globalChno); - auto x = chPos.X() + (*offsetFT0)[i].getX(); - auto y = chPos.Y() + (*offsetFT0)[i].getY(); - auto z = chPos.Z() + (*offsetFT0)[i].getZ(); - // i == 0 is FT0A (A-side, positive Z) - // i == 1 is FT0C (C-side, negative Z) - if (i == 1) { - z = -std::abs(z); - } else if (i == 0) { - z = std::abs(z); + for (int isp = 0; isp < KNsp; ++isp) { + if (isSpecies[isp]) { + sumWiTruth[isp][ieta]++; + sumWiptiTruth[isp][ieta] += pt; + } } - auto r = std::sqrt(x * x + y * y); - auto theta = std::atan2(r, z); - return -std::log(std::tan(0.5 * theta)); } - - void loadAlignParam(uint64_t timestamp) - { - if (timestamp == mLastTimestamp && offsetFT0 != nullptr) { - return; - } - offsetFT0 = ccdb->getForTimeStamp>("FT0/Calib/Align", timestamp); - mLastTimestamp = timestamp; - LOGF(info, "Successfully loaded new alignment parameters for timestamp %llu", timestamp); - LOGF(info, "Offset for FT0A: x = %.3f y = %.3f z = %.3f\n", (*offsetFT0)[0].getX(), (*offsetFT0)[0].getY(), (*offsetFT0)[0].getZ()); - LOGF(info, "Offset for FT0C: x = %.3f y = %.3f z = %.3f\n", (*offsetFT0)[1].getX(), (*offsetFT0)[1].getY(), (*offsetFT0)[1].getZ()); + } + + for (int isp = 0; isp < KNsp; ++isp) { + histos.fill(HIST("MCGen/Prof_Cent_Nsp_Nchrec"), cent, isp, sumWiTruth[isp][0]); + histos.fill(HIST("MCGen/Prof_Mult_Nsp_Nchrec"), multPV, isp, sumWiTruth[isp][0]); + if (sumWiTruth[isp][0] > 1.0f) { + histos.fill(HIST("MCGen/Prof_Cent_Nsp_MeanpT"), cent, isp, sumWiptiTruth[isp][0] / sumWiTruth[isp][0]); + histos.fill(HIST("MCGen/Prof_Mult_Nsp_MeanpT"), multPV, isp, sumWiptiTruth[isp][0] / sumWiTruth[isp][0]); } + } + + histos.fill(HIST("hZvtx_after_sel"), col.posZ()); + histos.fill(HIST("hCentrality"), cent); + + histos.fill(HIST("Hist2D_globalTracks_PVTracks"), col.multNTracksPV(), trackSlice.size()); + histos.fill(HIST("Hist2D_cent_nch"), trackSlice.size(), cent); + + for (const auto& track : trackSlice) { + if (!isTrackSelected(track)) + continue; + float pt = track.pt(), eta = track.eta(), phi = track.phi(); + if (pt <= cfgPtMin || pt > cfgPtMax) + continue; + auto sign = track.sign(); + bool isPi = selectionPion(track); + bool isKa = selectionKaon(track); + bool isPr = selectionProton(track); + + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + isPi && sign < 0, // kPiMinusIdx + isPi && sign > 0, // kPiPlusIdx + isPi, // kPiAllIdx + isKa && sign < 0, // kKaMinusIdx + isKa && sign > 0, // kKaPlusIdx + isKa, // kKaAllIdx + isPr && sign < 0, // kAntiPrIdx (Negative) + isPr && sign > 0, // kPrIdx (Positive) + isPr // kAllPrIdx + }; - template - std::pair calculateMeanAndC2FromSums(const double sumpmwk[KIntM][KIntK], const double sumwk[KIntK], float referenceMeanPt) const - { - if (sumwk[1] == 0.) { - return {0.f, 0.f}; + for (int isp = 0; isp < KNsp; ++isp) { + if (!isSpecies[isp]) + continue; + float eff = getEfficiency(multPV, pt, eta, static_cast(isp), 0, cfgEff); + float fake = getEfficiency(multPV, pt, eta, static_cast(isp), 1, cfgEff); + float flatW = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); + float w = flatW * (1.0 - fake) / eff; + if (!std::isfinite(w) || w <= 0.f || eff <= KFloatEpsilon) + continue; + + for (int ieta = 0; ieta < KNEta; ++ieta) { + if (eta <= etaLw[ieta] || eta > etaUp[ieta]) + continue; + sumWiReco[isp][ieta]++; + sumWiptiReco[isp][ieta] += pt; + sumWiRecoEffCorr[isp][ieta] += w; + sumWiptiRecoEffCorr[isp][ieta] += w * pt; } - double tau1 = sumwk[2] / (sumwk[1] * sumwk[1]); - double denom2 = 1. - tau1; + if (isp == kInclusiveIdx) { + histos.fill(HIST("Eff_cent"), cent, eff); + histos.fill(HIST("Fake_cent"), cent, fake); + histos.fill(HIST("wgt_cent"), cent, w); - if (std::abs(denom2) < KFloatEpsilon) { - double pmk11safe = sumpmwk[1][1] / sumwk[1]; - return {static_cast(pmk11safe), 0.f}; - } + histos.fill(HIST("Eff_Ntrk"), multPV, eff); + histos.fill(HIST("Fake_Ntrk"), multPV, fake); + histos.fill(HIST("wgt_Ntrk"), multPV, w); - double pmk11 = sumpmwk[1][1] / sumwk[1]; + histos.fill(HIST("Eff_pT"), pt, eff); + histos.fill(HIST("Fake_pT"), pt, fake); + histos.fill(HIST("wgt_pT"), pt, w); - double pmk12 = 0.f; - if (sumwk[2] != 0.f) { - pmk12 = sumpmwk[1][2] / sumwk[2]; + histos.fill(HIST("Eff_eta"), eta, eff); + histos.fill(HIST("Fake_eta"), eta, fake); + histos.fill(HIST("wgt_eta"), eta, w); } - double pmk22 = 0.f; - if (sumwk[2] != 0.f) { - pmk22 = sumpmwk[2][2] / sumwk[2]; + if (isp == kInclusiveIdx) { + histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPiMinusIdx) { + histos.fill(HIST("hEtaPhiReco_PiMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_PiMinus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiMinus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPiPlusIdx) { + histos.fill(HIST("hEtaPhiReco_PiPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_PiPlus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiPlus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPiAllIdx) { + histos.fill(HIST("hEtaPhiReco_PiAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_PiAll"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiAll"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kKaMinusIdx) { + histos.fill(HIST("hEtaPhiReco_KaMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_KaMinus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaMinus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kKaPlusIdx) { + histos.fill(HIST("hEtaPhiReco_KaPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_KaPlus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaPlus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kKaAllIdx) { + histos.fill(HIST("hEtaPhiReco_KaAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_KaAll"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaAll"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPrIdx) { + histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kAntiPrIdx) { + histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kAllPrIdx) { + histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); } + } + } - float calculatedMeanPt = pmk11; - - double p1kBar1 = pmk11 - referenceMeanPt; - double p2kBar2 = pmk22 - 2.0f * pmk12 * referenceMeanPt + referenceMeanPt * referenceMeanPt; + for (int isp = 0; isp < KNsp; ++isp) { + histos.fill(HIST("MCReco/Prof_Cent_Nsp_Nchrec"), cent, isp, sumWiReco[isp][0]); + histos.fill(HIST("MCReco/Prof_Mult_Nsp_Nchrec"), multPV, isp, sumWiReco[isp][0]); - double p1kBar1sq = p1kBar1 * p1kBar1; - double numerator2 = p1kBar1sq - (tau1 * p2kBar2); + histos.fill(HIST("MCRecoEffCorr/Prof_Cent_Nsp_Nchrec"), cent, isp, sumWiRecoEffCorr[isp][0]); + histos.fill(HIST("MCRecoEffCorr/Prof_Mult_Nsp_Nchrec"), multPV, isp, sumWiRecoEffCorr[isp][0]); - float twopcorr = numerator2 / denom2; - return {calculatedMeanPt, twopcorr}; + if (sumWiReco[isp][0] > 1.0f) { + histos.fill(HIST("MCReco/Prof_Cent_Nsp_MeanpT"), cent, isp, sumWiptiReco[isp][0] / sumWiReco[isp][0]); + histos.fill(HIST("MCReco/Prof_Mult_Nsp_MeanpT"), multPV, isp, sumWiptiReco[isp][0] / sumWiReco[isp][0]); } - - using GeneralCollisions = soa::Join; - - Filter collisionFilter = nabs(aod::collision::posZ) < cfgVtxZCut; - using AodCollisionsSel = soa::Filtered; - - using UnfilteredTracks = soa::Join< - aod::Tracks, - aod::TracksExtra, - aod::TrackSelection, - aod::TracksDCA, - aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr, - aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr>; - Filter trackFilter = aod::track::pt > KPtMin&& - aod::track::pt < KPtMax&& - requireGlobalTrackInFilter(); - using AodTracksSel = soa::Filtered; - using TCs = soa::Join; - using FilteredTCs = soa::Filtered; - using BCsRun3 = soa::Join; - - using MyRun3MCCollisions = soa::Join< - aod::Collisions, aod::EvSels, aod::Mults, aod::MultsExtra, - aod::CentFT0Ms,aod::CentFDDMs,aod::CentFV0As, - aod::CentNGlobals, aod::McCollisionLabels>; - - using MyMCTracks = soa::Join< - aod::Tracks, aod::TrackSelection, aod::TracksExtra, aod::TracksDCA, - aod::McTrackLabels, - aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr, - aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr>; - - PresliceUnsorted partPerMcCollision = aod::mcparticle::mcCollisionId; - PresliceUnsorted colPerMcCollision = aod::mccollisionlabel::mcCollisionId; - PresliceUnsorted trackPerMcParticle = aod::mctracklabel::mcParticleId; - Preslice perCollision = aod::track::collisionId; - Preslice trackPerCollision = aod::track::collisionId; - - void declareCommonQA() - { - histos.add("hZvtx_after_sel", ";z_{vtx} (cm)", kTH1F, {{KNbinsZvtx, KZvtxMin, KZvtxMax}}); - histos.add("hVtxZ", ";z_{vtx} (cm)", kTH1F, {{KNbinsZvtx, KZvtxMin, KZvtxMax}}); - histos.add("hCentrality", ";centrality (%)", kTH1F, {{centAxis1Per}}); - histos.add("Hist2D_globalTracks_PVTracks", ";N_{global};N_{PV}", kTH2F, {{nChAxis2}, {nChAxis2}}); - histos.add("Hist2D_cent_nch", ";N_{PV};cent (%)", kTH2F, {{nChAxis2}, {centAxis1Per}}); - histos.add("hP", ";p (GeV/c)", kTH1F, {{KNbinsPt, KPMin, KPMax}}); - histos.add("hPt", ";p_{T} (GeV/c)", kTH1F, {{KNbinsPt, KPtMin, KPtMax}}); - histos.add("hEta", ";#eta", kTH1F, {{KNbinsEtaFine, KEtaMin, KEtaMax}}); - histos.add("hPhi", ";#phi", kTH1F, {{KNbinsPhi, KPhiMin, TwoPI}}); + if (sumWiRecoEffCorr[isp][0] > 1.0f) { + histos.fill(HIST("MCRecoEffCorr/Prof_Cent_Nsp_MeanpT"), cent, isp, sumWiptiRecoEffCorr[isp][0] / sumWiRecoEffCorr[isp][0]); + histos.fill(HIST("MCRecoEffCorr/Prof_Mult_Nsp_MeanpT"), multPV, isp, sumWiptiRecoEffCorr[isp][0] / sumWiRecoEffCorr[isp][0]); } + } + + for (int ietaA = 0; ietaA < KNEta; ++ietaA) { + for (int ietaC = 0; ietaC < KNEta; ++ietaC) { + for (int isp = 0; isp < KNsp; ++isp) { + float nTruAB = sumWiTruth[isp][ietaA] + sumWiTruth[isp][ietaC]; + float nRecoAB = sumWiReco[isp][ietaA] + sumWiReco[isp][ietaC]; + float nCorrAB = sumWiRecoEffCorr[isp][ietaA] + sumWiRecoEffCorr[isp][ietaC]; + + float mptsubTru = (sumWiptiTruth[isp][ietaA] + sumWiptiTruth[isp][ietaC]) / nTruAB; + float mptsubReco = (sumWiptiReco[isp][ietaA] + sumWiptiReco[isp][ietaC]) / nRecoAB; + float mptsubRecoEffCorr = (sumWiptiRecoEffCorr[isp][ietaA] + sumWiptiRecoEffCorr[isp][ietaC]) / nCorrAB; + + if (nTruAB > 0) { + if (isp == kInclusiveIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kPiMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_PiMinus"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kPiPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_PiPlus"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kPiAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_PiAll"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kKaMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_KaMinus"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kKaPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_KaPlus"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kKaAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_KaAll"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_Pr"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kAntiPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_AntiPr"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kAllPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_AllPr"), cent, ietaA, ietaC, mptsubTru); + } - void declareMCCommonHists() - { - for (const auto& suf : pidSuffix) { - histos.add("h3_AllPrimary" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - histos.add("h3_RecoMatchedToPrimary" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - histos.add("h3_AllReco" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - histos.add("h3_RecoUnMatchedToPrimary_Secondary" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - histos.add("h3_RecoUnMatchedToPrimary_Fake" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - histos.add("h3_RecoMatchedToPrimary_MisID" + suf, ";N_{PV};p_{T};#eta", kTH3F, {{nChAxis2}, {KNbinsPtRes, KPtMin, KPtMax}, {KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - } - - histos.add("ptResolution", ";p_{T}^{MC};(p_{T}^{reco}-p_{T}^{MC})/p_{T}^{MC}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {100, -0.2, 0.2}}); - histos.add("etaResolution", ";#eta^{MC};#eta^{reco}-#eta^{MC}", kTH2F, {{KNbinsEtaRes, -KEtaFineMax, KEtaFineMax}, {100, -0.02, 0.02}}); - histos.add("etaTruthReco", ";#eta^{MC};#eta^{reco}", kTH2F, {{KNbinsEtaRes, -KEtaFineMax, KEtaFineMax}, {KNbinsEtaRes, -KEtaFineMax, KEtaFineMax}}); - histos.add("TruthTracKVz", ";Vz^{MC};Vz^{Reco}", kTH2F, {{KNbinsVz, KVzMin, KVzMax}, {KNbinsVz, KVzMin, KVzMax}}); - histos.add("vzResolution", ";Vz^{MC};(Vz^{reco}-Vz^{MC})/Vz^{MC}", kTH2F, {{KNbinsVz, KVzMin, KVzMax}, {100, -0.1, 0.1}}); - } + if (nRecoAB > 0) { + if (isp == kInclusiveIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kPiMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_PiMinus"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kPiPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_PiPlus"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kPiAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_PiAll"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kKaMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_KaMinus"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kKaPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_KaPlus"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kKaAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_KaAll"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_Pr"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kAntiPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_AntiPr"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kAllPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_AllPr"), cent, ietaA, ietaC, mptsubReco); + } - void declarenSigHists() - { - for (const auto& suf : pidSuffix) { - // Before Cuts - histos.add("h2DnsigmaTpcVsPtBeforeCut" + suf, "TPC nSigma vs pT Before Cut;p_{T} (GeV/c);n#sigma_{TPC}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); - histos.add("h2DnsigmaTofVsPtBeforeCut" + suf, "TOF nSigma vs pT Before Cut;p_{T} (GeV/c);n#sigma_{TOF}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); - histos.add("h2DnsigmaTpcVsTofBeforeCut" + suf, "TPC vs TOF nSigma Before Cut;n#sigma_{TOF};n#sigma_{TPC}", kTH2F, {{200, -10.f, 10.f}, {200, -10.f, 10.f}}); - - // After Cuts - histos.add("h2DnsigmaTpcVsPtAfterCut" + suf, "TPC nSigma vs pT After Cut;p_{T} (GeV/c);n#sigma_{TPC}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); - histos.add("h2DnsigmaTofVsPtAfterCut" + suf, "TOF nSigma vs pT After Cut;p_{T} (GeV/c);n#sigma_{TOF}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); - histos.add("h2DnsigmaTpcVsTofAfterCut" + suf, "TPC vs TOF nSigma After Cut;n#sigma_{TOF};n#sigma_{TPC}", kTH2F, {{200, -10.f, 10.f}, {200, -10.f, 10.f}}); + if (nCorrAB > 0) { + if (isp == kInclusiveIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kPiMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_PiMinus"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kPiPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_PiPlus"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kPiAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_PiAll"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kKaMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_KaMinus"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kKaPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_KaPlus"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kKaAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_KaAll"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_Pr"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kAntiPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_AntiPr"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kAllPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_AllPr"), cent, ietaA, ietaC, mptsubRecoEffCorr); + } } } - void declareMCGetFlatHists() - { - for (const auto& suf : pidSuffix) { - histos.add("MCGen/hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - histos.add("MCGen/hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - histos.add("MCGen/hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + for (int isp = 0; isp < KNsp; ++isp) { + if (sumWiTruth[isp][ietaA] > 0) { + float val = sumWiptiTruth[isp][ietaA] / sumWiTruth[isp][ietaA]; + histos.fill(HIST("pmeanTru_nch_etabin_spbin"), multPV, ietaA, isp, val); + histos.fill(HIST("pmeanMultTru_nch_etabin_spbin"), multPV, ietaA, isp, sumWiTruth[isp][ietaA]); } - } - - void declareMCMeanHists() - { - histos.add("Eff_cent", ";cent", kTProfile, {centAxis1Per}); - histos.add("Eff_Ntrk", ";N_{PV}", kTProfile, {nChAxis2}); - histos.add("Eff_pT", ";p_{T}", kTProfile, {{KNbinsPtRes, KPtMin, KPtMax}}); - histos.add("Eff_eta", ";#eta", kTProfile, {{KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - - histos.add("Fake_cent", ";cent", kTProfile, {centAxis1Per}); - histos.add("Fake_Ntrk", ";N_{PV}", kTProfile, {nChAxis2}); - histos.add("Fake_pT", ";p_{T}", kTProfile, {{KNbinsPtRes, KPtMin, KPtMax}}); - histos.add("Fake_eta", ";#eta", kTProfile, {{KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - - histos.add("wgt_cent", ";cent", kTProfile, {centAxis1Per}); - histos.add("wgt_Ntrk", ";N_{PV}", kTProfile, {nChAxis2}); - histos.add("wgt_pT", ";p_{T}", kTProfile, {{KNbinsPtRes, KPtMin, KPtMax}}); - histos.add("wgt_eta", ";#eta", kTProfile, {{KNbinsEtaFine, -KEtaFineMax, KEtaFineMax}}); - - histos.add("pmeanFT0Amultpv", ";N_{PV};Ampl", kTProfile, {nChAxis}); - histos.add("pmeanFT0Cmultpv", ";N_{PV};Ampl", kTProfile, {nChAxis}); - histos.add("pmeanFT0A_cent", ";cent;Ampl", kTProfile, {centAxis1Per}); - histos.add("pmeanFT0C_cent", ";cent;Ampl", kTProfile, {centAxis1Per}); - histos.add("pmean_cent_id_eta_FT0", ";cent;id;#eta", kTProfile3D, {{centAxis1Per}, {200, -0.5, 199.5}, {100, -5.0, 5.0}}); - histos.add("h3_cent_id_eta_FT0", ";cent;id;#eta", kTH3F, {{centAxis1Per}, {200, -0.5, 199.5}, {100, -5.0, 5.0}}); - - histos.add("MCGen/Prof_Cent_Nsp_Nchrec", ";cent;isp", kTProfile2D, {{centAxis1Per}, {spBinAxis}}); - histos.add("MCGen/Prof_Mult_Nsp_Nchrec", ";mult;isp", kTProfile2D, {{nChAxis}, {spBinAxis}}); - histos.add("MCGen/Prof_Cent_Nsp_MeanpT", ";cent;isp", kTProfile2D, {{centAxis1Per}, {spBinAxis}}); - histos.add("MCGen/Prof_Mult_Nsp_MeanpT", ";mult;isp", kTProfile2D, {{nChAxis}, {spBinAxis}}); - - histos.add("pmeanTru_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); - histos.add("pmeanReco_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); - histos.add("pmeanRecoEffcorr_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); - - histos.add("pmeanMultTru_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); - histos.add("pmeanMultReco_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); - histos.add("pmeanMultRecoEffcorr_nch_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); - - for (const auto& suf : pidSuffix) { - histos.add("hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - histos.add("hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - histos.add("hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - - histos.add("Prof2D_MeanpTSub_Tru" + suf, ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {etaBinAxis}}); - histos.add("Prof2D_MeanpTSub_Reco" + suf, ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {etaBinAxis}}); - histos.add("Prof2D_MeanpTSub_RecoEffCorr" + suf, ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {etaBinAxis}}); + if (sumWiReco[isp][ietaA] > 0) { + float val = sumWiptiReco[isp][ietaA] / sumWiReco[isp][ietaA]; + histos.fill(HIST("pmeanReco_nch_etabin_spbin"), multPV, ietaA, isp, val); + histos.fill(HIST("pmeanMultReco_nch_etabin_spbin"), multPV, ietaA, isp, sumWiReco[isp][ietaA]); } - } - - void declareMCFlucHists() - { - histos.add("MCGen/Prof_Cent_NEta_Nsp_Nchrec", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); - histos.add("MCGen/Prof_Mult_NEta_Nsp_Nchrec", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); - histos.add("MCGen/Prof_Cent_NEta_Nsp_MeanpT", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); - histos.add("MCGen/Prof_Mult_NEta_Nsp_MeanpT", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); - - histos.add("MCGen/Prof_MeanpT_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); - histos.add("MCGen/Prof_C2_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); - histos.add("MCGen/Prof_C2Sub_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); - histos.add("MCGen/Prof_Cov_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); - histos.add("MCGen/Prof_CovFT0A_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); - histos.add("MCGen/Prof_CovFT0C_Cent_etabin_spbin", ";cent;eta;isp", kTProfile3D, {{centAxis1Per}, {etaBinAxis}, {spBinAxis}}); - - histos.add("MCGen/Prof_MeanpT_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); - histos.add("MCGen/Prof_C2_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); - histos.add("MCGen/Prof_C2Sub_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); - histos.add("MCGen/Prof_Cov_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); - histos.add("MCGen/Prof_CovFT0A_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); - histos.add("MCGen/Prof_CovFT0C_Mult_etabin_spbin", ";mult;eta;isp", kTProfile3D, {{nChAxis}, {etaBinAxis}, {spBinAxis}}); - - for (const auto& suf : pidSuffix) { - histos.add("hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - histos.add("hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - histos.add("hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - - histos.add(Form("MCGen/Prof_C2Sub2D_Cent_etaA_etaC%s", suf.c_str()), ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); - histos.add(Form("MCGen/Prof_GapSum2D%s", suf.c_str()), ";cent;gap;sum", kTProfile3D, {{centAxis1Per}, {gapAxis}, {sumAxis}}); - histos.add(Form("MCGen/Prof_Cov2D_Cent_etaA_etaC%s", suf.c_str()), ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); - histos.add(Form("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC%s", suf.c_str()), ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); - histos.add(Form("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC%s", suf.c_str()), ";cent;etaA;etaC", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); + if (sumWiRecoEffCorr[isp][ietaA] > 0) { + float val = sumWiptiRecoEffCorr[isp][ietaA] / sumWiRecoEffCorr[isp][ietaA]; + histos.fill(HIST("pmeanRecoEffcorr_nch_etabin_spbin"), multPV, ietaA, isp, val); + histos.fill(HIST("pmeanMultRecoEffcorr_nch_etabin_spbin"), multPV, ietaA, isp, sumWiRecoEffCorr[isp][ietaA]); } } + } // end ietaA + + double amplFT0A = 0, amplFT0C = 0; + if (col.has_foundFT0()) { + const auto& ft0 = col.foundFT0(); + for (std::size_t iCh = 0; iCh < ft0.channelA().size(); iCh++) { + auto chanelid = ft0.channelA()[iCh]; + float ampl = ft0.amplitudeA()[iCh]; + amplFT0A += ampl; + auto eta = getEtaFT0(chanelid, 0); + histos.fill(HIST("pmean_cent_id_eta_FT0"), cent, chanelid, eta, ampl); + histos.fill(HIST("h3_cent_id_eta_FT0"), cent, chanelid, eta, ampl); + } + for (std::size_t iCh = 0; iCh < ft0.channelC().size(); iCh++) { + auto chanelid = ft0.channelC()[iCh]; + auto globalId = chanelid + KnFt0cCell; + float ampl = ft0.amplitudeC()[iCh]; + auto eta = getEtaFT0(globalId, 1); + amplFT0C += ampl; + histos.fill(HIST("pmean_cent_id_eta_FT0"), cent, globalId, eta, ampl); + histos.fill(HIST("h3_cent_id_eta_FT0"), cent, globalId, eta, ampl); + } + } + + histos.fill(HIST("pmeanFT0Amultpv"), multPV, amplFT0A); + histos.fill(HIST("pmeanFT0A_cent"), cent, amplFT0A); + histos.fill(HIST("pmeanFT0Cmultpv"), multPV, amplFT0C); + histos.fill(HIST("pmeanFT0C_cent"), cent, amplFT0C); + } + } + } + PROCESS_SWITCH(RadialFlowDecorr, processMCMean, "process MC to calculate mean pt and Eff Hists", cfgRunMCMean); + + void processMCFluc(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/, aod::FT0s const&, aod::McParticles const& mcParticles) + { + if (!state.pmeanTruNchEtabinSpbinStep2 || !state.pmeanRecoNchEtabinSpbinStep2 || !state.pmeanRecoEffcorrNchEtabinSpbinStep2 || + !state.pmeanMultTruNchEtabinSpbinStep2 || !state.pmeanMultRecoNchEtabinSpbinStep2 || !state.pmeanMultRecoEffcorrNchEtabinSpbinStep2) { + LOGF(warning, "MC fluc: Unified Mean pT or Mult map missing"); + return; + } + double sumPmwkTru[KNsp][KNEta][KIntM][KIntK]{}; + double sumWkTru[KNsp][KNEta][KIntK]{}; + double sumPmwkReco[KNsp][KNEta][KIntM][KIntK]{}; + double sumWkReco[KNsp][KNEta][KIntK]{}; + double sumPmwkRecoEffCor[KNsp][KNEta][KIntM][KIntK]{}; + double sumWkRecoEffCor[KNsp][KNEta][KIntK]{}; + + double meanTru[KNsp][KNEta]{}, c2Tru[KNsp][KNEta]{}; + double meanReco[KNsp][KNEta]{}, c2Reco[KNsp][KNEta]{}; + double meanRecoEffCor[KNsp][KNEta]{}, c2RecoEffCor[KNsp][KNEta]{}; + + double meanTruMult[KNsp][KNEta]{}; + double meanRecoMult[KNsp][KNEta]{}; + double meanRecoEffCorMult[KNsp][KNEta]{}; + + double p1kBarTru[KNsp][KNEta]{}, p1kBarReco[KNsp][KNEta]{}, p1kBarRecoEffCor[KNsp][KNEta]{}; + double p1kBarTruMult[KNsp][KNEta]{}, p1kBarRecoMult[KNsp][KNEta]{}, p1kBarRecoEffCorMult[KNsp][KNEta]{}; + + for (const auto& mcCollision : mcColl) { + auto partSlice = mcParticles.sliceBy(partPerMcCollision, mcCollision.globalIndex()); + auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); + if (colSlice.size() != 1) + continue; + + for (const auto& col : colSlice) { + if (!col.has_mcCollision() || !isEventSelected(col)) + continue; + + auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); + if (trackSlice.size() < 1) + continue; + + float cent = getCentrality(col); + if (cent > KCentMax) + continue; + float multPV = col.multNTracksPV(); + + memset(sumPmwkTru, 0, sizeof(sumPmwkTru)); + memset(sumWkTru, 0, sizeof(sumWkTru)); + memset(sumPmwkReco, 0, sizeof(sumPmwkReco)); + memset(sumWkReco, 0, sizeof(sumWkReco)); + memset(sumPmwkRecoEffCor, 0, sizeof(sumPmwkRecoEffCor)); + memset(sumWkRecoEffCor, 0, sizeof(sumWkRecoEffCor)); + + memset(meanTru, 0, sizeof(meanTru)); + memset(c2Tru, 0, sizeof(c2Tru)); + memset(meanReco, 0, sizeof(meanReco)); + memset(c2Reco, 0, sizeof(c2Reco)); + memset(meanRecoEffCor, 0, sizeof(meanRecoEffCor)); + memset(c2RecoEffCor, 0, sizeof(c2RecoEffCor)); + + memset(meanTruMult, 0, sizeof(meanTruMult)); + memset(meanRecoMult, 0, sizeof(meanRecoMult)); + memset(meanRecoEffCorMult, 0, sizeof(meanRecoEffCorMult)); + + memset(p1kBarTru, 0, sizeof(p1kBarTru)); + memset(p1kBarReco, 0, sizeof(p1kBarReco)); + memset(p1kBarRecoEffCor, 0, sizeof(p1kBarRecoEffCor)); + + memset(p1kBarTruMult, 0, sizeof(p1kBarTruMult)); + memset(p1kBarRecoMult, 0, sizeof(p1kBarRecoMult)); + memset(p1kBarRecoEffCorMult, 0, sizeof(p1kBarRecoEffCorMult)); + + double p1kBarFt0A = 0.0, p1kBarFt0C = 0.0; + + for (const auto& particle : partSlice) { + if (!isParticleSelected(particle) || !particle.isPhysicalPrimary()) + continue; + + float pt = particle.pt(); + if (pt <= cfgPtMin || pt > cfgPtMax) + continue; + float eta = particle.eta(); + int pdgCode = particle.pdgCode(); + int absPdg = std::abs(pdgCode); + + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + pdgCode == -KPiPlus, // kPiMinusIdx + pdgCode == KPiPlus, // kPiPlusIdx + absPdg == KPiPlus, // kPiAllIdx + pdgCode == -KKPlus, // kKaMinusIdx + pdgCode == KKPlus, // kKaPlusIdx + absPdg == KKPlus, // kKaAllIdx + pdgCode == -KProton, // kAntiPrIdx + pdgCode == KProton, // kPrIdx + absPdg == KProton // kAllPrIdx + }; - void declareDataGetFlatHists() - { - for (const auto& suf : pidSuffix) { - histos.add("hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - histos.add("hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - histos.add("hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + for (int ieta = 0; ieta < KNEta; ++ieta) { + if (eta <= etaLw[ieta] || eta > etaUp[ieta]) + continue; + for (int isp = 0; isp < KNsp; ++isp) { + if (isSpecies[isp]) { + for (int k = 0; k < KIntK; ++k) { + for (int m = 0; m < KIntM; ++m) { + sumPmwkTru[isp][ieta][m][k] += std::pow(pt, m); + } + sumWkTru[isp][ieta][k]++; + } + } } - histos.add("hnTrkPVZDC", ";N_{PV};ZDC_{A+C}", kTH2F, {{nChAxis2}, {200, 0, 3000}}); - histos.add("hNchZDC", ";N_{trk};ZDC_{A+C}", kTH2F, {{nChAxis2}, {200, 0, 30000}}); - histos.add("hCentnTrk", ";Centrality (%);N_{trk}", kTH2F, {{centAxis1Per}, {nChAxis2}}); - histos.add("hCentnTrkPV", ";Centrality (%);N_{trk, PV}", kTH2F, {{centAxis1Per}, {nChAxis2}}); } + } // end truth loop + float vz = col.posZ(); + + histos.fill(HIST("hZvtx_after_sel"), col.posZ()); + histos.fill(HIST("hCentrality"), cent); + + histos.fill(HIST("Hist2D_globalTracks_PVTracks"), col.multNTracksPV(), trackSlice.size()); + histos.fill(HIST("Hist2D_cent_nch"), trackSlice.size(), cent); + + for (const auto& track : trackSlice) { + if (!isTrackSelected(track)) + continue; + + float pt = track.pt(); + if (pt <= cfgPtMin || pt > cfgPtMax) + continue; + float eta = track.eta(); + float phi = track.phi(); + auto sign = track.sign(); + bool isPi = selectionPion(track); + bool isKa = selectionKaon(track); + bool isPr = selectionProton(track); + + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + isPi && sign < 0, // kPiMinusIdx + isPi && sign > 0, // kPiPlusIdx + isPi, // kPiAllIdx + isKa && sign < 0, // kKaMinusIdx + isKa && sign > 0, // kKaPlusIdx + isKa, // kKaAllIdx + isPr && sign < 0, // kAntiPrIdx (Negative) + isPr && sign > 0, // kPrIdx (Positive) + isPr // kAllPrIdx + }; - void declareDataMeanHists() - { - histos.add("pmeanFT0Amultpv", "N_{PV}; AmplitudeA", kTProfile, {nChAxis}); - histos.add("pmeanFT0A_cent", "cent; AmplitudeA", kTProfile, {centAxis1Per}); - histos.add("pmeanFT0Cmultpv", "N_{PV}; AmplitudeA", kTProfile, {nChAxis}); - histos.add("pmeanFT0C_cent", "cent; AmplitudeA", kTProfile, {centAxis1Per}); - - histos.add("pmean_cent_id_eta_FT0", ";cent;channel id; #eta;amplitude", kTProfile3D, {{centAxis1Per}, {100, -0.5, 99.5}, {100, -5.0, 5.0}}); - histos.add("h3_cent_id_eta_FT0", ";cent;channel id; #eta", kTH3F, {{centAxis1Per}, {100, -0.5, 99.5}, {100, -5.0, 5.0}}); - - histos.add("Prof_Cent_Nsp_Nchrec", ";cent;Species;#LT N_{PV}#GT", kTProfile2D, {{centAxis1Per}, {spBinAxis}}); - histos.add("Prof_Mult_Nsp_Nchrec", ";N_{PV};Species;#LT N_{PV}#GT", kTProfile2D, {{nChAxis}, {spBinAxis}}); - histos.add("Prof_Cent_Nsp_MeanpT", ";cent;Species;#LT p_{T}#GT", kTProfile2D, {{centAxis1Per}, {spBinAxis}}); - histos.add("Prof_Mult_Nsp_MeanpT", ";N_{PV};Species;#LT p_{T}#GT", kTProfile2D, {{nChAxis}, {spBinAxis}}); - - histos.add("pmean_nch_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); - histos.add("pmeanMult_nch_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); - histos.add("pmean_cent_etabin_spbin", ";Centrality (%) ;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); - histos.add("pmeanMult_cent_etabin_spbin", ";Centrality (%) ;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); - - for (const auto& suf : pidSuffix) { - histos.add("hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - histos.add("hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - histos.add("hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); + for (int isp = 0; isp < KNsp; ++isp) { + if (!isSpecies[isp]) + continue; - histos.add("Prof2D_MeanpTSub" + suf, ";cent;#eta_{A} bin;#eta_{C} bin", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {{etaBinAxis}}}); - } - } + float eff = getEfficiency(col.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); + float fake = getEfficiency(col.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); + float flatW = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); + float w = flatW * (1.0 - fake) / eff; - void declareDataFlucHists() - { - histos.add("Prof_MeanpT_Cent_etabin_spbin", ";cent;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); - histos.add("Prof_MeanpT_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); - histos.add("Prof_C2_Cent_etabin_spbin", ";cent;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); - histos.add("Prof_C2_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); - - histos.add("Prof_C2Sub_Cent_etabin_spbin", ";Centrality;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); - histos.add("Prof_C2Sub_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); - histos.add("Prof_Cov_Cent_etabin_spbin", ";Centrality;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); - histos.add("Prof_Cov_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); - - histos.add("Prof_CovFT0A_Cent_etabin_spbin", ";Centrality;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); - histos.add("Prof_CovFT0A_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); - histos.add("Prof_CovFT0C_Cent_etabin_spbin", ";Centrality;#eta-bin;Species", kTProfile3D, {{centAxis1Per}, {{etaBinAxis}}, {spBinAxis}}); - histos.add("Prof_CovFT0C_Mult_etabin_spbin", ";N_{PV};#eta-bin;Species", kTProfile3D, {{nChAxis}, {{etaBinAxis}}, {spBinAxis}}); - - for (const auto& suf : pidSuffix) { - histos.add("hEtaPhiReco" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - histos.add("hEtaPhiRecoEffWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - histos.add("hEtaPhiRecoWtd" + suf, ";vz;sign;pt;eta;phi", kTHnSparseF, {{vzAxis}, {chgAxis}, {pTAxis}, {etaAxis}, {phiAxis}}); - histos.add("Prof_C2Sub2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A};#eta_{C}", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); - histos.add("Prof_GapSum2D" + suf, ";cent;#Delta#eta (Gap);#Sigma#eta/2 (Sum)", kTProfile3D, {{centAxis1Per}, {gapAxis}, {sumAxis}}); - histos.add("Prof_Cov2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A} bin;#eta_{C} bin", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); - histos.add("Prof_CovFT0A2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A};#eta_{B}", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); - histos.add("Prof_CovFT0C2D_Cent_etaA_etaC" + suf, ";cent;#eta_{A};#eta_{B}", kTProfile3D, {{centAxis1Per}, {etaAxis}, {etaAxis}}); - } - } + if (!std::isfinite(w) || w <= 0.f || eff <= KFloatEpsilon) + continue; - THnSparseF* buildWeightMapFromRaw(THnSparseF* hRaw, const char* mapName) - { - if (!hRaw) { - LOGF(error, "Raw eta-phi map for '%s' is null; no flattening will be applied.", mapName); - return nullptr; - } - auto hWMap = reinterpret_cast(hRaw->Clone(mapName)); - hWMap->SetTitle(Form("Flattening Weight Map %s (w_{#phi} = / N_{#phi})", mapName)); - hWMap->Reset(); - auto axV = hRaw->GetAxis(0); // Vz - auto axChg = hRaw->GetAxis(1); // Charge - auto axPt = hRaw->GetAxis(2); // Pt - auto axE = hRaw->GetAxis(3); // Eta - auto axP = hRaw->GetAxis(4); // Phi - - int bins[5]; - for (int iv = 1; iv <= axV->GetNbins(); ++iv) { - bins[0] = iv; - for (int ichg = 1; ichg <= axChg->GetNbins(); ++ichg) { - bins[1] = ichg; - for (int ipt = 1; ipt <= axPt->GetNbins(); ++ipt) { - bins[2] = ipt; - for (int ie = 1; ie <= axE->GetNbins(); ++ie) { - bins[3] = ie; - double sum = 0.0; - int nphi = axP->GetNbins(); - for (int ip = 1; ip <= nphi; ++ip) { - bins[4] = ip; - sum += hRaw->GetBinContent(bins); - } - const double avg = (nphi > 0 ? sum / nphi : 0.0); - for (int ip = 1; ip <= nphi; ++ip) { - bins[4] = ip; - const double raw = hRaw->GetBinContent(bins); - const double w = (avg > 0.0 && raw > 0.0) ? (avg / raw) : 1.0; - hWMap->SetBinContent(bins, w); - } - } + for (int ieta = 0; ieta < KNEta; ++ieta) { + if (eta <= etaLw[ieta] || eta > etaUp[ieta]) + continue; + for (int k = 0; k < KIntK; ++k) { + for (int m = 0; m < KIntM; ++m) { + sumPmwkReco[isp][ieta][m][k] += std::pow(1.0, k) * std::pow(pt, m); + sumPmwkRecoEffCor[isp][ieta][m][k] += std::pow(w, k) * std::pow(pt, m); } + sumWkReco[isp][ieta][k] += std::pow(1.0, k); + sumWkRecoEffCor[isp][ieta][k] += std::pow(w, k); } } - LOGF(info, "Flattening weight map '%s' built.", mapName); - return hWMap; - } - - inline void loadTProfile3D(TDirectory* dir, const char* name, TProfile3D*& target) - { - if (!dir) { - LOGF(error, "loadTProfile3D: directory is null for object %s", name); - return; - } - auto* obj = dir->Get(name); - if (!obj) { - LOGF(error, "loadTProfile3D: object '%s' not found in directory %s", name, dir->GetName()); - return; - } - auto* prof = dynamic_cast(obj); - if (!prof) { - LOGF(error, "loadTProfile3D: object '%s' is not a TProfile3D (it is %s)", name, obj->ClassName()); - return; + if (isp == kInclusiveIdx) { + histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPiMinusIdx) { + histos.fill(HIST("hEtaPhiReco_PiMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_PiMinus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiMinus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPiPlusIdx) { + histos.fill(HIST("hEtaPhiReco_PiPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_PiPlus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiPlus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPiAllIdx) { + histos.fill(HIST("hEtaPhiReco_PiAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_PiAll"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiAll"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kKaMinusIdx) { + histos.fill(HIST("hEtaPhiReco_KaMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_KaMinus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaMinus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kKaPlusIdx) { + histos.fill(HIST("hEtaPhiReco_KaPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_KaPlus"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaPlus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kKaAllIdx) { + histos.fill(HIST("hEtaPhiReco_KaAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_KaAll"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaAll"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPrIdx) { + histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kAntiPrIdx) { + histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kAllPrIdx) { + histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); } - target = reinterpret_cast(prof->Clone(Form("%s_clone", name))); - target->SetDirectory(nullptr); - LOGF(info, "Loaded TProfile3D '%s' with entries = %.0f", name, target->GetEntries()); } + } // trkslice + + for (int ieta = 0; ieta < KNEta; ++ieta) { + const int ibx = state.pmeanTruNchEtabinSpbinStep2->GetXaxis()->FindBin(col.multNTracksPV()); + const int iby = ieta + 1; + + for (int isp = 0; isp < KNsp; ++isp) { + const int ibz = isp + 1; + + meanTruMult[isp][ieta] = sumWkTru[isp][ieta][1]; + meanRecoMult[isp][ieta] = sumWkReco[isp][ieta][1]; + meanRecoEffCorMult[isp][ieta] = sumWkRecoEffCor[isp][ieta][1]; + + float mmptTru = state.pmeanTruNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + float mmptReco = state.pmeanRecoNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + float mmptRecoEffCor = state.pmeanRecoEffcorrNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + + float mmMultTru = state.pmeanMultTruNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + float mmMultReco = state.pmeanMultRecoNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + float mmMultRecoEffCor = state.pmeanMultRecoEffcorrNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + + if (std::isfinite(mmptTru)) + std::tie(meanTru[isp][ieta], c2Tru[isp][ieta]) = calculateMeanAndC2FromSums(sumPmwkTru[isp][ieta], sumWkTru[isp][ieta], mmptTru); + if (std::isfinite(mmptReco)) + std::tie(meanReco[isp][ieta], c2Reco[isp][ieta]) = calculateMeanAndC2FromSums(sumPmwkReco[isp][ieta], sumWkReco[isp][ieta], mmptReco); + if (std::isfinite(mmptRecoEffCor)) + std::tie(meanRecoEffCor[isp][ieta], c2RecoEffCor[isp][ieta]) = calculateMeanAndC2FromSums(sumPmwkRecoEffCor[isp][ieta], sumWkRecoEffCor[isp][ieta], mmptRecoEffCor); + + if (mmptTru != 0.0f) + p1kBarTru[isp][ieta] = meanTru[isp][ieta] - mmptTru; + if (mmptReco != 0.0f) + p1kBarReco[isp][ieta] = meanReco[isp][ieta] - mmptReco; + if (mmptRecoEffCor != 0.0f) + p1kBarRecoEffCor[isp][ieta] = meanRecoEffCor[isp][ieta] - mmptRecoEffCor; + + if (mmMultTru != 0.0f) + p1kBarTruMult[isp][ieta] = meanTruMult[isp][ieta] - mmMultTru; + if (mmMultReco != 0.0f) + p1kBarRecoMult[isp][ieta] = meanRecoMult[isp][ieta] - mmMultReco; + if (mmMultRecoEffCor != 0.0f) + p1kBarRecoEffCorMult[isp][ieta] = meanRecoEffCorMult[isp][ieta] - mmMultRecoEffCor; + } + } + + double amplFT0A = 0, amplFT0C = 0; + if (col.has_foundFT0()) { + const auto& ft0 = col.foundFT0(); + for (std::size_t iCh = 0; iCh < ft0.channelA().size(); iCh++) { + float ampl = ft0.amplitudeA()[iCh]; + amplFT0A += ampl; + } + for (std::size_t iCh = 0; iCh < ft0.channelC().size(); iCh++) { + float ampl = ft0.amplitudeC()[iCh]; + amplFT0C += ampl; + } + } - void init(InitContext&) - { - if (cfgSys == kPbPb) { - nChAxis = {cfgNchPbMax / 4, KBinOffset, cfgNchPbMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; - nChAxis2 = {cfgNchPbMax / 20, KBinOffset, cfgNchPbMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; - } else if (cfgSys == kNeNe || cfgSys == kOO) { - nChAxis = {cfgNchOMax / 2, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; - nChAxis2 = {cfgNchOMax / 5, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; - } else { - nChAxis = {cfgNchOMax / 2, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; - nChAxis2 = {cfgNchOMax / 5, KBinOffset, cfgNchOMax + KBinOffset, "Nch", "PV-contributor track multiplicity"}; - } + for (int isp = 0; isp < KNsp; ++isp) { + for (int ieta = 0; ieta < KNEta; ++ieta) { + histos.fill(HIST("MCGen/Prof_Cent_NEta_Nsp_Nchrec"), cent, ieta, isp, sumWkTru[isp][ieta][1]); + histos.fill(HIST("MCGen/Prof_Mult_NEta_Nsp_Nchrec"), multPV, ieta, isp, sumWkTru[isp][ieta][1]); - ccdb->setURL(cfgCCDBurl.value); - ccdb->setCaching(true); - ccdb->setLocalObjectValidityChecking(); - int64_t now = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - ccdb->setCreatedNotAfter(now); - - loadAlignParam(now); - ft0Det.calculateChannelCenter(); - - std::string sysDir = ""; - switch (cfgSys) { - case kPbPb: - sysDir = "PbPbTest"; - break; - case kNeNe: - sysDir = "NeNeTest"; - break; - case kOO: - sysDir = "OOTest"; - break; - case kpp: - sysDir = "ppTest"; - break; - default: - LOGF(fatal, "Invalid cfgSys value: %d", cfgSys.value); - } + histos.fill(HIST("MCReco/Prof_Cent_NEta_Nsp_Nchrec"), cent, ieta, isp, sumWkReco[isp][ieta][1]); + histos.fill(HIST("MCReco/Prof_Mult_NEta_Nsp_Nchrec"), multPV, ieta, isp, sumWkReco[isp][ieta][1]); - std::string pathEff = cfgCCDBUserPath.value + "/" + sysDir + "/Job1_EffMaps"; - std::string pathMCFlat = cfgCCDBUserPath.value + "/" + sysDir + "/Job1_MCFlatMaps"; - std::string pathMCMean = cfgCCDBUserPath.value + "/" + sysDir + "/Job2_MCMean"; - std::string pathDataFlat = cfgCCDBUserPath.value + "/" + sysDir + "/Job1_DataFlatMaps"; - std::string pathDataMean = cfgCCDBUserPath.value + "/" + sysDir + "/Job2_DataMean"; + histos.fill(HIST("MCRecoEffCorr/Prof_Cent_NEta_Nsp_Nchrec"), cent, ieta, isp, sumWkRecoEffCor[isp][ieta][1]); + histos.fill(HIST("MCRecoEffCorr/Prof_Mult_NEta_Nsp_Nchrec"), multPV, ieta, isp, sumWkRecoEffCor[isp][ieta][1]); - declareCommonQA(); - if (cfgRunGetEff || cfgRunGetDataFlat) { - declarenSigHists(); + if (sumWkTru[isp][ieta][1] > 1.0f) { + histos.fill(HIST("MCGen/Prof_Cent_NEta_Nsp_MeanpT"), cent, ieta, isp, meanTru[isp][ieta]); + histos.fill(HIST("MCGen/Prof_Mult_NEta_Nsp_MeanpT"), multPV, ieta, isp, meanTru[isp][ieta]); } - if (cfgRunMCMean || cfgRunMCFluc || cfgRunGetEff) { - declareMCCommonHists(); + if (sumWkReco[isp][ieta][1] > 1.0f) { + histos.fill(HIST("MCReco/Prof_Cent_NEta_Nsp_MeanpT"), cent, ieta, isp, meanReco[isp][ieta]); + histos.fill(HIST("MCReco/Prof_Mult_NEta_Nsp_MeanpT"), multPV, ieta, isp, meanReco[isp][ieta]); } - if (cfgRunMCMean) { - declareMCMeanHists(); - histos.addClone("MCGen/", "MCReco/"); - histos.addClone("MCGen/", "MCRecoEffCorr/"); + if (sumWkRecoEffCor[isp][ieta][1] > 1.0f) { + histos.fill(HIST("MCReco/Prof_Cent_NEta_Nsp_MeanpT"), cent, ieta, isp, meanRecoEffCor[isp][ieta]); + histos.fill(HIST("MCReco/Prof_Mult_NEta_Nsp_MeanpT"), multPV, ieta, isp, meanRecoEffCor[isp][ieta]); } - if (cfgRunMCFluc) { - declareMCFlucHists(); - histos.addClone("MCGen/", "MCReco/"); - histos.addClone("MCGen/", "MCRecoEffCorr/"); + } + } + + for (int ieta = 0; ieta < KNEta; ++ieta) { + for (int isp = 0; isp < KNsp; ++isp) { + if (std::isfinite(meanTru[isp][ieta])) { + histos.fill(HIST("MCGen/Prof_MeanpT_Cent_etabin_spbin"), cent, ieta, isp, meanTru[isp][ieta]); + histos.fill(HIST("MCGen/Prof_MeanpT_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, meanTru[isp][ieta]); } - if (cfgRunGetDataFlat) { - declareDataGetFlatHists(); + if (std::isfinite(c2Tru[isp][ieta])) { + histos.fill(HIST("MCGen/Prof_C2_Cent_etabin_spbin"), cent, ieta, isp, c2Tru[isp][ieta]); + histos.fill(HIST("MCGen/Prof_C2_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, c2Tru[isp][ieta]); } - if (cfgRunGetMCFlat) { - declareMCGetFlatHists(); - histos.addClone("MCGen/", "MCReco/"); - histos.addClone("MCGen/", "MCRecoEffCorr/"); + if (std::isfinite(meanReco[isp][ieta])) { + histos.fill(HIST("MCReco/Prof_MeanpT_Cent_etabin_spbin"), cent, ieta, isp, meanReco[isp][ieta]); + histos.fill(HIST("MCReco/Prof_MeanpT_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, meanReco[isp][ieta]); } - if (cfgRunDataMean) { - declareDataMeanHists(); + if (std::isfinite(c2Reco[isp][ieta])) { + histos.fill(HIST("MCReco/Prof_C2_Cent_etabin_spbin"), cent, ieta, isp, c2Reco[isp][ieta]); + histos.fill(HIST("MCReco/Prof_C2_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, c2Reco[isp][ieta]); } - if (cfgRunDataFluc) { - declareDataFlucHists(); + if (std::isfinite(meanRecoEffCor[isp][ieta])) { + histos.fill(HIST("MCRecoEffCorr/Prof_MeanpT_Cent_etabin_spbin"), cent, ieta, isp, meanRecoEffCor[isp][ieta]); + histos.fill(HIST("MCRecoEffCorr/Prof_MeanpT_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, meanRecoEffCor[isp][ieta]); } + if (std::isfinite(c2RecoEffCor[isp][ieta])) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2_Cent_etabin_spbin"), cent, ieta, isp, c2RecoEffCor[isp][ieta]); + histos.fill(HIST("MCRecoEffCorr/Prof_C2_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, c2RecoEffCor[isp][ieta]); + } + } + } - if (!cfgRunGetEff && (cfgEff)) { - TList* lst = ccdb->getForTimeStamp(pathEff, now); - - if (!lst) { - LOGF(fatal, "Efficiency maps required but CCDB list is null at %s!", pathEff.c_str()); - } - - LOGF(info, "Loading Eff/Fake maps from TList for all species..."); + p1kBarFt0A = amplFT0A - state.pmeanFT0AmultpvStep2->GetBinContent(state.pmeanFT0AmultpvStep2->GetXaxis()->FindBin(col.multNTracksPV())); + p1kBarFt0C = amplFT0C - state.pmeanFT0CmultpvStep2->GetBinContent(state.pmeanFT0CmultpvStep2->GetXaxis()->FindBin(col.multNTracksPV())); - auto loadEffFakeForPID = [&](PIDIdx pidType) { - std::string suffix = pidSuffix[pidType]; - std::string hEffNumName = "h3_RecoMatchedToPrimary" + suffix; - std::string hEffDenName = "h3_AllPrimary" + suffix; - std::string hFakeNumSecName = "h3_RecoUnMatchedToPrimary_Secondary" + suffix; - std::string hFakeNumFakName = "h3_RecoUnMatchedToPrimary_Fake" + suffix; - std::string hFakeNumFakName2 = "h3_RecoMatchedToPrimary_MisID" + suffix; - std::string hFakeDenName = "h3_AllReco" + suffix; + for (int ietaA = 1; ietaA <= (KNEta - 1) / 2; ++ietaA) { + int ietaC = KNEta - ietaA; + for (int isp = 0; isp < KNsp; ++isp) { + float c2SubTru = p1kBarTru[isp][ietaA] * p1kBarTru[isp][ietaC]; + float c2SubReco = p1kBarReco[isp][ietaA] * p1kBarReco[isp][ietaC]; + float c2SubRecoEffCor = p1kBarRecoEffCor[isp][ietaA] * p1kBarRecoEffCor[isp][ietaC]; - auto* hNum = reinterpret_cast(lst->FindObject(hEffNumName.c_str())); - auto* hDen = reinterpret_cast(lst->FindObject(hEffDenName.c_str())); + float covTru = p1kBarTruMult[isp][ietaA] * p1kBarTru[isp][ietaC]; + float covReco = p1kBarRecoMult[isp][ietaA] * p1kBarReco[isp][ietaC]; + float covRecoEffCor = p1kBarRecoEffCorMult[isp][ietaA] * p1kBarRecoEffCor[isp][ietaC]; - if (hNum && hDen) { - state.hEff[pidType] = reinterpret_cast(hNum->Clone(Form("hEff%s", suffix.c_str()))); - state.hEff[pidType]->SetDirectory(nullptr); - state.hEff[pidType]->Divide(hDen); - } else { - LOGF(error, "Missing CCDB objects for efficiency. Checked: %s, %s", hEffNumName.c_str(), hEffDenName.c_str()); - } + float covFT0ATru = p1kBarFt0A * p1kBarTru[isp][ietaC]; + float covFT0AReco = p1kBarFt0A * p1kBarReco[isp][ietaC]; + float covFT0ARecoEffCor = p1kBarFt0A * p1kBarRecoEffCor[isp][ietaC]; - auto* hNumS = reinterpret_cast(lst->FindObject(hFakeNumSecName.c_str())); - auto* hNumF = reinterpret_cast(lst->FindObject(hFakeNumFakName.c_str())); - auto* hNumF2 = reinterpret_cast(lst->FindObject(hFakeNumFakName2.c_str())); - auto* hDenF = reinterpret_cast(lst->FindObject(hFakeDenName.c_str())); - - if (hNumS && hNumF && hDenF) { - state.hFake[pidType] = reinterpret_cast(hNumS->Clone(Form("hFake%s", suffix.c_str()))); - state.hFake[pidType]->Add(hNumF); - // state.hFake[pidType]->Add(hNumF2); - state.hFake[pidType]->SetDirectory(nullptr); - state.hFake[pidType]->Divide(hDenF); - } else { - LOGF(error, "Missing CCDB object(s) for fakes for %s in list.", suffix.c_str()); - } - }; + float covFT0CTru = p1kBarFt0C * p1kBarTru[isp][ietaA]; + float covFT0CReco = p1kBarFt0C * p1kBarReco[isp][ietaA]; + float covFT0CRecoEffCor = p1kBarFt0C * p1kBarRecoEffCor[isp][ietaA]; - for (int i = 0; i < KNsp; ++i) { - loadEffFakeForPID(static_cast(i)); - } + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub_Cent_etabin_spbin"), cent, ietaA, isp, c2SubTru); + histos.fill(HIST("MCGen/Prof_C2Sub_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, c2SubTru); } - - if (!cfgRunGetEff && (cfgFlat)) { - if (cfgRunDataMean || cfgRunDataFluc) { - LOGF(info, "Data Run: Loading flattening maps from %s", pathDataFlat.c_str()); - TList* lstDataFlat = ccdb->getForTimeStamp(pathDataFlat, now); - - if (lstDataFlat) { - for (int i = 0; i < KNsp; ++i) { - std::string suffix = pidSuffix[i]; - std::string hName; - - if (cfgEff && cfgFlat) { - hName = "hEtaPhiRecoWtd" + suffix; - } else if (cfgEff) { - hName = "hEtaPhiRecoEffWtd" + suffix; - } else { - hName = "hEtaPhiReco" + suffix; - } - auto* hRaw = reinterpret_cast(lstDataFlat->FindObject(hName.c_str())); - - if (hRaw) { - state.hFlatWeight[i] = buildWeightMapFromRaw(hRaw, Form("hFlatWeight%s", suffix.c_str())); - } else { - LOGF(error, "Data flattening map '%s' not found.", hName.c_str()); - } - } - } else { - LOGF(error, "Could not retrieve Data Flattening TList from: %s", pathDataFlat.c_str()); - } - } - - if (cfgRunMCMean || cfgRunMCFluc) { - LOGF(info, "MC Run: Loading flattening maps from %s", pathMCFlat.c_str()); - TList* lstMCFlat = ccdb->getForTimeStamp(pathMCFlat, now); - - if (lstMCFlat) { - auto loadFlatForPID = [&](PIDIdx pidType) { - std::string suffix = pidSuffix[pidType]; - std::string hFlatSrcName; - if (cfgEff && cfgFlat) { - hFlatSrcName = "MCReco/hEtaPhiRecoWtd" + suffix; - } else if (cfgEff) { - hFlatSrcName = "MCReco/hEtaPhiRecoEffWtd" + suffix; - } else { - hFlatSrcName = "MCReco/hEtaPhiReco" + suffix; - } - - auto* hRaw = reinterpret_cast(lstMCFlat->FindObject(hFlatSrcName.c_str())); - - if (hRaw) { - state.hFlatWeight[pidType] = buildWeightMapFromRaw(hRaw, Form("hFlatWeight%s", suffix.c_str())); - } else { - LOGF(warning, "MC flattening source '%s' not found in list.", hFlatSrcName.c_str()); - } - }; - - for (int i = 0; i < KNsp; ++i) { - loadFlatForPID(static_cast(i)); - } - } else { - LOGF(error, "Could not retrieve MC Flattening TList from: %s", pathMCFlat.c_str()); - } - } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub_Cent_etabin_spbin"), cent, ietaA, isp, c2SubReco); + histos.fill(HIST("MCReco/Prof_C2Sub_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, c2SubReco); } - - auto loadTProfile3DFromList = [&](TList* sourceList, const char* objName, TProfile3D*& target) { - if (!sourceList) - return; - auto* tp = reinterpret_cast(sourceList->FindObject(objName)); - if (tp) { - target = reinterpret_cast(tp->Clone()); - target->SetDirectory(nullptr); - LOGF(info, "Loaded %s from list", objName); - } else { - LOGF(error, "Histogram %s missing in CCDB TList", objName); - } - }; - - auto loadTProfileFromList = [&](TList* sourceList, const char* objName, TProfile*& target) { - if (!sourceList) - return; - auto* tp = reinterpret_cast(sourceList->FindObject(objName)); - if (tp) { - target = reinterpret_cast(tp->Clone()); - target->SetDirectory(nullptr); - LOGF(info, "Loaded %s from list", objName); - } else { - LOGF(error, "Histogram %s missing in CCDB TList", objName); - } - }; - - if (cfgRunMCFluc) { - LOGF(info, "Loading MC Mean profiles from CCDB path: %s", pathMCMean.c_str()); - TList* lstMCMean = ccdb->getForTimeStamp(pathMCMean, now); - - if (lstMCMean) { - loadTProfileFromList(lstMCMean, "pmeanFT0Amultpv", state.pmeanFT0AmultpvStep2); - loadTProfileFromList(lstMCMean, "pmeanFT0Cmultpv", state.pmeanFT0CmultpvStep2); - - loadTProfile3DFromList(lstMCMean, "pmeanTru_nch_etabin_spbin", state.pmeanTruNchEtabinSpbinStep2); - loadTProfile3DFromList(lstMCMean, "pmeanReco_nch_etabin_spbin", state.pmeanRecoNchEtabinSpbinStep2); - loadTProfile3DFromList(lstMCMean, "pmeanRecoEffcorr_nch_etabin_spbin", state.pmeanRecoEffcorrNchEtabinSpbinStep2); - - loadTProfile3DFromList(lstMCMean, "pmeanMultTru_nch_etabin_spbin", state.pmeanMultTruNchEtabinSpbinStep2); - loadTProfile3DFromList(lstMCMean, "pmeanMultReco_nch_etabin_spbin", state.pmeanMultRecoNchEtabinSpbinStep2); - loadTProfile3DFromList(lstMCMean, "pmeanMultRecoEffcorr_nch_etabin_spbin", state.pmeanMultRecoEffcorrNchEtabinSpbinStep2); - } else { - LOGF(error, "Could not retrieve TList for MC Mean from: %s", pathMCMean.c_str()); - } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub_Cent_etabin_spbin"), cent, ietaA, isp, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, c2SubRecoEffCor); + } + if (std::isfinite(covTru)) { + histos.fill(HIST("MCGen/Prof_Cov_Cent_etabin_spbin"), cent, ietaA, isp, covTru); + histos.fill(HIST("MCGen/Prof_Cov_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covTru); + } + if (std::isfinite(covReco)) { + histos.fill(HIST("MCReco/Prof_Cov_Cent_etabin_spbin"), cent, ietaA, isp, covReco); + histos.fill(HIST("MCReco/Prof_Cov_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covReco); + } + if (std::isfinite(covRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_Cov_Cent_etabin_spbin"), cent, ietaA, isp, covRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_Cov_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covRecoEffCor); } - if (cfgRunDataFluc) { - LOGF(info, "Loading Data Mean profiles from CCDB path: %s", pathDataMean.c_str()); - TList* lstDataMean = ccdb->getForTimeStamp(pathDataMean, now); - - if (lstDataMean) { - loadTProfileFromList(lstDataMean, "pmeanFT0Amultpv", state.pmeanFT0AmultpvStep2); - loadTProfileFromList(lstDataMean, "pmeanFT0Cmultpv", state.pmeanFT0CmultpvStep2); + if (std::isfinite(covFT0ATru)) { + histos.fill(HIST("MCGen/Prof_CovFT0A_Cent_etabin_spbin"), cent, ietaA, isp, covFT0ATru); + histos.fill(HIST("MCGen/Prof_CovFT0A_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0ATru); + } + if (std::isfinite(covFT0AReco)) { + histos.fill(HIST("MCReco/Prof_CovFT0A_Cent_etabin_spbin"), cent, ietaA, isp, covFT0AReco); + histos.fill(HIST("MCReco/Prof_CovFT0A_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0AReco); + } + if (std::isfinite(covFT0ARecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A_Cent_etabin_spbin"), cent, ietaA, isp, covFT0ARecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0ARecoEffCor); + } - loadTProfile3DFromList(lstDataMean, "pmean_nch_etabin_spbin", state.pmeanNchEtabinSpbinStep2); - loadTProfile3DFromList(lstDataMean, "pmeanMult_nch_etabin_spbin", state.pmeanMultNchEtabinSpbinStep2); - } else { - LOGF(error, "Could not retrieve TList for Data Mean from: %s", pathDataMean.c_str()); - } + if (std::isfinite(covFT0CTru)) { + histos.fill(HIST("MCGen/Prof_CovFT0C_Cent_etabin_spbin"), cent, ietaA, isp, covFT0CTru); + histos.fill(HIST("MCGen/Prof_CovFT0C_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0CTru); + } + if (std::isfinite(covFT0CReco)) { + histos.fill(HIST("MCReco/Prof_CovFT0C_Cent_etabin_spbin"), cent, ietaA, isp, covFT0CReco); + histos.fill(HIST("MCReco/Prof_CovFT0C_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0CReco); + } + if (std::isfinite(covFT0CRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C_Cent_etabin_spbin"), cent, ietaA, isp, covFT0CRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0CRecoEffCor); } - LOGF(info, "CCDB initialization complete for RadialFlowDecorr."); } + } - void processGetEffHists(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/, aod::McParticles const& mcParticles) - { - for (const auto& mcCollision : mcColl) { - auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); - if (colSlice.size() != 1) continue; - - for (const auto& col : colSlice) { - if (!col.has_mcCollision() || !isEventSelected(col)) continue; - - auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); - auto partSlice = mcParticles.sliceBy(partPerMcCollision, mcCollision.globalIndex()); - if (trackSlice.size() < 1 || partSlice.size() < 1) continue; - - float cent = getCentrality(col); - if (cent > KCentMax) continue; - float multPV = col.multNTracksPV(); - float vz = col.posZ(); - - for (const auto& particle : partSlice) { - if (!isParticleSelected(particle) || !particle.isPhysicalPrimary()) continue; - - const int pdg = particle.pdgCode(); - const int absPdg = std::abs(pdg); - float pt = particle.pt(), eta = particle.eta(); - - bool isSpecies[KNsp] = { - true, // kInclusiveIdx - pdg == -KPiPlus, // kPiMinusIdx - pdg == KPiPlus, // kPiPlusIdx - absPdg == KPiPlus, // kPiAllIdx - pdg == -KKPlus, // kKaMinusIdx - pdg == KKPlus, // kKaPlusIdx - absPdg == KKPlus, // kKaAllIdx - pdg == -KProton, // kAntiPrIdx - pdg == KProton, // kPrIdx - absPdg == KProton // kAllPrIdx - }; - - histos.fill(HIST("h3_AllPrimary"), multPV, pt, eta); - if (isSpecies[kPiMinusIdx]) histos.fill(HIST("h3_AllPrimary_PiMinus"), multPV, pt, eta); - else if (isSpecies[kPiPlusIdx]) histos.fill(HIST("h3_AllPrimary_PiPlus"), multPV, pt, eta); - if (isSpecies[kPiAllIdx]) histos.fill(HIST("h3_AllPrimary_PiAll"), multPV, pt, eta); - - if (isSpecies[kKaMinusIdx]) histos.fill(HIST("h3_AllPrimary_KaMinus"), multPV, pt, eta); - else if (isSpecies[kKaPlusIdx]) histos.fill(HIST("h3_AllPrimary_KaPlus"), multPV, pt, eta); - if (isSpecies[kKaAllIdx]) histos.fill(HIST("h3_AllPrimary_KaAll"), multPV, pt, eta); - - if (isSpecies[kAntiPrIdx]) histos.fill(HIST("h3_AllPrimary_AntiPr"), multPV, pt, eta); - else if (isSpecies[kPrIdx]) histos.fill(HIST("h3_AllPrimary_Pr"), multPV, pt, eta); - if (isSpecies[kAllPrIdx]) histos.fill(HIST("h3_AllPrimary_AllPr"), multPV, pt, eta); - } + for (int ietaA = 1; ietaA < KNEta; ++ietaA) { + for (int ietaC = 1; ietaC < KNEta; ++ietaC) { - histos.fill(HIST("hZvtx_after_sel"), col.posZ()); - histos.fill(HIST("hCentrality"), cent); - - histos.fill(HIST("Hist2D_globalTracks_PVTracks"), multPV, trackSlice.size()); - histos.fill(HIST("Hist2D_cent_nch"), trackSlice.size(), cent); - - for (const auto& track : trackSlice) { - if (!isTrackSelected(track)) continue; - - float pt = track.pt(), eta = track.eta(); - auto sign = track.sign(); - if (sign > 0) { - // PiPlus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiPlus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiPlus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); - // KaPlus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaPlus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaPlus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); - // Pr - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_Pr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_Pr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); - } else if (sign < 0) { - // PiMinus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiMinus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiMinus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); - // KaMinus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaMinus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaMinus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); - // AntiPr - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_AntiPr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_AntiPr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); - } + float etaValA = (etaLw[ietaA] + etaUp[ietaA]) / 2.0f; + float etaValB = (etaLw[ietaC] + etaUp[ietaC]) / 2.0f; + float gap = etaValA - etaValB; + float sum = (etaValA + etaValB) / 2.0f; + for (int isp = 0; isp < KNsp; ++isp) { - bool isPi = selectionPion(track); - bool isKa = selectionKaon(track); - bool isPr = selectionProton(track); - - bool isSpecies[KNsp] = { - true, - isPi && sign < 0, isPi && sign > 0, isPi, - isKa && sign < 0, isKa && sign > 0, isKa, - isPr && sign < 0, isPr && sign > 0, isPr - }; - - if (isSpecies[kPiPlusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiPlus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiPlus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); - } else if (isSpecies[kPiMinusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiMinus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiMinus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); - } + float c2SubTru = p1kBarTru[isp][ietaA] * p1kBarTru[isp][ietaC]; + float c2SubReco = p1kBarReco[isp][ietaA] * p1kBarReco[isp][ietaC]; + float c2SubRecoEffCor = p1kBarRecoEffCor[isp][ietaA] * p1kBarRecoEffCor[isp][ietaC]; - if (isSpecies[kKaPlusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaPlus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaPlus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); - } else if (isSpecies[kKaMinusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaMinus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaMinus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); - } + float covTru = p1kBarTruMult[isp][ietaA] * p1kBarTru[isp][ietaC]; + float covReco = p1kBarRecoMult[isp][ietaA] * p1kBarReco[isp][ietaC]; + float covRecoEffCor = p1kBarRecoEffCorMult[isp][ietaA] * p1kBarRecoEffCor[isp][ietaC]; - if (isSpecies[kPrIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_Pr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_Pr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); - } else if (isSpecies[kAntiPrIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_AntiPr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_AntiPr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); - } + float covFT0ATru = p1kBarFt0A * p1kBarTru[isp][ietaC]; + float covFT0AReco = p1kBarFt0A * p1kBarReco[isp][ietaC]; + float covFT0ARecoEffCor = p1kBarFt0A * p1kBarRecoEffCor[isp][ietaC]; - for (int isp = 0; isp < KNsp; ++isp) { - if (!isSpecies[isp]) continue; - - if (isp == kInclusiveIdx) { - histos.fill(HIST("h3_AllReco"), multPV, pt, eta); - if (track.has_mcParticle()) { - auto mcP = track.mcParticle(); - if (mcP.isPhysicalPrimary()) { - int mcPdg = std::abs(mcP.pdgCode()); - if (mcPdg == KPiPlus || mcPdg == KKPlus || mcPdg == KProton) { - histos.fill(HIST("ptResolution"), mcP.pt(), (pt - mcP.pt()) / mcP.pt()); - histos.fill(HIST("etaResolution"), mcP.eta(), eta - mcP.eta()); - histos.fill(HIST("etaTruthReco"), mcP.eta(), eta); - histos.fill(HIST("vzResolution"), mcP.vz(), (vz - mcP.vz()) / mcP.vz()); - histos.fill(HIST("TruthTracKVz"), mcP.vz(), vz); - histos.fill(HIST("h3_RecoMatchedToPrimary"), multPV, mcP.pt(), mcP.eta()); - } else { - // Misidentified! Reconstructed track, but true particle is not pi/K/P - histos.fill(HIST("h3_RecoMatchedToPrimary_MisID"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake"), multPV, pt, eta); - } - } - - else if (isp == kPiMinusIdx) { - histos.fill(HIST("h3_AllReco_PiMinus"), multPV, pt, eta); - if (track.has_mcParticle()) { - auto mcP = track.mcParticle(); - if (mcP.isPhysicalPrimary()) { - if (mcP.pdgCode() == -KPiPlus) { - histos.fill(HIST("h3_RecoMatchedToPrimary_PiMinus"), multPV, mcP.pt(), mcP.eta()); - } else { // Misidentified - histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_PiMinus"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_PiMinus"), multPV, pt, eta); - } - } else { // No MC - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_PiMinus"), multPV, pt, eta); - } - } - - else if (isp == kPiPlusIdx) { - histos.fill(HIST("h3_AllReco_PiPlus"), multPV, pt, eta); - if (track.has_mcParticle()) { - auto mcP = track.mcParticle(); - if (mcP.isPhysicalPrimary()) { - if (mcP.pdgCode() == KPiPlus) { - histos.fill(HIST("h3_RecoMatchedToPrimary_PiPlus"), multPV, mcP.pt(), mcP.eta()); - } else { // Misidentified - histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_PiPlus"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_PiPlus"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_PiPlus"), multPV, pt, eta); - } - } - - else if (isp == kPiAllIdx) { - histos.fill(HIST("h3_AllReco_PiAll"), multPV, pt, eta); - if (track.has_mcParticle()) { - auto mcP = track.mcParticle(); - if (mcP.isPhysicalPrimary()) { - if (std::abs(mcP.pdgCode()) == KPiPlus) { - histos.fill(HIST("h3_RecoMatchedToPrimary_PiAll"), multPV, mcP.pt(), mcP.eta()); - } else { // Misidentified - histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_PiAll"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_PiAll"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_PiAll"), multPV, pt, eta); - } - } - - else if (isp == kKaMinusIdx) { - histos.fill(HIST("h3_AllReco_KaMinus"), multPV, pt, eta); - if (track.has_mcParticle()) { - auto mcP = track.mcParticle(); - if (mcP.isPhysicalPrimary()) { - if (mcP.pdgCode() == -KKPlus) { - histos.fill(HIST("h3_RecoMatchedToPrimary_KaMinus"), multPV, mcP.pt(), mcP.eta()); - } else { // Misidentified - histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_KaMinus"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_KaMinus"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_KaMinus"), multPV, pt, eta); - } - } - - else if (isp == kKaPlusIdx) { - histos.fill(HIST("h3_AllReco_KaPlus"), multPV, pt, eta); - if (track.has_mcParticle()) { - auto mcP = track.mcParticle(); - if (mcP.isPhysicalPrimary()) { - if (mcP.pdgCode() == KKPlus) { - histos.fill(HIST("h3_RecoMatchedToPrimary_KaPlus"), multPV, mcP.pt(), mcP.eta()); - } else { // Misidentified - histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_KaPlus"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_KaPlus"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_KaPlus"), multPV, pt, eta); - } - } - - else if (isp == kKaAllIdx) { - histos.fill(HIST("h3_AllReco_KaAll"), multPV, pt, eta); - if (track.has_mcParticle()) { - auto mcP = track.mcParticle(); - if (mcP.isPhysicalPrimary()) { - if (std::abs(mcP.pdgCode()) == KKPlus) { - histos.fill(HIST("h3_RecoMatchedToPrimary_KaAll"), multPV, mcP.pt(), mcP.eta()); - } else { // Misidentified - histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_KaAll"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_KaAll"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_KaAll"), multPV, pt, eta); - } - } - - else if (isp == kAntiPrIdx) { - histos.fill(HIST("h3_AllReco_AntiPr"), multPV, pt, eta); - if (track.has_mcParticle()) { - auto mcP = track.mcParticle(); - if (mcP.isPhysicalPrimary()) { - if (mcP.pdgCode() == -KProton) { - histos.fill(HIST("h3_RecoMatchedToPrimary_AntiPr"), multPV, mcP.pt(), mcP.eta()); - } else { // Misidentified - histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_AntiPr"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_AntiPr"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_AntiPr"), multPV, pt, eta); - } - } - - else if (isp == kPrIdx) { - histos.fill(HIST("h3_AllReco_Pr"), multPV, pt, eta); - if (track.has_mcParticle()) { - auto mcP = track.mcParticle(); - if (mcP.isPhysicalPrimary()) { - if (mcP.pdgCode() == KProton) { - histos.fill(HIST("h3_RecoMatchedToPrimary_Pr"), multPV, mcP.pt(), mcP.eta()); - } else { // Misidentified - histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_Pr"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_Pr"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_Pr"), multPV, pt, eta); - } - } - - else if (isp == kAllPrIdx) { - histos.fill(HIST("h3_AllReco_AllPr"), multPV, pt, eta); - if (track.has_mcParticle()) { - auto mcP = track.mcParticle(); - if (mcP.isPhysicalPrimary()) { - if (std::abs(mcP.pdgCode()) == KProton) { - histos.fill(HIST("h3_RecoMatchedToPrimary_AllPr"), multPV, mcP.pt(), mcP.eta()); - } else { // Misidentified - histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_AllPr"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_AllPr"), multPV, pt, eta); - } - } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_AllPr"), multPV, pt, eta); - } - } - } + float covFT0CTru = p1kBarFt0C * p1kBarTru[isp][ietaA]; + float covFT0CReco = p1kBarFt0C * p1kBarReco[isp][ietaA]; + float covFT0CRecoEffCor = p1kBarFt0C * p1kBarRecoEffCor[isp][ietaA]; + + if (isp == kInclusiveIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D"), cent, gap, sum, c2SubTru); } - } - } - } - PROCESS_SWITCH(RadialFlowDecorr, processGetEffHists, "process MC to calculate EffWeights", cfgRunGetEff); - - void processMCFlat(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/) - { - for (const auto& mcCollision : mcColl) { - auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); - if (colSlice.size() != 1) continue; - - for (const auto& col : colSlice) { - if (!col.has_mcCollision() || !isEventSelected(col)) continue; - - float cent = getCentrality(col); - if (cent > KCentMax) continue; - - auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); - if (trackSlice.size() < 1) continue; - - float multPV = col.multNTracksPV(); - float vz = col.posZ(); - - histos.fill(HIST("hZvtx_after_sel"), col.posZ()); - histos.fill(HIST("hCentrality"), cent); - - histos.fill(HIST("Hist2D_globalTracks_PVTracks"), col.multNTracksPV(), trackSlice.size()); - histos.fill(HIST("Hist2D_cent_nch"), trackSlice.size(), cent); - for (const auto& track : trackSlice) { - if (!isTrackSelected(track)) continue; - - float pt = track.pt(), eta = track.eta(), phi = track.phi(); - auto sign = track.sign(); - bool isPi = selectionPion(track); - bool isKa = selectionKaon(track); - bool isPr = selectionProton(track); - - bool isSpecies[KNsp] = { - true, - isPi && sign < 0, isPi && sign > 0, isPi, - isKa && sign < 0, isKa && sign > 0, isKa, - isPr && sign < 0, isPr && sign > 0, isPr - }; - - for (int isp = 0; isp < KNsp; ++isp) { - if (!isSpecies[isp]) continue; - - float eff = getEfficiency(multPV, pt, eta, static_cast(isp), 0, cfgEff); - float fake = getEfficiency(multPV, pt, eta, static_cast(isp), 1, cfgEff); - float w = (eff > KFloatEpsilon) ? (1.0f - fake) / eff : 0.0f; - - if (std::isfinite(w) && w > 0.f) { - if (isp == kInclusiveIdx) { - histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("MCReco/hEtaPhiReco"), vz, sign, pt, eta, phi, 1.0); - histos.fill(HIST("MCReco/hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); - } else if (isp == kPiMinusIdx) { - histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_PiMinus"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("MCReco/hEtaPhiReco_PiMinus"), vz, sign, pt, eta, phi, 1.0); - histos.fill(HIST("MCReco/hEtaPhiRecoWtd_PiMinus"), vz, sign, pt, eta, phi, w); - } else if (isp == kPiPlusIdx) { - histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_PiPlus"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("MCReco/hEtaPhiReco_PiPlus"), vz, sign, pt, eta, phi, 1.0); - histos.fill(HIST("MCReco/hEtaPhiRecoWtd_PiPlus"), vz, sign, pt, eta, phi, w); - } else if (isp == kPiAllIdx) { - histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_PiAll"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("MCReco/hEtaPhiReco_PiAll"), vz, sign, pt, eta, phi, 1.0); - histos.fill(HIST("MCReco/hEtaPhiRecoWtd_PiAll"), vz, sign, pt, eta, phi, w); - } else if (isp == kKaMinusIdx) { - histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_KaMinus"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("MCReco/hEtaPhiReco_KaMinus"), vz, sign, pt, eta, phi, 1.0); - histos.fill(HIST("MCReco/hEtaPhiRecoWtd_KaMinus"), vz, sign, pt, eta, phi, w); - } else if (isp == kKaPlusIdx) { - histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_KaPlus"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("MCReco/hEtaPhiReco_KaPlus"), vz, sign, pt, eta, phi, 1.0); - histos.fill(HIST("MCReco/hEtaPhiRecoWtd_KaPlus"), vz, sign, pt, eta, phi, w); - } else if (isp == kKaAllIdx) { - histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_KaAll"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("MCReco/hEtaPhiReco_KaAll"), vz, sign, pt, eta, phi, 1.0); - histos.fill(HIST("MCReco/hEtaPhiRecoWtd_KaAll"), vz, sign, pt, eta, phi, w); - } else if (isp == kAntiPrIdx) { - histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("MCReco/hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi, 1.0); - histos.fill(HIST("MCReco/hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); - } else if (isp == kPrIdx) { - histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("MCReco/hEtaPhiReco_Pr"), vz, sign, pt, eta, phi, 1.0); - histos.fill(HIST("MCReco/hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); - } else if (isp == kAllPrIdx) { - histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("MCReco/hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi, 1.0); - histos.fill(HIST("MCReco/hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); - } - } - } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D"), cent, gap, sum, c2SubReco); } - } - } - } - PROCESS_SWITCH(RadialFlowDecorr, processMCFlat, "process MC to calculate FlatWeights", cfgRunGetMCFlat); - - void processMCMean(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/, aod::FT0s const&, aod::McParticles const& mcParticles) - { - double sumWiTruth[KNsp][KNEta]{}, sumWiptiTruth[KNsp][KNEta]{}; - double sumWiReco[KNsp][KNEta]{}, sumWiptiReco[KNsp][KNEta]{}; - double sumWiRecoEffCorr[KNsp][KNEta]{}, sumWiptiRecoEffCorr[KNsp][KNEta]{}; - - for (const auto& mcCollision : mcColl) { - auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); - if (colSlice.size() != 1) - continue; - - for (const auto& col : colSlice) { - if (!col.has_mcCollision() || !isEventSelected(col)) - continue; - - auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); - auto partSlice = mcParticles.sliceBy(partPerMcCollision, mcCollision.globalIndex()); - if (trackSlice.size() < 1 || partSlice.size() < 1) - continue; - - float cent = getCentrality(col); - if (cent > KCentMax) - continue; - float multPV = col.multNTracksPV(); - float vz = col.posZ(); - - memset(sumWiTruth, 0, sizeof(sumWiTruth)); - memset(sumWiptiTruth, 0, sizeof(sumWiptiTruth)); - memset(sumWiReco, 0, sizeof(sumWiReco)); - memset(sumWiptiReco, 0, sizeof(sumWiptiReco)); - memset(sumWiRecoEffCorr, 0, sizeof(sumWiRecoEffCorr)); - memset(sumWiptiRecoEffCorr, 0, sizeof(sumWiptiRecoEffCorr)); - - for (const auto& particle : partSlice) { - if (!isParticleSelected(particle) || !particle.isPhysicalPrimary()) - continue; - float pt = particle.pt(), eta = particle.eta(); - if (pt <= cfgPtMin || pt > cfgPtMax) - continue; - int pdgCode = particle.pdgCode(); - int absPdg = std::abs(pdgCode); - - bool isSpecies[KNsp] = { - true, // kInclusiveIdx - pdgCode == -KPiPlus, // kPiMinusIdx - pdgCode == KPiPlus, // kPiPlusIdx - absPdg == KPiPlus, // kPiAllIdx - pdgCode == -KKPlus, // kKaMinusIdx - pdgCode == KKPlus, // kKaPlusIdx - absPdg == KKPlus, // kKaAllIdx - pdgCode == -KProton, // kAntiPrIdx - pdgCode == KProton, // kPrIdx - absPdg == KProton // kAllPrIdx - }; - - for (int ieta = 0; ieta < KNEta; ++ieta) { - if (eta <= etaLw[ieta] || eta > etaUp[ieta]) - continue; - - for (int isp = 0; isp < KNsp; ++isp) { - if (isSpecies[isp]) { - sumWiTruth[isp][ieta]++; - sumWiptiTruth[isp][ieta] += pt; - } - } - } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D"), cent, gap, sum, c2SubRecoEffCor); } - for (int isp = 0; isp < KNsp; ++isp) { - histos.fill(HIST("MCGen/Prof_Cent_Nsp_Nchrec"), cent, isp, sumWiTruth[isp][0]); - histos.fill(HIST("MCGen/Prof_Mult_Nsp_Nchrec"), multPV, isp, sumWiTruth[isp][0]); - if (sumWiTruth[isp][0] > 1.0f) { - histos.fill(HIST("MCGen/Prof_Cent_Nsp_MeanpT"), cent, isp, sumWiptiTruth[isp][0] / sumWiTruth[isp][0]); - histos.fill(HIST("MCGen/Prof_Mult_Nsp_MeanpT"), multPV, isp, sumWiptiTruth[isp][0] / sumWiTruth[isp][0]); - } + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kPiMinusIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_PiMinus"), cent, gap, sum, c2SubTru); } - - histos.fill(HIST("hZvtx_after_sel"), col.posZ()); - histos.fill(HIST("hCentrality"), cent); - - histos.fill(HIST("Hist2D_globalTracks_PVTracks"), col.multNTracksPV(), trackSlice.size()); - histos.fill(HIST("Hist2D_cent_nch"), trackSlice.size(), cent); - - for (const auto& track : trackSlice) { - if (!isTrackSelected(track)) - continue; - float pt = track.pt(), eta = track.eta(), phi = track.phi(); - if (pt <= cfgPtMin || pt > cfgPtMax) - continue; - auto sign = track.sign(); - bool isPi = selectionPion(track); - bool isKa = selectionKaon(track); - bool isPr = selectionProton(track); - - bool isSpecies[KNsp] = { - true, // kInclusiveIdx - isPi && sign < 0, // kPiMinusIdx - isPi && sign > 0, // kPiPlusIdx - isPi, // kPiAllIdx - isKa && sign < 0, // kKaMinusIdx - isKa && sign > 0, // kKaPlusIdx - isKa, // kKaAllIdx - isPr && sign < 0, // kAntiPrIdx (Negative) - isPr && sign > 0, // kPrIdx (Positive) - isPr // kAllPrIdx - }; - - for (int isp = 0; isp < KNsp; ++isp) { - if (!isSpecies[isp]) - continue; - float eff = getEfficiency(multPV, pt, eta, static_cast(isp), 0, cfgEff); - float fake = getEfficiency(multPV, pt, eta, static_cast(isp), 1, cfgEff); - float flatW = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); - float w = flatW * (1.0 - fake) / eff; - if (!std::isfinite(w) || w <= 0.f || eff <= KFloatEpsilon) - continue; - - for (int ieta = 0; ieta < KNEta; ++ieta) { - if (eta <= etaLw[ieta] || eta > etaUp[ieta]) - continue; - sumWiReco[isp][ieta]++; - sumWiptiReco[isp][ieta] += pt; - sumWiRecoEffCorr[isp][ieta] += w; - sumWiptiRecoEffCorr[isp][ieta] += w * pt; - } - - if (isp == kInclusiveIdx) { - histos.fill(HIST("Eff_cent"), cent, eff); - histos.fill(HIST("Fake_cent"), cent, fake); - histos.fill(HIST("wgt_cent"), cent, w); - - histos.fill(HIST("Eff_Ntrk"), multPV, eff); - histos.fill(HIST("Fake_Ntrk"), multPV, fake); - histos.fill(HIST("wgt_Ntrk"), multPV, w); - - histos.fill(HIST("Eff_pT"), pt, eff); - histos.fill(HIST("Fake_pT"), pt, fake); - histos.fill(HIST("wgt_pT"), pt, w); - - histos.fill(HIST("Eff_eta"), eta, eff); - histos.fill(HIST("Fake_eta"), eta, fake); - histos.fill(HIST("wgt_eta"), eta, w); - } - - if (isp == kInclusiveIdx) { - histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kPiMinusIdx) { - histos.fill(HIST("hEtaPhiReco_PiMinus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_PiMinus"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_PiMinus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kPiPlusIdx) { - histos.fill(HIST("hEtaPhiReco_PiPlus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_PiPlus"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_PiPlus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kPiAllIdx) { - histos.fill(HIST("hEtaPhiReco_PiAll"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_PiAll"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_PiAll"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kKaMinusIdx) { - histos.fill(HIST("hEtaPhiReco_KaMinus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_KaMinus"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_KaMinus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kKaPlusIdx) { - histos.fill(HIST("hEtaPhiReco_KaPlus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_KaPlus"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_KaPlus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kKaAllIdx) { - histos.fill(HIST("hEtaPhiReco_KaAll"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_KaAll"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_KaAll"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kPrIdx) { - histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kAntiPrIdx) { - histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kAllPrIdx) { - histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } - } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_PiMinus"), cent, gap, sum, c2SubReco); } - - for (int isp = 0; isp < KNsp; ++isp) { - histos.fill(HIST("MCReco/Prof_Cent_Nsp_Nchrec"), cent, isp, sumWiReco[isp][0]); - histos.fill(HIST("MCReco/Prof_Mult_Nsp_Nchrec"), multPV, isp, sumWiReco[isp][0]); - - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_Nsp_Nchrec"), cent, isp, sumWiRecoEffCorr[isp][0]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_Nsp_Nchrec"), multPV, isp, sumWiRecoEffCorr[isp][0]); - - if (sumWiReco[isp][0] > 1.0f) { - histos.fill(HIST("MCReco/Prof_Cent_Nsp_MeanpT"), cent, isp, sumWiptiReco[isp][0] / sumWiReco[isp][0]); - histos.fill(HIST("MCReco/Prof_Mult_Nsp_MeanpT"), multPV, isp, sumWiptiReco[isp][0] / sumWiReco[isp][0]); - } - if (sumWiRecoEffCorr[isp][0] > 1.0f) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_Nsp_MeanpT"), cent, isp, sumWiptiRecoEffCorr[isp][0] / sumWiRecoEffCorr[isp][0]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_Nsp_MeanpT"), multPV, isp, sumWiptiRecoEffCorr[isp][0] / sumWiRecoEffCorr[isp][0]); - } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_PiMinus"), cent, gap, sum, c2SubRecoEffCor); } - for (int ietaA = 0; ietaA < KNEta; ++ietaA) { - for (int ietaC = 0; ietaC < KNEta; ++ietaC) { - for (int isp = 0; isp < KNsp; ++isp) { - float nTruAB = sumWiTruth[isp][ietaA] + sumWiTruth[isp][ietaC]; - float nRecoAB = sumWiReco[isp][ietaA] + sumWiReco[isp][ietaC]; - float nCorrAB = sumWiRecoEffCorr[isp][ietaA] + sumWiRecoEffCorr[isp][ietaC]; - - float mptsubTru = (sumWiptiTruth[isp][ietaA] + sumWiptiTruth[isp][ietaC]) / nTruAB; - float mptsubReco = (sumWiptiReco[isp][ietaA] + sumWiptiReco[isp][ietaC]) / nRecoAB; - float mptsubRecoEffCorr = (sumWiptiRecoEffCorr[isp][ietaA] + sumWiptiRecoEffCorr[isp][ietaC]) / nCorrAB; - - if (nTruAB > 0) { - if (isp == kInclusiveIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Tru"), cent, ietaA, ietaC, mptsubTru); - else if (isp == kPiMinusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Tru_PiMinus"), cent, ietaA, ietaC, mptsubTru); - else if (isp == kPiPlusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Tru_PiPlus"), cent, ietaA, ietaC, mptsubTru); - else if (isp == kPiAllIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Tru_PiAll"), cent, ietaA, ietaC, mptsubTru); - else if (isp == kKaMinusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Tru_KaMinus"), cent, ietaA, ietaC, mptsubTru); - else if (isp == kKaPlusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Tru_KaPlus"), cent, ietaA, ietaC, mptsubTru); - else if (isp == kKaAllIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Tru_KaAll"), cent, ietaA, ietaC, mptsubTru); - else if (isp == kPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Tru_Pr"), cent, ietaA, ietaC, mptsubTru); - else if (isp == kAntiPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Tru_AntiPr"), cent, ietaA, ietaC, mptsubTru); - else if (isp == kAllPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Tru_AllPr"), cent, ietaA, ietaC, mptsubTru); - } - - if (nRecoAB > 0) { - if (isp == kInclusiveIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Reco"), cent, ietaA, ietaC, mptsubReco); - else if (isp == kPiMinusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Reco_PiMinus"), cent, ietaA, ietaC, mptsubReco); - else if (isp == kPiPlusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Reco_PiPlus"), cent, ietaA, ietaC, mptsubReco); - else if (isp == kPiAllIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Reco_PiAll"), cent, ietaA, ietaC, mptsubReco); - else if (isp == kKaMinusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Reco_KaMinus"), cent, ietaA, ietaC, mptsubReco); - else if (isp == kKaPlusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Reco_KaPlus"), cent, ietaA, ietaC, mptsubReco); - else if (isp == kKaAllIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Reco_KaAll"), cent, ietaA, ietaC, mptsubReco); - else if (isp == kPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Reco_Pr"), cent, ietaA, ietaC, mptsubReco); - else if (isp == kAntiPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Reco_AntiPr"), cent, ietaA, ietaC, mptsubReco); - else if (isp == kAllPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Reco_AllPr"), cent, ietaA, ietaC, mptsubReco); - } - - if (nCorrAB > 0) { - if (isp == kInclusiveIdx) - histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr"), cent, ietaA, ietaC, mptsubRecoEffCorr); - else if (isp == kPiMinusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_PiMinus"), cent, ietaA, ietaC, mptsubRecoEffCorr); - else if (isp == kPiPlusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_PiPlus"), cent, ietaA, ietaC, mptsubRecoEffCorr); - else if (isp == kPiAllIdx) - histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_PiAll"), cent, ietaA, ietaC, mptsubRecoEffCorr); - else if (isp == kKaMinusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_KaMinus"), cent, ietaA, ietaC, mptsubRecoEffCorr); - else if (isp == kKaPlusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_KaPlus"), cent, ietaA, ietaC, mptsubRecoEffCorr); - else if (isp == kKaAllIdx) - histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_KaAll"), cent, ietaA, ietaC, mptsubRecoEffCorr); - else if (isp == kPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_Pr"), cent, ietaA, ietaC, mptsubRecoEffCorr); - else if (isp == kAntiPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_AntiPr"), cent, ietaA, ietaC, mptsubRecoEffCorr); - else if (isp == kAllPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_AllPr"), cent, ietaA, ietaC, mptsubRecoEffCorr); - } - } - } - - for (int isp = 0; isp < KNsp; ++isp) { - if (sumWiTruth[isp][ietaA] > 0) { - float val = sumWiptiTruth[isp][ietaA] / sumWiTruth[isp][ietaA]; - histos.fill(HIST("pmeanTru_nch_etabin_spbin"), multPV, ietaA, isp, val); - histos.fill(HIST("pmeanMultTru_nch_etabin_spbin"), multPV, ietaA, isp, sumWiTruth[isp][ietaA]); - } - if (sumWiReco[isp][ietaA] > 0) { - float val = sumWiptiReco[isp][ietaA] / sumWiReco[isp][ietaA]; - histos.fill(HIST("pmeanReco_nch_etabin_spbin"), multPV, ietaA, isp, val); - histos.fill(HIST("pmeanMultReco_nch_etabin_spbin"), multPV, ietaA, isp, sumWiReco[isp][ietaA]); - } - if (sumWiRecoEffCorr[isp][ietaA] > 0) { - float val = sumWiptiRecoEffCorr[isp][ietaA] / sumWiRecoEffCorr[isp][ietaA]; - histos.fill(HIST("pmeanRecoEffcorr_nch_etabin_spbin"), multPV, ietaA, isp, val); - histos.fill(HIST("pmeanMultRecoEffcorr_nch_etabin_spbin"), multPV, ietaA, isp, sumWiRecoEffCorr[isp][ietaA]); - } - } - } // end ietaA - - double amplFT0A = 0, amplFT0C = 0; - if (col.has_foundFT0()) { - const auto& ft0 = col.foundFT0(); - for (std::size_t iCh = 0; iCh < ft0.channelA().size(); iCh++) { - auto chanelid = ft0.channelA()[iCh]; - float ampl = ft0.amplitudeA()[iCh]; - amplFT0A += ampl; - auto eta = getEtaFT0(chanelid, 0); - histos.fill(HIST("pmean_cent_id_eta_FT0"), cent, chanelid, eta, ampl); - histos.fill(HIST("h3_cent_id_eta_FT0"), cent, chanelid, eta, ampl); - } - for (std::size_t iCh = 0; iCh < ft0.channelC().size(); iCh++) { - auto chanelid = ft0.channelC()[iCh]; - auto globalId = chanelid + KnFt0cCell; - float ampl = ft0.amplitudeC()[iCh]; - auto eta = getEtaFT0(globalId, 1); - amplFT0C += ampl; - histos.fill(HIST("pmean_cent_id_eta_FT0"), cent, globalId, eta, ampl); - histos.fill(HIST("h3_cent_id_eta_FT0"), cent, globalId, eta, ampl); - } + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kPiPlusIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_PiPlus"), cent, gap, sum, c2SubTru); } - - histos.fill(HIST("pmeanFT0Amultpv"), multPV, amplFT0A); - histos.fill(HIST("pmeanFT0A_cent"), cent, amplFT0A); - histos.fill(HIST("pmeanFT0Cmultpv"), multPV, amplFT0C); - histos.fill(HIST("pmeanFT0C_cent"), cent, amplFT0C); - } - } - } - PROCESS_SWITCH(RadialFlowDecorr, processMCMean, "process MC to calculate mean pt and Eff Hists", cfgRunMCMean); - - void processMCFluc(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/, aod::FT0s const&, aod::McParticles const& mcParticles) - { - if (!state.pmeanTruNchEtabinSpbinStep2 || !state.pmeanRecoNchEtabinSpbinStep2 || !state.pmeanRecoEffcorrNchEtabinSpbinStep2 || - !state.pmeanMultTruNchEtabinSpbinStep2 || !state.pmeanMultRecoNchEtabinSpbinStep2 || !state.pmeanMultRecoEffcorrNchEtabinSpbinStep2) { - LOGF(warning, "MC fluc: Unified Mean pT or Mult map missing"); - return; - } - double sumPmwkTru[KNsp][KNEta][KIntM][KIntK]{}; - double sumWkTru[KNsp][KNEta][KIntK]{}; - double sumPmwkReco[KNsp][KNEta][KIntM][KIntK]{}; - double sumWkReco[KNsp][KNEta][KIntK]{}; - double sumPmwkRecoEffCor[KNsp][KNEta][KIntM][KIntK]{}; - double sumWkRecoEffCor[KNsp][KNEta][KIntK]{}; - - double meanTru[KNsp][KNEta]{}, c2Tru[KNsp][KNEta]{}; - double meanReco[KNsp][KNEta]{}, c2Reco[KNsp][KNEta]{}; - double meanRecoEffCor[KNsp][KNEta]{}, c2RecoEffCor[KNsp][KNEta]{}; - - double meanTruMult[KNsp][KNEta]{}; - double meanRecoMult[KNsp][KNEta]{}; - double meanRecoEffCorMult[KNsp][KNEta]{}; - - double p1kBarTru[KNsp][KNEta]{}, p1kBarReco[KNsp][KNEta]{}, p1kBarRecoEffCor[KNsp][KNEta]{}; - double p1kBarTruMult[KNsp][KNEta]{}, p1kBarRecoMult[KNsp][KNEta]{}, p1kBarRecoEffCorMult[KNsp][KNEta]{}; - - for (const auto& mcCollision : mcColl) { - auto partSlice = mcParticles.sliceBy(partPerMcCollision, mcCollision.globalIndex()); - auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); - if (colSlice.size() != 1) - continue; - - for (const auto& col : colSlice) { - if (!col.has_mcCollision() || !isEventSelected(col)) - continue; - - auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); - if (trackSlice.size() < 1) - continue; - - float cent = getCentrality(col); - if (cent > KCentMax) - continue; - float multPV = col.multNTracksPV(); - - memset(sumPmwkTru, 0, sizeof(sumPmwkTru)); - memset(sumWkTru, 0, sizeof(sumWkTru)); - memset(sumPmwkReco, 0, sizeof(sumPmwkReco)); - memset(sumWkReco, 0, sizeof(sumWkReco)); - memset(sumPmwkRecoEffCor, 0, sizeof(sumPmwkRecoEffCor)); - memset(sumWkRecoEffCor, 0, sizeof(sumWkRecoEffCor)); - - memset(meanTru, 0, sizeof(meanTru)); - memset(c2Tru, 0, sizeof(c2Tru)); - memset(meanReco, 0, sizeof(meanReco)); - memset(c2Reco, 0, sizeof(c2Reco)); - memset(meanRecoEffCor, 0, sizeof(meanRecoEffCor)); - memset(c2RecoEffCor, 0, sizeof(c2RecoEffCor)); - - memset(meanTruMult, 0, sizeof(meanTruMult)); - memset(meanRecoMult, 0, sizeof(meanRecoMult)); - memset(meanRecoEffCorMult, 0, sizeof(meanRecoEffCorMult)); - - memset(p1kBarTru, 0, sizeof(p1kBarTru)); - memset(p1kBarReco, 0, sizeof(p1kBarReco)); - memset(p1kBarRecoEffCor, 0, sizeof(p1kBarRecoEffCor)); - - memset(p1kBarTruMult, 0, sizeof(p1kBarTruMult)); - memset(p1kBarRecoMult, 0, sizeof(p1kBarRecoMult)); - memset(p1kBarRecoEffCorMult, 0, sizeof(p1kBarRecoEffCorMult)); - - double p1kBarFt0A = 0.0, p1kBarFt0C = 0.0; - - for (const auto& particle : partSlice) { - if (!isParticleSelected(particle) || !particle.isPhysicalPrimary()) - continue; - - float pt = particle.pt(); - if (pt <= cfgPtMin || pt > cfgPtMax) - continue; - float eta = particle.eta(); - int pdgCode = particle.pdgCode(); - int absPdg = std::abs(pdgCode); - - bool isSpecies[KNsp] = { - true, // kInclusiveIdx - pdgCode == -KPiPlus, // kPiMinusIdx - pdgCode == KPiPlus, // kPiPlusIdx - absPdg == KPiPlus, // kPiAllIdx - pdgCode == -KKPlus, // kKaMinusIdx - pdgCode == KKPlus, // kKaPlusIdx - absPdg == KKPlus, // kKaAllIdx - pdgCode == -KProton, // kAntiPrIdx - pdgCode == KProton, // kPrIdx - absPdg == KProton // kAllPrIdx - }; - - for (int ieta = 0; ieta < KNEta; ++ieta) { - if (eta <= etaLw[ieta] || eta > etaUp[ieta]) - continue; - for (int isp = 0; isp < KNsp; ++isp) { - if (isSpecies[isp]) { - for (int k = 0; k < KIntK; ++k) { - for (int m = 0; m < KIntM; ++m) { - sumPmwkTru[isp][ieta][m][k] += std::pow(pt, m); - } - sumWkTru[isp][ieta][k]++; - } - } - } - } - } // end truth loop - float vz = col.posZ(); - - histos.fill(HIST("hZvtx_after_sel"), col.posZ()); - histos.fill(HIST("hCentrality"), cent); - - histos.fill(HIST("Hist2D_globalTracks_PVTracks"), col.multNTracksPV(), trackSlice.size()); - histos.fill(HIST("Hist2D_cent_nch"), trackSlice.size(), cent); - - - for (const auto& track : trackSlice) { - if (!isTrackSelected(track)) - continue; - - float pt = track.pt(); - if (pt <= cfgPtMin || pt > cfgPtMax) - continue; - float eta = track.eta(); - float phi = track.phi(); - auto sign = track.sign(); - bool isPi = selectionPion(track); - bool isKa = selectionKaon(track); - bool isPr = selectionProton(track); - - bool isSpecies[KNsp] = { - true, // kInclusiveIdx - isPi && sign < 0, // kPiMinusIdx - isPi && sign > 0, // kPiPlusIdx - isPi, // kPiAllIdx - isKa && sign < 0, // kKaMinusIdx - isKa && sign > 0, // kKaPlusIdx - isKa, // kKaAllIdx - isPr && sign < 0, // kAntiPrIdx (Negative) - isPr && sign > 0, // kPrIdx (Positive) - isPr // kAllPrIdx - }; - - for (int isp = 0; isp < KNsp; ++isp) { - if (!isSpecies[isp]) - continue; - - float eff = getEfficiency(col.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); - float fake = getEfficiency(col.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); - float flatW = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); - float w = flatW * (1.0 - fake) / eff; - - if (!std::isfinite(w) || w <= 0.f || eff <= KFloatEpsilon) - continue; - - for (int ieta = 0; ieta < KNEta; ++ieta) { - if (eta <= etaLw[ieta] || eta > etaUp[ieta]) - continue; - for (int k = 0; k < KIntK; ++k) { - for (int m = 0; m < KIntM; ++m) { - sumPmwkReco[isp][ieta][m][k] += std::pow(1.0, k) * std::pow(pt, m); - sumPmwkRecoEffCor[isp][ieta][m][k] += std::pow(w, k) * std::pow(pt, m); - } - sumWkReco[isp][ieta][k] += std::pow(1.0, k); - sumWkRecoEffCor[isp][ieta][k] += std::pow(w, k); - } - } - - if (isp == kInclusiveIdx) { - histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kPiMinusIdx) { - histos.fill(HIST("hEtaPhiReco_PiMinus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_PiMinus"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_PiMinus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kPiPlusIdx) { - histos.fill(HIST("hEtaPhiReco_PiPlus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_PiPlus"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_PiPlus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kPiAllIdx) { - histos.fill(HIST("hEtaPhiReco_PiAll"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_PiAll"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_PiAll"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kKaMinusIdx) { - histos.fill(HIST("hEtaPhiReco_KaMinus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_KaMinus"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_KaMinus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kKaPlusIdx) { - histos.fill(HIST("hEtaPhiReco_KaPlus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_KaPlus"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_KaPlus"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kKaAllIdx) { - histos.fill(HIST("hEtaPhiReco_KaAll"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_KaAll"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_KaAll"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kPrIdx) { - histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kAntiPrIdx) { - histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kAllPrIdx) { - histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } - } - } // trkslice - - for (int ieta = 0; ieta < KNEta; ++ieta) { - const int ibx = state.pmeanTruNchEtabinSpbinStep2->GetXaxis()->FindBin(col.multNTracksPV()); - const int iby = ieta + 1; - - for (int isp = 0; isp < KNsp; ++isp) { - const int ibz = isp + 1; - - meanTruMult[isp][ieta] = sumWkTru[isp][ieta][1]; - meanRecoMult[isp][ieta] = sumWkReco[isp][ieta][1]; - meanRecoEffCorMult[isp][ieta] = sumWkRecoEffCor[isp][ieta][1]; - - float mmptTru = state.pmeanTruNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); - float mmptReco = state.pmeanRecoNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); - float mmptRecoEffCor = state.pmeanRecoEffcorrNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); - - float mmMultTru = state.pmeanMultTruNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); - float mmMultReco = state.pmeanMultRecoNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); - float mmMultRecoEffCor = state.pmeanMultRecoEffcorrNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); - - if (std::isfinite(mmptTru)) - std::tie(meanTru[isp][ieta], c2Tru[isp][ieta]) = calculateMeanAndC2FromSums(sumPmwkTru[isp][ieta], sumWkTru[isp][ieta], mmptTru); - if (std::isfinite(mmptReco)) - std::tie(meanReco[isp][ieta], c2Reco[isp][ieta]) = calculateMeanAndC2FromSums(sumPmwkReco[isp][ieta], sumWkReco[isp][ieta], mmptReco); - if (std::isfinite(mmptRecoEffCor)) - std::tie(meanRecoEffCor[isp][ieta], c2RecoEffCor[isp][ieta]) = calculateMeanAndC2FromSums(sumPmwkRecoEffCor[isp][ieta], sumWkRecoEffCor[isp][ieta], mmptRecoEffCor); - - if (mmptTru != 0.0f) - p1kBarTru[isp][ieta] = meanTru[isp][ieta] - mmptTru; - if (mmptReco != 0.0f) - p1kBarReco[isp][ieta] = meanReco[isp][ieta] - mmptReco; - if (mmptRecoEffCor != 0.0f) - p1kBarRecoEffCor[isp][ieta] = meanRecoEffCor[isp][ieta] - mmptRecoEffCor; - - if (mmMultTru != 0.0f) - p1kBarTruMult[isp][ieta] = meanTruMult[isp][ieta] - mmMultTru; - if (mmMultReco != 0.0f) - p1kBarRecoMult[isp][ieta] = meanRecoMult[isp][ieta] - mmMultReco; - if (mmMultRecoEffCor != 0.0f) - p1kBarRecoEffCorMult[isp][ieta] = meanRecoEffCorMult[isp][ieta] - mmMultRecoEffCor; - } - } - - double amplFT0A = 0, amplFT0C = 0; - if (col.has_foundFT0()) { - const auto& ft0 = col.foundFT0(); - for (std::size_t iCh = 0; iCh < ft0.channelA().size(); iCh++) { - float ampl = ft0.amplitudeA()[iCh]; - amplFT0A += ampl; - } - for (std::size_t iCh = 0; iCh < ft0.channelC().size(); iCh++) { - float ampl = ft0.amplitudeC()[iCh]; - amplFT0C += ampl; - } - } - - for (int isp = 0; isp < KNsp; ++isp) { - for (int ieta = 0; ieta < KNEta; ++ieta) { - histos.fill(HIST("MCGen/Prof_Cent_NEta_Nsp_Nchrec"), cent, ieta, isp, sumWkTru[isp][ieta][1]); - histos.fill(HIST("MCGen/Prof_Mult_NEta_Nsp_Nchrec"), multPV, ieta, isp, sumWkTru[isp][ieta][1]); - - histos.fill(HIST("MCReco/Prof_Cent_NEta_Nsp_Nchrec"), cent, ieta, isp, sumWkReco[isp][ieta][1]); - histos.fill(HIST("MCReco/Prof_Mult_NEta_Nsp_Nchrec"), multPV, ieta, isp, sumWkReco[isp][ieta][1]); - - histos.fill(HIST("MCRecoEffCorr/Prof_Cent_NEta_Nsp_Nchrec"), cent, ieta, isp, sumWkRecoEffCor[isp][ieta][1]); - histos.fill(HIST("MCRecoEffCorr/Prof_Mult_NEta_Nsp_Nchrec"), multPV, ieta, isp, sumWkRecoEffCor[isp][ieta][1]); - - if (sumWkTru[isp][ieta][1] > 1.0f) { - histos.fill(HIST("MCGen/Prof_Cent_NEta_Nsp_MeanpT"), cent, ieta, isp, meanTru[isp][ieta]); - histos.fill(HIST("MCGen/Prof_Mult_NEta_Nsp_MeanpT"), multPV, ieta, isp, meanTru[isp][ieta]); - } - if (sumWkReco[isp][ieta][1] > 1.0f) { - histos.fill(HIST("MCReco/Prof_Cent_NEta_Nsp_MeanpT"), cent, ieta, isp, meanReco[isp][ieta]); - histos.fill(HIST("MCReco/Prof_Mult_NEta_Nsp_MeanpT"), multPV, ieta, isp, meanReco[isp][ieta]); - } - if (sumWkRecoEffCor[isp][ieta][1] > 1.0f) { - histos.fill(HIST("MCReco/Prof_Cent_NEta_Nsp_MeanpT"), cent, ieta, isp, meanRecoEffCor[isp][ieta]); - histos.fill(HIST("MCReco/Prof_Mult_NEta_Nsp_MeanpT"), multPV, ieta, isp, meanRecoEffCor[isp][ieta]); - } - } - } - - for (int ieta = 0; ieta < KNEta; ++ieta) { - for (int isp = 0; isp < KNsp; ++isp) { - if (std::isfinite(meanTru[isp][ieta])) { - histos.fill(HIST("MCGen/Prof_MeanpT_Cent_etabin_spbin"), cent, ieta, isp, meanTru[isp][ieta]); - histos.fill(HIST("MCGen/Prof_MeanpT_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, meanTru[isp][ieta]); - } - if (std::isfinite(c2Tru[isp][ieta])) { - histos.fill(HIST("MCGen/Prof_C2_Cent_etabin_spbin"), cent, ieta, isp, c2Tru[isp][ieta]); - histos.fill(HIST("MCGen/Prof_C2_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, c2Tru[isp][ieta]); - } - if (std::isfinite(meanReco[isp][ieta])) { - histos.fill(HIST("MCReco/Prof_MeanpT_Cent_etabin_spbin"), cent, ieta, isp, meanReco[isp][ieta]); - histos.fill(HIST("MCReco/Prof_MeanpT_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, meanReco[isp][ieta]); - } - if (std::isfinite(c2Reco[isp][ieta])) { - histos.fill(HIST("MCReco/Prof_C2_Cent_etabin_spbin"), cent, ieta, isp, c2Reco[isp][ieta]); - histos.fill(HIST("MCReco/Prof_C2_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, c2Reco[isp][ieta]); - } - if (std::isfinite(meanRecoEffCor[isp][ieta])) { - histos.fill(HIST("MCRecoEffCorr/Prof_MeanpT_Cent_etabin_spbin"), cent, ieta, isp, meanRecoEffCor[isp][ieta]); - histos.fill(HIST("MCRecoEffCorr/Prof_MeanpT_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, meanRecoEffCor[isp][ieta]); - } - if (std::isfinite(c2RecoEffCor[isp][ieta])) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2_Cent_etabin_spbin"), cent, ieta, isp, c2RecoEffCor[isp][ieta]); - histos.fill(HIST("MCRecoEffCorr/Prof_C2_Mult_etabin_spbin"), col.multNTracksPV(), ieta, isp, c2RecoEffCor[isp][ieta]); - } - } - } - - p1kBarFt0A = amplFT0A - state.pmeanFT0AmultpvStep2->GetBinContent(state.pmeanFT0AmultpvStep2->GetXaxis()->FindBin(col.multNTracksPV())); - p1kBarFt0C = amplFT0C - state.pmeanFT0CmultpvStep2->GetBinContent(state.pmeanFT0CmultpvStep2->GetXaxis()->FindBin(col.multNTracksPV())); - - for (int ietaA = 1; ietaA <= (KNEta - 1) / 2; ++ietaA) { - int ietaC = KNEta - ietaA; - for (int isp = 0; isp < KNsp; ++isp) { - float c2SubTru = p1kBarTru[isp][ietaA] * p1kBarTru[isp][ietaC]; - float c2SubReco = p1kBarReco[isp][ietaA] * p1kBarReco[isp][ietaC]; - float c2SubRecoEffCor = p1kBarRecoEffCor[isp][ietaA] * p1kBarRecoEffCor[isp][ietaC]; - - float covTru = p1kBarTruMult[isp][ietaA] * p1kBarTru[isp][ietaC]; - float covReco = p1kBarRecoMult[isp][ietaA] * p1kBarReco[isp][ietaC]; - float covRecoEffCor = p1kBarRecoEffCorMult[isp][ietaA] * p1kBarRecoEffCor[isp][ietaC]; - - float covFT0ATru = p1kBarFt0A * p1kBarTru[isp][ietaC]; - float covFT0AReco = p1kBarFt0A * p1kBarReco[isp][ietaC]; - float covFT0ARecoEffCor = p1kBarFt0A * p1kBarRecoEffCor[isp][ietaC]; - - float covFT0CTru = p1kBarFt0C * p1kBarTru[isp][ietaA]; - float covFT0CReco = p1kBarFt0C * p1kBarReco[isp][ietaA]; - float covFT0CRecoEffCor = p1kBarFt0C * p1kBarRecoEffCor[isp][ietaA]; - - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub_Cent_etabin_spbin"), cent, ietaA, isp, c2SubTru); - histos.fill(HIST("MCGen/Prof_C2Sub_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub_Cent_etabin_spbin"), cent, ietaA, isp, c2SubReco); - histos.fill(HIST("MCReco/Prof_C2Sub_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub_Cent_etabin_spbin"), cent, ietaA, isp, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, c2SubRecoEffCor); - } - if (std::isfinite(covTru)) { - histos.fill(HIST("MCGen/Prof_Cov_Cent_etabin_spbin"), cent, ietaA, isp, covTru); - histos.fill(HIST("MCGen/Prof_Cov_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covTru); - } - if (std::isfinite(covReco)) { - histos.fill(HIST("MCReco/Prof_Cov_Cent_etabin_spbin"), cent, ietaA, isp, covReco); - histos.fill(HIST("MCReco/Prof_Cov_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covReco); - } - if (std::isfinite(covRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_Cov_Cent_etabin_spbin"), cent, ietaA, isp, covRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_Cov_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covRecoEffCor); - } - - if (std::isfinite(covFT0ATru)) { - histos.fill(HIST("MCGen/Prof_CovFT0A_Cent_etabin_spbin"), cent, ietaA, isp, covFT0ATru); - histos.fill(HIST("MCGen/Prof_CovFT0A_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0ATru); - } - if (std::isfinite(covFT0AReco)) { - histos.fill(HIST("MCReco/Prof_CovFT0A_Cent_etabin_spbin"), cent, ietaA, isp, covFT0AReco); - histos.fill(HIST("MCReco/Prof_CovFT0A_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0AReco); - } - if (std::isfinite(covFT0ARecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A_Cent_etabin_spbin"), cent, ietaA, isp, covFT0ARecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0ARecoEffCor); - } - - if (std::isfinite(covFT0CTru)) { - histos.fill(HIST("MCGen/Prof_CovFT0C_Cent_etabin_spbin"), cent, ietaA, isp, covFT0CTru); - histos.fill(HIST("MCGen/Prof_CovFT0C_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0CTru); - } - if (std::isfinite(covFT0CReco)) { - histos.fill(HIST("MCReco/Prof_CovFT0C_Cent_etabin_spbin"), cent, ietaA, isp, covFT0CReco); - histos.fill(HIST("MCReco/Prof_CovFT0C_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0CReco); - } - if (std::isfinite(covFT0CRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C_Cent_etabin_spbin"), cent, ietaA, isp, covFT0CRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C_Mult_etabin_spbin"), col.multNTracksPV(), ietaA, isp, covFT0CRecoEffCor); - } - } - } - - for (int ietaA = 1; ietaA < KNEta; ++ietaA) { - for (int ietaC = 1; ietaC < KNEta; ++ietaC) { - - float etaValA = (etaLw[ietaA] + etaUp[ietaA]) / 2.0f; - float etaValB = (etaLw[ietaC] + etaUp[ietaC]) / 2.0f; - float gap = etaValA - etaValB; - float sum = (etaValA + etaValB) / 2.0f; - for (int isp = 0; isp < KNsp; ++isp) { - - float c2SubTru = p1kBarTru[isp][ietaA] * p1kBarTru[isp][ietaC]; - float c2SubReco = p1kBarReco[isp][ietaA] * p1kBarReco[isp][ietaC]; - float c2SubRecoEffCor = p1kBarRecoEffCor[isp][ietaA] * p1kBarRecoEffCor[isp][ietaC]; - - float covTru = p1kBarTruMult[isp][ietaA] * p1kBarTru[isp][ietaC]; - float covReco = p1kBarRecoMult[isp][ietaA] * p1kBarReco[isp][ietaC]; - float covRecoEffCor = p1kBarRecoEffCorMult[isp][ietaA] * p1kBarRecoEffCor[isp][ietaC]; - - float covFT0ATru = p1kBarFt0A * p1kBarTru[isp][ietaC]; - float covFT0AReco = p1kBarFt0A * p1kBarReco[isp][ietaC]; - float covFT0ARecoEffCor = p1kBarFt0A * p1kBarRecoEffCor[isp][ietaC]; - - float covFT0CTru = p1kBarFt0C * p1kBarTru[isp][ietaA]; - float covFT0CReco = p1kBarFt0C * p1kBarReco[isp][ietaA]; - float covFT0CRecoEffCor = p1kBarFt0C * p1kBarRecoEffCor[isp][ietaA]; - - if (isp == kInclusiveIdx) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_GapSum2D"), cent, gap, sum, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_GapSum2D"), cent, gap, sum, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D"), cent, gap, sum, c2SubRecoEffCor); - } - - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covRecoEffCor); - - if (std::isfinite(covFT0ATru)) - histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0ATru); - if (std::isfinite(covFT0AReco)) - histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0AReco); - if (std::isfinite(covFT0ARecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0ARecoEffCor); - - if (std::isfinite(covFT0CTru)) - histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0CTru); - if (std::isfinite(covFT0CReco)) - histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0CReco); - if (std::isfinite(covFT0CRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0CRecoEffCor); - - } else if (isp == kPiMinusIdx) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_GapSum2D_PiMinus"), cent, gap, sum, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_GapSum2D_PiMinus"), cent, gap, sum, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_PiMinus"), cent, gap, sum, c2SubRecoEffCor); - } - - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covRecoEffCor); - - if (std::isfinite(covFT0ATru)) - histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0ATru); - if (std::isfinite(covFT0AReco)) - histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0AReco); - if (std::isfinite(covFT0ARecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0ARecoEffCor); - - if (std::isfinite(covFT0CTru)) - histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0CTru); - if (std::isfinite(covFT0CReco)) - histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0CReco); - if (std::isfinite(covFT0CRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0CRecoEffCor); - - } else if (isp == kPiPlusIdx) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_GapSum2D_PiPlus"), cent, gap, sum, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_GapSum2D_PiPlus"), cent, gap, sum, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_PiPlus"), cent, gap, sum, c2SubRecoEffCor); - } - - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covRecoEffCor); - - if (std::isfinite(covFT0ATru)) - histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0ATru); - if (std::isfinite(covFT0AReco)) - histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0AReco); - if (std::isfinite(covFT0ARecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0ARecoEffCor); - - if (std::isfinite(covFT0CTru)) - histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0CTru); - if (std::isfinite(covFT0CReco)) - histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0CReco); - if (std::isfinite(covFT0CRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0CRecoEffCor); - - } else if (isp == kPiAllIdx) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_GapSum2D_PiAll"), cent, gap, sum, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_GapSum2D_PiAll"), cent, gap, sum, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_PiAll"), cent, gap, sum, c2SubRecoEffCor); - } - - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covRecoEffCor); - - if (std::isfinite(covFT0ATru)) - histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0ATru); - if (std::isfinite(covFT0AReco)) - histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0AReco); - if (std::isfinite(covFT0ARecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0ARecoEffCor); - - if (std::isfinite(covFT0CTru)) - histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0CTru); - if (std::isfinite(covFT0CReco)) - histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0CReco); - if (std::isfinite(covFT0CRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0CRecoEffCor); - - } else if (isp == kKaMinusIdx) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_GapSum2D_KaMinus"), cent, gap, sum, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_GapSum2D_KaMinus"), cent, gap, sum, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_KaMinus"), cent, gap, sum, c2SubRecoEffCor); - } - - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covRecoEffCor); - - if (std::isfinite(covFT0ATru)) - histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0ATru); - if (std::isfinite(covFT0AReco)) - histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0AReco); - if (std::isfinite(covFT0ARecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0ARecoEffCor); - - if (std::isfinite(covFT0CTru)) - histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0CTru); - if (std::isfinite(covFT0CReco)) - histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0CReco); - if (std::isfinite(covFT0CRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0CRecoEffCor); - - } else if (isp == kKaPlusIdx) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_GapSum2D_KaPlus"), cent, gap, sum, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_GapSum2D_KaPlus"), cent, gap, sum, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_KaPlus"), cent, gap, sum, c2SubRecoEffCor); - } - - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covRecoEffCor); - - if (std::isfinite(covFT0ATru)) - histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0ATru); - if (std::isfinite(covFT0AReco)) - histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0AReco); - if (std::isfinite(covFT0ARecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0ARecoEffCor); - - if (std::isfinite(covFT0CTru)) - histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0CTru); - if (std::isfinite(covFT0CReco)) - histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0CReco); - if (std::isfinite(covFT0CRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0CRecoEffCor); - - } else if (isp == kKaAllIdx) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_GapSum2D_KaAll"), cent, gap, sum, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_GapSum2D_KaAll"), cent, gap, sum, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_KaAll"), cent, gap, sum, c2SubRecoEffCor); - } - - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covRecoEffCor); - - if (std::isfinite(covFT0ATru)) - histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0ATru); - if (std::isfinite(covFT0AReco)) - histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0AReco); - if (std::isfinite(covFT0ARecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0ARecoEffCor); - - if (std::isfinite(covFT0CTru)) - histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0CTru); - if (std::isfinite(covFT0CReco)) - histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0CReco); - if (std::isfinite(covFT0CRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0CRecoEffCor); - - } else if (isp == kPrIdx) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_GapSum2D_Pr"), cent, gap, sum, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_GapSum2D_Pr"), cent, gap, sum, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_Pr"), cent, gap, sum, c2SubRecoEffCor); - } - - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covRecoEffCor); - - if (std::isfinite(covFT0ATru)) - histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0ATru); - if (std::isfinite(covFT0AReco)) - histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0AReco); - if (std::isfinite(covFT0ARecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0ARecoEffCor); - - if (std::isfinite(covFT0CTru)) - histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0CTru); - if (std::isfinite(covFT0CReco)) - histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0CReco); - if (std::isfinite(covFT0CRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0CRecoEffCor); - - } else if (isp == kAntiPrIdx) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_GapSum2D_AntiPr"), cent, gap, sum, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_GapSum2D_AntiPr"), cent, gap, sum, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_AntiPr"), cent, gap, sum, c2SubRecoEffCor); - } - - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covRecoEffCor); - - if (std::isfinite(covFT0ATru)) - histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0ATru); - if (std::isfinite(covFT0AReco)) - histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0AReco); - if (std::isfinite(covFT0ARecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0ARecoEffCor); - - if (std::isfinite(covFT0CTru)) - histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0CTru); - if (std::isfinite(covFT0CReco)) - histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0CReco); - if (std::isfinite(covFT0CRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0CRecoEffCor); - - } else if (isp == kAllPrIdx) { - if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_GapSum2D_AllPr"), cent, gap, sum, c2SubTru); - } - if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_GapSum2D_AllPr"), cent, gap, sum, c2SubReco); - } - if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_AllPr"), cent, gap, sum, c2SubRecoEffCor); - } - - if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covTru); - if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covReco); - if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covRecoEffCor); - - if (std::isfinite(covFT0ATru)) - histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0ATru); - if (std::isfinite(covFT0AReco)) - histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0AReco); - if (std::isfinite(covFT0ARecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0ARecoEffCor); - - if (std::isfinite(covFT0CTru)) - histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0CTru); - if (std::isfinite(covFT0CReco)) - histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0CReco); - if (std::isfinite(covFT0CRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0CRecoEffCor); - } - } - } - } - } // colSlice - } // mcColl - LOGF(info, "FINISHED RUNNING processMCFluc"); - } - PROCESS_SWITCH(RadialFlowDecorr, processMCFluc, "process MC to calculate pt fluc", cfgRunMCFluc); - - void processGetDataFlat(AodCollisionsSel::iterator const& coll, BCsRun3 const& /*bcs*/, aod::Zdcs const& /*zdcsData*/, AodTracksSel const& tracks) - { - histos.fill(HIST("hVtxZ"), coll.posZ()); - if (!isEventSelected(coll)) - return; - float cent = getCentrality(coll); - if (cent > KCentMax) - return; - - histos.fill(HIST("hZvtx_after_sel"), coll.posZ()); - histos.fill(HIST("hCentrality"), cent); - - histos.fill(HIST("Hist2D_globalTracks_PVTracks"), coll.multNTracksPV(), tracks.size()); - histos.fill(HIST("Hist2D_cent_nch"), tracks.size(), cent); - - int ntrk = 0; - float vz = coll.posZ(); - - for (const auto& track : tracks) { - if (!isTrackSelected(track)) - continue; - float pt = track.pt(); - if (pt <= cfgPtMin || pt > cfgPtMax) - continue; - float eta = track.eta(); - float phi = track.phi(); - auto sign = track.sign(); - - if (eta > etaLw[0] && eta < etaUp[0]) - ntrk++; - - if (sign > 0) { - // PiPlus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiPlus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiPlus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); - // KaPlus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaPlus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaPlus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); - // Pr - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_Pr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_Pr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); - } else if (sign < 0) { - // PiMinus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiMinus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiMinus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); - // KaMinus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaMinus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaMinus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); - // AntiPr - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_AntiPr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_AntiPr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_PiPlus"), cent, gap, sum, c2SubReco); } - - bool isPi = selectionPion(track); - bool isKa = selectionKaon(track); - bool isPr = selectionProton(track); - - bool isSpecies[KNsp] = { - true, // kInclusiveIdx - isPi && sign < 0, // kPiMinusIdx - isPi && sign > 0, // kPiPlusIdx - isPi, // kPiAllIdx - isKa && sign < 0, // kKaMinusIdx - isKa && sign > 0, // kKaPlusIdx - isKa, // kKaAllIdx - isPr && sign < 0, // kAntiPrIdx (Negative) - isPr && sign > 0, // kPrIdx (Positive) - isPr // kAllPrIdx - }; - - if (isSpecies[kPiPlusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiPlus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiPlus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); - } else if (isSpecies[kPiMinusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiMinus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiMinus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_PiPlus"), cent, gap, sum, c2SubRecoEffCor); } - if (isSpecies[kKaPlusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaPlus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaPlus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); - } else if (isSpecies[kKaMinusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaMinus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaMinus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kPiAllIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_PiAll"), cent, gap, sum, c2SubTru); } - - if (isSpecies[kPrIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_Pr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_Pr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); - } else if (isSpecies[kAntiPrIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_AntiPr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_AntiPr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_PiAll"), cent, gap, sum, c2SubReco); } - - for (int isp = 0; isp < KNsp; ++isp) { - if (!isSpecies[isp]) - continue; - float eff = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); - if (eff <= KFloatEpsilon) - continue; - - float fake = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); - float w = (1.0f - fake) / eff; - - if (!std::isfinite(w) || w <= 0.f) - continue; - - if (isp == kInclusiveIdx) { - histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); - } else if (isp == kPiMinusIdx) { - histos.fill(HIST("hEtaPhiReco_PiMinus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_PiMinus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_PiMinus"), vz, sign, pt, eta, phi, w); - } else if (isp == kPiPlusIdx) { - histos.fill(HIST("hEtaPhiReco_PiPlus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_PiPlus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_PiPlus"), vz, sign, pt, eta, phi, w); - } else if (isp == kPiAllIdx) { - histos.fill(HIST("hEtaPhiReco_PiAll"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_PiAll"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_PiAll"), vz, sign, pt, eta, phi, w); - } else if (isp == kKaMinusIdx) { - histos.fill(HIST("hEtaPhiReco_KaMinus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_KaMinus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_KaMinus"), vz, sign, pt, eta, phi, w); - } else if (isp == kKaPlusIdx) { - histos.fill(HIST("hEtaPhiReco_KaPlus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_KaPlus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_KaPlus"), vz, sign, pt, eta, phi, w); - } else if (isp == kKaAllIdx) { - histos.fill(HIST("hEtaPhiReco_KaAll"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_KaAll"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_KaAll"), vz, sign, pt, eta, phi, w); - } else if (isp == kPrIdx) { - histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); - } else if (isp == kAntiPrIdx) { - histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); - } else if (isp == kAllPrIdx) { - histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); - } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_PiAll"), cent, gap, sum, c2SubRecoEffCor); } - } - - histos.fill(HIST("hCentnTrk"), cent, ntrk); - histos.fill(HIST("hCentnTrkPV"), cent, coll.multNTracksPV()); - if (cfgZDC) { - const auto& foundBC = coll.foundBC_as(); - if (!foundBC.has_zdc()) { - return; + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kKaMinusIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_KaMinus"), cent, gap, sum, c2SubTru); } - auto zdc = foundBC.zdc(); - auto zdcAmp = zdc.energyCommonZNA() + zdc.energyCommonZNC(); - histos.fill(HIST("hnTrkPVZDC"), coll.multNTracksPV(), zdcAmp); - histos.fill(HIST("hNchZDC"), ntrk, zdcAmp); - } - } - PROCESS_SWITCH(RadialFlowDecorr, processGetDataFlat, "process data to calculate Flattening maps", cfgRunGetDataFlat); - - void processDataMean(AodCollisionsSel::iterator const& coll, BCsRun3 const& /*bcs*/, aod::Zdcs const& /*zdcsData*/, aod::FT0s const&, AodTracksSel const& tracks) - { - double sumWi[KNsp][KNEta]{}, sumWipti[KNsp][KNEta]{}; - - if (!isEventSelected(coll)) - return; - - float cent = getCentrality(coll); - if (cent > KCentMax) - return; - - histos.fill(HIST("hZvtx_after_sel"), coll.posZ()); - histos.fill(HIST("hCentrality"), cent); - - histos.fill(HIST("Hist2D_globalTracks_PVTracks"), coll.multNTracksPV(), tracks.size()); - histos.fill(HIST("Hist2D_cent_nch"), tracks.size(), cent); - - float vz = coll.posZ(); - - for (const auto& track : tracks) { - if (!isTrackSelected(track)) - continue; - - float p = track.p(); - float pt = track.pt(); - float eta = track.eta(); - float phi = track.phi(); - auto sign = track.sign(); - - if (p < KFloatEpsilon) - continue; - - if (pt <= cfgPtMin || pt > cfgPtMax) - continue; - - histos.fill(HIST("hP"), p); - histos.fill(HIST("hPt"), pt); - histos.fill(HIST("hEta"), eta); - histos.fill(HIST("hPhi"), phi); - - bool isPi = selectionPion(track); - bool isKa = selectionKaon(track); - bool isPr = selectionProton(track); - - // Updated to use the correct PIDIdx enum names - bool isSpecies[KNsp] = { - true, // kInclusiveIdx - isPi && sign < 0, // kPiMinusIdx - isPi && sign > 0, // kPiPlusIdx - isPi, // kPiAllIdx - isKa && sign < 0, // kKaMinusIdx - isKa && sign > 0, // kKaPlusIdx - isKa, // kKaAllIdx - isPr && sign < 0, // kAntiPrIdx (Negative) - isPr && sign > 0, // kPrIdx (Positive) - isPr // kAllPrIdx - }; - - for (int isp = 0; isp < KNsp; ++isp) { - if (!isSpecies[isp]) - continue; - - float eff = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); - - // Safety check BEFORE dividing - if (eff <= KFloatEpsilon) - continue; - - float fake = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); - float flatWeight = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); - float w = flatWeight * (1.0f - fake) / eff; - - if (!std::isfinite(w) || w <= 0.f) - continue; - - if (isp == kInclusiveIdx) { - histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); - } else if (isp == kPiMinusIdx) { - histos.fill(HIST("hEtaPhiReco_PiMinus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_PiMinus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_PiMinus"), vz, sign, pt, eta, phi, w); - } else if (isp == kPiPlusIdx) { - histos.fill(HIST("hEtaPhiReco_PiPlus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_PiPlus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_PiPlus"), vz, sign, pt, eta, phi, w); - } else if (isp == kPiAllIdx) { - histos.fill(HIST("hEtaPhiReco_PiAll"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_PiAll"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_PiAll"), vz, sign, pt, eta, phi, w); - } else if (isp == kKaMinusIdx) { - histos.fill(HIST("hEtaPhiReco_KaMinus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_KaMinus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_KaMinus"), vz, sign, pt, eta, phi, w); - } else if (isp == kKaPlusIdx) { - histos.fill(HIST("hEtaPhiReco_KaPlus"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_KaPlus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_KaPlus"), vz, sign, pt, eta, phi, w); - } else if (isp == kKaAllIdx) { - histos.fill(HIST("hEtaPhiReco_KaAll"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_KaAll"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_KaAll"), vz, sign, pt, eta, phi, w); - } else if (isp == kPrIdx) { - histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); - } else if (isp == kAntiPrIdx) { - histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); - } else if (isp == kAllPrIdx) { - histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); - } - - for (int ieta = 0; ieta < KNEta; ++ieta) { - if (eta <= etaLw[ieta] || eta > etaUp[ieta]) - continue; - sumWi[isp][ieta] += w; - sumWipti[isp][ieta] += w * pt; - } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_KaMinus"), cent, gap, sum, c2SubReco); } - } - - for (int isp = 0; isp < KNsp; ++isp) { - histos.fill(HIST("Prof_Cent_Nsp_Nchrec"), cent, isp, sumWi[isp][0]); - histos.fill(HIST("Prof_Mult_Nsp_Nchrec"), coll.multNTracksPV(), isp, sumWi[isp][0]); - if (sumWi[isp][0] > 1.0f) - histos.fill(HIST("Prof_Cent_Nsp_MeanpT"), cent, isp, sumWipti[isp][0] / sumWi[isp][0]); - histos.fill(HIST("Prof_Mult_Nsp_MeanpT"), coll.multNTracksPV(), isp, sumWipti[isp][0] / sumWi[isp][0]); - } - - for (int ietaA = 0; ietaA < KNEta; ++ietaA) { - for (int ietaC = 0; ietaC < KNEta; ++ietaC) { - for (int isp = 0; isp < KNsp; ++isp) { - double wCorrAB = sumWi[isp][ietaA] + sumWi[isp][ietaC]; - if (wCorrAB > 0) { - float mptsub = (sumWipti[isp][ietaA] + sumWipti[isp][ietaC]) / wCorrAB; - if (isp == kInclusiveIdx) - histos.fill(HIST("Prof2D_MeanpTSub"), cent, ietaA, ietaC, mptsub); - else if (isp == kPiMinusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_PiMinus"), cent, ietaA, ietaC, mptsub); - else if (isp == kPiPlusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_PiPlus"), cent, ietaA, ietaC, mptsub); - else if (isp == kPiAllIdx) - histos.fill(HIST("Prof2D_MeanpTSub_PiAll"), cent, ietaA, ietaC, mptsub); - else if (isp == kKaMinusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_KaMinus"), cent, ietaA, ietaC, mptsub); - else if (isp == kKaPlusIdx) - histos.fill(HIST("Prof2D_MeanpTSub_KaPlus"), cent, ietaA, ietaC, mptsub); - else if (isp == kKaAllIdx) - histos.fill(HIST("Prof2D_MeanpTSub_KaAll"), cent, ietaA, ietaC, mptsub); - else if (isp == kPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Pr"), cent, ietaA, ietaC, mptsub); - else if (isp == kAntiPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_AntiPr"), cent, ietaA, ietaC, mptsub); - else if (isp == kAllPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_AllPr"), cent, ietaA, ietaC, mptsub); - } - if (ietaA == ietaC) { - double mpt = sumWipti[isp][ietaA] / sumWi[isp][ietaA]; - if (sumWi[isp][ietaA] >= 1.0f && std::isfinite(mpt)) { - histos.fill(HIST("pmean_nch_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, mpt); - histos.fill(HIST("pmeanMult_nch_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, sumWi[isp][ietaA]); - histos.fill(HIST("pmean_cent_etabin_spbin"), cent, ietaA, isp, mpt); - histos.fill(HIST("pmeanMult_cent_etabin_spbin"), cent, ietaA, isp, sumWi[isp][ietaA]); - } - } - } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_KaMinus"), cent, gap, sum, c2SubRecoEffCor); } - } - double amplFT0A = 0, amplFT0C = 0; - if (coll.has_foundFT0()) { - const auto& ft0 = coll.foundFT0(); - for (std::size_t iCh = 0; iCh < ft0.channelA().size(); iCh++) { - auto chanelid = ft0.channelA()[iCh]; - float ampl = ft0.amplitudeA()[iCh]; - amplFT0A += ampl; - auto eta = getEtaFT0(chanelid, 0); - histos.fill(HIST("pmean_cent_id_eta_FT0"), cent, chanelid, eta, ampl); - histos.fill(HIST("h3_cent_id_eta_FT0"), cent, chanelid, eta, ampl); + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kKaPlusIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_KaPlus"), cent, gap, sum, c2SubTru); } - for (std::size_t iCh = 0; iCh < ft0.channelC().size(); iCh++) { - auto chanelid = ft0.channelC()[iCh]; - auto globalId = chanelid + KnFt0cCell; - float ampl = ft0.amplitudeC()[iCh]; - auto eta = getEtaFT0(globalId, 1); - amplFT0C += ampl; - histos.fill(HIST("pmean_cent_id_eta_FT0"), cent, globalId, eta, ampl); - histos.fill(HIST("h3_cent_id_eta_FT0"), cent, globalId, eta, ampl); + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_KaPlus"), cent, gap, sum, c2SubReco); } - } - - histos.fill(HIST("pmeanFT0Amultpv"), coll.multNTracksPV(), amplFT0A); - histos.fill(HIST("pmeanFT0A_cent"), cent, amplFT0A); - histos.fill(HIST("pmeanFT0Cmultpv"), coll.multNTracksPV(), amplFT0C); - histos.fill(HIST("pmeanFT0C_cent"), cent, amplFT0C); - } - PROCESS_SWITCH(RadialFlowDecorr, processDataMean, "process data to calculate mean pT", cfgRunDataMean); - - void processDataFluc(AodCollisionsSel::iterator const& coll, BCsRun3 const& /*bcs*/, aod::Zdcs const& /*zdcsData*/, aod::FT0s const&, AodTracksSel const& tracks) - { - if (!isEventSelected(coll)) - return; - float cent = getCentrality(coll); - if (cent > KCentMax) - return; - - if (!state.pmeanNchEtabinSpbinStep2 || !state.pmeanMultNchEtabinSpbinStep2) { - LOGF(warning, "Data fluc: Mean pT or Mult map missing"); - return; - } - - for (int isp = 0; isp < KNsp; ++isp) { - auto pid = static_cast(isp); - if (!state.hEff[pid] || !state.hFake[pid] || !state.hFlatWeight[pid]) { - LOGF(warning, "Data fluc: Correction maps (Eff, Fake, or Flat) are null for species index %d", isp); - return; + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_KaPlus"), cent, gap, sum, c2SubRecoEffCor); } - } - - double sumpmwk[KNsp][KNEta][KIntM][KIntK]{}; - double sumwk[KNsp][KNEta][KIntK]{}; - - double mean[KNsp][KNEta]{}, c2[KNsp][KNEta]{}; - double p1kBar[KNsp][KNEta]{}; - double meanMult[KNsp][KNEta]{}, p1kBarMult[KNsp][KNEta]{}; - float vz = coll.posZ(); - - for (const auto& track : tracks) { - if (!isTrackSelected(track)) - continue; - - float p = track.p(); - float pt = track.pt(); - float eta = track.eta(); - float phi = track.phi(); - auto sign = track.sign(); - - if (p < KFloatEpsilon) - continue; - - if (pt <= cfgPtMin || pt > cfgPtMax) - continue; - - bool isPi = selectionPion(track); - bool isKa = selectionKaon(track); - bool isPr = selectionProton(track); - - // Updated to use the correct PIDIdx enum names - bool isSpecies[KNsp] = { - true, // kInclusiveIdx - isPi && sign < 0, // kPiMinusIdx - isPi && sign > 0, // kPiPlusIdx - isPi, // kPiAllIdx - isKa && sign < 0, // kKaMinusIdx - isKa && sign > 0, // kKaPlusIdx - isKa, // kKaAllIdx - isPr && sign < 0, // kAntiPrIdx (Negative) - isPr && sign > 0, // kPrIdx (Positive) - isPr // kAllPrIdx - }; - - for (int isp = 0; isp < KNsp; ++isp) { - if (!isSpecies[isp]) - continue; - - float eff = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); - - // Safety check BEFORE dividing - if (eff <= KFloatEpsilon) - continue; - - float fake = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); - float flatWeight = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); - float w = flatWeight * (1.0f - fake) / eff; - - if (!std::isfinite(w) || w <= 0.f) - continue; - - for (int ieta = 0; ieta < KNEta; ++ieta) { - if (eta <= etaLw[ieta] || eta > etaUp[ieta]) - continue; - for (int k = 0; k < KIntK; ++k) { - for (int m = 0; m < KIntM; ++m) { - sumpmwk[isp][ieta][m][k] += std::pow(w, k) * std::pow(pt, m); - } - sumwk[isp][ieta][k] += std::pow(w, k); - } - } + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kKaAllIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_KaAll"), cent, gap, sum, c2SubTru); } - } - - double amplFT0A = 0, amplFT0C = 0; - if (coll.has_foundFT0()) { - const auto& ft0 = coll.foundFT0(); - for (std::size_t iCh = 0; iCh < ft0.channelA().size(); iCh++) { - float ampl = ft0.amplitudeA()[iCh]; - amplFT0A += ampl; + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_KaAll"), cent, gap, sum, c2SubReco); } - for (std::size_t iCh = 0; iCh < ft0.channelC().size(); iCh++) { - float ampl = ft0.amplitudeC()[iCh]; - amplFT0C += ampl; + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_KaAll"), cent, gap, sum, c2SubRecoEffCor); } - } - double p1kBarFt0A = amplFT0A - state.pmeanFT0AmultpvStep2->GetBinContent(state.pmeanFT0AmultpvStep2->GetXaxis()->FindBin(coll.multNTracksPV())); - double p1kBarFt0C = amplFT0C - state.pmeanFT0CmultpvStep2->GetBinContent(state.pmeanFT0CmultpvStep2->GetXaxis()->FindBin(coll.multNTracksPV())); - for (int ieta = 0; ieta < KNEta; ++ieta) { - const int ibx = state.pmeanNchEtabinSpbinStep2->GetXaxis()->FindBin(coll.multNTracksPV()); - const int iby = ieta + 1; - - for (int isp = 0; isp < KNsp; ++isp) { - const int ibz = isp + 1; - - float mmpt = state.pmeanNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); - float mmMult = state.pmeanMultNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); - - mean[isp][ieta] = sumpmwk[isp][ieta][1][1] / sumwk[isp][ieta][1]; - meanMult[isp][ieta] = sumwk[isp][ieta][1]; - - if (std::isfinite(mmpt)) { - std::tie(mean[isp][ieta], c2[isp][ieta]) = calculateMeanAndC2FromSums(sumpmwk[isp][ieta], sumwk[isp][ieta], mmpt); - p1kBar[isp][ieta] = mean[isp][ieta] - mmpt; - } - p1kBarMult[isp][ieta] = meanMult[isp][ieta] - mmMult; + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kPrIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_Pr"), cent, gap, sum, c2SubTru); } - } - for (int ieta = 0; ieta < KNEta; ++ieta) { - for (int isp = 0; isp < KNsp; ++isp) { - if (std::isfinite(mean[isp][ieta])) { - histos.fill(HIST("Prof_MeanpT_Cent_etabin_spbin"), cent, ieta, isp, mean[isp][ieta]); - histos.fill(HIST("Prof_MeanpT_Mult_etabin_spbin"), coll.multNTracksPV(), ieta, isp, mean[isp][ieta]); - } - if (std::isfinite(c2[isp][ieta])) { - histos.fill(HIST("Prof_C2_Cent_etabin_spbin"), cent, ieta, isp, c2[isp][ieta]); - histos.fill(HIST("Prof_C2_Mult_etabin_spbin"), coll.multNTracksPV(), ieta, isp, c2[isp][ieta]); - } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_Pr"), cent, gap, sum, c2SubReco); + } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_Pr"), cent, gap, sum, c2SubRecoEffCor); } - } - - for (int ietaA = 1; ietaA <= (KNEta - 1) / 2; ++ietaA) { - int ietaC = KNEta - ietaA; - for (int isp = 0; isp < KNsp; ++isp) { - float c2Sub = p1kBar[isp][ietaA] * p1kBar[isp][ietaC]; - float covAC = p1kBarMult[isp][ietaA] * p1kBar[isp][ietaC]; - float covCA = p1kBar[isp][ietaA] * p1kBarMult[isp][ietaC]; - - float covFT0A = p1kBarFt0A * p1kBar[isp][ietaC]; - float covFT0C = p1kBarFt0C * p1kBar[isp][ietaA]; - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub_Cent_etabin_spbin"), cent, ietaA, isp, c2Sub); - histos.fill(HIST("Prof_C2Sub_Mult_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, c2Sub); - } - if (std::isfinite(covAC)) { - histos.fill(HIST("Prof_Cov_Cent_etabin_spbin"), cent, ietaA, isp, covAC); - histos.fill(HIST("Prof_Cov_Mult_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, covAC); - } - if (std::isfinite(covCA)) { - histos.fill(HIST("Prof_Cov_Cent_etabin_spbin"), cent, ietaA, isp, covCA); - histos.fill(HIST("Prof_Cov_Mult_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, covCA); - } - if (std::isfinite(covFT0A)) { - histos.fill(HIST("Prof_CovFT0A_Cent_etabin_spbin"), cent, ietaA, isp, covFT0A); - histos.fill(HIST("Prof_CovFT0A_Mult_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, covFT0A); - } - if (std::isfinite(covFT0C)) { - histos.fill(HIST("Prof_CovFT0C_Cent_etabin_spbin"), cent, ietaA, isp, covFT0C); - histos.fill(HIST("Prof_CovFT0C_Mult_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, covFT0C); - } + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kAntiPrIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_AntiPr"), cent, gap, sum, c2SubTru); + } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_AntiPr"), cent, gap, sum, c2SubReco); + } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_AntiPr"), cent, gap, sum, c2SubRecoEffCor); } - } - for (int ietaA = 1; ietaA < KNEta; ++ietaA) { - for (int ietaC = 1; ietaC < KNEta; ++ietaC) { - - float etaValA = (etaLw[ietaA] + etaUp[ietaA]) / 2.0f; - float etaValB = (etaLw[ietaC] + etaUp[ietaC]) / 2.0f; - float gap = etaValA - etaValB; - float sum = (etaValA + etaValB) / 2.0f; - - for (int isp = 0; isp < KNsp; ++isp) { - - float c2Sub = p1kBar[isp][ietaA] * p1kBar[isp][ietaC]; - float cov = p1kBarMult[isp][ietaA] * p1kBar[isp][ietaC]; - float covFT0A = p1kBarFt0A * p1kBar[isp][ietaC]; - float covFT0C = p1kBarFt0C * p1kBar[isp][ietaA]; - - // Updated enum checks here - if (isp == kInclusiveIdx) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_GapSum2D"), cent, gap, sum, c2Sub); - } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, cov); - if (std::isfinite(covFT0A)) - histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0A); - if (std::isfinite(covFT0C)) - histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0C); - } else if (isp == kPiMinusIdx) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_GapSum2D_PiMinus"), cent, gap, sum, c2Sub); - } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, cov); - if (std::isfinite(covFT0A)) - histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0A); - if (std::isfinite(covFT0C)) - histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0C); - } else if (isp == kPiPlusIdx) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_GapSum2D_PiPlus"), cent, gap, sum, c2Sub); - } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, cov); - if (std::isfinite(covFT0A)) - histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0A); - if (std::isfinite(covFT0C)) - histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0C); - } else if (isp == kPiAllIdx) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_GapSum2D_PiAll"), cent, gap, sum, c2Sub); - } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, cov); - if (std::isfinite(covFT0A)) - histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0A); - if (std::isfinite(covFT0C)) - histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0C); - } else if (isp == kKaMinusIdx) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_GapSum2D_KaMinus"), cent, gap, sum, c2Sub); - } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, cov); - if (std::isfinite(covFT0A)) - histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0A); - if (std::isfinite(covFT0C)) - histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0C); - } else if (isp == kKaPlusIdx) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_GapSum2D_KaPlus"), cent, gap, sum, c2Sub); - } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, cov); - if (std::isfinite(covFT0A)) - histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0A); - if (std::isfinite(covFT0C)) - histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0C); - } else if (isp == kKaAllIdx) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_GapSum2D_KaAll"), cent, gap, sum, c2Sub); - } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, cov); - if (std::isfinite(covFT0A)) - histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0A); - if (std::isfinite(covFT0C)) - histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0C); - } else if (isp == kPrIdx) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_GapSum2D_Pr"), cent, gap, sum, c2Sub); - } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, cov); - if (std::isfinite(covFT0A)) - histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0A); - if (std::isfinite(covFT0C)) - histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0C); - } else if (isp == kAntiPrIdx) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_GapSum2D_AntiPr"), cent, gap, sum, c2Sub); - } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, cov); - if (std::isfinite(covFT0A)) - histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0A); - if (std::isfinite(covFT0C)) - histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0C); - } else if (isp == kAllPrIdx) { - if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_GapSum2D_AllPr"), cent, gap, sum, c2Sub); - } - if (std::isfinite(cov)) - histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, cov); - if (std::isfinite(covFT0A)) - histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0A); - if (std::isfinite(covFT0C)) - histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0C); - } - } + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0CRecoEffCor); + + } else if (isp == kAllPrIdx) { + if (std::isfinite(c2SubTru)) { + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_AllPr"), cent, gap, sum, c2SubTru); } + if (std::isfinite(c2SubReco)) { + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_AllPr"), cent, gap, sum, c2SubReco); + } + if (std::isfinite(c2SubRecoEffCor)) { + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_AllPr"), cent, gap, sum, c2SubRecoEffCor); + } + + if (std::isfinite(covTru)) + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covTru); + if (std::isfinite(covReco)) + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covReco); + if (std::isfinite(covRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covRecoEffCor); + + if (std::isfinite(covFT0ATru)) + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0ATru); + if (std::isfinite(covFT0AReco)) + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0AReco); + if (std::isfinite(covFT0ARecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0ARecoEffCor); + + if (std::isfinite(covFT0CTru)) + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0CTru); + if (std::isfinite(covFT0CReco)) + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0CReco); + if (std::isfinite(covFT0CRecoEffCor)) + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0CRecoEffCor); } } - PROCESS_SWITCH(RadialFlowDecorr, processDataFluc, "process data to calculate fluc pT", cfgRunDataFluc); - }; - - WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) - { - WorkflowSpec workflow{adaptAnalysisTask(cfgc)}; - return workflow; } + } + } // colSlice + } // mcColl + LOGF(info, "FINISHED RUNNING processMCFluc"); + } + PROCESS_SWITCH(RadialFlowDecorr, processMCFluc, "process MC to calculate pt fluc", cfgRunMCFluc); + + void processGetDataFlat(AodCollisionsSel::iterator const& coll, BCsRun3 const& /*bcs*/, aod::Zdcs const& /*zdcsData*/, AodTracksSel const& tracks) + { + histos.fill(HIST("hVtxZ"), coll.posZ()); + if (!isEventSelected(coll)) + return; + float cent = getCentrality(coll); + if (cent > KCentMax) + return; + + histos.fill(HIST("hZvtx_after_sel"), coll.posZ()); + histos.fill(HIST("hCentrality"), cent); + + histos.fill(HIST("Hist2D_globalTracks_PVTracks"), coll.multNTracksPV(), tracks.size()); + histos.fill(HIST("Hist2D_cent_nch"), tracks.size(), cent); + + int ntrk = 0; + float vz = coll.posZ(); + + for (const auto& track : tracks) { + if (!isTrackSelected(track)) + continue; + float pt = track.pt(); + if (pt <= cfgPtMin || pt > cfgPtMax) + continue; + float eta = track.eta(); + float phi = track.phi(); + auto sign = track.sign(); + + if (eta > etaLw[0] && eta < etaUp[0]) + ntrk++; + + if (sign > 0) { + // PiPlus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiPlus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiPlus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + // KaPlus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaPlus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaPlus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + // Pr + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_Pr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_Pr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + } else if (sign < 0) { + // PiMinus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiMinus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiMinus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + // KaMinus + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaMinus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaMinus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + // AntiPr + histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_AntiPr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_AntiPr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + } + + bool isPi = selectionPion(track); + bool isKa = selectionKaon(track); + bool isPr = selectionProton(track); + + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + isPi && sign < 0, // kPiMinusIdx + isPi && sign > 0, // kPiPlusIdx + isPi, // kPiAllIdx + isKa && sign < 0, // kKaMinusIdx + isKa && sign > 0, // kKaPlusIdx + isKa, // kKaAllIdx + isPr && sign < 0, // kAntiPrIdx (Negative) + isPr && sign > 0, // kPrIdx (Positive) + isPr // kAllPrIdx + }; + + if (isSpecies[kPiPlusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiPlus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiPlus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + } else if (isSpecies[kPiMinusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiMinus"), pt, track.tpcNSigmaPi()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiMinus"), pt, track.tofNSigmaPi()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); + } + + if (isSpecies[kKaPlusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaPlus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaPlus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + } else if (isSpecies[kKaMinusIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaMinus"), pt, track.tpcNSigmaKa()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaMinus"), pt, track.tofNSigmaKa()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); + } + + if (isSpecies[kPrIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_Pr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_Pr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + } else if (isSpecies[kAntiPrIdx]) { + histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_AntiPr"), pt, track.tpcNSigmaPr()); + histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_AntiPr"), pt, track.tofNSigmaPr()); + histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); + } + + for (int isp = 0; isp < KNsp; ++isp) { + if (!isSpecies[isp]) + continue; + float eff = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); + if (eff <= KFloatEpsilon) + continue; + + float fake = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); + float w = (1.0f - fake) / eff; + + if (!std::isfinite(w) || w <= 0.f) + continue; + + if (isp == kInclusiveIdx) { + histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiMinusIdx) { + histos.fill(HIST("hEtaPhiReco_PiMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiMinus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_PiMinus"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiPlusIdx) { + histos.fill(HIST("hEtaPhiReco_PiPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiPlus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_PiPlus"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiAllIdx) { + histos.fill(HIST("hEtaPhiReco_PiAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiAll"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_PiAll"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaMinusIdx) { + histos.fill(HIST("hEtaPhiReco_KaMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaMinus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_KaMinus"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaPlusIdx) { + histos.fill(HIST("hEtaPhiReco_KaPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaPlus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_KaPlus"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaAllIdx) { + histos.fill(HIST("hEtaPhiReco_KaAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaAll"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_KaAll"), vz, sign, pt, eta, phi, w); + } else if (isp == kPrIdx) { + histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); + } else if (isp == kAntiPrIdx) { + histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); + } else if (isp == kAllPrIdx) { + histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); + } + } + } + + histos.fill(HIST("hCentnTrk"), cent, ntrk); + histos.fill(HIST("hCentnTrkPV"), cent, coll.multNTracksPV()); + + if (cfgZDC) { + const auto& foundBC = coll.foundBC_as(); + if (!foundBC.has_zdc()) { + return; + } + auto zdc = foundBC.zdc(); + auto zdcAmp = zdc.energyCommonZNA() + zdc.energyCommonZNC(); + histos.fill(HIST("hnTrkPVZDC"), coll.multNTracksPV(), zdcAmp); + histos.fill(HIST("hNchZDC"), ntrk, zdcAmp); + } + } + PROCESS_SWITCH(RadialFlowDecorr, processGetDataFlat, "process data to calculate Flattening maps", cfgRunGetDataFlat); + + void processDataMean(AodCollisionsSel::iterator const& coll, BCsRun3 const& /*bcs*/, aod::Zdcs const& /*zdcsData*/, aod::FT0s const&, AodTracksSel const& tracks) + { + double sumWi[KNsp][KNEta]{}, sumWipti[KNsp][KNEta]{}; + + if (!isEventSelected(coll)) + return; + + float cent = getCentrality(coll); + if (cent > KCentMax) + return; + + histos.fill(HIST("hZvtx_after_sel"), coll.posZ()); + histos.fill(HIST("hCentrality"), cent); + + histos.fill(HIST("Hist2D_globalTracks_PVTracks"), coll.multNTracksPV(), tracks.size()); + histos.fill(HIST("Hist2D_cent_nch"), tracks.size(), cent); + + float vz = coll.posZ(); + + for (const auto& track : tracks) { + if (!isTrackSelected(track)) + continue; + + float p = track.p(); + float pt = track.pt(); + float eta = track.eta(); + float phi = track.phi(); + auto sign = track.sign(); + + if (p < KFloatEpsilon) + continue; + + if (pt <= cfgPtMin || pt > cfgPtMax) + continue; + + histos.fill(HIST("hP"), p); + histos.fill(HIST("hPt"), pt); + histos.fill(HIST("hEta"), eta); + histos.fill(HIST("hPhi"), phi); + + bool isPi = selectionPion(track); + bool isKa = selectionKaon(track); + bool isPr = selectionProton(track); + + // Updated to use the correct PIDIdx enum names + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + isPi && sign < 0, // kPiMinusIdx + isPi && sign > 0, // kPiPlusIdx + isPi, // kPiAllIdx + isKa && sign < 0, // kKaMinusIdx + isKa && sign > 0, // kKaPlusIdx + isKa, // kKaAllIdx + isPr && sign < 0, // kAntiPrIdx (Negative) + isPr && sign > 0, // kPrIdx (Positive) + isPr // kAllPrIdx + }; + + for (int isp = 0; isp < KNsp; ++isp) { + if (!isSpecies[isp]) + continue; + + float eff = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); + + // Safety check BEFORE dividing + if (eff <= KFloatEpsilon) + continue; + + float fake = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); + float flatWeight = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); + float w = flatWeight * (1.0f - fake) / eff; + + if (!std::isfinite(w) || w <= 0.f) + continue; + + if (isp == kInclusiveIdx) { + histos.fill(HIST("hEtaPhiReco"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiMinusIdx) { + histos.fill(HIST("hEtaPhiReco_PiMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiMinus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_PiMinus"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiPlusIdx) { + histos.fill(HIST("hEtaPhiReco_PiPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiPlus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_PiPlus"), vz, sign, pt, eta, phi, w); + } else if (isp == kPiAllIdx) { + histos.fill(HIST("hEtaPhiReco_PiAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_PiAll"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_PiAll"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaMinusIdx) { + histos.fill(HIST("hEtaPhiReco_KaMinus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaMinus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_KaMinus"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaPlusIdx) { + histos.fill(HIST("hEtaPhiReco_KaPlus"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaPlus"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_KaPlus"), vz, sign, pt, eta, phi, w); + } else if (isp == kKaAllIdx) { + histos.fill(HIST("hEtaPhiReco_KaAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_KaAll"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_KaAll"), vz, sign, pt, eta, phi, w); + } else if (isp == kPrIdx) { + histos.fill(HIST("hEtaPhiReco_Pr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); + } else if (isp == kAntiPrIdx) { + histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); + } else if (isp == kAllPrIdx) { + histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); + } + + for (int ieta = 0; ieta < KNEta; ++ieta) { + if (eta <= etaLw[ieta] || eta > etaUp[ieta]) + continue; + sumWi[isp][ieta] += w; + sumWipti[isp][ieta] += w * pt; + } + } + } + + for (int isp = 0; isp < KNsp; ++isp) { + histos.fill(HIST("Prof_Cent_Nsp_Nchrec"), cent, isp, sumWi[isp][0]); + histos.fill(HIST("Prof_Mult_Nsp_Nchrec"), coll.multNTracksPV(), isp, sumWi[isp][0]); + if (sumWi[isp][0] > 1.0f) + histos.fill(HIST("Prof_Cent_Nsp_MeanpT"), cent, isp, sumWipti[isp][0] / sumWi[isp][0]); + histos.fill(HIST("Prof_Mult_Nsp_MeanpT"), coll.multNTracksPV(), isp, sumWipti[isp][0] / sumWi[isp][0]); + } + + for (int ietaA = 0; ietaA < KNEta; ++ietaA) { + for (int ietaC = 0; ietaC < KNEta; ++ietaC) { + for (int isp = 0; isp < KNsp; ++isp) { + double wCorrAB = sumWi[isp][ietaA] + sumWi[isp][ietaC]; + if (wCorrAB > 0) { + float mptsub = (sumWipti[isp][ietaA] + sumWipti[isp][ietaC]) / wCorrAB; + if (isp == kInclusiveIdx) + histos.fill(HIST("Prof2D_MeanpTSub"), cent, ietaA, ietaC, mptsub); + else if (isp == kPiMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_PiMinus"), cent, ietaA, ietaC, mptsub); + else if (isp == kPiPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_PiPlus"), cent, ietaA, ietaC, mptsub); + else if (isp == kPiAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_PiAll"), cent, ietaA, ietaC, mptsub); + else if (isp == kKaMinusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_KaMinus"), cent, ietaA, ietaC, mptsub); + else if (isp == kKaPlusIdx) + histos.fill(HIST("Prof2D_MeanpTSub_KaPlus"), cent, ietaA, ietaC, mptsub); + else if (isp == kKaAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_KaAll"), cent, ietaA, ietaC, mptsub); + else if (isp == kPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Pr"), cent, ietaA, ietaC, mptsub); + else if (isp == kAntiPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_AntiPr"), cent, ietaA, ietaC, mptsub); + else if (isp == kAllPrIdx) + histos.fill(HIST("Prof2D_MeanpTSub_AllPr"), cent, ietaA, ietaC, mptsub); + } + if (ietaA == ietaC) { + double mpt = sumWipti[isp][ietaA] / sumWi[isp][ietaA]; + if (sumWi[isp][ietaA] >= 1.0f && std::isfinite(mpt)) { + histos.fill(HIST("pmean_nch_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, mpt); + histos.fill(HIST("pmeanMult_nch_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, sumWi[isp][ietaA]); + histos.fill(HIST("pmean_cent_etabin_spbin"), cent, ietaA, isp, mpt); + histos.fill(HIST("pmeanMult_cent_etabin_spbin"), cent, ietaA, isp, sumWi[isp][ietaA]); + } + } + } + } + } + + double amplFT0A = 0, amplFT0C = 0; + if (coll.has_foundFT0()) { + const auto& ft0 = coll.foundFT0(); + for (std::size_t iCh = 0; iCh < ft0.channelA().size(); iCh++) { + auto chanelid = ft0.channelA()[iCh]; + float ampl = ft0.amplitudeA()[iCh]; + amplFT0A += ampl; + auto eta = getEtaFT0(chanelid, 0); + histos.fill(HIST("pmean_cent_id_eta_FT0"), cent, chanelid, eta, ampl); + histos.fill(HIST("h3_cent_id_eta_FT0"), cent, chanelid, eta, ampl); + } + for (std::size_t iCh = 0; iCh < ft0.channelC().size(); iCh++) { + auto chanelid = ft0.channelC()[iCh]; + auto globalId = chanelid + KnFt0cCell; + float ampl = ft0.amplitudeC()[iCh]; + auto eta = getEtaFT0(globalId, 1); + amplFT0C += ampl; + histos.fill(HIST("pmean_cent_id_eta_FT0"), cent, globalId, eta, ampl); + histos.fill(HIST("h3_cent_id_eta_FT0"), cent, globalId, eta, ampl); + } + } + + histos.fill(HIST("pmeanFT0Amultpv"), coll.multNTracksPV(), amplFT0A); + histos.fill(HIST("pmeanFT0A_cent"), cent, amplFT0A); + histos.fill(HIST("pmeanFT0Cmultpv"), coll.multNTracksPV(), amplFT0C); + histos.fill(HIST("pmeanFT0C_cent"), cent, amplFT0C); + } + PROCESS_SWITCH(RadialFlowDecorr, processDataMean, "process data to calculate mean pT", cfgRunDataMean); + + void processDataFluc(AodCollisionsSel::iterator const& coll, BCsRun3 const& /*bcs*/, aod::Zdcs const& /*zdcsData*/, aod::FT0s const&, AodTracksSel const& tracks) + { + if (!isEventSelected(coll)) + return; + float cent = getCentrality(coll); + if (cent > KCentMax) + return; + + if (!state.pmeanNchEtabinSpbinStep2 || !state.pmeanMultNchEtabinSpbinStep2) { + LOGF(warning, "Data fluc: Mean pT or Mult map missing"); + return; + } + + for (int isp = 0; isp < KNsp; ++isp) { + auto pid = static_cast(isp); + if (!state.hEff[pid] || !state.hFake[pid] || !state.hFlatWeight[pid]) { + LOGF(warning, "Data fluc: Correction maps (Eff, Fake, or Flat) are null for species index %d", isp); + return; + } + } + + double sumpmwk[KNsp][KNEta][KIntM][KIntK]{}; + double sumwk[KNsp][KNEta][KIntK]{}; + + double mean[KNsp][KNEta]{}, c2[KNsp][KNEta]{}; + double p1kBar[KNsp][KNEta]{}; + double meanMult[KNsp][KNEta]{}, p1kBarMult[KNsp][KNEta]{}; + + float vz = coll.posZ(); + + for (const auto& track : tracks) { + if (!isTrackSelected(track)) + continue; + + float p = track.p(); + float pt = track.pt(); + float eta = track.eta(); + float phi = track.phi(); + auto sign = track.sign(); + + if (p < KFloatEpsilon) + continue; + + if (pt <= cfgPtMin || pt > cfgPtMax) + continue; + + bool isPi = selectionPion(track); + bool isKa = selectionKaon(track); + bool isPr = selectionProton(track); + + // Updated to use the correct PIDIdx enum names + bool isSpecies[KNsp] = { + true, // kInclusiveIdx + isPi && sign < 0, // kPiMinusIdx + isPi && sign > 0, // kPiPlusIdx + isPi, // kPiAllIdx + isKa && sign < 0, // kKaMinusIdx + isKa && sign > 0, // kKaPlusIdx + isKa, // kKaAllIdx + isPr && sign < 0, // kAntiPrIdx (Negative) + isPr && sign > 0, // kPrIdx (Positive) + isPr // kAllPrIdx + }; + + for (int isp = 0; isp < KNsp; ++isp) { + if (!isSpecies[isp]) + continue; + + float eff = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); + + // Safety check BEFORE dividing + if (eff <= KFloatEpsilon) + continue; + + float fake = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); + float flatWeight = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); + float w = flatWeight * (1.0f - fake) / eff; + + if (!std::isfinite(w) || w <= 0.f) + continue; + + for (int ieta = 0; ieta < KNEta; ++ieta) { + if (eta <= etaLw[ieta] || eta > etaUp[ieta]) + continue; + for (int k = 0; k < KIntK; ++k) { + for (int m = 0; m < KIntM; ++m) { + sumpmwk[isp][ieta][m][k] += std::pow(w, k) * std::pow(pt, m); + } + sumwk[isp][ieta][k] += std::pow(w, k); + } + } + } + } + + double amplFT0A = 0, amplFT0C = 0; + if (coll.has_foundFT0()) { + const auto& ft0 = coll.foundFT0(); + for (std::size_t iCh = 0; iCh < ft0.channelA().size(); iCh++) { + float ampl = ft0.amplitudeA()[iCh]; + amplFT0A += ampl; + } + for (std::size_t iCh = 0; iCh < ft0.channelC().size(); iCh++) { + float ampl = ft0.amplitudeC()[iCh]; + amplFT0C += ampl; + } + } + double p1kBarFt0A = amplFT0A - state.pmeanFT0AmultpvStep2->GetBinContent(state.pmeanFT0AmultpvStep2->GetXaxis()->FindBin(coll.multNTracksPV())); + double p1kBarFt0C = amplFT0C - state.pmeanFT0CmultpvStep2->GetBinContent(state.pmeanFT0CmultpvStep2->GetXaxis()->FindBin(coll.multNTracksPV())); + + for (int ieta = 0; ieta < KNEta; ++ieta) { + const int ibx = state.pmeanNchEtabinSpbinStep2->GetXaxis()->FindBin(coll.multNTracksPV()); + const int iby = ieta + 1; + + for (int isp = 0; isp < KNsp; ++isp) { + const int ibz = isp + 1; + + float mmpt = state.pmeanNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + float mmMult = state.pmeanMultNchEtabinSpbinStep2->GetBinContent(ibx, iby, ibz); + + mean[isp][ieta] = sumpmwk[isp][ieta][1][1] / sumwk[isp][ieta][1]; + meanMult[isp][ieta] = sumwk[isp][ieta][1]; + + if (std::isfinite(mmpt)) { + std::tie(mean[isp][ieta], c2[isp][ieta]) = calculateMeanAndC2FromSums(sumpmwk[isp][ieta], sumwk[isp][ieta], mmpt); + p1kBar[isp][ieta] = mean[isp][ieta] - mmpt; + } + p1kBarMult[isp][ieta] = meanMult[isp][ieta] - mmMult; + } + } + for (int ieta = 0; ieta < KNEta; ++ieta) { + for (int isp = 0; isp < KNsp; ++isp) { + if (std::isfinite(mean[isp][ieta])) { + histos.fill(HIST("Prof_MeanpT_Cent_etabin_spbin"), cent, ieta, isp, mean[isp][ieta]); + histos.fill(HIST("Prof_MeanpT_Mult_etabin_spbin"), coll.multNTracksPV(), ieta, isp, mean[isp][ieta]); + } + if (std::isfinite(c2[isp][ieta])) { + histos.fill(HIST("Prof_C2_Cent_etabin_spbin"), cent, ieta, isp, c2[isp][ieta]); + histos.fill(HIST("Prof_C2_Mult_etabin_spbin"), coll.multNTracksPV(), ieta, isp, c2[isp][ieta]); + } + } + } + + for (int ietaA = 1; ietaA <= (KNEta - 1) / 2; ++ietaA) { + int ietaC = KNEta - ietaA; + for (int isp = 0; isp < KNsp; ++isp) { + float c2Sub = p1kBar[isp][ietaA] * p1kBar[isp][ietaC]; + float covAC = p1kBarMult[isp][ietaA] * p1kBar[isp][ietaC]; + float covCA = p1kBar[isp][ietaA] * p1kBarMult[isp][ietaC]; + + float covFT0A = p1kBarFt0A * p1kBar[isp][ietaC]; + float covFT0C = p1kBarFt0C * p1kBar[isp][ietaA]; + + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub_Cent_etabin_spbin"), cent, ietaA, isp, c2Sub); + histos.fill(HIST("Prof_C2Sub_Mult_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, c2Sub); + } + if (std::isfinite(covAC)) { + histos.fill(HIST("Prof_Cov_Cent_etabin_spbin"), cent, ietaA, isp, covAC); + histos.fill(HIST("Prof_Cov_Mult_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, covAC); + } + if (std::isfinite(covCA)) { + histos.fill(HIST("Prof_Cov_Cent_etabin_spbin"), cent, ietaA, isp, covCA); + histos.fill(HIST("Prof_Cov_Mult_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, covCA); + } + if (std::isfinite(covFT0A)) { + histos.fill(HIST("Prof_CovFT0A_Cent_etabin_spbin"), cent, ietaA, isp, covFT0A); + histos.fill(HIST("Prof_CovFT0A_Mult_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, covFT0A); + } + if (std::isfinite(covFT0C)) { + histos.fill(HIST("Prof_CovFT0C_Cent_etabin_spbin"), cent, ietaA, isp, covFT0C); + histos.fill(HIST("Prof_CovFT0C_Mult_etabin_spbin"), coll.multNTracksPV(), ietaA, isp, covFT0C); + } + } + } + + for (int ietaA = 1; ietaA < KNEta; ++ietaA) { + for (int ietaC = 1; ietaC < KNEta; ++ietaC) { + + float etaValA = (etaLw[ietaA] + etaUp[ietaA]) / 2.0f; + float etaValB = (etaLw[ietaC] + etaUp[ietaC]) / 2.0f; + float gap = etaValA - etaValB; + float sum = (etaValA + etaValB) / 2.0f; + + for (int isp = 0; isp < KNsp; ++isp) { + + float c2Sub = p1kBar[isp][ietaA] * p1kBar[isp][ietaC]; + float cov = p1kBarMult[isp][ietaA] * p1kBar[isp][ietaC]; + float covFT0A = p1kBarFt0A * p1kBar[isp][ietaC]; + float covFT0C = p1kBarFt0C * p1kBar[isp][ietaA]; + + // Updated enum checks here + if (isp == kInclusiveIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kPiMinusIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_PiMinus"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_PiMinus"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kPiPlusIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_PiPlus"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_PiPlus"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kPiAllIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_PiAll"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_PiAll"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kKaMinusIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_KaMinus"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_KaMinus"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kKaPlusIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_KaPlus"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_KaPlus"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kKaAllIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_KaAll"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_KaAll"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kPrIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_Pr"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_Pr"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kAntiPrIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_AntiPr"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0C); + } else if (isp == kAllPrIdx) { + if (std::isfinite(c2Sub)) { + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_AllPr"), cent, gap, sum, c2Sub); + } + if (std::isfinite(cov)) + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, cov); + if (std::isfinite(covFT0A)) + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0A); + if (std::isfinite(covFT0C)) + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0C); + } + } + } + } + } + PROCESS_SWITCH(RadialFlowDecorr, processDataFluc, "process data to calculate fluc pT", cfgRunDataFluc); +}; + +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +{ + WorkflowSpec workflow{adaptAnalysisTask(cfgc)}; + return workflow; +} From d7c9b638dfd955fa54b9c2a87fecbe349b816c4c Mon Sep 17 00:00:00 2001 From: Somadutta Bhatta Date: Wed, 4 Mar 2026 08:21:27 +0100 Subject: [PATCH 3/6] Fix clang issues --- .../Tasks/radialFlowDecorr.cxx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx b/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx index bf6eb8cd8a7..84179f8872a 100644 --- a/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx +++ b/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx @@ -1329,7 +1329,7 @@ struct RadialFlowDecorr { } else { histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake"), multPV, pt, eta); } - }else if (isp == kPiMinusIdx) { + } else if (isp == kPiMinusIdx) { histos.fill(HIST("h3_AllReco_PiMinus"), multPV, pt, eta); if (track.has_mcParticle()) { auto mcP = track.mcParticle(); @@ -1345,7 +1345,7 @@ struct RadialFlowDecorr { } else { // No MC histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_PiMinus"), multPV, pt, eta); } - }else if (isp == kPiPlusIdx) { + } else if (isp == kPiPlusIdx) { histos.fill(HIST("h3_AllReco_PiPlus"), multPV, pt, eta); if (track.has_mcParticle()) { auto mcP = track.mcParticle(); @@ -1361,7 +1361,7 @@ struct RadialFlowDecorr { } else { histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_PiPlus"), multPV, pt, eta); } - }else if (isp == kPiAllIdx) { + } else if (isp == kPiAllIdx) { histos.fill(HIST("h3_AllReco_PiAll"), multPV, pt, eta); if (track.has_mcParticle()) { auto mcP = track.mcParticle(); @@ -1377,7 +1377,7 @@ struct RadialFlowDecorr { } else { histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_PiAll"), multPV, pt, eta); } - }else if (isp == kKaMinusIdx) { + } else if (isp == kKaMinusIdx) { histos.fill(HIST("h3_AllReco_KaMinus"), multPV, pt, eta); if (track.has_mcParticle()) { auto mcP = track.mcParticle(); @@ -1393,7 +1393,7 @@ struct RadialFlowDecorr { } else { histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_KaMinus"), multPV, pt, eta); } - }else if (isp == kKaPlusIdx) { + } else if (isp == kKaPlusIdx) { histos.fill(HIST("h3_AllReco_KaPlus"), multPV, pt, eta); if (track.has_mcParticle()) { auto mcP = track.mcParticle(); @@ -1409,7 +1409,7 @@ struct RadialFlowDecorr { } else { histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_KaPlus"), multPV, pt, eta); } - }else if (isp == kKaAllIdx) { + } else if (isp == kKaAllIdx) { histos.fill(HIST("h3_AllReco_KaAll"), multPV, pt, eta); if (track.has_mcParticle()) { auto mcP = track.mcParticle(); @@ -1425,7 +1425,7 @@ struct RadialFlowDecorr { } else { histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_KaAll"), multPV, pt, eta); } - }else if (isp == kAntiPrIdx) { + } else if (isp == kAntiPrIdx) { histos.fill(HIST("h3_AllReco_AntiPr"), multPV, pt, eta); if (track.has_mcParticle()) { auto mcP = track.mcParticle(); @@ -1441,7 +1441,7 @@ struct RadialFlowDecorr { } else { histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_AntiPr"), multPV, pt, eta); } - }else if (isp == kPrIdx) { + } else if (isp == kPrIdx) { histos.fill(HIST("h3_AllReco_Pr"), multPV, pt, eta); if (track.has_mcParticle()) { auto mcP = track.mcParticle(); @@ -1457,7 +1457,7 @@ struct RadialFlowDecorr { } else { histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_Pr"), multPV, pt, eta); } - }else if (isp == kAllPrIdx) { + } else if (isp == kAllPrIdx) { histos.fill(HIST("h3_AllReco_AllPr"), multPV, pt, eta); if (track.has_mcParticle()) { auto mcP = track.mcParticle(); From f63cca22159fda56cebfbccddc50e2cc79379179 Mon Sep 17 00:00:00 2001 From: Somadutta Bhatta Date: Thu, 5 Mar 2026 01:05:16 +0100 Subject: [PATCH 4/6] Added histograms and updated PID selection criteria --- .../Tasks/radialFlowDecorr.cxx | 1076 ++++++++++------- 1 file changed, 646 insertions(+), 430 deletions(-) diff --git a/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx b/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx index 84179f8872a..b9671ee46db 100644 --- a/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx +++ b/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx @@ -60,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -73,6 +74,11 @@ using namespace constants::math; struct RadialFlowDecorr { + static constexpr int KPidPionOne = 1; + static constexpr int KPidKaonTwo = 2; + static constexpr int KPidProtonThree = 3; + static constexpr int KConstTen = 10; + static constexpr int KnFt0cCell = 96; static constexpr int KIntM = 3; static constexpr int KIntK = 3; @@ -120,16 +126,27 @@ struct RadialFlowDecorr { kKaAllIdx, kAntiPrIdx, kPrIdx, - kAllPrIdx, + kPrAllIdx, KNsp }; - const std::vector pidSuffix = {"", "_PiMinus", "_PiPlus", "_PiAll", "_KaMinus", "_KaPlus", "_KaAll", "_AntiPr", "_Pr", "_AllPr"}; + const std::vector pidSuffix = {"", "_PiMinus", "_PiPlus", "_PiAll", "_KaMinus", "_KaPlus", "_KaAll", "_AntiPr", "_Pr", "_PrAll"}; + + struct PIDMeanSigmaMap { + static constexpr int MaxCentBins = 100; + double meanTOF[KNsp][MaxCentBins] = {{0.0}}; + double sigmaTOF[KNsp][MaxCentBins] = {{1.0}}; // Default sigma = 1 + double meanTPC[KNsp][MaxCentBins] = {{0.0}}; + double sigmaTPC[KNsp][MaxCentBins] = {{1.0}}; // Default sigma = 1 + }; + + PIDMeanSigmaMap* pidMeanSigmaMap = nullptr; enum ECentralityEstimator { - kCentFT0M = 1, - kCentFDDM = 2, - kCentFV0A = 3 + kCentFT0C = 1, + kCentFT0M = 2, + kCentFDDM = 3, + kCentFV0A = 4 }; enum SystemType { kPbPb = 1, @@ -153,28 +170,20 @@ struct RadialFlowDecorr { Configurable cfgChi2TPCMax{"cfgChi2TPCMax", 4.0f, "max TPC χ²"}; Configurable cfgCutTpcChi2NCl{"cfgCutTpcChi2NCl", 2.5f, "Maximum TPCchi2NCl"}; Configurable cfgCutItsChi2NCl{"cfgCutItsChi2NCl", 36.0f, "Maximum ITSchi2NCl"}; - Configurable cfgCutVertex{"cfgCutVertex", 7.0f, "Accepted z-vertex range"}; + Configurable cfgCutVertex{"cfgCutVertex", 10.0f, "Accepted z-vertex range"}; Configurable cfgCutTracKDcaMaxZ{"cfgCutTracKDcaMaxZ", 2.0f, "Maximum DcaZ"}; Configurable cfgCutTracKDcaMaxXY{"cfgCutTracKDcaMaxXY", 0.2f, "Maximum DcaZ"}; - Configurable cfgPtDepDCAxy{"cfgPtDepDCAxy", true, "Use pt-dependent DCAxy cut"}; + Configurable cfgPtDepDCAxy{"cfgPtDepDCAxy", false, "Use pt-dependent DCAxy cut"}; Configurable cfgDcaXyP0{"cfgDcaXyP0", 0.0026f, "p0 for DCAxy"}; Configurable cfgDcaXyP1{"cfgDcaXyP1", 0.005f, "p1 for DCAxy"}; Configurable cfgDcaXyP2{"cfgDcaXyP2", 1.01f, "p2 for DCAxy"}; - Configurable cfgPtDepDCAz{"cfgPtDepDCAz", true, "Use pt-dependent DCAz cut"}; + Configurable cfgPtDepDCAz{"cfgPtDepDCAz", false, "Use pt-dependent DCAz cut"}; Configurable cfgDcaZP0{"cfgDcaZP0", 0.0026f, "p0 for DCAz"}; Configurable cfgDcaZP1{"cfgDcaZP1", 0.005f, "p1 for DCAz"}; Configurable cfgDcaZP2{"cfgDcaZP2", 1.01f, "p2 for DCAz"}; - // Configurable cfgPtDepDCAxy{"cfgPtDepDCAxy", true, "Use pt-dependent DCAxy cut"}; - // Configurable cfgPtDepDCAz{"cfgPtDepDCAz", true, "Use pt-dependent DCAz cut"}; - // Configurable cfgPtDepDCAxyFunc{"cfgPtDepDCAxyFunc", "(0.0026+0.005/(x^1.01))", "Functional form of pt-dependent DCAxy cut"}; - // Configurable cfgPtDepDCAzFunc{"cfgDPtDepCAzFunc", "(0.0026+0.005/(x^1.01))", "Functional form of pt-dependent DCAz cut"}; - - // TF1* fPtDepDCAxy = nullptr; - // TF1* fPtDepDCAz = nullptr; - Configurable cfgITScluster{"cfgITScluster", 1, "Minimum Number of ITS cluster"}; Configurable cfgTPCcluster{"cfgTPCcluster", 80, "Minimum Number of TPC cluster"}; Configurable cfgTPCnCrossedRows{"cfgTPCnCrossedRows", 70, "Minimum Number of TPC crossed-rows"}; @@ -183,16 +192,19 @@ struct RadialFlowDecorr { Configurable cfgnSigmaCutTPC{"cfgnSigmaCutTPC", 2.0f, "PID nSigma cut for TPC"}; Configurable cfgnSigmaCutTOF{"cfgnSigmaCutTOF", 2.0f, "PID nSigma cut for TOF"}; Configurable cfgnSigmaCutCombTPCTOF{"cfgnSigmaCutCombTPCTOF", 2.0f, "PID nSigma combined cut for TPC and TOF"}; + + Configurable cfgTpcElRejCutMin{"cfgTpcElRejCutMin", -3.0f, "Electron Rejection Cut Minimum"}; + Configurable cfgTpcElRejCutMax{"cfgTpcElRejCutMax", 5.0f, "Electron Rejection Cut Maximum"}; + Configurable cfgTpcElRejCut{"cfgTpcElRejCut", 3.0f, "TPC Hadron Rejection Cut"}; + Configurable cfgCutPtLower{"cfgCutPtLower", 0.2f, "Lower pT cut"}; Configurable cfgCutPtUpper{"cfgCutPtUpper", 10.0f, "Higher pT cut for inclusive hadron analysis"}; Configurable cfgCutPtUpperPID{"cfgCutPtUpperPID", 6.0f, "Higher pT cut for identified particle analysis"}; Configurable cfgCutEta{"cfgCutEta", 0.8f, "absolute Eta cut"}; Configurable cfgNsubsample{"cfgNsubsample", 10, "Number of subsamples"}; - Configurable cfgCentralityChoice{"cfgCentralityChoice", 1, "Which centrality estimator? 1-->FT0C, 2-->FV0A"}; + Configurable cfgCentralityChoice{"cfgCentralityChoice", 2, "Which centrality estimator? 1-->FT0C, 2-->FT0M, 3-->FDDM, 4-->FV0A"}; Configurable cfgEvSelNoSameBunchPileup{"cfgEvSelNoSameBunchPileup", true, "Pileup removal"}; Configurable cfgUseGoodITSLayerAllCut{"cfgUseGoodITSLayerAllCut", true, "Remove time interval with dead ITS zone"}; - Configurable cfgEvSelkNoITSROFrameBorder{"cfgEvSelkNoITSROFrameBorder", true, "ITSROFrame border event selection cut"}; - Configurable cfgEvSelkNoTimeFrameBorder{"cfgEvSelkNoTimeFrameBorder", true, "TimeFrame border event selection cut"}; Configurable cfgIsGoodZvtxFT0VsPV{"cfgIsGoodZvtxFT0VsPV", true, "Good Vertexing cut"}; Configurable cfgNchPbMax{"cfgNchPbMax", 6000, "Max Nch range for PbPb collisions"}; @@ -206,10 +218,10 @@ struct RadialFlowDecorr { Configurable cfgCCDBurl{"cfgCCDBurl", "https://alice-ccdb.cern.ch", "ccdb url"}; Configurable cfgCCDBUserPath{"cfgCCDBUserPath", "/Users/s/somadutt", "Base CCDB path"}; - ConfigurableAxis cfgAxisCent{"cfgAxisCent", {0.0, 1.0, 3.0, 5.0, 10, 20, 30, 40, 50, 60, 70, 80, 100}, "centrality axis (percentile)"}; + ConfigurableAxis cfgAxisCent{"cfgAxisCent", {0.0, 1.0, 5.0, 10, 20, 40, 60, 80, 100}, "centrality axis (percentile)"}; const AxisSpec centAxis{cfgAxisCent, "Centrality (%)"}; - const AxisSpec centAxis1Per{101, -0.5, 100.5, "Centrality (%)"}; + const AxisSpec centAxis1Per{100, 0.0, 100.0, "Centrality (%)"}; AxisSpec nChAxis{1, 0., 1., "Nch", "Nch"}; AxisSpec nChAxis2{1, 0., 1., "Nch", "Nch"}; @@ -234,10 +246,13 @@ struct RadialFlowDecorr { 0.325, 0.375, 0.425, 0.475, 0.525, 0.575, 0.625, 0.675, 0.725, 0.775}, "Sums"}; + Configurable cfgRunMCGetNSig{"cfgRunMCGetNSig", false, "Run MC pass to get mean of Nsig Plots"}; Configurable cfgRunGetEff{"cfgRunGetEff", false, "Run MC pass to build efficiency/fake maps"}; Configurable cfgRunGetMCFlat{"cfgRunGetMCFlat", false, "Run MC to Get Flattening Weights"}; Configurable cfgRunMCMean{"cfgRunMCMean", false, "Run MC mean(pT) & mean(Et)"}; Configurable cfgRunMCFluc{"cfgRunMCFluc", false, "Run MC fluctuations (C2, subevent)"}; + + Configurable cfgRunDataGetNSig{"cfgRunDataGetNSig", false, "Run MC pass to get mean of Nsig Plots"}; Configurable cfgRunGetDataFlat{"cfgRunGetDataFlat", false, "Run Data Get Flattening Weights"}; Configurable cfgRunDataMean{"cfgRunDataMean", false, "Run DATA mean(pT) & mean(Et)"}; Configurable cfgRunDataFluc{"cfgRunDataFluc", false, "Run DATA fluctuations (C2, subevent)"}; @@ -268,71 +283,301 @@ struct RadialFlowDecorr { o2::ft0::Geometry ft0Det; template - static std::tuple getAllCombinedNSigmas(const T& candidate) + void fillNSigmaBefCut(const T& track, float cent) { - return { - std::hypot(candidate.tpcNSigmaPr(), candidate.tofNSigmaPr()), // Proton - std::hypot(candidate.tpcNSigmaPi(), candidate.tofNSigmaPi()), // Pion - std::hypot(candidate.tpcNSigmaKa(), candidate.tofNSigmaKa()) // Kaon - }; + float pt = track.pt(); + auto sign = track.sign(); + // --- Generic Inclusive --- + histos.fill(HIST("h3DnsigmaTpcVsPtBefCut_Cent"), cent, pt, track.tpcNSigmaPi()); + histos.fill(HIST("h3DnsigmaTofVsPtBefCut_Cent"), cent, pt, track.tofNSigmaPi()); + histos.fill(HIST("h3DnsigmaTpcVsTofBefCut_Cent"), cent, track.tofNSigmaPi(), track.tpcNSigmaPi()); + + histos.fill(HIST("h3DnsigmaTpcVsPtBefCut_Cent"), cent, pt, track.tpcNSigmaKa()); + histos.fill(HIST("h3DnsigmaTofVsPtBefCut_Cent"), cent, pt, track.tofNSigmaKa()); + histos.fill(HIST("h3DnsigmaTpcVsTofBefCut_Cent"), cent, track.tofNSigmaKa(), track.tpcNSigmaKa()); + + histos.fill(HIST("h3DnsigmaTpcVsPtBefCut_Cent"), cent, pt, track.tpcNSigmaPr()); + histos.fill(HIST("h3DnsigmaTofVsPtBefCut_Cent"), cent, pt, track.tofNSigmaPr()); + histos.fill(HIST("h3DnsigmaTpcVsTofBefCut_Cent"), cent, track.tofNSigmaPr(), track.tpcNSigmaPr()); + if (sign > 0) { + histos.fill(HIST("h3DnsigmaTpcVsPtBefCut_Cent_PiPlus"), cent, pt, track.tpcNSigmaPi()); + histos.fill(HIST("h3DnsigmaTofVsPtBefCut_Cent_PiPlus"), cent, pt, track.tofNSigmaPi()); + histos.fill(HIST("h3DnsigmaTpcVsTofBefCut_Cent_PiPlus"), cent, track.tofNSigmaPi(), track.tpcNSigmaPi()); + histos.fill(HIST("h3DnsigmaTpcVsPtBefCut_Cent_KaPlus"), cent, pt, track.tpcNSigmaKa()); + histos.fill(HIST("h3DnsigmaTofVsPtBefCut_Cent_KaPlus"), cent, pt, track.tofNSigmaKa()); + histos.fill(HIST("h3DnsigmaTpcVsTofBefCut_Cent_KaPlus"), cent, track.tofNSigmaKa(), track.tpcNSigmaKa()); + histos.fill(HIST("h3DnsigmaTpcVsPtBefCut_Cent_Pr"), cent, pt, track.tpcNSigmaPr()); + histos.fill(HIST("h3DnsigmaTofVsPtBefCut_Cent_Pr"), cent, pt, track.tofNSigmaPr()); + histos.fill(HIST("h3DnsigmaTpcVsTofBefCut_Cent_Pr"), cent, track.tofNSigmaPr(), track.tpcNSigmaPr()); + } else if (sign < 0) { + histos.fill(HIST("h3DnsigmaTpcVsPtBefCut_Cent_PiMinus"), cent, pt, track.tpcNSigmaPi()); + histos.fill(HIST("h3DnsigmaTofVsPtBefCut_Cent_PiMinus"), cent, pt, track.tofNSigmaPi()); + histos.fill(HIST("h3DnsigmaTpcVsTofBefCut_Cent_PiMinus"), cent, track.tofNSigmaPi(), track.tpcNSigmaPi()); + histos.fill(HIST("h3DnsigmaTpcVsPtBefCut_Cent_KaMinus"), cent, pt, track.tpcNSigmaKa()); + histos.fill(HIST("h3DnsigmaTofVsPtBefCut_Cent_KaMinus"), cent, pt, track.tofNSigmaKa()); + histos.fill(HIST("h3DnsigmaTpcVsTofBefCut_Cent_KaMinus"), cent, track.tofNSigmaKa(), track.tpcNSigmaKa()); + histos.fill(HIST("h3DnsigmaTpcVsPtBefCut_Cent_AntiPr"), cent, pt, track.tpcNSigmaPr()); + histos.fill(HIST("h3DnsigmaTofVsPtBefCut_Cent_AntiPr"), cent, pt, track.tofNSigmaPr()); + histos.fill(HIST("h3DnsigmaTpcVsTofBefCut_Cent_AntiPr"), cent, track.tofNSigmaPr(), track.tpcNSigmaPr()); + } + histos.fill(HIST("h3DnsigmaTpcVsPtBefCut_Cent_PiAll"), cent, pt, track.tpcNSigmaPi()); + histos.fill(HIST("h3DnsigmaTofVsPtBefCut_Cent_PiAll"), cent, pt, track.tofNSigmaPi()); + histos.fill(HIST("h3DnsigmaTpcVsTofBefCut_Cent_PiAll"), cent, track.tofNSigmaPi(), track.tpcNSigmaPi()); + + histos.fill(HIST("h3DnsigmaTpcVsPtBefCut_Cent_KaAll"), cent, pt, track.tpcNSigmaKa()); + histos.fill(HIST("h3DnsigmaTofVsPtBefCut_Cent_KaAll"), cent, pt, track.tofNSigmaKa()); + histos.fill(HIST("h3DnsigmaTpcVsTofBefCut_Cent_KaAll"), cent, track.tofNSigmaKa(), track.tpcNSigmaKa()); + + histos.fill(HIST("h3DnsigmaTpcVsPtBefCut_Cent_PrAll"), cent, pt, track.tpcNSigmaPr()); + histos.fill(HIST("h3DnsigmaTofVsPtBefCut_Cent_PrAll"), cent, pt, track.tofNSigmaPr()); + histos.fill(HIST("h3DnsigmaTpcVsTofBefCut_Cent_PrAll"), cent, track.tofNSigmaPr(), track.tpcNSigmaPr()); + } + + template + void fillNSigmaAftCut(const T& track, float cent, bool isSpecies[]) + { + float pt = track.pt(); + + if (isSpecies[kInclusiveIdx]) { + histos.fill(HIST("h3DnsigmaTpcVsPtAftCut_Cent"), cent, pt, track.tpcNSigmaPi()); + histos.fill(HIST("h3DnsigmaTofVsPtAftCut_Cent"), cent, pt, track.tofNSigmaPi()); + histos.fill(HIST("h3DnsigmaTpcVsTofAftCut_Cent"), cent, track.tofNSigmaPi(), track.tpcNSigmaPi()); + + histos.fill(HIST("h3DnsigmaTpcVsPtAftCut_Cent"), cent, pt, track.tpcNSigmaKa()); + histos.fill(HIST("h3DnsigmaTofVsPtAftCut_Cent"), cent, pt, track.tofNSigmaKa()); + histos.fill(HIST("h3DnsigmaTpcVsTofAftCut_Cent"), cent, track.tofNSigmaKa(), track.tpcNSigmaKa()); + + histos.fill(HIST("h3DnsigmaTpcVsPtAftCut_Cent"), cent, pt, track.tpcNSigmaPr()); + histos.fill(HIST("h3DnsigmaTofVsPtAftCut_Cent"), cent, pt, track.tofNSigmaPr()); + histos.fill(HIST("h3DnsigmaTpcVsTofAftCut_Cent"), cent, track.tofNSigmaPr(), track.tpcNSigmaPr()); + } + if (isSpecies[kPiPlusIdx]) { + histos.fill(HIST("h3DnsigmaTpcVsPtAftCut_Cent_PiPlus"), cent, pt, track.tpcNSigmaPi()); + histos.fill(HIST("h3DnsigmaTofVsPtAftCut_Cent_PiPlus"), cent, pt, track.tofNSigmaPi()); + histos.fill(HIST("h3DnsigmaTpcVsTofAftCut_Cent_PiPlus"), cent, track.tofNSigmaPi(), track.tpcNSigmaPi()); + } else if (isSpecies[kPiMinusIdx]) { + histos.fill(HIST("h3DnsigmaTpcVsPtAftCut_Cent_PiMinus"), cent, pt, track.tpcNSigmaPi()); + histos.fill(HIST("h3DnsigmaTofVsPtAftCut_Cent_PiMinus"), cent, pt, track.tofNSigmaPi()); + histos.fill(HIST("h3DnsigmaTpcVsTofAftCut_Cent_PiMinus"), cent, track.tofNSigmaPi(), track.tpcNSigmaPi()); + } + if (isSpecies[kPiAllIdx]) { + histos.fill(HIST("h3DnsigmaTpcVsPtAftCut_Cent_PiAll"), cent, pt, track.tpcNSigmaPi()); + histos.fill(HIST("h3DnsigmaTofVsPtAftCut_Cent_PiAll"), cent, pt, track.tofNSigmaPi()); + histos.fill(HIST("h3DnsigmaTpcVsTofAftCut_Cent_PiAll"), cent, track.tofNSigmaPi(), track.tpcNSigmaPi()); + } + if (isSpecies[kKaPlusIdx]) { + histos.fill(HIST("h3DnsigmaTpcVsPtAftCut_Cent_KaPlus"), cent, pt, track.tpcNSigmaKa()); + histos.fill(HIST("h3DnsigmaTofVsPtAftCut_Cent_KaPlus"), cent, pt, track.tofNSigmaKa()); + histos.fill(HIST("h3DnsigmaTpcVsTofAftCut_Cent_KaPlus"), cent, track.tofNSigmaKa(), track.tpcNSigmaKa()); + } else if (isSpecies[kKaMinusIdx]) { + histos.fill(HIST("h3DnsigmaTpcVsPtAftCut_Cent_KaMinus"), cent, pt, track.tpcNSigmaKa()); + histos.fill(HIST("h3DnsigmaTofVsPtAftCut_Cent_KaMinus"), cent, pt, track.tofNSigmaKa()); + histos.fill(HIST("h3DnsigmaTpcVsTofAftCut_Cent_KaMinus"), cent, track.tofNSigmaKa(), track.tpcNSigmaKa()); + } + if (isSpecies[kKaAllIdx]) { + histos.fill(HIST("h3DnsigmaTpcVsPtAftCut_Cent_KaAll"), cent, pt, track.tpcNSigmaKa()); + histos.fill(HIST("h3DnsigmaTofVsPtAftCut_Cent_KaAll"), cent, pt, track.tofNSigmaKa()); + histos.fill(HIST("h3DnsigmaTpcVsTofAftCut_Cent_KaAll"), cent, track.tofNSigmaKa(), track.tpcNSigmaKa()); + } + if (isSpecies[kPrIdx]) { + histos.fill(HIST("h3DnsigmaTpcVsPtAftCut_Cent_Pr"), cent, pt, track.tpcNSigmaPr()); + histos.fill(HIST("h3DnsigmaTofVsPtAftCut_Cent_Pr"), cent, pt, track.tofNSigmaPr()); + histos.fill(HIST("h3DnsigmaTpcVsTofAftCut_Cent_Pr"), cent, track.tofNSigmaPr(), track.tpcNSigmaPr()); + } else if (isSpecies[kAntiPrIdx]) { + histos.fill(HIST("h3DnsigmaTpcVsPtAftCut_Cent_AntiPr"), cent, pt, track.tpcNSigmaPr()); + histos.fill(HIST("h3DnsigmaTofVsPtAftCut_Cent_AntiPr"), cent, pt, track.tofNSigmaPr()); + histos.fill(HIST("h3DnsigmaTpcVsTofAftCut_Cent_AntiPr"), cent, track.tofNSigmaPr(), track.tpcNSigmaPr()); + } + if (isSpecies[kPrAllIdx]) { + histos.fill(HIST("h3DnsigmaTpcVsPtAftCut_Cent_PrAll"), cent, pt, track.tpcNSigmaPr()); + histos.fill(HIST("h3DnsigmaTofVsPtAftCut_Cent_PrAll"), cent, pt, track.tofNSigmaPr()); + histos.fill(HIST("h3DnsigmaTpcVsTofAftCut_Cent_PrAll"), cent, track.tofNSigmaPr(), track.tpcNSigmaPr()); + } + } + + // Returns: 0 = Unknown/Reject, 1 = Pion, 2 = Kaon, 3 = Proton + template + int identifyTrack(const T& candidate, int centBin) + { + // Initial sanity checks + if (!candidate.hasTPC()) + return 0; + float pt = candidate.pt(); + if (pt <= cfgCutPtLower || pt >= cfgCutPtUpperPID) + return 0; // Out of bounds + // Determine species indices based on charge + auto charge = candidate.sign(); + int piIdx = (charge > 0) ? kPiPlusIdx : kPiMinusIdx; + int kaIdx = (charge > 0) ? kKaPlusIdx : kKaMinusIdx; + int prIdx = (charge > 0) ? kPrIdx : kAntiPrIdx; + // Fetch Calibration Data (Means and Sigmas) + // TPC + float mPiTpc = pidMeanSigmaMap ? pidMeanSigmaMap->meanTPC[piIdx][centBin] : 0.f; + float sPiTpc = pidMeanSigmaMap ? pidMeanSigmaMap->sigmaTPC[piIdx][centBin] : 1.f; + float mKaTpc = pidMeanSigmaMap ? pidMeanSigmaMap->meanTPC[kaIdx][centBin] : 0.f; + float sKaTpc = pidMeanSigmaMap ? pidMeanSigmaMap->sigmaTPC[kaIdx][centBin] : 1.f; + float mPrTpc = pidMeanSigmaMap ? pidMeanSigmaMap->meanTPC[prIdx][centBin] : 0.f; + float sPrTpc = pidMeanSigmaMap ? pidMeanSigmaMap->sigmaTPC[prIdx][centBin] : 1.f; + // TOF + float mPiTof = pidMeanSigmaMap ? pidMeanSigmaMap->meanTOF[piIdx][centBin] : 0.f; + float sPiTof = pidMeanSigmaMap ? pidMeanSigmaMap->sigmaTOF[piIdx][centBin] : 1.f; + float mKaTof = pidMeanSigmaMap ? pidMeanSigmaMap->meanTOF[kaIdx][centBin] : 0.f; + float sKaTof = pidMeanSigmaMap ? pidMeanSigmaMap->sigmaTOF[kaIdx][centBin] : 1.f; + float mPrTof = pidMeanSigmaMap ? pidMeanSigmaMap->meanTOF[prIdx][centBin] : 0.f; + float sPrTof = pidMeanSigmaMap ? pidMeanSigmaMap->sigmaTOF[prIdx][centBin] : 1.f; + //Fetch Raw nSigma Values + float rawTpcPi = candidate.tpcNSigmaPi(); + float rawTpcKa = candidate.tpcNSigmaKa(); + float rawTpcPr = candidate.tpcNSigmaPr(); + float rawTpcEl = candidate.tpcNSigmaEl(); + + float rawTofPi = 0.f, rawTofKa = 0.f, rawTofPr = 0.f; + if (candidate.hasTOF()) { + rawTofPi = candidate.tofNSigmaPi(); + rawTofKa = candidate.tofNSigmaKa(); + rawTofPr = candidate.tofNSigmaPr(); + } + // ELECTRON REJECTION: Reject if it is > cTpcRejCut from ALL hadron hypotheses AND falls within the electron band [-3, 5] + if (std::abs(rawTpcPi - mPiTpc) > cfgTpcElRejCut && + std::abs(rawTpcKa - mKaTpc) > cfgTpcElRejCut && + std::abs(rawTpcPr - mPrTpc) > cfgTpcElRejCut && + rawTpcEl > cfgTpcElRejCutMin && rawTpcEl < cfgTpcElRejCutMax) { + return 0; // It's an electron, reject it! + } + + // --- Low PT Regime --- + if (pt <= cfgCutPtUpperTPC) { + // Basic TPC passing check: |Raw - Mean| < (Cut * Sigma) + bool inTpcPi = std::abs(rawTpcPi - mPiTpc) < (cfgnSigmaCutTPC * sPiTpc); + bool inTpcKa = std::abs(rawTpcKa - mKaTpc) < (cfgnSigmaCutTPC * sKaTpc); + bool inTpcPr = std::abs(rawTpcPr - mPrTpc) < (cfgnSigmaCutTPC * sPrTpc); + // Combined passing check (adds TOF if available) + bool passPi = inTpcPi && (!candidate.hasTOF() || std::abs(rawTofPi - mPiTof) < (cfgnSigmaCutTOF * sPiTof)); + bool passKa = inTpcKa && (!candidate.hasTOF() || std::abs(rawTofKa - mKaTof) < (cfgnSigmaCutTOF * sKaTof)); + bool passPr = inTpcPr && (!candidate.hasTOF() || std::abs(rawTofPr - mPrTof) < (cfgnSigmaCutTOF * sPrTof)); + // Uniqueness check: Must pass target cut, and NOT fall into the TPC range of the others + if (passPi && !passKa && !passPr) + return 1; + if (passKa && !passPi && !passPr) + return 2; + if (passPr && !passPi && !passKa) + return 3; + + return 0; // Ambiguous or failed all cuts + } + // --- High PT Regime--- + if (candidate.hasTOF() && pt > cfgCutPtUpperTPC) { + // Calculate 2D Normalized Distance (Elliptical distance normalized by sigma) + float dPi = std::hypot((rawTpcPi - mPiTpc) / sPiTpc, (rawTofPi - mPiTof) / sPiTof); + float dKa = std::hypot((rawTpcKa - mKaTpc) / sKaTpc, (rawTofKa - mKaTof) / sKaTof); + float dPr = std::hypot((rawTpcPr - mPrTpc) / sPrTpc, (rawTofPr - mPrTof) / sPrTof); + // Count how many particles are within the ambiguity radius + int competitors = (dPi < cfgnSigmaOtherParticles) + + (dKa < cfgnSigmaOtherParticles) + + (dPr < cfgnSigmaOtherParticles); + // If 1 or fewer are in the ambiguity region, pick the absolute best match + if (competitors <= 1) { + if (dPi <= dKa && dPi <= dPr && dPi < cfgnSigmaCutCombTPCTOF) + return 1; + if (dKa <= dPi && dKa <= dPr && dKa < cfgnSigmaCutCombTPCTOF) + return 2; + if (dPr <= dPi && dPr <= dKa && dPr < cfgnSigmaCutCombTPCTOF) + return 3; + } + } + return 0; // Unknown/Reject } template bool isEventSelected(const T& col) { + histos.fill(HIST("hEvtCount"), 0.5); + if (!col.sel8()) return false; + histos.fill(HIST("hEvtCount"), 1.5); + if (std::abs(col.posZ()) > cfgCutVertex) return false; + histos.fill(HIST("hEvtCount"), 2.5); + if (cfgEvSelNoSameBunchPileup && !col.selection_bit(o2::aod::evsel::kNoSameBunchPileup)) return false; + histos.fill(HIST("hEvtCount"), 3.5); + if (cfgUseGoodITSLayerAllCut && !col.selection_bit(o2::aod::evsel::kIsGoodITSLayersAll)) return false; + histos.fill(HIST("hEvtCount"), 4.5); + if (cfgIsGoodZvtxFT0VsPV && !col.selection_bit(o2::aod::evsel::kIsGoodZvtxFT0vsPV)) return false; + histos.fill(HIST("hEvtCount"), 5.5); + return true; } template bool isTrackSelected(const T& trk) { + histos.fill(HIST("hTrkCount"), 0.5); + if (trk.sign() == 0) return false; + histos.fill(HIST("hTrkCount"), 1.5); + if (!trk.has_collision()) return false; + histos.fill(HIST("hTrkCount"), 2.5); + if (!trk.isPVContributor()) return false; + histos.fill(HIST("hTrkCount"), 3.5); + if (!(trk.itsNCls() > cfgITScluster)) return false; + histos.fill(HIST("hTrkCount"), 4.5); + if (!(trk.tpcNClsFound() >= cfgTPCcluster)) return false; + histos.fill(HIST("hTrkCount"), 5.5); + if (!(trk.tpcNClsCrossedRows() >= cfgTPCnCrossedRows)) return false; + histos.fill(HIST("hTrkCount"), 6.5); + if (trk.pt() < cfgCutPtLower || trk.pt() > cfgCutPtUpper || std::abs(trk.eta()) > cfgCutEta) return false; - // --- DCAxy Cut --- + histos.fill(HIST("hTrkCount"), 7.5); + + if (!trk.isGlobalTrack()) + return false; + histos.fill(HIST("hTrkCount"), 8.5); + if (cfgPtDepDCAxy) { - // Evaluates: 0.0026 + 0.005 / (pt^1.01) + // Evaluates: P0 + P1 / (pt^P2) float maxDcaXY = cfgDcaXyP0 + cfgDcaXyP1 / std::pow(trk.pt(), cfgDcaXyP2); if (std::abs(trk.dcaXY()) > maxDcaXY) { - return false; // Reject track if DCA is too large + return false; } + histos.fill(HIST("hTrkCount"), 9.5); } else { if (std::abs(trk.dcaXY()) > cfgCutTracKDcaMaxXY) { return false; } + histos.fill(HIST("hTrkCount"), 9.5); } - // --- DCAz Cut --- if (cfgPtDepDCAz) { - // Evaluates: 0.0026 + 0.005 / (pt^1.01) + // Evaluates: P0 + P1 / (pt^P2) float maxDcaZ = cfgDcaZP0 + cfgDcaZP1 / std::pow(trk.pt(), cfgDcaZP2); if (std::abs(trk.dcaZ()) > maxDcaZ) { return false; // Reject track if DCA is too large } + histos.fill(HIST("hTrkCount"), 10.5); } else { if (std::abs(trk.dcaZ()) > cfgCutTracKDcaMaxZ) { return false; } + histos.fill(HIST("hTrkCount"), 10.5); } return true; } @@ -352,115 +597,10 @@ struct RadialFlowDecorr { return true; } - template - bool selectionProton(const T& candidate) - { - if (!candidate.hasTPC()) - return false; - int flag = 0; - if (candidate.pt() > cfgCutPtLower && candidate.pt() <= cfgCutPtUpperTPC) { - if (!candidate.hasTOF() && std::abs(candidate.tpcNSigmaPr()) < cfgnSigmaCutTPC) { - flag = 1; - } - if (candidate.hasTOF() && std::abs(candidate.tpcNSigmaPr()) < cfgnSigmaCutTPC && std::abs(candidate.tofNSigmaPr()) < cfgnSigmaCutTOF) { - flag = 1; - } - } - if (candidate.hasTOF() && candidate.pt() > cfgCutPtUpperTPC && candidate.pt() < cfgCutPtUpperPID) { - auto [combNSigmaPr, combNSigmaPi, combNSigmaKa] = getAllCombinedNSigmas(candidate); - int flag2 = 0; - if (combNSigmaPr < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaPi < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaKa < cfgnSigmaOtherParticles) - flag2 += 1; - if (!(flag2 > 1) && !(combNSigmaPr > combNSigmaPi) && !(combNSigmaPr > combNSigmaKa)) { - if (combNSigmaPr < cfgnSigmaCutCombTPCTOF) { - flag = 1; - } - } - } - if (flag == 1) - return true; - else - return false; - } - - template - bool selectionPion(const T& candidate) - { - if (!candidate.hasTPC()) - return false; - int flag = 0; - - if (candidate.pt() > cfgCutPtLower && candidate.pt() <= cfgCutPtUpperTPC) { - if (!candidate.hasTOF() && std::abs(candidate.tpcNSigmaPi()) < cfgnSigmaCutTPC) { - flag = 1; - } - if (candidate.hasTOF() && std::abs(candidate.tpcNSigmaPi()) < cfgnSigmaCutTPC && std::abs(candidate.tofNSigmaPi()) < cfgnSigmaCutTOF) { - flag = 1; - } - } - if (candidate.hasTOF() && candidate.pt() > cfgCutPtUpperTPC && candidate.pt() < cfgCutPtUpperPID) { - auto [combNSigmaPr, combNSigmaPi, combNSigmaKa] = getAllCombinedNSigmas(candidate); - int flag2 = 0; - if (combNSigmaPr < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaPi < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaKa < cfgnSigmaOtherParticles) - flag2 += 1; - if (!(flag2 > 1) && !(combNSigmaPi > combNSigmaPr) && !(combNSigmaPi > combNSigmaKa)) { - if (combNSigmaPi < cfgnSigmaCutCombTPCTOF) { - flag = 1; - } - } - } - if (flag == 1) - return true; - else - return false; - } - - template - bool selectionKaon(const T& candidate) - { - if (!candidate.hasTPC()) - return false; - int flag = 0; - - if (candidate.pt() > cfgCutPtLower && candidate.pt() <= cfgCutPtUpperTPC) { - if (!candidate.hasTOF() && std::abs(candidate.tpcNSigmaKa()) < cfgnSigmaCutTPC) { - flag = 1; - } - if (candidate.hasTOF() && std::abs(candidate.tpcNSigmaKa()) < cfgnSigmaCutTPC && std::abs(candidate.tofNSigmaKa()) < cfgnSigmaCutTOF) { - flag = 1; - } - } - if (candidate.hasTOF() && candidate.pt() > cfgCutPtUpperTPC && candidate.pt() < cfgCutPtUpperPID) { - auto [combNSigmaPr, combNSigmaPi, combNSigmaKa] = getAllCombinedNSigmas(candidate); - int flag2 = 0; - if (combNSigmaPr < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaPi < cfgnSigmaOtherParticles) - flag2 += 1; - if (combNSigmaKa < cfgnSigmaOtherParticles) - flag2 += 1; - if (!(flag2 > 1) && !(combNSigmaKa > combNSigmaPi) && !(combNSigmaKa > combNSigmaPr)) { - if (combNSigmaKa < cfgnSigmaCutCombTPCTOF) { - flag = 1; - } - } - } - if (flag == 1) - return true; - else - return false; - } - float getCentrality(const auto& col) const { + if (cfgCentralityChoice.value == kCentFT0C) + return col.centFT0C(); if (cfgCentralityChoice.value == kCentFT0M) return col.centFT0M(); if (cfgCentralityChoice.value == kCentFDDM) @@ -588,7 +728,7 @@ struct RadialFlowDecorr { using GeneralCollisions = soa::Join; Filter collisionFilter = nabs(aod::collision::posZ) < cfgVtxZCut; @@ -599,8 +739,8 @@ struct RadialFlowDecorr { aod::TracksExtra, aod::TrackSelection, aod::TracksDCA, - aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr, - aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr>; + aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr, aod::pidTPCFullEl, + aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr, aod::pidTOFFullEl>; Filter trackFilter = aod::track::pt > KPtMin&& aod::track::pt < KPtMax&& requireGlobalTrackInFilter(); @@ -611,14 +751,14 @@ struct RadialFlowDecorr { using MyRun3MCCollisions = soa::Join< aod::Collisions, aod::EvSels, aod::Mults, aod::MultsExtra, - aod::CentFT0Ms, aod::CentFDDMs, aod::CentFV0As, + aod::CentFT0Cs, aod::CentFT0Ms, aod::CentFDDMs, aod::CentFV0As, aod::CentNGlobals, aod::McCollisionLabels>; using MyMCTracks = soa::Join< aod::Tracks, aod::TrackSelection, aod::TracksExtra, aod::TracksDCA, aod::McTrackLabels, - aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr, - aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr>; + aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr, aod::pidTPCFullEl, + aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr, aod::pidTOFFullEl>; PresliceUnsorted partPerMcCollision = aod::mcparticle::mcCollisionId; PresliceUnsorted colPerMcCollision = aod::mccollisionlabel::mcCollisionId; @@ -628,7 +768,7 @@ struct RadialFlowDecorr { void declareCommonQA() { - histos.add("hZvtx_after_sel", ";z_{vtx} (cm)", kTH1F, {{KNbinsZvtx, KZvtxMin, KZvtxMax}}); + histos.add("hVtxZ_after_sel", ";z_{vtx} (cm)", kTH1F, {{KNbinsZvtx, KZvtxMin, KZvtxMax}}); histos.add("hVtxZ", ";z_{vtx} (cm)", kTH1F, {{KNbinsZvtx, KZvtxMin, KZvtxMax}}); histos.add("hCentrality", ";centrality (%)", kTH1F, {{centAxis1Per}}); histos.add("Hist2D_globalTracks_PVTracks", ";N_{global};N_{PV}", kTH2F, {{nChAxis2}, {nChAxis2}}); @@ -637,6 +777,27 @@ struct RadialFlowDecorr { histos.add("hPt", ";p_{T} (GeV/c)", kTH1F, {{KNbinsPt, KPtMin, KPtMax}}); histos.add("hEta", ";#eta", kTH1F, {{KNbinsEtaFine, KEtaMin, KEtaMax}}); histos.add("hPhi", ";#phi", kTH1F, {{KNbinsPhi, KPhiMin, TwoPI}}); + + histos.add("hEvtCount", "Number of Event;; Count", kTH1F, {{7, 0, 7}}); + histos.get(HIST("hEvtCount"))->GetXaxis()->SetBinLabel(1, "all Events"); + histos.get(HIST("hEvtCount"))->GetXaxis()->SetBinLabel(2, "after sel8"); + histos.get(HIST("hEvtCount"))->GetXaxis()->SetBinLabel(3, "after VertexZ Cut"); + histos.get(HIST("hEvtCount"))->GetXaxis()->SetBinLabel(4, "after kNoSameBunchPileup"); + histos.get(HIST("hEvtCount"))->GetXaxis()->SetBinLabel(5, "after kIsGoodZvtxFT0vsPV"); + histos.get(HIST("hEvtCount"))->GetXaxis()->SetBinLabel(6, "after kIsGoodITSLayersAll"); + + histos.add("hTrkCount", "Number of Tracks;; Count", kTH1F, {{11, 0, 11}}); + histos.get(HIST("hTrkCount"))->GetXaxis()->SetBinLabel(1, "all Tracks"); + histos.get(HIST("hTrkCount"))->GetXaxis()->SetBinLabel(2, "after sign!=0"); + histos.get(HIST("hTrkCount"))->GetXaxis()->SetBinLabel(3, "after has_collision"); + histos.get(HIST("hTrkCount"))->GetXaxis()->SetBinLabel(4, "after isPVContributor"); + histos.get(HIST("hTrkCount"))->GetXaxis()->SetBinLabel(5, "after itsNCls"); + histos.get(HIST("hTrkCount"))->GetXaxis()->SetBinLabel(6, "after tpcNClsFound"); + histos.get(HIST("hTrkCount"))->GetXaxis()->SetBinLabel(7, "after tpcNClsCrossedRows"); + histos.get(HIST("hTrkCount"))->GetXaxis()->SetBinLabel(8, "after pT,#eta selections"); + histos.get(HIST("hTrkCount"))->GetXaxis()->SetBinLabel(9, "after isGlobalTrack"); + histos.get(HIST("hTrkCount"))->GetXaxis()->SetBinLabel(10, "after dcaXY"); + histos.get(HIST("hTrkCount"))->GetXaxis()->SetBinLabel(11, "after dcaZ"); } void declareMCCommonHists() @@ -660,15 +821,12 @@ struct RadialFlowDecorr { void declarenSigHists() { for (const auto& suf : pidSuffix) { - // Before Cuts - histos.add("h2DnsigmaTpcVsPtBeforeCut" + suf, "TPC nSigma vs pT Before Cut;p_{T} (GeV/c);n#sigma_{TPC}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); - histos.add("h2DnsigmaTofVsPtBeforeCut" + suf, "TOF nSigma vs pT Before Cut;p_{T} (GeV/c);n#sigma_{TOF}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); - histos.add("h2DnsigmaTpcVsTofBeforeCut" + suf, "TPC vs TOF nSigma Before Cut;n#sigma_{TOF};n#sigma_{TPC}", kTH2F, {{200, -10.f, 10.f}, {200, -10.f, 10.f}}); - - // After Cuts - histos.add("h2DnsigmaTpcVsPtAfterCut" + suf, "TPC nSigma vs pT After Cut;p_{T} (GeV/c);n#sigma_{TPC}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); - histos.add("h2DnsigmaTofVsPtAfterCut" + suf, "TOF nSigma vs pT After Cut;p_{T} (GeV/c);n#sigma_{TOF}", kTH2F, {{KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); - histos.add("h2DnsigmaTpcVsTofAfterCut" + suf, "TPC vs TOF nSigma After Cut;n#sigma_{TOF};n#sigma_{TPC}", kTH2F, {{200, -10.f, 10.f}, {200, -10.f, 10.f}}); + histos.add("h3DnsigmaTpcVsPtBefCut_Cent" + suf, "TPC nSigma vs pT Before Cut;cent [%]; p_{T} (GeV/c);n#sigma_{TPC}", kTH3F, {{centAxis1Per}, {KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); + histos.add("h3DnsigmaTofVsPtBefCut_Cent" + suf, "TOF nSigma vs pT Before Cut;cent [%]; p_{T} (GeV/c);n#sigma_{TOF}", kTH3F, {{centAxis1Per}, {KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); + histos.add("h3DnsigmaTpcVsTofBefCut_Cent" + suf, "TPC vs TOF nSigma Before Cut;cent [%]; n#sigma_{TOF};n#sigma_{TPC}", kTH3F, {{centAxis1Per}, {200, -10.f, 10.f}, {200, -10.f, 10.f}}); + histos.add("h3DnsigmaTpcVsPtAftCut_Cent" + suf, "TPC nSigma vs pT After Cut;cent [%],; p_{T} (GeV/c);n#sigma_{TPC}", kTH3F, {{centAxis1Per}, {KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); + histos.add("h3DnsigmaTofVsPtAftCut_Cent" + suf, "TOF nSigma vs pT After Cut;cent [%],; p_{T} (GeV/c);n#sigma_{TOF}", kTH3F, {{centAxis1Per}, {KNbinsPtRes, KPtMin, KPtMax}, {200, -10.f, 10.f}}); + histos.add("h3DnsigmaTpcVsTofAftCut_Cent" + suf, "TPC vs TOF nSigma After Cut;cent [%],; n#sigma_{TOF};n#sigma_{TPC}", kTH3F, {{centAxis1Per}, {200, -10.f, 10.f}, {200, -10.f, 10.f}}); } } @@ -940,20 +1098,28 @@ struct RadialFlowDecorr { default: LOGF(fatal, "Invalid cfgSys value: %d", cfgSys.value); } - + std::string pathNsig = cfgCCDBUserPath.value + "/" + sysDir + "/Job0_nSigMaps"; std::string pathEff = cfgCCDBUserPath.value + "/" + sysDir + "/Job1_EffMaps"; std::string pathMCFlat = cfgCCDBUserPath.value + "/" + sysDir + "/Job1_MCFlatMaps"; std::string pathMCMean = cfgCCDBUserPath.value + "/" + sysDir + "/Job2_MCMean"; + + std::string pathDataNsig = cfgCCDBUserPath.value + "/" + sysDir + "/Job0_DatanSigMaps"; std::string pathDataFlat = cfgCCDBUserPath.value + "/" + sysDir + "/Job1_DataFlatMaps"; std::string pathDataMean = cfgCCDBUserPath.value + "/" + sysDir + "/Job2_DataMean"; declareCommonQA(); - if (cfgRunGetEff || cfgRunGetDataFlat) { + if (cfgRunMCGetNSig || cfgRunGetEff || cfgRunDataGetNSig || cfgRunGetDataFlat) { declarenSigHists(); } + if (cfgRunMCMean || cfgRunMCFluc || cfgRunGetEff) { declareMCCommonHists(); } + if (cfgRunGetMCFlat) { + declareMCGetFlatHists(); + histos.addClone("MCGen/", "MCReco/"); + histos.addClone("MCGen/", "MCRecoEffCorr/"); + } if (cfgRunMCMean) { declareMCMeanHists(); histos.addClone("MCGen/", "MCReco/"); @@ -964,13 +1130,11 @@ struct RadialFlowDecorr { histos.addClone("MCGen/", "MCReco/"); histos.addClone("MCGen/", "MCRecoEffCorr/"); } - if (cfgRunGetDataFlat) { + if (cfgRunDataGetNSig) { declareDataGetFlatHists(); } - if (cfgRunGetMCFlat) { - declareMCGetFlatHists(); - histos.addClone("MCGen/", "MCReco/"); - histos.addClone("MCGen/", "MCRecoEffCorr/"); + if (cfgRunGetDataFlat) { + declareDataGetFlatHists(); } if (cfgRunDataMean) { declareDataMeanHists(); @@ -979,7 +1143,7 @@ struct RadialFlowDecorr { declareDataFlucHists(); } - if (!cfgRunGetEff && (cfgEff)) { + if (!cfgRunGetEff && !cfgRunMCGetNSig && (cfgEff)) { TList* lst = ccdb->getForTimeStamp(pathEff, now); if (!lst) { @@ -1016,7 +1180,7 @@ struct RadialFlowDecorr { if (hNumS && hNumF && hDenF) { state.hFake[pidType] = reinterpret_cast(hNumS->Clone(Form("hFake%s", suffix.c_str()))); state.hFake[pidType]->Add(hNumF); - // state.hFake[pidType]->Add(hNumF2); + state.hFake[pidType]->Add(hNumF2); state.hFake[pidType]->SetDirectory(nullptr); state.hFake[pidType]->Divide(hDenF); } else { @@ -1029,6 +1193,114 @@ struct RadialFlowDecorr { } } + if (cfgRunGetEff || cfgRunGetMCFlat || cfgRunMCMean || cfgRunMCFluc) { + TList* pidList = ccdb->getForTimeStamp(pathNsig, now); + + if (!pidList) { + LOGF(warn, "nSigma maps required but CCDB list is null at %s! Using raw values.", pathNsig.c_str()); + } else { + if (!pidMeanSigmaMap) + pidMeanSigmaMap = new PIDMeanSigmaMap(); + + LOGF(info, "Performing 2D Gaussian fits on PID maps from CCDB..."); + + auto loadPIDMeans = [&](PIDIdx pidType) { + std::string suffix = pidSuffix[pidType]; + std::string hName = "h3DnsigmaTpcVsTofBefCut_Cent" + suffix; + auto* h3 = reinterpret_cast(pidList->FindObject(hName.c_str())); + + if (!h3) { + LOGF(warn, " [!] PID Hist %s not found in CCDB list.", hName.c_str()); + return; + } + + int nCentBins = std::min(h3->GetXaxis()->GetNbins(), PIDMeanSigmaMap::MaxCentBins - 1); + LOGF(info, " -> Species: %s (Bins: %d)", hName.c_str(), nCentBins); + + for (int iCent = 1; iCent <= nCentBins; ++iCent) { + h3->GetXaxis()->SetRange(iCent, iCent); + // Projecting: Z(TPC) vs Y(TOF). Result: X_axis=TOF, Y_axis=TPC + std::unique_ptr h2(reinterpret_cast(h3->Project3D("zy"))); + if (h2) { + TF2 f2("f2", "[0]*TMath::Gaus(x,[1],[2])*TMath::Gaus(y,[3],[4])", -3, 3, -3, 3); + // Initial Parameters: Amp, MeanTOF, SigmaTOF, MeanTPC, SigmaTPC + f2.SetParameter(0, h2->GetMaximum()); + f2.SetParameter(1, 0.0); + f2.SetParLimits(1, -2, 2); + + h2->Fit(&f2, "QRN"); + pidMeanSigmaMap->meanTOF[pidType][iCent - 1] = f2.GetParameter(1); + pidMeanSigmaMap->meanTPC[pidType][iCent - 1] = f2.GetParameter(3); + pidMeanSigmaMap->sigmaTOF[pidType][iCent - 1] = std::abs(f2.GetParameter(2)); + pidMeanSigmaMap->sigmaTPC[pidType][iCent - 1] = std::abs(f2.GetParameter(4)); + + if (iCent % KConstTen == 0) { + LOGF(info, " Bin %d: Mean TOF = %.3f, Mean TPC = %.3f", + iCent - 1, f2.GetParameter(1), f2.GetParameter(3)); + } + } + } + }; + for (int i = 0; i < KNsp; ++i) { + loadPIDMeans(static_cast(i)); + } + } + } + + if (cfgRunGetDataFlat || cfgRunDataMean || cfgRunDataFluc) { + TList* pidList = ccdb->getForTimeStamp(pathDataNsig, now); + + if (!pidList) { + LOGF(warn, "nSigma maps required but CCDB list is null at %s! Using raw values.", pathDataNsig.c_str()); + } else { + if (!pidMeanSigmaMap) + pidMeanSigmaMap = new PIDMeanSigmaMap(); + + LOGF(info, "Performing 2D Gaussian fits on PID maps from CCDB..."); + + auto loadPIDMeans = [&](PIDIdx pidType) { + std::string suffix = pidSuffix[pidType]; + std::string hName = "h3DnsigmaTpcVsTofBefCut_Cent" + suffix; + auto* h3 = reinterpret_cast(pidList->FindObject(hName.c_str())); + + if (!h3) { + LOGF(warn, " [!] PID Hist %s not found in CCDB list.", hName.c_str()); + return; + } + + int nCentBins = std::min(h3->GetXaxis()->GetNbins(), PIDMeanSigmaMap::MaxCentBins - 1); + LOGF(info, " -> Species: %s (Bins: %d)", hName.c_str(), nCentBins); + + for (int iCent = 1; iCent <= nCentBins; ++iCent) { + h3->GetXaxis()->SetRange(iCent, iCent); + // Projecting: Z(TPC) vs Y(TOF). Result: X_axis=TOF, Y_axis=TPC + std::unique_ptr h2(reinterpret_cast(h3->Project3D("zy"))); + if (h2) { + TF2 f2("f2", "[0]*TMath::Gaus(x,[1],[2])*TMath::Gaus(y,[3],[4])", -3, 3, -3, 3); + // Initial Parameters: Amp, MeanTOF, SigmaTOF, MeanTPC, SigmaTPC + f2.SetParameter(0, h2->GetMaximum()); + f2.SetParameter(1, 0.0); + f2.SetParLimits(1, -2, 2); + + h2->Fit(&f2, "QRN"); + pidMeanSigmaMap->meanTOF[pidType][iCent - 1] = f2.GetParameter(1); + pidMeanSigmaMap->meanTPC[pidType][iCent - 1] = f2.GetParameter(3); + pidMeanSigmaMap->sigmaTOF[pidType][iCent - 1] = std::abs(f2.GetParameter(2)); + pidMeanSigmaMap->sigmaTPC[pidType][iCent - 1] = std::abs(f2.GetParameter(4)); + + if (iCent % KConstTen == 0) { + LOGF(info, " Bin %d: Mean TOF = %.3f, Mean TPC = %.3f", + iCent - 1, f2.GetParameter(1), f2.GetParameter(3)); + } + } + } + }; + for (int i = 0; i < KNsp; ++i) { + loadPIDMeans(static_cast(i)); + } + } + } + if (!cfgRunGetEff && (cfgFlat)) { if (cfgRunDataMean || cfgRunDataFluc) { LOGF(info, "Data Run: Loading flattening maps from %s", pathDataFlat.c_str()); @@ -1156,6 +1428,44 @@ struct RadialFlowDecorr { LOGF(info, "CCDB initialization complete for RadialFlowDecorr."); } + void processMCGetMeanNsig(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/, aod::McParticles const& mcParticles) + { + for (const auto& mcCollision : mcColl) { + auto colSlice = collisions.sliceBy(colPerMcCollision, mcCollision.globalIndex()); + if (colSlice.size() != 1) + continue; + for (const auto& col : colSlice) { + histos.fill(HIST("hVtxZ"), col.posZ()); + if (!col.has_mcCollision() || !isEventSelected(col)) + continue; + auto trackSlice = tracks.sliceBy(trackPerCollision, col.globalIndex()); + auto partSlice = mcParticles.sliceBy(partPerMcCollision, mcCollision.globalIndex()); + if (trackSlice.size() < 1 || partSlice.size() < 1) + continue; + float cent = getCentrality(col); + if (cent > KCentMax) + continue; + float multPV = col.multNTracksPV(); + for (const auto& particle : partSlice) { + if (!isParticleSelected(particle) || !particle.isPhysicalPrimary()) + continue; + histos.fill(HIST("hVtxZ_after_sel"), col.posZ()); + histos.fill(HIST("hCentrality"), cent); + + histos.fill(HIST("Hist2D_globalTracks_PVTracks"), multPV, trackSlice.size()); + histos.fill(HIST("Hist2D_cent_nch"), trackSlice.size(), cent); + + for (const auto& track : trackSlice) { + if (!isTrackSelected(track)) + continue; + fillNSigmaBefCut(track, cent); + } + } + } + } + } + PROCESS_SWITCH(RadialFlowDecorr, processMCGetMeanNsig, "process MC to calculate Mean values of nSig Plots", cfgRunMCGetNSig); + void processGetEffHists(aod::McCollisions const& mcColl, MyRun3MCCollisions const& collisions, TCs const& tracks, FilteredTCs const& /*filteredTracks*/, aod::McParticles const& mcParticles) { for (const auto& mcCollision : mcColl) { @@ -1164,6 +1474,7 @@ struct RadialFlowDecorr { continue; for (const auto& col : colSlice) { + histos.fill(HIST("hVtxZ"), col.posZ()); if (!col.has_mcCollision() || !isEventSelected(col)) continue; @@ -1173,6 +1484,7 @@ struct RadialFlowDecorr { continue; float cent = getCentrality(col); + if (cent > KCentMax) continue; float multPV = col.multNTracksPV(); @@ -1196,7 +1508,7 @@ struct RadialFlowDecorr { absPdg == KKPlus, // kKaAllIdx pdg == -KProton, // kAntiPrIdx pdg == KProton, // kPrIdx - absPdg == KProton // kAllPrIdx + absPdg == KProton // kPrAllIdx }; histos.fill(HIST("h3_AllPrimary"), multPV, pt, eta); @@ -1218,11 +1530,11 @@ struct RadialFlowDecorr { histos.fill(HIST("h3_AllPrimary_AntiPr"), multPV, pt, eta); else if (isSpecies[kPrIdx]) histos.fill(HIST("h3_AllPrimary_Pr"), multPV, pt, eta); - if (isSpecies[kAllPrIdx]) - histos.fill(HIST("h3_AllPrimary_AllPr"), multPV, pt, eta); + if (isSpecies[kPrAllIdx]) + histos.fill(HIST("h3_AllPrimary_PrAll"), multPV, pt, eta); } - histos.fill(HIST("hZvtx_after_sel"), col.posZ()); + histos.fill(HIST("hVtxZ_after_sel"), col.posZ()); histos.fill(HIST("hCentrality"), cent); histos.fill(HIST("Hist2D_globalTracks_PVTracks"), multPV, trackSlice.size()); @@ -1234,37 +1546,13 @@ struct RadialFlowDecorr { float pt = track.pt(), eta = track.eta(); auto sign = track.sign(); - if (sign > 0) { - // PiPlus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiPlus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiPlus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); - // KaPlus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaPlus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaPlus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); - // Pr - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_Pr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_Pr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); - } else if (sign < 0) { - // PiMinus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiMinus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiMinus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); - // KaMinus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaMinus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaMinus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); - // AntiPr - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_AntiPr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_AntiPr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); - } + fillNSigmaBefCut(track, cent); - bool isPi = selectionPion(track); - bool isKa = selectionKaon(track); - bool isPr = selectionProton(track); + int centBin = static_cast(cent); + int id = identifyTrack(track, centBin); + bool isPi = (id == KPidPionOne); + bool isKa = (id == KPidKaonTwo); + bool isPr = (id == KPidProtonThree); bool isSpecies[KNsp] = { true, @@ -1272,40 +1560,12 @@ struct RadialFlowDecorr { isKa && sign < 0, isKa && sign > 0, isKa, isPr && sign < 0, isPr && sign > 0, isPr}; - if (isSpecies[kPiPlusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiPlus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiPlus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); - } else if (isSpecies[kPiMinusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiMinus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiMinus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); - } - - if (isSpecies[kKaPlusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaPlus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaPlus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); - } else if (isSpecies[kKaMinusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaMinus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaMinus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); - } - - if (isSpecies[kPrIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_Pr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_Pr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); - } else if (isSpecies[kAntiPrIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_AntiPr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_AntiPr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); - } - for (int isp = 0; isp < KNsp; ++isp) { if (!isSpecies[isp]) continue; + fillNSigmaAftCut(track, cent, isSpecies); + if (isp == kInclusiveIdx) { histos.fill(HIST("h3_AllReco"), multPV, pt, eta); if (track.has_mcParticle()) { @@ -1457,21 +1717,21 @@ struct RadialFlowDecorr { } else { histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_Pr"), multPV, pt, eta); } - } else if (isp == kAllPrIdx) { - histos.fill(HIST("h3_AllReco_AllPr"), multPV, pt, eta); + } else if (isp == kPrAllIdx) { + histos.fill(HIST("h3_AllReco_PrAll"), multPV, pt, eta); if (track.has_mcParticle()) { auto mcP = track.mcParticle(); if (mcP.isPhysicalPrimary()) { if (std::abs(mcP.pdgCode()) == KProton) { - histos.fill(HIST("h3_RecoMatchedToPrimary_AllPr"), multPV, mcP.pt(), mcP.eta()); + histos.fill(HIST("h3_RecoMatchedToPrimary_PrAll"), multPV, mcP.pt(), mcP.eta()); } else { // Misidentified - histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_AllPr"), multPV, pt, eta); + histos.fill(HIST("h3_RecoMatchedToPrimary_MisID_PrAll"), multPV, pt, eta); } } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_AllPr"), multPV, pt, eta); + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Secondary_PrAll"), multPV, pt, eta); } } else { - histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_AllPr"), multPV, pt, eta); + histos.fill(HIST("h3_RecoUnMatchedToPrimary_Fake_PrAll"), multPV, pt, eta); } } } @@ -1503,7 +1763,7 @@ struct RadialFlowDecorr { float multPV = col.multNTracksPV(); float vz = col.posZ(); - histos.fill(HIST("hZvtx_after_sel"), col.posZ()); + histos.fill(HIST("hVtxZ_after_sel"), col.posZ()); histos.fill(HIST("hCentrality"), cent); histos.fill(HIST("Hist2D_globalTracks_PVTracks"), col.multNTracksPV(), trackSlice.size()); @@ -1514,9 +1774,11 @@ struct RadialFlowDecorr { float pt = track.pt(), eta = track.eta(), phi = track.phi(); auto sign = track.sign(); - bool isPi = selectionPion(track); - bool isKa = selectionKaon(track); - bool isPr = selectionProton(track); + int centBin = static_cast(cent); + int id = identifyTrack(track, centBin); + bool isPi = (id == KPidPionOne); + bool isKa = (id == KPidKaonTwo); + bool isPr = (id == KPidProtonThree); bool isSpecies[KNsp] = { true, @@ -1569,10 +1831,10 @@ struct RadialFlowDecorr { histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_Pr"), vz, sign, pt, eta, phi, w); histos.fill(HIST("MCReco/hEtaPhiReco_Pr"), vz, sign, pt, eta, phi, 1.0); histos.fill(HIST("MCReco/hEtaPhiRecoWtd_Pr"), vz, sign, pt, eta, phi, w); - } else if (isp == kAllPrIdx) { - histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("MCReco/hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi, 1.0); - histos.fill(HIST("MCReco/hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); + } else if (isp == kPrAllIdx) { + histos.fill(HIST("MCReco/hEtaPhiRecoEffWtd_PrAll"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("MCReco/hEtaPhiReco_PrAll"), vz, sign, pt, eta, phi, 1.0); + histos.fill(HIST("MCReco/hEtaPhiRecoWtd_PrAll"), vz, sign, pt, eta, phi, w); } } } @@ -1634,7 +1896,7 @@ struct RadialFlowDecorr { absPdg == KKPlus, // kKaAllIdx pdgCode == -KProton, // kAntiPrIdx pdgCode == KProton, // kPrIdx - absPdg == KProton // kAllPrIdx + absPdg == KProton // kPrAllIdx }; for (int ieta = 0; ieta < KNEta; ++ieta) { @@ -1659,7 +1921,7 @@ struct RadialFlowDecorr { } } - histos.fill(HIST("hZvtx_after_sel"), col.posZ()); + histos.fill(HIST("hVtxZ_after_sel"), col.posZ()); histos.fill(HIST("hCentrality"), cent); histos.fill(HIST("Hist2D_globalTracks_PVTracks"), col.multNTracksPV(), trackSlice.size()); @@ -1672,22 +1934,17 @@ struct RadialFlowDecorr { if (pt <= cfgPtMin || pt > cfgPtMax) continue; auto sign = track.sign(); - bool isPi = selectionPion(track); - bool isKa = selectionKaon(track); - bool isPr = selectionProton(track); + int centBin = static_cast(cent); + int id = identifyTrack(track, centBin); + bool isPi = (id == KPidPionOne); + bool isKa = (id == KPidKaonTwo); + bool isPr = (id == KPidProtonThree); bool isSpecies[KNsp] = { - true, // kInclusiveIdx - isPi && sign < 0, // kPiMinusIdx - isPi && sign > 0, // kPiPlusIdx - isPi, // kPiAllIdx - isKa && sign < 0, // kKaMinusIdx - isKa && sign > 0, // kKaPlusIdx - isKa, // kKaAllIdx - isPr && sign < 0, // kAntiPrIdx (Negative) - isPr && sign > 0, // kPrIdx (Positive) - isPr // kAllPrIdx - }; + true, + isPi && sign < 0, isPi && sign > 0, isPi, + isKa && sign < 0, isKa && sign > 0, isKa, + isPr && sign < 0, isPr && sign > 0, isPr}; for (int isp = 0; isp < KNsp; ++isp) { if (!isSpecies[isp]) @@ -1762,10 +2019,10 @@ struct RadialFlowDecorr { histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kAllPrIdx) { - histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPrAllIdx) { + histos.fill(HIST("hEtaPhiReco_PrAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_PrAll"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_PrAll"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); } } } @@ -1817,8 +2074,8 @@ struct RadialFlowDecorr { histos.fill(HIST("Prof2D_MeanpTSub_Tru_Pr"), cent, ietaA, ietaC, mptsubTru); else if (isp == kAntiPrIdx) histos.fill(HIST("Prof2D_MeanpTSub_Tru_AntiPr"), cent, ietaA, ietaC, mptsubTru); - else if (isp == kAllPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Tru_AllPr"), cent, ietaA, ietaC, mptsubTru); + else if (isp == kPrAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Tru_PrAll"), cent, ietaA, ietaC, mptsubTru); } if (nRecoAB > 0) { @@ -1840,8 +2097,8 @@ struct RadialFlowDecorr { histos.fill(HIST("Prof2D_MeanpTSub_Reco_Pr"), cent, ietaA, ietaC, mptsubReco); else if (isp == kAntiPrIdx) histos.fill(HIST("Prof2D_MeanpTSub_Reco_AntiPr"), cent, ietaA, ietaC, mptsubReco); - else if (isp == kAllPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_Reco_AllPr"), cent, ietaA, ietaC, mptsubReco); + else if (isp == kPrAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_Reco_PrAll"), cent, ietaA, ietaC, mptsubReco); } if (nCorrAB > 0) { @@ -1863,8 +2120,8 @@ struct RadialFlowDecorr { histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_Pr"), cent, ietaA, ietaC, mptsubRecoEffCorr); else if (isp == kAntiPrIdx) histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_AntiPr"), cent, ietaA, ietaC, mptsubRecoEffCorr); - else if (isp == kAllPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_AllPr"), cent, ietaA, ietaC, mptsubRecoEffCorr); + else if (isp == kPrAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_RecoEffCorr_PrAll"), cent, ietaA, ietaC, mptsubRecoEffCorr); } } } @@ -2012,7 +2269,7 @@ struct RadialFlowDecorr { absPdg == KKPlus, // kKaAllIdx pdgCode == -KProton, // kAntiPrIdx pdgCode == KProton, // kPrIdx - absPdg == KProton // kAllPrIdx + absPdg == KProton // kPrAllIdx }; for (int ieta = 0; ieta < KNEta; ++ieta) { @@ -2032,7 +2289,7 @@ struct RadialFlowDecorr { } // end truth loop float vz = col.posZ(); - histos.fill(HIST("hZvtx_after_sel"), col.posZ()); + histos.fill(HIST("hVtxZ_after_sel"), col.posZ()); histos.fill(HIST("hCentrality"), cent); histos.fill(HIST("Hist2D_globalTracks_PVTracks"), col.multNTracksPV(), trackSlice.size()); @@ -2048,27 +2305,21 @@ struct RadialFlowDecorr { float eta = track.eta(); float phi = track.phi(); auto sign = track.sign(); - bool isPi = selectionPion(track); - bool isKa = selectionKaon(track); - bool isPr = selectionProton(track); + int centBin = static_cast(cent); + int id = identifyTrack(track, centBin); + bool isPi = (id == KPidPionOne); + bool isKa = (id == KPidKaonTwo); + bool isPr = (id == KPidProtonThree); bool isSpecies[KNsp] = { - true, // kInclusiveIdx - isPi && sign < 0, // kPiMinusIdx - isPi && sign > 0, // kPiPlusIdx - isPi, // kPiAllIdx - isKa && sign < 0, // kKaMinusIdx - isKa && sign > 0, // kKaPlusIdx - isKa, // kKaAllIdx - isPr && sign < 0, // kAntiPrIdx (Negative) - isPr && sign > 0, // kPrIdx (Positive) - isPr // kAllPrIdx - }; + true, + isPi && sign < 0, isPi && sign > 0, isPi, + isKa && sign < 0, isKa && sign > 0, isKa, + isPr && sign < 0, isPr && sign > 0, isPr}; for (int isp = 0; isp < KNsp; ++isp) { if (!isSpecies[isp]) continue; - float eff = getEfficiency(col.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); float fake = getEfficiency(col.multNTracksPV(), pt, eta, static_cast(isp), 1, cfgEff); float flatW = getFlatteningWeight(vz, sign, pt, eta, phi, static_cast(isp), cfgFlat); @@ -2126,10 +2377,10 @@ struct RadialFlowDecorr { histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); - } else if (isp == kAllPrIdx) { - histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); - histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); + } else if (isp == kPrAllIdx) { + histos.fill(HIST("hEtaPhiReco_PrAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoWtd_PrAll"), vz, sign, pt, eta, phi, w); + histos.fill(HIST("hEtaPhiRecoEffWtd_PrAll"), vz, sign, pt, eta, phi, (1.0 - fake) / eff); } } } // trkslice @@ -2659,40 +2910,40 @@ struct RadialFlowDecorr { if (std::isfinite(covFT0CRecoEffCor)) histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0CRecoEffCor); - } else if (isp == kAllPrIdx) { + } else if (isp == kPrAllIdx) { if (std::isfinite(c2SubTru)) { - histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2SubTru); - histos.fill(HIST("MCGen/Prof_GapSum2D_AllPr"), cent, gap, sum, c2SubTru); + histos.fill(HIST("MCGen/Prof_C2Sub2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, c2SubTru); + histos.fill(HIST("MCGen/Prof_GapSum2D_PrAll"), cent, gap, sum, c2SubTru); } if (std::isfinite(c2SubReco)) { - histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2SubReco); - histos.fill(HIST("MCReco/Prof_GapSum2D_AllPr"), cent, gap, sum, c2SubReco); + histos.fill(HIST("MCReco/Prof_C2Sub2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, c2SubReco); + histos.fill(HIST("MCReco/Prof_GapSum2D_PrAll"), cent, gap, sum, c2SubReco); } if (std::isfinite(c2SubRecoEffCor)) { - histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2SubRecoEffCor); - histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_AllPr"), cent, gap, sum, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_C2Sub2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, c2SubRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_GapSum2D_PrAll"), cent, gap, sum, c2SubRecoEffCor); } if (std::isfinite(covTru)) - histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covTru); + histos.fill(HIST("MCGen/Prof_Cov2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, covTru); if (std::isfinite(covReco)) - histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covReco); + histos.fill(HIST("MCReco/Prof_Cov2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, covReco); if (std::isfinite(covRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_Cov2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, covRecoEffCor); if (std::isfinite(covFT0ATru)) - histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0ATru); + histos.fill(HIST("MCGen/Prof_CovFT0A2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, covFT0ATru); if (std::isfinite(covFT0AReco)) - histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0AReco); + histos.fill(HIST("MCReco/Prof_CovFT0A2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, covFT0AReco); if (std::isfinite(covFT0ARecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0ARecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0A2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, covFT0ARecoEffCor); if (std::isfinite(covFT0CTru)) - histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0CTru); + histos.fill(HIST("MCGen/Prof_CovFT0C2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, covFT0CTru); if (std::isfinite(covFT0CReco)) - histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0CReco); + histos.fill(HIST("MCReco/Prof_CovFT0C2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, covFT0CReco); if (std::isfinite(covFT0CRecoEffCor)) - histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0CRecoEffCor); + histos.fill(HIST("MCRecoEffCorr/Prof_CovFT0C2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, covFT0CRecoEffCor); } } } @@ -2703,6 +2954,49 @@ struct RadialFlowDecorr { } PROCESS_SWITCH(RadialFlowDecorr, processMCFluc, "process MC to calculate pt fluc", cfgRunMCFluc); + void processDataGetNSig(AodCollisionsSel::iterator const& coll, BCsRun3 const& /*bcs*/, aod::Zdcs const& /*zdcsData*/, AodTracksSel const& tracks) + { + histos.fill(HIST("hVtxZ"), coll.posZ()); + if (!isEventSelected(coll)) + return; + float cent = getCentrality(coll); + if (cent > KCentMax) + return; + histos.fill(HIST("hVtxZ_after_sel"), coll.posZ()); + histos.fill(HIST("hCentrality"), cent); + + histos.fill(HIST("Hist2D_globalTracks_PVTracks"), coll.multNTracksPV(), tracks.size()); + histos.fill(HIST("Hist2D_cent_nch"), tracks.size(), cent); + + int ntrk = 0; + for (const auto& track : tracks) { + if (!isTrackSelected(track)) + continue; + float pt = track.pt(); + if (pt <= cfgPtMin || pt > cfgPtMax) + continue; + float eta = track.eta(); + if (eta > etaLw[0] && eta < etaUp[0]) + ntrk++; + fillNSigmaBefCut(track, cent); + } + + histos.fill(HIST("hCentnTrk"), cent, ntrk); + histos.fill(HIST("hCentnTrkPV"), cent, coll.multNTracksPV()); + + if (cfgZDC) { + const auto& foundBC = coll.foundBC_as(); + if (!foundBC.has_zdc()) { + return; + } + auto zdc = foundBC.zdc(); + auto zdcAmp = zdc.energyCommonZNA() + zdc.energyCommonZNC(); + histos.fill(HIST("hnTrkPVZDC"), coll.multNTracksPV(), zdcAmp); + histos.fill(HIST("hNchZDC"), ntrk, zdcAmp); + } + } + PROCESS_SWITCH(RadialFlowDecorr, processDataGetNSig, "process data to Get Nsigma cuts", cfgRunDataGetNSig); + void processGetDataFlat(AodCollisionsSel::iterator const& coll, BCsRun3 const& /*bcs*/, aod::Zdcs const& /*zdcsData*/, AodTracksSel const& tracks) { histos.fill(HIST("hVtxZ"), coll.posZ()); @@ -2712,7 +3006,7 @@ struct RadialFlowDecorr { if (cent > KCentMax) return; - histos.fill(HIST("hZvtx_after_sel"), coll.posZ()); + histos.fill(HIST("hVtxZ_after_sel"), coll.posZ()); histos.fill(HIST("hCentrality"), cent); histos.fill(HIST("Hist2D_globalTracks_PVTracks"), coll.multNTracksPV(), tracks.size()); @@ -2733,85 +3027,23 @@ struct RadialFlowDecorr { if (eta > etaLw[0] && eta < etaUp[0]) ntrk++; - - if (sign > 0) { - // PiPlus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiPlus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiPlus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); - // KaPlus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaPlus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaPlus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); - // Pr - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_Pr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_Pr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); - } else if (sign < 0) { - // PiMinus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_PiMinus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_PiMinus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); - // KaMinus - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_KaMinus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_KaMinus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); - // AntiPr - histos.fill(HIST("h2DnsigmaTpcVsPtBeforeCut_AntiPr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtBeforeCut_AntiPr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofBeforeCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); - } - - bool isPi = selectionPion(track); - bool isKa = selectionKaon(track); - bool isPr = selectionProton(track); + fillNSigmaBefCut(track, cent); + int centBin = static_cast(cent); + int id = identifyTrack(track, centBin); + bool isPi = (id == KPidPionOne); + bool isKa = (id == KPidKaonTwo); + bool isPr = (id == KPidProtonThree); bool isSpecies[KNsp] = { - true, // kInclusiveIdx - isPi && sign < 0, // kPiMinusIdx - isPi && sign > 0, // kPiPlusIdx - isPi, // kPiAllIdx - isKa && sign < 0, // kKaMinusIdx - isKa && sign > 0, // kKaPlusIdx - isKa, // kKaAllIdx - isPr && sign < 0, // kAntiPrIdx (Negative) - isPr && sign > 0, // kPrIdx (Positive) - isPr // kAllPrIdx - }; - - if (isSpecies[kPiPlusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiPlus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiPlus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiPlus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); - } else if (isSpecies[kPiMinusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_PiMinus"), pt, track.tpcNSigmaPi()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_PiMinus"), pt, track.tofNSigmaPi()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_PiMinus"), track.tofNSigmaPi(), track.tpcNSigmaPi()); - } - - if (isSpecies[kKaPlusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaPlus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaPlus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaPlus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); - } else if (isSpecies[kKaMinusIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_KaMinus"), pt, track.tpcNSigmaKa()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_KaMinus"), pt, track.tofNSigmaKa()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_KaMinus"), track.tofNSigmaKa(), track.tpcNSigmaKa()); - } - - if (isSpecies[kPrIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_Pr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_Pr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_Pr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); - } else if (isSpecies[kAntiPrIdx]) { - histos.fill(HIST("h2DnsigmaTpcVsPtAfterCut_AntiPr"), pt, track.tpcNSigmaPr()); - histos.fill(HIST("h2DnsigmaTofVsPtAfterCut_AntiPr"), pt, track.tofNSigmaPr()); - histos.fill(HIST("h2DnsigmaTpcVsTofAfterCut_AntiPr"), track.tofNSigmaPr(), track.tpcNSigmaPr()); - } + true, + isPi && sign < 0, isPi && sign > 0, isPi, + isKa && sign < 0, isKa && sign > 0, isKa, + isPr && sign < 0, isPr && sign > 0, isPr}; for (int isp = 0; isp < KNsp; ++isp) { if (!isSpecies[isp]) continue; + fillNSigmaAftCut(track, cent, isSpecies); float eff = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); if (eff <= KFloatEpsilon) continue; @@ -2858,10 +3090,10 @@ struct RadialFlowDecorr { histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); - } else if (isp == kAllPrIdx) { - histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); + } else if (isp == kPrAllIdx) { + histos.fill(HIST("hEtaPhiReco_PrAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_PrAll"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_PrAll"), vz, sign, pt, eta, phi, w); } } } @@ -2893,7 +3125,7 @@ struct RadialFlowDecorr { if (cent > KCentMax) return; - histos.fill(HIST("hZvtx_after_sel"), coll.posZ()); + histos.fill(HIST("hVtxZ_after_sel"), coll.posZ()); histos.fill(HIST("hCentrality"), cent); histos.fill(HIST("Hist2D_globalTracks_PVTracks"), coll.multNTracksPV(), tracks.size()); @@ -2921,29 +3153,21 @@ struct RadialFlowDecorr { histos.fill(HIST("hPt"), pt); histos.fill(HIST("hEta"), eta); histos.fill(HIST("hPhi"), phi); + int centBin = static_cast(cent); + int id = identifyTrack(track, centBin); + bool isPi = (id == KPidPionOne); + bool isKa = (id == KPidKaonTwo); + bool isPr = (id == KPidProtonThree); - bool isPi = selectionPion(track); - bool isKa = selectionKaon(track); - bool isPr = selectionProton(track); - - // Updated to use the correct PIDIdx enum names bool isSpecies[KNsp] = { - true, // kInclusiveIdx - isPi && sign < 0, // kPiMinusIdx - isPi && sign > 0, // kPiPlusIdx - isPi, // kPiAllIdx - isKa && sign < 0, // kKaMinusIdx - isKa && sign > 0, // kKaPlusIdx - isKa, // kKaAllIdx - isPr && sign < 0, // kAntiPrIdx (Negative) - isPr && sign > 0, // kPrIdx (Positive) - isPr // kAllPrIdx - }; + true, + isPi && sign < 0, isPi && sign > 0, isPi, + isKa && sign < 0, isKa && sign > 0, isKa, + isPr && sign < 0, isPr && sign > 0, isPr}; for (int isp = 0; isp < KNsp; ++isp) { if (!isSpecies[isp]) continue; - float eff = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); // Safety check BEFORE dividing @@ -2993,10 +3217,10 @@ struct RadialFlowDecorr { histos.fill(HIST("hEtaPhiReco_AntiPr"), vz, sign, pt, eta, phi); histos.fill(HIST("hEtaPhiRecoEffWtd_AntiPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); histos.fill(HIST("hEtaPhiRecoWtd_AntiPr"), vz, sign, pt, eta, phi, w); - } else if (isp == kAllPrIdx) { - histos.fill(HIST("hEtaPhiReco_AllPr"), vz, sign, pt, eta, phi); - histos.fill(HIST("hEtaPhiRecoEffWtd_AllPr"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); - histos.fill(HIST("hEtaPhiRecoWtd_AllPr"), vz, sign, pt, eta, phi, w); + } else if (isp == kPrAllIdx) { + histos.fill(HIST("hEtaPhiReco_PrAll"), vz, sign, pt, eta, phi); + histos.fill(HIST("hEtaPhiRecoEffWtd_PrAll"), vz, sign, pt, eta, phi, (1.0f - fake) / eff); + histos.fill(HIST("hEtaPhiRecoWtd_PrAll"), vz, sign, pt, eta, phi, w); } for (int ieta = 0; ieta < KNEta; ++ieta) { @@ -3040,8 +3264,8 @@ struct RadialFlowDecorr { histos.fill(HIST("Prof2D_MeanpTSub_Pr"), cent, ietaA, ietaC, mptsub); else if (isp == kAntiPrIdx) histos.fill(HIST("Prof2D_MeanpTSub_AntiPr"), cent, ietaA, ietaC, mptsub); - else if (isp == kAllPrIdx) - histos.fill(HIST("Prof2D_MeanpTSub_AllPr"), cent, ietaA, ietaC, mptsub); + else if (isp == kPrAllIdx) + histos.fill(HIST("Prof2D_MeanpTSub_PrAll"), cent, ietaA, ietaC, mptsub); } if (ietaA == ietaC) { double mpt = sumWipti[isp][ietaA] / sumWi[isp][ietaA]; @@ -3130,29 +3354,21 @@ struct RadialFlowDecorr { if (pt <= cfgPtMin || pt > cfgPtMax) continue; + int centBin = static_cast(cent); + int id = identifyTrack(track, centBin); + bool isPi = (id == KPidPionOne); + bool isKa = (id == KPidKaonTwo); + bool isPr = (id == KPidProtonThree); - bool isPi = selectionPion(track); - bool isKa = selectionKaon(track); - bool isPr = selectionProton(track); - - // Updated to use the correct PIDIdx enum names bool isSpecies[KNsp] = { - true, // kInclusiveIdx - isPi && sign < 0, // kPiMinusIdx - isPi && sign > 0, // kPiPlusIdx - isPi, // kPiAllIdx - isKa && sign < 0, // kKaMinusIdx - isKa && sign > 0, // kKaPlusIdx - isKa, // kKaAllIdx - isPr && sign < 0, // kAntiPrIdx (Negative) - isPr && sign > 0, // kPrIdx (Positive) - isPr // kAllPrIdx - }; + true, + isPi && sign < 0, isPi && sign > 0, isPi, + isKa && sign < 0, isKa && sign > 0, isKa, + isPr && sign < 0, isPr && sign > 0, isPr}; for (int isp = 0; isp < KNsp; ++isp) { if (!isSpecies[isp]) continue; - float eff = getEfficiency(coll.multNTracksPV(), pt, eta, static_cast(isp), 0, cfgEff); // Safety check BEFORE dividing @@ -3375,17 +3591,17 @@ struct RadialFlowDecorr { histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0A); if (std::isfinite(covFT0C)) histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_AntiPr"), cent, etaValA, etaValB, covFT0C); - } else if (isp == kAllPrIdx) { + } else if (isp == kPrAllIdx) { if (std::isfinite(c2Sub)) { - histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, c2Sub); - histos.fill(HIST("Prof_GapSum2D_AllPr"), cent, gap, sum, c2Sub); + histos.fill(HIST("Prof_C2Sub2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, c2Sub); + histos.fill(HIST("Prof_GapSum2D_PrAll"), cent, gap, sum, c2Sub); } if (std::isfinite(cov)) - histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, cov); + histos.fill(HIST("Prof_Cov2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, cov); if (std::isfinite(covFT0A)) - histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0A); + histos.fill(HIST("Prof_CovFT0A2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, covFT0A); if (std::isfinite(covFT0C)) - histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_AllPr"), cent, etaValA, etaValB, covFT0C); + histos.fill(HIST("Prof_CovFT0C2D_Cent_etaA_etaC_PrAll"), cent, etaValA, etaValB, covFT0C); } } } From 6c6366be08c9cfa819c95b3777903c6ea8cc1f7e Mon Sep 17 00:00:00 2001 From: Somadutta Bhatta Date: Thu, 5 Mar 2026 01:08:40 +0100 Subject: [PATCH 5/6] fix clang issue --- PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx b/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx index b9671ee46db..1e9eebd21aa 100644 --- a/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx +++ b/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx @@ -425,7 +425,7 @@ struct RadialFlowDecorr { float sKaTof = pidMeanSigmaMap ? pidMeanSigmaMap->sigmaTOF[kaIdx][centBin] : 1.f; float mPrTof = pidMeanSigmaMap ? pidMeanSigmaMap->meanTOF[prIdx][centBin] : 0.f; float sPrTof = pidMeanSigmaMap ? pidMeanSigmaMap->sigmaTOF[prIdx][centBin] : 1.f; - //Fetch Raw nSigma Values + // Fetch Raw nSigma Values float rawTpcPi = candidate.tpcNSigmaPi(); float rawTpcKa = candidate.tpcNSigmaKa(); float rawTpcPr = candidate.tpcNSigmaPr(); From d4f9d85f1ea18f39f982215dd020ae1f35b6fb2a Mon Sep 17 00:00:00 2001 From: Somadutta Bhatta Date: Thu, 5 Mar 2026 07:49:53 +0100 Subject: [PATCH 6/6] fixing o2 c++ error --- PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx b/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx index 1e9eebd21aa..33b16fb7c06 100644 --- a/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx +++ b/PWGCF/EbyEFluctuations/Tasks/radialFlowDecorr.cxx @@ -231,7 +231,7 @@ struct RadialFlowDecorr { const AxisSpec etaAxis{{-0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}, "Eta"}; const AxisSpec phiAxis{KNbinsPhi, KPhiMin, TwoPI, "#phi"}; const AxisSpec etaBinAxis{KNEta + 1, -0.5, KNEta + 0.5, "#eta bin Number"}; - const AxisSpec spBinAxis{KNsp + 1, -KBinOffset, KNsp + KBinOffset, "species index Number"}; + const AxisSpec spBinAxis{KNsp + 1, -KBinOffset, static_cast(KNsp) + KBinOffset, "species index Number"}; const AxisSpec gapAxis{{-1.55, -1.45, -1.35, -1.25, -1.15, -1.05, -0.95, -0.85, -0.75, -0.65, -0.55, -0.45, -0.35, -0.25, -0.15, -0.05,