diff --git a/PWGLF/DataModel/LFSpinAlignVecMesonTables.h b/PWGLF/DataModel/LFSpinAlignVecMesonTables.h new file mode 100644 index 00000000000..10ad0207c54 --- /dev/null +++ b/PWGLF/DataModel/LFSpinAlignVecMesonTables.h @@ -0,0 +1,141 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// \file LFSpinAlignVecMesonTables.h +/// \brief Derived-data tables for K*0 and phi spin-alignment studies + +#ifndef PWGLF_DATAMODEL_LFSPINALIGNVECMESONTABLES_H_ +#define PWGLF_DATAMODEL_LFSPINALIGNVECMESONTABLES_H_ + +#include "PWGLF/DataModel/EPCalibrationTables.h" + +#include "Common/DataModel/Centrality.h" + +#include +#include + +#include + +namespace o2::aod +{ +DECLARE_SOA_TABLE(SpinAlignEvents, "AOD", "SAVMEVENT", + o2::soa::Index<>, + bc::RunNumber, + collision::PosZ, + cent::CentFT0M, + cent::CentFT0C, + epcalibrationtable::PsiFT0C, + epcalibrationtable::PsiFT0A, + epcalibrationtable::PsiTPC, + epcalibrationtable::QFT0C, + epcalibrationtable::QFT0A, + epcalibrationtable::QTPC); +using SpinAlignEvent = SpinAlignEvents::iterator; + +namespace savmcand +{ +DECLARE_SOA_INDEX_COLUMN(SpinAlignEvent, spinAlignEvent); +DECLARE_SOA_COLUMN(Mass, mass, float); +DECLARE_SOA_COLUMN(Px, px, float); +DECLARE_SOA_COLUMN(Py, py, float); +DECLARE_SOA_COLUMN(Pz, pz, float); +DECLARE_SOA_COLUMN(PosPx, posPx, float); +DECLARE_SOA_COLUMN(PosPy, posPy, float); +DECLARE_SOA_COLUMN(PosPz, posPz, float); +DECLARE_SOA_COLUMN(PosTPCNSigma, posTPCNSigma, float); +DECLARE_SOA_COLUMN(PosTOFNSigma, posTOFNSigma, float); +DECLARE_SOA_COLUMN(PosHasTOF, posHasTOF, bool); +DECLARE_SOA_COLUMN(NegPx, negPx, float); +DECLARE_SOA_COLUMN(NegPy, negPy, float); +DECLARE_SOA_COLUMN(NegPz, negPz, float); +DECLARE_SOA_COLUMN(NegTPCNSigma, negTPCNSigma, float); +DECLARE_SOA_COLUMN(NegTOFNSigma, negTOFNSigma, float); +DECLARE_SOA_COLUMN(NegHasTOF, negHasTOF, bool); +DECLARE_SOA_COLUMN(Flavour, flavour, int8_t); +} // namespace savmcand + +DECLARE_SOA_TABLE(SAKstarCands, "AOD", "SAKSTARCAND", + o2::soa::Index<>, + savmcand::SpinAlignEventId, + savmcand::Flavour, + savmcand::Mass, + savmcand::Px, + savmcand::Py, + savmcand::Pz, + savmcand::PosPx, + savmcand::PosPy, + savmcand::PosPz, + savmcand::NegPx, + savmcand::NegPy, + savmcand::NegPz, + savmcand::PosTPCNSigma, + savmcand::PosTOFNSigma, + savmcand::PosHasTOF, + savmcand::NegTPCNSigma, + savmcand::NegTOFNSigma, + savmcand::NegHasTOF); +using SAKstarCand = SAKstarCands::iterator; + +DECLARE_SOA_TABLE(SAPhiCands, "AOD", "SAPHICAND", + o2::soa::Index<>, + savmcand::SpinAlignEventId, + savmcand::Mass, + savmcand::Px, + savmcand::Py, + savmcand::Pz, + savmcand::PosPx, + savmcand::PosPy, + savmcand::PosPz, + savmcand::NegPx, + savmcand::NegPy, + savmcand::NegPz, + savmcand::PosTPCNSigma, + savmcand::PosTOFNSigma, + savmcand::PosHasTOF, + savmcand::NegTPCNSigma, + savmcand::NegTOFNSigma, + savmcand::NegHasTOF); +using SAPhiCand = SAPhiCands::iterator; + +namespace savmtrack +{ +DECLARE_SOA_INDEX_COLUMN(SpinAlignEvent, spinAlignEvent); +DECLARE_SOA_COLUMN(Px, px, float); +DECLARE_SOA_COLUMN(Py, py, float); +DECLARE_SOA_COLUMN(Pz, pz, float); +DECLARE_SOA_COLUMN(Sign, sign, int8_t); +DECLARE_SOA_COLUMN(TPCNSigmaKa, tpcNSigmaKa, float); +DECLARE_SOA_COLUMN(TPCNSigmaPi, tpcNSigmaPi, float); +DECLARE_SOA_COLUMN(TOFNSigmaKa, tofNSigmaKa, float); +DECLARE_SOA_COLUMN(TOFNSigmaPi, tofNSigmaPi, float); +DECLARE_SOA_COLUMN(HasTOF, hasTOF, bool); +DECLARE_SOA_COLUMN(IsKaon, isKaon, bool); +DECLARE_SOA_COLUMN(IsPion, isPion, bool); +} // namespace savmtrack + +DECLARE_SOA_TABLE(SAVMTracks, "AOD", "SAVMTRACK", + o2::soa::Index<>, + savmtrack::SpinAlignEventId, + savmtrack::Px, + savmtrack::Py, + savmtrack::Pz, + savmtrack::Sign, + savmtrack::TPCNSigmaKa, + savmtrack::TPCNSigmaPi, + savmtrack::TOFNSigmaKa, + savmtrack::TOFNSigmaPi, + savmtrack::HasTOF, + savmtrack::IsKaon, + savmtrack::IsPion); +using SAVMTrack = SAVMTracks::iterator; +} // namespace o2::aod + +#endif // PWGLF_DATAMODEL_LFSPINALIGNVECMESONTABLES_H_ diff --git a/PWGLF/TableProducer/Resonances/CMakeLists.txt b/PWGLF/TableProducer/Resonances/CMakeLists.txt index bafd0b12ea0..1a23c718460 100644 --- a/PWGLF/TableProducer/Resonances/CMakeLists.txt +++ b/PWGLF/TableProducer/Resonances/CMakeLists.txt @@ -74,3 +74,8 @@ o2physics_add_dpl_workflow(hresonancecorrelationfilter SOURCES hResonanceCorrelationFilter.cxx PUBLIC_LINK_LIBRARIES O2::DCAFitter O2Physics::AnalysisCore O2Physics::EventFilteringUtils COMPONENT_NAME Analysis) + +o2physics_add_dpl_workflow(spin-align-vec-meson-table + SOURCES spinAlignVecMesonTable.cxx + PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore + COMPONENT_NAME Analysis) diff --git a/PWGLF/TableProducer/Resonances/spinAlignVecMesonTable.cxx b/PWGLF/TableProducer/Resonances/spinAlignVecMesonTable.cxx new file mode 100644 index 00000000000..19f50a9974a --- /dev/null +++ b/PWGLF/TableProducer/Resonances/spinAlignVecMesonTable.cxx @@ -0,0 +1,298 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// \file spinAlignVecMesonTable.cxx +/// \brief Derived-data producer for K*0 and phi spin alignment + +#include "PWGLF/DataModel/EPCalibrationTables.h" +#include "PWGLF/DataModel/LFSpinAlignVecMesonTables.h" + +#include "Common/CCDB/EventSelectionParams.h" +#include "Common/CCDB/RCTSelectionFlags.h" +#include "Common/DataModel/Centrality.h" +#include "Common/DataModel/EventSelection.h" +#include "Common/DataModel/PIDResponseTOF.h" +#include "Common/DataModel/PIDResponseTPC.h" +#include "Common/DataModel/TrackSelectionTables.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include // IWYU pragma: keep +#include + +#include +#include +#include + +using namespace o2; +using namespace o2::framework; +using namespace o2::framework::expressions; +using namespace o2::aod::rctsel; + +struct SpinAlignVecMesonTable { + + Produces eventTable; + Produces kstarTable; + Produces phiTable; + Produces trackTable; + + Configurable cfgCutVertex{"cfgCutVertex", 10.0f, "Maximum |Vz| (cm)"}; + Configurable cfgCentMin{"cfgCentMin", 0.0f, "Minimum FT0C centrality (%)"}; + Configurable cfgCentMax{"cfgCentMax", 80.0f, "Maximum FT0C centrality (%)"}; + Configurable cfgCutOccupancy{"cfgCutOccupancy", 2000, "Maximum track occupancy"}; + Configurable cfgUseRCT{"cfgUseRCT", true, "Apply RCT flag checker"}; + Configurable cfgRCTLabel{"cfgRCTLabel", "CBT_hadronPID", "RCT flag checker label"}; + + Configurable cfgCutPt{"cfgCutPt", 0.15f, "Minimum track pT (GeV/c)"}; + Configurable cfgCutEta{"cfgCutEta", 0.8f, "Maximum track |eta|"}; + Configurable cfgCutDCAxy{"cfgCutDCAxy", 0.1f, "Maximum |DCAxy| (cm)"}; + Configurable cfgCutDCAz{"cfgCutDCAz", 0.1f, "Maximum |DCAz| (cm)"}; + Configurable cfgMinTPCCrossedRows{"cfgMinTPCCrossedRows", 70, "Minimum TPC crossed rows"}; + Configurable cfgMinITSCls{"cfgMinITSCls", 5, "Minimum ITS clusters"}; + + Configurable cfgNSigmaTPCKa{"cfgNSigmaTPCKa", 3.0f, "Kaon: maximum |n-sigma TPC|"}; + Configurable cfgNSigmaTOFKa{"cfgNSigmaTOFKa", 3.0f, "Kaon: maximum |n-sigma TOF|"}; + Configurable cfgNSigmaTPCPi{"cfgNSigmaTPCPi", 3.0f, "Pion: maximum |n-sigma TPC|"}; + Configurable cfgNSigmaTOFPi{"cfgNSigmaTOFPi", 3.0f, "Pion: maximum |n-sigma TOF|"}; + Configurable cfgRequireTOF{"cfgRequireTOF", false, "Require a TOF hit above cfgPtTOFRequired"}; + Configurable cfgPtTOFRequired{"cfgPtTOFRequired", 0.5f, "pT (GeV/c) above which TOF is required"}; + + Configurable cfgKstarMassMin{"cfgKstarMassMin", 0.70f, "Minimum K pi mass (GeV/c^2)"}; + Configurable cfgKstarMassMax{"cfgKstarMassMax", 1.10f, "Maximum K pi mass (GeV/c^2)"}; + Configurable cfgPhiMassMin{"cfgPhiMassMin", 0.99f, "Minimum K K mass (GeV/c^2)"}; + Configurable cfgPhiMassMax{"cfgPhiMassMax", 1.07f, "Maximum K K mass (GeV/c^2)"}; + Configurable cfgPairRapidity{"cfgPairRapidity", 0.5f, "Maximum pair |y|"}; + Configurable cfgStoreTracks{"cfgStoreTracks", true, "Store the selected single kaon and pion tracks (SAVMTracks), needed for the v2 like-sign and mixed-event pairs (not for rho00)"}; + + HistogramRegistry histos{"histos", {}, OutputObjHandlingPolicy::AnalysisObject}; + RCTFlagsChecker rctChecker; + + static constexpr double MassKa = o2::constants::physics::MassKaonCharged; + static constexpr double MassPi = o2::constants::physics::MassPionCharged; + + void init(InitContext&) + { + rctChecker.init(cfgRCTLabel.value, false, true); + + histos.add("hEvents", "Number of events;;Events", kTH1F, {{2, 0.0f, 2.0f}}); + histos.add("hCent", "Selected events;FT0C centrality (%);Events", kTH1F, {{100, 0.0f, 100.0f}}); + histos.add("hKstarMass", "K* candidates;M_{K#pi} (GeV/c^{2});Counts", kTH1F, {{200, 0.6f, 1.2f}}); + histos.add("hPhiMass", "#phi candidates;M_{KK} (GeV/c^{2});Counts", kTH1F, {{200, 0.98f, 1.08f}}); + histos.add("hPsiFT0C", "Selected events;FT0C centrality (%);#Psi_{2}^{FT0C}", kTH2F, {{8, 0.0f, 80.0f}, {100, -o2::constants::math::PIHalf, o2::constants::math::PIHalf}}); + if (cfgStoreTracks) { + histos.add("hNTracks", "Stored kaon/pion tracks per event;N_{tracks};Events", kTH1F, {{500, 0.0f, 2000.0f}}); + } + } + + Filter vertexFilter = nabs(aod::collision::posZ) < cfgCutVertex; + Filter centFilter = aod::cent::centFT0C >= cfgCentMin && aod::cent::centFT0C < cfgCentMax; + Filter trackFilter = nabs(aod::track::eta) < cfgCutEta && aod::track::pt > cfgCutPt; + Filter dcaFilter = nabs(aod::track::dcaXY) < cfgCutDCAxy && nabs(aod::track::dcaZ) < cfgCutDCAz; + + using EventCandidates = soa::Filtered>; + using TrackCandidates = soa::Filtered>; + + template + bool isGoodEvent(T const& collision) + { + if (!collision.sel8()) { + return false; + } + if (!collision.selection_bit(aod::evsel::kNoSameBunchPileup)) { + return false; + } + if (!collision.selection_bit(aod::evsel::kIsGoodZvtxFT0vsPV)) { + return false; + } + if (!collision.selection_bit(aod::evsel::kNoTimeFrameBorder)) { + return false; + } + if (!collision.selection_bit(aod::evsel::kNoITSROFrameBorder)) { + return false; + } + if (collision.trackOccupancyInTimeRange() >= cfgCutOccupancy) { + return false; + } + if (cfgUseRCT && !rctChecker(collision)) { + return false; + } + if (!collision.triggereventep()) { + return false; + } + return true; + } + + template + bool isGoodTrack(T const& track) + { + if (!track.isGlobalTrack()) { + return false; + } + if (!track.isPVContributor()) { + return false; + } + if (track.tpcNClsCrossedRows() < cfgMinTPCCrossedRows) { + return false; + } + if (track.itsNCls() < cfgMinITSCls) { + return false; + } + return true; + } + + template + bool isKaon(T const& track) + { + if (std::abs(track.tpcNSigmaKa()) > cfgNSigmaTPCKa) { + return false; + } + if (cfgRequireTOF && track.pt() > cfgPtTOFRequired && !track.hasTOF()) { + return false; + } + if (track.hasTOF() && std::abs(track.tofNSigmaKa()) > cfgNSigmaTOFKa) { + return false; + } + return true; + } + + template + bool isPion(T const& track) + { + if (std::abs(track.tpcNSigmaPi()) > cfgNSigmaTPCPi) { + return false; + } + if (cfgRequireTOF && track.pt() > cfgPtTOFRequired && !track.hasTOF()) { + return false; + } + if (track.hasTOF() && std::abs(track.tofNSigmaPi()) > cfgNSigmaTOFPi) { + return false; + } + return true; + } + + template + ROOT::Math::PxPyPzMVector makePair(T const& pos, double massPos, T const& neg, double massNeg) + { + ROOT::Math::PxPyPzMVector p4Pos(pos.px(), pos.py(), pos.pz(), massPos); + ROOT::Math::PxPyPzMVector p4Neg(neg.px(), neg.py(), neg.pz(), massNeg); + return p4Pos + p4Neg; + } + + void processData(EventCandidates::iterator const& collision, + TrackCandidates const& tracks, + aod::BCsWithTimestamps const&) + { + histos.fill(HIST("hEvents"), 0.5); + if (!isGoodEvent(collision)) { + return; + } + histos.fill(HIST("hEvents"), 1.5); + histos.fill(HIST("hCent"), collision.centFT0C()); + histos.fill(HIST("hPsiFT0C"), collision.centFT0C(), collision.psiFT0C()); + + auto bc = collision.bc_as(); + eventTable(bc.runNumber(), collision.posZ(), collision.centFT0M(), collision.centFT0C(), + collision.psiFT0C(), collision.psiFT0A(), collision.psiTPC(), + collision.qFT0C(), collision.qFT0A(), collision.qTPC()); + auto eventIndex = eventTable.lastIndex(); + + if (cfgStoreTracks) { + int nStored = 0; + for (const auto& track : tracks) { + if (track.sign() == 0 || !isGoodTrack(track)) { + continue; + } + const bool kaon = isKaon(track); + const bool pion = isPion(track); + if (!kaon && !pion) { + continue; + } + trackTable(eventIndex, track.px(), track.py(), track.pz(), static_cast(track.sign()), + track.tpcNSigmaKa(), track.tpcNSigmaPi(), track.tofNSigmaKa(), track.tofNSigmaPi(), + track.hasTOF(), kaon, pion); + ++nStored; + } + histos.fill(HIST("hNTracks"), nStored); + } + + for (const auto& pos : tracks) { + if (pos.sign() <= 0 || !isGoodTrack(pos)) { + continue; + } + + for (const auto& neg : tracks) { + if (neg.sign() >= 0 || !isGoodTrack(neg)) { + continue; + } + + if (isKaon(pos) && isKaon(neg)) { + auto phi = makePair(pos, MassKa, neg, MassKa); + float mass = phi.M(); + if (mass > cfgPhiMassMin && mass < cfgPhiMassMax && std::abs(phi.Rapidity()) < cfgPairRapidity) { + phiTable(eventIndex, mass, + static_cast(phi.Px()), static_cast(phi.Py()), static_cast(phi.Pz()), + pos.px(), pos.py(), pos.pz(), + neg.px(), neg.py(), neg.pz(), + pos.tpcNSigmaKa(), pos.tofNSigmaKa(), pos.hasTOF(), + neg.tpcNSigmaKa(), neg.tofNSigmaKa(), neg.hasTOF()); + histos.fill(HIST("hPhiMass"), mass); + } + } + + if (isKaon(pos) && isPion(neg)) { + auto kstar = makePair(pos, MassKa, neg, MassPi); + float mass = kstar.M(); + if (mass > cfgKstarMassMin && mass < cfgKstarMassMax && std::abs(kstar.Rapidity()) < cfgPairRapidity) { + kstarTable(eventIndex, static_cast(1), mass, + static_cast(kstar.Px()), static_cast(kstar.Py()), static_cast(kstar.Pz()), + pos.px(), pos.py(), pos.pz(), + neg.px(), neg.py(), neg.pz(), + pos.tpcNSigmaKa(), pos.tofNSigmaKa(), pos.hasTOF(), + neg.tpcNSigmaPi(), neg.tofNSigmaPi(), neg.hasTOF()); + histos.fill(HIST("hKstarMass"), mass); + } + } + + if (isPion(pos) && isKaon(neg)) { + auto kstar = makePair(pos, MassPi, neg, MassKa); + float mass = kstar.M(); + if (mass > cfgKstarMassMin && mass < cfgKstarMassMax && std::abs(kstar.Rapidity()) < cfgPairRapidity) { + kstarTable(eventIndex, static_cast(-1), mass, + static_cast(kstar.Px()), static_cast(kstar.Py()), static_cast(kstar.Pz()), + pos.px(), pos.py(), pos.pz(), + neg.px(), neg.py(), neg.pz(), + pos.tpcNSigmaPi(), pos.tofNSigmaPi(), pos.hasTOF(), + neg.tpcNSigmaKa(), neg.tofNSigmaKa(), neg.hasTOF()); + histos.fill(HIST("hKstarMass"), mass); + } + } + } + } + } + PROCESS_SWITCH(SpinAlignVecMesonTable, processData, "Fill K* and phi derived tables", true); +}; + +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +{ + return WorkflowSpec{adaptAnalysisTask(cfgc)}; +} diff --git a/PWGLF/Tasks/Resonances/kstarpbpb.cxx b/PWGLF/Tasks/Resonances/kstarpbpb.cxx index 46c1a5ba640..a938143c0ba 100644 --- a/PWGLF/Tasks/Resonances/kstarpbpb.cxx +++ b/PWGLF/Tasks/Resonances/kstarpbpb.cxx @@ -12,9 +12,9 @@ /// \file kstarpbpb.cxx /// \brief Code for K*(892)^0 resonance flow and spin alignment analysis /// \author sourav.kundu@cern.ch , sarjeeta.gami@cern.ch -/// #include "PWGLF/DataModel/EPCalibrationTables.h" +#include "PWGLF/DataModel/LFSpinAlignVecMesonTables.h" #include "Common/CCDB/EventSelectionParams.h" #include "Common/CCDB/RCTSelectionFlags.h" @@ -25,13 +25,10 @@ #include "Common/DataModel/PIDResponseTPC.h" #include "Common/DataModel/TrackSelectionTables.h" -#include -#include #include #include #include #include -#include #include #include #include @@ -45,20 +42,21 @@ #include #include -#include // IWYU pragma: keep (do not replace with Math/Vector4Dfwd.h) +#include // IWYU pragma: keep #include #include -#include #include #include #include -#include -#include #include #include #include +#include #include +#include +#include +#include #include using namespace o2; @@ -67,16 +65,6 @@ using namespace o2::framework::expressions; using namespace o2::aod::rctsel; struct Kstarpbpb { - - struct : ConfigurableGroup { - Configurable cfgURL{"cfgURL", "http://alice-ccdb.cern.ch", "Address of the CCDB to browse"}; - Configurable nolaterthan{"nolaterthan", std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(), "Latest acceptable timestamp of creation for the object"}; - } cfgCcdbParam; - - // Enable access to the CCDB for the offset and correction constants and save them in dedicated variables. - Service ccdb{}; - o2::ccdb::CcdbApi ccdbApi; - // Service pdg; struct RCTCut : ConfigurableGroup { Configurable requireRCTFlagChecker{"requireRCTFlagChecker", true, "Check event quality in run condition table"}; Configurable cfgEvtRCTFlagCheckerLabel{"cfgEvtRCTFlagCheckerLabel", "CBT_hadronPID", "Evt sel: RCT flag checker label"}; @@ -88,17 +76,8 @@ struct Kstarpbpb { RCTCut rctCut; - // CCDB options - // Configurable ccdburl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; - // Configurable grpPath{"grpPath", "GLO/GRP/GRP", "Path of the grp file"}; - // Configurable grpmagPath{"grpmagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"}; - // Configurable lutPath{"lutPath", "GLO/Param/MatLUT", "Path of the Lut parametrization"}; - // Configurable geoPath{"geoPath", "GLO/Config/GeometryAligned", "Path of the geometry file"}; - - // events Configurable cfgCutVertex{"cfgCutVertex", 10.0f, "Accepted z-vertex range"}; Configurable cfgCutCentrality{"cfgCutCentrality", 80.0f, "Accepted maximum Centrality"}; - // track Configurable cfgCutCharge{"cfgCutCharge", 0.0, "cut on Charge"}; Configurable cfgCutPT{"cfgCutPT", 0.2, "PT cut on daughter track"}; Configurable cfgCutEta{"cfgCutEta", 0.8, "Eta cut on daughter track"}; @@ -118,7 +97,6 @@ struct Kstarpbpb { ConfigurableAxis configThnAxisPt{"configThnAxisPt", {100, 0.0, 10.}, "#it{p}_{T} (GeV/#it{c})"}; ConfigurableAxis configThnAxisCentrality{"configThnAxisCentrality", {8, 0., 80}, "Centrality"}; ConfigurableAxis configrapAxis{"configrapAxis", {VARIABLE_WIDTH, -0.8, -0.4, 0.4, 0.8}, "Rapidity"}; - Configurable confFakeKaonCut{"confFakeKaonCut", 0.1, "Cut based on track from momentum difference"}; ConfigurableAxis configThnAxisV2{"configThnAxisV2", {400, -16, 16}, "V2"}; Configurable isNoTOF{"isNoTOF", true, "isNoTOF"}; Configurable pdgcheck{"pdgcheck", true, "pdgcheck"}; @@ -131,19 +109,13 @@ struct Kstarpbpb { Configurable nBkgRotations{"nBkgRotations", 9, "Number of rotated copies (background) per each original candidate"}; Configurable fillRotation{"fillRotation", true, "fill rotation"}; Configurable fillSA{"fillSA", true, "same event SA"}; - Configurable doClosureTest{"doClosureTest", false, "Fill dedicated MC closure histograms for spin alignment"}; Configurable fillLikeSignSA{"fillLikeSignSA", false, "fill the same-event like-sign SA sparse (needs fillSA)"}; - Configurable useWeight{"useWeight", false, "use EP dep effi weight"}; Configurable useSP{"useSP", false, "use SP"}; - // spin-alignment quantization axis - Configurable cfgSAFrame{"cfgSAFrame", 0, "SA quantization axis: 0 = event plane (FT0C), 1 = production plane, 2 = random event plane"}; + Configurable cfgSAFrame{"cfgSAFrame", 0, "SA quantization axis: 0 = event plane (FT0C), 1 = production plane, 2 = random event plane (random direction in the transverse plane), 3 = random 3D direction (isotropic, per candidate)"}; Configurable cfgRndSeed{"cfgRndSeed", 0, "Seed for random event plane (0 = unique seed per job)"}; - Configurable cfgEPNormalHarmonic{"cfgEPNormalHarmonic", 1.0f, "EP normal = (sin(n*Psi), -cos(n*Psi), 0); n = 1 is the normal to the Psi2 plane (default), n = 2 is the old behaviour (axis at 2*Psi2 - pi/2, not the normal; the R2 resolution correction does not apply)"}; - // phi(1020) -> K+K- reflection veto for K* (off by default: the task then behaves exactly as before) Configurable cfgPhiVeto{"cfgPhiVeto", false, "Reject K pi pairs whose KK mass (pion candidate given the kaon mass) is near the phi(1020) mass"}; Configurable cfgPhiVetoWindow{"cfgPhiVetoWindow", 0.010f, "Half-width of the phi(1020) veto window (GeV/c^2)"}; - // event loss and signal loss for K* and phi(1020) (processEvtLossSigLossMC), adapted from processEvtLossSigLossMC1 in phianalysisrun3pbpb.cxx struct : ConfigurableGroup { std::string prefix = "evtSigLoss"; Configurable cutVzGen{"cutVzGen", true, "Cut |vz| < cfgCutVertex on the generated collision"}; @@ -152,21 +124,18 @@ struct Kstarpbpb { Configurable requireSingleReco{"requireSingleReco", true, "Accepted MC event: exactly one reconstructed collision passing the selection, as in processMC / processMCPhi (false: at least one, as in phianalysisrun3pbpb.cxx)"}; ConfigurableAxis axisImpactPar{"axisImpactPar", {200, 0.0, 20.0}, "Impact parameter (fm)"}; ConfigurableAxis axisMultMC{"axisMultMC", {500, 0.0, 2000.0}, "Generated charged particles in |eta| < 0.5"}; + ConfigurableAxis axisCosThetaStar{"axisCosThetaStar", {10, -1.0, 1.0}, "cos(#vartheta*) of the generated decay (axis from cfgSAFrame; event plane frame: true reaction plane)"}; } evtSigLoss; - // phi(1020) spin alignment: event selection is the K* one; track and PID selections identical to PWGLF/Tasks/Resonances/phianalysisrun3pbpb.cxx - // (JSON keys follow the O2 linter naming rules) struct : ConfigurableGroup { std::string prefix = "phiSA"; Configurable removeFakeTrack{"removeFakeTrack", true, "Remove fake track from momentum difference"}; Configurable confFakeKaonCut{"confFakeKaonCut", 0.1, "Cut based on track from momentum difference"}; - // track selection (phianalysisrun3pbpb.cxx) Configurable iscustomDCAcut{"iscustomDCAcut", false, "Global track (with DCA) + PV contributor + ITS clusters"}; Configurable ismanualDCAcut{"ismanualDCAcut", true, "Global track w/o DCA + PV contributor + manual DCAxy/DCAz + ITS clusters"}; Configurable cfgCutDCAxy{"cfgCutDCAxy", 2.0f, "DCAxy range for kaon tracks (manual DCA cut)"}; Configurable cfgCutDCAz{"cfgCutDCAz", 2.0f, "DCAz range for kaon tracks (manual DCA cut)"}; Configurable cfgITScluster{"cfgITScluster", 0, "Number of ITS cluster"}; - // PID (phianalysisrun3pbpb.cxx) Configurable nsigmaCutTPC{"nsigmaCutTPC", 3.0, "Value of the TPC Nsigma cut"}; Configurable nsigmaCutCombined{"nsigmaCutCombined", 3.0, "Value of the combined TPC-TOF Nsigma cut"}; Configurable isNoTOF{"isNoTOF", false, "TPC-only PID for all tracks"}; @@ -175,7 +144,6 @@ struct Kstarpbpb { Configurable confRapidity{"confRapidity", 0.5, "Rapidity cut"}; Configurable genacceptancecut{"genacceptancecut", true, "use acceptance cut for generated"}; Configurable avoidsplitrackMC{"avoidsplitrackMC", false, "avoid split track in MC"}; - // same-event backgrounds, as for K* (off by default: processSEPhi then behaves exactly as before) Configurable fillRotation{"fillRotation", false, "Fill the same-event rotated K+K- background (K+ rotated, with confMinRot, confMaxRot and nBkgRotations as for K*)"}; Configurable fillLikeSign{"fillLikeSign", false, "Fill the same-event like-sign (K+K+ and K-K-) background"}; ConfigurableAxis configThnAxisInvMass{"configThnAxisInvMass", {120, 0.98, 1.1}, "#it{M} (GeV/#it{c}^{2})"}; @@ -186,16 +154,10 @@ struct Kstarpbpb { ConfigurableAxis configThnAxisSA{"configThnAxisSA", {200, -1, 1}, "SA"}; } phiSA; - // MC closure test of the cos(theta*) chain (processMCClosure, processMCClosureME, processMCClosurePhi, processMCClosureMEPhi) - // Step 1: SE unlike-sign minus normalised ME (same cuts as data) -> raw yield vs cos(theta*) - // Step 2: raw yield compared with the true reconstructed yield (hSparseRecTrue) - // Step 3: raw yield / (Acc x Eff)(cos theta*), with Acc x Eff = hSparseRecTrueEff / hSparseGenEff - // Step 4: corrected yield and rho00 compared with the generated input (hSparseGen) struct : ConfigurableGroup { std::string prefix = "closure"; Configurable injectPolarization{"injectPolarization", false, "Reweight the true K*/phi with W(cos theta*) so that the sample has rho00 = rho00Inj"}; Configurable rho00Inj{"rho00Inj", 1.0f / 3.0f, "Injected rho00, in [0,1] (1/3 = unpolarized)"}; - Configurable useTrueEP{"useTrueEP", true, "Use the MC true event plane angle as Psi (false: Psi = 0, fixed axis as in processMC with mcEffEP.psiSource = 0)"}; Configurable splitSample{"splitSample", true, "Even MC events build Acc x Eff, odd MC events are the test sample (false: same events for both)"}; Configurable fillRotBkg{"fillRotBkg", false, "Fill the rotated-pair background (weight 1), cross-check of the ME background"}; Configurable genAcceptanceCut{"genAcceptanceCut", false, "Daughter pT/eta cut on the generated K*/phi (false: denominator is the full |y| < cut sample, so the correction is the full Acc x Eff in cos theta*)"}; @@ -204,10 +166,6 @@ struct Kstarpbpb { ConfigurableAxis axisCosThetaStar{"axisCosThetaStar", {10, -1.0, 1.0}, "cos(#vartheta*)"}; } closure; - // Psi of the EP-frame MC efficiency (processMC, processMCPhi). In data the axis follows Psi_FT0C, which is flat in the lab; - // with a fixed Psi = 0 the axis is fixed in the lab, so azimuthal holes of the detector enter Acc x Eff(cos theta*). - // psiSource = 1 follows the thesis (S. Kundu, App. B.10.4): Psi2 from the generated tracks in the forward EP-detector acceptance - // (V0C there, FT0C here), one Psi per MC event, for both the generated and the reconstructed K*/phi. struct : ConfigurableGroup { std::string prefix = "mcEffEP"; Configurable psiSource{"psiSource", 1, "Psi of the EP-frame MC efficiency: 0 = fixed Psi = 0 (old: axis -y for K*, in-plane x for phi), 1 = Psi2 from generated charged primaries in [etaMin, etaMax] (thesis), 2 = MC true event plane (mcCollision.eventPlaneAngle())"}; @@ -216,19 +174,59 @@ struct Kstarpbpb { Configurable fillPhiVMinusPsi{"fillPhiVMinusPsi", false, "Fill gen/rec Acc x Eff maps vs pT, cos theta* and phi_V - Psi (thesis Fig. B.69 / Table B.1 check)"}; ConfigurableAxis axisPhiVMinusPsi{"axisPhiVMinusPsi", {6, 0.0, o2::constants::math::PI}, "#varphi_{V} - #Psi"}; } mcEffEP; - Configurable cfgMinTrackPt{"cfgMinTrackPt", 0.15f, - "Minimum track pT"}; - Configurable cfgMaxTrackPt{"cfgMaxTrackPt", 10.0f, - "Maximum track pT"}; + struct : ConfigurableGroup { + std::string prefix = "moment"; + Configurable fillCosThetaStar{"fillCosThetaStar", true, "Also fill mass, pT, centrality, sample, cos(theta*) sparses next to the moments (SE/ME ratio fit, Method 1)"}; + ConfigurableAxis axisCosThetaStar{"axisCosThetaStar", {20, -1.0, 1.0}, "cos(#vartheta*), full range -1 to 1"}; + Configurable replNDraws{"replNDraws", 5, "Replacement ME: number of donor candidates drawn per target candidate"}; + Configurable replCellCapacity{"replCellCapacity", 10, "Replacement ME: donor reservoir size per matching cell (filled by previous events of the same vz and centrality class)"}; + Configurable replPtWidth{"replPtWidth", 0.2f, "Replacement ME: parent pT matching cell width (GeV/c)"}; + Configurable replEtaWidth{"replEtaWidth", 0.2f, "Replacement ME: parent eta matching cell width"}; + Configurable replPhiWidth{"replPhiWidth", static_cast(o2::constants::math::TwoPI / 18.), "Replacement ME: parent phi matching cell width (rad)"}; + ConfigurableAxis replAxisVertex{"replAxisVertex", {5, -10.0, 10.0}, "Replacement ME: vz classes of the donor pools (centrality classes: axisCentrality; never binned in Psi)"}; + Configurable mcClosure{"mcClosure", false, "processMCClosureRecoEP / processMCClosureRecoEPPhi also fill the moments: test-sample pairs with the injected weight (sample 0) and efficiency-sample true pairs as the MC reference (sample 2)"}; + Configurable mcRefRho00{"mcRefRho00", 1.0f / 3.0f, "MC reference (sample 2): rho00 put in by weight relative to the MC reaction plane (1/3 = unpolarized reference)"}; + Configurable nSubsamples{"nSubsamples", 30, "Number of event subsamples (resampling units of the offline bootstrap); the uncertainty itself is known to about 1/sqrt(2 (n - 1))"}; + ConfigurableAxis axisPt{"axisPt", {VARIABLE_WIDTH, 0.0, 0.4, 0.8, 1.2, 1.6, 2.0, 2.5, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0}, "#it{p}_{T} (GeV/#it{c})"}; + ConfigurableAxis axisCentrality{"axisCentrality", {8, 0.0, 80.0}, "FT0C centrality (%), AO2D and derived input"}; + } moment; + + struct : ConfigurableGroup { + std::string prefix = "candidate"; + Configurable kstarMassMin{"kstarMassMin", 0.70f, "Minimum K pi mass (GeV/c^2)"}; + Configurable kstarMassMax{"kstarMassMax", 1.10f, "Maximum K pi mass (GeV/c^2)"}; + Configurable phiMassMin{"phiMassMin", 0.99f, "Minimum K K mass (GeV/c^2)"}; + Configurable phiMassMax{"phiMassMax", 1.07f, "Maximum K K mass (GeV/c^2)"}; + ConfigurableAxis axisMassKstar{"axisMassKstar", {160, 0.7, 1.1}, "#it{M}_{K#pi} (GeV/#it{c}^{2})"}; + ConfigurableAxis axisMassPhi{"axisMassPhi", {80, 0.99, 1.07}, "#it{M}_{KK} (GeV/#it{c}^{2})"}; + Configurable nSigmaTPC{"nSigmaTPC", 3.0f, "Derived input: maximum |n-sigma TPC| of the daughters (assigned species)"}; + Configurable nSigmaTOF{"nSigmaTOF", 3.0f, "Derived input: maximum |n-sigma TOF| of the daughters with TOF (assigned species)"}; + } candCfg; + + struct : ConfigurableGroup { + std::string prefix = "v2derived"; + ConfigurableAxis axisPt{"axisPt", {100, 0.0, 10.0}, "#it{p}_{T} (GeV/#it{c})"}; + ConfigurableAxis axisCentrality{"axisCentrality", {16, 0.0, 80.0}, "FT0C centrality (%): analysis bins and mixing classes (5% in the paper)"}; + ConfigurableAxis axisUQ{"axisUQ", {400, -16.0, 16.0}, "u2 Q2* and mixed-event background term"}; + ConfigurableAxis axisResSP{"axisResSP", {6000, -30.0, 30.0}, "Q_a Q_b* of the SP resolution"}; + ConfigurableAxis mixAxisVertex{"mixAxisVertex", {10, -10.0, 10.0}, "vz classes of the mixing pools"}; + Configurable nMixedEvents{"nMixedEvents", 5, "Number of previous events of the same vz and centrality class each event is mixed with"}; + } v2Derived; + + enum MomentSample : int { + kMomSEUnlike = 0, + kMomMERepl = 1, + kMomMCRef = 2, + kNMomSamples = 3 + }; + Configurable genacceptancecut{"genacceptancecut", true, "use acceptance cut for generated"}; Configurable avoidsplitrackMC{"avoidsplitrackMC", false, "avoid split track in MC"}; Configurable additionalEvSel1{"additionalEvSel1", true, "Additional evsel1"}; Configurable additionalEvSel2{"additionalEvSel2", true, "Additional evsel2"}; Configurable additionalEvSel3{"additionalEvSel3", true, "Additional evsel3"}; Configurable additionalEvSel4{"additionalEvSel4", true, "Additional evsel4"}; - Configurable confWeightPath{"confWeightPath", "Users/s/skundu/My/Object/fitweight", "Path to gain calibration"}; - ConfigurableAxis axisPtKaonWeight{"axisPtKaonWeight", {VARIABLE_WIDTH, 0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f, 1.9f, 2.0f, 2.2f, 2.4f, 2.6f, 2.8f, 3.0f, 3.2f, 3.4f, 3.6f, 3.8f, 4.0f, 4.4f, 4.8f, 5.2f, 5.6f, 6.0f, 6.5f, 7.0f, 7.5f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f}, "pt axis"}; Filter collisionFilter = nabs(aod::collision::posZ) < cfgCutVertex; Filter centralityFilter = nabs(aod::cent::centFT0C) < cfgCutCentrality; @@ -246,27 +244,19 @@ struct Kstarpbpb { using FilTrackMCRecTable = soa::Filtered; Preslice perCollision = aod::track::collisionId; - // reconstructed MC collisions for the closure: adds EPCalibrationTables (psiFT0C etc.) on top of CollisionMCRecTableCentFT0C, - // so the closure can optionally use the reconstructed (finite-resolution) Psi_FT0C instead of the MC true event plane using CollisionMCRecTableClosure = soa::SmallGroups>; - // reconstructed MC collisions for the closure mixed event (posZ and centrality filters as in data) - using CollisionMCRecMixTable = soa::Filtered>; - // same as CollisionMCRecMixTable, plus EPCalibrationTables (psiFT0C etc.) for the reconstructed-event-plane closure using CollisionMCRecMixTableRecoEP = soa::Filtered>; - using BinningTypeMCClosure = ColumnBinningPolicy; - // same as BinningTypeMCClosure, plus Psi_FT0C (as in data's BinningTypeVertexContributor), for the reconstructed-EP closure ME using BinningTypeMCClosureRecoEP = ColumnBinningPolicy; SliceCache cache; - // Partition posTracks = aod::track::signed1Pt > cfgCutCharge; - // Partition negTracks = aod::track::signed1Pt < cfgCutCharge; HistogramRegistry histos{"histos", {}, OutputObjHandlingPolicy::AnalysisObject}; enum SAFrame : int { kEventPlane = 0, kProductionPlane = 1, - kRandomEventPlane = 2 + kRandomEventPlane = 2, + kRandom3D = 3 }; TRandom3 rndGen; @@ -277,11 +267,8 @@ struct Kstarpbpb { rctCut.cfgEvtRCTFlagCheckerZDCCheck, rctCut.cfgEvtRCTFlagCheckerLimitAcceptAsBad); - if (cfgSAFrame.value < kEventPlane || cfgSAFrame.value > kRandomEventPlane) { - LOGF(fatal, "cfgSAFrame = %d not supported (0 = event plane, 1 = production plane, 2 = random event plane)", cfgSAFrame.value); - } - if (cfgSAFrame.value != kProductionPlane && cfgEPNormalHarmonic.value != 1.0f) { - LOGF(warning, "cfgEPNormalHarmonic = %.1f: the SA axis is not the normal to the Psi2 plane, so the R2 = resolution correction does not close", cfgEPNormalHarmonic.value); + if (cfgSAFrame.value < kEventPlane || cfgSAFrame.value > kRandom3D) { + LOGF(fatal, "cfgSAFrame = %d not supported (0 = event plane, 1 = production plane, 2 = random event plane, 3 = random 3D direction)", cfgSAFrame.value); } rndGen.SetSeed(cfgRndSeed); @@ -307,7 +294,7 @@ struct Kstarpbpb { if (fillRotation) { histos.add("hSparseSAvsraprot", "hSparseSAvsraprot", HistType::kTHnSparseF, {configThnAxisInvMass, configThnAxisPt, configThnAxisV2, configrapAxis, configThnAxisCentrality}); } - if (cfgSAFrame.value == kRandomEventPlane) { + if (isRandomFrame()) { histos.add("hPsiRandom", "Random event plane angle", kTH2F, {centAxis, phiAxis}); } } @@ -342,45 +329,6 @@ struct Kstarpbpb { } } - if (doClosureTest) { - histos.add("closure/KstarSameEventCosThetaStar", "K*0 closure: same-event unlike-sign;M (GeV/c^{2});p_{T} (GeV/c);cos(#vartheta);|y|;centrality", HistType::kTHnSparseF, - {configThnAxisInvMass, configThnAxisPt, {20, -1.0, 1.0, "cos(#vartheta)"}, configrapAxis, configThnAxisCentrality}); - histos.add("closure/KstarMixedEventCosThetaStar", "K*0 closure: mixed-event unlike-sign;M (GeV/c^{2});p_{T} (GeV/c);cos(#vartheta);|y|;centrality", HistType::kTHnSparseF, - {configThnAxisInvMass, configThnAxisPt, {20, -1.0, 1.0, "cos(#vartheta)"}, configrapAxis, configThnAxisCentrality}); - histos.add("closure/KstarMCRecTrueCosThetaStar", "K*0 closure: true matched reconstructed;M (GeV/c^{2});p_{T} (GeV/c);cos(#vartheta);|y|;centrality", HistType::kTHnSparseF, - {configThnAxisInvMass, configThnAxisPt, {20, -1.0, 1.0, "cos(#vartheta)"}, configrapAxis, configThnAxisCentrality}); - histos.add("closure/KstarMCGenCosThetaStar", "K*0 closure: generated;M (GeV/c^{2});p_{T} (GeV/c);cos(#vartheta);|y|;centrality", HistType::kTHnSparseF, - {configThnAxisInvMass, configThnAxisPt, {20, -1.0, 1.0, "cos(#vartheta)"}, configrapAxis, configThnAxisCentrality}); - - const AxisSpec closurePhiMass{phiSA.configThnAxisInvMass, "#it{M} (GeV/#it{c}^{2})"}; - const AxisSpec closurePhiPt{phiSA.configThnAxisPt, "#it{p}_{T} (GeV/#it{c})"}; - const AxisSpec closurePhiCos{20, -1.0, 1.0, "cos(#vartheta)"}; - const AxisSpec closurePhiRap{phiSA.configThnAxisRapidity, "|y|"}; - const AxisSpec closurePhiCent{phiSA.configThnAxisCentrality, "Centrality (%)"}; - histos.add("closure/PhiSameEventCosThetaStar", "phi closure: same-event unlike-sign;M (GeV/c^{2});p_{T} (GeV/c);cos(#vartheta);|y|;centrality", HistType::kTHnSparseF, - {closurePhiMass, closurePhiPt, closurePhiCos, closurePhiRap, closurePhiCent}); - histos.add("closure/PhiMixedEventCosThetaStar", "phi closure: mixed-event unlike-sign;M (GeV/c^{2});p_{T} (GeV/c);cos(#vartheta);|y|;centrality", HistType::kTHnSparseF, - {closurePhiMass, closurePhiPt, closurePhiCos, closurePhiRap, closurePhiCent}); - histos.add("closure/PhiMCRecTrueCosThetaStar", "phi closure: true matched reconstructed;M (GeV/c^{2});p_{T} (GeV/c);cos(#vartheta);|y|;centrality", HistType::kTHnSparseF, - {closurePhiMass, closurePhiPt, closurePhiCos, closurePhiRap, closurePhiCent}); - histos.add("closure/PhiMCGenCosThetaStar", "phi closure: generated;M (GeV/c^{2});p_{T} (GeV/c);cos(#vartheta);|y|;centrality", HistType::kTHnSparseF, - {closurePhiMass, closurePhiPt, closurePhiCos, closurePhiRap, closurePhiCent}); - } - - if (doprocessMCkstarWeight) { - histos.add("h1PhiRecsplit", "Phi meson Rec split", kTH1F, {{100, 0.0f, 10.0f}}); - histos.add("hImpactParameter", "Impact parameter", kTH1F, {{200, 0.0f, 20.0f}}); - histos.add("hEventPlaneAngle", "hEventPlaneAngle", kTH1F, {{200, -o2::constants::math::TwoPI, o2::constants::math::TwoPI}}); - histos.add("hSparseKstarMCGenWeight", "hSparseKstarMCGenWeight", HistType::kTHnSparseD, {configThnAxisCentrality, {36, 0.0f, o2::constants::math::PI}, {400, 0.0f, 1}, configThnAxisPt, {8, -0.8, 0.8}}); - histos.add("hSparseKstarMCRecWeight", "hSparseKstarMCRecWeight", HistType::kTHnSparseD, {configThnAxisCentrality, {36, 0.0f, o2::constants::math::PI}, {400, 0.0f, 1}, configThnAxisPt, {8, -0.8, 0.8}}); - histos.add("hSparseKstarMCGenKaonWeight", "hSparseKstarMCGenKaonWeight", HistType::kTHnSparseD, {configThnAxisCentrality, {36, 0.0f, o2::constants::math::PI}, {400, 0.0f, 1}, axisPtKaonWeight, {8, -0.8, 0.8}}); - histos.add("hSparseKstarMCRecKaonWeight", "hSparseKstarMCRecKaonWeight", HistType::kTHnSparseD, {configThnAxisCentrality, {36, 0.0f, o2::constants::math::PI}, {400, 0.0f, 1}, axisPtKaonWeight, {8, -0.8, 0.8}}); - histos.add("hSparseKstarMCRecKaonMissMatchWeight", "hSparseKstarMCRecKaonMissMatchWeight", HistType::kTHnSparseD, {configThnAxisCentrality, {36, 0.0f, o2::constants::math::PI}, {400, 0.0f, 1}, axisPtKaonWeight, {8, -0.8, 0.8}}); - histos.add("hSparseKstarMCGenPionWeight", "hSparseKstarMCGenPionWeight", HistType::kTHnSparseD, {configThnAxisCentrality, {36, 0.0f, o2::constants::math::PI}, {400, 0.0f, 1}, axisPtKaonWeight, {8, -0.8, 0.8}}); - histos.add("hSparseKstarMCRecPionWeight", "hSparseKstarMCRecPionWeight", HistType::kTHnSparseD, {configThnAxisCentrality, {36, 0.0f, o2::constants::math::PI}, {400, 0.0f, 1}, axisPtKaonWeight, {8, -0.8, 0.8}}); - histos.add("hSparseKstarMCRecPionMissMatchWeight", "hSparseKstarMCRecPionMissMatchWeight", HistType::kTHnSparseD, {configThnAxisCentrality, {36, 0.0f, o2::constants::math::PI}, {400, 0.0f, 1}, axisPtKaonWeight, {8, -0.8, 0.8}}); - } - if (doprocessSE && additionalQAplots1) { histos.add("hFTOCvsTPCSelected", "Mult correlation FT0C vs. TPC after selection", kTH2F, {{80, 0.0f, 80.0f}, {100, -0.5f, 5999.5f}}); histos.add("hCentrality", "Centrality distribution", kTH1F, {{200, 0.0, 200.0}}); @@ -405,31 +353,25 @@ struct Kstarpbpb { histos.add("hQTPCvsVz", "q_{TPC} vs Z_{vtx}", kTH2F, {vzAxis, qvecAxis}); } if (doprocessSE && additionalQAplots) { - // DCA QA histos.add("QAbefore/trkDCAxyka", "DCAxy distribution of kaon track candidates", HistType::kTH1F, {{150, -1.0f, 1.0f}}); histos.add("QAbefore/trkDCAzka", "DCAz distribution of kaon track candidates", HistType::kTH1F, {{150, -1.0f, 1.0f}}); histos.add("QAafter/trkDCAxyka", "DCAxy distribution of kaon track candidates", HistType::kTH1F, {{150, -1.0f, 1.0f}}); histos.add("QAafter/trkDCAzka", "DCAz distribution of kaon track candidates", HistType::kTH1F, {{150, -1.0f, 1.0f}}); - // PID QA before cuts histos.add("QAbefore/TOF_TPC_Mapka_allka", "TOF + TPC Combined PID for Kaon;#sigma_{TOF}^{Kaon};#sigma_{TPC}^{Kaon}", {HistType::kTH2D, {{100, -6, 6}, {100, -6, 6}}}); histos.add("QAbefore/TOF_Nsigma_allka", "TOF NSigma for Kaon;#it{p}_{T} (GeV/#it{c});#sigma_{TOF}^{Kaon};", {HistType::kTH3D, {{200, 0.0, 20.0}, {100, -6, 6}, {100, 0.0, 100.0}}}); histos.add("QAbefore/TPC_Nsigma_allka", "TPC NSigma for Kaon;#it{p}_{T} (GeV/#it{c});#sigma_{TPC}^{Kaon};", {HistType::kTH3D, {{200, 0.0, 20.0}, {100, -6, 6}, {100, 0.0, 100.0}}}); - // PID QA after cuts histos.add("QAafter/TOF_TPC_Mapka_allka", "TOF + TPC Combined PID for Kaon;#sigma_{TOF}^{Kaon};#sigma_{TPC}^{Kaon}", {HistType::kTH2D, {{100, -6, 6}, {100, -6, 6}}}); histos.add("QAafter/TOF_Nsigma_allka", "TOF NSigma for Kaon;#it{p}_{T} (GeV/#it{c});#sigma_{TOF}^{Kaon};", {HistType::kTH3D, {{200, 0.0, 20.0}, {100, -6, 6}, {100, 0.0, 100.0}}}); histos.add("QAafter/TPC_Nsigma_allka", "TPC NSigma for Kaon;#it{p}_{T} (GeV/#it{c});#sigma_{TPC}^{Kaon};", {HistType::kTH3D, {{200, 0.0, 20.0}, {100, -6, 6}, {100, 0.0, 100.0}}}); - // DCA QA histos.add("QAbefore/trkDCAxypi", "DCAxy distribution of pion track candidates", HistType::kTH1F, {{150, -1.0f, 1.0f}}); histos.add("QAbefore/trkDCAzpi", "DCAz distribution of pion track candidates", HistType::kTH1F, {{150, -1.0f, 1.0f}}); histos.add("QAafter/trkDCAxypi", "DCAxy distribution of pion track candidates", HistType::kTH1F, {{150, -1.0f, 1.0f}}); histos.add("QAafter/trkDCAzpi", "DCAz distribution of pion track candidates", HistType::kTH1F, {{150, -1.0f, 1.0f}}); - // PID QA before cuts histos.add("QAbefore/TOF_TPC_Mapka_allpi", "TOF + TPC Combined PID for pion;#sigma_{TOF}^{pion};#sigma_{TPC}^{pion}", {HistType::kTH2D, {{100, -6, 6}, {100, -6, 6}}}); histos.add("QAbefore/TOF_Nsigma_allpi", "TOF NSigma for pion;#it{p}_{T} (GeV/#it{c});#sigma_{TOF}^{pion};", {HistType::kTH3D, {{200, 0.0, 20.0}, {100, -6, 6}, {100, 0.0, 100.0}}}); histos.add("QAbefore/TPC_Nsigma_allpi", "TPC NSigma for pion;#it{p}_{T} (GeV/#it{c});#sigma_{TPC}^{pion};", {HistType::kTH3D, {{200, 0.0, 20.0}, {100, -6, 6}, {100, 0.0, 100.0}}}); - // PID QA after cuts histos.add("QAafter/TOF_TPC_Mapka_allpi", "TOF + TPC Combined PID for pion;#sigma_{TOF}^{pion};#sigma_{TPC}^{pion}", {HistType::kTH2D, {{100, -6, 6}, {100, -6, 6}}}); histos.add("QAafter/TOF_Nsigma_allpi", "TOF NSigma for pion;#it{p}_{T} (GeV/#it{c});#sigma_{TOF}^{pion};", {HistType::kTH3D, {{200, 0.0, 20.0}, {100, -6, 6}, {100, 0.0, 100.0}}}); histos.add("QAafter/TPC_Nsigma_allpi", "TPC NSigma for pion;#it{p}_{T} (GeV/#it{c});#sigma_{TPC}^{pion};", {HistType::kTH3D, {{200, 0.0, 20.0}, {100, -6, 6}, {100, 0.0, 100.0}}}); @@ -445,7 +387,6 @@ struct Kstarpbpb { histos.add("hMassMixedEventUnlike", "Mixed-event unlike-sign mass", kTH2F, {configThnAxisInvMass, configThnAxisCentrality}); } - // phi(1020) spin alignment, same names and binning as phipbpb.cxx if (doprocessSEPhi || doprocessMEPhi || doprocessMCPhi) { const AxisSpec thnAxisInvMassPhi{phiSA.configThnAxisInvMass, "#it{M} (GeV/#it{c}^{2})"}; const AxisSpec thnAxisPtPhi{phiSA.configThnAxisPt, "#it{p}_{T} (GeV/#it{c})"}; @@ -453,10 +394,13 @@ struct Kstarpbpb { const AxisSpec thnAxisCentralityPhi{phiSA.configThnAxisCentrality, "Centrality (%)"}; const AxisSpec thnAxisRapidityPhi{phiSA.configThnAxisRapidity, "Rapidity"}; const AxisSpec thnAxisSAPhi{phiSA.configThnAxisSA, "SA"}; - if (cfgSAFrame.value == kRandomEventPlane) { + if (isRandomFrame()) { histos.add("phi/hPsiRandom", "Random event plane angle", kTH2F, {centAxis, phiAxis}); } if (doprocessSEPhi) { + histos.add("phi/ResFT0CTPC", "ResFT0CTPC", kTH2F, {centAxis, resAxis}); + histos.add("phi/ResFT0CFT0A", "ResFT0CFT0A", kTH2F, {centAxis, resAxis}); + histos.add("phi/ResFT0ATPC", "ResFT0ATPC", kTH2F, {centAxis, resAxis}); histos.add("phi/hSparseV2SameEventSA", "hSparseV2SameEventSA", HistType::kTHnSparseF, {thnAxisInvMassPhi, thnAxisPtPhi, thnAxisSAPhi, thnAxisRapidityPhi, thnAxisCentralityPhi}); histos.add("phi/hSparseV2SameEventCosThetaStar", "hSparseV2SameEventCosThetaStar", HistType::kTHnSparseF, {thnAxisInvMassPhi, thnAxisPtPhi, thnAxisCosThetaStarPhi, thnAxisRapidityPhi, thnAxisCentralityPhi}); if (phiSA.fillRotation) { @@ -491,19 +435,132 @@ struct Kstarpbpb { } } + if (doprocessV2DerivedSE || doprocessV2DerivedME) { + if (v2Derived.nMixedEvents.value < 1) { + LOGF(fatal, "v2derived.nMixedEvents = %d, must be >= 1", v2Derived.nMixedEvents.value); + } + const AxisSpec v2MassKstarAxis{candCfg.axisMassKstar, "#it{M}_{K#pi} (GeV/#it{c}^{2})"}; + const AxisSpec v2MassPhiAxis{candCfg.axisMassPhi, "#it{M}_{KK} (GeV/#it{c}^{2})"}; + const AxisSpec v2PtAxis{v2Derived.axisPt, "#it{p}_{T} (GeV/#it{c})"}; + const AxisSpec v2CentAxis{v2Derived.axisCentrality, "FT0C centrality (%)"}; + if (doprocessV2DerivedSE) { + const AxisSpec v2UQAxis{v2Derived.axisUQ, "#it{u}_{2}#it{Q}_{2}^{FT0C*}"}; + const AxisSpec v2ResAxis{v2Derived.axisResSP, "#it{Q}_{a}#it{Q}_{b}^{*}"}; + histos.add("v2derived/ResFT0CTPCSP", "SP resolution: Q^{FT0C} Q^{TPC*}", kTH2F, {v2CentAxis, v2ResAxis}); + histos.add("v2derived/ResFT0CFT0ASP", "SP resolution: Q^{FT0C} Q^{FT0A*}", kTH2F, {v2CentAxis, v2ResAxis}); + histos.add("v2derived/ResFT0ATPCSP", "SP resolution: Q^{FT0A} Q^{TPC*}", kTH2F, {v2CentAxis, v2ResAxis}); + histos.add("v2derived/kstar/hSEUnlike", "K* same event, unlike sign: N^{tot}(M) and u_{2}Q_{2}^{*}", HistType::kTHnSparseF, {v2MassKstarAxis, v2PtAxis, v2UQAxis, v2CentAxis}); + histos.add("v2derived/kstar/hSELikePP", "K^{+}#pi^{+} same event", kTH3F, {v2MassKstarAxis, v2PtAxis, v2CentAxis}); + histos.add("v2derived/kstar/hSELikeNN", "K^{-}#pi^{-} same event", kTH3F, {v2MassKstarAxis, v2PtAxis, v2CentAxis}); + histos.add("v2derived/phi/hSEUnlike", "#phi same event, unlike sign: N^{tot}(M) and u_{2}Q_{2}^{*}", HistType::kTHnSparseF, {v2MassPhiAxis, v2PtAxis, v2UQAxis, v2CentAxis}); + histos.add("v2derived/phi/hSELikePP", "K^{+}K^{+} same event", kTH3F, {v2MassPhiAxis, v2PtAxis, v2CentAxis}); + histos.add("v2derived/phi/hSELikeNN", "K^{-}K^{-} same event", kTH3F, {v2MassPhiAxis, v2PtAxis, v2CentAxis}); + } + if (doprocessV2DerivedME) { + const AxisSpec v2BkgAxis{v2Derived.axisUQ, "#sum_{i} #it{u}_{2}^{(i)}#it{Q}_{2}^{(i)*} cos 2(#varphi_{i} - #varphi)"}; + histos.add("v2derived/kstar/hMEUnlike", "K* mixed event, unlike sign: N^{mix}(M) and Eq. 5 numerator", HistType::kTHnSparseF, {v2MassKstarAxis, v2PtAxis, v2BkgAxis, v2CentAxis}); + histos.add("v2derived/kstar/hMELikePP", "K^{+}#pi^{+} mixed event", kTH3F, {v2MassKstarAxis, v2PtAxis, v2CentAxis}); + histos.add("v2derived/kstar/hMELikeNN", "K^{-}#pi^{-} mixed event", kTH3F, {v2MassKstarAxis, v2PtAxis, v2CentAxis}); + histos.add("v2derived/phi/hMEUnlike", "#phi mixed event, unlike sign: N^{mix}(M) and Eq. 5 numerator", HistType::kTHnSparseF, {v2MassPhiAxis, v2PtAxis, v2BkgAxis, v2CentAxis}); + histos.add("v2derived/phi/hMELikePP", "K^{+}K^{+} mixed event", kTH3F, {v2MassPhiAxis, v2PtAxis, v2CentAxis}); + histos.add("v2derived/phi/hMELikeNN", "K^{-}K^{-} mixed event", kTH3F, {v2MassPhiAxis, v2PtAxis, v2CentAxis}); + histos.add("v2derived/hMixedEventPairs", "Mixed event pairs;FT0C centrality (%);Pairs", kTH1F, {v2CentAxis}); + } + } + + const bool replKstar = doprocessMomentDerivedMERepl || doprocessMCClosureReplacementME; + const bool replPhi = doprocessMomentDerivedMERepl || doprocessMCClosureReplacementMEPhi; + const bool mcRefKstar = moment.mcClosure && doprocessMCClosureRecoEP; + const bool mcRefPhi = moment.mcClosure && doprocessMCClosureRecoEPPhi; + const bool momentKstar = doprocessMomentDerivedSE || replKstar || mcRefKstar; + const bool momentPhi = doprocessMomentDerivedSE || replPhi || mcRefPhi; + if (momentKstar || momentPhi) { + if (moment.nSubsamples.value < 2) { + LOGF(fatal, "moment.nSubsamples = %d, must be >= 2 for the bootstrap uncertainty", moment.nSubsamples.value); + } + const AxisSpec momPtAxis{moment.axisPt, "#it{p}_{T} (GeV/#it{c})"}; + const AxisSpec momCentAxis{moment.axisCentrality, "Centrality (%)"}; + const AxisSpec momSampleAxis{static_cast(kNMomSamples), -0.5, static_cast(kNMomSamples) - 0.5, "sample (0 SE unlike, 1 ME replacement, 2 MC reference)"}; + const AxisSpec momCosAxis{moment.axisCosThetaStar, "cos(#vartheta*)"}; + const AxisSpec momSubAxis{moment.nSubsamples.value, -0.5, moment.nSubsamples.value - 0.5, "subsample"}; + if (momentKstar) { + const AxisSpec momMassAxis{candCfg.axisMassKstar, "#it{M}_{K#pi} (GeV/#it{c}^{2})"}; + histos.add("moment/kstar/hX0", "K*: #Sigma 1", HistType::kTHnSparseD, {momMassAxis, momPtAxis, momCentAxis, momSampleAxis, momSubAxis}); + histos.add("moment/kstar/hX2", "K*: #Sigma cos^{2}#theta*", HistType::kTHnSparseD, {momMassAxis, momPtAxis, momCentAxis, momSampleAxis, momSubAxis}); + histos.add("moment/kstar/hX4", "K*: #Sigma cos^{4}#theta*", HistType::kTHnSparseD, {momMassAxis, momPtAxis, momCentAxis, momSampleAxis, momSubAxis}); + if (moment.fillCosThetaStar) { + histos.add("moment/kstar/hCosThetaStar", "K*: cos#theta* (SE/ME ratio fit)", HistType::kTHnSparseD, {momMassAxis, momPtAxis, momCentAxis, momSampleAxis, momCosAxis}); + } + if (replKstar) { + histos.add("moment/kstar/hXD", "K*: #Sigma cos 2(#Psi_{target} - #Psi_{donor}), replacement ME", HistType::kTHnSparseD, {momMassAxis, momPtAxis, momCentAxis, momSampleAxis, momSubAxis}); + } + if (doprocessMCClosureReplacementME) { + histos.add("moment/kstar/hXC", "K*: #Sigma cos 2(#Psi^{EP}_{target} - #Psi^{RP}_{donor}), MC replacement ME", HistType::kTHnSparseD, {momMassAxis, momPtAxis, momCentAxis, momSampleAxis, momSubAxis}); + } + } + if (momentPhi) { + const AxisSpec momMassAxis{candCfg.axisMassPhi, "#it{M}_{KK} (GeV/#it{c}^{2})"}; + histos.add("moment/phi/hX0", "#phi: #Sigma 1", HistType::kTHnSparseD, {momMassAxis, momPtAxis, momCentAxis, momSampleAxis, momSubAxis}); + histos.add("moment/phi/hX2", "#phi: #Sigma cos^{2}#theta*", HistType::kTHnSparseD, {momMassAxis, momPtAxis, momCentAxis, momSampleAxis, momSubAxis}); + histos.add("moment/phi/hX4", "#phi: #Sigma cos^{4}#theta*", HistType::kTHnSparseD, {momMassAxis, momPtAxis, momCentAxis, momSampleAxis, momSubAxis}); + if (moment.fillCosThetaStar) { + histos.add("moment/phi/hCosThetaStar", "#phi: cos#theta* (SE/ME ratio fit)", HistType::kTHnSparseD, {momMassAxis, momPtAxis, momCentAxis, momSampleAxis, momCosAxis}); + } + if (replPhi) { + histos.add("moment/phi/hXD", "#phi: #Sigma cos 2(#Psi_{target} - #Psi_{donor}), replacement ME", HistType::kTHnSparseD, {momMassAxis, momPtAxis, momCentAxis, momSampleAxis, momSubAxis}); + } + if (doprocessMCClosureReplacementMEPhi) { + histos.add("moment/phi/hXC", "#phi: #Sigma cos 2(#Psi^{EP}_{target} - #Psi^{RP}_{donor}), MC replacement ME", HistType::kTHnSparseD, {momMassAxis, momPtAxis, momCentAxis, momSampleAxis, momSubAxis}); + } + } + if (replKstar || replPhi) { + if (cfgSAFrame.value == kProductionPlane) { + LOGF(fatal, "The replacement ME projects the donor decay on the target event plane; it needs cfgSAFrame = 0 (event plane), 2 (random event plane) or 3 (random 3D direction)"); + } + if (moment.replNDraws.value < 1 || moment.replCellCapacity.value < 1 || moment.replPtWidth.value <= 0.f || moment.replEtaWidth.value <= 0.f || moment.replPhiWidth.value <= 0.f) { + LOGF(fatal, "Replacement ME: replNDraws and replCellCapacity must be >= 1 and the matching cell widths > 0"); + } + histos.add("moment/hReplCos2DeltaPsi", "Replacement ME: target vs donor plane;centrality (%);cos 2(#Psi_{target} - #Psi_{donor})", kTH2F, {centAxis, {200, -1.0, 1.0}}); + if (replKstar) { + histos.add("moment/kstar/hReplacement", "K* replacement ME;;target candidates", kTH1F, {{2, -0.5, 1.5}}); + auto hRepl = histos.get(HIST("moment/kstar/hReplacement")); + hRepl->GetXaxis()->SetBinLabel(1, "replaced"); + hRepl->GetXaxis()->SetBinLabel(2, "no donor in cell"); + } + if (replPhi) { + histos.add("moment/phi/hReplacement", "#phi replacement ME;;target candidates", kTH1F, {{2, -0.5, 1.5}}); + auto hRepl = histos.get(HIST("moment/phi/hReplacement")); + hRepl->GetXaxis()->SetBinLabel(1, "replaced"); + hRepl->GetXaxis()->SetBinLabel(2, "no donor in cell"); + } + } + if (doprocessMomentDerivedSE || mcRefKstar || mcRefPhi) { + histos.add("moment/ResFT0CTPC", "ResFT0CTPC", kTH2F, {centAxis, resAxis}); + histos.add("moment/ResFT0CFT0A", "ResFT0CFT0A", kTH2F, {centAxis, resAxis}); + histos.add("moment/ResFT0ATPC", "ResFT0ATPC", kTH2F, {centAxis, resAxis}); + } + if (mcRefKstar || mcRefPhi) { + if (moment.mcRefRho00.value < 0.f || moment.mcRefRho00.value > 1.f) { + LOGF(fatal, "moment.mcRefRho00 = %f is outside [0,1]", moment.mcRefRho00.value); + } + histos.add("moment/hResMCTrueRef", "MC reference events;centrality (%);cos 2(#Psi_{EP} - #Psi_{RP})", kTH2F, {centAxis, resAxis}); + histos.add("moment/hResMCTrueTest", "MC test events;centrality (%);cos 2(#Psi_{EP} - #Psi_{RP})", kTH2F, {centAxis, resAxis}); + } + } + if (doprocessEvtLossSigLossMC) { const AxisSpec impactParAxis{evtSigLoss.axisImpactPar, "Impact parameter (fm)"}; const AxisSpec multMCAxis{evtSigLoss.axisMultMC, "N_{ch}^{gen} (|#eta| < 0.5)"}; const AxisSpec centLossAxis{100, 0.0, 100.0, "Centrality FT0C (%)"}; const AxisSpec ptKstarAxis{configThnAxisPt, "#it{p}_{T} (GeV/#it{c})"}; const AxisSpec ptPhiAxis{phiSA.configThnAxisPt, "#it{p}_{T} (GeV/#it{c})"}; + const AxisSpec cosLossAxis{evtSigLoss.axisCosThetaStar, "cos(#vartheta*)"}; histos.add("evtSigLoss/MCEventHist", "MC event statistics", kTH1F, {{4, 0.5, 4.5}}); auto hstat = histos.get(HIST("evtSigLoss/MCEventHist")); hstat->GetXaxis()->SetBinLabel(1, "All MC events"); hstat->GetXaxis()->SetBinLabel(2, "MC events with selected reco event"); hstat->GetXaxis()->SetBinLabel(3, "MC events with no reco event"); hstat->GetXaxis()->SetBinLabel(4, "MC events with >1 reco event"); - // event loss histos.add("evtSigLoss/hImpactParameterGen", "Impact parameter, all generated events", kTH1F, {impactParAxis}); histos.add("evtSigLoss/hImpactParameterRec", "Impact parameter, generated events with selected reco event", kTH1F, {impactParAxis}); histos.add("evtSigLoss/hImpactParameterGenNoReco", "Impact parameter, generated events with no reco event", kTH1F, {impactParAxis}); @@ -512,75 +569,19 @@ struct Kstarpbpb { histos.add("evtSigLoss/hMultEta05Rec", "N_{ch}^{gen}, generated events with selected reco event", kTH1F, {multMCAxis}); histos.add("evtSigLoss/hMultEta05GenNoReco", "N_{ch}^{gen}, generated events with no reco event", kTH1F, {multMCAxis}); histos.add("evtSigLoss/hMultEta05VsCentRec", "N_{ch}^{gen} vs centrality of the selected reco event", kTH2F, {centLossAxis, multMCAxis}); - // signal loss: K*0 + anti-K*0 - histos.add("evtSigLoss/hKstarGenBeforeEvtSel", "Generated K*0, all events", kTH2F, {ptKstarAxis, impactParAxis}); - histos.add("evtSigLoss/hKstarGenAfterEvtSel", "Generated K*0, events with selected reco event", kTH2F, {ptKstarAxis, impactParAxis}); - histos.add("evtSigLoss/hKstarGenVsMultBeforeEvtSel", "Generated K*0, all events", kTH2F, {ptKstarAxis, multMCAxis}); - histos.add("evtSigLoss/hKstarGenVsMultAfterEvtSel", "Generated K*0, events with selected reco event", kTH2F, {ptKstarAxis, multMCAxis}); - histos.add("evtSigLoss/hKstarGenAfterEvtSelVsCent", "Generated K*0, events with selected reco event", kTH2F, {ptKstarAxis, centLossAxis}); - // signal loss: phi(1020) - histos.add("evtSigLoss/hPhiGenBeforeEvtSel", "Generated phi, all events", kTH2F, {ptPhiAxis, impactParAxis}); - histos.add("evtSigLoss/hPhiGenAfterEvtSel", "Generated phi, events with selected reco event", kTH2F, {ptPhiAxis, impactParAxis}); - histos.add("evtSigLoss/hPhiGenVsMultBeforeEvtSel", "Generated phi, all events", kTH2F, {ptPhiAxis, multMCAxis}); - histos.add("evtSigLoss/hPhiGenVsMultAfterEvtSel", "Generated phi, events with selected reco event", kTH2F, {ptPhiAxis, multMCAxis}); - histos.add("evtSigLoss/hPhiGenAfterEvtSelVsCent", "Generated phi, events with selected reco event", kTH2F, {ptPhiAxis, centLossAxis}); - } - - // MC closure test of the cos(theta*) chain - if (doprocessMCClosure || doprocessMCClosureME || doprocessMCClosurePhi || doprocessMCClosureMEPhi) { - if (closure.rho00Inj.value < 0.f || closure.rho00Inj.value > 1.f) { - LOGF(fatal, "closure.rho00Inj = %f is outside [0,1]", closure.rho00Inj.value); - } - const AxisSpec cosAxisClosure{closure.axisCosThetaStar, "cos(#vartheta*)"}; - const AxisSpec cosFineAxis{100, -1.0, 1.0, "cos(#vartheta*)"}; - if (doprocessMCClosure || doprocessMCClosureME) { - const AxisSpec massAxis{configThnAxisInvMass, "#it{M}_{K#pi} (GeV/#it{c}^{2})"}; - const AxisSpec ptAxis{configThnAxisPt, "#it{p}_{T} (GeV/#it{c})"}; - const AxisSpec centAxisClosureKstar{configThnAxisCentrality, "Centrality (%)"}; - if (doprocessMCClosure) { - // bins: 0 all MC events, 1 no reco event, 2 more than one reco event, 3 selected (eff sample), 4 selected (test sample) - histos.add("closureKstar/hMC", "MC event statistics", kTH1F, {{5, 0.0f, 5.0f}}); - // Acc x Eff sample - histos.add("closureKstar/hSparseGenEff", "Generated K*, efficiency sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosureKstar}, true); - histos.add("closureKstar/hSparseRecTrueEff", "Reconstructed true K*, efficiency sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosureKstar}, true); - // test sample - histos.add("closureKstar/hSparseGen", "Generated K* (input), test sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosureKstar}, true); - histos.add("closureKstar/hSparseRecTrue", "Reconstructed true K*, test sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosureKstar}, true); - histos.add("closureKstar/hSparseSE", "Same-event unlike-sign K#pi pairs, test sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosureKstar}, true); - if (closure.fillRotBkg) { - histos.add("closureKstar/hSparseRot", "Rotated unlike-sign K#pi pairs, test sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosureKstar}, true); - } - histos.add("closureKstar/hCosThetaStarGenVsRec", "cos(#vartheta*) gen vs rec, true K*", kTH2F, {cosFineAxis, cosFineAxis}); - } - if (doprocessMCClosureME) { - histos.add("closureKstar/hSparseME", "Mixed-event unlike-sign K#pi pairs, test sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosureKstar}, true); - } - } - if (doprocessMCClosurePhi || doprocessMCClosureMEPhi) { - const AxisSpec massAxis{phiSA.configThnAxisInvMass, "#it{M}_{KK} (GeV/#it{c}^{2})"}; - const AxisSpec ptAxis{phiSA.configThnAxisPt, "#it{p}_{T} (GeV/#it{c})"}; - const AxisSpec centAxisClosurePhi{phiSA.configThnAxisCentrality, "Centrality (%)"}; - if (doprocessMCClosurePhi) { - histos.add("closurePhi/hMC", "MC event statistics", kTH1F, {{5, 0.0f, 5.0f}}); - histos.add("closurePhi/hSparseGenEff", "Generated phi, efficiency sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosurePhi}, true); - histos.add("closurePhi/hSparseRecTrueEff", "Reconstructed true phi, efficiency sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosurePhi}, true); - histos.add("closurePhi/hSparseGen", "Generated phi (input), test sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosurePhi}, true); - histos.add("closurePhi/hSparseRecTrue", "Reconstructed true phi, test sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosurePhi}, true); - histos.add("closurePhi/hSparseSE", "Same-event K^{+}K^{-} pairs, test sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosurePhi}, true); - if (closure.fillRotBkg) { - histos.add("closurePhi/hSparseRot", "Rotated K^{+}K^{-} pairs, test sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosurePhi}, true); - } - histos.add("closurePhi/hCosThetaStarGenVsRec", "cos(#vartheta*) gen vs rec, true phi", kTH2F, {cosFineAxis, cosFineAxis}); - } - if (doprocessMCClosureMEPhi) { - histos.add("closurePhi/hSparseME", "Mixed-event K^{+}K^{-} pairs, test sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosurePhi}, true); - } - } - } - - // MC closure test of the cos(theta*) chain, using the reconstructed (finite-resolution) Psi_FT0C instead of the MC true event plane. - // Needs EPCalibrationTables on the MC sample (i.e. the epvector producer run on it), unlike the true-EP closure above. - if (doprocessMCClosureRecoEP || doprocessMCClosureMERecoEP || doprocessMCClosureRecoEPPhi || doprocessMCClosureMERecoEPPhi) { + histos.add("evtSigLoss/hKstarGenBeforeEvtSel", "Generated K*0, all events", kTH3F, {ptKstarAxis, cosLossAxis, impactParAxis}); + histos.add("evtSigLoss/hKstarGenAfterEvtSel", "Generated K*0, events with selected reco event", kTH3F, {ptKstarAxis, cosLossAxis, impactParAxis}); + histos.add("evtSigLoss/hKstarGenVsMultBeforeEvtSel", "Generated K*0, all events", kTH3F, {ptKstarAxis, cosLossAxis, multMCAxis}); + histos.add("evtSigLoss/hKstarGenVsMultAfterEvtSel", "Generated K*0, events with selected reco event", kTH3F, {ptKstarAxis, cosLossAxis, multMCAxis}); + histos.add("evtSigLoss/hKstarGenAfterEvtSelVsCent", "Generated K*0, events with selected reco event", kTH3F, {ptKstarAxis, cosLossAxis, centLossAxis}); + histos.add("evtSigLoss/hPhiGenBeforeEvtSel", "Generated phi, all events", kTH3F, {ptPhiAxis, cosLossAxis, impactParAxis}); + histos.add("evtSigLoss/hPhiGenAfterEvtSel", "Generated phi, events with selected reco event", kTH3F, {ptPhiAxis, cosLossAxis, impactParAxis}); + histos.add("evtSigLoss/hPhiGenVsMultBeforeEvtSel", "Generated phi, all events", kTH3F, {ptPhiAxis, cosLossAxis, multMCAxis}); + histos.add("evtSigLoss/hPhiGenVsMultAfterEvtSel", "Generated phi, events with selected reco event", kTH3F, {ptPhiAxis, cosLossAxis, multMCAxis}); + histos.add("evtSigLoss/hPhiGenAfterEvtSelVsCent", "Generated phi, events with selected reco event", kTH3F, {ptPhiAxis, cosLossAxis, centLossAxis}); + } + + if (doprocessMCClosureRecoEP || doprocessMCClosureMERecoEP || doprocessMCClosureRecoEPPhi || doprocessMCClosureMERecoEPPhi || doprocessMCClosureReplacementME || doprocessMCClosureReplacementMEPhi) { if (closure.rho00Inj.value < 0.f || closure.rho00Inj.value > 1.f) { LOGF(fatal, "closure.rho00Inj = %f is outside [0,1]", closure.rho00Inj.value); } @@ -591,12 +592,9 @@ struct Kstarpbpb { const AxisSpec ptAxis{configThnAxisPt, "#it{p}_{T} (GeV/#it{c})"}; const AxisSpec centAxisClosureKstar{configThnAxisCentrality, "Centrality (%)"}; if (doprocessMCClosureRecoEP) { - // bins: 0 all MC events, 1 no reco event, 2 more than one reco event, 3 selected (eff sample), 4 selected (test sample) histos.add("closureKstarRecoEP/hMC", "MC event statistics", kTH1F, {{5, 0.0f, 5.0f}}); - // Acc x Eff sample histos.add("closureKstarRecoEP/hSparseGenEff", "Generated K*, efficiency sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosureKstar}, true); histos.add("closureKstarRecoEP/hSparseRecTrueEff", "Reconstructed true K*, efficiency sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosureKstar}, true); - // test sample histos.add("closureKstarRecoEP/hSparseGen", "Generated K* (input), test sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosureKstar}, true); histos.add("closureKstarRecoEP/hSparseRecTrue", "Reconstructed true K*, test sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosureKstar}, true); histos.add("closureKstarRecoEP/hSparseSE", "Same-event unlike-sign K#pi pairs, test sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosureKstar}, true); @@ -604,15 +602,12 @@ struct Kstarpbpb { histos.add("closureKstarRecoEP/hSparseRot", "Rotated unlike-sign K#pi pairs, test sample", HistType::kTHnSparseD, {massAxis, ptAxis, cosAxisClosure, centAxisClosureKstar}, true); } histos.add("closureKstarRecoEP/hCosThetaStarGenVsRec", "cos(#vartheta*) gen vs rec, true K*", kTH2F, {cosFineAxis, cosFineAxis}); - // sub-event resolution of the closure sample, needed to derive R2 and un-smear rho00 downstream; same definition as the data ResFT0C*SP histos.add("closureKstarRecoEP/ResFT0CTPCSP", "ResFT0CTPCSP", kTH2F, {centAxis, resAxis}); histos.add("closureKstarRecoEP/ResFT0CFT0ASP", "ResFT0CFT0ASP", kTH2F, {centAxis, resAxis}); histos.add("closureKstarRecoEP/ResFT0ATPCSP", "ResFT0ATPCSP", kTH2F, {centAxis, resAxis}); - // plain (unweighted) sub-event resolution, as needed by the EP-method correction formula; same definition as the data ResFT0CTPC etc. histos.add("closureKstarRecoEP/ResFT0CTPC", "ResFT0CTPC", kTH2F, {centAxis, resAxis}); histos.add("closureKstarRecoEP/ResFT0CFT0A", "ResFT0CFT0A", kTH2F, {centAxis, resAxis}); histos.add("closureKstarRecoEP/ResFT0ATPC", "ResFT0ATPC", kTH2F, {centAxis, resAxis}); - // closure-only: Psi_FT0C vs the MC true event plane, to cross-check R from sub-events against the true R histos.add("closureKstarRecoEP/ResTrueFT0C", "ResTrueFT0C", kTH2F, {centAxis, resAxis}); } if (doprocessMCClosureMERecoEP) { @@ -647,12 +642,6 @@ struct Kstarpbpb { } } } - - ccdb->setURL(cfgCcdbParam.cfgURL); - ccdbApi.init("http://alice-ccdb.cern.ch"); - ccdb->setCaching(true); - ccdb->setLocalObjectValidityChecking(); - ccdb->setCreatedNotAfter(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()); } static constexpr double MassKa = o2::constants::physics::MassKPlus; @@ -764,31 +753,41 @@ struct Kstarpbpb { while (result < 0) { result += o2::constants::math::PI; } - while (result >= o2::constants::math::PI) { // >= not > + while (result >= o2::constants::math::PI) { result -= o2::constants::math::PI; } return result; } - // event-level plane angle for SA: reconstructed Psi2 (event plane) or a random angle (random event plane) + bool isRandomFrame() const + { + return cfgSAFrame.value == kRandomEventPlane || cfgSAFrame.value == kRandom3D; + } + + ROOT::Math::XYZVector getRandom3DAxis() + { + const double cosTheta = rndGen.Uniform(-1., 1.); + const double sinTheta = std::sqrt(1. - cosTheta * cosTheta); + const double phi = rndGen.Uniform(0., o2::constants::math::TwoPI); + return {sinTheta * std::cos(phi), sinTheta * std::sin(phi), cosTheta}; + } + double getSAEventAngle(double psiEP) { - if (cfgSAFrame.value == kRandomEventPlane) { + if (isRandomFrame()) { return rndGen.Uniform(-o2::constants::math::PIHalf, o2::constants::math::PIHalf); } return psiEP; } - // in-plane angle of the SA plane, used for the cos(2(phi* - Psi)) variable double getSAPlaneAngle(const ROOT::Math::PxPyPzMVector& mother, double psiSA) { if (cfgSAFrame.value == kProductionPlane) { - return mother.Phi(); // production plane is spanned by the beam axis and the mother momentum + return mother.Phi(); } return psiSA; } - // phi(1020) -> K+K- with one kaon taken as the pion: true if the KK mass is inside the veto window (always false if cfgPhiVeto is off) bool isPhiReflection(const ROOT::Math::PxPyPzMVector& kaon, const ROOT::Math::PxPyPzMVector& pion) { if (!cfgPhiVeto) { @@ -799,23 +798,55 @@ struct Kstarpbpb { return std::abs((kaonAsKaon + pionAsKaon).M() - o2::constants::physics::MassPhi) < cfgPhiVetoWindow; } - // quantization axis = normal to the SA plane + ROOT::Math::XYZVector getEPAxis(double psiSA) + { + return {std::sin(psiSA), -std::cos(psiSA), 0.}; + } + ROOT::Math::XYZVector getSAAxis(const ROOT::Math::PxPyPzMVector& mother, double psiSA) { if (cfgSAFrame.value == kProductionPlane) { - return ROOT::Math::XYZVector(0., 0., 1.).Cross(mother.Vect()).Unit(); // z x p + return ROOT::Math::XYZVector(0., 0., 1.).Cross(mother.Vect()).Unit(); + } + if (cfgSAFrame.value == kRandom3D) { + return getRandom3DAxis(); + } + return getEPAxis(psiSA); + } + + int getMomentSubsample(int64_t eventIndex) + { + return static_cast(eventIndex % moment.nSubsamples.value); + } + + template + void fillMoments(double mass, double pt, double centrality, int sample, int subsample, double cosThetaStar, double weight = 1.0) + { + const double x2 = cosThetaStar * cosThetaStar; + const double x4 = x2 * x2; + if constexpr (IsPhi) { + histos.fill(HIST("moment/phi/hX0"), mass, pt, centrality, sample, subsample, weight); + histos.fill(HIST("moment/phi/hX2"), mass, pt, centrality, sample, subsample, weight * x2); + histos.fill(HIST("moment/phi/hX4"), mass, pt, centrality, sample, subsample, weight * x4); + if (moment.fillCosThetaStar) { + histos.fill(HIST("moment/phi/hCosThetaStar"), mass, pt, centrality, sample, cosThetaStar, weight); + } + } else { + histos.fill(HIST("moment/kstar/hX0"), mass, pt, centrality, sample, subsample, weight); + histos.fill(HIST("moment/kstar/hX2"), mass, pt, centrality, sample, subsample, weight * x2); + histos.fill(HIST("moment/kstar/hX4"), mass, pt, centrality, sample, subsample, weight * x4); + if (moment.fillCosThetaStar) { + histos.fill(HIST("moment/kstar/hCosThetaStar"), mass, pt, centrality, sample, cosThetaStar, weight); + } } - return {std::sin(cfgEPNormalHarmonic.value * psiSA), -std::cos(cfgEPNormalHarmonic.value * psiSA), 0.}; } - // ---------------- event selection, common to all K* and phi(1020) process functions ---------------- template bool selectionEventRCT(const TCollision& collision) { return !rctCut.requireRCTFlagChecker || rctCut.rctChecker(collision); } - // additionalEvSel1-4 (data and reconstructed MC) template bool selectionEventBits(const TCollision& collision) { @@ -834,21 +865,18 @@ struct Kstarpbpb { return true; } - // sel8, EP trigger and additionalEvSel1-4 template bool selectionEventCuts(const TCollision& collision) { return collision.sel8() && collision.triggereventep() && selectionEventBits(collision); } - // full data event selection template bool selectionEvent(const TCollision& collision) { return selectionEventRCT(collision) && selectionEventCuts(collision); } - // mixed-event pair: both events selected and not from the same bunch crossing template bool selectionEventPairME(const TCollision& collision1, const TCollision& collision2) { @@ -858,8 +886,6 @@ struct Kstarpbpb { return collision1.bcId() != collision2.bcId(); } - // ---------------- phi(1020) track and PID selections, identical to phianalysisrun3pbpb.cxx ---------------- - template bool selectionTrackPhi(const T& candidate) { @@ -872,7 +898,6 @@ struct Kstarpbpb { return true; } - // kaon PID: circular TPC-TOF cut if TOF is present, TPC-only otherwise (or always, if isNoTOF) template bool selectionPIDPhi(const T& candidate) { @@ -888,14 +913,13 @@ struct Kstarpbpb { return false; } - // deep angle cut on pair to remove photon conversion template bool selectionPairPhi(const T1& candidate1, const T2& candidate2) { double pt1 = candidate1.pt(), pt2 = candidate2.pt(); double pz1 = candidate1.pz(), pz2 = candidate2.pz(); double p1 = candidate1.p(), p2 = candidate2.p(); - double angle = std::acos(std::clamp((pt1 * pt2 + pz1 * pz2) / (p1 * p2), -1.0, 1.0)); // clamp = TMath::ACos behaviour + double angle = std::acos(std::clamp((pt1 * pt2 + pz1 * pz2) / (p1 * p2), -1.0, 1.0)); return !phiSA.isDeepAngle || angle >= phiSA.cfgDeepAngle; } @@ -905,8 +929,6 @@ struct Kstarpbpb { return std::abs(track.p() - track.tpcInnerParam()) > phiSA.confFakeKaonCut; } - // phipbpb.cxx builds the EP-frame MC efficiency with the in-plane vector at Psi = 0 (x axis); kept for identical results - // with mcEffEP.psiSource = 0 only. With an event-by-event Psi the axis must be the plane normal, as in data (getSAAxis). ROOT::Math::XYZVector getSAAxisPhiMC(const ROOT::Math::PxPyPzMVector& mother, double psiSA) { if (cfgSAFrame.value == kEventPlane && mcEffEP.psiSource == 0) { @@ -915,7 +937,6 @@ struct Kstarpbpb { return getSAAxis(mother, psiSA); } - // Psi2 = atan2(Q2y, Q2x) / 2 from the generated charged physical primaries in [etaMin, etaMax] (thesis Eq. B.16, unit weights) template double getGenPsi2(TParticles const& particles) { @@ -934,7 +955,6 @@ struct Kstarpbpb { return 0.5 * std::atan2(qy, qx); } - // Psi of the EP-frame MC efficiency, one per MC event (see mcEffEP) template double getMCEffPsi(TMcCollision const& mcCollision, TParticles const& particles) { @@ -947,14 +967,6 @@ struct Kstarpbpb { return 0.0; } - template - bool isFakeKaon(T const& track, int /*PID*/) - { - const auto pglobal = track.p(); - const auto ptpc = track.tpcInnerParam(); - return std::abs(pglobal - ptpc) > confFakeKaonCut; - } - static constexpr float HalfPI = o2::constants::math::PI * 0.5f; ConfigurableAxis axisVertex{"axisVertex", {20, -10, 10}, "vertex axis for bin"}; ConfigurableAxis axisMultiplicityClass{"axisMultiplicityClass", {20, 0, 100}, "multiplicity percentile for bin"}; @@ -964,12 +976,8 @@ struct Kstarpbpb { using BinningTypeVertexContributor = ColumnBinningPolicy; - int currentRunNumber = -999; - int lastRunNumber = -999; - TH2D* hweight = nullptr; - void processSE(EventCandidates::iterator const& collision, TrackCandidates const& tracks, aod::BCsWithTimestamps const&) + void processSE(EventCandidates::iterator const& collision, TrackCandidates const& tracks) { - // scratch vectors: local to this call, never carry state across events/tracks ROOT::Math::PxPyPzMVector kstarMother, fourVecDauCM, daughter1, daughter2, kaonrot, kstarrot; ROOT::Math::XYZVector threeVecDauCM, threeVecDauCMXY, eventplaneVecNorm; ROOT::Math::PxPyPzMVector fourVecDauCMrot; @@ -1015,19 +1023,10 @@ struct Kstarpbpb { histos.fill(HIST("hQTPCvsCent"), centrality, qTPC); histos.fill(HIST("hQTPCvsVz"), collision.posZ(), qTPC); } - // one angle per event: Psi2 from FT0C, or a random angle for the random-EP null test auto psiSA = getSAEventAngle(psiFT0C); - if (fillSA && cfgSAFrame.value == kRandomEventPlane) { + if (fillSA && isRandomFrame()) { histos.fill(HIST("hPsiRandom"), centrality, psiSA); } - auto bc = collision.bc_as(); - currentRunNumber = collision.bc_as().runNumber(); - if (useWeight && (currentRunNumber != lastRunNumber)) { - hweight = ccdb->getForTimeStamp(confWeightPath.value, bc.timestamp()); - } - lastRunNumber = currentRunNumber; - float weight1 = 1.0; - float weight2 = 1.0; for (const auto& track1 : tracks) { if (!selectionTrack(track1)) { continue; @@ -1040,15 +1039,6 @@ struct Kstarpbpb { if (isTOFOnly && !selectionPID2(track1, 0)) { continue; } - - if (useWeight) { - if (track1.pt() < cfgMaxTrackPt && - track1.pt() > cfgMinTrackPt) { - weight1 = 1 + hweight->GetBinContent(hweight->FindBin(centrality, track1.pt() + 0.000005)) * std::cos(2.0 * getPhiInRange(track1.phi() - psiFT0C)); - } else { - weight1 = 1; - } - } for (const auto& track2 : tracks) { if (!selectionTrack(track2)) { continue; @@ -1078,21 +1068,13 @@ struct Kstarpbpb { histos.fill(HIST("QAafter/trkDCAxypi"), track2.dcaXY()); histos.fill(HIST("QAafter/trkDCAzpi"), track2.dcaZ()); } - if (useWeight) { - if (track2.pt() < cfgMaxTrackPt && - track2.pt() > cfgMinTrackPt) { - weight2 = 1 + hweight->GetBinContent(hweight->FindBin(centrality, track2.pt() + 0.000005)) * std::cos(2.0 * getPhiInRange(track2.phi() - psiFT0C)); - } else { - weight2 = 1; - } - } daughter1 = ROOT::Math::PxPyPzMVector(track1.px(), track1.py(), track1.pz(), MassKa); daughter2 = ROOT::Math::PxPyPzMVector(track2.px(), track2.py(), track2.pz(), MassPi); kstarMother = daughter1 + daughter2; if (std::abs(kstarMother.Rapidity()) > confRapidity) { continue; } - if (isPhiReflection(daughter1, daughter2)) { // phi(1020) veto (cfgPhiVeto); also skips the rotations of this pair + if (isPhiReflection(daughter1, daughter2)) { continue; } auto phiMinusPsi = getPhiInRange(kstarMother.Phi() - psiFT0C); @@ -1103,23 +1085,13 @@ struct Kstarpbpb { if (!useSP) { v2 = std::cos(2.0 * phiMinusPsi); } - auto totalweight = weight1 * weight2; - static constexpr float MinTotalWeight = 5e-7f; - if (totalweight <= MinTotalWeight) { - totalweight = 1.0; - } if (additionalQAplots1) { histos.fill(HIST("ResTrackSPFT0CTPC"), centrality, qFT0C * qTPC * std::cos(2.0 * (psiFT0C - psiTPC))); histos.fill(HIST("ResTrackSPFT0CFT0A"), centrality, qFT0C * qFT0A * std::cos(2.0 * (psiFT0C - psiFT0A))); histos.fill(HIST("ResTrackSPFT0ATPC"), centrality, qTPC * qFT0A * std::cos(2.0 * (psiTPC - psiFT0A))); } if (!fillSA) { - - if (useWeight) { - histos.fill(HIST("hSparseV2SASameEvent_V2"), kstarMother.M(), kstarMother.Pt(), v2, centrality, 1 / totalweight); - } else { - histos.fill(HIST("hSparseV2SASameEvent_V2"), kstarMother.M(), kstarMother.Pt(), v2, centrality); - } + histos.fill(HIST("hSparseV2SASameEvent_V2"), kstarMother.M(), kstarMother.Pt(), v2, centrality); } int track1Sign = track1.sign(); int track2Sign = track2.sign(); @@ -1143,10 +1115,6 @@ struct Kstarpbpb { auto sa = std::cos(2.0 * cosPhistarminuspsi); auto cosThetaStar = eventplaneVecNorm.Dot(threeVecDauCM) / std::sqrt(threeVecDauCM.Mag2()) / std::sqrt(eventplaneVecNorm.Mag2()); - if (doClosureTest && track1Sign * track2Sign < 0) { - histos.fill(HIST("closure/KstarSameEventCosThetaStar"), kstarMother.M(), kstarMother.Pt(), cosThetaStar, std::abs(kstarMother.Rapidity()), centrality); - } - if (track1Sign * track2Sign < 0) { if (usepolar) { histos.fill(HIST("hSparseSAvsrapsameunlike"), kstarMother.M(), kstarMother.Pt(), cosThetaStar, kstarMother.Rapidity(), centrality); @@ -1177,7 +1145,7 @@ struct Kstarpbpb { if (std::abs(kstarrot.Rapidity()) > confRapidity) { continue; } - if (isPhiReflection(kaonrot, daughter2)) { // phi(1020) veto (cfgPhiVeto) on the rotated pair + if (isPhiReflection(kaonrot, daughter2)) { continue; } auto phiMinusPsiRot = getPhiInRange(kstarrot.Phi() - psiFT0C); @@ -1197,7 +1165,6 @@ struct Kstarpbpb { fourVecDauCMrot = boost(kaonrot); threeVecDauCMrot = fourVecDauCMrot.Vect(); threeVecDauCMXYrot = ROOT::Math::XYZVector(threeVecDauCMrot.X(), threeVecDauCMrot.Y(), 0.); - // production-plane axis must follow the rotated candidate auto saAxisRot = getSAAxis(kstarrot, psiSA); auto cosPhistarminuspsirot = getPhiInRange(fourVecDauCMrot.Phi() - getSAPlaneAngle(kstarrot, psiSA)); auto sarot = std::cos(2.0 * cosPhistarminuspsirot); @@ -1214,11 +1181,10 @@ struct Kstarpbpb { } } } - PROCESS_SWITCH(Kstarpbpb, processSE, "Process Same event latest", true); + PROCESS_SWITCH(Kstarpbpb, processSE, "K* AO2D: same event (SA or v2 sparses)", true); void processMixedEvent(EventCandidates const& collisions, TrackCandidates const& tracks) { - // scratch vectors: local to this call, never carry state across pairs ROOT::Math::PxPyPzMVector kstarMother, fourVecDauCM, daughter1, daughter2; ROOT::Math::XYZVector threeVecDauCM, threeVecDauCMXY, eventplaneVecNorm; double v2 = 0.; @@ -1262,7 +1228,7 @@ struct Kstarpbpb { if (std::abs(kstarMother.Rapidity()) > confRapidity) { continue; } - if (isPhiReflection(daughter1, daughter2)) { // phi(1020) veto (cfgPhiVeto), same as in the same event + if (isPhiReflection(daughter1, daughter2)) { continue; } @@ -1294,9 +1260,6 @@ struct Kstarpbpb { auto cosPhistarminuspsi = getPhiInRange(fourVecDauCM.Phi() - getSAPlaneAngle(kstarMother, psiSA1)); auto sa = std::cos(2.0 * cosPhistarminuspsi); auto cosThetaStar = eventplaneVecNorm.Dot(threeVecDauCM) / std::sqrt(threeVecDauCM.Mag2()) / std::sqrt(eventplaneVecNorm.Mag2()); - if (doClosureTest) { - histos.fill(HIST("closure/KstarMixedEventCosThetaStar"), kstarMother.M(), kstarMother.Pt(), cosThetaStar, std::abs(kstarMother.Rapidity()), centrality); - } if (usepolar) { histos.fill(HIST("hSparseSAvsrapmix"), kstarMother.M(), kstarMother.Pt(), cosThetaStar, kstarMother.Rapidity(), centrality); } else { @@ -1314,11 +1277,10 @@ struct Kstarpbpb { } } } - PROCESS_SWITCH(Kstarpbpb, processMixedEvent, "Process Mixed event", true); + PROCESS_SWITCH(Kstarpbpb, processMixedEvent, "K* AO2D: mixed event (combinatorial background, SA or v2 sparses)", true); void processMC(CollisionMCTrueTable::iterator const& TrueCollision, CollisionMCRecTableCentFT0C const& RecCollisions, TrackMCTrueTable const& GenParticles, FilTrackMCRecTable const& RecTracks) { - // scratch vectors: local to this call, never carry state across particles ROOT::Math::PxPyPzMVector kstarMother, kaonPlus, pionMinus; double v2 = 0.; @@ -1332,7 +1294,7 @@ struct Kstarpbpb { return; } for (const auto& RecCollision : RecCollisions) { - auto psiFT0C = getMCEffPsi(TrueCollision, GenParticles); // one Psi per MC event (mcEffEP.psiSource; 0 = old fixed Psi = 0) + auto psiFT0C = getMCEffPsi(TrueCollision, GenParticles); histos.fill(HIST("hMC"), 3); if (!RecCollision.sel8()) { histos.fill(HIST("hMC"), 4); @@ -1349,11 +1311,10 @@ struct Kstarpbpb { histos.fill(HIST("hMC"), 7); auto centrality = RecCollision.centFT0C(); histos.fill(HIST("CentPercentileMCRecHist"), centrality); - auto psiSA = getSAEventAngle(psiFT0C); // same angle for rec and gen of this event + auto psiSA = getSAEventAngle(psiFT0C); histos.fill(HIST("hMCEffPsi"), centrality, psiSA); auto oldindex = -999; auto rectrackspart = RecTracks.sliceBy(perCollision, RecCollision.globalIndex()); - // loop over reconstructed particle for (const auto& track1 : rectrackspart) { if (!selectionTrack(track1)) { continue; @@ -1370,8 +1331,6 @@ struct Kstarpbpb { auto track1ID = track1.index(); for (const auto& track2 : rectrackspart) { auto track2ID = track2.index(); - // roles are fixed (track1 = kaon candidate, track2 = pion candidate, checked against the MC PDG below), - // so every true K pi pair is found exactly once whatever the track order; only skip the same track if (track2ID == track1ID) { continue; } @@ -1414,7 +1373,6 @@ struct Kstarpbpb { if (std::abs(mothertrack1.y()) > confRapidity) { continue; } - // K*0 and anti-K*0, as in data (all unlike-sign K pi pairs) if (pdgcheck && std::abs(mothertrack1.pdgCode()) != o2::constants::physics::kK0Star892) { continue; } @@ -1428,15 +1386,13 @@ struct Kstarpbpb { continue; } oldindex = mothertrack1.globalIndex(); - // track1 is always the kaon-PID candidate and track2 always the pion-PID candidate (enforced above); - // assign unconditionally so the boost below always uses the true kaon, regardless of its charge sign kaonPlus = ROOT::Math::PxPyPzMVector(track1.px(), track1.py(), track1.pz(), MassKa); pionMinus = ROOT::Math::PxPyPzMVector(track2.px(), track2.py(), track2.pz(), MassPi); kstarMother = kaonPlus + pionMinus; if (std::abs(kstarMother.Rapidity()) > confRapidity) { continue; } - if (isPhiReflection(kaonPlus, pionMinus)) { // phi(1020) veto (cfgPhiVeto), so the efficiency includes the true K* it removes + if (isPhiReflection(kaonPlus, pionMinus)) { continue; } auto phiMinusPsi = getPhiInRange(kstarMother.Phi() - psiFT0C); @@ -1461,20 +1417,15 @@ struct Kstarpbpb { if (mcEffEP.fillPhiVMinusPsi) { histos.fill(HIST("hSparseKstarMCRecCosThetaStarPhiVPsi"), kstarMother.Pt(), cosThetaStarRec, getPhiInRange(kstarMother.Phi() - psiSA), centrality); } - if (doClosureTest) { - histos.fill(HIST("closure/KstarMCRecTrueCosThetaStar"), kstarMother.M(), kstarMother.Pt(), cosThetaStarRec, std::abs(kstarMother.Rapidity()), centrality); - } } } } } } - // loop over generated particle for (const auto& mcParticle : GenParticles) { if (std::abs(mcParticle.y()) > confRapidity) { continue; } - // K*0 and anti-K*0, as in data and in the reconstructed loop above if (pdgcheck && std::abs(mcParticle.pdgCode()) != o2::constants::physics::kK0Star892) { continue; } @@ -1484,8 +1435,6 @@ struct Kstarpbpb { if (kDaughters.size() != NumberOfDaughters) { continue; } - // daughtp = kaon daughter found, daughtm = pion daughter found (either charge: K+ pi- or K- pi+); - // kaonPlus / pionMinus hold the kaon / pion daughter, so the boost uses the kaon as in the reconstructed loop auto daughtp = false; auto daughtm = false; for (const auto& kCurrentDaughter : kDaughters) { @@ -1536,189 +1485,18 @@ struct Kstarpbpb { if (mcEffEP.fillPhiVMinusPsi) { histos.fill(HIST("hSparseKstarMCGenCosThetaStarPhiVPsi"), kstarMother.Pt(), cosThetaStarGen, getPhiInRange(kstarMother.Phi() - psiSA), centrality); } - if (doClosureTest) { - histos.fill(HIST("closure/KstarMCGenCosThetaStar"), kstarMother.M(), kstarMother.Pt(), cosThetaStarGen, std::abs(kstarMother.Rapidity()), centrality); - } } } } - } // rec collision loop - - } // process MC - PROCESS_SWITCH(Kstarpbpb, processMC, "Process MC", false); - - void processMCkstarWeight(CollisionMCTrueTable::iterator const& TrueCollision, CollisionMCRecTableCentFT0C const& RecCollisions, TrackMCTrueTable const& GenParticles, FilTrackMCRecTable const& RecTracks) - { - // scratch vectors: local to this call, never carry state across particles - ROOT::Math::PxPyPzMVector kaonPlus, pionMinus; - - float imp = TrueCollision.impactParameter(); - float evPhi = TrueCollision.eventPlaneAngle() / 2.0; - static constexpr std::array CentEdges = { - 0.0f, 3.49f, 4.93f, 6.98f, 8.55f, - 9.87f, 11.0f, 12.1f, 13.1f, 14.0f}; - - static constexpr std::array CentValues = { - 2.5f, 7.5f, 15.0f, 25.0f, 35.0f, - 45.0f, 55.0f, 65.0f, 75.0f}; - float centclass = -999.f; - - for (size_t i = 0; i < CentValues.size(); ++i) { - if (imp >= CentEdges[i] && imp < CentEdges[i + 1]) { - centclass = CentValues[i]; - break; - } - } - histos.fill(HIST("hImpactParameter"), imp); - histos.fill(HIST("hEventPlaneAngle"), evPhi); - static constexpr float MinCentrality = 0.0f; - static constexpr float MaxCentrality = 80.0f; - - if (centclass < MinCentrality || centclass > MaxCentrality) { - return; } - for (const auto& RecCollision : RecCollisions) { - auto psiFT0C = TrueCollision.eventPlaneAngle(); - /* - if (!RecCollision.sel8()) { - continue; - } - if (!RecCollision.selection_bit(aod::evsel::kNoITSROFrameBorder)) { - continue; - } - */ - if (std::abs(RecCollision.posZ()) > cfgCutVertex) { - continue; - } - auto oldindex = -999; - auto rectrackspart = RecTracks.sliceBy(perCollision, RecCollision.globalIndex()); - // loop over reconstructed particle - for (const auto& track1 : rectrackspart) { - if (!track1.has_mcParticle()) { - continue; - } - - const auto mctrack1 = track1.mcParticle(); - - if (selectionTrack(track1) && strategySelectionPID(track1, 0, strategyPID) && std::abs(mctrack1.pdgCode()) == PDG_t::kKPlus && mctrack1.isPhysicalPrimary()) { - histos.fill(HIST("hSparseKstarMCRecKaonWeight"), centclass, getPhiInRange(mctrack1.phi() - psiFT0C), std::pow(std::cos(2.0 * getPhiInRange(mctrack1.phi() - psiFT0C)), 2.0), mctrack1.pt(), mctrack1.eta()); - } - if (selectionTrack(track1) && track1.pt() > TPCOnlyPt && track1.hasTOF() && std::abs(track1.tofNSigmaKa()) > nsigmaCutTOF && std::abs(track1.tpcNSigmaKa()) < nsigmaCutTPC && std::abs(mctrack1.pdgCode()) == PDG_t::kKPlus && mctrack1.isPhysicalPrimary()) { - histos.fill(HIST("hSparseKstarMCRecKaonMissMatchWeight"), centclass, getPhiInRange(mctrack1.phi() - psiFT0C), std::pow(std::cos(2.0 * getPhiInRange(mctrack1.phi() - psiFT0C)), 2.0), mctrack1.pt(), mctrack1.eta()); - } - if (selectionTrack(track1) && strategySelectionPID(track1, 1, strategyPID) && std::abs(mctrack1.pdgCode()) == PDG_t::kPiPlus && mctrack1.isPhysicalPrimary()) { - histos.fill(HIST("hSparseKstarMCRecPionWeight"), centclass, getPhiInRange(mctrack1.phi() - psiFT0C), std::pow(std::cos(2.0 * getPhiInRange(mctrack1.phi() - psiFT0C)), 2.0), mctrack1.pt(), mctrack1.eta()); - } - if (selectionTrack(track1) && track1.pt() > TPCOnlyPt && track1.hasTOF() && std::abs(track1.tofNSigmaPi()) > nsigmaCutTOF && std::abs(track1.tpcNSigmaPi()) < nsigmaCutTPC && std::abs(mctrack1.pdgCode()) == PDG_t::kPiPlus && mctrack1.isPhysicalPrimary()) { - histos.fill(HIST("hSparseKstarMCRecPionMissMatchWeight"), centclass, getPhiInRange(mctrack1.phi() - psiFT0C), std::pow(std::cos(2.0 * getPhiInRange(mctrack1.phi() - psiFT0C)), 2.0), mctrack1.pt(), mctrack1.eta()); - } - auto track1ID = track1.index(); - for (const auto& track2 : rectrackspart) { - if (!track2.has_mcParticle()) { - continue; - } - auto track2ID = track2.index(); - if (track2ID <= track1ID) { - continue; - } - const auto mctrack2 = track2.mcParticle(); - int track1PDG = std::abs(mctrack1.pdgCode()); - int track2PDG = std::abs(mctrack2.pdgCode()); - if (!mctrack1.isPhysicalPrimary()) { - continue; - } - if (!mctrack2.isPhysicalPrimary()) { - continue; - } - if (track1PDG != PDG_t::kKPlus || track2PDG != PDG_t::kPiPlus) { - continue; - } - for (const auto& mothertrack1 : mctrack1.mothers_as()) { - for (const auto& mothertrack2 : mctrack2.mothers_as()) { - if (mothertrack1.pdgCode() != mothertrack2.pdgCode()) { - continue; - } - if (mothertrack1 != mothertrack2) { - continue; - } - if (std::abs(mothertrack1.y()) > confRapidity) { - continue; - } - if (std::abs(mothertrack1.pdgCode()) != o2::constants::physics::kK0Star892) { - continue; - } - // if (avoidsplitrackMC && oldindex == mothertrack1.globalIndex()) { - if (avoidsplitrackMC && oldindex == mothertrack1.index()) { - histos.fill(HIST("h1PhiRecsplit"), mothertrack1.pt()); - continue; - } - // oldindex = mothertrack1.globalIndex(); - oldindex = mothertrack1.index(); - auto phiMinusPsi = getPhiInRange(mothertrack1.phi() - psiFT0C); - histos.fill(HIST("hSparseKstarMCRecWeight"), centclass, phiMinusPsi, std::pow(std::cos(2.0 * phiMinusPsi), 2.0), mothertrack1.pt(), mothertrack1.eta()); - } - } - } - } - // loop over generated particle - for (const auto& mcParticle : GenParticles) { - static constexpr float MaxEtaAcceptance = 0.8f; - if (std::abs(mcParticle.eta()) > MaxEtaAcceptance) { - continue; - } - if (std::abs(mcParticle.pdgCode()) == PDG_t::kKPlus && mcParticle.isPhysicalPrimary()) { - histos.fill(HIST("hSparseKstarMCGenKaonWeight"), centclass, getPhiInRange(mcParticle.phi() - psiFT0C), std::pow(std::cos(2.0 * getPhiInRange(mcParticle.phi() - psiFT0C)), 2.0), mcParticle.pt(), mcParticle.eta()); - } - if (std::abs(mcParticle.pdgCode()) == PDG_t::kPiPlus && mcParticle.isPhysicalPrimary()) { - histos.fill(HIST("hSparseKstarMCGenPionWeight"), centclass, getPhiInRange(mcParticle.phi() - psiFT0C), std::pow(std::cos(2.0 * getPhiInRange(mcParticle.phi() - psiFT0C)), 2.0), mcParticle.pt(), mcParticle.eta()); - } - if (std::abs(mcParticle.y()) > confRapidity) { - continue; - } - if (mcParticle.pdgCode() != o2::constants::physics::kK0Star892) { - continue; - } - auto kDaughters = mcParticle.daughters_as(); - static constexpr std::size_t NumberOfDaughters = 2; - - if (kDaughters.size() != NumberOfDaughters) { - continue; - } - auto daughtp = false; - auto daughtm = false; - for (const auto& kCurrentDaughter : kDaughters) { - if (!kCurrentDaughter.isPhysicalPrimary()) { - continue; - } - if (kCurrentDaughter.pdgCode() == +PDG_t::kKPlus) { - if (kCurrentDaughter.pt() > cfgCutPT && std::abs(kCurrentDaughter.eta()) < cfgCutEta) { - daughtp = true; - } - kaonPlus = ROOT::Math::PxPyPzMVector(kCurrentDaughter.px(), kCurrentDaughter.py(), kCurrentDaughter.pz(), MassKa); - } else if (kCurrentDaughter.pdgCode() == -PDG_t::kPiPlus) { - if (kCurrentDaughter.pt() > cfgCutPT && std::abs(kCurrentDaughter.eta()) < cfgCutEta) { - daughtm = true; - } - pionMinus = ROOT::Math::PxPyPzMVector(kCurrentDaughter.px(), kCurrentDaughter.py(), kCurrentDaughter.pz(), MassPi); - } - } - if (daughtp && daughtm) { - auto phiMinusPsiGen = getPhiInRange(mcParticle.phi() - psiFT0C); - histos.fill(HIST("hSparseKstarMCGenWeight"), centclass, phiMinusPsiGen, std::pow(std::cos(2.0 * phiMinusPsiGen), 2.0), mcParticle.pt(), mcParticle.eta()); - } - } - } // rec collision loop - - } // process MC - PROCESS_SWITCH(Kstarpbpb, processMCkstarWeight, "Process MC kstar Weight", false); + } + PROCESS_SWITCH(Kstarpbpb, processMC, "K* MC: Acc x Eff (gen, rec)", false); - // ================= phi(1020) spin alignment: port of the SA part of phipbpb.cxx ================= struct SAValues { double cosThetaStar; double sa; }; - // K- in the phi rest frame (as in phipbpb.cxx) w.r.t. the chosen quantization axis SAValues getSAValuesPhi(const ROOT::Math::PxPyPzMVector& mother, const ROOT::Math::PxPyPzMVector& kaonMinus, const ROOT::Math::XYZVector& axis, double psiSA) { ROOT::Math::Boost boost{mother.BoostToCM()}; @@ -1735,20 +1513,23 @@ struct Kstarpbpb { } auto centrality = collision.centFT0C(); auto psiSA = getSAEventAngle(collision.psiFT0C()); - if (cfgSAFrame.value == kRandomEventPlane) { + if (isRandomFrame()) { histos.fill(HIST("phi/hPsiRandom"), centrality, psiSA); } + histos.fill(HIST("phi/ResFT0CTPC"), centrality, std::cos(2.0 * (collision.psiFT0C() - collision.psiTPC()))); + histos.fill(HIST("phi/ResFT0CFT0A"), centrality, std::cos(2.0 * (collision.psiFT0C() - collision.psiFT0A()))); + histos.fill(HIST("phi/ResFT0ATPC"), centrality, std::cos(2.0 * (collision.psiTPC() - collision.psiFT0A()))); ROOT::Math::PxPyPzMVector kaonPlusPhi, kaonMinusPhi, phiMother, kaonPlusRot, phiRot; for (const auto& track1 : tracks) { - if (!(track1.signed1Pt() > cfgCutCharge.value)) { // positive kaon + if (!(track1.signed1Pt() > cfgCutCharge.value)) { continue; } if (!selectionTrackPhi(track1) || !selectionPIDPhi(track1)) { continue; } for (const auto& track2 : tracks) { - if (!(track2.signed1Pt() < cfgCutCharge.value)) { // negative kaon + if (!(track2.signed1Pt() < cfgCutCharge.value)) { continue; } if (!selectionTrackPhi(track2) || !selectionPIDPhi(track2)) { @@ -1768,13 +1549,8 @@ struct Kstarpbpb { continue; } auto [cosThetaStar, sa] = getSAValuesPhi(phiMother, kaonMinusPhi, getSAAxis(phiMother, psiSA), psiSA); - if (doClosureTest) { - histos.fill(HIST("closure/PhiSameEventCosThetaStar"), phiMother.M(), phiMother.Pt(), cosThetaStar, absRapidity, centrality); - } histos.fill(HIST("phi/hSparseV2SameEventSA"), phiMother.M(), phiMother.Pt(), sa, absRapidity, centrality); histos.fill(HIST("phi/hSparseV2SameEventCosThetaStar"), phiMother.M(), phiMother.Pt(), cosThetaStar, absRapidity, centrality); - - // rotated background, same rotation as for K* in processSE: rotate the K+, cos(theta*) of the K- in the rotated pair if (phiSA.fillRotation && nBkgRotations.value > 1) { const double angleStart = confMinRot.value; const double angleStep = (confMaxRot.value - angleStart) / (nBkgRotations.value - 1.0); @@ -1786,7 +1562,6 @@ struct Kstarpbpb { if (absRapidityRot > phiSA.confRapidity) { continue; } - // production-plane axis must follow the rotated candidate auto [cosThetaStarRot, saRot] = getSAValuesPhi(phiRot, kaonMinusPhi, getSAAxis(phiRot, psiSA), psiSA); histos.fill(HIST("phi/hSparseV2RotationSA"), phiRot.M(), phiRot.Pt(), saRot, absRapidityRot, centrality); histos.fill(HIST("phi/hSparseV2RotationCosThetaStar"), phiRot.M(), phiRot.Pt(), cosThetaStarRot, absRapidityRot, centrality); @@ -1795,8 +1570,6 @@ struct Kstarpbpb { } } - // like-sign background (K+K+ and K-K-): same track, PID and pair cuts as the unlike-sign pairs, each pair taken once; - // cos(theta*) of the first kaon of the pair (the two kaons are back to back in the pair rest frame, so the choice only flips the sign) if (phiSA.fillLikeSign) { ROOT::Math::PxPyPzMVector kaonLike1, kaonLike2, pairLike; for (const auto& track1 : tracks) { @@ -1838,7 +1611,7 @@ struct Kstarpbpb { } } } - PROCESS_SWITCH(Kstarpbpb, processSEPhi, "Process same event phi(1020) spin alignment", false); + PROCESS_SWITCH(Kstarpbpb, processSEPhi, "phi AO2D: same event (SA sparses)", false); void processMEPhi(EventCandidates const& collisions, TrackCandidates const& tracks) { @@ -1881,15 +1654,12 @@ struct Kstarpbpb { continue; } auto [cosThetaStar, sa] = getSAValuesPhi(phiMother, kaonMinusPhi, getSAAxis(phiMother, psiSA), psiSA); - if (doClosureTest) { - histos.fill(HIST("closure/PhiMixedEventCosThetaStar"), phiMother.M(), phiMother.Pt(), cosThetaStar, absRapidity, centrality); - } histos.fill(HIST("phi/hSparseV2MixedEventSA"), phiMother.M(), phiMother.Pt(), sa, absRapidity, centrality); histos.fill(HIST("phi/hSparseV2MixedEventCosThetaStar"), phiMother.M(), phiMother.Pt(), cosThetaStar, absRapidity, centrality); } } } - PROCESS_SWITCH(Kstarpbpb, processMEPhi, "Process mixed event phi(1020) spin alignment", false); + PROCESS_SWITCH(Kstarpbpb, processMEPhi, "phi AO2D: mixed event (combinatorial background)", false); void processMCPhi(CollisionMCTrueTable::iterator const& TrueCollision, CollisionMCRecTableCentFT0C const& RecCollisions, TrackMCTrueTable const& GenParticles, FilTrackMCRecTable const& RecTracks) { @@ -1904,7 +1674,7 @@ struct Kstarpbpb { } ROOT::Math::PxPyPzMVector kaonPlusPhi, kaonMinusPhi, phiMother; for (const auto& RecCollision : RecCollisions) { - auto psiFT0C = getMCEffPsi(TrueCollision, GenParticles); // one Psi per MC event (mcEffEP.psiSource; 0 = old fixed Psi = 0) + auto psiFT0C = getMCEffPsi(TrueCollision, GenParticles); histos.fill(HIST("phi/hMC"), 3); if (!RecCollision.sel8()) { histos.fill(HIST("phi/hMC"), 4); @@ -1913,7 +1683,7 @@ struct Kstarpbpb { if (!selectionEventBits(RecCollision)) { continue; } - histos.fill(HIST("phi/hMC"), 5); // same bin meaning as the K* hMC + histos.fill(HIST("phi/hMC"), 5); if (std::abs(RecCollision.posZ()) > cfgCutVertex) { histos.fill(HIST("phi/hMC"), 6); continue; @@ -1921,11 +1691,10 @@ struct Kstarpbpb { histos.fill(HIST("phi/hMC"), 7); auto centrality = RecCollision.centFT0C(); histos.fill(HIST("phi/CentPercentileMCRecHist"), centrality); - auto psiSA = getSAEventAngle(psiFT0C); // same angle for rec and gen of this event + auto psiSA = getSAEventAngle(psiFT0C); histos.fill(HIST("phi/hMCEffPsi"), centrality, psiSA); auto oldindex = -999; auto rectrackspart = RecTracks.sliceBy(perCollision, RecCollision.globalIndex()); - // loop over reconstructed particle for (const auto& track1 : rectrackspart) { if (!selectionTrackPhi(track1)) { continue; @@ -1992,7 +1761,6 @@ struct Kstarpbpb { kaonPlusPhi = ROOT::Math::PxPyPzMVector(track2.px(), track2.py(), track2.pz(), MassKa); } phiMother = kaonPlusPhi + kaonMinusPhi; - // reconstructed-pair rapidity, same cut as in processSEPhi / processMEPhi (true-mother y is cut above) if (std::abs(phiMother.Rapidity()) > phiSA.confRapidity) { continue; } @@ -2001,15 +1769,11 @@ struct Kstarpbpb { if (mcEffEP.fillPhiVMinusPsi) { histos.fill(HIST("phi/hSparseV2MCRecCosThetaStarPhiVPsi"), phiMother.Pt(), cosThetaStar, getPhiInRange(phiMother.Phi() - psiSA), centrality); } - if (doClosureTest) { - histos.fill(HIST("closure/PhiMCRecTrueCosThetaStar"), phiMother.M(), phiMother.Pt(), cosThetaStar, std::abs(phiMother.Rapidity()), centrality); - } histos.fill(HIST("phi/hSparseV2MCRecSA"), phiMother.M(), phiMother.Pt(), sa, std::abs(phiMother.Rapidity()), centrality); } } } } - // loop over generated particle for (const auto& mcParticle : GenParticles) { if (std::abs(mcParticle.y()) > phiSA.confRapidity) { continue; @@ -2044,20 +1808,13 @@ struct Kstarpbpb { if (mcEffEP.fillPhiVMinusPsi) { histos.fill(HIST("phi/hSparseV2MCGenCosThetaStarPhiVPsi"), phiMother.Pt(), cosThetaStar, getPhiInRange(phiMother.Phi() - psiSA), centrality); } - if (doClosureTest) { - histos.fill(HIST("closure/PhiMCGenCosThetaStar"), phiMother.M(), phiMother.Pt(), cosThetaStar, std::abs(phiMother.Rapidity()), centrality); - } histos.fill(HIST("phi/hSparseV2MCGenSA"), phiMother.M(), phiMother.Pt(), sa, std::abs(phiMother.Rapidity()), centrality); } } - } // rec collision loop + } } - PROCESS_SWITCH(Kstarpbpb, processMCPhi, "Process MC phi(1020) spin alignment", false); + PROCESS_SWITCH(Kstarpbpb, processMCPhi, "phi MC: Acc x Eff (gen, rec)", false); - // ================= event loss and signal loss for K* and phi(1020) ================= - // adapted from processEvtLossSigLossMC1 in phianalysisrun3pbpb.cxx. The accepted MC event uses the same reconstructed-event - // selection as processMC / processMCPhi (sel8, additionalEvSel1-4, |vz|) and, by default, the same single-reco-collision - // requirement; the generated K* and phi use the same rapidity and daughter conditions as the generated loops there. void processEvtLossSigLossMC(McCollisionMults::iterator const& mcCollision, CollisionMCRecTableCentFT0C const& RecCollisions, TrackMCTrueTable const& GenParticles) { if (evtSigLoss.cutVzGen && std::abs(mcCollision.posZ()) > cfgCutVertex) { @@ -2072,7 +1829,6 @@ struct Kstarpbpb { const float impactPar = mcCollision.impactParameter(); const float multMC = mcCollision.multMCNParticlesEta05(); - // all generated events histos.fill(HIST("evtSigLoss/MCEventHist"), 1); histos.fill(HIST("evtSigLoss/hImpactParameterGen"), impactPar); histos.fill(HIST("evtSigLoss/hMultEta05Gen"), multMC); @@ -2085,7 +1841,6 @@ struct Kstarpbpb { histos.fill(HIST("evtSigLoss/MCEventHist"), 4); } - // generated events with a selected reconstructed collision (event loss) bool selected = false; float centrality = -999.f; if (!evtSigLoss.requireSingleReco || RecCollisions.size() == 1) { @@ -2105,8 +1860,8 @@ struct Kstarpbpb { histos.fill(HIST("evtSigLoss/hMultEta05VsCentRec"), centrality, multMC); } - // generated K*0 / anti-K*0 and phi(1020) (signal loss) static constexpr std::size_t NumberOfDaughters = 2; + const double psiTrue = getSAEventAngle(mcCollision.eventPlaneAngle()); for (const auto& mcParticle : GenParticles) { const int pdgMother = std::abs(mcParticle.pdgCode()); if (pdgMother != o2::constants::physics::kK0Star892 && mcParticle.pdgCode() != o2::constants::physics::kPhi) { @@ -2144,49 +1899,44 @@ struct Kstarpbpb { } } } - const double pt = (dau1 + dau2).Pt(); + const ROOT::Math::PxPyPzMVector mother = dau1 + dau2; + const double pt = mother.Pt(); if (isKstar && hasKaon && hasPion) { - histos.fill(HIST("evtSigLoss/hKstarGenBeforeEvtSel"), pt, impactPar); - histos.fill(HIST("evtSigLoss/hKstarGenVsMultBeforeEvtSel"), pt, multMC); + const double cosThetaStar = getCosThetaStar(mother, dau1, getSAAxis(mother, psiTrue)); + histos.fill(HIST("evtSigLoss/hKstarGenBeforeEvtSel"), pt, cosThetaStar, impactPar); + histos.fill(HIST("evtSigLoss/hKstarGenVsMultBeforeEvtSel"), pt, cosThetaStar, multMC); if (selected) { - histos.fill(HIST("evtSigLoss/hKstarGenAfterEvtSel"), pt, impactPar); - histos.fill(HIST("evtSigLoss/hKstarGenVsMultAfterEvtSel"), pt, multMC); - histos.fill(HIST("evtSigLoss/hKstarGenAfterEvtSelVsCent"), pt, centrality); + histos.fill(HIST("evtSigLoss/hKstarGenAfterEvtSel"), pt, cosThetaStar, impactPar); + histos.fill(HIST("evtSigLoss/hKstarGenVsMultAfterEvtSel"), pt, cosThetaStar, multMC); + histos.fill(HIST("evtSigLoss/hKstarGenAfterEvtSelVsCent"), pt, cosThetaStar, centrality); } } else if (!isKstar && hasKPlus && hasKMinus) { - histos.fill(HIST("evtSigLoss/hPhiGenBeforeEvtSel"), pt, impactPar); - histos.fill(HIST("evtSigLoss/hPhiGenVsMultBeforeEvtSel"), pt, multMC); + const double cosThetaStar = getCosThetaStar(mother, dau2, getSAAxis(mother, psiTrue)); + histos.fill(HIST("evtSigLoss/hPhiGenBeforeEvtSel"), pt, cosThetaStar, impactPar); + histos.fill(HIST("evtSigLoss/hPhiGenVsMultBeforeEvtSel"), pt, cosThetaStar, multMC); if (selected) { - histos.fill(HIST("evtSigLoss/hPhiGenAfterEvtSel"), pt, impactPar); - histos.fill(HIST("evtSigLoss/hPhiGenVsMultAfterEvtSel"), pt, multMC); - histos.fill(HIST("evtSigLoss/hPhiGenAfterEvtSelVsCent"), pt, centrality); + histos.fill(HIST("evtSigLoss/hPhiGenAfterEvtSel"), pt, cosThetaStar, impactPar); + histos.fill(HIST("evtSigLoss/hPhiGenVsMultAfterEvtSel"), pt, cosThetaStar, multMC); + histos.fill(HIST("evtSigLoss/hPhiGenAfterEvtSelVsCent"), pt, cosThetaStar, centrality); } } } } - PROCESS_SWITCH(Kstarpbpb, processEvtLossSigLossMC, "Process event loss and signal loss for K* and phi(1020)", false); + PROCESS_SWITCH(Kstarpbpb, processEvtLossSigLossMC, "K* and phi MC: event loss and signal loss", false); - // ================= MC closure test of the cos(theta*) chain ================= - // Test sample (reconstructed MC analysed like data): - // hSparseSE all same-event unlike-sign pairs (signal + background), true pairs weighted by W - // hSparseME mixed-event unlike-sign pairs (weight 1) -> step 1: SE - norm * ME - // hSparseRecTrue reconstructed true K* (phi), weighted by W -> step 2: truth for the raw yield - // hSparseGen generated K* (phi), daughters in acceptance, weighted -> step 4: input yield and rho00 - // Efficiency sample (independent events if closure.splitSample): - // hSparseRecTrueEff / hSparseGenEff = Acc x Eff(cos theta*) -> step 3 - // W(cos) = 3/2 [(1 - rho00) + (3 rho00 - 1) cos^2] with the GENERATED cos(theta*) (W = 1 if injectPolarization is off) + double getRho00Weight(double cosThetaStar, double rho) + { + return 1.5 * ((1.0 - rho) + (3.0 * rho - 1.0) * cosThetaStar * cosThetaStar); + } - // W(cos) = 3/2 [(1 - rho) + (3 rho - 1) cos^2]; = 1 over cos in [-1,1]; W = 1 for rho = 1/3 double getInjectionWeight(double cosThetaStar) { if (!closure.injectPolarization) { return 1.0; } - const double rho = closure.rho00Inj.value; - return 1.5 * ((1.0 - rho) + (3.0 * rho - 1.0) * cosThetaStar * cosThetaStar); + return getRho00Weight(cosThetaStar, closure.rho00Inj.value); } - // cos(theta*) of 'dau' in the rest frame of 'mother' with respect to 'axis' double getCosThetaStar(const ROOT::Math::PxPyPzMVector& mother, const ROOT::Math::PxPyPzMVector& dau, const ROOT::Math::XYZVector& axis) { ROOT::Math::Boost boost{mother.BoostToCM()}; @@ -2194,13 +1944,6 @@ struct Kstarpbpb { return axis.Dot(threeVecDau) / std::sqrt(threeVecDau.Mag2()) / std::sqrt(axis.Mag2()); } - // one Psi per MC event (call once per event: the random-EP option draws a new angle at each call) - double getClosurePsi(double trueEventPlaneAngle) - { - return getSAEventAngle(closure.useTrueEP ? trueEventPlaneAngle : 0.0); - } - - // even MC events -> Acc x Eff sample, odd MC events -> test sample (both if splitSample is off) static constexpr int64_t SplitSampleModulus = 2; bool isClosureEffSample(int64_t mcCollisionIndex) { @@ -2211,14 +1954,12 @@ struct Kstarpbpb { return !closure.splitSample || (mcCollisionIndex % SplitSampleModulus == 1); } - // track enters the SE / ME / rotated pairs: always if requirePrimaryTracks is off, else only if matched to a physical primary template bool selectionClosurePrimary(const TTrack& track) { return !closure.requirePrimaryTracks || (track.has_mcParticle() && track.mcParticle().isPhysicalPrimary()); } - // number of reco collisions per MC collision (for the single-reco requirement of the ME, same as the SE) std::vector countRecoPerMcCollision(aod::McCollisionLabels const& mcLabels, int64_t nMcCollisions) { std::vector nRecPerMc(nMcCollisions, 0); @@ -2230,41 +1971,18 @@ struct Kstarpbpb { return nRecPerMc; } - // mixed-event pair of the closure test sample: same event class as the SE - template - bool selectionClosurePairME(const TCollision& collision1, const TCollision& collision2, const std::vector& nRecPerMc) - { - if (!selectionEventMC(collision1) || !selectionEventMC(collision2) || collision1.bcId() == collision2.bcId()) { - return false; - } - if (!collision1.has_mcCollision() || !collision2.has_mcCollision()) { - return false; - } - if (!isClosureTestSample(collision1.mcCollisionId()) || !isClosureTestSample(collision2.mcCollisionId())) { - return false; - } - if (closure.meRequireSingleReco && (nRecPerMc[collision1.mcCollisionId()] != 1 || nRecPerMc[collision2.mcCollisionId()] != 1)) { - return false; - } - return true; - } - - // reco-event selection of processMC / processMCPhi, plus the data centrality cut (identical for SE and ME) template bool selectionEventMC(const TCollision& collision) { return collision.sel8() && selectionEventBits(collision) && std::abs(collision.posZ()) < cfgCutVertex && std::abs(collision.centFT0C()) < cfgCutCentrality; } - // reco-event selection of the reconstructed-Psi_FT0C closure: selectionEventMC plus the EP-calibration trigger required - // on data (processSE / processSEPhi via selectionEventCuts), only available once EPCalibrationTables is joined template bool selectionEventMCRecoEP(const TCollision& collision) { return selectionEventMC(collision) && collision.triggereventep(); } - // mixed-event pair of the reconstructed-Psi_FT0C closure test sample: same as selectionClosurePairME, with the EP trigger template bool selectionClosurePairMERecoEP(const TCollision& collision1, const TCollision& collision2, const std::vector& nRecPerMc) { @@ -2283,7 +2001,6 @@ struct Kstarpbpb { return true; } - // K pi pair from the decay of one primary K*0 / anti-K*0 (|y| < confRapidity) template bool isTrueKstarPair(const TTrack& trackKaon, const TTrack& trackPion) { @@ -2315,7 +2032,6 @@ struct Kstarpbpb { return false; } - // K+ K- pair from the decay of one primary phi(1020) (|y| < phiSA.confRapidity) template bool isTruePhiPair(const TTrack& trackPlus, const TTrack& trackMinus) { @@ -2347,40 +2063,64 @@ struct Kstarpbpb { return false; } - // ---------------- K*0: same event, true reco, generated ---------------- - // track1 = kaon candidate, track2 = pion candidate, unlike-sign, same cuts as processSE. - // The axis is built with getSAAxis, as in processMC (efficiency) and processSE (data). - void processMCClosure(CollisionMCTrueTable::iterator const& trueCollision, CollisionMCRecTableCentFT0C const& recCollisions, TrackMCTrueTable const& genParticles, FilTrackMCRecTable const& recTracks) + void processMCClosureRecoEP(CollisionMCTrueTable::iterator const& trueCollision, CollisionMCRecTableClosure const& recCollisions, TrackMCTrueTable const& genParticles, FilTrackMCRecTable const& recTracks) { ROOT::Math::PxPyPzMVector kaon, pion, kstar, kaonRot, kstarRot, kaonGen, pionGen, kstarGen; static constexpr std::size_t NumberOfDaughters = 2; - histos.fill(HIST("closureKstar/hMC"), 0.5); + histos.fill(HIST("closureKstarRecoEP/hMC"), 0.5); if (recCollisions.size() == 0) { - histos.fill(HIST("closureKstar/hMC"), 1.5); + histos.fill(HIST("closureKstarRecoEP/hMC"), 1.5); return; } if (recCollisions.size() > 1) { - histos.fill(HIST("closureKstar/hMC"), 2.5); + histos.fill(HIST("closureKstarRecoEP/hMC"), 2.5); return; } const bool isEffSample = isClosureEffSample(trueCollision.globalIndex()); const bool isTestSample = isClosureTestSample(trueCollision.globalIndex()); - const double psi = getClosurePsi(trueCollision.eventPlaneAngle()); // same angle for the rec and the gen part of this event + const double psiTrue = getSAEventAngle(trueCollision.eventPlaneAngle()); for (const auto& recCollision : recCollisions) { - if (!selectionEventMC(recCollision)) { + if (!selectionEventMCRecoEP(recCollision)) { continue; } if (isEffSample) { - histos.fill(HIST("closureKstar/hMC"), 3.5); + histos.fill(HIST("closureKstarRecoEP/hMC"), 3.5); } if (isTestSample) { - histos.fill(HIST("closureKstar/hMC"), 4.5); + histos.fill(HIST("closureKstarRecoEP/hMC"), 4.5); } const auto centrality = recCollision.centFT0C(); + const double recoPsiFT0C = recCollision.psiFT0C(); + const double psi = getSAEventAngle(recoPsiFT0C); + { + const double psiTPC = recCollision.psiTPC(); + const double psiFT0A = recCollision.psiFT0A(); + const double qFT0C = recCollision.qFT0C(); + const double qTPC = recCollision.qTPC(); + const double qFT0A = recCollision.qFT0A(); + histos.fill(HIST("closureKstarRecoEP/ResFT0CTPCSP"), centrality, qFT0C * qTPC * std::cos(2.0 * (recoPsiFT0C - psiTPC))); + histos.fill(HIST("closureKstarRecoEP/ResFT0CFT0ASP"), centrality, qFT0C * qFT0A * std::cos(2.0 * (recoPsiFT0C - psiFT0A))); + histos.fill(HIST("closureKstarRecoEP/ResFT0ATPCSP"), centrality, qTPC * qFT0A * std::cos(2.0 * (psiTPC - psiFT0A))); + histos.fill(HIST("closureKstarRecoEP/ResFT0CTPC"), centrality, std::cos(2.0 * (recoPsiFT0C - psiTPC))); + histos.fill(HIST("closureKstarRecoEP/ResFT0CFT0A"), centrality, std::cos(2.0 * (recoPsiFT0C - psiFT0A))); + histos.fill(HIST("closureKstarRecoEP/ResFT0ATPC"), centrality, std::cos(2.0 * (psiTPC - psiFT0A))); + histos.fill(HIST("closureKstarRecoEP/ResTrueFT0C"), centrality, std::cos(2.0 * (recoPsiFT0C - trueCollision.eventPlaneAngle()))); + if (moment.mcClosure) { + if (isEffSample) { + histos.fill(HIST("moment/hResMCTrueRef"), centrality, std::cos(2.0 * (psi - psiTrue))); + } + if (isTestSample) { + histos.fill(HIST("moment/hResMCTrueTest"), centrality, std::cos(2.0 * (psi - psiTrue))); + histos.fill(HIST("moment/ResFT0CTPC"), centrality, std::cos(2.0 * (recoPsiFT0C - psiTPC))); + histos.fill(HIST("moment/ResFT0CFT0A"), centrality, std::cos(2.0 * (recoPsiFT0C - psiFT0A))); + histos.fill(HIST("moment/ResFT0ATPC"), centrality, std::cos(2.0 * (psiTPC - psiFT0A))); + } + } + } + const int momSubsample = getMomentSubsample(recCollision.globalIndex()); auto recTracksThisColl = recTracks.sliceBy(perCollision, recCollision.globalIndex()); - // ---- reconstructed pairs ---- for (const auto& track1 : recTracksThisColl) { if (!selectionTrack(track1) || !selectionClosurePrimary(track1)) { continue; @@ -2425,23 +2165,27 @@ struct Kstarpbpb { kaonGen = ROOT::Math::PxPyPzMVector(mcKaon.px(), mcKaon.py(), mcKaon.pz(), MassKa); pionGen = ROOT::Math::PxPyPzMVector(mcPion.px(), mcPion.py(), mcPion.pz(), MassPi); kstarGen = kaonGen + pionGen; - const double cosGen = getCosThetaStar(kstarGen, kaonGen, getSAAxis(kstarGen, psi)); + const double cosGen = getCosThetaStar(kstarGen, kaonGen, getSAAxis(kstarGen, psiTrue)); weight = getInjectionWeight(cosGen); - // Acc x Eff must come from an unweighted (unpolarized) sample, independent of the injected rho00 under test if (isEffSample) { - histos.fill(HIST("closureKstar/hSparseRecTrueEff"), kstar.M(), kstar.Pt(), cosRec, centrality, 1.0); + histos.fill(HIST("closureKstarRecoEP/hSparseRecTrueEff"), kstar.M(), kstar.Pt(), cosRec, centrality, 1.0); + if (moment.mcClosure && passCandWindow(kstar)) { + fillMoments(kstar.M(), kstar.Pt(), centrality, kMomMCRef, momSubsample, cosRec, getRho00Weight(cosGen, moment.mcRefRho00.value)); + } } if (isTestSample) { - histos.fill(HIST("closureKstar/hSparseRecTrue"), kstar.M(), kstar.Pt(), cosRec, centrality, weight); - histos.fill(HIST("closureKstar/hCosThetaStarGenVsRec"), cosGen, cosRec); + histos.fill(HIST("closureKstarRecoEP/hSparseRecTrue"), kstar.M(), kstar.Pt(), cosRec, centrality, weight); + histos.fill(HIST("closureKstarRecoEP/hCosThetaStarGenVsRec"), cosGen, cosRec); } } if (!isTestSample) { continue; } - histos.fill(HIST("closureKstar/hSparseSE"), kstar.M(), kstar.Pt(), cosRec, centrality, weight); + histos.fill(HIST("closureKstarRecoEP/hSparseSE"), kstar.M(), kstar.Pt(), cosRec, centrality, weight); + if (moment.mcClosure && passCandWindow(kstar)) { + fillMoments(kstar.M(), kstar.Pt(), centrality, kMomSEUnlike, momSubsample, cosRec, weight); + } - // rotated background, same rotation as in processSE (weight 1) if (closure.fillRotBkg && nBkgRotations.value > 1) { const double angleStart = confMinRot.value; const double angleStep = (confMaxRot.value - angleStart) / (nBkgRotations.value - 1.0); @@ -2456,13 +2200,12 @@ struct Kstarpbpb { continue; } const double cosRot = getCosThetaStar(kstarRot, kaonRot, getSAAxis(kstarRot, psi)); - histos.fill(HIST("closureKstar/hSparseRot"), kstarRot.M(), kstarRot.Pt(), cosRot, centrality); + histos.fill(HIST("closureKstarRecoEP/hSparseRot"), kstarRot.M(), kstarRot.Pt(), cosRot, centrality); } } } } - // ---- generated K*0 / anti-K*0: Acc x Eff denominator (eff sample) and input truth (test sample) ---- for (const auto& mcParticle : genParticles) { if (std::abs(mcParticle.y()) > confRapidity) { continue; @@ -2496,35 +2239,32 @@ struct Kstarpbpb { if (std::abs(kstarGen.Rapidity()) > confRapidity) { continue; } - const double cosGen = getCosThetaStar(kstarGen, kaonGen, getSAAxis(kstarGen, psi)); - // Acc x Eff must come from an unweighted (unpolarized) sample, independent of the injected rho00 under test + const double cosGen = getCosThetaStar(kstarGen, kaonGen, getSAAxis(kstarGen, psiTrue)); if (isEffSample) { - histos.fill(HIST("closureKstar/hSparseGenEff"), kstarGen.M(), kstarGen.Pt(), cosGen, centrality, 1.0); + histos.fill(HIST("closureKstarRecoEP/hSparseGenEff"), kstarGen.M(), kstarGen.Pt(), cosGen, centrality, 1.0); } if (isTestSample) { const double weight = getInjectionWeight(cosGen); - histos.fill(HIST("closureKstar/hSparseGen"), kstarGen.M(), kstarGen.Pt(), cosGen, centrality, weight); + histos.fill(HIST("closureKstarRecoEP/hSparseGen"), kstarGen.M(), kstarGen.Pt(), cosGen, centrality, weight); } } - } // rec collision loop + } } - PROCESS_SWITCH(Kstarpbpb, processMCClosure, "Process MC closure of cos(theta*) for K*: SE, true rec, gen", false); + PROCESS_SWITCH(Kstarpbpb, processMCClosureRecoEP, "Process MC closure of cos(theta*) for K*, reconstructed Psi_FT0C: SE, true rec, gen", false); - // ---------------- K*0: mixed event of the test sample ---------------- - // Same pairing as processMixedEvent (kaon from event 1, pion from event 2, unlike-sign), axis from event 1. - void processMCClosureME(CollisionMCRecMixTable const& collisions, FilTrackMCRecTable const& tracks, aod::McCollisions const& mcCollisions, aod::McCollisionLabels const& mcLabels, aod::McParticles const&) + void processMCClosureMERecoEP(CollisionMCRecMixTableRecoEP const& collisions, FilTrackMCRecTable const& tracks, aod::McCollisions const& mcCollisions, aod::McCollisionLabels const& mcLabels, aod::McParticles const&) { ROOT::Math::PxPyPzMVector kaon, pion, kstar; const auto nRecPerMc = countRecoPerMcCollision(mcLabels, mcCollisions.size()); auto tracksTuple = std::make_tuple(tracks); - BinningTypeMCClosure binningOnPositions{{axisVertex, axisMultiplicityClass}}; - SameKindPair pair{binningOnPositions, cfgNoMixedEvents, -1, collisions, tracksTuple, &cache}; + BinningTypeMCClosureRecoEP binningOnPositions{{axisVertex, axisMultiplicityClass, axisEPAngle}}; + SameKindPair pair{binningOnPositions, cfgNoMixedEvents, -1, collisions, tracksTuple, &cache}; for (const auto& [collision1, tracks1, collision2, tracks2] : pair) { - if (!selectionClosurePairME(collision1, collision2, nRecPerMc)) { + if (!selectionClosurePairMERecoEP(collision1, collision2, nRecPerMc)) { continue; } const auto centrality = collision1.centFT0C(); - const double psi = getClosurePsi(collision1.mcCollision().eventPlaneAngle()); + const double psi = getSAEventAngle(collision1.psiFT0C()); for (const auto& [track1, track2] : o2::soa::combinations(o2::soa::CombinationsFullIndexPolicy(tracks1, tracks2))) { if (track1.sign() * track2.sign() > 0) { continue; @@ -2551,55 +2291,79 @@ struct Kstarpbpb { continue; } const double cosRec = getCosThetaStar(kstar, kaon, getSAAxis(kstar, psi)); - histos.fill(HIST("closureKstar/hSparseME"), kstar.M(), kstar.Pt(), cosRec, centrality); + histos.fill(HIST("closureKstarRecoEP/hSparseME"), kstar.M(), kstar.Pt(), cosRec, centrality); } } } - PROCESS_SWITCH(Kstarpbpb, processMCClosureME, "Process MC closure of cos(theta*) for K*: mixed event", false); + PROCESS_SWITCH(Kstarpbpb, processMCClosureMERecoEP, "Process MC closure of cos(theta*) for K*, reconstructed Psi_FT0C: mixed event", false); - // ---------------- phi(1020): same event, true reco, generated ---------------- - // track1 = K+, track2 = K-, as in processSEPhi; cos(theta*) of the K-. - // The axis is built with getSAAxis, as in processSEPhi/processMEPhi (the real data analysis). - void processMCClosurePhi(CollisionMCTrueTable::iterator const& trueCollision, CollisionMCRecTableCentFT0C const& recCollisions, TrackMCTrueTable const& genParticles, FilTrackMCRecTable const& recTracks) + void processMCClosureRecoEPPhi(CollisionMCTrueTable::iterator const& trueCollision, CollisionMCRecTableClosure const& recCollisions, TrackMCTrueTable const& genParticles, FilTrackMCRecTable const& recTracks) { ROOT::Math::PxPyPzMVector kaonPlus, kaonMinus, phi, kaonPlusRot, phiRot, kaonPlusGen, kaonMinusGen, phiGen; static constexpr std::size_t NumberOfDaughters = 2; - histos.fill(HIST("closurePhi/hMC"), 0.5); + histos.fill(HIST("closurePhiRecoEP/hMC"), 0.5); if (recCollisions.size() == 0) { - histos.fill(HIST("closurePhi/hMC"), 1.5); + histos.fill(HIST("closurePhiRecoEP/hMC"), 1.5); return; } if (recCollisions.size() > 1) { - histos.fill(HIST("closurePhi/hMC"), 2.5); + histos.fill(HIST("closurePhiRecoEP/hMC"), 2.5); return; } const bool isEffSample = isClosureEffSample(trueCollision.globalIndex()); const bool isTestSample = isClosureTestSample(trueCollision.globalIndex()); - const double psi = getClosurePsi(trueCollision.eventPlaneAngle()); + const double psiTrue = getSAEventAngle(trueCollision.eventPlaneAngle()); for (const auto& recCollision : recCollisions) { - if (!selectionEventMC(recCollision)) { + if (!selectionEventMCRecoEP(recCollision)) { continue; } if (isEffSample) { - histos.fill(HIST("closurePhi/hMC"), 3.5); + histos.fill(HIST("closurePhiRecoEP/hMC"), 3.5); } if (isTestSample) { - histos.fill(HIST("closurePhi/hMC"), 4.5); + histos.fill(HIST("closurePhiRecoEP/hMC"), 4.5); } const auto centrality = recCollision.centFT0C(); + const double recoPsiFT0C = recCollision.psiFT0C(); + const double psi = getSAEventAngle(recoPsiFT0C); + { + const double psiTPC = recCollision.psiTPC(); + const double psiFT0A = recCollision.psiFT0A(); + const double qFT0C = recCollision.qFT0C(); + const double qTPC = recCollision.qTPC(); + const double qFT0A = recCollision.qFT0A(); + histos.fill(HIST("closurePhiRecoEP/ResFT0CTPCSP"), centrality, qFT0C * qTPC * std::cos(2.0 * (recoPsiFT0C - psiTPC))); + histos.fill(HIST("closurePhiRecoEP/ResFT0CFT0ASP"), centrality, qFT0C * qFT0A * std::cos(2.0 * (recoPsiFT0C - psiFT0A))); + histos.fill(HIST("closurePhiRecoEP/ResFT0ATPCSP"), centrality, qTPC * qFT0A * std::cos(2.0 * (psiTPC - psiFT0A))); + histos.fill(HIST("closurePhiRecoEP/ResFT0CTPC"), centrality, std::cos(2.0 * (recoPsiFT0C - psiTPC))); + histos.fill(HIST("closurePhiRecoEP/ResFT0CFT0A"), centrality, std::cos(2.0 * (recoPsiFT0C - psiFT0A))); + histos.fill(HIST("closurePhiRecoEP/ResFT0ATPC"), centrality, std::cos(2.0 * (psiTPC - psiFT0A))); + histos.fill(HIST("closurePhiRecoEP/ResTrueFT0C"), centrality, std::cos(2.0 * (recoPsiFT0C - trueCollision.eventPlaneAngle()))); + if (moment.mcClosure && !doprocessMCClosureRecoEP) { + if (isEffSample) { + histos.fill(HIST("moment/hResMCTrueRef"), centrality, std::cos(2.0 * (psi - psiTrue))); + } + if (isTestSample) { + histos.fill(HIST("moment/hResMCTrueTest"), centrality, std::cos(2.0 * (psi - psiTrue))); + histos.fill(HIST("moment/ResFT0CTPC"), centrality, std::cos(2.0 * (recoPsiFT0C - psiTPC))); + histos.fill(HIST("moment/ResFT0CFT0A"), centrality, std::cos(2.0 * (recoPsiFT0C - psiFT0A))); + histos.fill(HIST("moment/ResFT0ATPC"), centrality, std::cos(2.0 * (psiTPC - psiFT0A))); + } + } + } + const int momSubsample = getMomentSubsample(recCollision.globalIndex()); auto recTracksThisColl = recTracks.sliceBy(perCollision, recCollision.globalIndex()); - // ---- reconstructed pairs ---- for (const auto& track1 : recTracksThisColl) { - if (!(track1.signed1Pt() > cfgCutCharge.value)) { // K+ + if (!(track1.signed1Pt() > cfgCutCharge.value)) { continue; } if (!selectionTrackPhi(track1) || !selectionPIDPhi(track1) || !selectionClosurePrimary(track1)) { continue; } for (const auto& track2 : recTracksThisColl) { - if (!(track2.signed1Pt() < cfgCutCharge.value)) { // K- + if (!(track2.signed1Pt() < cfgCutCharge.value)) { continue; } if (!selectionTrackPhi(track2) || !selectionPIDPhi(track2) || !selectionClosurePrimary(track2)) { @@ -2626,23 +2390,27 @@ struct Kstarpbpb { kaonPlusGen = ROOT::Math::PxPyPzMVector(mcPlus.px(), mcPlus.py(), mcPlus.pz(), MassKa); kaonMinusGen = ROOT::Math::PxPyPzMVector(mcMinus.px(), mcMinus.py(), mcMinus.pz(), MassKa); phiGen = kaonPlusGen + kaonMinusGen; - const double cosGen = getCosThetaStar(phiGen, kaonMinusGen, getSAAxis(phiGen, psi)); + const double cosGen = getCosThetaStar(phiGen, kaonMinusGen, getSAAxis(phiGen, psiTrue)); weight = getInjectionWeight(cosGen); - // Acc x Eff must come from an unweighted (unpolarized) sample, independent of the injected rho00 under test if (isEffSample) { - histos.fill(HIST("closurePhi/hSparseRecTrueEff"), phi.M(), phi.Pt(), cosRec, centrality, 1.0); + histos.fill(HIST("closurePhiRecoEP/hSparseRecTrueEff"), phi.M(), phi.Pt(), cosRec, centrality, 1.0); + if (moment.mcClosure && passCandWindow(phi)) { + fillMoments(phi.M(), phi.Pt(), centrality, kMomMCRef, momSubsample, cosRec, getRho00Weight(cosGen, moment.mcRefRho00.value)); + } } if (isTestSample) { - histos.fill(HIST("closurePhi/hSparseRecTrue"), phi.M(), phi.Pt(), cosRec, centrality, weight); - histos.fill(HIST("closurePhi/hCosThetaStarGenVsRec"), cosGen, cosRec); + histos.fill(HIST("closurePhiRecoEP/hSparseRecTrue"), phi.M(), phi.Pt(), cosRec, centrality, weight); + histos.fill(HIST("closurePhiRecoEP/hCosThetaStarGenVsRec"), cosGen, cosRec); } } if (!isTestSample) { continue; } - histos.fill(HIST("closurePhi/hSparseSE"), phi.M(), phi.Pt(), cosRec, centrality, weight); + histos.fill(HIST("closurePhiRecoEP/hSparseSE"), phi.M(), phi.Pt(), cosRec, centrality, weight); + if (moment.mcClosure && passCandWindow(phi)) { + fillMoments(phi.M(), phi.Pt(), centrality, kMomSEUnlike, momSubsample, cosRec, weight); + } - // rotated background: rotate the K+ (weight 1) if (closure.fillRotBkg && nBkgRotations.value > 1) { const double angleStart = confMinRot.value; const double angleStep = (confMaxRot.value - angleStart) / (nBkgRotations.value - 1.0); @@ -2654,13 +2422,12 @@ struct Kstarpbpb { continue; } const double cosRot = getCosThetaStar(phiRot, kaonMinus, getSAAxis(phiRot, psi)); - histos.fill(HIST("closurePhi/hSparseRot"), phiRot.M(), phiRot.Pt(), cosRot, centrality); + histos.fill(HIST("closurePhiRecoEP/hSparseRot"), phiRot.M(), phiRot.Pt(), cosRot, centrality); } } } } - // ---- generated phi: Acc x Eff denominator (eff sample) and input truth (test sample) ---- for (const auto& mcParticle : genParticles) { if (std::abs(mcParticle.y()) > phiSA.confRapidity) { continue; @@ -2691,35 +2458,32 @@ struct Kstarpbpb { continue; } phiGen = kaonPlusGen + kaonMinusGen; - const double cosGen = getCosThetaStar(phiGen, kaonMinusGen, getSAAxis(phiGen, psi)); - // Acc x Eff must come from an unweighted (unpolarized) sample, independent of the injected rho00 under test + const double cosGen = getCosThetaStar(phiGen, kaonMinusGen, getSAAxis(phiGen, psiTrue)); if (isEffSample) { - histos.fill(HIST("closurePhi/hSparseGenEff"), phiGen.M(), phiGen.Pt(), cosGen, centrality, 1.0); + histos.fill(HIST("closurePhiRecoEP/hSparseGenEff"), phiGen.M(), phiGen.Pt(), cosGen, centrality, 1.0); } if (isTestSample) { const double weight = getInjectionWeight(cosGen); - histos.fill(HIST("closurePhi/hSparseGen"), phiGen.M(), phiGen.Pt(), cosGen, centrality, weight); + histos.fill(HIST("closurePhiRecoEP/hSparseGen"), phiGen.M(), phiGen.Pt(), cosGen, centrality, weight); } } - } // rec collision loop + } } - PROCESS_SWITCH(Kstarpbpb, processMCClosurePhi, "Process MC closure of cos(theta*) for phi(1020): SE, true rec, gen", false); + PROCESS_SWITCH(Kstarpbpb, processMCClosureRecoEPPhi, "Process MC closure of cos(theta*) for phi(1020), reconstructed Psi_FT0C: SE, true rec, gen", false); - // ---------------- phi(1020): mixed event of the test sample ---------------- - // Same pairing as processMEPhi (K+K- from two events), cos(theta*) of the K-, axis from event 1. - void processMCClosureMEPhi(CollisionMCRecMixTable const& collisions, FilTrackMCRecTable const& tracks, aod::McCollisions const& mcCollisions, aod::McCollisionLabels const& mcLabels, aod::McParticles const&) + void processMCClosureMERecoEPPhi(CollisionMCRecMixTableRecoEP const& collisions, FilTrackMCRecTable const& tracks, aod::McCollisions const& mcCollisions, aod::McCollisionLabels const& mcLabels, aod::McParticles const&) { ROOT::Math::PxPyPzMVector kaonPlus, kaonMinus, phi; const auto nRecPerMc = countRecoPerMcCollision(mcLabels, mcCollisions.size()); auto tracksTuple = std::make_tuple(tracks); - BinningTypeMCClosure binningOnPositions{{axisVertex, axisMultiplicityClass}}; - SameKindPair pair{binningOnPositions, cfgNoMixedEvents, -1, collisions, tracksTuple, &cache}; + BinningTypeMCClosureRecoEP binningOnPositions{{axisVertex, axisMultiplicityClass, axisEPAngle}}; + SameKindPair pair{binningOnPositions, cfgNoMixedEvents, -1, collisions, tracksTuple, &cache}; for (const auto& [collision1, tracks1, collision2, tracks2] : pair) { - if (!selectionClosurePairME(collision1, collision2, nRecPerMc)) { + if (!selectionClosurePairMERecoEP(collision1, collision2, nRecPerMc)) { continue; } const auto centrality = collision1.centFT0C(); - const double psi = getClosurePsi(collision1.mcCollision().eventPlaneAngle()); + const double psi = getSAEventAngle(collision1.psiFT0C()); for (const auto& [track1, track2] : o2::soa::combinations(o2::soa::CombinationsFullIndexPolicy(tracks1, tracks2))) { if (track1.sign() * track2.sign() > 0) { continue; @@ -2751,459 +2515,536 @@ struct Kstarpbpb { continue; } const double cosRec = getCosThetaStar(phi, kaonMinus, getSAAxis(phi, psi)); - histos.fill(HIST("closurePhi/hSparseME"), phi.M(), phi.Pt(), cosRec, centrality); + histos.fill(HIST("closurePhiRecoEP/hSparseME"), phi.M(), phi.Pt(), cosRec, centrality); } } } - PROCESS_SWITCH(Kstarpbpb, processMCClosureMEPhi, "Process MC closure of cos(theta*) for phi(1020): mixed event", false); + PROCESS_SWITCH(Kstarpbpb, processMCClosureMERecoEPPhi, "Process MC closure of cos(theta*) for phi(1020), reconstructed Psi_FT0C: mixed event", false); - // ================= MC closure test of the cos(theta*) chain, reconstructed (finite-resolution) Psi_FT0C ================= - // Same as processMCClosure(Phi)/processMCClosureME(Phi) above, but Psi is the reconstructed Psi_FT0C (as on data) instead of - // the MC true event plane, and the sub-event resolution of the sample is filled too (ResFT0C*SP, needed to derive R2 and - // un-smear the fitted raw rho00 downstream). Kept as separate process functions (own histogram directories, own collision - // tables joined with EPCalibrationTables) so the true-EP closure above keeps zero dependency on the EP-calibration producer. + struct MomDaughter { + float px; + float py; + float pz; + float tpcNSigma; + float tofNSigma; + bool hasTOF; + }; - // ---------------- K*0: same event, true reco, generated (reconstructed Psi_FT0C) ---------------- - void processMCClosureRecoEP(CollisionMCTrueTable::iterator const& trueCollision, CollisionMCRecTableClosure const& recCollisions, TrackMCTrueTable const& genParticles, FilTrackMCRecTable const& recTracks) + bool passDerivedPID(const MomDaughter& daughter) { - ROOT::Math::PxPyPzMVector kaon, pion, kstar, kaonRot, kstarRot, kaonGen, pionGen, kstarGen; - static constexpr std::size_t NumberOfDaughters = 2; + if (std::abs(daughter.tpcNSigma) > candCfg.nSigmaTPC) { + return false; + } + return !daughter.hasTOF || std::abs(daughter.tofNSigma) <= candCfg.nSigmaTOF; + } - histos.fill(HIST("closureKstarRecoEP/hMC"), 0.5); - if (recCollisions.size() == 0) { - histos.fill(HIST("closureKstarRecoEP/hMC"), 1.5); - return; + template + bool passCandWindow(const ROOT::Math::PxPyPzMVector& mother) + { + const double mass = mother.M(); + if constexpr (IsPhi) { + return mass >= candCfg.phiMassMin && mass <= candCfg.phiMassMax && std::abs(mother.Rapidity()) <= phiSA.confRapidity; + } else { + return mass >= candCfg.kstarMassMin && mass <= candCfg.kstarMassMax && std::abs(mother.Rapidity()) <= confRapidity; } - if (recCollisions.size() > 1) { - histos.fill(HIST("closureKstarRecoEP/hMC"), 2.5); - return; + } + + template + bool makeCandPair(float px1, float py1, float pz1, float px2, float py2, float pz2, ROOT::Math::PxPyPzMVector& mother) + { + ROOT::Math::PxPyPzMVector first(px1, py1, pz1, MassKa); + ROOT::Math::PxPyPzMVector second(px2, py2, pz2, IsPhi ? MassKa : MassPi); + mother = first + second; + if constexpr (IsPhi) { + return passCandWindow(mother); + } else { + return passCandWindow(mother) && !isPhiReflection(first, second); } - const bool isEffSample = isClosureEffSample(trueCollision.globalIndex()); - const bool isTestSample = isClosureTestSample(trueCollision.globalIndex()); - // true axis: defines the injected weight and the Gen/GenEff truth, so the test is not tautological against the smeared axis - const double psiTrue = getSAEventAngle(trueCollision.eventPlaneAngle()); - for (const auto& recCollision : recCollisions) { - if (!selectionEventMCRecoEP(recCollision)) { + } + + template + MomDaughter getPosDaughter(const TCand& cand) + { + return {cand.posPx(), cand.posPy(), cand.posPz(), cand.posTPCNSigma(), cand.posTOFNSigma(), cand.posHasTOF()}; + } + + template + MomDaughter getNegDaughter(const TCand& cand) + { + return {cand.negPx(), cand.negPy(), cand.negPz(), cand.negTPCNSigma(), cand.negTOFNSigma(), cand.negHasTOF()}; + } + + template + void forEachDerivedCand(const TCands& cands, const F& f) + { + ROOT::Math::PxPyPzMVector mother; + for (const auto& cand : cands) { + const auto pos = getPosDaughter(cand); + const auto neg = getNegDaughter(cand); + if (!passDerivedPID(pos) || !passDerivedPID(neg)) { continue; } - if (isEffSample) { - histos.fill(HIST("closureKstarRecoEP/hMC"), 3.5); - } - if (isTestSample) { - histos.fill(HIST("closureKstarRecoEP/hMC"), 4.5); - } - const auto centrality = recCollision.centFT0C(); - const double recoPsiFT0C = recCollision.psiFT0C(); - const double psi = getSAEventAngle(recoPsiFT0C); // measured axis: defines cosRec (SE/ME/RecTrue/RecTrueEff/Rot) only - { - const double psiTPC = recCollision.psiTPC(); - const double psiFT0A = recCollision.psiFT0A(); - const double qFT0C = recCollision.qFT0C(); - const double qTPC = recCollision.qTPC(); - const double qFT0A = recCollision.qFT0A(); - histos.fill(HIST("closureKstarRecoEP/ResFT0CTPCSP"), centrality, qFT0C * qTPC * std::cos(2.0 * (recoPsiFT0C - psiTPC))); - histos.fill(HIST("closureKstarRecoEP/ResFT0CFT0ASP"), centrality, qFT0C * qFT0A * std::cos(2.0 * (recoPsiFT0C - psiFT0A))); - histos.fill(HIST("closureKstarRecoEP/ResFT0ATPCSP"), centrality, qTPC * qFT0A * std::cos(2.0 * (psiTPC - psiFT0A))); - // plain (unweighted) sub-event resolution, as needed by the EP-method correction formula; same definition as the data ResFT0CTPC etc. - histos.fill(HIST("closureKstarRecoEP/ResFT0CTPC"), centrality, std::cos(2.0 * (recoPsiFT0C - psiTPC))); - histos.fill(HIST("closureKstarRecoEP/ResFT0CFT0A"), centrality, std::cos(2.0 * (recoPsiFT0C - psiFT0A))); - histos.fill(HIST("closureKstarRecoEP/ResFT0ATPC"), centrality, std::cos(2.0 * (psiTPC - psiFT0A))); - // closure-only: Psi_FT0C vs the MC true event plane, to cross-check R from sub-events against the true R - histos.fill(HIST("closureKstarRecoEP/ResTrueFT0C"), centrality, std::cos(2.0 * (recoPsiFT0C - trueCollision.eventPlaneAngle()))); - } - auto recTracksThisColl = recTracks.sliceBy(perCollision, recCollision.globalIndex()); - - // ---- reconstructed pairs ---- - for (const auto& track1 : recTracksThisColl) { - if (!selectionTrack(track1) || !selectionClosurePrimary(track1)) { - continue; - } - if (!isTOFOnly && !strategySelectionPID(track1, 0, strategyPID)) { - continue; + if constexpr (IsPhi) { + if (makeCandPair(pos.px, pos.py, pos.pz, neg.px, neg.py, neg.pz, mother)) { + f(mother, ROOT::Math::PxPyPzMVector(neg.px, neg.py, neg.pz, MassKa)); } - if (isTOFOnly && !selectionPID2(track1, 0)) { - continue; + } else { + const auto& kaon = cand.flavour() > 0 ? pos : neg; + const auto& pion = cand.flavour() > 0 ? neg : pos; + if (makeCandPair(kaon.px, kaon.py, kaon.pz, pion.px, pion.py, pion.pz, mother)) { + f(mother, ROOT::Math::PxPyPzMVector(kaon.px, kaon.py, kaon.pz, MassKa)); } - for (const auto& track2 : recTracksThisColl) { - if (track2.globalIndex() == track1.globalIndex()) { - continue; - } - if (track1.sign() * track2.sign() > 0) { - continue; - } - if (!selectionTrack(track2) || !selectionClosurePrimary(track2)) { - continue; - } - if (!isTOFOnly && !strategySelectionPID(track2, 1, strategyPID)) { - continue; - } - if (isTOFOnly && !selectionPID2(track2, 1)) { - continue; - } - kaon = ROOT::Math::PxPyPzMVector(track1.px(), track1.py(), track1.pz(), MassKa); - pion = ROOT::Math::PxPyPzMVector(track2.px(), track2.py(), track2.pz(), MassPi); - kstar = kaon + pion; - if (std::abs(kstar.Rapidity()) > confRapidity) { - continue; - } - if (isPhiReflection(kaon, pion)) { - continue; - } - const double cosRec = getCosThetaStar(kstar, kaon, getSAAxis(kstar, psi)); + } + } + } - double weight = 1.0; - if (isTrueKstarPair(track1, track2)) { - const auto mcKaon = track1.mcParticle(); - const auto mcPion = track2.mcParticle(); - kaonGen = ROOT::Math::PxPyPzMVector(mcKaon.px(), mcKaon.py(), mcKaon.pz(), MassKa); - pionGen = ROOT::Math::PxPyPzMVector(mcPion.px(), mcPion.py(), mcPion.pz(), MassPi); - kstarGen = kaonGen + pionGen; - const double cosGen = getCosThetaStar(kstarGen, kaonGen, getSAAxis(kstarGen, psiTrue)); - weight = getInjectionWeight(cosGen); - // Acc x Eff must come from an unweighted (unpolarized) sample, independent of the injected rho00 under test - if (isEffSample) { - histos.fill(HIST("closureKstarRecoEP/hSparseRecTrueEff"), kstar.M(), kstar.Pt(), cosRec, centrality, 1.0); - } - if (isTestSample) { - histos.fill(HIST("closureKstarRecoEP/hSparseRecTrue"), kstar.M(), kstar.Pt(), cosRec, centrality, weight); - histos.fill(HIST("closureKstarRecoEP/hCosThetaStarGenVsRec"), cosGen, cosRec); - } - } - if (!isTestSample) { - continue; - } - histos.fill(HIST("closureKstarRecoEP/hSparseSE"), kstar.M(), kstar.Pt(), cosRec, centrality, weight); + void processMomentDerivedSE(aod::SpinAlignEvent const& event, aod::SAKstarCands const& kstars, aod::SAPhiCands const& phis) + { + const double psiSA = getSAEventAngle(event.psiFT0C()); + const double centrality = event.centFT0C(); + const int subsample = getMomentSubsample(event.globalIndex()); + histos.fill(HIST("moment/ResFT0CTPC"), centrality, std::cos(2.0 * (event.psiFT0C() - event.psiTPC()))); + histos.fill(HIST("moment/ResFT0CFT0A"), centrality, std::cos(2.0 * (event.psiFT0C() - event.psiFT0A()))); + histos.fill(HIST("moment/ResFT0ATPC"), centrality, std::cos(2.0 * (event.psiTPC() - event.psiFT0A()))); + forEachDerivedCand(kstars, [&](const auto& mother, const auto& daughter) { + fillMoments(mother.M(), mother.Pt(), centrality, kMomSEUnlike, subsample, getCosThetaStar(mother, daughter, getSAAxis(mother, psiSA))); + }); + forEachDerivedCand(phis, [&](const auto& mother, const auto& daughter) { + fillMoments(mother.M(), mother.Pt(), centrality, kMomSEUnlike, subsample, getCosThetaStar(mother, daughter, getSAAxis(mother, psiSA))); + }); + } + PROCESS_SWITCH(Kstarpbpb, processMomentDerivedSE, "rho00 derived: SE moments (sample 0), K* and phi", false); + + struct ReplCand { + float mass; + float pt; + float psi; + float psiRP; + float weight; + int64_t bcId; + double ux, uy, uz; + }; - // rotated background, same rotation as in processSE (weight 1) - if (closure.fillRotBkg && nBkgRotations.value > 1) { - const double angleStart = confMinRot.value; - const double angleStep = (confMaxRot.value - angleStart) / (nBkgRotations.value - 1.0); - for (int irot = 0; irot < nBkgRotations.value; irot++) { - const double rotAngle = angleStart + irot * angleStep; - kaonRot = ROOT::Math::PxPyPzMVector(track1.px() * std::cos(rotAngle) - track1.py() * std::sin(rotAngle), track1.px() * std::sin(rotAngle) + track1.py() * std::cos(rotAngle), track1.pz(), MassKa); - kstarRot = kaonRot + pion; - if (std::abs(kstarRot.Rapidity()) > confRapidity) { - continue; - } - if (isPhiReflection(kaonRot, pion)) { - continue; - } - const double cosRot = getCosThetaStar(kstarRot, kaonRot, getSAAxis(kstarRot, psi)); - histos.fill(HIST("closureKstarRecoEP/hSparseRot"), kstarRot.M(), kstarRot.Pt(), cosRot, centrality); - } + struct ReplCellBuffer { + std::vector cands; + std::size_t next = 0; + }; + + struct ReplPool { + std::unordered_map kstar, phi; + }; + + struct ReplEvent { + int64_t index = -1; + int64_t bcId = -1; + double psi = 0.; + double psiRP = 0.; + bool hasRP = false; + double centrality = 0.; + std::vector> kstar, phi; + }; + + using BinningTypeRepl = ColumnBinningPolicy; + static constexpr int64_t ReplCellStride = 4096; + static constexpr double ReplEtaOffset = 10.0; + + PresliceOptional kstarPerEventDerived = aod::savmcand::spinAlignEventId; + PresliceOptional phiPerEventDerived = aod::savmcand::spinAlignEventId; + + int64_t getReplCell(double pt, double eta, double phi) + { + double phi02 = std::fmod(phi, o2::constants::math::TwoPI); + if (phi02 < 0.) { + phi02 += o2::constants::math::TwoPI; + } + const auto iPt = static_cast(std::floor(pt / moment.replPtWidth.value)); + const auto iEta = static_cast(std::floor((eta + ReplEtaOffset) / moment.replEtaWidth.value)); + const auto iPhi = static_cast(std::floor(phi02 / moment.replPhiWidth.value)); + return (iPt * ReplCellStride + iEta) * ReplCellStride + iPhi; + } + + template + void addReplCand(ReplEvent& event, const ROOT::Math::PxPyPzMVector& mother, const ROOT::Math::PxPyPzMVector& daughter, double weight = 1.0) + { + if (!passCandWindow(mother)) { + return; + } + ROOT::Math::Boost boost{mother.BoostToCM()}; + const auto dir = boost(daughter).Vect().Unit(); + ReplCand cand{.mass = static_cast(mother.M()), .pt = static_cast(mother.Pt()), .psi = static_cast(event.psi), .psiRP = static_cast(event.psiRP), .weight = static_cast(weight), .bcId = event.bcId, .ux = dir.X(), .uy = dir.Y(), .uz = dir.Z()}; + auto& cands = IsPhi ? event.phi : event.kstar; + cands.emplace_back(getReplCell(mother.Pt(), mother.Eta(), mother.Phi()), cand); + } + + template + void mixReplacement(const ReplEvent& event, ReplPool& pool) + { + const auto& targets = IsPhi ? event.phi : event.kstar; + auto& cells = IsPhi ? pool.phi : pool.kstar; + const auto targetAxis = getEPAxis(event.psi); + const int subsample = getMomentSubsample(event.index); + for (const auto& [cell, target] : targets) { + const auto found = cells.find(cell); + if (found == cells.end() || found->second.cands.empty()) { + if constexpr (IsPhi) { + histos.fill(HIST("moment/phi/hReplacement"), 1); + } else { + histos.fill(HIST("moment/kstar/hReplacement"), 1); + } + continue; + } + if constexpr (IsPhi) { + histos.fill(HIST("moment/phi/hReplacement"), 0); + } else { + histos.fill(HIST("moment/kstar/hReplacement"), 0); + } + const auto& donors = found->second.cands; + for (int iDraw = 0; iDraw < moment.replNDraws.value; ++iDraw) { + const auto& donor = donors[rndGen.Integer(static_cast(donors.size()))]; + if (event.bcId >= 0 && donor.bcId == event.bcId) { + continue; + } + const auto axis = cfgSAFrame.value == kRandom3D ? getRandom3DAxis() : targetAxis; + const double cosThetaStar = donor.ux * axis.X() + donor.uy * axis.Y() + donor.uz * axis.Z(); + const double weight = target.weight * donor.weight; + const double cos2DeltaPsi = std::cos(2.0 * (event.psi - donor.psi)); + fillMoments(donor.mass, donor.pt, event.centrality, kMomMERepl, subsample, cosThetaStar, weight); + histos.fill(HIST("moment/hReplCos2DeltaPsi"), event.centrality, cos2DeltaPsi); + if constexpr (IsPhi) { + histos.fill(HIST("moment/phi/hXD"), donor.mass, donor.pt, event.centrality, kMomMERepl, subsample, weight * cos2DeltaPsi); + } else { + histos.fill(HIST("moment/kstar/hXD"), donor.mass, donor.pt, event.centrality, kMomMERepl, subsample, weight * cos2DeltaPsi); + } + if (event.hasRP) { + const double cos2EPRP = std::cos(2.0 * (event.psi - donor.psiRP)); + if constexpr (IsPhi) { + histos.fill(HIST("moment/phi/hXC"), donor.mass, donor.pt, event.centrality, kMomMERepl, subsample, weight * cos2EPRP); + } else { + histos.fill(HIST("moment/kstar/hXC"), donor.mass, donor.pt, event.centrality, kMomMERepl, subsample, weight * cos2EPRP); } } } + } + const auto capacity = static_cast(moment.replCellCapacity.value); + for (const auto& [cell, cand] : targets) { + auto& buffer = cells[cell]; + if (buffer.cands.size() < capacity) { + buffer.cands.push_back(cand); + } else { + buffer.cands[buffer.next] = cand; + buffer.next = (buffer.next + 1) % capacity; + } + } + } - // ---- generated K*0 / anti-K*0: Acc x Eff denominator (eff sample) and input truth (test sample) ---- - for (const auto& mcParticle : genParticles) { - if (std::abs(mcParticle.y()) > confRapidity) { + template + void buildReplCandsKstarMC(ReplEvent& event, TTracks const& tracks) + { + ROOT::Math::PxPyPzMVector kaon, pion; + for (const auto& track1 : tracks) { + if (!selectionTrack(track1) || !selectionClosurePrimary(track1)) { + continue; + } + if ((!isTOFOnly && !strategySelectionPID(track1, 0, strategyPID)) || (isTOFOnly && !selectionPID2(track1, 0))) { + continue; + } + for (const auto& track2 : tracks) { + if (track1.sign() * track2.sign() >= 0) { continue; } - if (std::abs(mcParticle.pdgCode()) != o2::constants::physics::kK0Star892) { + if (!selectionTrack(track2) || !selectionClosurePrimary(track2)) { continue; } - auto daughters = mcParticle.daughters_as(); - if (daughters.size() != NumberOfDaughters) { + if ((!isTOFOnly && !strategySelectionPID(track2, 1, strategyPID)) || (isTOFOnly && !selectionPID2(track2, 1))) { continue; } - bool hasKaon = false; - bool hasPion = false; - for (const auto& dau : daughters) { - if (!dau.isPhysicalPrimary()) { - continue; - } - const bool inAcceptance = !closure.genAcceptanceCut || (dau.pt() > cfgCutPT && std::abs(dau.eta()) < cfgCutEta); - if (std::abs(dau.pdgCode()) == PDG_t::kKPlus) { - hasKaon = hasKaon || inAcceptance; - kaonGen = ROOT::Math::PxPyPzMVector(dau.px(), dau.py(), dau.pz(), MassKa); - } else if (std::abs(dau.pdgCode()) == PDG_t::kPiPlus) { - hasPion = hasPion || inAcceptance; - pionGen = ROOT::Math::PxPyPzMVector(dau.px(), dau.py(), dau.pz(), MassPi); - } - } - if (!hasKaon || !hasPion) { + kaon = ROOT::Math::PxPyPzMVector(track1.px(), track1.py(), track1.pz(), MassKa); + pion = ROOT::Math::PxPyPzMVector(track2.px(), track2.py(), track2.pz(), MassPi); + if (isPhiReflection(kaon, pion)) { continue; } - kstarGen = kaonGen + pionGen; - if (std::abs(kstarGen.Rapidity()) > confRapidity) { - continue; - } - const double cosGen = getCosThetaStar(kstarGen, kaonGen, getSAAxis(kstarGen, psiTrue)); - // Acc x Eff must come from an unweighted (unpolarized) sample, independent of the injected rho00 under test - if (isEffSample) { - histos.fill(HIST("closureKstarRecoEP/hSparseGenEff"), kstarGen.M(), kstarGen.Pt(), cosGen, centrality, 1.0); - } - if (isTestSample) { - const double weight = getInjectionWeight(cosGen); - histos.fill(HIST("closureKstarRecoEP/hSparseGen"), kstarGen.M(), kstarGen.Pt(), cosGen, centrality, weight); + double weight = 1.0; + if (isTrueKstarPair(track1, track2)) { + const auto mcKaon = track1.mcParticle(); + const auto mcPion = track2.mcParticle(); + const ROOT::Math::PxPyPzMVector kaonGen(mcKaon.px(), mcKaon.py(), mcKaon.pz(), MassKa); + const ROOT::Math::PxPyPzMVector pionGen(mcPion.px(), mcPion.py(), mcPion.pz(), MassPi); + const auto kstarGen = kaonGen + pionGen; + weight = getInjectionWeight(getCosThetaStar(kstarGen, kaonGen, getSAAxis(kstarGen, event.psiRP))); } + addReplCand(event, kaon + pion, kaon, weight); } - } // rec collision loop + } } - PROCESS_SWITCH(Kstarpbpb, processMCClosureRecoEP, "Process MC closure of cos(theta*) for K*, reconstructed Psi_FT0C: SE, true rec, gen", false); - // ---------------- K*0: mixed event of the test sample (reconstructed Psi_FT0C) ---------------- - void processMCClosureMERecoEP(CollisionMCRecMixTableRecoEP const& collisions, FilTrackMCRecTable const& tracks, aod::McCollisions const& mcCollisions, aod::McCollisionLabels const& mcLabels, aod::McParticles const&) + template + void buildReplCandsPhiMC(ReplEvent& event, TTracks const& tracks) { - ROOT::Math::PxPyPzMVector kaon, pion, kstar; - const auto nRecPerMc = countRecoPerMcCollision(mcLabels, mcCollisions.size()); - auto tracksTuple = std::make_tuple(tracks); - BinningTypeMCClosureRecoEP binningOnPositions{{axisVertex, axisMultiplicityClass, axisEPAngle}}; - SameKindPair pair{binningOnPositions, cfgNoMixedEvents, -1, collisions, tracksTuple, &cache}; - for (const auto& [collision1, tracks1, collision2, tracks2] : pair) { - if (!selectionClosurePairMERecoEP(collision1, collision2, nRecPerMc)) { + ROOT::Math::PxPyPzMVector kaonPlus, kaonMinus; + for (const auto& track1 : tracks) { + if (!(track1.signed1Pt() > cfgCutCharge.value) || !selectionTrackPhi(track1) || !selectionPIDPhi(track1) || !selectionClosurePrimary(track1)) { continue; } - const auto centrality = collision1.centFT0C(); - const double psi = getSAEventAngle(collision1.psiFT0C()); - for (const auto& [track1, track2] : o2::soa::combinations(o2::soa::CombinationsFullIndexPolicy(tracks1, tracks2))) { - if (track1.sign() * track2.sign() > 0) { - continue; - } - if (!selectionTrack(track1) || !selectionTrack(track2)) { - continue; - } - if (!selectionClosurePrimary(track1) || !selectionClosurePrimary(track2)) { - continue; - } - if (!isTOFOnly && (!strategySelectionPID(track1, 0, strategyPID) || !strategySelectionPID(track2, 1, strategyPID))) { + for (const auto& track2 : tracks) { + if (!(track2.signed1Pt() < cfgCutCharge.value) || !selectionTrackPhi(track2) || !selectionPIDPhi(track2) || !selectionClosurePrimary(track2)) { continue; } - if (isTOFOnly && (!selectionPID2(track1, 0) || !selectionPID2(track2, 1))) { + if (!selectionPairPhi(track1, track2)) { continue; } - kaon = ROOT::Math::PxPyPzMVector(track1.px(), track1.py(), track1.pz(), MassKa); - pion = ROOT::Math::PxPyPzMVector(track2.px(), track2.py(), track2.pz(), MassPi); - kstar = kaon + pion; - if (std::abs(kstar.Rapidity()) > confRapidity) { + if (phiSA.removeFakeTrack && (isFakeKaonPhi(track1) || isFakeKaonPhi(track2))) { continue; } - if (isPhiReflection(kaon, pion)) { - continue; + kaonPlus = ROOT::Math::PxPyPzMVector(track1.px(), track1.py(), track1.pz(), MassKa); + kaonMinus = ROOT::Math::PxPyPzMVector(track2.px(), track2.py(), track2.pz(), MassKa); + double weight = 1.0; + if (isTruePhiPair(track1, track2)) { + const auto mcPlus = track1.mcParticle(); + const auto mcMinus = track2.mcParticle(); + const ROOT::Math::PxPyPzMVector kaonPlusGen(mcPlus.px(), mcPlus.py(), mcPlus.pz(), MassKa); + const ROOT::Math::PxPyPzMVector kaonMinusGen(mcMinus.px(), mcMinus.py(), mcMinus.pz(), MassKa); + const auto phiGen = kaonPlusGen + kaonMinusGen; + weight = getInjectionWeight(getCosThetaStar(phiGen, kaonMinusGen, getSAAxis(phiGen, event.psiRP))); } - const double cosRec = getCosThetaStar(kstar, kaon, getSAAxis(kstar, psi)); - histos.fill(HIST("closureKstarRecoEP/hSparseME"), kstar.M(), kstar.Pt(), cosRec, centrality); + addReplCand(event, kaonPlus + kaonMinus, kaonMinus, weight); } } } - PROCESS_SWITCH(Kstarpbpb, processMCClosureMERecoEP, "Process MC closure of cos(theta*) for K*, reconstructed Psi_FT0C: mixed event", false); - // ---------------- phi(1020): same event, true reco, generated (reconstructed Psi_FT0C) ---------------- - void processMCClosureRecoEPPhi(CollisionMCTrueTable::iterator const& trueCollision, CollisionMCRecTableClosure const& recCollisions, TrackMCTrueTable const& genParticles, FilTrackMCRecTable const& recTracks) + template + void runMCClosureReplacementME(CollisionMCRecMixTableRecoEP const& collisions, FilTrackMCRecTable const& tracks, aod::McCollisions const& mcCollisions, aod::McCollisionLabels const& mcLabels) { - ROOT::Math::PxPyPzMVector kaonPlus, kaonMinus, phi, kaonPlusRot, phiRot, kaonPlusGen, kaonMinusGen, phiGen; - static constexpr std::size_t NumberOfDaughters = 2; - - histos.fill(HIST("closurePhiRecoEP/hMC"), 0.5); - if (recCollisions.size() == 0) { - histos.fill(HIST("closurePhiRecoEP/hMC"), 1.5); - return; - } - if (recCollisions.size() > 1) { - histos.fill(HIST("closurePhiRecoEP/hMC"), 2.5); - return; - } - const bool isEffSample = isClosureEffSample(trueCollision.globalIndex()); - const bool isTestSample = isClosureTestSample(trueCollision.globalIndex()); - // true axis: defines the injected weight and the Gen/GenEff truth, so the test is not tautological against the smeared axis - const double psiTrue = getSAEventAngle(trueCollision.eventPlaneAngle()); - for (const auto& recCollision : recCollisions) { - if (!selectionEventMCRecoEP(recCollision)) { + const auto nRecPerMc = countRecoPerMcCollision(mcLabels, mcCollisions.size()); + BinningTypeRepl binning{{moment.replAxisVertex, moment.axisCentrality}, true}; + std::vector pools(binning.getAllBinsCount()); + for (const auto& collision : collisions) { + if (!selectionEventMCRecoEP(collision) || !collision.has_mcCollision()) { continue; } - if (isEffSample) { - histos.fill(HIST("closurePhiRecoEP/hMC"), 3.5); + const auto mcCollisionId = collision.mcCollisionId(); + if (!isClosureTestSample(mcCollisionId) || nRecPerMc[mcCollisionId] != 1) { + continue; } - if (isTestSample) { - histos.fill(HIST("closurePhiRecoEP/hMC"), 4.5); + const int bin = binning.getBin(std::make_tuple(collision.posZ(), collision.centFT0C())); + if (bin < 0) { + continue; } - const auto centrality = recCollision.centFT0C(); - const double recoPsiFT0C = recCollision.psiFT0C(); - const double psi = getSAEventAngle(recoPsiFT0C); // measured axis: defines cosRec (SE/ME/RecTrue/RecTrueEff/Rot) only - { - const double psiTPC = recCollision.psiTPC(); - const double psiFT0A = recCollision.psiFT0A(); - const double qFT0C = recCollision.qFT0C(); - const double qTPC = recCollision.qTPC(); - const double qFT0A = recCollision.qFT0A(); - histos.fill(HIST("closurePhiRecoEP/ResFT0CTPCSP"), centrality, qFT0C * qTPC * std::cos(2.0 * (recoPsiFT0C - psiTPC))); - histos.fill(HIST("closurePhiRecoEP/ResFT0CFT0ASP"), centrality, qFT0C * qFT0A * std::cos(2.0 * (recoPsiFT0C - psiFT0A))); - histos.fill(HIST("closurePhiRecoEP/ResFT0ATPCSP"), centrality, qTPC * qFT0A * std::cos(2.0 * (psiTPC - psiFT0A))); - // plain (unweighted) sub-event resolution, as needed by the EP-method correction formula; same definition as the data ResFT0CTPC etc. - histos.fill(HIST("closurePhiRecoEP/ResFT0CTPC"), centrality, std::cos(2.0 * (recoPsiFT0C - psiTPC))); - histos.fill(HIST("closurePhiRecoEP/ResFT0CFT0A"), centrality, std::cos(2.0 * (recoPsiFT0C - psiFT0A))); - histos.fill(HIST("closurePhiRecoEP/ResFT0ATPC"), centrality, std::cos(2.0 * (psiTPC - psiFT0A))); - // closure-only: Psi_FT0C vs the MC true event plane, to cross-check R from sub-events against the true R - histos.fill(HIST("closurePhiRecoEP/ResTrueFT0C"), centrality, std::cos(2.0 * (recoPsiFT0C - trueCollision.eventPlaneAngle()))); + auto tracksThisEvent = tracks.sliceBy(perCollision, collision.globalIndex()); + ReplEvent event; + event.index = collision.globalIndex(); + event.bcId = collision.bcId(); + event.psi = getSAEventAngle(collision.psiFT0C()); + event.psiRP = getSAEventAngle(collision.mcCollision_as().eventPlaneAngle()); + event.hasRP = true; + event.centrality = collision.centFT0C(); + if constexpr (IsPhi) { + buildReplCandsPhiMC(event, tracksThisEvent); + } else { + buildReplCandsKstarMC(event, tracksThisEvent); + } + mixReplacement(event, pools[bin]); + } + } + + void processMCClosureReplacementME(CollisionMCRecMixTableRecoEP const& collisions, FilTrackMCRecTable const& tracks, aod::McCollisions const& mcCollisions, aod::McCollisionLabels const& mcLabels, aod::McParticles const&) + { + runMCClosureReplacementME(collisions, tracks, mcCollisions, mcLabels); + } + PROCESS_SWITCH(Kstarpbpb, processMCClosureReplacementME, "rho00 K* MC closure: replacement ME of the test sample with injected weights (sample 1), plane correlation hXD and hXC", false); + + void processMCClosureReplacementMEPhi(CollisionMCRecMixTableRecoEP const& collisions, FilTrackMCRecTable const& tracks, aod::McCollisions const& mcCollisions, aod::McCollisionLabels const& mcLabels, aod::McParticles const&) + { + runMCClosureReplacementME(collisions, tracks, mcCollisions, mcLabels); + } + PROCESS_SWITCH(Kstarpbpb, processMCClosureReplacementMEPhi, "rho00 phi MC closure: replacement ME of the test sample with injected weights (sample 1), plane correlation hXD and hXC", false); + + void processMomentDerivedMERepl(aod::SpinAlignEvents const& events, aod::SAKstarCands const& kstars, aod::SAPhiCands const& phis) + { + BinningTypeRepl binning{{moment.replAxisVertex, moment.axisCentrality}, true}; + std::vector pools(binning.getAllBinsCount()); + for (const auto& ev : events) { + const int bin = binning.getBin(std::make_tuple(ev.posZ(), ev.centFT0C())); + if (bin < 0) { + continue; } - auto recTracksThisColl = recTracks.sliceBy(perCollision, recCollision.globalIndex()); + ReplEvent event; + event.index = ev.globalIndex(); + event.psi = getSAEventAngle(ev.psiFT0C()); + event.centrality = ev.centFT0C(); + forEachDerivedCand(kstars.sliceBy(kstarPerEventDerived, ev.globalIndex()), [&](const auto& mother, const auto& daughter) { + addReplCand(event, mother, daughter); + }); + forEachDerivedCand(phis.sliceBy(phiPerEventDerived, ev.globalIndex()), [&](const auto& mother, const auto& daughter) { + addReplCand(event, mother, daughter); + }); + mixReplacement(event, pools[bin]); + mixReplacement(event, pools[bin]); + } + } + PROCESS_SWITCH(Kstarpbpb, processMomentDerivedMERepl, "rho00 derived: ME reference by candidate replacement (sample 1), K* and phi", false); + + struct V2Track { + float px; + float py; + float pz; + float phi; + int8_t sign; + bool isKaon; + bool isPion; + }; - // ---- reconstructed pairs ---- - for (const auto& track1 : recTracksThisColl) { - if (!(track1.signed1Pt() > cfgCutCharge.value)) { // K+ - continue; - } - if (!selectionTrackPhi(track1) || !selectionPIDPhi(track1) || !selectionClosurePrimary(track1)) { - continue; - } - for (const auto& track2 : recTracksThisColl) { - if (!(track2.signed1Pt() < cfgCutCharge.value)) { // K- - continue; - } - if (!selectionTrackPhi(track2) || !selectionPIDPhi(track2) || !selectionClosurePrimary(track2)) { - continue; - } - if (!selectionPairPhi(track1, track2)) { - continue; - } - if (phiSA.removeFakeTrack && (isFakeKaonPhi(track1) || isFakeKaonPhi(track2))) { - continue; - } - kaonPlus = ROOT::Math::PxPyPzMVector(track1.px(), track1.py(), track1.pz(), MassKa); - kaonMinus = ROOT::Math::PxPyPzMVector(track2.px(), track2.py(), track2.pz(), MassKa); - phi = kaonPlus + kaonMinus; - if (std::abs(phi.Rapidity()) > phiSA.confRapidity) { - continue; - } - const double cosRec = getCosThetaStar(phi, kaonMinus, getSAAxis(phi, psi)); + struct V2Event { + int64_t index = -1; + double psi = 0.; + double q = 0.; + double centrality = 0.; + std::vector tracks; + }; - double weight = 1.0; - if (isTruePhiPair(track1, track2)) { - const auto mcPlus = track1.mcParticle(); - const auto mcMinus = track2.mcParticle(); - kaonPlusGen = ROOT::Math::PxPyPzMVector(mcPlus.px(), mcPlus.py(), mcPlus.pz(), MassKa); - kaonMinusGen = ROOT::Math::PxPyPzMVector(mcMinus.px(), mcMinus.py(), mcMinus.pz(), MassKa); - phiGen = kaonPlusGen + kaonMinusGen; - const double cosGen = getCosThetaStar(phiGen, kaonMinusGen, getSAAxis(phiGen, psiTrue)); - weight = getInjectionWeight(cosGen); - // Acc x Eff must come from an unweighted (unpolarized) sample, independent of the injected rho00 under test - if (isEffSample) { - histos.fill(HIST("closurePhiRecoEP/hSparseRecTrueEff"), phi.M(), phi.Pt(), cosRec, centrality, 1.0); - } - if (isTestSample) { - histos.fill(HIST("closurePhiRecoEP/hSparseRecTrue"), phi.M(), phi.Pt(), cosRec, centrality, weight); - histos.fill(HIST("closurePhiRecoEP/hCosThetaStarGenVsRec"), cosGen, cosRec); - } - } - if (!isTestSample) { - continue; - } - histos.fill(HIST("closurePhiRecoEP/hSparseSE"), phi.M(), phi.Pt(), cosRec, centrality, weight); + using BinningTypeV2Derived = ColumnBinningPolicy; + PresliceOptional trackPerEventV2 = aod::savmtrack::spinAlignEventId; - // rotated background: rotate the K+ (weight 1) - if (closure.fillRotBkg && nBkgRotations.value > 1) { - const double angleStart = confMinRot.value; - const double angleStep = (confMaxRot.value - angleStart) / (nBkgRotations.value - 1.0); - for (int irot = 0; irot < nBkgRotations.value; irot++) { - const double rotAngle = angleStart + irot * angleStep; - kaonPlusRot = ROOT::Math::PxPyPzMVector(track1.px() * std::cos(rotAngle) - track1.py() * std::sin(rotAngle), track1.px() * std::sin(rotAngle) + track1.py() * std::cos(rotAngle), track1.pz(), MassKa); - phiRot = kaonPlusRot + kaonMinus; - if (std::abs(phiRot.Rapidity()) > phiSA.confRapidity) { - continue; - } - const double cosRot = getCosThetaStar(phiRot, kaonMinus, getSAAxis(phiRot, psi)); - histos.fill(HIST("closurePhiRecoEP/hSparseRot"), phiRot.M(), phiRot.Pt(), cosRot, centrality); - } - } - } + template + V2Event buildV2Event(const TEvent& event, const TTracks& tracks) + { + V2Event v2Event; + v2Event.index = event.globalIndex(); + v2Event.psi = event.psiFT0C(); + v2Event.q = event.qFT0C(); + v2Event.centrality = event.centFT0C(); + for (const auto& track : tracks) { + const bool kaon = track.isKaon() && passDerivedPID(MomDaughter{track.px(), track.py(), track.pz(), track.tpcNSigmaKa(), track.tofNSigmaKa(), track.hasTOF()}); + const bool pion = track.isPion() && passDerivedPID(MomDaughter{track.px(), track.py(), track.pz(), track.tpcNSigmaPi(), track.tofNSigmaPi(), track.hasTOF()}); + if (!kaon && !pion) { + continue; } + v2Event.tracks.push_back({track.px(), track.py(), track.pz(), static_cast(std::atan2(track.py(), track.px())), track.sign(), kaon, pion}); + } + return v2Event; + } - // ---- generated phi: Acc x Eff denominator (eff sample) and input truth (test sample) ---- - for (const auto& mcParticle : genParticles) { - if (std::abs(mcParticle.y()) > phiSA.confRapidity) { - continue; - } - if (mcParticle.pdgCode() != o2::constants::physics::kPhi) { - continue; - } - auto daughters = mcParticle.daughters_as(); - if (daughters.size() != NumberOfDaughters) { + void fillV2LikeSignSE(const V2Event& event) + { + ROOT::Math::PxPyPzMVector mother; + const auto& tracks = event.tracks; + for (std::size_t i = 0; i < tracks.size(); ++i) { + for (std::size_t j = 0; j < tracks.size(); ++j) { + if (i == j || tracks[i].sign != tracks[j].sign) { continue; } - bool hasKPlus = false; - bool hasKMinus = false; - for (const auto& dau : daughters) { - if (!dau.isPhysicalPrimary()) { - continue; - } - const bool inAcceptance = !closure.genAcceptanceCut || (dau.pt() > cfgCutPT && std::abs(dau.eta()) < cfgCutEta); - if (dau.pdgCode() == PDG_t::kKPlus) { - hasKPlus = hasKPlus || inAcceptance; - kaonPlusGen = ROOT::Math::PxPyPzMVector(dau.px(), dau.py(), dau.pz(), MassKa); - } else if (dau.pdgCode() == PDG_t::kKMinus) { - hasKMinus = hasKMinus || inAcceptance; - kaonMinusGen = ROOT::Math::PxPyPzMVector(dau.px(), dau.py(), dau.pz(), MassKa); + if (tracks[i].isKaon && tracks[j].isPion && makeCandPair(tracks[i].px, tracks[i].py, tracks[i].pz, tracks[j].px, tracks[j].py, tracks[j].pz, mother)) { + if (tracks[i].sign > 0) { + histos.fill(HIST("v2derived/kstar/hSELikePP"), mother.M(), mother.Pt(), event.centrality); + } else { + histos.fill(HIST("v2derived/kstar/hSELikeNN"), mother.M(), mother.Pt(), event.centrality); } } - if (!hasKPlus || !hasKMinus) { - continue; - } - phiGen = kaonPlusGen + kaonMinusGen; - const double cosGen = getCosThetaStar(phiGen, kaonMinusGen, getSAAxis(phiGen, psiTrue)); - // Acc x Eff must come from an unweighted (unpolarized) sample, independent of the injected rho00 under test - if (isEffSample) { - histos.fill(HIST("closurePhiRecoEP/hSparseGenEff"), phiGen.M(), phiGen.Pt(), cosGen, centrality, 1.0); - } - if (isTestSample) { - const double weight = getInjectionWeight(cosGen); - histos.fill(HIST("closurePhiRecoEP/hSparseGen"), phiGen.M(), phiGen.Pt(), cosGen, centrality, weight); + if (j > i && tracks[i].isKaon && tracks[j].isKaon && makeCandPair(tracks[i].px, tracks[i].py, tracks[i].pz, tracks[j].px, tracks[j].py, tracks[j].pz, mother)) { + if (tracks[i].sign > 0) { + histos.fill(HIST("v2derived/phi/hSELikePP"), mother.M(), mother.Pt(), event.centrality); + } else { + histos.fill(HIST("v2derived/phi/hSELikeNN"), mother.M(), mother.Pt(), event.centrality); + } } } - } // rec collision loop + } } - PROCESS_SWITCH(Kstarpbpb, processMCClosureRecoEPPhi, "Process MC closure of cos(theta*) for phi(1020), reconstructed Psi_FT0C: SE, true rec, gen", false); - // ---------------- phi(1020): mixed event of the test sample (reconstructed Psi_FT0C) ---------------- - void processMCClosureMERecoEPPhi(CollisionMCRecMixTableRecoEP const& collisions, FilTrackMCRecTable const& tracks, aod::McCollisions const& mcCollisions, aod::McCollisionLabels const& mcLabels, aod::McParticles const&) + static double v2DaughterTerm(const V2Event& event, const V2Track& track, double phiMother) { - ROOT::Math::PxPyPzMVector kaonPlus, kaonMinus, phi; - const auto nRecPerMc = countRecoPerMcCollision(mcLabels, mcCollisions.size()); - auto tracksTuple = std::make_tuple(tracks); - BinningTypeMCClosureRecoEP binningOnPositions{{axisVertex, axisMultiplicityClass, axisEPAngle}}; - SameKindPair pair{binningOnPositions, cfgNoMixedEvents, -1, collisions, tracksTuple, &cache}; - for (const auto& [collision1, tracks1, collision2, tracks2] : pair) { - if (!selectionClosurePairMERecoEP(collision1, collision2, nRecPerMc)) { + return event.q * std::cos(2.0 * (track.phi - event.psi)) * std::cos(2.0 * (track.phi - phiMother)); + } + + void fillV2MixedKstar(const V2Event& a, const V2Event& b, double centrality) + { + ROOT::Math::PxPyPzMVector mother; + for (const auto& kaon : a.tracks) { + if (!kaon.isKaon) { continue; } - const auto centrality = collision1.centFT0C(); - const double psi = getSAEventAngle(collision1.psiFT0C()); - for (const auto& [track1, track2] : o2::soa::combinations(o2::soa::CombinationsFullIndexPolicy(tracks1, tracks2))) { - if (track1.sign() * track2.sign() > 0) { - continue; - } - if (!selectionTrackPhi(track1) || !selectionTrackPhi(track2)) { - continue; - } - if (!selectionClosurePrimary(track1) || !selectionClosurePrimary(track2)) { - continue; - } - if (!selectionPIDPhi(track1) || !selectionPIDPhi(track2)) { + for (const auto& pion : b.tracks) { + if (!pion.isPion || !makeCandPair(kaon.px, kaon.py, kaon.pz, pion.px, pion.py, pion.pz, mother)) { continue; } - if (!selectionPairPhi(track1, track2)) { - continue; + if (kaon.sign != pion.sign) { + const double term = v2DaughterTerm(a, kaon, mother.Phi()) + v2DaughterTerm(b, pion, mother.Phi()); + histos.fill(HIST("v2derived/kstar/hMEUnlike"), mother.M(), mother.Pt(), term, centrality); + } else if (kaon.sign > 0) { + histos.fill(HIST("v2derived/kstar/hMELikePP"), mother.M(), mother.Pt(), centrality); + } else { + histos.fill(HIST("v2derived/kstar/hMELikeNN"), mother.M(), mother.Pt(), centrality); } - if (phiSA.removeFakeTrack && (isFakeKaonPhi(track1) || isFakeKaonPhi(track2))) { + } + } + } + + void fillV2MixedPhi(const V2Event& a, const V2Event& b, double centrality) + { + ROOT::Math::PxPyPzMVector mother; + for (const auto& kaonA : a.tracks) { + if (!kaonA.isKaon) { + continue; + } + for (const auto& kaonB : b.tracks) { + if (!kaonB.isKaon || !makeCandPair(kaonA.px, kaonA.py, kaonA.pz, kaonB.px, kaonB.py, kaonB.pz, mother)) { continue; } - if (track1.sign() > 0) { - kaonPlus = ROOT::Math::PxPyPzMVector(track1.px(), track1.py(), track1.pz(), MassKa); - kaonMinus = ROOT::Math::PxPyPzMVector(track2.px(), track2.py(), track2.pz(), MassKa); + if (kaonA.sign != kaonB.sign) { + const double term = v2DaughterTerm(a, kaonA, mother.Phi()) + v2DaughterTerm(b, kaonB, mother.Phi()); + histos.fill(HIST("v2derived/phi/hMEUnlike"), mother.M(), mother.Pt(), term, centrality); + } else if (kaonA.sign > 0) { + histos.fill(HIST("v2derived/phi/hMELikePP"), mother.M(), mother.Pt(), centrality); } else { - kaonMinus = ROOT::Math::PxPyPzMVector(track1.px(), track1.py(), track1.pz(), MassKa); - kaonPlus = ROOT::Math::PxPyPzMVector(track2.px(), track2.py(), track2.pz(), MassKa); + histos.fill(HIST("v2derived/phi/hMELikeNN"), mother.M(), mother.Pt(), centrality); } - phi = kaonPlus + kaonMinus; - if (std::abs(phi.Rapidity()) > phiSA.confRapidity) { - continue; - } - const double cosRec = getCosThetaStar(phi, kaonMinus, getSAAxis(phi, psi)); - histos.fill(HIST("closurePhiRecoEP/hSparseME"), phi.M(), phi.Pt(), cosRec, centrality); } } } - PROCESS_SWITCH(Kstarpbpb, processMCClosureMERecoEPPhi, "Process MC closure of cos(theta*) for phi(1020), reconstructed Psi_FT0C: mixed event", false); + + void processV2DerivedSE(aod::SpinAlignEvent const& event, aod::SAKstarCands const& kstars, aod::SAPhiCands const& phis, aod::SAVMTracks const& tracks) + { + const double centrality = event.centFT0C(); + const double psi = event.psiFT0C(); + const double q = event.qFT0C(); + histos.fill(HIST("v2derived/ResFT0CTPCSP"), centrality, event.qFT0C() * event.qTPC() * std::cos(2.0 * (event.psiFT0C() - event.psiTPC()))); + histos.fill(HIST("v2derived/ResFT0CFT0ASP"), centrality, event.qFT0C() * event.qFT0A() * std::cos(2.0 * (event.psiFT0C() - event.psiFT0A()))); + histos.fill(HIST("v2derived/ResFT0ATPCSP"), centrality, event.qFT0A() * event.qTPC() * std::cos(2.0 * (event.psiFT0A() - event.psiTPC()))); + + forEachDerivedCand(kstars, [&](const auto& mother, const auto&) { + histos.fill(HIST("v2derived/kstar/hSEUnlike"), mother.M(), mother.Pt(), q * std::cos(2.0 * (mother.Phi() - psi)), centrality); + }); + forEachDerivedCand(phis, [&](const auto& mother, const auto&) { + histos.fill(HIST("v2derived/phi/hSEUnlike"), mother.M(), mother.Pt(), q * std::cos(2.0 * (mother.Phi() - psi)), centrality); + }); + + fillV2LikeSignSE(buildV2Event(event, tracks)); + } + PROCESS_SWITCH(Kstarpbpb, processV2DerivedSE, "v2 derived: same event (u2 Q2* vs mass, like-sign pairs, SP resolution), K* and phi", false); + + void processV2DerivedME(aod::SpinAlignEvents const& events, aod::SAVMTracks const& tracks) + { + BinningTypeV2Derived binning{{v2Derived.mixAxisVertex, v2Derived.axisCentrality}, true}; + std::vector> pools(binning.getAllBinsCount()); + for (const auto& event : events) { + const int bin = binning.getBin(std::make_tuple(event.posZ(), event.centFT0C())); + if (bin < 0) { + continue; + } + auto tracksThisEvent = tracks.sliceBy(trackPerEventV2, event.globalIndex()); + V2Event current = buildV2Event(event, tracksThisEvent); + for (const auto& previous : pools[bin]) { + histos.fill(HIST("v2derived/hMixedEventPairs"), current.centrality); + fillV2MixedKstar(current, previous, current.centrality); + fillV2MixedKstar(previous, current, current.centrality); + fillV2MixedPhi(current, previous, current.centrality); + } + pools[bin].push_back(std::move(current)); + if (static_cast(pools[bin].size()) > v2Derived.nMixedEvents.value) { + pools[bin].pop_front(); + } + } + } + PROCESS_SWITCH(Kstarpbpb, processV2DerivedME, "v2 derived: mixed event (background v2, Eq. 5; like-sign normalisation, Eq. 6), K* and phi", false); }; WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) {