diff --git a/PWGCF/EbyEFluctuations/Tasks/multAndPtFluctuations.cxx b/PWGCF/EbyEFluctuations/Tasks/multAndPtFluctuations.cxx index 2032d0e252a..76b2768eaf8 100644 --- a/PWGCF/EbyEFluctuations/Tasks/multAndPtFluctuations.cxx +++ b/PWGCF/EbyEFluctuations/Tasks/multAndPtFluctuations.cxx @@ -15,218 +15,1011 @@ #include "Common/CCDB/EventSelectionParams.h" #include "Common/DataModel/Centrality.h" #include "Common/DataModel/EventSelection.h" +#include "Common/DataModel/Multiplicity.h" #include "Common/DataModel/TrackSelectionTables.h" #include +#include #include #include #include #include #include +#include #include #include -#include +#include +#include +#include + +#include +#include #include using namespace o2; using namespace o2::framework; -using namespace o2::aod; using namespace o2::framework::expressions; +using namespace std; +using namespace o2::constants::physics; -struct MultAndPtFluctuations { +using namespace o2; +using namespace o2::framework; +using namespace o2::framework::expressions; - // ------ Histogram binning +struct MultAndPtFluctuations { + static constexpr float CentMin = 0.f; + static constexpr float Cent10 = 10.f; + static constexpr float CentMax = 100.f; + // PDG charge tolerance + static constexpr double ChargeTolerance = 1.e-6; - Configurable nBinsPt{"nBinsPt", 100, "pT bins"}; - Configurable ndcaXY{"ndcaXY", 100, "DCAxy bins"}; - Configurable ndcaZ{"ndcaZ", 100, "DCAz bins"}; - Configurable nCentBins{"nCentBins", 100, "Number of centrality bins"}; + Service pdgService{}; - // ------ Event Cuts - Configurable vtxZcut{"vtxZcut", 10.0f, "vertex Z"}; - Configurable cfgNoSameBunchPileup{"cfgNoSameBunchPileup", true, "kNoSameBunchPileup"}; - Configurable cfgEvSelUseGoodZvtxFT0vsPV{"cfgEvSelUseGoodZvtxFT0vsPV", true, "Good Zvtx FT0 vs PV"}; - Configurable cfgUseGoodITSLayerAllCut{"cfgUseGoodITSLayerAllCut", true, "Good ITS Layers"}; + // -------------------------------------------------- + // Configurables + // -------------------------------------------------- - // ----- Centrality estimator - Configurable cFT0M{"cFT0M", false, "FT0M centrality"}; // for pp + Configurable cFT0M{"cFT0M", false, "Use FT0M centrality"}; Configurable cFT0C{"cFT0C", true, "Use FT0C centrality"}; - // ------ Track cuts + Configurable vertexZcut{"vertexZcut", 10.f, "Vertex Z cut"}; + Configurable cSel8Trig{"cSel8Trig", true, "Require sel8"}; + + Configurable cPileupReject{"cPileupReject", false, "Reject same-bunch pileup"}; + Configurable cfgUseGoodItsLayerAllCut{"cfgUseGoodItsLayerAllCut", false, "Require good ITS layers"}; + Configurable cTFBorder{"cTFBorder", false, "Reject timeframe border"}; + Configurable cNoItsROBorder{"cNoItsROBorder", false, "Reject ITS readout-frame border"}; + Configurable cItsTpcVtx{"cItsTpcVtx", false, "Require ITS-TPC vertex"}; + Configurable cZVtxTimeDiff{"cZVtxTimeDiff", false, "Require good FT0-PV vertex difference"}; + + Configurable etaCut{"etaCut", 0.8f, "Pseudorapidity cut"}; Configurable ptMinCut{"ptMinCut", 0.2f, "Minimum pT"}; - Configurable ptMaxCut{"ptMaxCut", 5.0f, "Maximum pT"}; - Configurable etaCut{"etaCut", 0.8f, "Maximum |eta|"}; - Configurable itsNClsCut{"itsNClsCut", 4, "Minimum ITS clusters"}; - Configurable tpcCrossCut{"tpcCrossCut", 70.0f, "TPC crossed rows"}; - Configurable crossedRowsOverFindableCut{"crossedRowsOverFindableCut", 0.8f, "TPC crossed rows over findable"}; - Configurable dcaZCut{"dcaZCut", 2.0f, "Maximum DCAz"}; - Configurable dcaXYCut{"dcaXYCut", 0.2f, "Maximum DCAxy"}; - Configurable tpcChiCut{"tpcChiCut", 4.0f, "TPC chi2/NCls"}; - Configurable itsChiCut{"itsChiCut", 36.0f, "ITS chi2/NCls"}; - Configurable requireITS{"requireITS", true, "Require ITS hit"}; - Configurable requireTPC{"requireTPC", true, "Require TPC hit"}; - Configurable requireInnerITS{"requireInnerITS", true, "At least one hit in ITS layers 0,1,2"}; - - //----- Histogram Registry - HistogramRegistry histos{"histos", {}, OutputObjHandlingPolicy::AnalysisObject}; + Configurable ptMaxCut{"ptMaxCut", 5.f, "Maximum pT"}; + + Configurable dcaXYCut{"dcaXYCut", 0.2f, "DCAxy cut"}; + Configurable dcaZCut{"dcaZCut", 2.f, "DCAz cut"}; + Configurable tpcCrossCut{"tpcCrossCut", 70.f, "Minimum TPC crossed rows"}; + Configurable itsChiCut{"itsChiCut", 36.f, "Maximum ITS chi2 per cluster"}; + Configurable tpcChiCut{"tpcChiCut", 4.f, "Maximum TPC chi2 per cluster"}; + + Configurable cPVcont{"cPVcont", false, "Require primary vertex contributor"}; + Configurable cDcaXy{"cDcaXy", true, "Apply DCAxy cut"}; + Configurable cDcaZ{"cDcaZ", true, "Apply DCAz cut"}; + Configurable cTpcCr{"cTpcCr", true, "Apply TPC crossed-rows cut"}; + Configurable cItsChi{"cItsChi", true, "Apply ITS chi2 cut"}; + Configurable cTpcChi{"cTpcChi", true, "Apply TPC chi2 cut"}; + + Configurable cfgNSubsample{"cfgNSubsample", 30, "Number of subsamples"}; + + ConfigurableAxis centBining{"centBining", {0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100}, "Custom centrality binning"}; + + Configurable nCentBins{"nCentBins", 100, "Number of standard centrality bins"}; + + Configurable cfgEvSelMultCorrelation{"cfgEvSelMultCorrelation", true, "Enable multiplicity-correlation rejection"}; + + // -------------------------------------------------- + // Multiplicity-correlation cut configurables + // -------------------------------------------------- + + struct : ConfigurableGroup { + + Configurable cfgMultPVT0CCutEnabled{"cfgMultPVT0CCutEnabled", true, "Enable PV multiplicity vs FT0C cut"}; + + Configurable cfgMultGlobalFT0CCutEnabled{"cfgMultGlobalFT0CCutEnabled", true, "Enable global tracks vs FT0C cut"}; + + Configurable cfgMultGlobalPVCutEnabled{"cfgMultGlobalPVCutEnabled", true, "Enable global tracks vs PV multiplicity cut"}; + + Configurable cfgMultCutNSigma{"cfgMultCutNSigma", 3.5f, "Number of sigma for multiplicity-correlation cuts"}; + + Configurable> cfgMultPVT0CCutPars{"cfgMultPVT0CCutPars", std::vector{30.434, -0.917137, 0.0185032, -0.000198425, 7.94381e-07, 13.7406, -0.282656, 0.00556147, -6.32766e-05, 2.51648e-07}, "PV multiplicity vs FT0C cut parameters"}; + + Configurable> cfgMultGlobalFT0CCutPars{"cfgMultGlobalFT0CCutPars", std::vector{18.9628, -0.576466, 0.0117324, -0.000126086, 5.05365e-07, 8.99921, -0.188022, 0.0037089, -4.20275e-05, 1.68234e-07}, "Global tracks vs FT0C cut parameters"}; + + Configurable> cfgMultGlobalPVCutPars{"cfgMultGlobalPVCutPars", std::vector{0.148031, 0.616699, 0.603083, 0.112751, -0.0013846, 8.38211e-06}, "Global tracks vs PV multiplicity cut parameters"}; + + std::vector multPVT0CCutPars; + std::vector multGlobalFT0CPars; + std::vector multGlobalPVCutPars; + + TF1* fMultPVT0CCutLow = nullptr; + TF1* fMultPVT0CCutHigh = nullptr; + + TF1* fMultGlobalFT0CCutLow = nullptr; + TF1* fMultGlobalFT0CCutHigh = nullptr; + + TF1* fMultGlobalPVCutLow = nullptr; + TF1* fMultGlobalPVCutHigh = nullptr; + + } cfgFunCoeff; + + // ---------------Filters and table definitions + Filter trackFilter = (nabs(aod::track::eta) < etaCut) && (aod::track::pt > ptMinCut) && (aod::track::pt < ptMaxCut) && requireGlobalTrackInFilter(); + + using MyCollisions = soa::Join; + using MyCollision = MyCollisions::iterator; + + using MyTracks = soa::Filtered>; + + using MyMCCollisions = soa::Join; + using MyMCCollision = MyMCCollisions::iterator; + + using MyMCTracks = soa::Filtered>; + using MyMCTrack = MyMCTracks::iterator; + + // -----------------Histogram registry + HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject}; + + // ------------------Initialization void init(InitContext const&) { - const AxisSpec axisEta{30, -1.5, +1.5, "#eta"}; - const AxisSpec axisPt{nBinsPt, 0.15, 10.0, "p_{T}"}; - const AxisSpec axisVtxz{80, -20, 20, "V_{Z} (cm)"}; - const AxisSpec axisPhi{40, -1, 7, "#phi"}; - const AxisSpec axisdcaXY{ndcaXY, -0.3, 0.3, "DCAxy"}; - const AxisSpec axisdcaZ{ndcaZ, -3.0, 3.0, "DCAz"}; - const AxisSpec axisNch{500, 0, 500, "Nch"}; - const AxisSpec axisCent{nCentBins, 0.0, 100.0, "Centrality (%)"}; // ------------- centrality bins - histos.add("QA/BeforeCut/VtxZ", "Vertex Z", kTH1F, {axisVtxz}); - histos.add("QA/AfterCut/VtxZ", "Vertex Z", kTH1F, {axisVtxz}); - histos.add("QA/BeforeCut/Cent", "Centrality", kTH1F, {axisCent}); - histos.add("QA/AfterCut/Cent", "Centrality", kTH1F, {axisCent}); - histos.add("QA/BeforeCut/Eta", "Eta", kTH1F, {axisEta}); - histos.add("QA/AfterCut/Eta", "Eta", kTH1F, {axisEta}); - histos.add("QA/BeforeCut/Pt", "Pt", kTH1F, {axisPt}); - histos.add("QA/AfterCut/Pt", "Pt", kTH1F, {axisPt}); - histos.add("QA/BeforeCut/Phi", "Phi", kTH1F, {axisPhi}); - histos.add("QA/AfterCut/Phi", "Phi", kTH1F, {axisPhi}); - histos.add("QA/BeforeCut/DcaXY", "DCAxy", kTH1F, {axisdcaXY}); - histos.add("QA/AfterCut/DcaXY", "DCAxy", kTH1F, {axisdcaXY}); - histos.add("QA/BeforeCut/DcaZ", "DCAz", kTH1F, {axisdcaZ}); - histos.add("QA/AfterCut/DcaZ", "DCAz", kTH1F, {axisdcaZ}); - histos.add("hNch", "Nch", kTH1F, {axisNch}); - histos.add("h2_DcaZ", "DCA_{Z}", kTH2D, {{axisPt}, {axisdcaZ}}); - histos.add("h2_DcaXY", "DCA_{XY}", kTH2D, {{axisPt}, {axisdcaXY}}); - histos.add("hEventCounter", "Number of events vs centrality", kTH1F, {axisCent}); - histos.add("p_a", " vs centrality", kTProfile, {axisCent}); - histos.add("p_b", " vs centrality", kTProfile, {axisCent}); - histos.add("p_a2", " vs centrality", kTProfile, {axisCent}); - histos.add("p_b2", " vs centrality", kTProfile, {axisCent}); - histos.add("p_ab", " vs centrality", kTProfile, {axisCent}); - histos.add("p_asumb", " vs centrality", kTProfile, {axisCent}); - } + const AxisSpec vtxzAxis{800, -20., 20., "V_{Z} (cm)"}; + const AxisSpec dcaAxis{1000, -0.5, 0.5, "DCA_{xy} (cm)"}; + const AxisSpec dcazAxis{600, -3., 3., "DCA_{z} (cm)"}; + const AxisSpec phiAxis{70, 0., 7., "#phi"}; + const AxisSpec ptAxis{70, 0., 7., "#it{p}_{T} (GeV/#it{c})"}; + const AxisSpec etaAxis{20, -1., 1., "#eta"}; + const AxisSpec centAxis{100, 0., 100., "Centrality (%)"}; + const AxisSpec axisCent{nCentBins, 0., 100., "Centrality (%)"}; + const AxisSpec cent1Axis{centBining, "Centrality (%)"}; + const AxisSpec axisNch{2000, 0., 2000., "N_{ch}"}; + const AxisSpec tpcChiAxis{700, 0., 7., "TPC #chi^{2}/N_{cls}"}; + const AxisSpec itsChiAxis{400, 0., 40., "ITS #chi^{2}/N_{cls}"}; + const AxisSpec crossedRowAxis{1600, 0., 160., "TPC crossed rows"}; + + const int nSub = std::max(1, static_cast(cfgNSubsample)); + const AxisSpec subsampleAxis{nSub, 0., static_cast(nSub), "Subsample"}; + + // -----------Track QA: before manual track selection----------- + histos.add("QA/Before/VtxZ", "Vertex Z before event selection", kTH1F, {vtxzAxis}); + histos.add("QA/Before/DcaXY", "DCAxy before track selection", kTH1F, {dcaAxis}); + histos.add("QA/Before/DcaZ", "DCAz before track selection", kTH1F, {dcazAxis}); + histos.add("QA/Before/TPCchi2perCluster", "TPC chi2 before track selection", kTH1D, {tpcChiAxis}); + histos.add("QA/Before/ITSchi2perCluster", "ITS chi2 before track selection", kTH1D, {itsChiAxis}); + histos.add("QA/Before/TPCCrossedrows", "TPC crossed rows before track selection", kTH1D, {crossedRowAxis}); + histos.add("QA/Before/PtDcaXY_before", "pT vs DCAxy before track selection", kTH2D, {ptAxis, dcaAxis}); + histos.add("QA/Before/PtDcaZ_before", "pT vs DCAz before track selection", kTH2D, {ptAxis, dcazAxis}); + + // ----------Track QA: after manual track selection------------- + histos.add("QA/phi", "Azimuthal angle", kTH1F, {phiAxis}); + + histos.add("QA/After/VtxZ", "Vertex Z after event selection", kTH1F, {vtxzAxis}); + histos.add("QA/After/DcaXY", "DCAxy after track selection", kTH1F, {dcaAxis}); + histos.add("QA/After/DcaZ", "DCAz after track selection", kTH1F, {dcazAxis}); + histos.add("QA/After/TPCchi2perCluster", "TPC chi2 after track selection", kTH1D, {tpcChiAxis}); + histos.add("QA/After/ITSchi2perCluster", "ITS chi2 after track selection", kTH1D, {itsChiAxis}); + histos.add("QA/After/TPCCrossedrows", "TPC crossed rows after track selection", kTH1D, {crossedRowAxis}); + histos.add("QA/After/PtDcaXY", "pT vs DCAxy after track selection", kTH2D, {ptAxis, dcaAxis}); + histos.add("QA/After/PtDcaZ", "pT vs DCAz after track selection", kTH2D, {ptAxis, dcazAxis}); + + histos.add("QA/After/Eta", "Eta after track selection", kTH1F, {etaAxis}); + histos.add("QA/After/Pt", "pT after track selection", kTH1F, {ptAxis}); + histos.add("QA/After/Pt_eta", "pT vs eta", kTH2F, {ptAxis, etaAxis}); + histos.add("QA/After/cent_hEta", "Centrality vs eta", kTH2F, {cent1Axis, etaAxis}); + histos.add("QA/After/cent_hPt", "Centrality vs pT", kTH2F, {cent1Axis, ptAxis}); + histos.add("QA/After/Centrality", "Accepted-event centrality", kTH1F, {centAxis}); + histos.add("QA/After/Multiplicity", "Global track multiplicity", kTH1F, {axisNch}); + + // ------------------------------------------------ + // Nch histograms + // ------------------------------------------------ + + histos.add("Nch/hNch", "Event-wise Nch", kTH1F, {axisNch}); + histos.add("Nch/hNch_0_10", "Nch (0-10%)", kTH1F, {axisNch}); + histos.add("Nch/hNch_10_20", "Nch (10-20%)", kTH1F, {axisNch}); + histos.add("Nch/hNch_20_30", "Nch (20-30%)", kTH1F, {axisNch}); + histos.add("Nch/hNch_30_40", "Nch (30-40%)", kTH1F, {axisNch}); + histos.add("Nch/hNch_40_50", "Nch (40-50%)", kTH1F, {axisNch}); + histos.add("Nch/hNch_50_60", "Nch (50-60%)", kTH1F, {axisNch}); + histos.add("Nch/hNch_60_70", "Nch (60-70%)", kTH1F, {axisNch}); + histos.add("Nch/hNch_70_80", "Nch (70-80%)", kTH1F, {axisNch}); + histos.add("Nch/hNch_80_90", "Nch (80-90%)", kTH1F, {axisNch}); + histos.add("Nch/hNch_90_100", "Nch (90-100%)", kTH1F, {axisNch}); + + // ------------------------------------------------ + // Multiplicity QA and correlation plots + // ------------------------------------------------ + + histos.add("QA/hCentFT0C", "Centrality", kTH1F, {centAxis}); + histos.add("QA/hNchGlobal", "Global track multiplicity", kTH1F, {axisNch}); + histos.add("QA/hNchPV", "PV track multiplicity", kTH1F, {axisNch}); + + histos.add("MultCorrelationPlots/globalTracks_PV_bef", "PV tracks (x) vs global tracks (y) before rejection", kTH2D, {axisNch, axisNch}); + histos.add("MultCorrelationPlots/globalTracks_FT0C_bef", "FT0C centrality (x) vs global tracks (y) before rejection", kTH2D, {centAxis, axisNch}); + histos.add("MultCorrelationPlots/PV_FT0C_bef", "FT0C centrality (x) vs PV tracks (y) before rejection", kTH2D, {centAxis, axisNch}); + + histos.add("MultCorrelationPlots/globalTracks_PV_aft", "PV tracks (x) vs global tracks (y) after rejection", kTH2D, {axisNch, axisNch}); + histos.add("MultCorrelationPlots/globalTracks_FT0C_aft", "FT0C centrality (x) vs global tracks (y) after rejection", kTH2D, {centAxis, axisNch}); + histos.add("MultCorrelationPlots/PV_FT0C_aft", "FT0C centrality (x) vs PV tracks (y) after rejection", kTH2D, {centAxis, axisNch}); + + // ------------------------------------------------ + // DATA profiles + // ------------------------------------------------ + + histos.add("Data/p_a", " vs centrality", kTProfile, {axisCent}); + histos.add("Data/p_b", " vs centrality", kTProfile, {axisCent}); + histos.add("Data/p_a2", " vs centrality", kTProfile, {axisCent}); + histos.add("Data/p_b2", " vs centrality", kTProfile, {axisCent}); + histos.add("Data/p_ab", " vs centrality", kTProfile, {axisCent}); + histos.add("Data/p_asumb", " vs centrality", kTProfile, {axisCent}); + + histos.add("Data/p_a_custom", " vs custom centrality", kTProfile, {cent1Axis}); + histos.add("Data/p_b_custom", " vs custom centrality", kTProfile, {cent1Axis}); + histos.add("Data/p_a2_custom", " vs custom centrality", kTProfile, {cent1Axis}); + histos.add("Data/p_b2_custom", " vs custom centrality", kTProfile, {cent1Axis}); + histos.add("Data/p_ab_custom", " vs custom centrality", kTProfile, {cent1Axis}); + histos.add("Data/p_asumb_custom", " vs custom centrality", kTProfile, {cent1Axis}); + + // DATA standard subsample profiles + histos.add("Data/subsample/p_a", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + histos.add("Data/subsample/p_b", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + histos.add("Data/subsample/p_a2", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + histos.add("Data/subsample/p_b2", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + histos.add("Data/subsample/p_ab", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + histos.add("Data/subsample/p_asumb", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + + // DATA custom subsample profiles + histos.add("Data/subsample/p_a_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + histos.add("Data/subsample/p_b_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + histos.add("Data/subsample/p_a2_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + histos.add("Data/subsample/p_b2_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + histos.add("Data/subsample/p_ab_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + histos.add("Data/subsample/p_asumb_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + + // ------------------------------------------------ + // MC RECONSTRUCTED profiles + // ------------------------------------------------ + + histos.add("MCRec/p_a", " vs centrality", kTProfile, {axisCent}); + histos.add("MCRec/p_b", " vs centrality", kTProfile, {axisCent}); + histos.add("MCRec/p_a2", " vs centrality", kTProfile, {axisCent}); + histos.add("MCRec/p_b2", " vs centrality", kTProfile, {axisCent}); + histos.add("MCRec/p_ab", " vs centrality", kTProfile, {axisCent}); + histos.add("MCRec/p_asumb", " vs centrality", kTProfile, {axisCent}); + + histos.add("MCRec/p_a_custom", " vs custom centrality", kTProfile, {cent1Axis}); + histos.add("MCRec/p_b_custom", " vs custom centrality", kTProfile, {cent1Axis}); + histos.add("MCRec/p_a2_custom", " vs custom centrality", kTProfile, {cent1Axis}); + histos.add("MCRec/p_b2_custom", " vs custom centrality", kTProfile, {cent1Axis}); + histos.add("MCRec/p_ab_custom", " vs custom centrality", kTProfile, {cent1Axis}); + histos.add("MCRec/p_asumb_custom", " vs custom centrality", kTProfile, {cent1Axis}); + + // MC reconstructed inclusive pT moments + histos.add("MCRec/pT_inclusive", " vs centrality", kTProfile, {axisCent}); + histos.add("MCRec/pT2_inclusive", " vs centrality", kTProfile, {axisCent}); + + // MC reconstructed standard subsample profiles + histos.add("MCRec/subsample/p_a", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + histos.add("MCRec/subsample/p_b", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + histos.add("MCRec/subsample/p_a2", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + histos.add("MCRec/subsample/p_b2", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + histos.add("MCRec/subsample/p_ab", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + histos.add("MCRec/subsample/p_asumb", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + + // MC reconstructed custom subsample profiles + histos.add("MCRec/subsample/p_a_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + histos.add("MCRec/subsample/p_b_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + histos.add("MCRec/subsample/p_a2_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + histos.add("MCRec/subsample/p_b2_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + histos.add("MCRec/subsample/p_ab_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + histos.add("MCRec/subsample/p_asumb_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + + // ------------------------------------------------ + // MC GENERATED profiles + // ------------------------------------------------ + + histos.add("MCGen/p_a", " vs centrality", kTProfile, {axisCent}); + histos.add("MCGen/p_b", " vs centrality", kTProfile, {axisCent}); + histos.add("MCGen/p_a2", " vs centrality", kTProfile, {axisCent}); + histos.add("MCGen/p_b2", " vs centrality", kTProfile, {axisCent}); + histos.add("MCGen/p_ab", " vs centrality", kTProfile, {axisCent}); + histos.add("MCGen/p_asumb", " vs centrality", kTProfile, {axisCent}); + + histos.add("MCGen/p_a_custom", " vs custom centrality", kTProfile, {cent1Axis}); + histos.add("MCGen/p_b_custom", " vs custom centrality", kTProfile, {cent1Axis}); + histos.add("MCGen/p_a2_custom", " vs custom centrality", kTProfile, {cent1Axis}); + histos.add("MCGen/p_b2_custom", " vs custom centrality", kTProfile, {cent1Axis}); + histos.add("MCGen/p_ab_custom", " vs custom centrality", kTProfile, {cent1Axis}); + histos.add("MCGen/p_asumb_custom", " vs custom centrality", kTProfile, {cent1Axis}); + + // MC generated inclusive pT moments + histos.add("MCGen/pT_inclusive", " vs centrality", kTProfile, {axisCent}); + histos.add("MCGen/pT2_inclusive", " vs centrality", kTProfile, {axisCent}); + + // MC generated standard subsample profiles + histos.add("MCGen/subsample/p_a", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + histos.add("MCGen/subsample/p_b", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + histos.add("MCGen/subsample/p_a2", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + histos.add("MCGen/subsample/p_b2", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + histos.add("MCGen/subsample/p_ab", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); + histos.add("MCGen/subsample/p_asumb", " vs centrality and subsample", kTProfile2D, {axisCent, subsampleAxis}); - //---------- Filters - Filter ptFilter = (aod::track::pt > ptMinCut) && (aod::track::pt < ptMaxCut); - Filter etaFilter = nabs(aod::track::eta) < etaCut; - Filter posZFilter = nabs(aod::collision::posZ) < vtxZcut; + // MC generated custom subsample profiles + histos.add("MCGen/subsample/p_a_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + histos.add("MCGen/subsample/p_b_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + histos.add("MCGen/subsample/p_a2_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + histos.add("MCGen/subsample/p_b2_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + histos.add("MCGen/subsample/p_ab_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); + histos.add("MCGen/subsample/p_asumb_custom", " vs custom centrality and subsample", kTProfile2D, {cent1Axis, subsampleAxis}); - using MyColsData = soa::Join; - using MyTracksData = soa::Join; - using MyFilteredTracksData = soa::Filtered; + // MC reconstructed QA: vertex and track kinematics + histos.add("MCRec/QA/Before/VtxZ", "Reconstructed MC vertex Z before event selection", kTH1F, {vtxzAxis}); + histos.add("MCRec/QA/After/VtxZ", "Reconstructed MC vertex Z after event selection", kTH1F, {vtxzAxis}); + histos.add("MCRec/QA/Before/Pt", "Reconstructed track pT before manual track selection", kTH1F, {ptAxis}); + histos.add("MCRec/QA/Before/Eta", "Reconstructed track eta before manual track selection", kTH1F, {etaAxis}); + histos.add("MCRec/QA/Before/PtEta", "Reconstructed track pT vs eta before manual track selection", kTH2D, {ptAxis, etaAxis}); + histos.add("MCRec/QA/After/Pt", "Reconstructed track pT after manual track selection", kTH1F, {ptAxis}); + histos.add("MCRec/QA/After/Eta", "Reconstructed track eta after manual track selection", kTH1F, {etaAxis}); + histos.add("MCRec/QA/After/PtEta", "Reconstructed track pT vs eta after manual track selection", kTH2D, {ptAxis, etaAxis}); + histos.add("MCRec/QA/Centrality", "Reconstructed MC centrality", kTH1F, {centAxis}); + histos.add("MCRec/QA/GlobalNch", "Reconstructed MC global-track multiplicity", kTH1F, {axisNch}); + histos.add("MCRec/QA/PVNch", "Reconstructed MC PV-track multiplicity", kTH1F, {axisNch}); - void process(MyColsData::iterator const& col, MyFilteredTracksData const& tracks) + // MC reconstructed multiplicity correlations + histos.add("MCRec/MultCorrelationPlots/globalTracks_PV_bef", "PV tracks (x) vs global tracks (y) before rejection", kTH2D, {axisNch, axisNch}); + histos.add("MCRec/MultCorrelationPlots/globalTracks_FT0C_bef", "FT0C centrality (x) vs global tracks (y) before rejection", kTH2D, {centAxis, axisNch}); + histos.add("MCRec/MultCorrelationPlots/PV_FT0C_bef", "FT0C centrality (x) vs PV tracks (y) before rejection", kTH2D, {centAxis, axisNch}); + histos.add("MCRec/MultCorrelationPlots/globalTracks_PV_aft", "PV tracks (x) vs global tracks (y) after rejection", kTH2D, {axisNch, axisNch}); + histos.add("MCRec/MultCorrelationPlots/globalTracks_FT0C_aft", "FT0C centrality (x) vs global tracks (y) after rejection", kTH2D, {centAxis, axisNch}); + histos.add("MCRec/MultCorrelationPlots/PV_FT0C_aft", "FT0C centrality (x) vs PV tracks (y) after rejection", kTH2D, {centAxis, axisNch}); + + // MC generated QA: collision vertex and particle kinematics + histos.add("MCGen/QA/Before/VtxZ", "Generated MC vertex Z before vertex selection", kTH1F, {vtxzAxis}); + histos.add("MCGen/QA/After/VtxZ", "Generated MC vertex Z after vertex selection", kTH1F, {vtxzAxis}); + histos.add("MCGen/QA/Before/Pt", "Generated-particle pT before particle selection", kTH1F, {ptAxis}); + histos.add("MCGen/QA/Before/Eta", "Generated-particle eta before particle selection", kTH1F, {etaAxis}); + histos.add("MCGen/QA/Before/PtEta", "Generated-particle pT vs eta before particle selection", kTH2D, {ptAxis, etaAxis}); + histos.add("MCGen/QA/After/Pt", "Generated-particle pT after particle selection", kTH1F, {ptAxis}); + histos.add("MCGen/QA/After/Eta", "Generated-particle eta after particle selection", kTH1F, {etaAxis}); + histos.add("MCGen/QA/After/PtEta", "Generated-particle pT vs eta after particle selection", kTH2D, {ptAxis, etaAxis}); + histos.add("MCGen/QA/GeneratedNch", "Generated charged-particle multiplicity", kTH1F, {axisNch}); + histos.add("MCGen/QA/Centrality", "Reconstructed centrality for generated MC sample", kTH1F, {centAxis}); + histos.add("MCGen/QA/GlobalNch", "Reconstructed global-track multiplicity for generated MC sample", kTH1F, {axisNch}); + histos.add("MCGen/QA/PVNch", "Reconstructed PV-track multiplicity for generated MC sample", kTH1F, {axisNch}); + + // ------------------------------------------------ + // Initialize multiplicity-correlation functions + // ------------------------------------------------ + + const float nSigma = cfgFunCoeff.cfgMultCutNSigma; + + cfgFunCoeff.multPVT0CCutPars = cfgFunCoeff.cfgMultPVT0CCutPars; + cfgFunCoeff.multGlobalFT0CPars = cfgFunCoeff.cfgMultGlobalFT0CCutPars; + cfgFunCoeff.multGlobalPVCutPars = cfgFunCoeff.cfgMultGlobalPVCutPars; + + cfgFunCoeff.fMultPVT0CCutLow = new TF1( + "fMultPVT0CCutLow", + Form("[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x-%f*([5]+[6]*x+[7]*x*x+[8]*x*x*x+[9]*x*x*x*x)", nSigma), + 0., 100.); + cfgFunCoeff.fMultPVT0CCutLow->SetParameters(cfgFunCoeff.multPVT0CCutPars.data()); + + cfgFunCoeff.fMultPVT0CCutHigh = new TF1( + "fMultPVT0CCutHigh", + Form("[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+%f*([5]+[6]*x+[7]*x*x+[8]*x*x*x+[9]*x*x*x*x)", nSigma), + 0., 100.); + cfgFunCoeff.fMultPVT0CCutHigh->SetParameters(cfgFunCoeff.multPVT0CCutPars.data()); + + cfgFunCoeff.fMultGlobalFT0CCutLow = new TF1( + "fMultGlobalFT0CCutLow", + Form("[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x-%f*([5]+[6]*x+[7]*x*x+[8]*x*x*x+[9]*x*x*x*x)", nSigma), + 0., 100.); + cfgFunCoeff.fMultGlobalFT0CCutLow->SetParameters(cfgFunCoeff.multGlobalFT0CPars.data()); + + cfgFunCoeff.fMultGlobalFT0CCutHigh = new TF1( + "fMultGlobalFT0CCutHigh", + Form("[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+%f*([5]+[6]*x+[7]*x*x+[8]*x*x*x+[9]*x*x*x*x)", nSigma), + 0., 100.); + cfgFunCoeff.fMultGlobalFT0CCutHigh->SetParameters(cfgFunCoeff.multGlobalFT0CPars.data()); + + cfgFunCoeff.fMultGlobalPVCutLow = new TF1( + "fMultGlobalPVCutLow", + Form("[0]+[1]*x-%f*([2]+[3]*x+[4]*x*x+[5]*x*x*x)", nSigma), + 0., 100000.); + cfgFunCoeff.fMultGlobalPVCutLow->SetParameters(cfgFunCoeff.multGlobalPVCutPars.data()); + + cfgFunCoeff.fMultGlobalPVCutHigh = new TF1( + "fMultGlobalPVCutHigh", + Form("[0]+[1]*x+%f*([2]+[3]*x+[4]*x*x+[5]*x*x*x)", nSigma), + 0., 100000.); + cfgFunCoeff.fMultGlobalPVCutHigh->SetParameters(cfgFunCoeff.multGlobalPVCutPars.data()); + } + + // -------------------------------------------------- + // Event selection + // -------------------------------------------------- + + template + bool selCollision(C const& coll, float& cent) { - histos.fill(HIST("QA/BeforeCut/VtxZ"), col.posZ()); - float cent = -1.0f; + cent = -1.f; + if (cFT0M) { - cent = col.centFT0M(); + cent = coll.centFT0M(); + } else if (cFT0C) { + cent = coll.centFT0C(); + } else { + return false; } - if (cFT0C) { - cent = col.centFT0C(); - // if (!track.isGlobalTrack()) continue; + + if (cent < CentMin || cent >= CentMax) { + return false; } - if (cent < 0) { - return; + + if (std::abs(coll.posZ()) >= vertexZcut) { + return false; } - histos.fill(HIST("QA/BeforeCut/Cent"), cent); - if (!col.sel8()) { - return; + if (cSel8Trig && !coll.sel8()) { + return false; } - if (std::abs(col.posZ()) > vtxZcut) { - return; + + if (cNoItsROBorder && + !coll.selection_bit(aod::evsel::kNoITSROFrameBorder)) { + return false; } - if (cfgNoSameBunchPileup && !col.selection_bit(o2::aod::evsel::kNoSameBunchPileup)) { - return; + + if (cTFBorder && + !coll.selection_bit(aod::evsel::kNoTimeFrameBorder)) { + return false; } - if (cfgEvSelUseGoodZvtxFT0vsPV && !col.selection_bit(o2::aod::evsel::kIsGoodZvtxFT0vsPV)) { - return; + + if (cPileupReject && + !coll.selection_bit(aod::evsel::kNoSameBunchPileup)) { + return false; } - if (cfgUseGoodITSLayerAllCut && !col.selection_bit(o2::aod::evsel::kIsGoodITSLayersAll)) { - return; + + if (cZVtxTimeDiff && + !coll.selection_bit(aod::evsel::kIsGoodZvtxFT0vsPV)) { + return false; } - histos.fill(HIST("hEventCounter"), cent); - histos.fill(HIST("QA/AfterCut/VtxZ"), col.posZ()); - histos.fill(HIST("QA/AfterCut/Cent"), cent); + if (cItsTpcVtx && + !coll.selection_bit(aod::evsel::kIsVertexITSTPC)) { + return false; + } - double a = 0.0; - double b = 0.0; + if (cfgUseGoodItsLayerAllCut && + !coll.selection_bit(aod::evsel::kIsGoodITSLayersAll)) { + return false; + } - // if (!track.isGlobalTrack()) continue; - for (const auto& track : tracks) { + return true; + } - histos.fill(HIST("QA/BeforeCut/Eta"), track.eta()); - histos.fill(HIST("QA/BeforeCut/Pt"), track.pt()); - histos.fill(HIST("QA/BeforeCut/Phi"), track.phi()); - histos.fill(HIST("QA/BeforeCut/DcaXY"), track.dcaXY()); - histos.fill(HIST("QA/BeforeCut/DcaZ"), track.dcaZ()); + // -------------------------------------------------- + // Track selection + // -------------------------------------------------- - // Track quality cuts + template + bool selTrack(T const& track) + { + if (!track.isGlobalTrack()) { + return false; + } - if (requireITS && !track.hasITS()) { - continue; + if (cPVcont && !track.isPVContributor()) { + return false; + } + + if (std::abs(track.eta()) >= etaCut) { + return false; + } + + if (track.pt() <= ptMinCut || track.pt() >= ptMaxCut) { + return false; + } + + if (cDcaXy && std::abs(track.dcaXY()) >= dcaXYCut) { + return false; + } + + if (cDcaZ && std::abs(track.dcaZ()) >= dcaZCut) { + return false; + } + + if (cTpcCr && track.tpcNClsCrossedRows() <= tpcCrossCut) { + return false; + } + + if (cItsChi && track.itsChi2NCl() >= itsChiCut) { + return false; + } + + if (cTpcChi && track.tpcChi2NCl() >= tpcChiCut) { + return false; + } + + return true; + } + + // -------------------------------------------------- + // Before-selection track QA + // -------------------------------------------------- + + template + void fillBeforeQA(T const& track) + { + histos.fill(HIST("QA/Before/TPCchi2perCluster"), track.tpcChi2NCl()); + histos.fill(HIST("QA/Before/ITSchi2perCluster"), track.itsChi2NCl()); + histos.fill(HIST("QA/Before/TPCCrossedrows"), track.tpcNClsCrossedRows()); + histos.fill(HIST("QA/Before/DcaXY"), track.dcaXY()); + histos.fill(HIST("QA/Before/DcaZ"), track.dcaZ()); + histos.fill(HIST("QA/Before/PtDcaXY_before"), track.pt(), track.dcaXY()); + histos.fill(HIST("QA/Before/PtDcaZ_before"), track.pt(), track.dcaZ()); + } + + // -------------------------------------------------- + // After-selection track QA + // -------------------------------------------------- + + template + void fillAfterQA(T const& track, float cent) + { + histos.fill(HIST("QA/phi"), track.phi()); + + histos.fill(HIST("QA/After/DcaXY"), track.dcaXY()); + histos.fill(HIST("QA/After/DcaZ"), track.dcaZ()); + histos.fill(HIST("QA/After/TPCchi2perCluster"), track.tpcChi2NCl()); + histos.fill(HIST("QA/After/ITSchi2perCluster"), track.itsChi2NCl()); + histos.fill(HIST("QA/After/TPCCrossedrows"), track.tpcNClsCrossedRows()); + + histos.fill(HIST("QA/After/PtDcaXY"), track.pt(), track.dcaXY()); + histos.fill(HIST("QA/After/PtDcaZ"), track.pt(), track.dcaZ()); + + histos.fill(HIST("QA/After/Pt"), track.pt()); + histos.fill(HIST("QA/After/Eta"), track.eta()); + histos.fill(HIST("QA/After/Pt_eta"), track.pt(), track.eta()); + histos.fill(HIST("QA/After/cent_hPt"), cent, track.pt()); + histos.fill(HIST("QA/After/cent_hEta"), cent, track.eta()); + } + + // -------------------------------------------------- + // Multiplicity-correlation event selection + // -------------------------------------------------- + + bool eventSelected(float globalNch, float pvTrack, float centrality) + { + if (cfgFunCoeff.cfgMultPVT0CCutEnabled) { + if (pvTrack < cfgFunCoeff.fMultPVT0CCutLow->Eval(centrality) || + pvTrack > cfgFunCoeff.fMultPVT0CCutHigh->Eval(centrality)) { + return false; } - if (requireTPC && !track.hasTPC()) { - continue; + } + + if (cfgFunCoeff.cfgMultGlobalFT0CCutEnabled) { + if (globalNch < cfgFunCoeff.fMultGlobalFT0CCutLow->Eval(centrality) || + globalNch > cfgFunCoeff.fMultGlobalFT0CCutHigh->Eval(centrality)) { + return false; } - if (track.itsNCls() < itsNClsCut) { - continue; + } + + if (cfgFunCoeff.cfgMultGlobalPVCutEnabled) { + if (globalNch < cfgFunCoeff.fMultGlobalPVCutLow->Eval(pvTrack) || + globalNch > cfgFunCoeff.fMultGlobalPVCutHigh->Eval(pvTrack)) { + return false; } - if (track.tpcNClsCrossedRows() < tpcCrossCut) { + } + + return true; + } + + // -------------------------------------------------- + // Fill event-wise moments and profiles + // -------------------------------------------------- + + void fillHistograms(float nch, float cent, float sumPt, int subsample) + { + const float nch2 = nch * nch; + const float sumPt2 = sumPt * sumPt; + const float nchSumPt = nch * sumPt; + const float nchPlusSumPt = nch + sumPt; + + // Event-wise Nch distributions + histos.fill(HIST("Nch/hNch"), nch); + + if (cent < Cent10) { + histos.fill(HIST("Nch/hNch_0_10"), nch); + } else if (cent < Cent10 * 2) { + histos.fill(HIST("Nch/hNch_10_20"), nch); + } else if (cent < Cent10 * 3) { + histos.fill(HIST("Nch/hNch_20_30"), nch); + } else if (cent < Cent10 * 4) { + histos.fill(HIST("Nch/hNch_30_40"), nch); + } else if (cent < Cent10 * 5) { + histos.fill(HIST("Nch/hNch_40_50"), nch); + } else if (cent < Cent10 * 6) { + histos.fill(HIST("Nch/hNch_50_60"), nch); + } else if (cent < Cent10 * 7) { + histos.fill(HIST("Nch/hNch_60_70"), nch); + } else if (cent < Cent10 * 8) { + histos.fill(HIST("Nch/hNch_70_80"), nch); + } else if (cent < Cent10 * 9) { + histos.fill(HIST("Nch/hNch_80_90"), nch); + } else if (cent < Cent10 * 10) { + histos.fill(HIST("Nch/hNch_90_100"), nch); + } + + // Standard centrality profiles + histos.fill(HIST("Data/p_a"), cent, nch); + histos.fill(HIST("Data/p_b"), cent, sumPt); + histos.fill(HIST("Data/p_a2"), cent, nch2); + histos.fill(HIST("Data/p_b2"), cent, sumPt2); + histos.fill(HIST("Data/p_ab"), cent, nchSumPt); + histos.fill(HIST("Data/p_asumb"), cent, nchPlusSumPt); + + // Custom centrality profiles + histos.fill(HIST("Data/p_a_custom"), cent, nch); + histos.fill(HIST("Data/p_b_custom"), cent, sumPt); + histos.fill(HIST("Data/p_a2_custom"), cent, nch2); + histos.fill(HIST("Data/p_b2_custom"), cent, sumPt2); + histos.fill(HIST("Data/p_ab_custom"), cent, nchSumPt); + histos.fill(HIST("Data/p_asumb_custom"), cent, nchPlusSumPt); + + // Standard centrality subsample profiles + histos.fill(HIST("Data/subsample/p_a"), cent, subsample, nch); + histos.fill(HIST("Data/subsample/p_b"), cent, subsample, sumPt); + histos.fill(HIST("Data/subsample/p_a2"), cent, subsample, nch2); + histos.fill(HIST("Data/subsample/p_b2"), cent, subsample, sumPt2); + histos.fill(HIST("Data/subsample/p_ab"), cent, subsample, nchSumPt); + histos.fill(HIST("Data/subsample/p_asumb"), cent, subsample, nchPlusSumPt); + + // Custom centrality subsample profiles + histos.fill(HIST("Data/subsample/p_a_custom"), cent, subsample, nch); + histos.fill(HIST("Data/subsample/p_b_custom"), cent, subsample, sumPt); + histos.fill(HIST("Data/subsample/p_a2_custom"), cent, subsample, nch2); + histos.fill(HIST("Data/subsample/p_b2_custom"), cent, subsample, sumPt2); + histos.fill(HIST("Data/subsample/p_ab_custom"), cent, subsample, nchSumPt); + histos.fill(HIST("Data/subsample/p_asumb_custom"), cent, subsample, nchPlusSumPt); + } + + // -------------------------------------------------- + // DATA calculation + // -------------------------------------------------- + + template + void calculationData(C const& coll, T const& inputTracks) + { + float cent = -1.f; + + // QA before event selection + histos.fill(HIST("QA/Before/VtxZ"), coll.posZ()); + + if (!selCollision(coll, cent)) { + return; + } + + const float pvTrack = coll.multNTracksPV(); + + // Count collision-associated tracks in the filtered track table. + float globalNch = 0.f; + for (const auto& track : inputTracks) { + if (track.collisionId() != coll.globalIndex()) { continue; } - if (track.tpcCrossedRowsOverFindableCls() < crossedRowsOverFindableCut) { + globalNch += 1.f; + } + + // Multiplicity QA before correlation rejection + histos.fill(HIST("QA/hCentFT0C"), cent); + histos.fill(HIST("QA/hNchGlobal"), globalNch); + histos.fill(HIST("QA/hNchPV"), pvTrack); + + histos.fill(HIST("MultCorrelationPlots/globalTracks_PV_bef"), pvTrack, globalNch); + histos.fill(HIST("MultCorrelationPlots/globalTracks_FT0C_bef"), cent, globalNch); + histos.fill(HIST("MultCorrelationPlots/PV_FT0C_bef"), cent, pvTrack); + + // Multiplicity-correlation rejection + if (cfgEvSelMultCorrelation && + !eventSelected(globalNch, pvTrack, cent)) { + return; + } + + // Multiplicity QA after correlation rejection + histos.fill(HIST("MultCorrelationPlots/globalTracks_PV_aft"), pvTrack, globalNch); + histos.fill(HIST("MultCorrelationPlots/globalTracks_FT0C_aft"), cent, globalNch); + histos.fill(HIST("MultCorrelationPlots/PV_FT0C_aft"), cent, pvTrack); + + histos.fill(HIST("QA/After/VtxZ"), coll.posZ()); + histos.fill(HIST("QA/After/Centrality"), cent); + histos.fill(HIST("QA/After/Multiplicity"), globalNch); + + // Event-wise analysis quantities + float nch = 0.f; + float sumPt = 0.f; + + for (const auto& track : inputTracks) { + if (track.collisionId() != coll.globalIndex()) { continue; } - if (std::abs(track.dcaZ()) > dcaZCut) { + + fillBeforeQA(track); + if (!selTrack(track)) { continue; } - if (std::abs(track.dcaXY()) > dcaXYCut) { + + fillAfterQA(track, cent); + + // A = Nch + nch += 1.f; + + // B = sum of pT + sumPt += track.pt(); + } + + // subsample assignment + const int nSub = std::max(1, static_cast(cfgNSubsample)); + const int subsample = static_cast(coll.globalIndex() % nSub); + + // Fill all event-wise moments + fillHistograms(nch, cent, sumPt, subsample); + } + + // -------------------------------------------------- + // DATA process + // -------------------------------------------------- + + void processData(MyCollision const& coll, MyTracks const& tracks) + { + calculationData(coll, tracks); + } + + PROCESS_SWITCH(MultAndPtFluctuations, processData, "Process for DATA", true); + + // -------------------------------------------------- + // MC processing: RECONSTRUCTED + GENERATED + // -------------------------------------------------- + + SliceCache cache; + Preslice perMcCollision = aod::mcparticle::mcCollisionId; + void processMC(MyMCCollision const& coll, MyMCTracks const& tracks, aod::McCollisions const& mcCollisions, aod::McParticles const& mcParticles) + { + (void)mcCollisions; + + // MC RECONSTRUCTED + [&]() { + float cent = -1.f; + // Vertex QA before event selection. + histos.fill(HIST("MCRec/QA/Before/VtxZ"), coll.posZ()); + + if (!selCollision(coll, cent)) { + return; + } + + const float pvTrack = coll.multNTracksPV(); + + float globalNch = 0.f; + + for (const auto& track : tracks) { + if (track.collisionId() != coll.globalIndex()) { + continue; + } + + globalNch += 1.f; + } + // QA and correlations before multiplicity-correlation rejection. + histos.fill(HIST("MCRec/QA/Centrality"), cent); + histos.fill(HIST("MCRec/QA/GlobalNch"), globalNch); + histos.fill(HIST("MCRec/QA/PVNch"), pvTrack); + + histos.fill(HIST("MCRec/MultCorrelationPlots/globalTracks_PV_bef"), pvTrack, globalNch); + histos.fill(HIST("MCRec/MultCorrelationPlots/globalTracks_FT0C_bef"), cent, globalNch); + histos.fill(HIST("MCRec/MultCorrelationPlots/PV_FT0C_bef"), cent, pvTrack); + + // Apply multiplicity-correlation rejection. + if (cfgEvSelMultCorrelation && !eventSelected(globalNch, pvTrack, cent)) { + return; + } + + // QA and correlations after event selection. + histos.fill(HIST("MCRec/QA/After/VtxZ"), coll.posZ()); + histos.fill(HIST("MCRec/MultCorrelationPlots/globalTracks_PV_aft"), pvTrack, globalNch); + histos.fill(HIST("MCRec/MultCorrelationPlots/globalTracks_FT0C_aft"), cent, globalNch); + histos.fill(HIST("MCRec/MultCorrelationPlots/PV_FT0C_aft"), cent, pvTrack); + + // Reconstructed event-wise quantities. + float nch = 0.f; + float sumPt = 0.f; + + for (const auto& track : tracks) { + if (track.collisionId() != coll.globalIndex()) { + continue; + } + + // Track QA before additional manual track cuts. + histos.fill(HIST("MCRec/QA/Before/Pt"), track.pt()); + histos.fill(HIST("MCRec/QA/Before/Eta"), track.eta()); + histos.fill(HIST("MCRec/QA/Before/PtEta"), track.pt(), track.eta()); + + if (!selTrack(track)) { + continue; + } + // Inclusive pT moments for reconstructed MC + histos.fill(HIST("MCRec/pT_inclusive"), cent, track.pt()); + histos.fill(HIST("MCRec/pT2_inclusive"), cent, track.pt() * track.pt()); + // Track QA after manual selection. + histos.fill(HIST("MCRec/QA/After/Pt"), track.pt()); + histos.fill(HIST("MCRec/QA/After/Eta"), track.eta()); + histos.fill(HIST("MCRec/QA/After/PtEta"), track.pt(), track.eta()); + + nch += 1.f; + sumPt += track.pt(); + } + const float nch2 = nch * nch; + const float sumPt2 = sumPt * sumPt; + const float nchSumPt = nch * sumPt; + const float nchPlusSumPt = nch + sumPt; + + const int nSub = std::max(1, static_cast(cfgNSubsample)); + const int subsample = static_cast(coll.globalIndex() % nSub); + + // Standard centrality profiles. + histos.fill(HIST("MCRec/p_a"), cent, nch); + histos.fill(HIST("MCRec/p_b"), cent, sumPt); + histos.fill(HIST("MCRec/p_a2"), cent, nch2); + histos.fill(HIST("MCRec/p_b2"), cent, sumPt2); + histos.fill(HIST("MCRec/p_ab"), cent, nchSumPt); + histos.fill(HIST("MCRec/p_asumb"), cent, nchPlusSumPt); + + // Custom centrality profiles. + histos.fill(HIST("MCRec/p_a_custom"), cent, nch); + histos.fill(HIST("MCRec/p_b_custom"), cent, sumPt); + histos.fill(HIST("MCRec/p_a2_custom"), cent, nch2); + histos.fill(HIST("MCRec/p_b2_custom"), cent, sumPt2); + histos.fill(HIST("MCRec/p_ab_custom"), cent, nchSumPt); + histos.fill(HIST("MCRec/p_asumb_custom"), cent, nchPlusSumPt); + + // Standard centrality subsample profiles. + histos.fill(HIST("MCRec/subsample/p_a"), cent, subsample, nch); + histos.fill(HIST("MCRec/subsample/p_b"), cent, subsample, sumPt); + histos.fill(HIST("MCRec/subsample/p_a2"), cent, subsample, nch2); + histos.fill(HIST("MCRec/subsample/p_b2"), cent, subsample, sumPt2); + histos.fill(HIST("MCRec/subsample/p_ab"), cent, subsample, nchSumPt); + histos.fill(HIST("MCRec/subsample/p_asumb"), cent, subsample, nchPlusSumPt); + + // Custom centrality subsample profiles. + histos.fill(HIST("MCRec/subsample/p_a_custom"), cent, subsample, nch); + histos.fill(HIST("MCRec/subsample/p_b_custom"), cent, subsample, sumPt); + histos.fill(HIST("MCRec/subsample/p_a2_custom"), cent, subsample, nch2); + histos.fill(HIST("MCRec/subsample/p_b2_custom"), cent, subsample, sumPt2); + histos.fill(HIST("MCRec/subsample/p_ab_custom"), cent, subsample, nchSumPt); + histos.fill(HIST("MCRec/subsample/p_asumb_custom"), cent, subsample, nchPlusSumPt); + }(); // mc reconstructed calculation + + //------------ MC GENERATED + + if (!coll.has_mcCollision()) { + return; + } + + const auto mcCollision = coll.mcCollision(); + + // Generated-collision vertex QA before and after vertex cut. + histos.fill(HIST("MCGen/QA/Before/VtxZ"), mcCollision.posZ()); + + if (std::abs(mcCollision.posZ()) >= vertexZcut) { + return; + } + + histos.fill(HIST("MCGen/QA/After/VtxZ"), mcCollision.posZ()); + + // Slice generated particles belonging to this MC collision. + const auto& generatedParticles = mcParticles.sliceByCached(aod::mcparticle::mcCollisionId, mcCollision.globalIndex(), cache); + + float nch = 0.f; + float sumPt = 0.f; + + // Use centrality from the matched reconstructed collision. + float cent = -1.f; + + if (!selCollision(coll, cent)) { + return; + } + + const float pvTrack = coll.multNTracksPV(); + + for (const auto& particle : generatedParticles) { + // Before-selection QA. + histos.fill(HIST("MCGen/QA/Before/Pt"), particle.pt()); + histos.fill(HIST("MCGen/QA/Before/Eta"), particle.eta()); + histos.fill(HIST("MCGen/QA/Before/PtEta"), particle.pt(), particle.eta()); + + if (!particle.isPhysicalPrimary()) { continue; } - if (track.tpcChi2NCl() > tpcChiCut) { + + auto* pdgParticle = pdgService->GetParticle(particle.pdgCode()); + + if (pdgParticle == nullptr || std::abs(pdgParticle->Charge()) < ChargeTolerance) { continue; } - if (track.itsChi2NCl() > itsChiCut) { + + if (std::abs(particle.eta()) >= etaCut) { continue; } - if (std::abs(track.eta()) > etaCut) { + + if (particle.pt() <= ptMinCut || particle.pt() >= ptMaxCut) { continue; } - if (requireInnerITS) { - auto itsMap = track.itsClusterMap(); - if (((itsMap & (1 << 0)) == 0) && - ((itsMap & (1 << 1)) == 0) && - ((itsMap & (1 << 2)) == 0)) { - continue; - } + + // After-selection QA. + histos.fill(HIST("MCGen/QA/After/Pt"), particle.pt()); + histos.fill(HIST("MCGen/QA/After/Eta"), particle.eta()); + histos.fill(HIST("MCGen/QA/After/PtEta"), particle.pt(), particle.eta()); + + // Inclusive pT distributions. + histos.fill(HIST("MCGen/pT_inclusive"), cent, particle.pt()); + histos.fill(HIST("MCGen/pT2_inclusive"), cent, particle.pt() * particle.pt()); + + nch += 1.f; + sumPt += particle.pt(); + } + histos.fill(HIST("MCGen/QA/GeneratedNch"), nch); + + // Reconstructed multiplicity for the matched collision. + float globalNch = 0.f; + + for (const auto& track : tracks) { + if (track.collisionId() != coll.globalIndex()) { + continue; } + globalNch += 1.f; + } + // Correlation QA before multiplicity-correlation rejection. + histos.fill(HIST("MCGen/QA/Centrality"), cent); + histos.fill(HIST("MCGen/QA/GlobalNch"), globalNch); + histos.fill(HIST("MCGen/QA/PVNch"), pvTrack); - // After cuts QA - histos.fill(HIST("QA/AfterCut/Eta"), track.eta()); - histos.fill(HIST("QA/AfterCut/Pt"), track.pt()); - histos.fill(HIST("QA/AfterCut/Phi"), track.phi()); - histos.fill(HIST("QA/AfterCut/DcaXY"), track.dcaXY()); - histos.fill(HIST("QA/AfterCut/DcaZ"), track.dcaZ()); - histos.fill(HIST("h2_DcaZ"), track.pt(), track.dcaZ()); - histos.fill(HIST("h2_DcaXY"), track.pt(), track.dcaXY()); - a++; // A-nch, B =pt - b += track.pt(); - } - - // ---- Fill TProfiles (once per event) - histos.fill(HIST("p_a"), cent, a); - histos.fill(HIST("p_b"), cent, b); - histos.fill(HIST("p_a2"), cent, a * a); - histos.fill(HIST("p_b2"), cent, b * b); - histos.fill(HIST("p_ab"), cent, a * b); - histos.fill(HIST("p_asumb"), cent, a + b); + // Generated event-wise quantities. + const float nch2 = nch * nch; + const float sumPt2 = sumPt * sumPt; + const float nchSumPt = nch * sumPt; + const float nchPlusSumPt = nch + sumPt; + + const int nSub = std::max(1, static_cast(cfgNSubsample)); + const int subsample = static_cast(mcCollision.globalIndex() % nSub); + + // Standard centrality profiles. + histos.fill(HIST("MCGen/p_a"), cent, nch); + histos.fill(HIST("MCGen/p_b"), cent, sumPt); + histos.fill(HIST("MCGen/p_a2"), cent, nch2); + histos.fill(HIST("MCGen/p_b2"), cent, sumPt2); + histos.fill(HIST("MCGen/p_ab"), cent, nchSumPt); + histos.fill(HIST("MCGen/p_asumb"), cent, nchPlusSumPt); + + // Custom centrality profiles. + histos.fill(HIST("MCGen/p_a_custom"), cent, nch); + histos.fill(HIST("MCGen/p_b_custom"), cent, sumPt); + histos.fill(HIST("MCGen/p_a2_custom"), cent, nch2); + histos.fill(HIST("MCGen/p_b2_custom"), cent, sumPt2); + histos.fill(HIST("MCGen/p_ab_custom"), cent, nchSumPt); + histos.fill(HIST("MCGen/p_asumb_custom"), cent, nchPlusSumPt); + + // Standard centrality subsample profiles. + histos.fill(HIST("MCGen/subsample/p_a"), cent, subsample, nch); + histos.fill(HIST("MCGen/subsample/p_b"), cent, subsample, sumPt); + histos.fill(HIST("MCGen/subsample/p_a2"), cent, subsample, nch2); + histos.fill(HIST("MCGen/subsample/p_b2"), cent, subsample, sumPt2); + histos.fill(HIST("MCGen/subsample/p_ab"), cent, subsample, nchSumPt); + histos.fill(HIST("MCGen/subsample/p_asumb"), cent, subsample, nchPlusSumPt); + + // Custom centrality subsample profiles. + histos.fill(HIST("MCGen/subsample/p_a_custom"), cent, subsample, nch); + histos.fill(HIST("MCGen/subsample/p_b_custom"), cent, subsample, sumPt); + histos.fill(HIST("MCGen/subsample/p_a2_custom"), cent, subsample, nch2); + histos.fill(HIST("MCGen/subsample/p_b2_custom"), cent, subsample, sumPt2); + histos.fill(HIST("MCGen/subsample/p_ab_custom"), cent, subsample, nchSumPt); + histos.fill(HIST("MCGen/subsample/p_asumb_custom"), cent, subsample, nchPlusSumPt); } -}; + + PROCESS_SWITCH(MultAndPtFluctuations, processMC, "Process reconstructed and generated MC", false); +}; // close structure + +// ---------------------------------------------------- +// Workflow +// ---------------------------------------------------- WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { - return WorkflowSpec{adaptAnalysisTask(cfgc)}; + return WorkflowSpec{ + adaptAnalysisTask(cfgc)}; }