diff --git a/PWGJE/DataModel/HadronPhotonCorrelation.h b/PWGJE/DataModel/HadronPhotonCorrelation.h new file mode 100644 index 00000000000..b42cecae505 --- /dev/null +++ b/PWGJE/DataModel/HadronPhotonCorrelation.h @@ -0,0 +1,284 @@ +// 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. + +/// +/// \brief table definitions for hadron-photon correlation analyses +/// +/// \author Julius Kinner +/// \file HadronPhotonCorrelation.h + +#ifndef PWGJE_DATAMODEL_HADRONPHOTONCORRELATION_H_ +#define PWGJE_DATAMODEL_HADRONPHOTONCORRELATION_H_ + +#include "PWGEM/PhotonMeson/DataModel/gammaTables.h" +#include "PWGJE/DataModel/Jet.h" +#include "PWGJE/DataModel/JetReducedData.h" + +#include + +namespace hpc +{ + +enum class AssocType { + Hadron, + Pipm, + PhotonPcm, + PhotonDecay, + PhotonDirect, + PhotonPcmPair, + Pi0Pcm, + Pi0PcmPeak, + Pi0PcmSide, + PhotonPi0, + EtaPcm, + EtaPcmPeak, + EtaPcmSide, + PhotonEta, + Omega, + PhotonOmega, + EtaPrime, + PhotonEtaPrime, + PhotonOtherMother +}; + +enum class TruthLevel : int { + Unknown = -1, + Reco = 0, + RecoMcMatched = 1, + RecoAssocEv = 2, + RecoPure = 3, + RecoPureTruePtAssoc = 4, + PseudoReco = 5, + PseudoRecoAssocEv = 6, + PseudoRecoPure = 7, + PseudoRecoPureTruePtAssoc = 8, + TrueGeoAcc = 9, + TrueMeasDecay = 10, + TrueRecoEvRecoPtTrig = 11, + TrueRecoEv = 12, + True = 13, + TrueDecaySelfTrig = 14 +}; +// true level: associated particles taken from mc truth +constexpr bool isTrueLevel(TruthLevel const truthLevel) +{ + switch (truthLevel) { + case TruthLevel::Unknown: + case TruthLevel::Reco: + case TruthLevel::RecoMcMatched: + case TruthLevel::RecoAssocEv: + case TruthLevel::RecoPure: + case TruthLevel::RecoPureTruePtAssoc: + case TruthLevel::PseudoReco: + case TruthLevel::PseudoRecoAssocEv: + case TruthLevel::PseudoRecoPure: + case TruthLevel::PseudoRecoPureTruePtAssoc: + return false; + case TruthLevel::TrueGeoAcc: + case TruthLevel::TrueMeasDecay: + case TruthLevel::TrueRecoEvRecoPtTrig: + case TruthLevel::TrueRecoEv: + case TruthLevel::True: + case TruthLevel::TrueDecaySelfTrig: + return true; + } + return false; +} + +enum class PhotonImpurity : int { + Unknown = -1, + Pure = 0, + WrongEv = 1, + MisId = 2, + K0Short = 3, + K0Long = 4, + Lambda0 = 5, + Other = 6 +}; +constexpr double binValuePhotonImpurity(PhotonImpurity const impurity) +{ + return static_cast(impurity) + 0.5; +} + +template +bool constexpr AlwaysFalseType = false; +template +bool constexpr AlwaysFalseValue = false; + +} // namespace hpc + +namespace o2::aod +{ + +// common correlation columns +namespace hpc_common +{ +DECLARE_SOA_INDEX_COLUMN_FULL(JetMcCollision, jetMcCollision, int, JMcCollisions, ""); +DECLARE_SOA_COLUMN(SelEv, selEv, bool); +DECLARE_SOA_COLUMN(NSelectSplitMcEv, nSelectSplitMcEv, int); +DECLARE_SOA_COLUMN(Pt, pt, float); +DECLARE_SOA_COLUMN(PtTruePure, ptTruePure, float); +DECLARE_SOA_COLUMN(PtTrueOrigin, ptTrueOrigin, float); // and the blind forest +DECLARE_SOA_COLUMN(Phi, phi, float); +DECLARE_SOA_COLUMN(Eta, eta, float); +} // namespace hpc_common + +// reco + +// correlation collision +namespace hpc_collision +{ +// plain jet collision column for derived data +DECLARE_SOA_COLUMN(JetCollisionId, jetCollisionId, int); +DECLARE_SOA_COLUMN(TrigEv, trigEv, bool); +DECLARE_SOA_COLUMN(PtMax, ptMax, float); +DECLARE_SOA_COLUMN(PosZ, posZ, float); +DECLARE_SOA_COLUMN(NGlobalTracks, nGlobalTracks, int); +} // namespace hpc_collision +DECLARE_SOA_TABLE(HpcCollisions, "AOD", "HPCCOL", + o2::soa::Index<>, + hpc_common::SelEv, hpc_common::NSelectSplitMcEv, hpc_collision::TrigEv, hpc_collision::PtMax, hpc_collision::PosZ, hpc_collision::NGlobalTracks); +DECLARE_SOA_TABLE(HpcCollisionIds, "AOD", "HPCCOLID", + hpc_collision::JetCollisionId); +DECLARE_SOA_TABLE(HpcCollisionMcIds, "AOD", "HPCCOLMCID", + hpc_common::JetMcCollisionId); + +// add to common columns +namespace hpc_common +{ +DECLARE_SOA_INDEX_COLUMN_FULL(CorrCollision, corrCollision, int, HpcCollisions, ""); +} // namespace hpc_common + +// trigger +namespace hpc_trigger +{ +DECLARE_SOA_INDEX_COLUMN_FULL(JetTrack, jetTrack, int, JetTracks, ""); +} // namespace hpc_trigger +DECLARE_SOA_TABLE(HpcTriggers, "AOD", "HPCTRIG", + o2::soa::Index<>, hpc_common::CorrCollisionId, + hpc_common::Pt, hpc_common::Phi, hpc_common::Eta); +DECLARE_SOA_TABLE(HpcTriggerTrackIds, "AOD", "HPCTRIGTRID", + hpc_trigger::JetTrackId); + +// add to common columns +namespace hpc_common +{ +DECLARE_SOA_ARRAY_INDEX_COLUMN_FULL(IntersectTrigger, intersectTrigger, int, HpcTriggers, ""); +} // namespace hpc_common + +// hadron (global tracks) +namespace hpc_hadron +{ +DECLARE_SOA_INDEX_COLUMN_FULL(JetTrack, jetTrack, int, JetTracks, ""); +DECLARE_SOA_COLUMN(TruthLevelRecoHadron, truthLevelRecoHadron, int); +} // namespace hpc_hadron +DECLARE_SOA_TABLE(HpcHadrons, "AOD", "HPCHAD", + o2::soa::Index<>, hpc_common::CorrCollisionId, hpc_common::IntersectTriggerIds, + hpc_common::Pt, hpc_common::Phi, hpc_common::Eta, + hpc_hadron::TruthLevelRecoHadron, hpc_common::PtTruePure); +DECLARE_SOA_TABLE(HpcHadronTrackIds, "AOD", "HPCHADTRID", + hpc_hadron::JetTrackId); + +// pipm +namespace hpc_pipm +{ +DECLARE_SOA_INDEX_COLUMN_FULL(JetTrack, jetTrack, int, JetTracks, ""); +DECLARE_SOA_COLUMN(TruthLevelRecoPipm, truthLevelRecoPipm, int); +} // namespace hpc_pipm +DECLARE_SOA_TABLE(HpcPipms, "AOD", "HPCPIPM", + o2::soa::Index<>, hpc_common::CorrCollisionId, hpc_common::IntersectTriggerIds, + hpc_common::Pt, hpc_common::Phi, hpc_common::Eta, + hpc_pipm::TruthLevelRecoPipm, hpc_common::PtTruePure); +DECLARE_SOA_TABLE(HpcPipmTrackIds, "AOD", "HPCPIPMTRID", + hpc_pipm::JetTrackId); + +// photonPcm +namespace hpc_photon_pcm +{ +DECLARE_SOA_INDEX_COLUMN_FULL(V0PhotonKF, v0PhotonKF, int, V0PhotonsKF, ""); +DECLARE_SOA_INDEX_COLUMN_FULL(PosJetTrack, posJetTrack, int, JetTracks, "_pos"); +DECLARE_SOA_INDEX_COLUMN_FULL(NegJetTrack, negJetTrack, int, JetTracks, "_neg"); +DECLARE_SOA_COLUMN(TruthLevelRecoPhotonPcm, truthLevelRecoPhotonPcm, int); +DECLARE_SOA_COLUMN(ImpurityPhotonPcm, impurityPhotonPcm, int); +} // namespace hpc_photon_pcm +DECLARE_SOA_TABLE(HpcPhotonPcms, "AOD", "HPCPHPCM", + o2::soa::Index<>, hpc_common::CorrCollisionId, hpc_common::IntersectTriggerIds, + hpc_common::Pt, hpc_common::Phi, hpc_common::Eta, + hpc_photon_pcm::TruthLevelRecoPhotonPcm, hpc_common::PtTruePure, + hpc_photon_pcm::ImpurityPhotonPcm, hpc_common::PtTrueOrigin); +DECLARE_SOA_TABLE(HpcPhotonPcmTrackIds, "AOD", "HPCPHPCMTRID", + hpc_photon_pcm::PosJetTrackId, hpc_photon_pcm::NegJetTrackId); +DECLARE_SOA_TABLE(HpcPhotonPcmV0PhotonIds, "AOD", "HPCPHPCMV0ID", + hpc_photon_pcm::V0PhotonKFId); + +// photonPcm pairs +namespace hpc_photon_pcm_pair +{ +DECLARE_SOA_INDEX_COLUMN_FULL(V0PhotonKF1, v0PhotonKF1, int, V0PhotonsKF, "_1"); +DECLARE_SOA_INDEX_COLUMN_FULL(V0PhotonKF2, v0PhotonKF2, int, V0PhotonsKF, "_2"); +DECLARE_SOA_INDEX_COLUMN_FULL(PosJetTrack1, posJetTrack1, int, JetTracks, "_pos1"); +DECLARE_SOA_INDEX_COLUMN_FULL(NegJetTrack1, negJetTrack1, int, JetTracks, "_neg1"); +DECLARE_SOA_INDEX_COLUMN_FULL(PosJetTrack2, posJetTrack2, int, JetTracks, "_pos2"); +DECLARE_SOA_INDEX_COLUMN_FULL(NegJetTrack2, negJetTrack2, int, JetTracks, "_neg2"); +DECLARE_SOA_COLUMN(Mgg, mgg, float); +DECLARE_SOA_COLUMN(TruthLevelRecoPi0Pcm, truthLevelRecoPi0Pcm, int); +DECLARE_SOA_COLUMN(TruthLevelRecoEtaPcm, truthLevelRecoEtaPcm, int); +DECLARE_SOA_COLUMN(ImpurityPi0Pcm, impurityPi0Pcm, int); +} // namespace hpc_photon_pcm_pair +DECLARE_SOA_TABLE(HpcPhotonPcmPairs, "AOD", "HPCPCMPAIR", + o2::soa::Index<>, hpc_common::CorrCollisionId, hpc_common::IntersectTriggerIds, + hpc_common::Pt, hpc_common::Phi, hpc_common::Eta, hpc_photon_pcm_pair::Mgg, + hpc_photon_pcm_pair::TruthLevelRecoPi0Pcm, hpc_photon_pcm_pair::TruthLevelRecoEtaPcm, hpc_common::PtTruePure, + hpc_photon_pcm_pair::ImpurityPi0Pcm, hpc_common::PtTrueOrigin); +DECLARE_SOA_TABLE(HpcPhotonPcmPairTrackIds, "AOD", "HPCPCMPAIRTRID", + hpc_photon_pcm_pair::PosJetTrack1Id, hpc_photon_pcm_pair::NegJetTrack1Id, hpc_photon_pcm_pair::PosJetTrack2Id, hpc_photon_pcm_pair::NegJetTrack2Id); +DECLARE_SOA_TABLE(HpcPhotonPcmPairV0PhotonIds, "AOD", "HPCPCMPAIRV0ID", + hpc_photon_pcm_pair::V0PhotonKF1Id, hpc_photon_pcm_pair::V0PhotonKF2Id); + +// photon selection +namespace hpc_photon_pcm +{ +DECLARE_SOA_COLUMN(SelPhotonPcm, selPhotonPcm, bool); +} // namespace hpc_photon_pcm +DECLARE_SOA_TABLE(HpcPhotonPcmSels, "AOD", "HPCPHPCMSEL", + hpc_photon_pcm::SelPhotonPcm); +namespace hpc_photon_pcm_pair +{ +DECLARE_SOA_COLUMN(SelPhotons, selPhotons, bool); +DECLARE_SOA_COLUMN(EnergyAsym, energyAsym, float); +} // namespace hpc_photon_pcm_pair +DECLARE_SOA_TABLE(HpcPhotonPcmPairSels, "AOD", "HPCPCMPAIRSEL", + hpc_photon_pcm_pair::SelPhotons, hpc_photon_pcm_pair::EnergyAsym); + +// mc + +// mcCollision extension +namespace hpc_mc_collision_extra +{ +DECLARE_SOA_COLUMN(TrigEv, trigEv, bool); +DECLARE_SOA_COLUMN(PtMax, ptMax, float); +DECLARE_SOA_COLUMN(NChargedInEtaRange, nChargedInEtaRange, int); +} // namespace hpc_mc_collision_extra +DECLARE_SOA_TABLE(HpcMcCollisionsExtra, "AOD", "HPCMCCOLEXTRA", + hpc_common::SelEv, hpc_common::NSelectSplitMcEv, hpc_mc_collision_extra::TrigEv, hpc_mc_collision_extra::PtMax, hpc_mc_collision_extra::NChargedInEtaRange); + +// trigger +namespace hpc_true_trigger +{ +DECLARE_SOA_INDEX_COLUMN_FULL(JetMcParticle, jetMcParticle, int, JetParticles, ""); +} // namespace hpc_true_trigger +DECLARE_SOA_TABLE(HpcTrueTriggers, "AOD", "HPCTRUETRIG", + o2::soa::Index<>, hpc_common::JetMcCollisionId, hpc_true_trigger::JetMcParticleId, + hpc_common::Pt, hpc_common::Phi, hpc_common::Eta); + +} // namespace o2::aod + +#endif // PWGJE_DATAMODEL_HADRONPHOTONCORRELATION_H_ diff --git a/PWGJE/DataModel/PhotonChargedTriggerCorrelation.h b/PWGJE/DataModel/PhotonChargedTriggerCorrelation.h deleted file mode 100644 index 637a7f18c35..00000000000 --- a/PWGJE/DataModel/PhotonChargedTriggerCorrelation.h +++ /dev/null @@ -1,138 +0,0 @@ -// 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. - -/// -/// \brief table definitions for photon-hadron correlation analyses -/// -/// \author Julius Kinner -/// \file PhotonChargedTriggerCorrelation.h - -#ifndef PWGJE_DATAMODEL_PHOTONCHARGEDTRIGGERCORRELATION_H_ -#define PWGJE_DATAMODEL_PHOTONCHARGEDTRIGGERCORRELATION_H_ - -#include "PWGEM/PhotonMeson/DataModel/gammaTables.h" -#include "PWGJE/DataModel/Jet.h" -#include "PWGJE/DataModel/JetReducedData.h" - -#include - -namespace o2::aod -{ - -// basic correlation particle columns -namespace corr_particle -{ -DECLARE_SOA_INDEX_COLUMN_FULL(JetCollision, jetCollision, int, JCollisions, ""); -DECLARE_SOA_INDEX_COLUMN_FULL(JetMcCollision, jetMcCollision, int, JMcCollisions, ""); -DECLARE_SOA_COLUMN(Pt, pt, float); -DECLARE_SOA_COLUMN(Phi, phi, float); -DECLARE_SOA_COLUMN(Eta, eta, float); -} // namespace corr_particle - -// reco - -// collision extension -namespace collision_extra_corr -{ -DECLARE_SOA_COLUMN(SelEv, selEv, bool); -DECLARE_SOA_COLUMN(ThirdDecimalTruePosZ, thirdDecimalTruePosZ, int); -DECLARE_SOA_COLUMN(TrigEv, trigEv, bool); -DECLARE_SOA_COLUMN(PtMax, ptMax, float); -DECLARE_SOA_COLUMN(NGlobalTracks, nGlobalTracks, int); -} // namespace collision_extra_corr -DECLARE_SOA_TABLE(CollisionsExtraCorr, "AOD", "COLLISIONSEXTRACORR", - collision_extra_corr::SelEv, collision_extra_corr::ThirdDecimalTruePosZ, collision_extra_corr::TrigEv, collision_extra_corr::PtMax, collision_extra_corr::NGlobalTracks); - -// trigger -namespace trigger -{ -DECLARE_SOA_INDEX_COLUMN_FULL(JetTrack, jetTrack, int, JetTracks, ""); -} // namespace trigger -DECLARE_SOA_TABLE(Triggers, "AOD", "TRIGGERS", - o2::soa::Index<>, corr_particle::JetCollisionId, trigger::JetTrackId, - corr_particle::Pt, corr_particle::Phi, corr_particle::Eta); -using Trigger = Triggers::iterator; - -// hadrons (global tracks) -namespace hadron -{ -DECLARE_SOA_INDEX_COLUMN_FULL(JetTrack, jetTrack, int, JetTracks, ""); -} // namespace hadron -DECLARE_SOA_TABLE(Hadrons, "AOD", "HADRONS", - o2::soa::Index<>, corr_particle::JetCollisionId, hadron::JetTrackId, - corr_particle::Pt, corr_particle::Phi, corr_particle::Eta); -using Hadron = Hadrons::iterator; - -// pipm -namespace pipm -{ -DECLARE_SOA_INDEX_COLUMN_FULL(JetTrack, jetTrack, int, JetTracks, ""); -} // namespace pipm -DECLARE_SOA_TABLE(Pipms, "AOD", "PIPMS", - o2::soa::Index<>, corr_particle::JetCollisionId, pipm::JetTrackId, - corr_particle::Pt, corr_particle::Phi, corr_particle::Eta); -using Pipm = Pipms::iterator; - -// photonPCM -namespace photon_pcm -{ -DECLARE_SOA_INDEX_COLUMN_FULL(V0PhotonKF, v0PhotonKF, int, V0PhotonsKF, ""); -DECLARE_SOA_INDEX_COLUMN_FULL(PosJetTrack, posJetTrack, int, JetTracks, "_pos"); -DECLARE_SOA_INDEX_COLUMN_FULL(NegJetTrack, negJetTrack, int, JetTracks, "_neg"); -} // namespace photon_pcm -DECLARE_SOA_TABLE(PhotonPCMs, "AOD", "PHOTONPCMS", - o2::soa::Index<>, corr_particle::JetCollisionId, photon_pcm::V0PhotonKFId, - photon_pcm::PosJetTrackId, photon_pcm::NegJetTrackId, - corr_particle::Pt, corr_particle::Phi, corr_particle::Eta); -using PhotonPCM = PhotonPCMs::iterator; - -// photonPCM pairs (pi0) -namespace photon_pcm_pair -{ -DECLARE_SOA_INDEX_COLUMN_FULL(V0PhotonKF1, v0PhotonKF1, int, V0PhotonsKF, "_1"); -DECLARE_SOA_INDEX_COLUMN_FULL(V0PhotonKF2, v0PhotonKF2, int, V0PhotonsKF, "_2"); -DECLARE_SOA_INDEX_COLUMN_FULL(PosJetTrack1, posJetTrack1, int, JetTracks, "_pos1"); -DECLARE_SOA_INDEX_COLUMN_FULL(NegJetTrack1, negJetTrack1, int, JetTracks, "_neg1"); -DECLARE_SOA_INDEX_COLUMN_FULL(PosJetTrack2, posJetTrack2, int, JetTracks, "_pos2"); -DECLARE_SOA_INDEX_COLUMN_FULL(NegJetTrack2, negJetTrack2, int, JetTracks, "_neg2"); -DECLARE_SOA_COLUMN(Mgg, mgg, float); -} // namespace photon_pcm_pair -DECLARE_SOA_TABLE(PhotonPCMPairs, "AOD", "PHOTONPCMPAIRS", - o2::soa::Index<>, corr_particle::JetCollisionId, photon_pcm_pair::V0PhotonKF1Id, photon_pcm_pair::V0PhotonKF2Id, - photon_pcm_pair::PosJetTrack1Id, photon_pcm_pair::NegJetTrack1Id, photon_pcm_pair::PosJetTrack2Id, photon_pcm_pair::NegJetTrack2Id, - corr_particle::Pt, corr_particle::Phi, corr_particle::Eta, photon_pcm_pair::Mgg); -using PhotonPCMPair = PhotonPCMPairs::iterator; - -// mc - -// mcCollision extension -namespace mc_collision_extra_corr -{ -DECLARE_SOA_COLUMN(ThirdDecimalTruePosZ, thirdDecimalTruePosZ, int); -DECLARE_SOA_COLUMN(TrigEv, trigEv, bool); -DECLARE_SOA_COLUMN(PtMax, ptMax, float); -DECLARE_SOA_COLUMN(NChargedInEtaRange, nChargedInEtaRange, int); -} // namespace mc_collision_extra_corr -DECLARE_SOA_TABLE(McCollisionsExtraCorr, "AOD", "MCCOLLISIONSEXTRACORR", - mc_collision_extra_corr::ThirdDecimalTruePosZ, mc_collision_extra_corr::TrigEv, mc_collision_extra_corr::PtMax, mc_collision_extra_corr::NChargedInEtaRange); - -// trigger -namespace trigger_particle -{ -DECLARE_SOA_INDEX_COLUMN_FULL(JetMcParticle, jetMcParticle, int, JetParticles, ""); -} // namespace trigger_particle -DECLARE_SOA_TABLE(TriggerParticles, "AOD", "TRIGGERPARTICLES", - o2::soa::Index<>, corr_particle::JetMcCollisionId, trigger_particle::JetMcParticleId, - corr_particle::Pt, corr_particle::Phi, corr_particle::Eta); -using TriggerParticle = TriggerParticles::iterator; -} // namespace o2::aod - -#endif // PWGJE_DATAMODEL_PHOTONCHARGEDTRIGGERCORRELATION_H_ diff --git a/PWGJE/Tasks/CMakeLists.txt b/PWGJE/Tasks/CMakeLists.txt index 3a558ae55df..68eabc58ee1 100644 --- a/PWGJE/Tasks/CMakeLists.txt +++ b/PWGJE/Tasks/CMakeLists.txt @@ -96,22 +96,22 @@ o2physics_add_dpl_workflow(photon-isolation-qa SOURCES photonIsolationQA.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::EMCALBase O2::EMCALCalib O2Physics::AnalysisCore COMPONENT_NAME Analysis) -o2physics_add_dpl_workflow(photon-charged-trigger-correlation - SOURCES photonChargedTriggerCorrelation.cxx +o2physics_add_dpl_workflow(hadron-photon-correlation + SOURCES hadronPhotonCorrelation.cxx REUSE_FROM JetDataModelPCH - PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore + PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::PWGEMPhotonMesonCore COMPONENT_NAME Analysis) o2physics_add_dpl_workflow(task-emc-extensive-mc-qa SOURCES taskEmcExtensiveMcQa.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::EMCALBase O2Physics::AnalysisCore O2Physics::EventFilteringUtils COMPONENT_NAME Analysis) -o2physics_add_dpl_workflow(photon-charged-trigger-producer - SOURCES photonChargedTriggerProducer.cxx +o2physics_add_dpl_workflow(hadron-photon-producer + SOURCES hadronPhotonProducer.cxx REUSE_FROM JetDataModelPCH PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore COMPONENT_NAME Analysis) -o2physics_add_dpl_workflow(hadron-photon-correlation - SOURCES hadronPhotonCorrelation.cxx +o2physics_add_dpl_workflow(hadron-photon-correlation-sim + SOURCES hadronPhotonCorrelationSim.cxx REUSE_FROM JetDataModelPCH PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore COMPONENT_NAME Analysis) diff --git a/PWGJE/Tasks/hadronPhotonCorrelation.cxx b/PWGJE/Tasks/hadronPhotonCorrelation.cxx index 18e73087ff7..21ff851d66b 100644 --- a/PWGJE/Tasks/hadronPhotonCorrelation.cxx +++ b/PWGJE/Tasks/hadronPhotonCorrelation.cxx @@ -9,1170 +9,2194 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +/// \file hadronPhotonCorrelation.cxx +/// \author Julius Kinner +/// \brief hadron-photon angular correlation analysis /// -/// \file hadronPhotonCorrelation.cxx -/// \author Peter Stratmann -/// \brief This code loops over JetTracks to extract pt and angular information -/// for hadrons and photons to compute angular correlations -/// +/// Analysis for angular correlations between jets and photons via two-particle correlations with charged high-pt triggers +/// Associated hadrons (tracks), pipm, photons (pcm), pi0 (pcm) +/// Also contains checks and monte-carlo (efficiency, purity, mc-true correlation,...) +/// End goal of studying correlations between direct photons and jets + +#include "PWGJE/DataModel/HadronPhotonCorrelation.h" -#include "PWGEM/PhotonMeson/DataModel/gammaTables.h" -#include "PWGJE/Core/JetDerivedDataUtilities.h" #include "PWGJE/DataModel/Jet.h" #include "PWGJE/DataModel/JetReducedData.h" -#include "PWGLF/DataModel/LFStrangenessTables.h" +// +#include "PWGEM/PhotonMeson/Core/V0PhotonCut.h" +#include "PWGEM/PhotonMeson/DataModel/gammaTables.h" #include "Common/Core/RecoDecay.h" -#include "Common/DataModel/PIDResponseTPC.h" -#include "Common/DataModel/TrackSelectionTables.h" +#include "Common/Core/TableHelper.h" +#include #include -#include +#include +#include #include #include #include +#include #include -#include +#include #include #include #include #include +#include #include +#include // IWYU pragma: keep (do not replace with Math/Vector4Dfwd.h) +#include #include -#include +#include #include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include #include +#include +#include #include +#include +#include #include using namespace o2; -using namespace o2::aod; using namespace o2::framework; -using namespace o2::framework::expressions; -using namespace o2::soa; -using namespace o2::constants::physics; -using namespace o2::constants::math; +using namespace hpc; + +using HpcCollisionsMcD = soa::Join; +using HpcMcCollisions = soa::Join; + +using PhotonPcmsWithV0 = soa::Join; +using PhotonPcmPairsWithV0 = soa::Join; + +using BinningZPvMult = ColumnBinningPolicy; + +// photon cut selection /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// =/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/ + +struct HadronPhotonPcmSelection { + Produces photonPcmSel; + Produces photonPcmPairSel; + + // pcm cuts + struct : o2::framework::ConfigurableGroup { + std::string prefix = "pcmcut_group"; + o2::framework::Configurable cfgRequireV0WithItstpc{"cfgRequireV0WithItstpc", false, "flag to select V0s with ITS-TPC matched tracks"}; + o2::framework::Configurable cfgRequireV0WithItsonly{"cfgRequireV0WithItsonly", false, "flag to select V0s with ITSonly tracks"}; + o2::framework::Configurable cfgRequireV0WithTpconly{"cfgRequireV0WithTpconly", false, "flag to select V0s with TPConly tracks"}; + o2::framework::Configurable cfgMinPtV0{"cfgMinPtV0", 0.1, "min pt for v0 photons at PV"}; + o2::framework::Configurable cfgMaxPtV0{"cfgMaxPtV0", 1e+10, "max pt for v0 photons at PV"}; + o2::framework::Configurable cfgMinEtaV0{"cfgMinEtaV0", -1e+10, "min eta for v0 photons at PV"}; + o2::framework::Configurable cfgMaxEtaV0{"cfgMaxEtaV0", 1e+10, "max eta for v0 photons at PV"}; + o2::framework::Configurable cfgMinV0radius{"cfgMinV0radius", 4.0, "min v0 radius"}; + o2::framework::Configurable cfgMaxV0radius{"cfgMaxV0radius", 90.0, "max v0 radius"}; + o2::framework::Configurable cfgMidLV0radius{"cfgMidLV0radius", -1.0, "middle low v0 radius for rejection if >0"}; + o2::framework::Configurable cfgMidHV0radius{"cfgMidHV0radius", -1.0, "middle high v0 radius for rejection if >0"}; + o2::framework::Configurable cfgMaxAlphaAp{"cfgMaxAlphaAp", 0.95, "max alpha for AP cut"}; + o2::framework::Configurable cfgMaxQtAp{"cfgMaxQtAp", 0.01, "max qT for AP cut"}; + o2::framework::Configurable cfgMinCospa{"cfgMinCospa", 0.999, "min V0 CosPA"}; + o2::framework::Configurable cfgMaxPca{"cfgMaxPca", 1.5, "max distance btween 2 legs"}; + o2::framework::Configurable cfgMaxChi2kf{"cfgMaxChi2kf", 1e+10, "max chi2/ndf with KF"}; + o2::framework::Configurable cfgRejectV0OnItsib{"cfgRejectV0OnItsib", true, "flag to reject V0s on ITSib"}; + + o2::framework::Configurable cfgMinNclusterTpc{"cfgMinNclusterTpc", 0, "min ncluster tpc"}; + o2::framework::Configurable cfgMinNcrossedrows{"cfgMinNcrossedrows", 40, "min ncrossed rows"}; + o2::framework::Configurable cfgMaxFracSharedClustersTpc{"cfgMaxFracSharedClustersTpc", 999.f, "max fraction of shared clusters in TPC"}; + o2::framework::Configurable cfgMaxChi2tpc{"cfgMaxChi2tpc", 4.0, "max chi2/NclsTPC"}; + o2::framework::Configurable cfgMaxChi2its{"cfgMaxChi2its", 36.0, "max chi2/NclsITS"}; + o2::framework::Configurable cfgMinTPCNsigmaEl{"cfgMinTPCNsigmaEl", -3.0, "min. TPC n sigma for electron"}; + o2::framework::Configurable cfgMaxTPCNsigmaEl{"cfgMaxTPCNsigmaEl", +3.0, "max. TPC n sigma for electron"}; + o2::framework::Configurable cfgDisableItsonlyTrack{"cfgDisableItsonlyTrack", false, "flag to disable ITSonly tracks"}; + o2::framework::Configurable cfgDisableTpconlyTrack{"cfgDisableTpconlyTrack", false, "flag to disable TPConly tracks"}; + } configPcmCuts; + + // pcm cut class + V0PhotonCut fV0PhotonCut; + + void initV0PhotonCut() + { + fV0PhotonCut = V0PhotonCut("fV0PhotonCut", "fV0PhotonCut"); + + // for v0 + fV0PhotonCut.SetV0PtRange(configPcmCuts.cfgMinPtV0, configPcmCuts.cfgMaxPtV0); + fV0PhotonCut.SetV0EtaRange(configPcmCuts.cfgMinEtaV0, configPcmCuts.cfgMaxEtaV0); + fV0PhotonCut.SetMinCosPA(configPcmCuts.cfgMinCospa); + fV0PhotonCut.SetMaxPCA(configPcmCuts.cfgMaxPca); + fV0PhotonCut.SetMaxChi2KF(configPcmCuts.cfgMaxChi2kf); + fV0PhotonCut.SetRxyRange(configPcmCuts.cfgMinV0radius, configPcmCuts.cfgMaxV0radius, configPcmCuts.cfgMidLV0radius, configPcmCuts.cfgMidHV0radius); + fV0PhotonCut.SetAPRange(configPcmCuts.cfgMaxAlphaAp, configPcmCuts.cfgMaxQtAp); + fV0PhotonCut.RejectITSib(configPcmCuts.cfgRejectV0OnItsib); + + // for leg + fV0PhotonCut.SetMinNClustersTPC(configPcmCuts.cfgMinNclusterTpc); + fV0PhotonCut.SetMinNCrossedRowsTPC(configPcmCuts.cfgMinNcrossedrows); + fV0PhotonCut.SetMinNCrossedRowsOverFindableClustersTPC(0.8); + fV0PhotonCut.SetMaxFracSharedClustersTPC(configPcmCuts.cfgMaxFracSharedClustersTpc); + fV0PhotonCut.SetChi2PerClusterTPC(0.0, configPcmCuts.cfgMaxChi2tpc); + fV0PhotonCut.SetTPCNsigmaElRange(configPcmCuts.cfgMinTPCNsigmaEl, configPcmCuts.cfgMaxTPCNsigmaEl); + fV0PhotonCut.SetChi2PerClusterITS(-1e+10, configPcmCuts.cfgMaxChi2its); + fV0PhotonCut.SetNClustersITS(0, 7); + fV0PhotonCut.SetMeanClusterSizeITSob(0.0, 16.0); + fV0PhotonCut.SetDisableITSonly(configPcmCuts.cfgDisableItsonlyTrack); + fV0PhotonCut.SetDisableTPConly(configPcmCuts.cfgDisableTpconlyTrack); + fV0PhotonCut.SetRequireITSTPC(configPcmCuts.cfgRequireV0WithItstpc); + fV0PhotonCut.SetRequireITSonly(configPcmCuts.cfgRequireV0WithItsonly); + fV0PhotonCut.SetRequireTPConly(configPcmCuts.cfgRequireV0WithTpconly); + } -struct HadronPhotonCorrelation { + // add pmeventId() due to unguarded call in V0PhotonCut.h qa; selection unaffected + template + struct V0PhotonNoEvent : T_V0PhotonType { + explicit V0PhotonNoEvent(T_V0PhotonType const& v0PhotonType) : T_V0PhotonType(v0PhotonType) {} + [[nodiscard]] int pmeventId() const { return -1; } + }; + bool isSelectedV0Photon(auto const& v0Photon) + { + using V0PhotonType = std::decay_t; + return fV0PhotonCut.template IsSelected, aod::V0Legs>(V0PhotonNoEvent{v0Photon}); + } - Configurable eventSelections{"eventSelections", "sel8", "choose event selection"}; - Configurable trackSelections{"trackSelections", "globalTracks", "set track selections"}; - Configurable subGeneratorIdSelections{"subGeneratorIdSelections", -1, "set sub generator id"}; - Configurable hardQCDgg2gg{"hardQCDgg2gg", true, "include gg2gg process in hardQCD"}; - - Configurable tpcNClsCrossedRows{"tpcNClsCrossedRows", 70, "tpcNClsCrossedRows"}; - Configurable tpcCrossedRowsOverFindableCls{"tpcCrossedRowsOverFindableCls", 0.8, "tpcCrossedRowsOverFindableCls"}; - Configurable tpcNSigmaPi{"tpcNSigmaPi", 2., "tpcNSigmaPi"}; - - Configurable pTHatMin{"pTHatMin", 5, "minimum pTHat cut"}; - Configurable pTHatMax{"pTHatMax", 600, "minimum pTHat cut"}; - - const int pidCodeHadronCut = 100; - const int pythiaCodeIncomingHard = 21; - const int pythiaCodeOutgoingHard = 23; - const int pythiaCodeOutgoingDiff = 15; - - Configurable etaMaxTrig{"etaMaxTrig", 0.8, "maximum eta cut for triggers"}; - Configurable etaMaxAssoc{"etaMaxAssoc", 0.8, "maximum eta cut for associateds"}; - Configurable etaBinsTrig{"etaBinsTrig", 40, "number of eta bins for triggers"}; - Configurable etaBinsAssoc{"etaBinsAssoc", 40, "number of eta bins for associateds"}; - Configurable phiBins{"phiBins", 72, "number of phi bins"}; - - // remove this comment - AxisSpec axisEventStats = {6, -.5, 5.5, "Stats"}; - ConfigurableAxis axisPtHat = {"axisPtHat", - {VARIABLE_WIDTH, 0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, - 1., 2., 3., 4., 5., 6., 7., 8., 9., - 10., 20., 30., 40., 50., 60., 70., 80., 90., - 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}, - "p_{T}^{#hat}"}; - ConfigurableAxis axisPtTrig = {"axisPtTrig", - {VARIABLE_WIDTH, - 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 9.0f, 11.0f, 15.0f, 20.0f}, - "p_{T, trig} [GeV]"}; // Axis for trigger particle pt distribution - ConfigurableAxis axisPtAssoc = {"axisPtAssoc", - {VARIABLE_WIDTH, - 0.2, 0.5, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 9.0f, 11.0f, 15.0f}, - "p_{T, assoc} [GeV]"}; // Axis for associated particle pt distribution - ConfigurableAxis axisDeltaPt = {"axisDeltaPt", {200, 0., 1.2}, "#Delta p_T"}; // Axis for pt ratio between neutral hadrons and decay photons - int nHadrons = 6; - AxisSpec axisPid = {10, -3.5, nHadrons + 0.5, "pid"}; // Axis for PID of neutral hadrons - ConfigurableAxis axisMult = {"axisMult", {100, 0., 99.}, "N_{ch}"}; // Axis for mutplipicity - AxisSpec axisAlpha = {100, 0., 1., "alpha"}; // Axis for decay photon pt assymetry - ConfigurableAxis axisDeltaRDecay = {"axisDeltaRDecay", {400, 0., 3.2}, "#Delta R"}; // Axis for Delta R = sqrt(Delta eta^2 + Delta phi^2) between neutral hadrons and decay photons - - float ptMinTrig; - float ptMaxTrig; - float ptMinAssoc; - float ptMaxAssoc; - - // TPythia8Decayer* decayer = new TPythia8Decayer; - // TLorentzVector* motherLV = new TLorentzVector(); // o2-linter: disable= root/lorentz-vector (TLorentzVector is needed for TPythia8Decayer) - // TClonesArray* decayParticles = new TClonesArray("TParticle", 10); - - HistogramRegistry registry{"histogram registry"}; - - // Particle ids for storing neutral hadrons - std::map pidCodes = { - {"pi0", 1}, // pi0 - {"eta", 2}, // eta - {"eta'", 3}, // eta' - {"phi", 4}, // phi - {"omega", 5}, // omega - {"Sigma0", 6}, // Sigma - {"Sigma0_bar", 6}}; - - std::map pidToPdg = { - {1, 111}, // pi0 - {2, 221}, // eta - {3, 331}, // eta' - {4, 333}, // phi - {5, 223}, // omega - {6, 3212}}; // Sigma - - Service pdg; - - std::vector eventSelectionBits; - int trackSelection = -1; - - void init(o2::framework::InitContext&) - { - ptMinTrig = axisPtTrig->at(1); - ptMaxTrig = axisPtTrig->back(); - ptMinAssoc = axisPtAssoc->at(1); - ptMaxAssoc = axisPtAssoc->back(); - - AxisSpec axisPhi = {phiBins, 0., TwoPI, "#phi"}; // Axis for phi distribution - AxisSpec axisDeltaPhi = {phiBins, -PIHalf, 3 * PIHalf, "#Delta #phi"}; // Axis for Delta phi in correlations - AxisSpec axisEtaTrig = {etaBinsTrig, -etaMaxTrig, etaMaxTrig, "#eta"}; // Axis for eta distribution - AxisSpec axisEtaAssoc = {etaBinsAssoc, -etaMaxAssoc, etaMaxAssoc, "#eta"}; // Axis for eta distribution - AxisSpec axisDeltaEta = {etaBinsTrig + etaBinsAssoc, -(etaMaxTrig + etaMaxAssoc), etaMaxTrig + etaMaxAssoc, "#Delta #eta"}; // Axis for Delta eta in correlations - - eventSelectionBits = jetderiveddatautilities::initialiseEventSelectionBits(eventSelections); - trackSelection = jetderiveddatautilities::initialiseTrackSelection(trackSelections); - - // Generated histograms - registry.add("generated/events/hEventStats", "Event statistics", kTH1F, {axisEventStats}); - registry.get(HIST("generated/events/hEventStats"))->Sumw2(); - registry.add("generated/events/hPtHat", "pT of hard collision", kTH1F, {axisPtHat}); - registry.get(HIST("generated/events/hPtHat"))->Sumw2(); - - // Triggers - registry.add("generated/triggers/hTrigMultGen", "Generated Trigger Multiplicity", kTH1F, {axisMult}); - registry.get(HIST("generated/triggers/hTrigMultGen"))->Sumw2(); - registry.add("generated/triggers/hTrigSpectrumGen", "Generated Trigger Spectrum", kTHnSparseF, {axisPtTrig, axisEtaTrig, axisPhi}); - registry.get(HIST("generated/triggers/hTrigSpectrumGen"))->Sumw2(); - - // Hadrons - registry.add("generated/hadrons/hHadronCorrelGen", "Generated Trigger-Hadron Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisDeltaEta, axisDeltaPhi}); - registry.get(HIST("generated/hadrons/hHadronCorrelGen"))->Sumw2(); - registry.add("generated/hadrons/hHadronMultGen", "Generated Hadron Multiplicity", kTH1F, {axisMult}); - registry.get(HIST("generated/hadrons/hHadronMultGen"))->Sumw2(); - registry.add("generated/hadrons/hHadronSpectrumGen", "Generated Hadron Spectrum", kTHnSparseF, {axisPtAssoc, axisEtaAssoc, axisPhi}); - registry.get(HIST("generated/hadrons/hHadronSpectrumGen"))->Sumw2(); - - // Photons - registry.add("generated/photons/hPhotonCorrelGen", "Generated Trigger-Photon Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisDeltaEta, axisDeltaPhi, axisPid}); - registry.get(HIST("generated/photons/hPhotonCorrelGen"))->Sumw2(); - registry.add("generated/photons/hPhotonMultGen", "Generated Photon Multiplicity", kTH1F, {axisMult}); - registry.get(HIST("generated/photons/hPhotonMultGen"))->Sumw2(); - registry.add("generated/photons/hPhotonSpectrumGen", "Generated Photon Spectrum", kTHnSparseF, {axisPtAssoc, axisEtaAssoc, axisPhi, axisPid}); - registry.get(HIST("generated/photons/hPhotonSpectrumGen"))->Sumw2(); - - // Charged pions - registry.add("generated/charged/hPionCorrelGen", "Generated Trigger-Pion Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisDeltaEta, axisDeltaPhi}); - registry.get(HIST("generated/charged/hPionCorrelGen"))->Sumw2(); - registry.add("generated/charged/hPionMultGen", "Generated Pion Multiplicity", kTH1F, {axisMult}); - registry.get(HIST("generated/charged/hPionMultGen"))->Sumw2(); - registry.add("generated/charged/hPionSpectrumGen", "Generated Pion Spectrum", kTHnSparseF, {axisPtAssoc, axisEtaAssoc, axisPhi}); - registry.get(HIST("generated/charged/hPionSpectrumGen"))->Sumw2(); - registry.add("generated/charged/hCocktailPhotonCorrelGen", "Cocktail Photon from Pion-Hadron Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisPtAssoc, axisDeltaEta, axisDeltaPhi, axisPid}); - registry.get(HIST("generated/charged/hCocktailPhotonCorrelGen"))->Sumw2(); - registry.add("generated/charged/hCocktailPhotonSpectrumGen", "Cocktail Photon from Pion Spectrum", kTHnSparseF, {axisPtAssoc, axisPtAssoc, axisEtaAssoc, axisPhi, axisPid}); - registry.get(HIST("generated/charged/hCocktailPhotonSpectrumGen"))->Sumw2(); - - ////Neutral particles - registry.add("generated/neutral/hNeutralCorrelGen", "Generated Trigger-Neutral Hadron Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisDeltaEta, axisDeltaPhi, axisPid}); - registry.get(HIST("generated/neutral/hNeutralCorrelGen"))->Sumw2(); - registry.add("generated/neutral/hNeutralMultGen", "Generated Neutral Hadron Multiplicity", kTH1F, {axisMult}); - registry.get(HIST("generated/neutral/hNeutralMultGen"))->Sumw2(); - registry.add("generated/neutral/hNeutralSpectrumGen", "Generated Neutral Hadron Spectrum", kTHnSparseF, {axisPtAssoc, axisEtaAssoc, axisPhi, axisPid}); - registry.get(HIST("generated/neutral/hNeutralSpectrumGen"))->Sumw2(); - registry.add("generated/neutral/hNeutralDecayGen", "Generated Neutral Hadron-Decay Photon Correlation", kTHnSparseF, {axisPtAssoc, axisDeltaPt, axisDeltaRDecay, axisAlpha, axisPid}); // Correlation with decay photons - registry.get(HIST("generated/neutral/hNeutralDecayGen"))->Sumw2(); - registry.add("generated/neutral/hCocktailPhotonCorrelGen", "Cocktail Photon from Hadron-Hadron Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisPtAssoc, axisDeltaEta, axisDeltaPhi, axisPid}); - registry.get(HIST("generated/neutral/hCocktailPhotonCorrelGen"))->Sumw2(); - registry.add("generated/neutral/hCocktailPhotonSpectrumGen", "Cocktail Photon from Hadron Spectrum", kTHnSparseF, {axisPtAssoc, axisPtAssoc, axisEtaAssoc, axisPhi, axisPid}); - registry.get(HIST("generated/neutral/hCocktailPhotonSpectrumGen"))->Sumw2(); - - // Reconstructed histograms - registry.add("reconstructed/events/hEventStats", "Event statistics", kTH1F, {axisEventStats}); - registry.get(HIST("reconstructed/events/hEventStats"))->Sumw2(); - - // Triggers - registry.add("reconstructed/triggers/hTrigMultReco", "Reconstructed Trigger Multiplicity", kTH1F, {axisMult}); - registry.get(HIST("reconstructed/triggers/hTrigMultReco"))->Sumw2(); - registry.add("reconstructed/triggers/hTrigSpectrumReco", "Reconstructed Trigger Spectrum", kTHnSparseF, {axisPtTrig, axisEtaTrig, axisPhi}); - registry.get(HIST("reconstructed/triggers/hTrigSpectrumReco"))->Sumw2(); - - // Hadrons - registry.add("reconstructed/hadrons/hHadronCorrelReco", "Reconstructed Trigger-Hadron Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisDeltaEta, axisDeltaPhi}); - registry.get(HIST("reconstructed/hadrons/hHadronCorrelReco"))->Sumw2(); - registry.add("reconstructed/hadrons/hHadronMultReco", "Reconstructed Hadron Multiplicity", kTH1F, {axisMult}); - registry.get(HIST("reconstructed/hadrons/hHadronMultReco"))->Sumw2(); - registry.add("reconstructed/hadrons/hHadronSpectrumReco", "Reconstructed Hadron Spectrum", kTHnSparseF, {axisPtAssoc, axisEtaAssoc, axisPhi}); - registry.get(HIST("reconstructed/hadrons/hHadronSpectrumReco"))->Sumw2(); - registry.add("reconstructed/hadrons/hHadronPtPrimReco", "Reconstructed Primaries Spectrum", kTH1F, {axisPtAssoc}); // Primary hadron spectrum - registry.get(HIST("reconstructed/hadrons/hHadronPtPrimReco"))->Sumw2(); - registry.add("reconstructed/hadrons/hHadronPtSecReco", "Reconstructed Secondaries Spectrum", kTH1F, {axisPtAssoc}); // Secondary hadron spectrum - registry.get(HIST("reconstructed/hadrons/hHadronPtSecReco"))->Sumw2(); - - // Photons - registry.add("reconstructed/photons/hPhotonCorrelReco", "Reconstructed Trigger-Photon Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisDeltaEta, axisDeltaPhi}); - registry.get(HIST("reconstructed/photons/hPhotonCorrelReco"))->Sumw2(); - registry.add("reconstructed/photons/hPhotonMultReco", "Reconstructed Photon Multiplicity", kTH1F, {axisMult}); - registry.get(HIST("reconstructed/photons/hPhotonMultReco"))->Sumw2(); - registry.add("reconstructed/photons/hPhotonSpectrumReco", "Reconstructed Photon Spectrum", kTHnSparseF, {axisPtAssoc, axisEtaAssoc, axisPhi}); - registry.get(HIST("reconstructed/photons/hPhotonSpectrumReco"))->Sumw2(); - - // Charged Pions - registry.add("reconstructed/charged/hPionCorrelReco", "Reconstructed Trigger-Pion Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisDeltaEta, axisDeltaPhi}); - registry.get(HIST("reconstructed/charged/hPionCorrelReco"))->Sumw2(); - registry.add("reconstructed/charged/hPionMultReco", "Reconstructed Pion Multiplicity", kTH1F, {axisMult}); - registry.get(HIST("reconstructed/charged/hPionMultReco"))->Sumw2(); - registry.add("reconstructed/charged/hPionSpectrumReco", "Reconstructed Pion Spectrum", kTHnSparseF, {axisPtAssoc, axisEtaAssoc, axisPhi}); - registry.get(HIST("reconstructed/charged/hPionSpectrumReco"))->Sumw2(); - } - - // Get pTHat of the event - template - double getCollisionPtHat(const P& particles) - { - double pTHat = 0; - bool isDiffractive = false; - - for (const auto& particle : particles) { - - if (std::abs(particle.getGenStatusCode()) == pythiaCodeOutgoingHard && !isDiffractive) { - if (particle.pt() > pTHat) { - pTHat = particle.pt(); - } - } - if (std::abs(particle.getGenStatusCode()) == pythiaCodeOutgoingDiff) { - if (isDiffractive) { - if (particle.pt() > pTHat) { - pTHat = particle.pt(); - } - } else { - pTHat = particle.pt(); - isDiffractive = true; - } - } - } + // energy asymmetry for photon pair + static double getEnergyAsymDiPhoton(auto const& v0Photon1, auto const& v0Photon2) + { + double const e1 = v0Photon1.pt() * std::cosh(v0Photon1.eta()); + double const e2 = v0Photon2.pt() * std::cosh(v0Photon2.eta()); + double const energyAsym = std::abs((e1 - e2) / (e1 + e2)); + return energyAsym; + } - return pTHat; + void init(InitContext&) + { + initV0PhotonCut(); } - template - bool rejectOutliers(const P& particles, double pTHat) + void processSelection(aod::HpcPhotonPcmV0PhotonIds const& photonPcms, aod::HpcPhotonPcmPairV0PhotonIds const& photonPcmPairs, + aod::V0PhotonsKF const&, aod::V0Legs const&) { - if (subGeneratorIdSelections == 0) { - return false; + // joinable tables + for (auto const& photonPcm : photonPcms) { + photonPcmSel(isSelectedV0Photon(photonPcm.v0PhotonKF())); } - - for (const auto& particle : particles) { - if (particle.getGenStatusCode() > 0 && particle.pt() > pTHat) { - return true; - } + for (auto const& pair : photonPcmPairs) { + auto const v0Photon1 = pair.v0PhotonKF1(); + auto const v0Photon2 = pair.v0PhotonKF2(); + photonPcmPairSel(isSelectedV0Photon(v0Photon1) && isSelectedV0Photon(v0Photon2), getEnergyAsymDiPhoton(v0Photon1, v0Photon2)); } + } + PROCESS_SWITCH(HadronPhotonPcmSelection, processSelection, "process photonPcm selection", false); +}; - return false; +// correlation analysis /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// =/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/ + +const double absEtaMaxDefault = 0.8; + +struct HadronPhotonCorrelation { + // configurables + + // main config + struct : o2::framework::ConfigurableGroup { + // general (kenobi) + Configurable pathCcdbAnalysis{"pathCcdbAnalysis", "Users/j/jkinner/analysis/set_in_config", "base path to the ccdb for analysis objects"}; + Configurable urlCcdb{"urlCcdb", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; + Configurable noLaterThanCcdbConfig{"noLaterThanCcdbConfig", -1, "latest acceptable timestamp of creation for the object (-1 for task start time)"}; + + // central cuts + Configurable absEtaMax{"absEtaMax", 0.8, "maximum absEta cut"}; + Configurable ptTrigMin{"ptTrigMin", 5, "minimum pt of triggers"}; + + // analysis settings + Configurable nSelectSplitMcEv{"nSelectSplitMcEv", 1, "selected event fraction number in MC (starts at 1) | (select 1 for data)"}; + + // mc scaling to data + // caution: applied to true-level very broadly, full mc-true possibly inconsistent (e.g. gammaDir scaled as well), only use for correcting + Configurable applyScalingPhotonPt{"applyScalingPhotonPt", false, "apply photon mc scaling factor"}; + Configurable> ptRangeScalingPhoton{"ptRangeScalingPhoton", {0.5, 15}, "pt for photon mc scaling factor using tcm, switching to constant outside"}; + Configurable> parScalingPhotonPtData{"parScalingPhotonPtData", {}, "tcm params, corrected data, photonPcm"}; + Configurable> parScalingPhotonPtMc{"parScalingPhotonPtMc", {}, "tcm params, mc gen, photonPcm"}; + Configurable applyScalingPi0Pt{"applyScalingPi0Pt", false, "apply pi0 mc scaling factor"}; + Configurable> ptRangeScalingPi0{"ptRangeScalingPi0", {0.5, 10}, "pt for pi0 mc scaling factor using tcm, switching to constant outside"}; + Configurable> parScalingPi0PtData{"parScalingPi0PtData", {}, "tcm params, corrected data, pi0Pcm"}; + Configurable> parScalingPi0PtMc{"parScalingPi0PtMc", {}, "tcm params, mc gen, pi0Pcm"}; + Configurable applyScalingEtaPt{"applyScalingEtaPt", false, "apply eta mc scaling factor"}; + Configurable> ptRangeScalingEta{"ptRangeScalingEta", {1.0, 10}, "pt for eta mc scaling factor using tcm, switching to constant outside"}; + Configurable> parScalingEtaPtData{"parScalingEtaPtData", {}, "tcm params, corrected data, etaPcm"}; + Configurable> parScalingEtaPtMc{"parScalingEtaPtMc", {}, "tcm params, mc gen, etaPcm"}; + // scalings and corrections applied to reco + Configurable applyScalingK0ShortPt{"applyScalingK0ShortPt", false, "apply K0Short mc scaling factor"}; + Configurable applyTriggerPtCorrection{"applyTriggerPtCorrection", false, "whether to apply on-the-fly total correction factor for triggers"}; + + Configurable doTrigEvMixing{"doTrigEvMixing", false, "whether to use trigger events for trigger mixing"}; + + Configurable nTriggerSavedForMixing{"nTriggerSavedForMixing", 8192, "number of triggers that are saved for mixing with other events"}; + Configurable nTriggerBinMinThreshold{"nTriggerBinMinThreshold", 4, "threshold minimum number of triggers in mixing bin required"}; + Configurable iTriggerStartFraction{"iTriggerStartFraction", 0.5, "ratio of bin size for randomised iTrigger start"}; + Configurable nTriggerScaleCoefficient{"nTriggerScaleCoefficient", 1, "coeffcient a in mixing-number pt power scaling"}; + Configurable nTriggerScaleExponent{"nTriggerScaleExponent", 2, "exponent a in mixing-number pt power scaling"}; + Configurable nMixingAt0McTrue{"nMixingAt0McTrue", 1, "number of triggers that are used for mc true mixing"}; + Configurable nMixingAt0Hadron{"nMixingAt0Hadron", 16, "number of triggers that are used for hadron mixing"}; + Configurable nMixingAt0Pipm{"nMixingAt0Pipm", 16, "number of triggers that are used for pipm mixing"}; + Configurable nMixingAt0PhotonPcm{"nMixingAt0PhotonPcm", 256, "number of triggers that are saved for photonPcm mixing"}; + Configurable nMixingAt0PhotonPcmPair{"nMixingAt0PhotonPcmPair", 1024, "number of triggers that are saved for photonPcmPair (pi0, eta) mixing"}; + + Configurable nNeighboursMixingPhotonPcmPair{"nNeighboursMixingPhotonPcmPair", 32, "number neighbours used for for photonPcm pair mixing"}; + + Configurable> pi0PcmPeakMassRange{"pi0PcmPeakMassRange", {0.10, 0.15}, "photon-pair mass integration range for pi0Pcm"}; + Configurable> pi0PcmSideMassRange{"pi0PcmSideMassRange", {0.16, 0.22}, "photon-pair mass integration range outside pi0Pcm region"}; + Configurable> etaPcmPeakMassRange{"etaPcmPeakMassRange", {0.51, 0.56}, "photon-pair mass integration range for etaPcm"}; + Configurable> etaPcmLowSideMassRange{"etaPcmLowSideMassRange", {0.44, 0.48}, "photon-pair mass integration range below etaPcm region"}; + Configurable> etaPcmHighSideMassRange{"etaPcmHighSideMassRange", {0.58, 0.62}, "photon-pair mass integration range above etaPcm region"}; + + Configurable energyAsymmPhotonPairMax{"energyAsymmPhotonPairMax", 1.0, "maximum energy asymmetry ((E1 - E2) / (E1 + E2)) of photon pairs"}; + } config; + + // histogram config + struct : ConfigurableGroup { + Configurable nBinsZPvPlain{"nBinsZPvPlain", 28, "number zPv bins in histos"}; + Configurable nBinsMultPlain{"nBinsMultPlain", 64, "number multiplicity bins in histos"}; + + Configurable nBinsPhi{"nBinsPhi", 72, "number phi bins"}; + Configurable nBinsEta{"nBinsEta", 32, "number eta bins"}; + Configurable nBinsDcaZ{"nBinsDcaZ", 100, "number dcaZ bins"}; + Configurable nBinsMgg{"nBinsMgg", 240, "number mass-photon-pair bins"}; + + Configurable> binsPtTrig{"binsPtTrig", {5, 10, 25, 100}, "correlation ptTrig bins"}; + Configurable> binsPtAssoc{"binsPtAssoc", + {0.2, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 7.0, 8.0, 9.0, 10, + 12.5, 15, 17.5, 20, 25, 35, 50, 100}, + "correlation ptAssoc bins"}; + Configurable> binsDPhi{"binsDPhi", + {(0.00 - 1. / 4) * constants::math::TwoPI, + (0.05 - 1. / 4) * constants::math::TwoPI, (0.10 - 1. / 4) * constants::math::TwoPI, + (0.14 - 1. / 4) * constants::math::TwoPI, (0.17 - 1. / 4) * constants::math::TwoPI, + (0.20 - 1. / 4) * constants::math::TwoPI, + (0.22 - 1. / 4) * constants::math::TwoPI, (0.24 - 1. / 4) * constants::math::TwoPI, + (0.26 - 1. / 4) * constants::math::TwoPI, (0.28 - 1. / 4) * constants::math::TwoPI, + (0.30 - 1. / 4) * constants::math::TwoPI, + (0.33 - 1. / 4) * constants::math::TwoPI, (0.36 - 1. / 4) * constants::math::TwoPI, + (0.40 - 1. / 4) * constants::math::TwoPI, (0.45 - 1. / 4) * constants::math::TwoPI, + (0.50 - 1. / 4) * constants::math::TwoPI, + (0.55 - 1. / 4) * constants::math::TwoPI, (0.60 - 1. / 4) * constants::math::TwoPI, + (0.64 - 1. / 4) * constants::math::TwoPI, (0.68 - 1. / 4) * constants::math::TwoPI, + (0.71 - 1. / 4) * constants::math::TwoPI, + (0.74 - 1. / 4) * constants::math::TwoPI, (0.76 - 1. / 4) * constants::math::TwoPI, + (0.79 - 1. / 4) * constants::math::TwoPI, + (0.82 - 1. / 4) * constants::math::TwoPI, (0.86 - 1. / 4) * constants::math::TwoPI, + (0.90 - 1. / 4) * constants::math::TwoPI, (0.95 - 1. / 4) * constants::math::TwoPI, + (1.00 - 1. / 4) * constants::math::TwoPI}, + "correlation bins DeltaPhi"}; + Configurable> binsDEta{"binsDEta", + {(0 / 32. * 4 - 2) * absEtaMaxDefault, + (2 / 32. * 4 - 2) * absEtaMaxDefault, (4 / 32. * 4 - 2) * absEtaMaxDefault, + (6 / 32. * 4 - 2) * absEtaMaxDefault, (8 / 32. * 4 - 2) * absEtaMaxDefault, + (9.5 / 32. * 4 - 2) * absEtaMaxDefault, (11 / 32. * 4 - 2) * absEtaMaxDefault, + (12.5 / 32. * 4 - 2) * absEtaMaxDefault, (14 / 32. * 4 - 2) * absEtaMaxDefault, + (15.5 / 32. * 4 - 2) * absEtaMaxDefault, (16.5 / 32. * 4 - 2) * absEtaMaxDefault, + (18 / 32. * 4 - 2) * absEtaMaxDefault, + (19.5 / 32. * 4 - 2) * absEtaMaxDefault, (21 / 32. * 4 - 2) * absEtaMaxDefault, + (22.5 / 32. * 4 - 2) * absEtaMaxDefault, (24 / 32. * 4 - 2) * absEtaMaxDefault, + (26 / 32. * 4 - 2) * absEtaMaxDefault, (28 / 32. * 4 - 2) * absEtaMaxDefault, + (30 / 32. * 4 - 2) * absEtaMaxDefault, (32 / 32. * 4 - 2) * absEtaMaxDefault}, + "correlation bins DeltaEta"}; + Configurable> binsZPvBinning{"binsZPvBinning", + {-7, -5, -3, -1, 1, 3, 5, 7}, + "zPv mixing bins"}; + Configurable> binsMultBinning{"binsMultBinning", + {-0.5, 10.5, 15.5, 20.5, 27.5, 66.5}, + "multiplicity mixing bins"}; + Configurable> binsZPvBinningMcTrue{"binsZPvBinningMcTrue", + {-10000, 10000}, + "zPv mixing bins for mc true"}; + Configurable> binsMultBinningMcTrue{"binsMultBinningMcTrue", + {-0.5, 16.5, 24.5, 31.5, 39.5, 99.5}, + "multiplicity mixing bins for mc true"}; + } configHist; + + // further variables ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + + enum class HistFillMode { + PlainPt, + PlainPhiEta, + PlainZPvMult, + Plain, + Correlation, + Mixing + }; + + struct HistFillInfoPlainPhiEtaZPvMult { + double ptMax = -1, ptAssoc = -1, phi = 0, eta = 0, zPv = 0, mult = -1; + double weight = 1; + }; + struct HistFillInfoCorr { + double dPhi = 0, dEta = 0, ptTrig = -1, ptAssoc = -1, zPv = 0, mult = -1; + double weight = 1; + }; + + std::mt19937 randomMt{3141u}; + int randomIntInInterval(int const lowEdgeInclusive, int const upEdgeInclusive) + { + return lowEdgeInclusive + (randomMt() % (upEdgeInclusive - lowEdgeInclusive + 1)); // speeds up task by factor > 2; modulo bias should not be relevant here + // return std::uniform_int_distribution(lowEdgeInclusive, upEdgeInclusive)(randomMt); } - // If event is a HardQCD gg->gg event (which is not implemented in POWHEG directphoton) - template - bool isHardQCDgg2gg(const P& particles) + // O2 varables ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + + // filters + expressions::Filter filterEvTotal = aod::hpc_common::selEv == true && aod::hpc_common::nSelectSplitMcEv == config.nSelectSplitMcEv; + expressions::Filter filterPhotonPcm = aod::hpc_photon_pcm::selPhotonPcm == true; + expressions::Filter filterPhotonPcmPair = aod::hpc_photon_pcm_pair::selPhotons == true && + aod::hpc_photon_pcm_pair::energyAsym < expressions::as(config.energyAsymmPhotonPairMax); + + // partitions + SliceCache cache; + + // prepare for per collision slicing + Preslice perColTriggers = aod::hpc_common::corrCollisionId; + Preslice perColHadrons = aod::hpc_common::corrCollisionId; + Preslice perColPipms = aod::hpc_common::corrCollisionId; + Preslice perColPhotonPcms = aod::hpc_common::corrCollisionId; + Preslice perColPhotonPcmPairs = aod::hpc_common::corrCollisionId; + Preslice perColMcParticles = aod::jmcparticle::mcCollisionId; + Preslice perColTrueTriggers = aod::hpc_common::jetMcCollisionId; + + // ccdb calls + Service ccdb{}; + // for mc info + Service pdg{}; + + // objects to hold histograms + HistogramRegistry histos{"histogramRegistry", {}, OutputObjHandlingPolicy::AnalysisObject, false, false}; + + // declare analysis variables --------------------------------------------------------------------------------------------------------------------------------------------------------------- + + // correction histograms + TH1D* h1PtCorrectionTrigger = nullptr; + TH1D* h1PtScalingK0Short = nullptr; + + // mixing trigger memory + struct MixingTrigger { + MixingTrigger(float pt, float phi, float eta) + : fPt(pt), fPhi(phi), fEta(eta) {} + float fPt, fPhi, fEta; + [[nodiscard]] float pt() const { return fPt; } + [[nodiscard]] float phi() const { return fPhi; } + [[nodiscard]] float eta() const { return fEta; } + }; + // class to handle trigger info from previous collisions (beyond single dataframe) + // organised as zPv- and mult-bin matrix of deque (pt, phi, eta) to save triggers in buffer + // last mult bin open to account for overflow and adjusted zVtx limits to account for rounding errors -> all events accounted for + // (possibly replace by some advanced derived data method and O2 event mixing in future?) + class MixingTriggerMemory { - for (const auto& particle : particles) { - if (std::abs(particle.getGenStatusCode()) == pythiaCodeIncomingHard && std::abs(particle.pdgCode()) != kGluon) { - return false; + public: + // finds bin that value belongs to (assumes ordered bin edges) (starts at 0; includes underflow (return -1) and overflow (return binEdges.size() - 1)) + // should be faster than some std binary search due to small number of bins (zPv, mult) + static int findIntervalBin(double value, const std::vector& binEdges) + { + if (binEdges.empty()) { + throw std::invalid_argument("binEdges in findIntervalBin"); } - if (std::abs(particle.getGenStatusCode()) == pythiaCodeOutgoingHard && std::abs(particle.pdgCode()) != kGluon) { - return false; + const int n = binEdges.size() - 1; + if (value < binEdges[0]) { + return -1; // underflow + } + for (int i_bin = 0; i_bin < n; i_bin++) { + if (value < binEdges[i_bin + 1]) { + return i_bin; + } + } + return n; // overflow + } + + MixingTriggerMemory(std::vector const& binEdgesZPvIn, std::vector const& binEdgesMultIn, size_t const nTriggerPerBinLimitIn) + : binEdgesZPv(binEdgesZPvIn), + nBinsZPv(binEdgesZPvIn.size() - 1), + binEdgesMult(binEdgesMultIn), + nBinsMult(binEdgesMultIn.size() - 1), + nTriggerPerBinLimit(nTriggerPerBinLimitIn) + { + int const nEdgesMin = 2; + if (binEdgesZPv.size() < nEdgesMin || binEdgesMult.size() < nEdgesMin) { + throw std::invalid_argument("too few bin edges to define zPv or mult bins"); + } + if (!std::is_sorted(binEdgesZPv.begin(), binEdgesZPv.end()) || !std::is_sorted(binEdgesMult.begin(), binEdgesMult.end())) { + throw std::invalid_argument("bin edges must be sorted"); + } + // prevent zPv over/underflow due to rounding errors + binEdgesZPv.front() = binEdgesZPv.front() < 0 ? binEdgesZPv.front() * zPvRoundingErrorAdjust : binEdgesZPv.front() / zPvRoundingErrorAdjust; + binEdgesZPv.back() = binEdgesZPv.back() > 0 ? binEdgesZPv.back() * zPvRoundingErrorAdjust : binEdgesZPv.back() / zPvRoundingErrorAdjust; + // init correct size of zPv-mult matrix + savedTriggersZPvMult.resize(nBinsZPv); + for (size_t i_zPv = 0; i_zPv < nBinsZPv; i_zPv++) { + savedTriggersZPvMult[i_zPv].resize(nBinsMult); } } - return true; - } - // Initialize collision - template - bool initCollisionMC(const C& collision, const P& particles) - { - if (collision.getSubGeneratorId() != subGeneratorIdSelections) { - return false; + // save trigger for mixing + // up to nTriggerPerBinLimit stored in rolling buffer for each zPv-mult bin + void saveTrigger(float const pt, float const phi, float const eta, double const zPv, double const mult) + { + int const iBinCorrZPv = getZPvBin(zPv); + int const iBinCorrMult = getMultBin(mult); + // fill + std::deque& triggerBin = savedTriggersZPvMult[iBinCorrZPv][iBinCorrMult]; + triggerBin.push_front(MixingTrigger{pt, phi, eta}); + if (triggerBin.size() > nTriggerPerBinLimit) { + triggerBin.pop_back(); + return; // skip nTriggerBinMin update when unnecessary + } + // update nTriggerBinMin + nTriggerBinMin = nTriggerPerBinLimit; + for (size_t i_zPv = 0; i_zPv < nBinsZPv; i_zPv++) { + for (size_t i_mult = 0; i_mult < nBinsMult; i_mult++) { + nTriggerBinMin = std::min(nTriggerBinMin, savedTriggersZPvMult[i_zPv][i_mult].size()); + } + } } - double pTHat = getCollisionPtHat(particles); - if (pTHat < pTHatMin || pTHat > pTHatMax) { - return false; + // return deques of trigger pt, phi, eta in the given zPv/mult bin + [[nodiscard]] std::deque const& getTriggers(double const zPv, double const mult) const + { + int const iBinCorrZPv = getZPvBin(zPv); + int const iBinCorrMult = getMultBin(mult); + return savedTriggersZPvMult[iBinCorrZPv][iBinCorrMult]; } - if (rejectOutliers(particles, pTHat)) { - return false; + [[nodiscard]] size_t getBinSizeMin() const + { + return nTriggerBinMin; } - if (!hardQCDgg2gg && isHardQCDgg2gg(particles)) { - return false; + private: + double zPvRoundingErrorAdjust = 1.0001; + std::vector binEdgesZPv; + size_t nBinsZPv; + std::vector binEdgesMult; + size_t nBinsMult; + std::vector>> savedTriggersZPvMult; + size_t nTriggerPerBinLimit; + size_t nTriggerBinMin = 0; + + [[nodiscard]] size_t getZPvBin(double const zPv) const + { + int const iBinInit = findIntervalBin(zPv, binEdgesZPv); + if (iBinInit == -1 || iBinInit == static_cast(nBinsZPv)) { + throw std::runtime_error("zPv underflow or overflow in MixingTriggerMemory"); + } + return iBinInit; + } + [[nodiscard]] size_t getMultBin(double const mult) const + { + int const iBinInit = findIntervalBin(mult, binEdgesMult); + if (iBinInit == static_cast(nBinsMult)) { + return iBinInit - 1; + } + if (iBinInit == -1) { + throw std::runtime_error("mult underflow in MixingTriggerMemory"); + } + return iBinInit; } + }; - return true; - } + // different buffers for mixing modes + std::unique_ptr triggerMemoryReco; + std::unique_ptr triggerMemoryTrue; + std::unique_ptr triggerMemoryTrueRecoEv; + std::unique_ptr triggerMemoryTrueRecoEvRecoPtTrig; - // To check if object has has_mcParticle() (i.e. is MC Track or data track) - template - struct HasHasMcParticle { - template - static auto test(U* ptr) -> decltype(ptr->has_mcParticle(), std::true_type{}); - static std::false_type test(...); - static constexpr bool Value = decltype(test(std::declval()))::value; - }; + // functions //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ========================================================================================================================================================================================== + + // general (kenobi) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - // Initialize track - template - bool initTrack(const T& track) + static std::vector prependVariableWidth(std::vector const& vec) { + std::vector result{VARIABLE_WIDTH}; + result.insert(result.end(), vec.begin(), vec.end()); + return result; + } - // if constexpr (HasHasMcParticle) { - if constexpr (HasHasMcParticle::Value) { - if (!track.has_mcParticle()) { - return false; - } + static std::vector getBinEdges(TAxis const* axis) + { + std::vector edges; + for (int iBin = 1; iBin <= axis->GetNbins(); iBin++) { + edges.push_back(axis->GetBinLowEdge(iBin)); } + edges.push_back(axis->GetXmax()); + return edges; + } - if (std::abs(track.eta()) > etaMaxAssoc) { - return false; + // get histograms from ccdb + // save corrections from ccdb in histogram registry + void initCcdbHistograms(int64_t const noLaterThanCcdb) + { + // trigger + if (config.applyTriggerPtCorrection.value) { + h1PtCorrectionTrigger = ccdb->getForTimeStamp(config.pathCcdbAnalysis.value + "/correction/trigger", noLaterThanCcdb); + + const AxisSpec axis{getBinEdges(h1PtCorrectionTrigger->GetXaxis()), "#it{p}_{T}"}; + histos.add("usedObjectsCcdb/h1_pt_correction_trigger_ccdb", "h1_pt_correction_trigger_ccdb", kTH1D, {axis}, true); + for (int iBin = 0; iBin <= h1PtCorrectionTrigger->GetNbinsX() + 1; iBin++) { + histos.get(HIST("usedObjectsCcdb/h1_pt_correction_trigger_ccdb"))->SetBinContent(iBin, h1PtCorrectionTrigger->GetBinContent(iBin)); + histos.get(HIST("usedObjectsCcdb/h1_pt_correction_trigger_ccdb"))->SetBinError(iBin, h1PtCorrectionTrigger->GetBinError(iBin)); + } } + // K0Short + if (config.applyScalingK0ShortPt.value) { + h1PtScalingK0Short = ccdb->getForTimeStamp(config.pathCcdbAnalysis.value + "/scaling/K0Short", noLaterThanCcdb); - if (track.pt() < ptMinAssoc || track.pt() > ptMaxAssoc) { - return false; + const AxisSpec axis{getBinEdges(h1PtScalingK0Short->GetXaxis()), "#it{p}_{T}"}; + histos.add("usedObjectsCcdb/h1_pt_scaling_K0Short_ccdb", "h1_pt_scaling_K0Short_ccdb", kTH1D, {axis}, true); + for (int iBin = 0; iBin <= h1PtScalingK0Short->GetNbinsX() + 1; iBin++) { + histos.get(HIST("usedObjectsCcdb/h1_pt_scaling_K0Short_ccdb"))->SetBinContent(iBin, h1PtScalingK0Short->GetBinContent(iBin)); + histos.get(HIST("usedObjectsCcdb/h1_pt_scaling_K0Short_ccdb"))->SetBinError(iBin, h1PtScalingK0Short->GetBinError(iBin)); + } } - - return true; } - // Initialize particle - template - bool initParticle(const T& particle, bool checkIsPrimary = true) - { + // histograms - if (checkIsPrimary && !particle.isPhysicalPrimary()) { - return false; + // main histogram naming (compile time 'string' required for O2 hist registry) + static constexpr std::string_view nameHistMainRecoOrMc(TruthLevel const truthLevel) + { + return truthLevel == TruthLevel::Reco ? "reco" : "mc"; + } + static constexpr std::string_view nameHistMainMode(HistFillMode const histFillMode) + { + switch (histFillMode) { + case HistFillMode::PlainPt: + return "plain/h2_ptTrigPtAssoc_"; + case HistFillMode::PlainPhiEta: + return "plain/h4_ptTrigPtAssocPhiEta_"; + case HistFillMode::PlainZPvMult: + return "plain/h4_ptTrigPtAssocZPvMult_"; + case HistFillMode::Correlation: + return "corr/h6_corr_"; + case HistFillMode::Mixing: + return "corr/h6_mix_"; + default: + throw std::runtime_error("histFillMode not found for hist name"); + } + } + static constexpr std::string_view nameHistMainTruth(TruthLevel const truthLevel) + { + switch (truthLevel) { + case TruthLevel::Reco: + return "reco"; + case TruthLevel::RecoAssocEv: + return "recoAssocEv"; + case TruthLevel::RecoPure: + return "recoPure"; + case TruthLevel::RecoPureTruePtAssoc: + return "recoPureTruePtAssoc"; + case TruthLevel::PseudoReco: + return "pseudoReco"; + case TruthLevel::PseudoRecoAssocEv: + return "pseudoRecoAssocEv"; + case TruthLevel::PseudoRecoPure: + return "pseudoRecoPure"; + case TruthLevel::PseudoRecoPureTruePtAssoc: + return "pseudoRecoPureTruePtAssoc"; + case TruthLevel::TrueGeoAcc: + return "trueGeoAcc"; + case TruthLevel::TrueMeasDecay: + return "trueMeasDecay"; + case TruthLevel::TrueRecoEvRecoPtTrig: + return "trueRecoEvRecoPtTrig"; + case TruthLevel::TrueRecoEv: + return "trueRecoEv"; + case TruthLevel::True: + return "true"; + case TruthLevel::TrueDecaySelfTrig: + return "trueDecaySelfTrig"; + default: + throw std::runtime_error("truthLevel not found for hist name"); + } + } + static constexpr std::string_view nameHistMainAssoc(AssocType const assocType, TruthLevel const truthLevel) + { + switch (assocType) { + case AssocType::Hadron: + return "hadron"; + case AssocType::Pipm: + return "pipm"; + case AssocType::PhotonPcm: + return isTrueLevel(truthLevel) ? "photon" : "photonPcm"; + case AssocType::PhotonDecay: + return "photonDecay"; + case AssocType::PhotonDirect: + return "photonDirect"; + case AssocType::Pi0Pcm: + return isTrueLevel(truthLevel) ? "pi0" : "pi0Pcm"; + case AssocType::Pi0PcmPeak: + return "pi0PcmPeak"; + case AssocType::Pi0PcmSide: + return "pi0PcmSide"; + case AssocType::PhotonPi0: + return "photonPi0"; + case AssocType::EtaPcm: + return isTrueLevel(truthLevel) ? "eta" : "etaPcm"; + case AssocType::EtaPcmPeak: + return "etaPcmPeak"; + case AssocType::EtaPcmSide: + return "etaPcmSide"; + case AssocType::PhotonEta: + return "photonEta"; + case AssocType::Omega: + return "omega"; + case AssocType::PhotonOmega: + return "photonOmega"; + case AssocType::EtaPrime: + return "etaPrime"; + case AssocType::PhotonEtaPrime: + return "photonEtaPrime"; + case AssocType::PhotonOtherMother: + return "photonOtherMother"; + default: + throw std::runtime_error("assocType not found for hist name"); } + } + template + static constexpr auto histPath() + { + return HIST(nameHistMainRecoOrMc(TruthLevelV)) + HIST("/") + + HIST(nameHistMainMode(HistFillModeV)) + HIST(nameHistMainTruth(TruthLevelV)) + HIST("_") + HIST(nameHistMainAssoc(AssocTypeV, TruthLevelV)); + } - if (particle.getGenStatusCode() == -1) { - return false; + // create histograms + void initHistograms() + { + // define axes + const AxisSpec axisN{1, 0., 1., "#it{N}_{something}"}; + const AxisSpec axisCategories{32, 0., 32., "categories"}; + const AxisSpec axisInts{2049, -1024.5, 1024.5, "ints"}; + + const AxisSpec axisZPv{configHist.nBinsZPvPlain, -7, 7, "#it{z}_{pv}"}; + const AxisSpec axisMult{configHist.nBinsMultPlain + 1, -0.5, configHist.nBinsMultPlain + 0.5, "multiplicity"}; + + const AxisSpec axisPhi{configHist.nBinsPhi, 0, constants::math::TwoPI, "#it{#varphi}"}; + const AxisSpec axisEta{configHist.nBinsEta, -config.absEtaMax.value, config.absEtaMax.value, "#it{#eta}"}; + const AxisSpec axisDcaZ{configHist.nBinsDcaZ, -5, 5, "DCA_{z}"}; + const AxisSpec axisMgg{configHist.nBinsMgg, 0, 0.8, "#it{m}_{#gamma#gamma}"}; + + const AxisSpec axisPtTrig{configHist.binsPtTrig, "#it{p}_{T}^{trig}"}; + const AxisSpec axisPtAssoc{configHist.binsPtAssoc, "#it{p}_{T}^{assoc}"}; + const AxisSpec axisDPhi{configHist.binsDPhi, "#Delta#it{#varphi}"}; + const AxisSpec axisDEta{configHist.binsDEta, "#Delta#it{#eta}"}; + const AxisSpec axisZPvBinning{configHist.binsZPvBinning, "#it{z}_{pv} correlation binning"}; + const AxisSpec axisMultBinning{configHist.binsMultBinning, "multiplicity correlation binning"}; + const AxisSpec axisZPvBinningMcTrue{configHist.binsZPvBinningMcTrue, "#it{z}_{pv} correlation binning for mc true"}; + const AxisSpec axisMultBinningMcTrue{configHist.binsMultBinningMcTrue, "multiplicity correlation binning for mc true"}; + + // main info for assocType (spectra and correlation) + auto const addMainAssocHists = + [&](TruthLevel const truthLevel, AssocType const assocType, bool const resolvedInfo, bool const trueColInfo) { + // runtime counterpart of histPath(), title is name without directories + auto const addMainHist = [&](HistFillMode const histFillMode, std::vector const& axes) { + std::string const name = std::format("{}/{}{}_{}", nameHistMainRecoOrMc(truthLevel), nameHistMainMode(histFillMode), + nameHistMainTruth(truthLevel), nameHistMainAssoc(assocType, truthLevel)); + histos.add(name, name.substr(name.rfind('/') + 1).data(), kTHnSparseD, axes, true); + }; + if (resolvedInfo) { + addMainHist(HistFillMode::PlainPhiEta, {axisPtTrig, axisPtAssoc, axisPhi, axisEta}); + addMainHist(HistFillMode::PlainZPvMult, {axisPtTrig, axisPtAssoc, axisZPv, axisMult}); + } else { + addMainHist(HistFillMode::PlainPt, {axisPtTrig, axisPtAssoc}); + } + if (!trueColInfo) { + addMainHist(HistFillMode::Correlation, {axisDPhi, axisDEta, axisPtTrig, axisPtAssoc, axisZPvBinning, axisMultBinning}); + addMainHist(HistFillMode::Mixing, {axisDPhi, axisDEta, axisPtTrig, axisPtAssoc, axisZPvBinning, axisMultBinning}); + } else { + addMainHist(HistFillMode::Correlation, {axisDPhi, axisDEta, axisPtTrig, axisPtAssoc, axisZPvBinningMcTrue, axisMultBinningMcTrue}); + addMainHist(HistFillMode::Mixing, {axisDPhi, axisDEta, axisPtTrig, axisPtAssoc, axisZPvBinningMcTrue, axisMultBinningMcTrue}); + } + }; + + // reco info + histos.add("reco/info/h1_nEvents", "h1_nEvents", kTH1D, {axisCategories}, true); + histos.add("reco/info/h3_nEv_ptTrigZPvMult_reco", "h3_nEv_ptTrigZPvMult_reco", kTHnSparseD, {axisPtTrig, axisZPv, axisMult}, true); + + // reco (correlation) analysis + histos.add("reco/corr/h3_ptPhiEta_trig_reco", "h3_ptPhiEta_trig_reco", kTHnSparseD, {axisPtAssoc, axisPhi, axisEta}, true); + for (AssocType const& assocType : {AssocType::Hadron, AssocType::Pipm, AssocType::PhotonPcm}) { + addMainAssocHists(TruthLevel::Reco, assocType, true, false); + } + for (AssocType const& assocType : {AssocType::Pi0PcmPeak, AssocType::Pi0PcmSide, AssocType::EtaPcmPeak, AssocType::EtaPcmSide}) { + addMainAssocHists(TruthLevel::Reco, assocType, false, false); + } + + // photonPcm pairs + // mgg + histos.add("reco/plain/h5_ptTrigPtAssocMggZPvMult_reco_photonPcmPair", "h5_ptTrigPtAssocMggZPvMult_reco_photonPcmPair", + kTHnSparseD, {axisPtTrig, axisPtAssoc, axisMgg, axisZPvBinning, axisMultBinning}, true); + histos.add("reco/corr/h5_ptTrigPtAssocMggZPvMult_reco_photonPcmPair", "h5_ptTrigPtAssocMggZPvMult_reco_photonPcmPair", + kTHnSparseD, {axisPtTrig, axisPtAssoc, axisMgg, axisZPvBinning, axisMultBinning}, true); + // event mixing for photon pairs + histos.add("reco/plain/h4_ptMggZPvMult_reco_photonPcmPair_evMix", "h4_ptMggZPvMult_reco_photonPcmPair_evMix", + kTHnSparseD, {axisPtAssoc, axisMgg, axisZPvBinning, axisMultBinning}, true); + // pseudo mgg + // pi0Pcm + histos.add("mc/plain/h5_ptTrigPtAssocMggZPvMult_pseudoReco_pi0Pcm", "h5_ptTrigPtAssocMggZPvMult_pseudoReco_pi0Pcm", + kTHnSparseD, {axisPtTrig, axisPtAssoc, axisMgg, axisZPvBinning, axisMultBinning}, true); + histos.add("mc/corr/h5_ptTrigPtAssocMggZPvMult_pseudoReco_pi0Pcm", "h5_ptTrigPtAssocMggZPvMult_pseudoReco_pi0Pcm", + kTHnSparseD, {axisPtTrig, axisPtAssoc, axisMgg, axisZPvBinning, axisMultBinning}, true); + histos.add("mc/plain/h5_ptTrigPtAssocMggZPvMult_pseudoReco_etaPcm", "h5_ptTrigPtAssocMggZPvMult_pseudoReco_etaPcm", + kTHnSparseD, {axisPtTrig, axisPtAssoc, axisMgg, axisZPvBinning, axisMultBinning}, true); + histos.add("mc/corr/h5_ptTrigPtAssocMggZPvMult_pseudoReco_etaPcm", "h5_ptTrigPtAssocMggZPvMult_pseudoReco_etaPcm", + kTHnSparseD, {axisPtTrig, axisPtAssoc, axisMgg, axisZPvBinning, axisMultBinning}, true); + + // mc info + histos.add("mc/info/h3_nEv_ptTrigZPvMult_true", "h3_nEv_ptTrigZPvMult_true", kTHnSparseD, {axisPtTrig, axisZPv, axisMult}, true); + histos.add("mc/info/h3_nEv_ptTrigZPvMult_trueRecoEv", "h3_nEv_ptTrigZPvMult_trueRecoEv", kTHnSparseD, {axisPtTrig, axisZPv, axisMult}, true); + histos.add("mc/info/h3_nEv_ptTrigZPvMult_trueRecoEvRecoPtTrig", "h3_nEv_ptTrigZPvMult_trueRecoEvRecoPtTrig", kTHnSparseD, {axisPtTrig, axisZPv, axisMult}, true); + + // true++ (event selection) + for (TruthLevel const& truthLevel : {TruthLevel::True, TruthLevel::TrueRecoEv, TruthLevel::TrueRecoEvRecoPtTrig}) { + histos.add(std::format("mc/corr/h3_ptPhiEta_trig_{}", nameHistMainTruth(truthLevel)).data(), std::format("h3_ptPhiEta_trig_{}", nameHistMainTruth(truthLevel)).data(), + kTHnSparseD, {axisPtAssoc, axisPhi, axisEta}, true); + for (AssocType const& assocType : {AssocType::Hadron, AssocType::Pipm, AssocType::PhotonPcm}) { + addMainAssocHists(truthLevel, assocType, true, true); + } + for (AssocType const& assocType : {AssocType::Pi0Pcm, AssocType::EtaPcm}) { + addMainAssocHists(truthLevel, assocType, false, true); + } + } + // extra truthLevels for photonPcmPair + for (TruthLevel const& truthLevel : {TruthLevel::TrueDecaySelfTrig, TruthLevel::TrueMeasDecay, TruthLevel::TrueGeoAcc}) { + for (AssocType const& assocType : {AssocType::Pi0Pcm, AssocType::EtaPcm}) { + addMainAssocHists(truthLevel, assocType, false, true); + } + } + // assocTypes just on true level + for (AssocType const& assocType : {AssocType::PhotonDecay, AssocType::PhotonDirect, AssocType::PhotonPi0, AssocType::PhotonEta, + AssocType::Omega, AssocType::PhotonOmega, AssocType::EtaPrime, AssocType::PhotonEtaPrime, AssocType::PhotonOtherMother}) { + addMainAssocHists(TruthLevel::True, assocType, false, true); } - if (std::abs(particle.eta()) > etaMaxAssoc) { - return false; + // reco++ (MC info) + // std assoc + for (TruthLevel const& truthLevel : {TruthLevel::RecoAssocEv, TruthLevel::RecoPure, TruthLevel::RecoPureTruePtAssoc}) { + for (AssocType const& assocType : {AssocType::Hadron, AssocType::Pipm, AssocType::PhotonPcm}) { + addMainAssocHists(truthLevel, assocType, true, false); + } + } + // photonPcmPair assoc + for (TruthLevel const& truthLevel : {TruthLevel::PseudoReco, TruthLevel::PseudoRecoAssocEv, TruthLevel::PseudoRecoPure, TruthLevel::PseudoRecoPureTruePtAssoc}) { + for (AssocType const& assocType : {AssocType::Pi0Pcm, AssocType::EtaPcm}) { + addMainAssocHists(truthLevel, assocType, false, false); + } } + // impurity details + histos.add("mc/plain/h3_ptTrigPtAssocCategory_recoImpurities_photonPcm", "h3_ptTrigPtAssocCategory_recoImpurities_photonPcm", + kTHnSparseD, {axisPtTrig, axisPtAssoc, axisCategories}, true); + histos.add("mc/plain/h3_ptTrigPtAssocCategory_pseudoRecoImpurities_pi0Pcm", "h3_ptTrigPtAssocCategory_pseudoRecoImpurities_pi0Pcm", + kTHnSparseD, {axisPtTrig, axisPtAssoc, axisCategories}, true); + + // check count histograms - should not be filled, unless something is off / changed + histos.add("mc/info/h1_noMatch_event", "h1_noMatch_event", kTH1D, {axisN}, true); + histos.add("mc/info/h1_pt_noMatch_trigger", "h1_pt_noMatch_trigger", kTH1D, {axisPtTrig}, true); + histos.add("mc/info/h1_unusualStatus_photonDirect", "h1_unusualStatus_photonDirect", kTH1D, {axisInts}, true); + + // pcm dcaZ + histos.add("reco/plain/h5_ptTrigPtAssocDcaZZPvMult_photonPcm", "h5_ptTrigPtAssocDcaZZPvMult_photonPcm", + kTHnSparseD, {axisPtTrig, axisPtAssoc, axisDcaZ, axisZPvBinning, axisMultBinning}, true); + histos.add("mc/plain/h5_ptTrigPtAssocDcaZZPvMult_photonPcm", "h5_ptTrigPtAssocDcaZZPvMult_photonPcm", + kTHnSparseD, {axisPtTrig, axisPtAssoc, axisDcaZ, axisZPvBinning, axisMultBinning}, true); + } - if (particle.pt() < ptMinAssoc || particle.pt() > ptMaxAssoc) { + // selections /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + + // checks if mcParticle is charged + bool isCharged(auto const& mcParticle) + { + auto const pdgParticle = pdg->GetParticle(mcParticle.pdgCode()); + return pdgParticle && pdgParticle->Charge() != 0; + } + // checks if fast decaying mcParticle is 'primary' + bool isDecayPrimary(auto const& mcParticle) + { + // identify decaying primary + return mcParticle.producedByGenerator(); + } + + // checks if mcParticle daughters are two photons + bool isDecayToGG(auto const& mcParticle) + { + auto const& daughters = mcParticle.template daughters_as(); + constexpr int NDaughtersToGG = 2; + if (daughters.size() != NDaughtersToGG) { return false; } - + for (auto const& daughter : daughters) { + if (daughter.pdgCode() != PDG_t::kGamma) { + return false; + } + } return true; } - - // Initialize Pythia8 decay particle - /*bool initDecayParticle(const TParticle* particle) + // check if particle has associated mother in parent tree + // includes associated particle checks + bool checkForAssocDecay(auto const& mcParticle, AssocType const assocType) { + int const pdgCode = [&]() { + if (assocType == AssocType::Pi0Pcm) { + return static_cast(PDG_t::kPi0); + } else if (assocType == AssocType::EtaPcm) { + return static_cast(constants::physics::Pdg::kEta); + } else { + throw std::runtime_error("invalid assocType for mother search"); + } + }(); - if (particle->GetMother(0) != 0) { + if (!mcParticle.has_mothers()) { return false; } + auto const mothers = mcParticle.template mothers_as(); + for (auto const& mother : mothers) { + // exclude pre-hadonisation + int const statusPreHadronisationCut = 80; + if (mother.producedByGenerator() && std::abs(mother.getGenStatusCode()) < statusPreHadronisationCut) { + return false; + } + // check valid associated particle + if (mother.pdgCode() == pdgCode || mother.pdgCode() == -pdgCode) { + if (std::abs(mother.eta()) < config.absEtaMax.value && isDecayPrimary(mother)) { + return true; + } + } + if (checkForAssocDecay(mother, assocType)) { + return true; + } + } + return false; + } + // get plain self trigger associated map for event + template + std::map getDecaySelfTrigPlainMap(auto const& triggersThisEvent) + { + std::map decaySelfTrigPlainMap; - if (std::abs(particle->GetPdgCode()) != kGamma) { - return false; + for (AssocType const& assocType : {AssocType::Pi0Pcm, AssocType::EtaPcm}) { + decaySelfTrigPlainMap[assocType] = [&]() { + // false for no triggers + if (triggersThisEvent.size() == 0) { + return false; + } + // check every trigger for self trigger and return false if unrelated (event triggers independently) + for (auto const& trigger : triggersThisEvent) { + if constexpr (TruthLevelV == TruthLevel::TrueRecoEvRecoPtTrig) { + if (!isMcMatchedTrigger(trigger)) { + return false; + } + if (!checkForAssocDecay(trigger.template jetTrack_as().mcParticle(), assocType)) { + return false; + } + } else if constexpr (TruthLevelV == TruthLevel::TrueRecoEv || TruthLevelV == TruthLevel::True) { + if (!checkForAssocDecay(trigger.jetMcParticle(), assocType)) { + return false; + } + } else { + static_assert(AlwaysFalseValue, "truthLevel not found"); + } + } + return true; + }(); } - if (std::abs(particle->Eta()) > etaMaxAssoc) { + return decaySelfTrigPlainMap; + } + // recursive helper to exclude loopDeLoops + template + bool producesTrigger(T_mcParticle const& mcParticle, T_mcParticle const& triggerParticle, std::unordered_set& visited) + { + if (!visited.insert(mcParticle.globalIndex()).second) { return false; } - - if (particle->Pt() < ptMinAssoc || particle->Pt() > ptMaxAssoc) { + if (!mcParticle.has_daughters()) { return false; } + auto const daughters = mcParticle.template daughters_as(); + for (auto const& daughter : daughters) { + if (daughter.globalIndex() == triggerParticle.globalIndex()) { + return true; + } + if (producesTrigger(daughter, triggerParticle, visited)) { + return true; + } + } + return false; + } + // check if particle has trigger in daughter tree + template + bool producesTrigger(T_mcParticle const& mcParticle, T_mcParticle const& triggerParticle) + { + std::unordered_set visited; + return producesTrigger(mcParticle, triggerParticle, visited); + } + // checks if daughters are in acceptance + bool checkDaughtersInAcceptance(auto const& mcParticle, std::pair const etaRange, std::pair const phiRange = {0, constants::math::TwoPI}) + { + auto const& daughters = mcParticle.template daughters_as(); + for (auto const& daughter : daughters) { + if (daughter.eta() < etaRange.first || daughter.eta() > etaRange.second) { + return false; + } + if (daughter.phi() < phiRange.first || daughter.phi() > phiRange.second) { + return false; + } + } return true; - }*/ + } - // Initialize trigger tracks - template - bool initTrig(const T& track) + // assocType dependent checks --------------------------------------------------------------------------------------------------------------------------------------------------------------- + + // check trivial self correlation for reconstruction + bool isRecoSelfTrigger(auto const& trigger, auto const& associated) { - // if constexpr (HasHasMcParticle) { - if constexpr (HasHasMcParticle::Value) { - if (!track.has_mcParticle()) { - return false; + for (auto const& intersectTriggerId : associated.intersectTriggerIds()) { + if (intersectTriggerId == trigger.globalIndex()) { + return true; } } + return false; + }; - if (std::abs(track.eta()) > etaMaxTrig) { - return false; + // check reco-mc match + bool isMcMatchedCollision(auto const& collision) + { + return collision.has_jetMcCollision(); + }; + bool isMcMatchedTrigger(auto const& trigger) + { + return trigger.template jetTrack_as().has_mcParticle(); + }; + + // check reco truthLevel reached + template + bool checkTruthLevelReco(auto const& associated) + { + // std + static constexpr std::array TruthLevelsRecoStdRanked{ + TruthLevel::Reco, + TruthLevel::RecoMcMatched, + TruthLevel::RecoAssocEv, + TruthLevel::RecoPure}; + // diPhoton + static constexpr std::array TruthLevelsRecoDiPhotonRanked{ + TruthLevel::Reco, + TruthLevel::RecoMcMatched, + TruthLevel::PseudoReco, + TruthLevel::PseudoRecoAssocEv, + TruthLevel::PseudoRecoPure}; + // position of truthLevel in chain, -1 if not in ranked truthLevels + auto constexpr GetRank = [](TruthLevel const truthLevel, auto const& truthLevelsRanked) constexpr -> int { + for (size_t iRank = 0; iRank < truthLevelsRanked.size(); iRank++) { + if (truthLevelsRanked[iRank] == truthLevel) { + return static_cast(iRank); + } + } + return -1; + }; + // TruthLevelV compared to the stored maximum level + auto const isReached = [&GetRank](TruthLevel const truthLevelRecoMax, auto const& truthLevelsRanked) { + int const rankRecoToCheck = GetRank(TruthLevelV, truthLevelsRanked); + int const rankRecoMax = GetRank(truthLevelRecoMax, truthLevelsRanked); + if (rankRecoMax < 0) { + throw std::runtime_error("rankRecoMax not found"); + } + return rankRecoToCheck <= rankRecoMax; + }; + // assocType cases + if constexpr (AssocTypeV == AssocType::Hadron) { + static_assert(GetRank(TruthLevelV, TruthLevelsRecoStdRanked) >= 0, "truthLevel not in std reco chain"); + TruthLevel const truthLevelRecoMax = static_cast(associated.truthLevelRecoHadron()); + return isReached(truthLevelRecoMax, TruthLevelsRecoStdRanked); + } else if constexpr (AssocTypeV == AssocType::Pipm) { + static_assert(GetRank(TruthLevelV, TruthLevelsRecoStdRanked) >= 0, "truthLevel not in std reco chain"); + TruthLevel const truthLevelRecoMax = static_cast(associated.truthLevelRecoPipm()); + return isReached(truthLevelRecoMax, TruthLevelsRecoStdRanked); + } else if constexpr (AssocTypeV == AssocType::PhotonPcm) { + static_assert(GetRank(TruthLevelV, TruthLevelsRecoStdRanked) >= 0, "truthLevel not in std reco chain"); + TruthLevel const truthLevelRecoMax = static_cast(associated.truthLevelRecoPhotonPcm()); + return isReached(truthLevelRecoMax, TruthLevelsRecoStdRanked); + } else if constexpr (AssocTypeV == AssocType::Pi0Pcm) { + static_assert(GetRank(TruthLevelV, TruthLevelsRecoDiPhotonRanked) >= 0, "truthLevel not in diPhoton reco chain"); + TruthLevel const truthLevelRecoMax = static_cast(associated.truthLevelRecoPi0Pcm()); + return isReached(truthLevelRecoMax, TruthLevelsRecoDiPhotonRanked); + } else if constexpr (AssocTypeV == AssocType::EtaPcm) { + static_assert(GetRank(TruthLevelV, TruthLevelsRecoDiPhotonRanked) >= 0, "truthLevel not in diPhoton reco chain"); + TruthLevel const truthLevelRecoMax = static_cast(associated.truthLevelRecoEtaPcm()); + return isReached(truthLevelRecoMax, TruthLevelsRecoDiPhotonRanked); + } else { + static_assert(AlwaysFalseValue, "assocType not found"); } + } - if (track.pt() < ptMinTrig || track.pt() > ptMaxTrig) { - return false; + // analysis helpers ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + + // fill main histogram + template + void fillHistMain(auto const& histFillInfo) + { + if constexpr (HistFillModeV == HistFillMode::Plain) { + if constexpr (AssocTypeV == AssocType::Hadron || AssocTypeV == AssocType::Pipm || AssocTypeV == AssocType::PhotonPcm) { + histos.fill(histPath(), + histFillInfo.ptMax, histFillInfo.ptAssoc, histFillInfo.phi, histFillInfo.eta, + histFillInfo.weight); + histos.fill(histPath(), + histFillInfo.ptMax, histFillInfo.ptAssoc, histFillInfo.zPv, histFillInfo.mult, + histFillInfo.weight); + } else { + histos.fill(histPath(), + histFillInfo.ptMax, histFillInfo.ptAssoc, + histFillInfo.weight); + } + } else if constexpr (HistFillModeV == HistFillMode::Correlation || HistFillModeV == HistFillMode::Mixing) { + histos.fill(histPath(), + histFillInfo.dPhi, histFillInfo.dEta, histFillInfo.ptTrig, histFillInfo.ptAssoc, histFillInfo.zPv, histFillInfo.mult, + histFillInfo.weight); + } else { + static_assert(AlwaysFalseValue, "fillMode not valid"); } + } - return true; + // tcm component: exponential for low pt + // parameter shape: [m0_h, A_e, T_e] + double tcmInvariantSoftExp(double const* pt, double const* par) + { + double const etKin = std::sqrt(std::pow(pt[0], 2) + std::pow(par[0], 2)) - par[0]; + return std::abs(par[1]) * std::exp(-etKin / par[2]); + } + // tcm component: power law for high pt + // parameter shape: [A_p, T_p, N_p] + double tcmInvariantHardPower(double const* pt, double const* par) + { + return std::abs(par[0]) / std::pow(1 + std::pow(pt[0], 2) / (std::pow(par[1], 2) * par[2]), par[2]); + } + // fit function for invariant pt spectrum + // parameter shape: [m0_h, A_e, T_e, A_p, T_p, N_p] + double tcmInvariantFit(double const* pt, double const* par) + { + int const nParSoftExp = 3; + return tcmInvariantSoftExp(pt, par) + tcmInvariantHardPower(pt, par + nParSoftExp); + } + // tcm function (non-invariant) + double tcmParam(double const pt, std::vector const& par) + { + return pt * tcmInvariantFit(&pt, par.data()); } - // Initialize trigger particles (charged) - template - bool initTrigParticle(const T& particle) + // pt weight + double ptWeightTcms(double const pt, std::vector const& parNum, std::vector const& parDenom) { - if (!particle.isPhysicalPrimary()) { - return false; - } + return tcmParam(pt, parNum) / tcmParam(pt, parDenom); + } - auto pdgParticle = pdg->GetParticle(particle.pdgCode()); - if (!pdgParticle || pdgParticle->Charge() == 0.) { - return false; - } + // rescale of pt spectra for mc - if (std::abs(particle.eta()) > etaMaxTrig) { - return false; + template + double getMcAssocPtScalingFromPt(double const ptTrue) + { + auto const getWeight = [this](double const pt, std::vector const& ptRange, std::vector const& parNum, std::vector const& parDenom) { + if (pt < ptRange.at(0)) { + return ptWeightTcms(ptRange.at(0), parNum, parDenom); + } + if (pt > ptRange.at(1)) { + return ptWeightTcms(ptRange.at(1), parNum, parDenom); + } + return ptWeightTcms(pt, parNum, parDenom); + }; + if constexpr (AssocTypeV == AssocType::PhotonPcm) { + return config.applyScalingPhotonPt.value ? getWeight(ptTrue, config.ptRangeScalingPhoton.value, config.parScalingPhotonPtData.value, config.parScalingPhotonPtMc.value) : 1; + } else if constexpr (AssocTypeV == AssocType::Pi0Pcm) { + return config.applyScalingPi0Pt.value ? getWeight(ptTrue, config.ptRangeScalingPi0.value, config.parScalingPi0PtData.value, config.parScalingPi0PtMc.value) : 1; + } else if constexpr (AssocTypeV == AssocType::EtaPcm) { + return config.applyScalingEtaPt.value ? getWeight(ptTrue, config.ptRangeScalingEta.value, config.parScalingEtaPtData.value, config.parScalingEtaPtMc.value) : 1; + } else { + static_assert(AlwaysFalseValue, "assocType not found"); } - - if (particle.pt() < ptMinTrig || particle.pt() > ptMaxTrig) { - return false; + } + template + double getMcAssocPtScaling(auto const& associated) + { + if constexpr (AssocTypeV == AssocType::Hadron || AssocTypeV == AssocType::Pipm) { + return 1; + } else if constexpr (AssocTypeV == AssocType::PhotonPcm) { + if (!config.applyScalingPhotonPt.value) + return 1; + if (checkTruthLevelReco(associated)) { + return getMcAssocPtScalingFromPt(associated.ptTruePure()); + } else { + return 1; + } + } else if constexpr (AssocTypeV == AssocType::PhotonPcmPair) { + if (!config.applyScalingPi0Pt.value && !config.applyScalingEtaPt.value) + return 1; + if (checkTruthLevelReco(associated)) { + return getMcAssocPtScalingFromPt(associated.ptTruePure()); + } else if (checkTruthLevelReco(associated)) { + return getMcAssocPtScalingFromPt(associated.ptTruePure()); + } else { + return 1; + } + } else { + static_assert(AlwaysFalseValue, "assocType not found"); } + } - return true; + // get histogram y-quantity at x-value + double getH1ValueAt(auto const* const h1, double const value) + { + return h1->GetBinContent(h1->FindFixBin(value)); } - // Initialize V0s - template - bool initV0(TV0 const& v0) + // K0Short mc scaling + double getMcK0ShortPtScalingFromPt(double const ptTrue) { - auto pos = v0.template posTrack_as(); - auto neg = v0.template negTrack_as(); - if (!initV0leg(pos) || !initV0leg(neg)) { - return false; + return config.applyScalingK0ShortPt.value ? getH1ValueAt(h1PtScalingK0Short, ptTrue) : 1; + } + template + double getMcK0ShortPtScaling(auto const& associated) + { + if constexpr (AssocTypeV == AssocType::Hadron || AssocTypeV == AssocType::Pipm) { + return 1; + } else if constexpr (AssocTypeV == AssocType::PhotonPcm) { + if (associated.impurityPhotonPcm() == static_cast(PhotonImpurity::K0Short)) { + return getMcK0ShortPtScalingFromPt(associated.ptTrueOrigin()); + } else { + return 1; + } + } else if constexpr (AssocTypeV == AssocType::PhotonPcmPair) { + if (associated.impurityPi0Pcm() == static_cast(PhotonImpurity::K0Short)) { + return getMcK0ShortPtScalingFromPt(associated.ptTrueOrigin()); + } else { + return 1; + } + } else { + static_assert(AlwaysFalseValue, "assocType not found"); } + } - return true; + // correction trigger as function of pt + double getTriggerPtCorrection(double const pt) + { + return config.applyTriggerPtCorrection.value ? getH1ValueAt(h1PtCorrectionTrigger, pt) : 1; } - template - bool initV0leg(TTrack const& track) + // performs 'phi1 - phi2' and pushes it into the interval [-pi/2, 3pi/2] + double getDeltaPhi(double const phi1, double const phi2) { - if (!initTrack(track)) { - return false; - } + return RecoDecay::constrainAngle(phi1 - phi2, -constants::math::PIHalf); + } - if (!track.hasTPC()) { - return false; + // check if invariant mass range + template + bool isInMassRange(double const mgg) + { + if constexpr (AssocTypeV == AssocType::Pi0PcmPeak) { + return mgg > config.pi0PcmPeakMassRange.value.at(0) && mgg < config.pi0PcmPeakMassRange.value.at(1); + } else if constexpr (AssocTypeV == AssocType::Pi0PcmSide) { + return mgg > config.pi0PcmSideMassRange.value.at(0) && mgg < config.pi0PcmSideMassRange.value.at(1); + } else if constexpr (AssocTypeV == AssocType::EtaPcmPeak) { + return mgg > config.etaPcmPeakMassRange.value.at(0) && mgg < config.etaPcmPeakMassRange.value.at(1); + } else if constexpr (AssocTypeV == AssocType::EtaPcmSide) { + return (mgg > config.etaPcmLowSideMassRange.value.at(0) && mgg < config.etaPcmLowSideMassRange.value.at(1)) || + (mgg > config.etaPcmHighSideMassRange.value.at(0) && mgg < config.etaPcmHighSideMassRange.value.at(1)); + } else { + static_assert(AlwaysFalseValue, "assocType not found"); } + } - if (track.tpcNClsCrossedRows() < tpcNClsCrossedRows) { - return false; - } + // analysis ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - if (track.tpcCrossedRowsOverFindableCls() < tpcCrossedRowsOverFindableCls) { - return false; - } + // generalised correlation functions - return true; - } + struct CorrNoCondition { + }; - /**************************************************************************************************** - ************************************************ EVENTS ******************************************** - ****************************************************************************************************/ - void processEventsMCGen(JetMcCollision const& collision, - JetParticles const& particles) + // plain info + void corrProcessPlain(auto const& collision, auto const& associatedThisEvent, + auto const& funcPlain) { - if (collision.getSubGeneratorId() == subGeneratorIdSelections) { - registry.fill(HIST("generated/events/hEventStats"), 0); - registry.fill(HIST("generated/events/hEventStats"), 2, collision.weight()); - registry.fill(HIST("generated/events/hEventStats"), 4, collision.xsectGen()); + // normal spectra (per event - not per trigger) + for (auto const& associated : associatedThisEvent) { + funcPlain(collision, associated); } + } - if (!initCollisionMC(collision, particles)) { - return; + // correlation + void corrProcessCorrelation(auto const& collision, auto const& triggersThisEvent, auto const& associatedThisEvent, + auto const& funcCorrelation) + { + // correlation combinations + for (auto const& [trigger, associated] : soa::combinations(soa::CombinationsFullIndexPolicy(triggersThisEvent, associatedThisEvent))) { + funcCorrelation(collision, trigger, associated); } + } - registry.fill(HIST("generated/events/hEventStats"), 1); - registry.fill(HIST("generated/events/hEventStats"), 3, collision.weight()); - registry.fill(HIST("generated/events/hEventStats"), 5, collision.xsectGen()); - - registry.fill(HIST("generated/events/hPtHat"), getCollisionPtHat(particles)); + // mixing-number pt scaling with power law + size_t nMixingPtPowerScaling(size_t const n0, double const pt) + { + double const scale = 1 + config.nTriggerScaleCoefficient.value * std::pow(pt, config.nTriggerScaleExponent.value); + return n0 * scale; } - PROCESS_SWITCH(HadronPhotonCorrelation, processEventsMCGen, "event stats MC gen", true); - void processEventsMCReco(JetCollisionMCD const& collision, - JetMcCollisions const&, - JetParticles const&) + // mixing + template + void corrProcessMixing(auto const& collision, auto const& associatedThisEvent, + auto const& funcMixing, size_t const nTriggerMixingAt0, T_AssocCondition const& funcConditionAssocOnly = {}) { - if (collision.getSubGeneratorId() != subGeneratorIdSelections) { + size_t triggerMemoryBinSizeMin = 0; + + // mixing loops (more dynamic than O2 mixing) + std::deque const& savedTriggers = + [&]() -> std::deque const& { + if constexpr (TruthLevelV == TruthLevel::Reco) { + triggerMemoryBinSizeMin = triggerMemoryReco->getBinSizeMin(); + return triggerMemoryReco->getTriggers(collision.posZ(), collision.nGlobalTracks()); + } else if constexpr (TruthLevelV == TruthLevel::True) { + triggerMemoryBinSizeMin = triggerMemoryTrue->getBinSizeMin(); + return triggerMemoryTrue->getTriggers(collision.posZ(), collision.nChargedInEtaRange()); + } else if constexpr (TruthLevelV == TruthLevel::TrueRecoEv) { + triggerMemoryBinSizeMin = triggerMemoryTrueRecoEv->getBinSizeMin(); + return triggerMemoryTrueRecoEv->getTriggers(collision.posZ(), collision.nChargedInEtaRange()); + } else if constexpr (TruthLevelV == TruthLevel::TrueRecoEvRecoPtTrig) { + triggerMemoryBinSizeMin = triggerMemoryTrueRecoEvRecoPtTrig->getBinSizeMin(); + return triggerMemoryTrueRecoEvRecoPtTrig->getTriggers(collision.posZ(), collision.nChargedInEtaRange()); + } else { + static_assert(AlwaysFalseValue, "TruthLevel not found"); + } + }(); + // require enough mixing statistics + if (triggerMemoryBinSizeMin < static_cast(config.nTriggerBinMinThreshold.value)) { return; } - registry.fill(HIST("reconstructed/events/hEventStats"), 0); - registry.fill(HIST("reconstructed/events/hEventStats"), 2, collision.mcCollision().weight()); - registry.fill(HIST("reconstructed/events/hEventStats"), 4, collision.mcCollision().xsectGen()); - - if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits, false)) { - return; + const size_t nSavedTriggers = savedTriggers.size(); + const size_t iStartTrigger = randomIntInInterval(0, config.iTriggerStartFraction.value * nSavedTriggers); + // associated loop + for (auto const& associated : associatedThisEvent) { + if constexpr (!std::is_same_v) { + if (!funcConditionAssocOnly(associated)) { + continue; + } + } + // trigger settings + const size_t nTriggerMixing = nMixingPtPowerScaling(nTriggerMixingAt0, associated.pt()); + const size_t mixUpToTriggerN = std::min(nSavedTriggers, iStartTrigger + nTriggerMixing); + const float perTriggerWeight = 1. / (mixUpToTriggerN - iStartTrigger); // mixUpToTriggerN <= iStartTrigger caught by break statement of loop + // trigger loop + for (size_t i_mixingTrigger = iStartTrigger; i_mixingTrigger < mixUpToTriggerN; i_mixingTrigger++) { + MixingTrigger const& mixingTrigger = savedTriggers[i_mixingTrigger]; + funcMixing(collision, mixingTrigger, associated, perTriggerWeight); + } } - - registry.fill(HIST("reconstructed/events/hEventStats"), 1); - registry.fill(HIST("reconstructed/events/hEventStats"), 3, collision.mcCollision().weight()); - registry.fill(HIST("reconstructed/events/hEventStats"), 5, collision.mcCollision().xsectGen()); } - PROCESS_SWITCH(HadronPhotonCorrelation, processEventsMCReco, "event stats MC reco", true); - /**************************************************************************************************** - ************************************************ TRIGGER ******************************************** - ****************************************************************************************************/ + // analysis tasks /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // =/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/ - /********************************************** DATA ***********************************************/ - - void processTrigsReco(JetCollision const& collision, - JetTracks const& tracks) + void init(InitContext& initContext) { - if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits)) { - return; + double const doublePrecisionDeltaCheck = 1e-5; + double zPvMaxProducer; + double absEtaMaxProducer; + double ptTrigMinProducer; + float cfgMinEtaV0Selection; + float cfgMaxEtaV0Selection; + + // analysis info + int64_t const noLaterThanCcdb = + config.noLaterThanCcdbConfig.value == -1 ? std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() : config.noLaterThanCcdbConfig.value; + ccdb->setURL(config.urlCcdb.value); + // enabling object caching (otherwise each call goes to CCDB server) + ccdb->setCaching(true); + // ccdb->setLocalObjectValidityChecking(); + // not later than (avoids replacing objects while a train is running) + ccdb->setCreatedNotAfter(noLaterThanCcdb); + + // variables from other tasks + if (common::core::getTaskOptionValue(initContext, "hadron-photon-producer", "zPvMax", zPvMaxProducer, false)) { + if (std::abs(configHist.binsZPvBinning.value.front() + zPvMaxProducer) > doublePrecisionDeltaCheck || + std::abs(configHist.binsZPvBinning.value.back() - zPvMaxProducer) > doublePrecisionDeltaCheck) { + throw std::runtime_error("binsZPvBinning does not match producer"); + } } - - int nTrigs = 0; - for (const auto& track : tracks) { - if (!jetderiveddatautilities::selectTrack(track, trackSelection)) { - continue; + // variables from other tasks + if (common::core::getTaskOptionValue(initContext, "hadron-photon-producer", "absEtaMax", absEtaMaxProducer, false)) { + if (std::abs(config.absEtaMax.value - absEtaMaxProducer) > doublePrecisionDeltaCheck) { + throw std::runtime_error("absEtaMax does not match producer"); } + } + if (common::core::getTaskOptionValue(initContext, "hadron-photon-producer", "ptTrigMin", ptTrigMinProducer, false)) { + if (std::abs(config.ptTrigMin.value - ptTrigMinProducer) > doublePrecisionDeltaCheck) { + throw std::runtime_error("ptTrigMin does not match producer"); + } + } - if (!initTrig(track)) { - continue; + if (common::core::getTaskOptionValue(initContext, "hadron-photon-pcm-selection", "pcmcut_group.cfgMinEtaV0", cfgMinEtaV0Selection, false) && + common::core::getTaskOptionValue(initContext, "hadron-photon-pcm-selection", "pcmcut_group.cfgMaxEtaV0", cfgMaxEtaV0Selection, false)) { + if (config.absEtaMax.value > std::abs(cfgMinEtaV0Selection) || config.absEtaMax.value > std::abs(cfgMaxEtaV0Selection)) { + throw std::runtime_error("absEtaMax does not constrain v0 cut"); } + } + + // check coherent config - registry.fill(HIST("reconstructed/triggers/hTrigSpectrumReco"), track.pt(), track.eta(), track.phi()); - nTrigs++; + if (std::abs(config.ptTrigMin.value - configHist.binsPtTrig.value.at(0)) > doublePrecisionDeltaCheck) { + throw std::runtime_error("ptTrigMin does not match trigger axis"); + } + if (std::abs(2 * config.absEtaMax.value + configHist.binsDEta.value.front()) > doublePrecisionDeltaCheck || + std::abs(2 * config.absEtaMax.value - configHist.binsDEta.value.back()) > doublePrecisionDeltaCheck) { + throw std::runtime_error("absEtaMax does not match binsDEta axis"); } - registry.fill(HIST("reconstructed/triggers/hTrigMultReco"), nTrigs); - } - PROCESS_SWITCH(HadronPhotonCorrelation, processTrigsReco, "trigger particle properties", true); - /*********************************************** MC ************************************************/ + int const nParTcm = 6; + if (config.applyScalingPhotonPt.value && (config.parScalingPhotonPtData.value.size() != nParTcm || config.parScalingPhotonPtMc.value.size() != nParTcm)) { + throw std::runtime_error("wrong number of mc scaling params for photon"); + } + if (config.applyScalingPi0Pt.value && (config.parScalingPi0PtData.value.size() != nParTcm || config.parScalingPi0PtMc.value.size() != nParTcm)) { + throw std::runtime_error("wrong number of mc scaling params for pi0"); + } + if (config.applyScalingEtaPt.value && (config.parScalingEtaPtData.value.size() != nParTcm || config.parScalingEtaPtMc.value.size() != nParTcm)) { + throw std::runtime_error("wrong number of mc scaling params for eta"); + } - void processTrigsMCReco(JetCollisionMCD const& collision, - JetMcCollisions const&, - Join const& tracks, - JetParticles const&) - { - if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits, false)) { - return; + // doprocess combinations + + if (static_cast(doprocessRecoHadron) + static_cast(doprocessMcRecoHadron) > 1) { + throw std::runtime_error("invalid doprocess-recoHadron config"); } - if (collision.getSubGeneratorId() != subGeneratorIdSelections) { - return; + if (static_cast(doprocessRecoPipm) + static_cast(doprocessMcRecoPipm) > 1) { + throw std::runtime_error("invalid doprocess-recoPipm config"); + } + if (static_cast(doprocessRecoPhotonPcm) + static_cast(doprocessMcRecoPhotonPcm) > 1) { + throw std::runtime_error("invalid doprocess-recoPhotonPcm config"); + } + if (static_cast(doprocessRecoPhotonPcmPair) + static_cast(doprocessMcRecoPhotonPcmPair) > 1) { + throw std::runtime_error("invalid doprocess-recoPhotonPcmPair config"); } - int nTrigs = 0; - for (const auto& track : tracks) { - if (!jetderiveddatautilities::selectTrack(track, trackSelection)) { - continue; - } + // histograms from ccdb + initCcdbHistograms(noLaterThanCcdb); - if (!initTrig(track)) { - continue; + // create analysis histograms + initHistograms(); + + // mixing trigger memory + triggerMemoryReco = std::make_unique(configHist.binsZPvBinning.value, configHist.binsMultBinning.value, + config.nTriggerSavedForMixing.value); + triggerMemoryTrue = std::make_unique(configHist.binsZPvBinningMcTrue.value, configHist.binsMultBinningMcTrue.value, + config.nTriggerSavedForMixing.value); + triggerMemoryTrueRecoEv = std::make_unique(configHist.binsZPvBinningMcTrue.value, configHist.binsMultBinningMcTrue.value, + config.nTriggerSavedForMixing.value); + triggerMemoryTrueRecoEvRecoPtTrig = std::make_unique(configHist.binsZPvBinningMcTrue.value, configHist.binsMultBinningMcTrue.value, + config.nTriggerSavedForMixing.value); + } + + // reco only //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ========================================================================================================================================================================================== + + // correlations ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + + template + void fillAssocsRecoMain(auto histFillInfo, auto const& collision, auto const& associated) + { + if constexpr (AssocTypeV == AssocType::Hadron || AssocTypeV == AssocType::Pipm || AssocTypeV == AssocType::PhotonPcm) { + fillHistMain(histFillInfo); + if constexpr (FillMcRecoInfo) { + fillTruthLevelsMcRecoStd(histFillInfo, collision, associated); } - registry.fill(HIST("reconstructed/triggers/hTrigSpectrumReco"), track.pt(), track.eta(), track.phi(), collision.mcCollision().weight()); - nTrigs++; + } else if constexpr (AssocTypeV == AssocType::PhotonPcmPair) { + fillAssocsRecoPhotonPcmPair(histFillInfo, collision, associated); + if constexpr (FillMcRecoInfo) { + fillAssocsMcRecoPhotonPcmPair(histFillInfo, collision, associated); + } + } else { + static_assert(AlwaysFalseValue, "assocType not found"); } - registry.fill(HIST("reconstructed/triggers/hTrigMultReco"), nTrigs, collision.mcCollision().weight()); } - PROCESS_SWITCH(HadronPhotonCorrelation, processTrigsMCReco, "trigger particle mc properties", true); - void processTrigsMCGen(JetMcCollision const& collision, - JetParticles const& particles) + template + void fillProcessRecoMain(auto const& collisions, auto const& triggers, auto const& assocs, T_AssocConditionMix const& mixConditionAssocOnly = {}) { - if (!initCollisionMC(collision, particles)) { - return; - } + for (auto const& collision : collisions) { + // group collision ++ + auto const triggersThisEvent = triggers.sliceBy(perColTriggers, collision.globalIndex()); + auto const [assocsThisEvent, nMixingAt0] = [&]() { + if constexpr (AssocTypeV == AssocType::Hadron) { + return std::tuple{assocs.sliceBy(perColHadrons, collision.globalIndex()), config.nMixingAt0Hadron.value}; + } else if constexpr (AssocTypeV == AssocType::Pipm) { + return std::tuple{assocs.sliceBy(perColPipms, collision.globalIndex()), config.nMixingAt0Pipm.value}; + } else if constexpr (AssocTypeV == AssocType::PhotonPcm) { + return std::tuple{assocs.sliceBy(perColPhotonPcms, collision.globalIndex()), config.nMixingAt0PhotonPcm.value}; + } else if constexpr (AssocTypeV == AssocType::PhotonPcmPair) { + return std::tuple{assocs.sliceBy(perColPhotonPcmPairs, collision.globalIndex()), config.nMixingAt0PhotonPcmPair.value}; + } else { + static_assert(AlwaysFalseValue, "assocType not supported"); + } + }(); + + auto const funcPlain = [this](auto const& collision, auto const& associated) { + HistFillInfoPlainPhiEtaZPvMult histFillInfo = {collision.ptMax(), associated.pt(), associated.phi(), associated.eta(), + collision.posZ(), static_cast(collision.nGlobalTracks())}; + histFillInfo.weight = getMcAssocPtScaling(associated) * getMcK0ShortPtScaling(associated); + fillAssocsRecoMain(histFillInfo, collision, associated); + }; + corrProcessPlain(collision, assocsThisEvent, funcPlain); + + auto const funcCorrelation = [this](auto const& collision, auto const& trigger, auto const& associated) { + // exclude self correlation + if (isRecoSelfTrigger(trigger, associated)) { + return; + } - int nTrigs = 0; - for (const auto& particle : particles) { - if (!initTrigParticle(particle)) { + HistFillInfoCorr histFillInfo = {getDeltaPhi(trigger.phi(), associated.phi()), trigger.eta() - associated.eta(), + trigger.pt(), associated.pt(), collision.posZ(), static_cast(collision.nGlobalTracks())}; + histFillInfo.weight = getMcAssocPtScaling(associated) * getMcK0ShortPtScaling(associated) * + getTriggerPtCorrection(trigger.pt()); + fillAssocsRecoMain(histFillInfo, collision, associated); + }; + corrProcessCorrelation(collision, triggersThisEvent, assocsThisEvent, funcCorrelation); + + // select mixing events + if (config.doTrigEvMixing.value && !collision.trigEv()) { continue; } - registry.fill(HIST("generated/triggers/hTrigSpectrumGen"), particle.pt(), particle.eta(), particle.phi(), collision.weight()); - nTrigs++; + + auto const funcMixing = [this](auto const& collision, auto const& mixingTrigger, auto const& associated, auto const perTriggerWeight) { + HistFillInfoCorr histFillInfo = {getDeltaPhi(mixingTrigger.phi(), associated.phi()), mixingTrigger.eta() - associated.eta(), + mixingTrigger.pt(), associated.pt(), collision.posZ(), static_cast(collision.nGlobalTracks())}; + histFillInfo.weight = perTriggerWeight * + getMcAssocPtScaling(associated) * getMcK0ShortPtScaling(associated) * + getTriggerPtCorrection(mixingTrigger.pt()); + fillAssocsRecoMain(histFillInfo, collision, associated); + }; + corrProcessMixing(collision, assocsThisEvent, funcMixing, nMixingAt0, mixConditionAssocOnly); } - registry.fill(HIST("generated/triggers/hTrigMultGen"), nTrigs, collision.weight()); } - PROCESS_SWITCH(HadronPhotonCorrelation, processTrigsMCGen, "trigger particle mc properties", true); - /**************************************************************************************************** - ********************************************** PHOTONS ********************************************** - ****************************************************************************************************/ + // standard reco :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - /********************************************** DATA ***********************************************/ - using MyTracks = soa::Join; - Preslice perCol = aod::v0::collisionId; - void processPhotonCorrelations(JetCollision const& collision, - JetTracks const& tracks, - MyTracks const&, - V0Datas const& v0s) + void processRecoHadron(soa::Filtered const& collisions, aod::HpcTriggers const& triggers, aod::HpcHadrons const& hadrons) { - if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits)) { - return; - } + fillProcessRecoMain(collisions, triggers, hadrons); + } + PROCESS_SWITCH(HadronPhotonCorrelation, processRecoHadron, "process standard for associated hadron", false); - int nPhotons = 0; - auto v0PerCollision = v0s.sliceBy(perCol, collision.globalIndex()); - for (const auto& v0 : v0PerCollision) { - if (!initV0(v0)) { - continue; - } - registry.fill(HIST("reconstructed/photons/hPhotonSpectrumReco"), v0.pt(), v0.eta(), v0.phi()); - nPhotons++; + void processRecoPipm(soa::Filtered const& collisions, aod::HpcTriggers const& triggers, aod::HpcPipms const& pipms) + { + fillProcessRecoMain(collisions, triggers, pipms); + } + PROCESS_SWITCH(HadronPhotonCorrelation, processRecoPipm, "process standard for associated pipm", false); - for (const auto& track : tracks) { - if (!jetderiveddatautilities::selectTrack(track, trackSelection)) { - continue; - } + void processRecoPhotonPcm(soa::Filtered const& collisions, aod::HpcTriggers const& triggers, soa::Filtered const& photonPcms, + aod::V0PhotonsKF const&, aod::V0Legs const&) + { + fillProcessRecoMain(collisions, triggers, photonPcms); + } + PROCESS_SWITCH(HadronPhotonCorrelation, processRecoPhotonPcm, "process standard for associated photonPcm", false); - if (!initTrig(track)) { - continue; - } - float dphi = RecoDecay::constrainAngle(v0.phi() - track.phi(), -PIHalf); - registry.fill(HIST("reconstructed/photons/hPhotonCorrelReco"), track.pt(), v0.pt(), v0.eta() - track.eta(), dphi); - } + // photonPcmPair reco ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + bool fillConditionRecoPhotonPcmPairMix(auto const& associated) + { + // pi0 + if (isInMassRange(associated.mgg()) || isInMassRange(associated.mgg())) { + return true; } - registry.fill(HIST("reconstructed/photons/hPhotonMultReco"), nPhotons); + // eta + if (isInMassRange(associated.mgg()) || isInMassRange(associated.mgg())) { + return true; + } + return false; } - PROCESS_SWITCH(HadronPhotonCorrelation, processPhotonCorrelations, "hadron-photon correlation", true); - /*********************************************** MC ************************************************/ - - using MyTracksMC = soa::Join; - void processPhotonCorrelationsMCReco(Join::iterator const& collision_reco, - JetMcCollisions const&, - JetTracks const& tracks_reco, - JetParticles const&, - MyTracksMC const&, - V0Datas const& v0s) + template + void fillAssocsRecoPhotonPcmPair(auto const& histFillInfo, auto const& collision, auto const& associated) { - if (!jetderiveddatautilities::selectCollision(collision_reco, eventSelectionBits, false)) { + // mgg distribution + if constexpr (HistFillModeV == HistFillMode::Plain) { + histos.fill(HIST("reco/plain/h5_ptTrigPtAssocMggZPvMult_reco_photonPcmPair"), + histFillInfo.ptMax, histFillInfo.ptAssoc, associated.mgg(), collision.posZ(), collision.nGlobalTracks(), + histFillInfo.weight); + } else if constexpr (HistFillModeV == HistFillMode::Correlation) { + histos.fill(HIST("reco/corr/h5_ptTrigPtAssocMggZPvMult_reco_photonPcmPair"), + histFillInfo.ptTrig, histFillInfo.ptAssoc, associated.mgg(), collision.posZ(), collision.nGlobalTracks(), + histFillInfo.weight); + } + + // pi0 + if (isInMassRange(associated.mgg())) { + fillHistMain(histFillInfo); return; } - if (collision_reco.mcCollision().getSubGeneratorId() != subGeneratorIdSelections) { + if (isInMassRange(associated.mgg())) { + fillHistMain(histFillInfo); return; } + // eta + if (isInMassRange(associated.mgg())) { + fillHistMain(histFillInfo); + return; + } + if (isInMassRange(associated.mgg())) { + fillHistMain(histFillInfo); + return; + } + } - int nPhotons = 0; - - auto v0PerCollision = v0s.sliceBy(perCol, collision_reco.globalIndex()); - for (const auto& v0 : v0PerCollision) { - if (!initV0(v0)) { - continue; - } - registry.fill(HIST("reconstructed/photons/hPhotonSpectrumReco"), v0.pt(), v0.eta(), v0.phi(), collision_reco.mcCollision().weight()); - nPhotons++; + void processRecoPhotonPcmPair(soa::Filtered const& collisions, aod::HpcTriggers const& triggers, soa::Filtered const& photonPcmPairs, + aod::V0PhotonsKF const&, aod::V0Legs const&) + { + fillProcessRecoMain(collisions, triggers, photonPcmPairs, + [this](auto const& associated) { return fillConditionRecoPhotonPcmPairMix(associated); }); + } + PROCESS_SWITCH(HadronPhotonCorrelation, processRecoPhotonPcmPair, "process standard for associated photonPcmPair", false); - for (const auto& track : tracks_reco) { - if (!jetderiveddatautilities::selectTrack(track, trackSelection)) { + void processPhotonPcmPairMix(soa::Filtered const& collisions, soa::Filtered const& photonPcms) + { + BinningZPvMult const binningZPvMult{{prependVariableWidth(configHist.binsZPvBinning.value), prependVariableWidth(configHist.binsMultBinning.value)}, true}; + auto photonPcmsTuple = std::make_tuple(photonPcms); + SameKindPair, soa::Filtered, BinningZPvMult> pairs{binningZPvMult, config.nNeighboursMixingPhotonPcmPair.value, -1, + collisions, photonPcmsTuple, &cache}; + + // mixed events + for (auto pair = pairs.begin(); pair != pairs.end(); pair++) { + auto const& [collision1, photonPcms1, collision2, photonPcms2] = *pair; + // mixing loop + for (auto const& [photonPcm1, photonPcm2] : soa::combinations(soa::CombinationsFullIndexPolicy(photonPcms1, photonPcms2))) { + ROOT::Math::PtEtaPhiMVector const p4photonPcm1(photonPcm1.pt(), photonPcm1.eta(), photonPcm1.phi(), 0.); + ROOT::Math::PtEtaPhiMVector const p4photonPcm2(photonPcm2.pt(), photonPcm2.eta(), photonPcm2.phi(), 0.); + ROOT::Math::PtEtaPhiMVector const p4photonPcmPair = p4photonPcm1 + p4photonPcm2; + + if (std::abs(p4photonPcmPair.eta()) > config.absEtaMax.value) { continue; } - - if (!initTrig(track)) { + // reco assoc selection + if (HadronPhotonPcmSelection::getEnergyAsymDiPhoton(photonPcm1, photonPcm2) > config.energyAsymmPhotonPairMax.value) { continue; } - float dphi = RecoDecay::constrainAngle(v0.phi() - track.phi(), -PIHalf); - registry.fill(HIST("reconstructed/photons/hPhotonCorrelReco"), track.pt(), v0.pt(), v0.eta() - track.eta(), dphi, collision_reco.mcCollision().weight()); + + histos.fill(HIST("reco/plain/h4_ptMggZPvMult_reco_photonPcmPair_evMix"), + p4photonPcmPair.pt(), p4photonPcmPair.M(), collision1.posZ(), collision1.nGlobalTracks()); } } - registry.fill(HIST("reconstructed/photons/hPhotonMultReco"), nPhotons, collision_reco.mcCollision().weight()); } - PROCESS_SWITCH(HadronPhotonCorrelation, processPhotonCorrelationsMCReco, "hadron-photon correlation", true); + PROCESS_SWITCH(HadronPhotonCorrelation, processPhotonPcmPairMix, "process gamma-gamma mixing for photonPcm", false); + + // other //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - void processPhotonCorrelationsMCGen(JetMcCollision const& collision, - JetParticles const& tracks_true) + void processPcmDcaZ(soa::Filtered::iterator const& collision, soa::Filtered const& photonPcms, + aod::V0PhotonsKF const&, aod::V0Legs const&) { - if (!initCollisionMC(collision, tracks_true)) { - return; + for (auto const& photonPcm : photonPcms) { + double const weight = getMcAssocPtScaling(photonPcm) * getMcK0ShortPtScaling(photonPcm); + + histos.fill(HIST("reco/plain/h5_ptTrigPtAssocDcaZZPvMult_photonPcm"), + collision.ptMax(), photonPcm.pt(), photonPcm.v0PhotonKF().dcaZtopv(), collision.posZ(), collision.nGlobalTracks(), + weight); } + } + PROCESS_SWITCH(HadronPhotonCorrelation, processPcmDcaZ, "process to test dcaZ distribution of photons", false); - int nPhotons = 0; - for (const auto& track_assoc : tracks_true) { - if (!initParticle(track_assoc, false)) { - continue; - } - if (std::abs(track_assoc.pdgCode()) != kGamma) { - continue; - } - if (!track_assoc.isPhysicalPrimary() && track_assoc.getGenStatusCode() < 0) { - continue; - } + // MC /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ========================================================================================================================================================================================== - // Iterate through mother particles until original mother is reached - auto origPhoton = track_assoc; - auto mother = track_assoc.mothers_as().at(0); - while (mother.pdgCode() == kGamma) { - origPhoton = mother; - mother = mother.mothers_as().at(0); - } + // correlations ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - auto pdgMother = pdg->GetParticle(mother.pdgCode()); - if (!pdgMother) { - continue; - } - int photonGeneration; - switch (std::abs(origPhoton.getGenStatusCode())) { - case 23: // prompt direct photons - case 33: - photonGeneration = -2; - break; - case 43: // shower photons - case 44: - case 51: - case 52: - photonGeneration = -1; - break; - case 91: // decay photons - photonGeneration = pidCodes[pdgMother->GetName()]; - break; + // mc true++ :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + bool fillConditionMcTrueBasic(auto const& assocParticle) + { + if (std::abs(assocParticle.eta()) > config.absEtaMax.value) { + return false; + } + if (assocParticle.isPhysicalPrimary()) { + return true; + } + if (isDecayPrimary(assocParticle)) { + switch (assocParticle.pdgCode()) { + case PDG_t::kPi0: + return true; + case constants::physics::Pdg::kEta: + return true; + case constants::physics::Pdg::kOmega: + return true; + case constants::physics::Pdg::kEtaPrime: + return true; default: - photonGeneration = -3; - break; + return false; } + } + return false; + } - registry.fill(HIST("generated/photons/hPhotonSpectrumGen"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), photonGeneration, collision.weight()); - - nPhotons++; + template + void fillPi0EtaMcTrue(auto& histFillInfo, auto const& assocParticle, auto const& isDecaySelfTrig) + { + // mc-to-data scaling + histFillInfo.weight *= getMcAssocPtScalingFromPt(assocParticle.pt()); - for (const auto& track_trig : tracks_true) { - if (!initTrigParticle(track_trig)) { - continue; - } - float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); - registry.fill(HIST("generated/photons/hPhotonCorrelGen"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi, photonGeneration, collision.weight()); + if constexpr (TruthLevelV == TruthLevel::True) { + fillHistMain(histFillInfo); + } + // self trigger + if constexpr (HistFillModeV == HistFillMode::Plain) { + if (isDecaySelfTrig(AssocTypeV)) { + return; + } + } else if constexpr (HistFillModeV == HistFillMode::Correlation) { + if (isDecaySelfTrig()) { + return; + } + } else if constexpr (HistFillModeV == HistFillMode::Mixing) { + } else { + static_assert(AlwaysFalseValue, "histFillMode not found"); + } + fillHistMain(histFillInfo); + // decaying particles extra info + if constexpr (TruthLevelV == TruthLevel::TrueRecoEvRecoPtTrig) { + // chosen decay + if (!isDecayToGG(assocParticle)) { + return; + } + fillHistMain(histFillInfo); + // daughters in acceptance + if (!checkDaughtersInAcceptance(assocParticle, {-config.absEtaMax.value, config.absEtaMax.value})) { + return; } + fillHistMain(histFillInfo); } - - registry.fill(HIST("generated/photons/hPhotonMultGen"), nPhotons, collision.weight()); } - PROCESS_SWITCH(HadronPhotonCorrelation, processPhotonCorrelationsMCGen, "mc hadron-photon correlation", true); - - /**************************************************************************************************** - ***************************************** HADRONS *************************************************** - ****************************************************************************************************/ - /********************************************** DATA ***********************************************/ - void processHadronCorrelations(JetCollision const& collision, - Join const& tracks) + template + void fillAssocsMcTrue(auto histFillInfo, auto const& assocParticle, T_DecaySelfTrigFunc const& isDecaySelfTrig = {}) { - if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits)) { + // main eta cut + if (std::abs(assocParticle.eta()) > config.absEtaMax.value) { return; } - int nHadrons = 0; - for (const auto& track_assoc : tracks) { - if (!jetderiveddatautilities::selectTrack(track_assoc, trackSelection)) { - continue; + // standard particles (marked physical primary) + if (assocParticle.isPhysicalPrimary()) { + // hadron (charged primary) + if (isCharged(assocParticle)) { + fillHistMain(histFillInfo); } - - if (!initTrack(track_assoc)) { - continue; + // pipm + if (std::abs(assocParticle.pdgCode()) == PDG_t::kPiPlus) { + fillHistMain(histFillInfo); + return; } - registry.fill(HIST("reconstructed/hadrons/hHadronSpectrumReco"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi()); - nHadrons++; - - for (const auto& track_trig : tracks) { - if (!jetderiveddatautilities::selectTrack(track_trig, trackSelection)) { - continue; - } - if (track_trig == track_assoc) { - continue; - } - if (!initTrig(track_trig)) { - continue; + // photon + if (assocParticle.pdgCode() == PDG_t::kGamma) { + // mc-to-data scaling + histFillInfo.weight *= getMcAssocPtScalingFromPt(assocParticle.pt()); + + fillHistMain(histFillInfo); + + // extra info for decay correlation only for total true level + if constexpr (TruthLevelV == TruthLevel::True) { + // decay and direct + int const statusDecayLow = 91; + int const statusDecayUp = 99; + int const statusDirect = 62; + + if (std::abs(assocParticle.getGenStatusCode()) >= statusDecayLow && std::abs(assocParticle.getGenStatusCode()) <= statusDecayUp) { + fillHistMain(histFillInfo); + // decays from different mothers + int const pdgMother = assocParticle.template mothers_as().begin()->pdgCode(); + switch (pdgMother) { + case PDG_t::kPi0: + fillHistMain(histFillInfo); + break; + case constants::physics::Pdg::kEta: + fillHistMain(histFillInfo); + break; + case constants::physics::Pdg::kOmega: + fillHistMain(histFillInfo); + break; + case constants::physics::Pdg::kEtaPrime: + fillHistMain(histFillInfo); + break; + default: + fillHistMain(histFillInfo); + break; + } + } else { + fillHistMain(histFillInfo); + // log unexpected status + if (assocParticle.getGenStatusCode() != statusDirect) { + histos.fill(HIST("mc/info/h1_unusualStatus_photonDirect"), assocParticle.getGenStatusCode()); + } + } } - float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); - registry.fill(HIST("reconstructed/hadrons/hHadronCorrelReco"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi); + return; } + return; } - registry.fill(HIST("reconstructed/hadrons/hHadronMultReco"), nHadrons); - } - PROCESS_SWITCH(HadronPhotonCorrelation, processHadronCorrelations, "hadron-hadron correlation", true); - - /*********************************************** MC ************************************************/ - - void processHadronCorrelationsMCGen(JetMcCollision const& collision, - JetParticles const& tracks_true) - { - if (!initCollisionMC(collision, tracks_true)) { + // decaying particles (not marked physical primary) + if (!isDecayPrimary(assocParticle)) { + return; + } + // pi0 + if (assocParticle.pdgCode() == PDG_t::kPi0) { + fillPi0EtaMcTrue(histFillInfo, assocParticle, isDecaySelfTrig); + return; + } + // eta + if (assocParticle.pdgCode() == constants::physics::Pdg::kEta) { + fillPi0EtaMcTrue(histFillInfo, assocParticle, isDecaySelfTrig); return; } - int nHadrons = 0; - for (const auto& track_assoc : tracks_true) { - if (!initParticle(track_assoc)) { - continue; + // extra info for decay correlation only for total true level + if constexpr (TruthLevelV == TruthLevel::True) { + // omega + if (assocParticle.pdgCode() == constants::physics::Pdg::kOmega) { + fillHistMain(histFillInfo); + return; } - auto pdgParticle = pdg->GetParticle(track_assoc.pdgCode()); - if (!pdgParticle || pdgParticle->Charge() == 0.) { - continue; - } - if (std::abs(track_assoc.pdgCode()) < pidCodeHadronCut) { - continue; + // etaPrime + if (assocParticle.pdgCode() == constants::physics::Pdg::kEtaPrime) { + fillHistMain(histFillInfo); + return; } + } + } - registry.fill(HIST("generated/hadrons/hHadronSpectrumGen"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), collision.weight()); - nHadrons++; - - for (const auto& track_trig : tracks_true) { - if (!initTrigParticle(track_trig)) { + template + void fillProcessMcTrueTrig(auto const& collisions, auto const& trueTriggers, auto const& mcParticles) + { + for (auto const& collision : collisions) { + if constexpr (TruthLevelV == TruthLevel::TrueRecoEv) { + if (!isMcMatchedCollision(collision)) { continue; } - if (track_trig == track_assoc) { - continue; + } + auto const& mcCollision = [&]() { + if constexpr (TruthLevelV == TruthLevel::True) { + return collision; + } else if constexpr (TruthLevelV == TruthLevel::TrueRecoEv) { + return collision.template jetMcCollision_as>(); + } else { + static_assert(AlwaysFalseValue, "truthLevel not found"); + } + }(); + + // group collision + auto const trueTriggersThisEvent = trueTriggers.sliceBy(perColTrueTriggers, mcCollision.globalIndex()); + auto const mcParticlesThisEvent = mcParticles.sliceBy(perColMcParticles, mcCollision.globalIndex()); + + // self correlation of events (plain) + std::map const decaySelfTrigPlainMap = getDecaySelfTrigPlainMap(trueTriggersThisEvent); + + auto const funcPlain = [this, &decaySelfTrigPlainMap](auto const& mcCollision, auto const& assocParticle) { + // self trigger info for decaying particles + auto const isDecaySelfTrig = [&decaySelfTrigPlainMap](AssocType const assocType) { + return decaySelfTrigPlainMap.at(assocType); + }; + HistFillInfoPlainPhiEtaZPvMult histFillInfo = {mcCollision.ptMax(), assocParticle.pt(), assocParticle.phi(), assocParticle.eta(), + mcCollision.posZ(), static_cast(mcCollision.nChargedInEtaRange())}; + fillAssocsMcTrue(histFillInfo, assocParticle, isDecaySelfTrig); + }; + corrProcessPlain(mcCollision, mcParticlesThisEvent, funcPlain); + + auto const funcCorrelation = [this](auto const& mcCollision, auto const& trueTrigger, auto const& assocParticle) { + auto const& triggerParticle = trueTrigger.jetMcParticle(); + // self trigger info for decaying particles + auto const isDecaySelfTrig = [this, &assocParticle, &triggerParticle]() { + return producesTrigger(assocParticle, triggerParticle); + }; + // exclude self correlation + if (trueTrigger.jetMcParticleId() == assocParticle.globalIndex()) { + return; } - float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); - registry.fill(HIST("generated/hadrons/hHadronCorrelGen"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi, collision.weight()); + HistFillInfoCorr histFillInfo = {getDeltaPhi(trueTrigger.phi(), assocParticle.phi()), trueTrigger.eta() - assocParticle.eta(), + trueTrigger.pt(), assocParticle.pt(), mcCollision.posZ(), static_cast(mcCollision.nChargedInEtaRange())}; + fillAssocsMcTrue(histFillInfo, assocParticle, isDecaySelfTrig); + }; + corrProcessCorrelation(mcCollision, trueTriggersThisEvent, mcParticlesThisEvent, funcCorrelation); + + // select mixing events + if (config.doTrigEvMixing.value && !mcCollision.trigEv()) { + continue; } + + auto const funcMixing = [this](auto const& mcCollision, auto const& mixingTrigger, auto const& assocParticle, auto const perTriggerWeight) { + HistFillInfoCorr histFillInfo = {getDeltaPhi(mixingTrigger.phi(), assocParticle.phi()), mixingTrigger.eta() - assocParticle.eta(), + mixingTrigger.pt(), assocParticle.pt(), mcCollision.posZ(), static_cast(mcCollision.nChargedInEtaRange())}; + histFillInfo.weight = perTriggerWeight; + fillAssocsMcTrue(histFillInfo, assocParticle); + }; + corrProcessMixing(mcCollision, mcParticlesThisEvent, funcMixing, config.nMixingAt0McTrue.value, + [this](auto const& assocParticle) { return fillConditionMcTrueBasic(assocParticle); }); } - registry.fill(HIST("generated/hadrons/hHadronMultGen"), nHadrons, collision.weight()); } - PROCESS_SWITCH(HadronPhotonCorrelation, processHadronCorrelationsMCGen, "mc hadron-hadron correlation", true); - void processHadronCorrelationsMCReco(JetCollisionMCD const& collision_reco, - JetMcCollisions const&, - JetTracksMCD const& tracks_reco, - JetParticles const&) + void processMcTrue(soa::Filtered const& mcCollisions, aod::HpcTrueTriggers const& trueTriggers, aod::JetParticles const& mcParticles) { - if (!jetderiveddatautilities::selectCollision(collision_reco, eventSelectionBits, false)) { - return; - } - if (collision_reco.mcCollision().getSubGeneratorId() != subGeneratorIdSelections) { - return; - } + fillProcessMcTrueTrig(mcCollisions, trueTriggers, mcParticles); + } + PROCESS_SWITCH(HadronPhotonCorrelation, processMcTrue, "process mc-true (all collisions) for multiple associated particles", false); - int nHadrons = 0; - for (const auto& track_assoc : tracks_reco) { - if (!jetderiveddatautilities::selectTrack(track_assoc, trackSelection)) { - continue; - } + void processMcTrueRecoEv(soa::Filtered const& collisions, + soa::Filtered const&, aod::HpcTrueTriggers const& trueTriggers, aod::JetParticles const& mcParticles) + { + fillProcessMcTrueTrig(collisions, trueTriggers, mcParticles); + } + PROCESS_SWITCH(HadronPhotonCorrelation, processMcTrueRecoEv, "process mc-true (reco collisions) correlation for multiple associated particles", false); - if (!initTrack(track_assoc)) { - continue; - } - auto particle = track_assoc.mcParticle(); - auto pdgParticle = pdg->GetParticle(particle.pdgCode()); - if (!pdgParticle || pdgParticle->Charge() == 0.) { - continue; - } - if (std::abs(particle.pdgCode()) < pidCodeHadronCut) { + void processMcTrueRecoEvRecoPtTrig(soa::Filtered const& collisions, soa::Join const& triggers, aod::JetTracksMCD const&, + soa::Filtered const&, aod::JetParticles const& mcParticles) + { + for (auto const& collision : collisions) { + if (!isMcMatchedCollision(collision)) { continue; } - registry.fill(HIST("reconstructed/hadrons/hHadronSpectrumReco"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), collision_reco.mcCollision().weight()); - - if (particle.isPhysicalPrimary()) { - registry.fill(HIST("reconstructed/hadrons/hHadronPtPrimReco"), track_assoc.pt(), collision_reco.mcCollision().weight()); - } else { - registry.fill(HIST("reconstructed/hadrons/hHadronPtSecReco"), track_assoc.pt(), collision_reco.mcCollision().weight()); - } - nHadrons++; - - for (const auto& track_trig : tracks_reco) { - if (!jetderiveddatautilities::selectTrack(track_trig, trackSelection)) { - continue; + auto const& mcCollision = collision.jetMcCollision_as>(); + + // group collision + auto const triggersThisEvent = triggers.sliceBy(perColTriggers, collision.globalIndex()); + auto const mcParticlesThisEvent = mcParticles.sliceBy(perColMcParticles, collision.jetMcCollisionId()); + + // self correlation of events (plain) + std::map const decaySelfTrigPlainMap = getDecaySelfTrigPlainMap(triggersThisEvent); + + auto const funcPlain = [this, &decaySelfTrigPlainMap](auto const& collision, auto const& assocParticle) { + auto const& mcCollision = collision.template jetMcCollision_as>(); + // self trigger info for decaying particles + auto const isDecaySelfTrig = [&decaySelfTrigPlainMap](AssocType const assocType) { + return decaySelfTrigPlainMap.at(assocType); + }; + HistFillInfoPlainPhiEtaZPvMult histFillInfo = {collision.ptMax(), assocParticle.pt(), assocParticle.phi(), assocParticle.eta(), + mcCollision.posZ(), static_cast(mcCollision.nChargedInEtaRange())}; + fillAssocsMcTrue(histFillInfo, assocParticle, isDecaySelfTrig); + }; + corrProcessPlain(collision, mcParticlesThisEvent, funcPlain); + + auto const funcCorrelation = [this](auto const& mcCollision, auto const& trigger, auto const& assocParticle) { + if (!isMcMatchedTrigger(trigger)) { + return; } - if (track_trig == track_assoc) { - continue; + auto const& triggerParticle = trigger.template jetTrack_as().mcParticle(); + // self trigger info for decaying particles + auto const isDecaySelfTrig = [this, &assocParticle, &triggerParticle]() { + return producesTrigger(assocParticle, triggerParticle); + }; + // exclude self correlation + if (triggerParticle.globalIndex() == assocParticle.globalIndex()) { + return; } - if (!initTrig(track_trig)) { - continue; + // match reco self-correlation exclusions + // trigger from conversion leg of the photon (pi0,eta legs handled implicily in isDecaySelfTrig) + if (assocParticle.pdgCode() == PDG_t::kGamma && + triggerParticle.has_mothers() && triggerParticle.mothersIds().front() == assocParticle.globalIndex() && + triggerParticle.getProcess() == TMCProcess::kPPair) { + return; } - float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); - registry.fill(HIST("reconstructed/hadrons/hHadronCorrelReco"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi, collision_reco.mcCollision().weight()); + HistFillInfoCorr histFillInfo = {getDeltaPhi(triggerParticle.phi(), assocParticle.phi()), triggerParticle.eta() - assocParticle.eta(), + trigger.pt(), assocParticle.pt(), mcCollision.posZ(), static_cast(mcCollision.nChargedInEtaRange())}; + fillAssocsMcTrue(histFillInfo, assocParticle, isDecaySelfTrig); + }; + corrProcessCorrelation(mcCollision, triggersThisEvent, mcParticlesThisEvent, funcCorrelation); + + // select mixing events + if (config.doTrigEvMixing.value && !collision.trigEv()) { + continue; } + + auto const funcMixing = [this](auto const& mcCollision, auto const& mixingTrigger, auto const& assocParticle, auto const perTriggerWeight) { + HistFillInfoCorr histFillInfo = {getDeltaPhi(mixingTrigger.phi(), assocParticle.phi()), mixingTrigger.eta() - assocParticle.eta(), + mixingTrigger.pt(), assocParticle.pt(), mcCollision.posZ(), static_cast(mcCollision.nChargedInEtaRange())}; + histFillInfo.weight = perTriggerWeight; + fillAssocsMcTrue(histFillInfo, assocParticle, []() { return false; }); + }; + corrProcessMixing(mcCollision, mcParticlesThisEvent, funcMixing, config.nMixingAt0McTrue.value, + [this](auto const& assocParticle) { return fillConditionMcTrueBasic(assocParticle); }); } - registry.fill(HIST("reconstructed/hadrons/hHadronMultReco"), nHadrons, collision_reco.mcCollision().weight()); } - PROCESS_SWITCH(HadronPhotonCorrelation, processHadronCorrelationsMCReco, "mc hadron-hadron correlation", true); + PROCESS_SWITCH(HadronPhotonCorrelation, processMcTrueRecoEvRecoPtTrig, "process mc-true (reco collisions with reco ptTrig) correlation for multiple associated particles", false); - /**************************************************************************************************** - *************************************** CHARGED PIONS *********************************************** - ****************************************************************************************************/ + // standard mc reco++ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - /********************************************** DATA ***********************************************/ - void processPionCorrelations(JetCollision const& collision, - Join const& tracks) + template + void fillTruthLevelsMcRecoStd(auto histFillInfo, auto const& collision, auto const& associated) { - if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits)) { + // photon impurity + if constexpr (HistFillModeV == HistFillMode::Plain && AssocTypeV == AssocType::PhotonPcm) { + PhotonImpurity const impurity = static_cast(associated.impurityPhotonPcm()); + histos.fill(HIST("mc/plain/h3_ptTrigPtAssocCategory_recoImpurities_photonPcm"), + collision.ptMax(), associated.pt(), binValuePhotonImpurity(impurity), + histFillInfo.weight); + } + // collision association + if (!checkTruthLevelReco(associated)) { return; } + fillHistMain(histFillInfo); + // purity + if (!checkTruthLevelReco(associated)) { + return; + } + fillHistMain(histFillInfo); + // true ptAssoc + histFillInfo.ptAssoc = associated.ptTruePure(); + fillHistMain(histFillInfo); + } - int nPions = 0; - for (const auto& track_assoc : tracks) { - if (!jetderiveddatautilities::selectTrack(track_assoc, trackSelection)) { - continue; - } + void processMcRecoHadron(soa::Filtered const& collisions, aod::HpcTriggers const& triggers, aod::HpcHadrons const& hadrons) + { + fillProcessRecoMain(collisions, triggers, hadrons); + } + PROCESS_SWITCH(HadronPhotonCorrelation, processMcRecoHadron, "process standard for associated hadron with additional mc information", false); - if (!initTrack(track_assoc)) { - continue; - } - if (std::abs(track_assoc.tpcNSigmaPi()) > tpcNSigmaPi) { - continue; - } // remove non-pions - registry.fill(HIST("reconstructed/charged/hPionSpectrumReco"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi()); - nPions++; + void processMcRecoPipm(soa::Filtered const& collisions, aod::HpcTriggers const& triggers, aod::HpcPipms const& pipms) + { + fillProcessRecoMain(collisions, triggers, pipms); + } + PROCESS_SWITCH(HadronPhotonCorrelation, processMcRecoPipm, "process standard for associated pipm with additional mc information", false); - for (const auto& track_trig : tracks) { - if (!jetderiveddatautilities::selectTrack(track_trig, trackSelection)) { - continue; - } - if (track_trig == track_assoc) { - continue; - } - if (!initTrig(track_trig)) { - continue; - } - float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); - registry.fill(HIST("reconstructed/charged/hPionCorrelReco"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi); - } - } - registry.fill(HIST("reconstructed/charged/hPionMultReco"), nPions); + void processMcRecoPhotonPcm(soa::Filtered const& collisions, aod::HpcTriggers const& triggers, soa::Filtered const& photonPcms, + aod::V0PhotonsKF const&, aod::V0Legs const&) + { + fillProcessRecoMain(collisions, triggers, photonPcms); } - PROCESS_SWITCH(HadronPhotonCorrelation, processPionCorrelations, "hadron-pion correlation", true); + PROCESS_SWITCH(HadronPhotonCorrelation, processMcRecoPhotonPcm, "process standard for associated photonPcm with additional mc information", false); - /*********************************************** MC ************************************************/ + // photonPcmPair mc reco++ :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - void processPionCorrelationsMCGen(JetMcCollision const& collision, - JetParticles const& tracks_true) + template + void fillTruthLevelsMcRecoPhotonPcmPair(auto histFillInfo, auto const& collision, auto const& associated) { - if (!initCollisionMC(collision, tracks_true)) { + // pi0 impurity + if constexpr (HistFillModeV == HistFillMode::Plain && AssocTypeV == AssocType::Pi0Pcm) { + PhotonImpurity const impurity = static_cast(associated.impurityPi0Pcm()); + histos.fill(HIST("mc/plain/h3_ptTrigPtAssocCategory_pseudoRecoImpurities_pi0Pcm"), + collision.ptMax(), associated.pt(), binValuePhotonImpurity(impurity), + histFillInfo.weight); + } + // collision association + if (!checkTruthLevelReco(associated)) { return; } + fillHistMain(histFillInfo); + // purity + if (!checkTruthLevelReco(associated)) { + return; + } + fillHistMain(histFillInfo); + // true ptAssoc + histFillInfo.ptAssoc = associated.ptTruePure(); + fillHistMain(histFillInfo); + } - int nPions = 0; - for (const auto& track_assoc : tracks_true) { - if (!initParticle(track_assoc)) { - continue; - } - if (std::abs(track_assoc.pdgCode()) != kPiPlus) { - continue; + template + void fillAssocsMcRecoPhotonPcmPair(auto histFillInfo, auto const& collision, auto const& associated) + { + // pi0Pcm pseudo yield + if (checkTruthLevelReco(associated)) { + // mgg distribution + if constexpr (HistFillModeV == HistFillMode::Plain) { + histos.fill(HIST("mc/plain/h5_ptTrigPtAssocMggZPvMult_pseudoReco_pi0Pcm"), + histFillInfo.ptMax, histFillInfo.ptAssoc, associated.mgg(), collision.posZ(), collision.nGlobalTracks(), + histFillInfo.weight); + } else if constexpr (HistFillModeV == HistFillMode::Correlation) { + histos.fill(HIST("mc/corr/h5_ptTrigPtAssocMggZPvMult_pseudoReco_pi0Pcm"), + histFillInfo.ptTrig, histFillInfo.ptAssoc, associated.mgg(), collision.posZ(), collision.nGlobalTracks(), + histFillInfo.weight); } - registry.fill(HIST("generated/charged/hPionSpectrumGen"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), collision.weight()); - nPions++; - - // Get correlations - for (const auto& track_trig : tracks_true) { - if (!initTrigParticle(track_trig)) { - continue; - } - if (track_trig == track_assoc) { - continue; - } - float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); - - registry.fill(HIST("generated/charged/hPionCorrelGen"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi, collision.weight()); + fillHistMain(histFillInfo); + fillTruthLevelsMcRecoPhotonPcmPair(histFillInfo, collision, associated); + return; + } + // etaPcm pseudo yield + if (checkTruthLevelReco(associated)) { + // mgg distribution + if constexpr (HistFillModeV == HistFillMode::Plain) { + histos.fill(HIST("mc/plain/h5_ptTrigPtAssocMggZPvMult_pseudoReco_etaPcm"), + histFillInfo.ptMax, histFillInfo.ptAssoc, associated.mgg(), collision.posZ(), collision.nGlobalTracks(), + histFillInfo.weight); + } else if constexpr (HistFillModeV == HistFillMode::Correlation) { + histos.fill(HIST("mc/corr/h5_ptTrigPtAssocMggZPvMult_pseudoReco_etaPcm"), + histFillInfo.ptTrig, histFillInfo.ptAssoc, associated.mgg(), collision.posZ(), collision.nGlobalTracks(), + histFillInfo.weight); } - // Use PYTHIA to simulate decay - /*decayer->Init(); - for (int pid = 1; pid <= nHadrons; pid++) { - TParticlePDG* pdgParticle = nullptr; + fillHistMain(histFillInfo); + fillTruthLevelsMcRecoPhotonPcmPair(histFillInfo, collision, associated); + return; + } + } - auto it = pidToPdg.find(pid); - if (it != pidToPdg.end()) { - pdgParticle = pdg->GetParticle(it->second); - } else { - continue; - } + void processMcRecoPhotonPcmPair(soa::Filtered const& collisions, aod::HpcTriggers const& triggers, soa::Filtered const& photonPcmPairs, + aod::V0PhotonsKF const&, aod::V0Legs const&) + { + fillProcessRecoMain(collisions, triggers, photonPcmPairs); + } + PROCESS_SWITCH(HadronPhotonCorrelation, processMcRecoPhotonPcmPair, "process correlation for associated photonPcmPair with additional mc information", false); - motherLV->SetPtEtaPhiM(track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), pdgParticle->Mass()); - decayer->Decay(pdgParticle->PdgCode(), motherLV); - decayer->ImportParticles(decayParticles); - for (int i = 0; i < decayParticles->GetEntriesFast(); ++i) { - TParticle* daughter = static_cast(decayParticles->At(i)); + // other //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - if (!initDecayParticle(daughter)) { - continue; - } + void processPcmDcaZTrue(soa::Filtered::iterator const& collision, soa::Filtered> const& photonPcms, + aod::V0PhotonsKF const&, aod::V0Legs const&, aod::JetTracksMCD const&, soa::Filtered const&, aod::JetParticles const&) + { + for (auto const& photonPcm : photonPcms) { + if (!checkTruthLevelReco(photonPcm)) { + continue; + } + // check mc + auto const& posTrack = photonPcm.posJetTrack_as(); + auto const& negTrack = photonPcm.negJetTrack_as(); + // collision association + if (posTrack.mcParticle().mcCollisionId() != collision.jetMcCollisionId() || negTrack.mcParticle().mcCollisionId() != collision.jetMcCollisionId()) { + continue; + } - registry.fill(HIST("generated/charged/hCocktailPhotonSpectrumGen"), track_assoc.pt(), daughter->Pt(), daughter->Eta(), daughter->Phi(), pidCodes[pdgParticle->GetName()], collision.weight()); + double const weight = getMcAssocPtScaling(photonPcm) * getMcK0ShortPtScaling(photonPcm); - for (const auto& track_trig : tracks_true) { - if (!initTrigParticle(track_trig)) { - continue; - } - if (track_trig == track_assoc) { - continue; - } - float dphi = RecoDecay::constrainAngle(daughter->Phi() - track_trig.phi(), -PIHalf); - registry.fill(HIST("generated/charged/hCocktailPhotonCorrelGen"), track_trig.pt(), track_assoc.pt(), daughter->Pt(), daughter->Eta() - track_trig.eta(), dphi, pidCodes[pdgParticle->GetName()], collision.weight()); - } - } - }*/ + histos.fill(HIST("mc/plain/h5_ptTrigPtAssocDcaZZPvMult_photonPcm"), + collision.ptMax(), photonPcm.pt(), photonPcm.v0PhotonKF().dcaZtopv(), collision.posZ(), collision.nGlobalTracks(), + weight); } - registry.fill(HIST("generated/charged/hPionMultGen"), nPions, collision.weight()); } - PROCESS_SWITCH(HadronPhotonCorrelation, processPionCorrelationsMCGen, "mc hadron-pion correlation", true); + PROCESS_SWITCH(HadronPhotonCorrelation, processPcmDcaZTrue, "process to test true dcaZ distribution of photons in trigger collisions", false); - void processPionCorrelationsMCReco(JetCollisionMCD const& collision_reco, - JetMcCollisions const&, - JetTracksMCD const& tracks_reco, - JetParticles const&) + // last ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + + void processRecoLast(aod::HpcCollisions const& collisions, aod::HpcTriggers const& triggers) { - if (!jetderiveddatautilities::selectCollision(collision_reco, eventSelectionBits, false)) { - return; - } - if (collision_reco.mcCollision().getSubGeneratorId() != subGeneratorIdSelections) { - return; - } + // do at end of each data frame (after other reco correlation process functions) + // (PROCESS_SWITCH of this process has to be declared last) - int nPions = 0; - for (const auto& track_assoc : tracks_reco) { - if (!jetderiveddatautilities::selectTrack(track_assoc, trackSelection)) { - continue; - } + for (auto const& collision : collisions) { + // all events + histos.fill(HIST("reco/info/h1_nEvents"), 0.5); - if (!initTrack(track_assoc)) { + // mc split + if (collision.nSelectSplitMcEv() != config.nSelectSplitMcEv.value) { continue; } - if (std::abs(track_assoc.mcParticle().pdgCode()) != kPiPlus) { + histos.fill(HIST("reco/info/h1_nEvents"), 1.5); + + // standard event selection + if (!collision.selEv()) { continue; } + histos.fill(HIST("reco/info/h1_nEvents"), 2.5); - registry.fill(HIST("reconstructed/charged/hPionSpectrumReco"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), collision_reco.mcCollision().weight()); - nPions++; + histos.fill(HIST("reco/info/h3_nEv_ptTrigZPvMult_reco"), collision.ptMax(), collision.posZ(), collision.nGlobalTracks()); - for (const auto& track_trig : tracks_reco) { - if (!jetderiveddatautilities::selectTrack(track_trig, trackSelection)) { - continue; - } - if (track_trig == track_assoc) { - continue; - } + // group collision + auto const triggersThisEvent = triggers.sliceBy(perColTriggers, collision.globalIndex()); - if (!initTrig(track_trig)) { - continue; - } - float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); - registry.fill(HIST("reconstructed/charged/hPionCorrelReco"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi, collision_reco.mcCollision().weight()); + // trigger loop + for (auto const& trigger : triggersThisEvent) { + // trigger info + histos.fill(HIST("reco/corr/h3_ptPhiEta_trig_reco"), trigger.pt(), trigger.phi(), trigger.eta(), + getTriggerPtCorrection(trigger.pt())); + + // save trigger for mixing + triggerMemoryReco->saveTrigger(trigger.pt(), trigger.phi(), trigger.eta(), collision.posZ(), collision.nGlobalTracks()); } } - registry.fill(HIST("reconstructed/charged/hPionMultReco"), nPions, collision_reco.mcCollision().weight()); } - PROCESS_SWITCH(HadronPhotonCorrelation, processPionCorrelationsMCReco, "mc hadron-pion correlation", true); + PROCESS_SWITCH(HadronPhotonCorrelation, processRecoLast, "process general info for reconstructed collisions and later correlations last", true); - /**************************************************************************************************** - ****************************************** NEUTRALS ************************************************* - ****************************************************************************************************/ + void processMcLast(soa::Filtered const& collisions, soa::Join const& triggers, aod::JetTracksMCD const&, + soa::Filtered const& mcCollisions, aod::HpcTrueTriggers const& trueTriggers, aod::JetParticles const&) + { + // do at end of each data frame (after other mc correlation process functions) + // (PROCESS_SWITCH of this process has to be declared last) - /*********************************************** MC ************************************************/ + for (auto const& mcCollision : mcCollisions) { + // group collision + auto const trueTriggersThisEvent = trueTriggers.sliceBy(perColTrueTriggers, mcCollision.globalIndex()); - void processNeutralCorrelationsMCGen(JetMcCollision const& collision, - JetParticles const& tracks_true) - { - if (!initCollisionMC(collision, tracks_true)) { - return; - } + histos.fill(HIST("mc/info/h3_nEv_ptTrigZPvMult_true"), mcCollision.ptMax(), mcCollision.posZ(), mcCollision.nChargedInEtaRange()); - int nNeutrals = 0; - for (const auto& track_assoc : tracks_true) { - if (!initParticle(track_assoc, false)) { - continue; + // trigger loop + for (auto const& trueTrigger : trueTriggersThisEvent) { + // trigger info + histos.fill(HIST("mc/corr/h3_ptPhiEta_trig_true"), trueTrigger.pt(), trueTrigger.phi(), trueTrigger.eta()); + + // save trigger for mixing + triggerMemoryTrue->saveTrigger(trueTrigger.pt(), trueTrigger.phi(), trueTrigger.eta(), mcCollision.posZ(), mcCollision.nChargedInEtaRange()); } - auto pdgParticle = pdg->GetParticle(track_assoc.pdgCode()); - if (!pdgParticle) { - continue; - } // remove unknown particles - if (pdgParticle->Charge() != 0.) { - continue; - } // remove charged particles - if (std::abs(track_assoc.pdgCode()) < pidCodeHadronCut || track_assoc.pdgCode() == kNeutron) { + } + for (auto const& collision : collisions) { + if (!isMcMatchedCollision(collision)) { + histos.fill(HIST("mc/info/h1_noMatch_event"), 0.5); continue; - } // remove non-hadrons and neutrons - - registry.fill(HIST("generated/neutral/hNeutralSpectrumGen"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), pidCodes[pdgParticle->GetName()], collision.weight()); - nNeutrals++; - - // Get correlations between neutral hadrons and their respective decay photons - auto daughters = track_assoc.daughters_as(); - double alpha = -1; - int nPhotonsPionDecay = 2; - if (daughters.size() == nPhotonsPionDecay) { - auto daughter = daughters.begin(); - double pt1 = daughter.pt(); - ++daughter; - double pt2 = daughter.pt(); - alpha = std::abs((pt1 - pt2) / (pt1 + pt2)); } - for (const auto& daughter : daughters) { - if (std::abs(daughter.pdgCode()) != kGamma) { - continue; - } - if (!daughter.isPhysicalPrimary() && daughter.getGenStatusCode() == -1) { - continue; - } - double deltaPt = daughter.pt() / track_assoc.pt(); - double deltaEta = daughter.eta() - track_assoc.eta(); - double deltaPhi = RecoDecay::constrainAngle(daughter.phi() - track_assoc.phi(), -PIHalf); - double deltaR = std::sqrt(deltaEta * deltaEta + deltaPhi * deltaPhi); + auto const& mcCollision = collision.jetMcCollision_as>(); - registry.fill(HIST("generated/neutral/hNeutralDecayGen"), track_assoc.pt(), deltaPt, deltaR, alpha, pidCodes[pdgParticle->GetName()], collision.weight()); - } + // group collision + auto const trueTriggersThisEvent = trueTriggers.sliceBy(perColTrueTriggers, mcCollision.globalIndex()); + auto const triggersThisEvent = triggers.sliceBy(perColTriggers, collision.globalIndex()); - // Get correlations between triggers and neutral hadrons - for (const auto& track_trig : tracks_true) { - if (!initTrigParticle(track_trig)) { - continue; - } - float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); - registry.fill(HIST("generated/neutral/hNeutralCorrelGen"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi, pidCodes[pdgParticle->GetName()], collision.weight()); - } + histos.fill(HIST("mc/info/h3_nEv_ptTrigZPvMult_trueRecoEv"), mcCollision.ptMax(), mcCollision.posZ(), mcCollision.nChargedInEtaRange()); + histos.fill(HIST("mc/info/h3_nEv_ptTrigZPvMult_trueRecoEvRecoPtTrig"), collision.ptMax(), mcCollision.posZ(), mcCollision.nChargedInEtaRange()); - // Use PYTHIA to simulate decay - /*decayer->Init(); - motherLV->SetPtEtaPhiM(track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), pdgParticle->Mass()); - decayer->Decay(track_assoc.pdgCode(), motherLV); - decayer->ImportParticles(decayParticles); - for (int i = 0; i < decayParticles->GetEntriesFast(); ++i) { - TParticle* daughter = static_cast(decayParticles->At(i)); + // trigger loops + for (auto const& trueTrigger : trueTriggersThisEvent) { + // trigger info + histos.fill(HIST("mc/corr/h3_ptPhiEta_trig_trueRecoEv"), trueTrigger.pt(), trueTrigger.phi(), trueTrigger.eta()); - if (!initDecayParticle(daughter)) { + // save trigger for mixing + triggerMemoryTrueRecoEv->saveTrigger(trueTrigger.pt(), trueTrigger.phi(), trueTrigger.eta(), mcCollision.posZ(), mcCollision.nChargedInEtaRange()); + } + for (auto const& trigger : triggersThisEvent) { + if (!isMcMatchedTrigger(trigger)) { + histos.fill(HIST("mc/info/h1_pt_noMatch_trigger"), trigger.pt()); continue; } - registry.fill(HIST("generated/neutral/hCocktailPhotonSpectrumGen"), track_assoc.pt(), daughter->Pt(), daughter->Eta(), daughter->Phi(), pidCodes[pdgParticle->GetName()], collision.weight()); + auto const& triggerParticle = trigger.jetTrack_as().mcParticle(); - for (const auto& track_trig : tracks_true) { - if (!initTrigParticle(track_trig)) { - continue; - } - float dphi = RecoDecay::constrainAngle(daughter->Phi() - track_trig.phi(), -PIHalf); - registry.fill(HIST("generated/neutral/hCocktailPhotonCorrelGen"), track_trig.pt(), track_assoc.pt(), daughter->Pt(), daughter->Eta() - track_trig.eta(), dphi, pidCodes[pdgParticle->GetName()], collision.weight()); - } - }*/ + // trigger info + histos.fill(HIST("mc/corr/h3_ptPhiEta_trig_trueRecoEvRecoPtTrig"), trigger.pt(), triggerParticle.phi(), triggerParticle.eta()); + + // save trigger for mixing + triggerMemoryTrueRecoEvRecoPtTrig->saveTrigger(trigger.pt(), triggerParticle.phi(), triggerParticle.eta(), mcCollision.posZ(), mcCollision.nChargedInEtaRange()); + } } - registry.fill(HIST("generated/neutral/hNeutralMultGen"), nNeutrals, collision.weight()); } - PROCESS_SWITCH(HadronPhotonCorrelation, processNeutralCorrelationsMCGen, "mc hadron-pion correlation", true); + PROCESS_SWITCH(HadronPhotonCorrelation, processMcLast, "process general MC info for collisions and later correlations last", false); }; -WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +WorkflowSpec defineDataProcessing(ConfigContext const& configContext) { - return WorkflowSpec{adaptAnalysisTask(cfgc)}; -}; + return WorkflowSpec{adaptAnalysisTask(configContext), adaptAnalysisTask(configContext)}; +} diff --git a/PWGJE/Tasks/hadronPhotonCorrelationSim.cxx b/PWGJE/Tasks/hadronPhotonCorrelationSim.cxx new file mode 100644 index 00000000000..ef15c5d82ac --- /dev/null +++ b/PWGJE/Tasks/hadronPhotonCorrelationSim.cxx @@ -0,0 +1,1181 @@ +// 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 hadronPhotonCorrelationSim.cxx +/// \author Peter Stratmann +/// \brief This code loops over JetTracks to extract pt and angular information +/// for hadrons and photons to compute angular correlations +/// + +#include "PWGEM/PhotonMeson/DataModel/gammaTables.h" +#include "PWGJE/Core/JetDerivedDataUtilities.h" +#include "PWGJE/DataModel/Jet.h" +#include "PWGJE/DataModel/JetReducedData.h" +#include "PWGLF/DataModel/LFStrangenessTables.h" + +#include "Common/Core/RecoDecay.h" +#include "Common/DataModel/PIDResponseTPC.h" +#include "Common/DataModel/TrackSelectionTables.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +using namespace o2; +using namespace o2::aod; +using namespace o2::framework; +using namespace o2::framework::expressions; +using namespace o2::soa; +using namespace o2::constants::physics; +using namespace o2::constants::math; + +struct HadronPhotonCorrelationSim { + + Configurable eventSelections{"eventSelections", "sel8", "choose event selection"}; + Configurable trackSelections{"trackSelections", "globalTracks", "set track selections"}; + Configurable subGeneratorIdSelections{"subGeneratorIdSelections", -1, "set sub generator id"}; + Configurable hardQCDgg2gg{"hardQCDgg2gg", true, "include gg2gg process in hardQCD"}; + + Configurable tpcNClsCrossedRows{"tpcNClsCrossedRows", 70, "tpcNClsCrossedRows"}; + Configurable tpcCrossedRowsOverFindableCls{"tpcCrossedRowsOverFindableCls", 0.8, "tpcCrossedRowsOverFindableCls"}; + Configurable tpcNSigmaPi{"tpcNSigmaPi", 2., "tpcNSigmaPi"}; + + Configurable pTHatMin{"pTHatMin", 5, "minimum pTHat cut"}; + Configurable pTHatMax{"pTHatMax", 600, "minimum pTHat cut"}; + + const int pidCodeHadronCut = 100; + const int pythiaCodeIncomingHard = 21; + const int pythiaCodeOutgoingHard = 23; + const int pythiaCodeOutgoingDiff = 15; + + Configurable etaMaxTrig{"etaMaxTrig", 0.8, "maximum eta cut for triggers"}; + Configurable etaMaxAssoc{"etaMaxAssoc", 0.8, "maximum eta cut for associateds"}; + Configurable etaBinsTrig{"etaBinsTrig", 40, "number of eta bins for triggers"}; + Configurable etaBinsAssoc{"etaBinsAssoc", 40, "number of eta bins for associateds"}; + Configurable phiBins{"phiBins", 72, "number of phi bins"}; + + // remove this comment + AxisSpec axisEventStats = {6, -.5, 5.5, "Stats"}; + ConfigurableAxis axisPtHat = {"axisPtHat", + {VARIABLE_WIDTH, 0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, + 1., 2., 3., 4., 5., 6., 7., 8., 9., + 10., 20., 30., 40., 50., 60., 70., 80., 90., + 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}, + "p_{T}^{#hat}"}; + ConfigurableAxis axisPtTrig = {"axisPtTrig", + {VARIABLE_WIDTH, + 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 9.0f, 11.0f, 15.0f, 20.0f}, + "p_{T, trig} [GeV]"}; // Axis for trigger particle pt distribution + ConfigurableAxis axisPtAssoc = {"axisPtAssoc", + {VARIABLE_WIDTH, + 0.2, 0.5, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 9.0f, 11.0f, 15.0f}, + "p_{T, assoc} [GeV]"}; // Axis for associated particle pt distribution + ConfigurableAxis axisDeltaPt = {"axisDeltaPt", {200, 0., 1.2}, "#Delta p_T"}; // Axis for pt ratio between neutral hadrons and decay photons + int nHadron = 6; + AxisSpec axisPid = {10, -3.5, nHadron + 0.5, "pid"}; // Axis for PID of neutral hadrons + ConfigurableAxis axisMult = {"axisMult", {100, 0., 99.}, "N_{ch}"}; // Axis for mutplipicity + AxisSpec axisAlpha = {100, 0., 1., "alpha"}; // Axis for decay photon pt assymetry + ConfigurableAxis axisDeltaRDecay = {"axisDeltaRDecay", {400, 0., 3.2}, "#Delta R"}; // Axis for Delta R = sqrt(Delta eta^2 + Delta phi^2) between neutral hadrons and decay photons + + float ptMinTrig = -1; + float ptMaxTrig = -1; + float ptMinAssoc = -1; + float ptMaxAssoc = -1; + + // TPythia8Decayer* decayer = new TPythia8Decayer; + // TLorentzVector* motherLV = new TLorentzVector(); // o2-linter: disable= root/lorentz-vector (TLorentzVector is needed for TPythia8Decayer) + // TClonesArray* decayParticles = new TClonesArray("TParticle", 10); + + HistogramRegistry registry{"histogram registry"}; + + // Particle ids for storing neutral hadrons + std::map pidCodes = { + {"pi0", 1}, // pi0 + {"eta", 2}, // eta + {"eta'", 3}, // eta' + {"phi", 4}, // phi + {"omega", 5}, // omega + {"Sigma0", 6}, // Sigma + {"Sigma0_bar", 6}}; + + std::map pidToPdg = { + {1, 111}, // pi0 + {2, 221}, // eta + {3, 331}, // eta' + {4, 333}, // phi + {5, 223}, // omega + {6, 3212}}; // Sigma + + Service pdg; + + std::vector eventSelectionBits; + int trackSelection = -1; + + void init(o2::framework::InitContext&) + { + ptMinTrig = axisPtTrig->at(1); + ptMaxTrig = axisPtTrig->back(); + ptMinAssoc = axisPtAssoc->at(1); + ptMaxAssoc = axisPtAssoc->back(); + + AxisSpec axisPhi = {phiBins, 0., TwoPI, "#phi"}; // Axis for phi distribution + AxisSpec axisDeltaPhi = {phiBins, -PIHalf, 3 * PIHalf, "#Delta #phi"}; // Axis for Delta phi in correlations + AxisSpec axisEtaTrig = {etaBinsTrig, -etaMaxTrig, etaMaxTrig, "#eta"}; // Axis for eta distribution + AxisSpec axisEtaAssoc = {etaBinsAssoc, -etaMaxAssoc, etaMaxAssoc, "#eta"}; // Axis for eta distribution + AxisSpec axisDeltaEta = {etaBinsTrig + etaBinsAssoc, -(etaMaxTrig + etaMaxAssoc), etaMaxTrig + etaMaxAssoc, "#Delta #eta"}; // Axis for Delta eta in correlations + + eventSelectionBits = jetderiveddatautilities::initialiseEventSelectionBits(eventSelections); + trackSelection = jetderiveddatautilities::initialiseTrackSelection(trackSelections); + + // Generated histograms + registry.add("generated/events/hEventStats", "Event statistics", kTH1F, {axisEventStats}); + registry.get(HIST("generated/events/hEventStats"))->Sumw2(); + registry.add("generated/events/hPtHat", "pT of hard collision", kTH1F, {axisPtHat}); + registry.get(HIST("generated/events/hPtHat"))->Sumw2(); + + // Triggers + registry.add("generated/triggers/hTrigMultGen", "Generated Trigger Multiplicity", kTH1F, {axisMult}); + registry.get(HIST("generated/triggers/hTrigMultGen"))->Sumw2(); + registry.add("generated/triggers/hTrigSpectrumGen", "Generated Trigger Spectrum", kTHnSparseF, {axisPtTrig, axisEtaTrig, axisPhi}); + registry.get(HIST("generated/triggers/hTrigSpectrumGen"))->Sumw2(); + + // Hadrons + registry.add("generated/hadrons/hHadronCorrelGen", "Generated Trigger-Hadron Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisDeltaEta, axisDeltaPhi}); + registry.get(HIST("generated/hadrons/hHadronCorrelGen"))->Sumw2(); + registry.add("generated/hadrons/hHadronMultGen", "Generated Hadron Multiplicity", kTH1F, {axisMult}); + registry.get(HIST("generated/hadrons/hHadronMultGen"))->Sumw2(); + registry.add("generated/hadrons/hHadronSpectrumGen", "Generated Hadron Spectrum", kTHnSparseF, {axisPtAssoc, axisEtaAssoc, axisPhi}); + registry.get(HIST("generated/hadrons/hHadronSpectrumGen"))->Sumw2(); + + // Photons + registry.add("generated/photons/hPhotonCorrelGen", "Generated Trigger-Photon Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisDeltaEta, axisDeltaPhi, axisPid}); + registry.get(HIST("generated/photons/hPhotonCorrelGen"))->Sumw2(); + registry.add("generated/photons/hPhotonMultGen", "Generated Photon Multiplicity", kTH1F, {axisMult}); + registry.get(HIST("generated/photons/hPhotonMultGen"))->Sumw2(); + registry.add("generated/photons/hPhotonSpectrumGen", "Generated Photon Spectrum", kTHnSparseF, {axisPtAssoc, axisEtaAssoc, axisPhi, axisPid}); + registry.get(HIST("generated/photons/hPhotonSpectrumGen"))->Sumw2(); + + // Charged pions + registry.add("generated/charged/hPionCorrelGen", "Generated Trigger-Pion Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisDeltaEta, axisDeltaPhi}); + registry.get(HIST("generated/charged/hPionCorrelGen"))->Sumw2(); + registry.add("generated/charged/hPionMultGen", "Generated Pion Multiplicity", kTH1F, {axisMult}); + registry.get(HIST("generated/charged/hPionMultGen"))->Sumw2(); + registry.add("generated/charged/hPionSpectrumGen", "Generated Pion Spectrum", kTHnSparseF, {axisPtAssoc, axisEtaAssoc, axisPhi}); + registry.get(HIST("generated/charged/hPionSpectrumGen"))->Sumw2(); + registry.add("generated/charged/hCocktailPhotonCorrelGen", "Cocktail Photon from Pion-Hadron Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisPtAssoc, axisDeltaEta, axisDeltaPhi, axisPid}); + registry.get(HIST("generated/charged/hCocktailPhotonCorrelGen"))->Sumw2(); + registry.add("generated/charged/hCocktailPhotonSpectrumGen", "Cocktail Photon from Pion Spectrum", kTHnSparseF, {axisPtAssoc, axisPtAssoc, axisEtaAssoc, axisPhi, axisPid}); + registry.get(HIST("generated/charged/hCocktailPhotonSpectrumGen"))->Sumw2(); + + ////Neutral particles + registry.add("generated/neutral/hNeutralCorrelGen", "Generated Trigger-Neutral Hadron Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisDeltaEta, axisDeltaPhi, axisPid}); + registry.get(HIST("generated/neutral/hNeutralCorrelGen"))->Sumw2(); + registry.add("generated/neutral/hNeutralMultGen", "Generated Neutral Hadron Multiplicity", kTH1F, {axisMult}); + registry.get(HIST("generated/neutral/hNeutralMultGen"))->Sumw2(); + registry.add("generated/neutral/hNeutralSpectrumGen", "Generated Neutral Hadron Spectrum", kTHnSparseF, {axisPtAssoc, axisEtaAssoc, axisPhi, axisPid}); + registry.get(HIST("generated/neutral/hNeutralSpectrumGen"))->Sumw2(); + registry.add("generated/neutral/hNeutralDecayGen", "Generated Neutral Hadron-Decay Photon Correlation", kTHnSparseF, {axisPtAssoc, axisDeltaPt, axisDeltaRDecay, axisAlpha, axisPid}); // Correlation with decay photons + registry.get(HIST("generated/neutral/hNeutralDecayGen"))->Sumw2(); + registry.add("generated/neutral/hCocktailPhotonCorrelGen", "Cocktail Photon from Hadron-Hadron Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisPtAssoc, axisDeltaEta, axisDeltaPhi, axisPid}); + registry.get(HIST("generated/neutral/hCocktailPhotonCorrelGen"))->Sumw2(); + registry.add("generated/neutral/hCocktailPhotonSpectrumGen", "Cocktail Photon from Hadron Spectrum", kTHnSparseF, {axisPtAssoc, axisPtAssoc, axisEtaAssoc, axisPhi, axisPid}); + registry.get(HIST("generated/neutral/hCocktailPhotonSpectrumGen"))->Sumw2(); + + // Reconstructed histograms + registry.add("reconstructed/events/hEventStats", "Event statistics", kTH1F, {axisEventStats}); + registry.get(HIST("reconstructed/events/hEventStats"))->Sumw2(); + + // Triggers + registry.add("reconstructed/triggers/hTrigMultReco", "Reconstructed Trigger Multiplicity", kTH1F, {axisMult}); + registry.get(HIST("reconstructed/triggers/hTrigMultReco"))->Sumw2(); + registry.add("reconstructed/triggers/hTrigSpectrumReco", "Reconstructed Trigger Spectrum", kTHnSparseF, {axisPtTrig, axisEtaTrig, axisPhi}); + registry.get(HIST("reconstructed/triggers/hTrigSpectrumReco"))->Sumw2(); + + // Hadrons + registry.add("reconstructed/hadrons/hHadronCorrelReco", "Reconstructed Trigger-Hadron Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisDeltaEta, axisDeltaPhi}); + registry.get(HIST("reconstructed/hadrons/hHadronCorrelReco"))->Sumw2(); + registry.add("reconstructed/hadrons/hHadronMultReco", "Reconstructed Hadron Multiplicity", kTH1F, {axisMult}); + registry.get(HIST("reconstructed/hadrons/hHadronMultReco"))->Sumw2(); + registry.add("reconstructed/hadrons/hHadronSpectrumReco", "Reconstructed Hadron Spectrum", kTHnSparseF, {axisPtAssoc, axisEtaAssoc, axisPhi}); + registry.get(HIST("reconstructed/hadrons/hHadronSpectrumReco"))->Sumw2(); + registry.add("reconstructed/hadrons/hHadronPtPrimReco", "Reconstructed Primaries Spectrum", kTH1F, {axisPtAssoc}); // Primary hadron spectrum + registry.get(HIST("reconstructed/hadrons/hHadronPtPrimReco"))->Sumw2(); + registry.add("reconstructed/hadrons/hHadronPtSecReco", "Reconstructed Secondaries Spectrum", kTH1F, {axisPtAssoc}); // Secondary hadron spectrum + registry.get(HIST("reconstructed/hadrons/hHadronPtSecReco"))->Sumw2(); + + // Photons + registry.add("reconstructed/photons/hPhotonCorrelReco", "Reconstructed Trigger-Photon Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisDeltaEta, axisDeltaPhi}); + registry.get(HIST("reconstructed/photons/hPhotonCorrelReco"))->Sumw2(); + registry.add("reconstructed/photons/hPhotonMultReco", "Reconstructed Photon Multiplicity", kTH1F, {axisMult}); + registry.get(HIST("reconstructed/photons/hPhotonMultReco"))->Sumw2(); + registry.add("reconstructed/photons/hPhotonSpectrumReco", "Reconstructed Photon Spectrum", kTHnSparseF, {axisPtAssoc, axisEtaAssoc, axisPhi}); + registry.get(HIST("reconstructed/photons/hPhotonSpectrumReco"))->Sumw2(); + + // Charged Pions + registry.add("reconstructed/charged/hPionCorrelReco", "Reconstructed Trigger-Pion Correlation", kTHnSparseF, {axisPtTrig, axisPtAssoc, axisDeltaEta, axisDeltaPhi}); + registry.get(HIST("reconstructed/charged/hPionCorrelReco"))->Sumw2(); + registry.add("reconstructed/charged/hPionMultReco", "Reconstructed Pion Multiplicity", kTH1F, {axisMult}); + registry.get(HIST("reconstructed/charged/hPionMultReco"))->Sumw2(); + registry.add("reconstructed/charged/hPionSpectrumReco", "Reconstructed Pion Spectrum", kTHnSparseF, {axisPtAssoc, axisEtaAssoc, axisPhi}); + registry.get(HIST("reconstructed/charged/hPionSpectrumReco"))->Sumw2(); + } + + // Get pTHat of the event + template + double getCollisionPtHat(const P& particles) + { + double pTHat = 0; + bool isDiffractive = false; + + for (const auto& particle : particles) { + + if (std::abs(particle.getGenStatusCode()) == pythiaCodeOutgoingHard && !isDiffractive) { + if (particle.pt() > pTHat) { + pTHat = particle.pt(); + } + } + if (std::abs(particle.getGenStatusCode()) == pythiaCodeOutgoingDiff) { + if (isDiffractive) { + if (particle.pt() > pTHat) { + pTHat = particle.pt(); + } + } else { + pTHat = particle.pt(); + isDiffractive = true; + } + } + } + + return pTHat; + } + + template + bool rejectOutliers(const P& particles, double pTHat) + { + if (subGeneratorIdSelections == 0) { + return false; + } + + for (const auto& particle : particles) { + if (particle.getGenStatusCode() > 0 && particle.pt() > pTHat) { + return true; + } + } + + return false; + } + + // If event is a HardQCD gg->gg event (which is not implemented in POWHEG directphoton) + template + bool isHardQCDgg2gg(const P& particles) + { + for (const auto& particle : particles) { + if (std::abs(particle.getGenStatusCode()) == pythiaCodeIncomingHard && std::abs(particle.pdgCode()) != kGluon) { + return false; + } + if (std::abs(particle.getGenStatusCode()) == pythiaCodeOutgoingHard && std::abs(particle.pdgCode()) != kGluon) { + return false; + } + } + return true; + } + + // Initialize collision + template + bool initCollisionMC(const C& collision, const P& particles) + { + if (collision.getSubGeneratorId() != subGeneratorIdSelections) { + return false; + } + + double pTHat = getCollisionPtHat(particles); + if (pTHat < pTHatMin || pTHat > pTHatMax) { + return false; + } + + if (rejectOutliers(particles, pTHat)) { + return false; + } + + if (!hardQCDgg2gg && isHardQCDgg2gg(particles)) { + return false; + } + + return true; + } + + // To check if object has has_mcParticle() (i.e. is MC Track or data track) + template + struct HasHasMcParticle { + template + static auto test(U* ptr) -> decltype(ptr->has_mcParticle(), std::true_type{}); + static std::false_type test(...); + static constexpr bool Value() + { + return decltype(test(std::declval()))::value; + } + }; + + // Initialize track + template + bool initTrack(const T& track) + { + + // if constexpr (HasHasMcParticle) { + if constexpr (HasHasMcParticle::Value()) { + if (!track.has_mcParticle()) { + return false; + } + } + + if (std::abs(track.eta()) > etaMaxAssoc) { + return false; + } + + if (track.pt() < ptMinAssoc || track.pt() > ptMaxAssoc) { + return false; + } + + return true; + } + + // Initialize particle + template + bool initParticle(const T& particle, bool checkIsPrimary = true) + { + + if (checkIsPrimary && !particle.isPhysicalPrimary()) { + return false; + } + + if (particle.getGenStatusCode() == -1) { + return false; + } + + if (std::abs(particle.eta()) > etaMaxAssoc) { + return false; + } + + if (particle.pt() < ptMinAssoc || particle.pt() > ptMaxAssoc) { + return false; + } + + return true; + } + + // Initialize Pythia8 decay particle + /*bool initDecayParticle(const TParticle* particle) + { + + if (particle->GetMother(0) != 0) { + return false; + } + + if (std::abs(particle->GetPdgCode()) != kGamma) { + return false; + } + + if (std::abs(particle->Eta()) > etaMaxAssoc) { + return false; + } + + if (particle->Pt() < ptMinAssoc || particle->Pt() > ptMaxAssoc) { + return false; + } + + return true; + }*/ + + // Initialize trigger tracks + template + bool initTrig(const T& track) + { + // if constexpr (HasHasMcParticle) { + if constexpr (HasHasMcParticle::Value()) { + if (!track.has_mcParticle()) { + return false; + } + } + + if (std::abs(track.eta()) > etaMaxTrig) { + return false; + } + + if (track.pt() < ptMinTrig || track.pt() > ptMaxTrig) { + return false; + } + + return true; + } + + // Initialize trigger particles (charged) + template + bool initTrigParticle(const T& particle) + { + if (!particle.isPhysicalPrimary()) { + return false; + } + + auto pdgParticle = pdg->GetParticle(particle.pdgCode()); + if (!pdgParticle || pdgParticle->Charge() == 0.) { + return false; + } + + if (std::abs(particle.eta()) > etaMaxTrig) { + return false; + } + + if (particle.pt() < ptMinTrig || particle.pt() > ptMaxTrig) { + return false; + } + + return true; + } + + // Initialize V0s + template + bool initV0(TV0 const& v0) + { + auto pos = v0.template posTrack_as(); + auto neg = v0.template negTrack_as(); + if (!initV0leg(pos) || !initV0leg(neg)) { + return false; + } + + return true; + } + + template + bool initV0leg(TTrack const& track) + { + if (!initTrack(track)) { + return false; + } + + if (!track.hasTPC()) { + return false; + } + + if (track.tpcNClsCrossedRows() < tpcNClsCrossedRows) { + return false; + } + + if (track.tpcCrossedRowsOverFindableCls() < tpcCrossedRowsOverFindableCls) { + return false; + } + + return true; + } + + /**************************************************************************************************** + ************************************************ EVENTS ******************************************** + ****************************************************************************************************/ + void processEventsMCGen(JetMcCollision const& collision, + JetParticles const& particles) + { + if (collision.getSubGeneratorId() == subGeneratorIdSelections) { + registry.fill(HIST("generated/events/hEventStats"), 0); + registry.fill(HIST("generated/events/hEventStats"), 2, collision.weight()); + registry.fill(HIST("generated/events/hEventStats"), 4, collision.xsectGen()); + } + + if (!initCollisionMC(collision, particles)) { + return; + } + + registry.fill(HIST("generated/events/hEventStats"), 1); + registry.fill(HIST("generated/events/hEventStats"), 3, collision.weight()); + registry.fill(HIST("generated/events/hEventStats"), 5, collision.xsectGen()); + + registry.fill(HIST("generated/events/hPtHat"), getCollisionPtHat(particles)); + } + PROCESS_SWITCH(HadronPhotonCorrelationSim, processEventsMCGen, "event stats MC gen", true); + + void processEventsMCReco(JetCollisionMCD const& collision, + JetMcCollisions const&, + JetParticles const&) + { + if (collision.getSubGeneratorId() != subGeneratorIdSelections) { + return; + } + registry.fill(HIST("reconstructed/events/hEventStats"), 0); + registry.fill(HIST("reconstructed/events/hEventStats"), 2, collision.mcCollision().weight()); + registry.fill(HIST("reconstructed/events/hEventStats"), 4, collision.mcCollision().xsectGen()); + + if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits, false)) { + return; + } + + registry.fill(HIST("reconstructed/events/hEventStats"), 1); + registry.fill(HIST("reconstructed/events/hEventStats"), 3, collision.mcCollision().weight()); + registry.fill(HIST("reconstructed/events/hEventStats"), 5, collision.mcCollision().xsectGen()); + } + PROCESS_SWITCH(HadronPhotonCorrelationSim, processEventsMCReco, "event stats MC reco", true); + + /**************************************************************************************************** + ************************************************ TRIGGER ******************************************** + ****************************************************************************************************/ + + /********************************************** DATA ***********************************************/ + + void processTrigsReco(JetCollision const& collision, + JetTracks const& tracks) + { + if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits)) { + return; + } + + int nTrigs = 0; + for (const auto& track : tracks) { + if (!jetderiveddatautilities::selectTrack(track, trackSelection)) { + continue; + } + + if (!initTrig(track)) { + continue; + } + + registry.fill(HIST("reconstructed/triggers/hTrigSpectrumReco"), track.pt(), track.eta(), track.phi()); + nTrigs++; + } + registry.fill(HIST("reconstructed/triggers/hTrigMultReco"), nTrigs); + } + PROCESS_SWITCH(HadronPhotonCorrelationSim, processTrigsReco, "trigger particle properties", true); + + /*********************************************** MC ************************************************/ + + void processTrigsMCReco(JetCollisionMCD const& collision, + JetMcCollisions const&, + Join const& tracks, + JetParticles const&) + { + if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits, false)) { + return; + } + if (collision.getSubGeneratorId() != subGeneratorIdSelections) { + return; + } + + int nTrigs = 0; + for (const auto& track : tracks) { + if (!jetderiveddatautilities::selectTrack(track, trackSelection)) { + continue; + } + + if (!initTrig(track)) { + continue; + } + registry.fill(HIST("reconstructed/triggers/hTrigSpectrumReco"), track.pt(), track.eta(), track.phi(), collision.mcCollision().weight()); + nTrigs++; + } + registry.fill(HIST("reconstructed/triggers/hTrigMultReco"), nTrigs, collision.mcCollision().weight()); + } + PROCESS_SWITCH(HadronPhotonCorrelationSim, processTrigsMCReco, "trigger particle mc properties", true); + + void processTrigsMCGen(JetMcCollision const& collision, + JetParticles const& particles) + { + if (!initCollisionMC(collision, particles)) { + return; + } + + int nTrigs = 0; + for (const auto& particle : particles) { + if (!initTrigParticle(particle)) { + continue; + } + registry.fill(HIST("generated/triggers/hTrigSpectrumGen"), particle.pt(), particle.eta(), particle.phi(), collision.weight()); + nTrigs++; + } + registry.fill(HIST("generated/triggers/hTrigMultGen"), nTrigs, collision.weight()); + } + PROCESS_SWITCH(HadronPhotonCorrelationSim, processTrigsMCGen, "trigger particle mc properties", true); + + /**************************************************************************************************** + ********************************************** PHOTONS ********************************************** + ****************************************************************************************************/ + + /********************************************** DATA ***********************************************/ + using MyTracks = soa::Join; + Preslice perCol = aod::v0::collisionId; + void processPhotonCorrelations(JetCollision const& collision, + JetTracks const& tracks, + MyTracks const&, + V0Datas const& v0s) + { + if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits)) { + return; + } + + int nPhotons = 0; + auto v0PerCollision = v0s.sliceBy(perCol, collision.globalIndex()); + for (const auto& v0 : v0PerCollision) { + if (!initV0(v0)) { + continue; + } + registry.fill(HIST("reconstructed/photons/hPhotonSpectrumReco"), v0.pt(), v0.eta(), v0.phi()); + nPhotons++; + + for (const auto& track : tracks) { + if (!jetderiveddatautilities::selectTrack(track, trackSelection)) { + continue; + } + + if (!initTrig(track)) { + continue; + } + float dphi = RecoDecay::constrainAngle(v0.phi() - track.phi(), -PIHalf); + registry.fill(HIST("reconstructed/photons/hPhotonCorrelReco"), track.pt(), v0.pt(), v0.eta() - track.eta(), dphi); + } + } + registry.fill(HIST("reconstructed/photons/hPhotonMultReco"), nPhotons); + } + PROCESS_SWITCH(HadronPhotonCorrelationSim, processPhotonCorrelations, "hadron-photon correlation", true); + + /*********************************************** MC ************************************************/ + + using MyTracksMC = soa::Join; + void processPhotonCorrelationsMCReco(Join::iterator const& collision_reco, + JetMcCollisions const&, + JetTracks const& tracks_reco, + JetParticles const&, + MyTracksMC const&, + V0Datas const& v0s) + { + if (!jetderiveddatautilities::selectCollision(collision_reco, eventSelectionBits, false)) { + return; + } + if (collision_reco.mcCollision().getSubGeneratorId() != subGeneratorIdSelections) { + return; + } + + int nPhotons = 0; + + auto v0PerCollision = v0s.sliceBy(perCol, collision_reco.globalIndex()); + for (const auto& v0 : v0PerCollision) { + if (!initV0(v0)) { + continue; + } + registry.fill(HIST("reconstructed/photons/hPhotonSpectrumReco"), v0.pt(), v0.eta(), v0.phi(), collision_reco.mcCollision().weight()); + nPhotons++; + + for (const auto& track : tracks_reco) { + if (!jetderiveddatautilities::selectTrack(track, trackSelection)) { + continue; + } + + if (!initTrig(track)) { + continue; + } + float dphi = RecoDecay::constrainAngle(v0.phi() - track.phi(), -PIHalf); + registry.fill(HIST("reconstructed/photons/hPhotonCorrelReco"), track.pt(), v0.pt(), v0.eta() - track.eta(), dphi, collision_reco.mcCollision().weight()); + } + } + registry.fill(HIST("reconstructed/photons/hPhotonMultReco"), nPhotons, collision_reco.mcCollision().weight()); + } + PROCESS_SWITCH(HadronPhotonCorrelationSim, processPhotonCorrelationsMCReco, "hadron-photon correlation", true); + + void processPhotonCorrelationsMCGen(JetMcCollision const& collision, + JetParticles const& tracks_true) + { + if (!initCollisionMC(collision, tracks_true)) { + return; + } + + int nPhotons = 0; + for (const auto& track_assoc : tracks_true) { + if (!initParticle(track_assoc, false)) { + continue; + } + if (std::abs(track_assoc.pdgCode()) != kGamma) { + continue; + } + if (!track_assoc.isPhysicalPrimary() && track_assoc.getGenStatusCode() < 0) { + continue; + } + + // Iterate through mother particles until original mother is reached + auto origPhoton = track_assoc; + auto mother = track_assoc.mothers_as().at(0); + while (mother.pdgCode() == kGamma) { + origPhoton = mother; + mother = mother.mothers_as().at(0); + } + + auto pdgMother = pdg->GetParticle(mother.pdgCode()); + if (!pdgMother) { + continue; + } + int photonGeneration; + switch (std::abs(origPhoton.getGenStatusCode())) { + case 23: // prompt direct photons + case 33: + photonGeneration = -2; + break; + case 43: // shower photons + case 44: + case 51: + case 52: + photonGeneration = -1; + break; + case 91: // decay photons + photonGeneration = pidCodes[pdgMother->GetName()]; + break; + default: + photonGeneration = -3; + break; + } + + registry.fill(HIST("generated/photons/hPhotonSpectrumGen"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), photonGeneration, collision.weight()); + + nPhotons++; + + for (const auto& track_trig : tracks_true) { + if (!initTrigParticle(track_trig)) { + continue; + } + float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); + registry.fill(HIST("generated/photons/hPhotonCorrelGen"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi, photonGeneration, collision.weight()); + } + } + + registry.fill(HIST("generated/photons/hPhotonMultGen"), nPhotons, collision.weight()); + } + PROCESS_SWITCH(HadronPhotonCorrelationSim, processPhotonCorrelationsMCGen, "mc hadron-photon correlation", true); + + /**************************************************************************************************** + ***************************************** HADRONS *************************************************** + ****************************************************************************************************/ + + /********************************************** DATA ***********************************************/ + void processHadronCorrelations(JetCollision const& collision, + Join const& tracks) + { + if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits)) { + return; + } + + int nHadrons = 0; + for (const auto& track_assoc : tracks) { + if (!jetderiveddatautilities::selectTrack(track_assoc, trackSelection)) { + continue; + } + + if (!initTrack(track_assoc)) { + continue; + } + registry.fill(HIST("reconstructed/hadrons/hHadronSpectrumReco"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi()); + nHadrons++; + + for (const auto& track_trig : tracks) { + if (!jetderiveddatautilities::selectTrack(track_trig, trackSelection)) { + continue; + } + if (track_trig == track_assoc) { + continue; + } + if (!initTrig(track_trig)) { + continue; + } + float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); + registry.fill(HIST("reconstructed/hadrons/hHadronCorrelReco"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi); + } + } + registry.fill(HIST("reconstructed/hadrons/hHadronMultReco"), nHadrons); + } + PROCESS_SWITCH(HadronPhotonCorrelationSim, processHadronCorrelations, "hadron-hadron correlation", true); + + /*********************************************** MC ************************************************/ + + void processHadronCorrelationsMCGen(JetMcCollision const& collision, + JetParticles const& tracks_true) + { + if (!initCollisionMC(collision, tracks_true)) { + return; + } + + int nHadrons = 0; + for (const auto& track_assoc : tracks_true) { + if (!initParticle(track_assoc)) { + continue; + } + auto pdgParticle = pdg->GetParticle(track_assoc.pdgCode()); + if (!pdgParticle || pdgParticle->Charge() == 0.) { + continue; + } + if (std::abs(track_assoc.pdgCode()) < pidCodeHadronCut) { + continue; + } + + registry.fill(HIST("generated/hadrons/hHadronSpectrumGen"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), collision.weight()); + nHadrons++; + + for (const auto& track_trig : tracks_true) { + if (!initTrigParticle(track_trig)) { + continue; + } + if (track_trig == track_assoc) { + continue; + } + float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); + + registry.fill(HIST("generated/hadrons/hHadronCorrelGen"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi, collision.weight()); + } + } + registry.fill(HIST("generated/hadrons/hHadronMultGen"), nHadrons, collision.weight()); + } + PROCESS_SWITCH(HadronPhotonCorrelationSim, processHadronCorrelationsMCGen, "mc hadron-hadron correlation", true); + + void processHadronCorrelationsMCReco(JetCollisionMCD const& collision_reco, + JetMcCollisions const&, + JetTracksMCD const& tracks_reco, + JetParticles const&) + { + if (!jetderiveddatautilities::selectCollision(collision_reco, eventSelectionBits, false)) { + return; + } + if (collision_reco.mcCollision().getSubGeneratorId() != subGeneratorIdSelections) { + return; + } + + int nHadrons = 0; + for (const auto& track_assoc : tracks_reco) { + if (!jetderiveddatautilities::selectTrack(track_assoc, trackSelection)) { + continue; + } + + if (!initTrack(track_assoc)) { + continue; + } + auto particle = track_assoc.mcParticle(); + auto pdgParticle = pdg->GetParticle(particle.pdgCode()); + if (!pdgParticle || pdgParticle->Charge() == 0.) { + continue; + } + if (std::abs(particle.pdgCode()) < pidCodeHadronCut) { + continue; + } + + registry.fill(HIST("reconstructed/hadrons/hHadronSpectrumReco"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), collision_reco.mcCollision().weight()); + + if (particle.isPhysicalPrimary()) { + registry.fill(HIST("reconstructed/hadrons/hHadronPtPrimReco"), track_assoc.pt(), collision_reco.mcCollision().weight()); + } else { + registry.fill(HIST("reconstructed/hadrons/hHadronPtSecReco"), track_assoc.pt(), collision_reco.mcCollision().weight()); + } + nHadrons++; + + for (const auto& track_trig : tracks_reco) { + if (!jetderiveddatautilities::selectTrack(track_trig, trackSelection)) { + continue; + } + if (track_trig == track_assoc) { + continue; + } + if (!initTrig(track_trig)) { + continue; + } + float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); + + registry.fill(HIST("reconstructed/hadrons/hHadronCorrelReco"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi, collision_reco.mcCollision().weight()); + } + } + registry.fill(HIST("reconstructed/hadrons/hHadronMultReco"), nHadrons, collision_reco.mcCollision().weight()); + } + PROCESS_SWITCH(HadronPhotonCorrelationSim, processHadronCorrelationsMCReco, "mc hadron-hadron correlation", true); + + /**************************************************************************************************** + *************************************** CHARGED PIONS *********************************************** + ****************************************************************************************************/ + + /********************************************** DATA ***********************************************/ + void processPionCorrelations(JetCollision const& collision, + Join const& tracks) + { + if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits)) { + return; + } + + int nPions = 0; + for (const auto& track_assoc : tracks) { + if (!jetderiveddatautilities::selectTrack(track_assoc, trackSelection)) { + continue; + } + + if (!initTrack(track_assoc)) { + continue; + } + if (std::abs(track_assoc.tpcNSigmaPi()) > tpcNSigmaPi) { + continue; + } // remove non-pions + registry.fill(HIST("reconstructed/charged/hPionSpectrumReco"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi()); + nPions++; + + for (const auto& track_trig : tracks) { + if (!jetderiveddatautilities::selectTrack(track_trig, trackSelection)) { + continue; + } + if (track_trig == track_assoc) { + continue; + } + if (!initTrig(track_trig)) { + continue; + } + float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); + registry.fill(HIST("reconstructed/charged/hPionCorrelReco"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi); + } + } + registry.fill(HIST("reconstructed/charged/hPionMultReco"), nPions); + } + PROCESS_SWITCH(HadronPhotonCorrelationSim, processPionCorrelations, "hadron-pion correlation", true); + + /*********************************************** MC ************************************************/ + + void processPionCorrelationsMCGen(JetMcCollision const& collision, + JetParticles const& tracks_true) + { + if (!initCollisionMC(collision, tracks_true)) { + return; + } + + int nPions = 0; + for (const auto& track_assoc : tracks_true) { + if (!initParticle(track_assoc)) { + continue; + } + if (std::abs(track_assoc.pdgCode()) != kPiPlus) { + continue; + } + + registry.fill(HIST("generated/charged/hPionSpectrumGen"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), collision.weight()); + nPions++; + + // Get correlations + for (const auto& track_trig : tracks_true) { + if (!initTrigParticle(track_trig)) { + continue; + } + if (track_trig == track_assoc) { + continue; + } + float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); + + registry.fill(HIST("generated/charged/hPionCorrelGen"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi, collision.weight()); + } + + // Use PYTHIA to simulate decay + /*decayer->Init(); + for (int pid = 1; pid <= nHadron; pid++) { + TParticlePDG* pdgParticle = nullptr; + + auto it = pidToPdg.find(pid); + if (it != pidToPdg.end()) { + pdgParticle = pdg->GetParticle(it->second); + } else { + continue; + } + + motherLV->SetPtEtaPhiM(track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), pdgParticle->Mass()); + decayer->Decay(pdgParticle->PdgCode(), motherLV); + decayer->ImportParticles(decayParticles); + for (int i = 0; i < decayParticles->GetEntriesFast(); ++i) { + TParticle* daughter = static_cast(decayParticles->At(i)); + + if (!initDecayParticle(daughter)) { + continue; + } + + registry.fill(HIST("generated/charged/hCocktailPhotonSpectrumGen"), track_assoc.pt(), daughter->Pt(), daughter->Eta(), daughter->Phi(), pidCodes[pdgParticle->GetName()], collision.weight()); + + for (const auto& track_trig : tracks_true) { + if (!initTrigParticle(track_trig)) { + continue; + } + if (track_trig == track_assoc) { + continue; + } + float dphi = RecoDecay::constrainAngle(daughter->Phi() - track_trig.phi(), -PIHalf); + registry.fill(HIST("generated/charged/hCocktailPhotonCorrelGen"), track_trig.pt(), track_assoc.pt(), daughter->Pt(), daughter->Eta() - track_trig.eta(), dphi, pidCodes[pdgParticle->GetName()], collision.weight()); + } + } + }*/ + } + registry.fill(HIST("generated/charged/hPionMultGen"), nPions, collision.weight()); + } + PROCESS_SWITCH(HadronPhotonCorrelationSim, processPionCorrelationsMCGen, "mc hadron-pion correlation", true); + + void processPionCorrelationsMCReco(JetCollisionMCD const& collision_reco, + JetMcCollisions const&, + JetTracksMCD const& tracks_reco, + JetParticles const&) + { + if (!jetderiveddatautilities::selectCollision(collision_reco, eventSelectionBits, false)) { + return; + } + if (collision_reco.mcCollision().getSubGeneratorId() != subGeneratorIdSelections) { + return; + } + + int nPions = 0; + for (const auto& track_assoc : tracks_reco) { + if (!jetderiveddatautilities::selectTrack(track_assoc, trackSelection)) { + continue; + } + + if (!initTrack(track_assoc)) { + continue; + } + if (std::abs(track_assoc.mcParticle().pdgCode()) != kPiPlus) { + continue; + } + + registry.fill(HIST("reconstructed/charged/hPionSpectrumReco"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), collision_reco.mcCollision().weight()); + nPions++; + + for (const auto& track_trig : tracks_reco) { + if (!jetderiveddatautilities::selectTrack(track_trig, trackSelection)) { + continue; + } + if (track_trig == track_assoc) { + continue; + } + + if (!initTrig(track_trig)) { + continue; + } + float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); + registry.fill(HIST("reconstructed/charged/hPionCorrelReco"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi, collision_reco.mcCollision().weight()); + } + } + registry.fill(HIST("reconstructed/charged/hPionMultReco"), nPions, collision_reco.mcCollision().weight()); + } + PROCESS_SWITCH(HadronPhotonCorrelationSim, processPionCorrelationsMCReco, "mc hadron-pion correlation", true); + + /**************************************************************************************************** + ****************************************** NEUTRALS ************************************************* + ****************************************************************************************************/ + + /*********************************************** MC ************************************************/ + + void processNeutralCorrelationsMCGen(JetMcCollision const& collision, + JetParticles const& tracks_true) + { + if (!initCollisionMC(collision, tracks_true)) { + return; + } + + int nNeutrals = 0; + for (const auto& track_assoc : tracks_true) { + if (!initParticle(track_assoc, false)) { + continue; + } + auto pdgParticle = pdg->GetParticle(track_assoc.pdgCode()); + if (!pdgParticle) { + continue; + } // remove unknown particles + if (pdgParticle->Charge() != 0.) { + continue; + } // remove charged particles + if (std::abs(track_assoc.pdgCode()) < pidCodeHadronCut || track_assoc.pdgCode() == kNeutron) { + continue; + } // remove non-hadrons and neutrons + + registry.fill(HIST("generated/neutral/hNeutralSpectrumGen"), track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), pidCodes[pdgParticle->GetName()], collision.weight()); + nNeutrals++; + + // Get correlations between neutral hadrons and their respective decay photons + auto daughters = track_assoc.daughters_as(); + double alpha = -1; + int nPhotonsPionDecay = 2; + if (daughters.size() == nPhotonsPionDecay) { + auto daughter = daughters.begin(); + double pt1 = daughter.pt(); + ++daughter; + double pt2 = daughter.pt(); + alpha = std::abs((pt1 - pt2) / (pt1 + pt2)); + } + + for (const auto& daughter : daughters) { + if (std::abs(daughter.pdgCode()) != kGamma) { + continue; + } + if (!daughter.isPhysicalPrimary() && daughter.getGenStatusCode() == -1) { + continue; + } + double deltaPt = daughter.pt() / track_assoc.pt(); + double deltaEta = daughter.eta() - track_assoc.eta(); + double deltaPhi = RecoDecay::constrainAngle(daughter.phi() - track_assoc.phi(), -PIHalf); + double deltaR = std::sqrt(deltaEta * deltaEta + deltaPhi * deltaPhi); + + registry.fill(HIST("generated/neutral/hNeutralDecayGen"), track_assoc.pt(), deltaPt, deltaR, alpha, pidCodes[pdgParticle->GetName()], collision.weight()); + } + + // Get correlations between triggers and neutral hadrons + for (const auto& track_trig : tracks_true) { + if (!initTrigParticle(track_trig)) { + continue; + } + float dphi = RecoDecay::constrainAngle(track_assoc.phi() - track_trig.phi(), -PIHalf); + registry.fill(HIST("generated/neutral/hNeutralCorrelGen"), track_trig.pt(), track_assoc.pt(), track_assoc.eta() - track_trig.eta(), dphi, pidCodes[pdgParticle->GetName()], collision.weight()); + } + + // Use PYTHIA to simulate decay + /*decayer->Init(); + motherLV->SetPtEtaPhiM(track_assoc.pt(), track_assoc.eta(), track_assoc.phi(), pdgParticle->Mass()); + decayer->Decay(track_assoc.pdgCode(), motherLV); + decayer->ImportParticles(decayParticles); + for (int i = 0; i < decayParticles->GetEntriesFast(); ++i) { + TParticle* daughter = static_cast(decayParticles->At(i)); + + if (!initDecayParticle(daughter)) { + continue; + } + + registry.fill(HIST("generated/neutral/hCocktailPhotonSpectrumGen"), track_assoc.pt(), daughter->Pt(), daughter->Eta(), daughter->Phi(), pidCodes[pdgParticle->GetName()], collision.weight()); + + for (const auto& track_trig : tracks_true) { + if (!initTrigParticle(track_trig)) { + continue; + } + float dphi = RecoDecay::constrainAngle(daughter->Phi() - track_trig.phi(), -PIHalf); + registry.fill(HIST("generated/neutral/hCocktailPhotonCorrelGen"), track_trig.pt(), track_assoc.pt(), daughter->Pt(), daughter->Eta() - track_trig.eta(), dphi, pidCodes[pdgParticle->GetName()], collision.weight()); + } + }*/ + } + registry.fill(HIST("generated/neutral/hNeutralMultGen"), nNeutrals, collision.weight()); + } + PROCESS_SWITCH(HadronPhotonCorrelationSim, processNeutralCorrelationsMCGen, "mc hadron-pion correlation", true); +}; + +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +{ + return WorkflowSpec{adaptAnalysisTask(cfgc)}; +}; diff --git a/PWGJE/Tasks/hadronPhotonProducer.cxx b/PWGJE/Tasks/hadronPhotonProducer.cxx new file mode 100644 index 00000000000..0ec2f7245a3 --- /dev/null +++ b/PWGJE/Tasks/hadronPhotonProducer.cxx @@ -0,0 +1,937 @@ +// 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 hadronPhotonProducer.cxx +/// \author Julius Kinner +/// \brief hadron-photon angular correlation table producer +/// +/// Table producer for hadron-photon angular correlation analysis + +#include "PWGJE/Core/JetDerivedDataUtilities.h" +#include "PWGJE/DataModel/HadronPhotonCorrelation.h" +#include "PWGJE/DataModel/Jet.h" +#include "PWGJE/DataModel/JetReducedData.h" +// +#include "PWGEM/PhotonMeson/DataModel/gammaTables.h" + +#include "Common/Core/RecoDecay.h" +#include "Common/DataModel/PIDResponseTOF.h" +#include "Common/DataModel/PIDResponseTPC.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include // IWYU pragma: keep (do not replace with Math/Vector4Dfwd.h) +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace o2; +using namespace o2::framework; +using namespace hpc; + +// correlation derived data =================================================================================================================================================================== + +template +concept IsCollisionMCD = requires(T& collision) { collision.mcCollision(); }; +template +concept IsMcCollision = requires(T& collision) { collision.getGeneratorId(); }; + +struct HadronPhotonProducer { + struct : ProducesGroup { + // reco + Produces collision; + Produces collisionId; + Produces collisionMcId; + Produces trigger; + Produces triggerTrackId; + Produces hadron; + Produces hadronTrackId; + Produces pipm; + Produces pipmTrackId; + Produces photonPcm; + Produces photonPcmTrackId; + Produces photonPcmV0PhotonId; + Produces photonPcmPair; + Produces photonPcmPairTrackId; + Produces photonPcmPairV0PhotonId; + // true + Produces mcCollisionExtraCorr; + Produces trueTrigger; + } tableProduction; + + Configurable zPvMax{"zPvMax", 7, "maximum absZ primary-vertex cut"}; + Configurable occupancyMin{"occupancyMin", -1, "minimum occupancy cut"}; + Configurable occupancyMax{"occupancyMax", 2000, "maximum occupancy cut"}; + + Configurable eventSelections{"eventSelections", "sel8", "JE framework - event selection"}; + Configurable skipMBGapEvents{"skipMBGapEvents", true, "skip MB gap events"}; + Configurable applyRctSelection{"applyRctSelection", true, "apply RCT selection"}; + Configurable rctLabel{"rctLabel", "CBT_hadronPID", "RCT selection label"}; + Configurable trackSelections{"trackSelections", "globalTracks", "JE framework - track selections"}; + Configurable triggerMasks{"triggerMasks", "", "JE framework - skimmed data trigger masks (relevent for correlation: fTrackLowPt,fTrackHighPt)"}; + Configurable nTimesSplitMcEv{"nTimesSplitMcEv", 1, "number of event fractions for selection in MC (as modulo from {0,1,...,99}) | (select 1 for data)"}; + + Configurable absEtaMax{"absEtaMax", 0.8, "maximum absEta cut"}; + Configurable ptTrigMin{"ptTrigMin", 5, "minimum pt of triggers"}; + Configurable ptMinTrack{"ptMinTrack", 0.1, "min pt value for tracks (hadron, pipm, mult, trig,... (not v0 legs or other external))"}; + Configurable ptMinHadron{"ptMinHadron", 0.2, "min pt value for hadrons"}; + Configurable piPidLowPt{"piPidLowPt", 0.5, "max pt value for pipm pid without tof"}; + Configurable piPidHighPt{"piPidHighPt", 2.5, "min pt value for pipm pid without tof in relativistic rise of Bethe-Bloch"}; + Configurable> nSigmaPiTpcLowPt{"nSigmaPiTpcLowPt", {-2, 2}, "minimum-maximum nSigma for pipm in tpc at low pt"}; + Configurable> nSigmaPiTpcMidPt{"nSigmaPiTpcMidPt", {-1, 1}, "minimum-maximum nSigma for pipm in tpc at mid pt"}; + Configurable> nSigmaPiTof{"nSigmaPiTof", {-2, 1}, "minimum-maximum nSigma for pipm in tof"}; + Configurable> nSigmaPiRelRise{"nSigmaPiRelRise", {0, 2}, "minimum-maximum nSigma pipm tpc at high pt"}; + + Configurable> pcmAbsDcaZLim{"pcmAbsDcaZLim", {0, 5}, "absolute values of dcaZ limits for pcm"}; + + Configurable oneTriggerPerEvent{"oneTriggerPerEvent", false, "use only one trigger (of highest pt) in an event"}; + + // derivatives of configurables + + std::vector eventSelectionBits; + int trackSelection = -1; + std::vector triggerMaskBits; + + struct TruthLevelInfo { + TruthLevel truthLevel = TruthLevel::Unknown; + double ptTruePure = -1; + }; + struct PhotonImpurityInfo { + PhotonImpurity impurity = PhotonImpurity::Unknown; + double ptTrueOrigin = -1; + }; + + // map ids + std::map jetToHpcCollisionMap; + std::map trackToTriggerMap; + + HistogramRegistry histos{"histogramRegistry", {}, OutputObjHandlingPolicy::AnalysisObject, false, false}; + + // for mc + Service pdg{}; + + // partitions++ + SliceCache cache; + + Preslice perColTracks = aod::jtrack::collisionId; + Preslice perColMcParticles = aod::jmcparticle::mcCollisionId; + + Preslice perColV0Photons = aod::v0photonkf::collisionId; + + // functions ================================================================================================================================================================================ + + // get v0 leg tracks {posTrack, negTrack} as jet tracks via JTrackPI. throws in case of problems + auto getV0LegJetTracks(auto const& v0Photon, auto const& tracks) + { + auto const posTrack = tracks.rawIteratorAt(v0Photon.posTrack().trackId() - tracks.offset()); + auto const negTrack = tracks.rawIteratorAt(v0Photon.negTrack().trackId() - tracks.offset()); + // check index match + if (posTrack.trackId() != v0Photon.posTrack().trackId() || negTrack.trackId() != v0Photon.negTrack().trackId()) { + throw std::runtime_error("v0Photon legs not correctly matched to jetTracks"); + } + return std::tuple(posTrack, negTrack); + } + + template + std::vector getIntersectTriggerIds(std::initializer_list const& tracks) + { + std::vector intersectTriggerIds; + + for (auto const& track : tracks) { + auto const triggerTrackIt = trackToTriggerMap.find(track.globalIndex()); + if (triggerTrackIt != trackToTriggerMap.end()) { + intersectTriggerIds.push_back(triggerTrackIt->second); + } + } + return intersectTriggerIds; + } + + // selections /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + // reco only -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + + // event selection (without trigger skimming) + bool checkEventSelection(auto const& collision) + { + if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits, skipMBGapEvents, applyRctSelection, rctLabel)) { + return false; + } + if (std::abs(collision.posZ()) > zPvMax) { + return false; + } + if (collision.trackOccupancyInTimeRange() < occupancyMin || collision.trackOccupancyInTimeRange() > occupancyMax) { + return false; + } + return true; + } + + // checks track cuts (wow, such explanation) + bool checkTrackCuts(auto const& track) + { + if (!jetderiveddatautilities::selectTrack(track, trackSelection)) { + return false; + } + if (!jetderiveddatautilities::applyTrackKinematics(track, ptMinTrack, 1000, -absEtaMax, absEtaMax)) { + return false; + } + return true; + } + + // checks v0Photon eta and dcaZ + bool checkPhotonEtaDcaZ(auto const& v0Photon) + { + if (std::abs(v0Photon.eta()) > absEtaMax) { + return false; + } + if (std::abs(v0Photon.dcaZtopv()) < pcmAbsDcaZLim.value[0] || std::abs(v0Photon.dcaZtopv()) > pcmAbsDcaZLim.value[1]) { + return false; + } + return true; + } + + // checks pipm selection (just pid (no additional track cuts) + bool checkPipmTPCTOF(auto const& track) + { + // too low for tof + if (track.pt() < piPidLowPt) { + return (track.tpcNSigmaPi() > nSigmaPiTpcLowPt.value[0] && track.tpcNSigmaPi() < nSigmaPiTpcLowPt.value[1]); + } + // Bethe-Bloch overlap (-> tpc + tof) + if (track.pt() < piPidHighPt) { + if (track.hasTOF()) { // has to stay inside pt-if due to return-layout of function + if (track.tpcNSigmaPi() > nSigmaPiTpcMidPt.value[0] && track.tpcNSigmaPi() < nSigmaPiTpcMidPt.value[1] && + track.tofNSigmaPi() > nSigmaPiTof.value[0] && track.tofNSigmaPi() < nSigmaPiTof.value[1]) { + return true; + } + } + return false; + } + // Bethe-Bloch rel rise (too high for tof) + return (track.tpcNSigmaPi() > nSigmaPiRelRise.value[0] && track.tpcNSigmaPi() < nSigmaPiRelRise.value[1]); + } + + // checks pipm selection (just pid (no additional track cuts)) + bool checkPipmTPC(auto const& track) + { + // Bethe-Bloch rel rise + if (track.pt() > piPidHighPt) { + if (track.tpcNSigmaPi() > nSigmaPiRelRise.value[0] && track.tpcNSigmaPi() < nSigmaPiRelRise.value[1]) { + return true; + } + } + return false; + } + + // reco MC ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + + // checks if mcParticle is charged + bool isCharged(auto const& mcParticle) + { + auto const pdgParticle = pdg->GetParticle(mcParticle.pdgCode()); + return pdgParticle && pdgParticle->Charge() != 0; + } + // checks if fast decaying mcParticle is 'primary' + bool isDecayPrimary(auto const& mcParticle) + { + // identify decaying primary + return mcParticle.producedByGenerator(); + } + + // check if particle has mother in parent tree + // returns optional pt of mother + std::optional checkForMother(auto const& mcParticle, int const pdgCode, bool const checkAntiParticle, bool const includePreHadronisation = true) + { + if (!mcParticle.has_mothers()) { + return std::nullopt; + } + auto const mothers = mcParticle.template mothers_as(); + for (auto const& mother : mothers) { + // optional exclude pre-hadonisation + int const statusPreHadronisationCut = 80; + if (!includePreHadronisation && mother.producedByGenerator() && std::abs(mother.getGenStatusCode()) < statusPreHadronisationCut) { + return std::nullopt; + } + if (mother.pdgCode() == pdgCode || (checkAntiParticle && mother.pdgCode() == -pdgCode)) { + return mother.pt(); + } + if (auto const ptMother = checkForMother(mother, pdgCode, checkAntiParticle, includePreHadronisation)) { + return ptMother; + } + } + return std::nullopt; + } + + // checks if tracks come from photon conversion + template + bool isConversionPhoton(T_track const& posTrack, T_track const& negTrack) + { + auto const& posParticle = posTrack.mcParticle(); + auto const& negParticle = negTrack.mcParticle(); + if (!posParticle.has_mothers() || !negParticle.has_mothers()) { + return false; + } + // check same mother + auto const& posMothers = posParticle.template mothers_as(); + auto const& negMothers = negParticle.template mothers_as(); + if (posMothers.begin()->globalIndex() != negMothers.begin()->globalIndex()) { + return false; + } + // check photon + if (posMothers.begin()->pdgCode() != PDG_t::kGamma) { + return false; + } + + return true; + }; + // checks if tracks come from double conversion + template + bool isGGFromDoubleConversion(T_track const& posTrack1, T_track const& negTrack1, T_track const& posTrack2, T_track const& negTrack2, int const pdgCode) + { + // check conversion + if (!isConversionPhoton(posTrack1, negTrack1) || !isConversionPhoton(posTrack2, negTrack2)) { + return false; + } + auto const& photons1 = posTrack1.mcParticle().template mothers_as(); + auto const& photons2 = posTrack2.mcParticle().template mothers_as(); + if (!photons1.begin()->has_mothers() || !photons2.begin()->has_mothers()) { + return false; + } + auto const& mothers1 = photons1.begin()->template mothers_as(); + auto const& mothers2 = photons2.begin()->template mothers_as(); + // check same mother of photons + if (mothers1.begin()->globalIndex() != mothers2.begin()->globalIndex()) { + return false; + } + // check particle type + if (mothers1.begin()->pdgCode() != pdgCode) { + return false; + } + + return true; + }; + + // get highest reco truthLevel particle canidate + + template + TruthLevelInfo getMcRecoInfoHadronPipm(auto const& collision, auto const& track) + { + if (!track.has_mcParticle()) { + histos.fill(HIST("info/h1_noMatch_assoc"), 0.5); + return {TruthLevel::Reco, -1}; + } + auto const& mcParticle = track.mcParticle(); + if (mcParticle.mcCollisionId() != collision.mcCollisionId()) { + return {TruthLevel::RecoMcMatched, -1}; + } + if constexpr (AssocTypeV == AssocType::Hadron) { + if (!isCharged(mcParticle) || !mcParticle.isPhysicalPrimary()) { + return {TruthLevel::RecoAssocEv, -1}; + } + } else if constexpr (AssocTypeV == AssocType::Pipm) { + if (std::abs(mcParticle.pdgCode()) != PDG_t::kPiPlus || !mcParticle.isPhysicalPrimary()) { + return {TruthLevel::RecoAssocEv, -1}; + } + } else { + static_assert(AlwaysFalseValue, "assocType not found"); + } + double const ptTruePure = mcParticle.pt(); + return {TruthLevel::RecoPure, ptTruePure}; + } + std::tuple getMcRecoInfoPhoton(auto const& collision, auto const& v0Photon, auto const& tracks) + { + TruthLevelInfo truthLevelInfo; + PhotonImpurityInfo impurityInfo; + + auto const [posTrack, negTrack] = getV0LegJetTracks(v0Photon, tracks); + if (!posTrack.has_mcParticle() || !negTrack.has_mcParticle()) { + histos.fill(HIST("info/h1_noMatch_assoc"), 0.5); + truthLevelInfo.truthLevel = TruthLevel::Reco; + return {truthLevelInfo, impurityInfo}; + } + if (posTrack.mcParticle().mcCollisionId() != collision.mcCollisionId() || negTrack.mcParticle().mcCollisionId() != collision.mcCollisionId()) { + truthLevelInfo.truthLevel = TruthLevel::RecoMcMatched; + impurityInfo.impurity = PhotonImpurity::WrongEv; + return {truthLevelInfo, impurityInfo}; + } + auto const& photons = posTrack.mcParticle().template mothers_as(); + bool const isPhoton = isConversionPhoton(posTrack, negTrack); + if (!isPhoton || !photons.begin()->isPhysicalPrimary()) { + truthLevelInfo.truthLevel = TruthLevel::RecoAssocEv; + if (!isPhoton) { + impurityInfo.impurity = PhotonImpurity::MisId; + } else { + if (auto const ptMother = checkForMother(*(photons.begin()), PDG_t::kK0Short, true, false)) { + impurityInfo.impurity = PhotonImpurity::K0Short; + impurityInfo.ptTrueOrigin = *ptMother; + } else if (auto const ptMother = checkForMother(*(photons.begin()), PDG_t::kK0Long, true, false)) { + impurityInfo.impurity = PhotonImpurity::K0Long; + impurityInfo.ptTrueOrigin = *ptMother; + } else if (auto const ptMother = checkForMother(*(photons.begin()), PDG_t::kLambda0, true, false)) { + impurityInfo.impurity = PhotonImpurity::Lambda0; + impurityInfo.ptTrueOrigin = *ptMother; + } else { + impurityInfo.impurity = PhotonImpurity::Other; + } + } + return {truthLevelInfo, impurityInfo}; + } + truthLevelInfo.truthLevel = TruthLevel::RecoPure; + truthLevelInfo.ptTruePure = photons.begin()->pt(); + impurityInfo.impurity = PhotonImpurity::Pure; + return {truthLevelInfo, impurityInfo}; + } + template + std::tuple getMcRecoInfoDiPhoton(auto const& collision, auto const& v0Photon1, auto const& v0Photon2, auto const& tracks) + { + TruthLevelInfo truthLevelInfo; + PhotonImpurityInfo impurityInfo; + + int constexpr PdgCode = []() { + if constexpr (AssocTypeV == AssocType::Pi0Pcm) { + return PDG_t::kPi0; + } else if constexpr (AssocTypeV == AssocType::EtaPcm) { + return constants::physics::Pdg::kEta; + } else { + static_assert(AlwaysFalseValue, "assocType not found"); + } + }(); + auto const [posTrack1, negTrack1] = getV0LegJetTracks(v0Photon1, tracks); + auto const [posTrack2, negTrack2] = getV0LegJetTracks(v0Photon2, tracks); + if (!posTrack1.has_mcParticle() || !negTrack1.has_mcParticle() || !posTrack2.has_mcParticle() || !negTrack2.has_mcParticle()) { + histos.fill(HIST("info/h1_noMatch_assoc"), 0.5); + truthLevelInfo.truthLevel = TruthLevel::Reco; + return {truthLevelInfo, impurityInfo}; + } + if (!isGGFromDoubleConversion(posTrack1, negTrack1, posTrack2, negTrack2, PdgCode)) { + truthLevelInfo.truthLevel = TruthLevel::RecoMcMatched; + return {truthLevelInfo, impurityInfo}; + } + if (posTrack1.mcParticle().mcCollisionId() != collision.mcCollisionId()) { + truthLevelInfo.truthLevel = TruthLevel::PseudoReco; + if constexpr (AssocTypeV == AssocType::Pi0Pcm) { + impurityInfo.impurity = PhotonImpurity::WrongEv; + } + return {truthLevelInfo, impurityInfo}; + } + // note: do not dereference 'mothers' and store element in 'const&' (leads to seg fault) + auto const& photons1 = posTrack1.mcParticle().template mothers_as(); + auto const& mothersOfPhoton = photons1.begin()->template mothers_as(); + if (!isDecayPrimary(*(mothersOfPhoton.begin()))) { + truthLevelInfo.truthLevel = TruthLevel::PseudoRecoAssocEv; + if constexpr (AssocTypeV == AssocType::Pi0Pcm) { + if (auto const ptMother = checkForMother(*(photons1.begin()), PDG_t::kK0Short, true, false)) { + impurityInfo.impurity = PhotonImpurity::K0Short; + impurityInfo.ptTrueOrigin = *ptMother; + } else if (auto const ptMother = checkForMother(*(photons1.begin()), PDG_t::kK0Long, true, false)) { + impurityInfo.impurity = PhotonImpurity::K0Long; + impurityInfo.ptTrueOrigin = *ptMother; + } else if (auto const ptMother = checkForMother(*(photons1.begin()), PDG_t::kLambda0, true, false)) { + impurityInfo.impurity = PhotonImpurity::Lambda0; + impurityInfo.ptTrueOrigin = *ptMother; + } else { + impurityInfo.impurity = PhotonImpurity::Other; + } + } + return {truthLevelInfo, impurityInfo}; + } + truthLevelInfo.truthLevel = TruthLevel::PseudoRecoPure; + truthLevelInfo.ptTruePure = mothersOfPhoton.begin()->pt(); + if constexpr (AssocTypeV == AssocType::Pi0Pcm) { + impurityInfo.impurity = PhotonImpurity::Pure; + } + return {truthLevelInfo, impurityInfo}; + } + + // other ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + + // mc split event selection based in the thrid and fourth decimal of mc-true posZ + // returns reco value in case of no mc match + int getThirdFourthDecimalTruePosZ(auto const& collision) + { + double absPosZ = -1; + + // get third decimal + if constexpr (IsCollisionMCD) { + if (!collision.has_mcCollision()) { + absPosZ = std::abs(collision.posZ()); + } else { + absPosZ = std::abs(collision.template mcCollision_as().posZ()); + } + } else if constexpr (IsMcCollision) { + absPosZ = std::abs(collision.posZ()); + } else { + static_assert(AlwaysFalseType, "collision type not allowed"); + } + int const thirdFourthDecimalPosZ = static_cast(10000 * absPosZ) % 100; + + return thirdFourthDecimalPosZ; + } + + // analysis ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + void init(InitContext const&) + { + // selection JE utilities + eventSelectionBits = jetderiveddatautilities::initialiseEventSelectionBits(static_cast(eventSelections)); + trackSelection = jetderiveddatautilities::initialiseTrackSelection(static_cast(trackSelections)); + triggerMaskBits = jetderiveddatautilities::initialiseTriggerMaskBits(triggerMasks); + + // check config + + // doprocess combinations + + if (static_cast(doprocessRecoCollisionTrigger) + static_cast(doprocessMcRecoCollisionTrigger) > 1) { + throw std::runtime_error("invalid doprocess-collisionTrigger config"); + } + if (static_cast(doprocessRecoHadronPipmTPCTOF) + static_cast(doprocessMcRecoHadronPipmTPCTOF) + + static_cast(doprocessRecoHadronPipmTPC) + static_cast(doprocessMcRecoHadronPipmTPC) > + 1) { + throw std::runtime_error("invalid doprocess-hadronPipm config"); + } + if (static_cast(doprocessRecoPhotonPcm) + static_cast(doprocessMcRecoPhotonPcm) > 1) { + throw std::runtime_error("invalid doprocess-photonPcm config"); + } + + // histograms + AxisSpec const axisN{1, 0., 1., "#it{N}_{something}"}; + AxisSpec const axisZPv{40, -10, 10, "#it{z}_{pv}"}; + AxisSpec const axisMult{101, -0.5, 100.5, "multiplicity"}; + AxisSpec const axisHadronicRate{1001, -0.5, 1000.5, "hadronicRate"}; + AxisSpec const axisPt{200, 0, 100, "#it{p}_{T}"}; + AxisSpec const axisPhi{72, 0, constants::math::TwoPI, "#varphi"}; + AxisSpec const axisEta{64, -absEtaMax, absEtaMax, "#eta"}; + AxisSpec const axisMgg{240, 0, 0.8, "#it{m}_{#gamma#gamma}"}; + // reco + histos.add("reco/h2_zPvMult", "h2_zPvMult", kTH2D, {axisZPv, axisMult}, true); + histos.add("reco/h1_hadronicRate", "h1_hadronicRate", kTH1D, {axisHadronicRate}, true); + histos.add("reco/h3_ptPhiEta_trigger", "h3_ptPhiEta_trigger", kTH3D, {axisPt, axisPhi, axisEta}, true); + histos.add("reco/h3_ptPhiEta_hadron", "h3_ptPhiEta_hadron", kTH3D, {axisPt, axisPhi, axisEta}, true); + histos.add("reco/h3_ptPhiEta_pipm", "h3_ptPhiEta_pipm", kTH3D, {axisPt, axisPhi, axisEta}, true); + histos.add("reco/h3_ptPhiEta_photonPcm", "h3_ptPhiEta_photonPcm", kTH3D, {axisPt, axisPhi, axisEta}, true); + histos.add("reco/h3_ptPhiEta_photonPcmPair", "h3_ptPhiEta_photonPcmPair", kTH3D, {axisPt, axisPhi, axisEta}, true); + // true + histos.add("true/h2_zPvMult", "h2_zPvMult", kTH2D, {axisZPv, axisMult}, true); + histos.add("true/h3_ptPhiEta_trigger", "h3_ptPhiEta_trigger", kTH3D, {axisPt, axisPhi, axisEta}, true); + // info + // count missing mc match (should be 0 in output) + histos.add("info/h1_noMatch_assoc", "h1_noMatch_assoc", kTH1D, {axisN}, true); + } + + void fillProcessRecoCollisionTrigger(auto const& collisions, auto const& tracks) + { + // clear mapping at start of dataframe (in first process) + jetToHpcCollisionMap.clear(); + trackToTriggerMap.clear(); + + for (auto const& collision : collisions) { + // skip non-triggered events + if (!jetderiveddatautilities::selectTrigger(collision, triggerMaskBits)) { + continue; + } + // event selection + bool const isSelectedEvent = checkEventSelection(collision); + + // group collision + auto const tracksThisEvent = tracks.sliceBy(perColTracks, collision.globalIndex()); + + // mc split event selection n + // default 1 for data reconstruction + int nSelectSplitMcEv = 1; + if constexpr (IsCollisionMCD) { + nSelectSplitMcEv = getThirdFourthDecimalTruePosZ(collision) % nTimesSplitMcEv.value + 1; + } + // maximum track pt + float maxTrackPt = -1; + int maxTriggerGlobalIndex = -1; + float maxTriggerPhi = 0; + float maxTriggerEta = 0; + // number global tracks + int nGlobalTracks = 0; + + // count global tracks (for independence of multiplicity task (uses only JE derieved data)) + for (auto const& track : tracksThisEvent) { + // track selection + if (!checkTrackCuts(track)) { + continue; + } + + nGlobalTracks++; + if (track.pt() > maxTrackPt) { + maxTrackPt = track.pt(); + maxTriggerGlobalIndex = track.globalIndex(); + maxTriggerPhi = track.phi(); + maxTriggerEta = track.eta(); + } + + if (!isSelectedEvent) { + continue; + } + if (track.pt() < ptTrigMin) { + continue; + } + if (oneTriggerPerEvent) { + continue; + } + + // trigger info + histos.fill(HIST("reco/h3_ptPhiEta_trigger"), track.pt(), track.phi(), track.eta()); + tableProduction.trigger(tableProduction.collision.lastIndex() + 1, + track.pt(), track.phi(), track.eta()); + tableProduction.triggerTrackId(track.globalIndex()); + trackToTriggerMap[track.globalIndex()] = tableProduction.trigger.lastIndex(); + } + bool const isTriggerEvent = maxTrackPt > ptTrigMin; + if (oneTriggerPerEvent && isSelectedEvent && isTriggerEvent) { + histos.fill(HIST("reco/h3_ptPhiEta_trigger"), maxTrackPt, maxTriggerPhi, maxTriggerEta); + tableProduction.trigger(tableProduction.collision.lastIndex() + 1, + maxTrackPt, maxTriggerPhi, maxTriggerEta); + tableProduction.triggerTrackId(maxTriggerGlobalIndex); + trackToTriggerMap[maxTriggerGlobalIndex] = tableProduction.trigger.lastIndex(); + } + + // collision info + histos.fill(HIST("reco/h2_zPvMult"), collision.posZ(), nGlobalTracks); + histos.fill(HIST("reco/h1_hadronicRate"), collision.hadronicRate()); + tableProduction.collision(isSelectedEvent, nSelectSplitMcEv, isTriggerEvent, maxTrackPt, collision.posZ(), nGlobalTracks); + tableProduction.collisionId(collision.globalIndex()); + // mc true collsion label + if constexpr (IsCollisionMCD) { + tableProduction.collisionMcId(collision.mcCollisionId()); + } + jetToHpcCollisionMap[collision.globalIndex()] = tableProduction.collision.lastIndex(); + } + } + + void processRecoCollisionTrigger(soa::Join const& collisions, aod::JetTracks const& tracks) + { + fillProcessRecoCollisionTrigger(collisions, tracks); + } + PROCESS_SWITCH(HadronPhotonProducer, processRecoCollisionTrigger, "process correlation collision_extra and trigger table (reconstructed)", false); + + void processMcRecoCollisionTrigger(soa::Join const& collisions, aod::JetTracks const& tracks, aod::JetMcCollisions const&) + { + fillProcessRecoCollisionTrigger(collisions, tracks); + } + PROCESS_SWITCH(HadronPhotonProducer, processMcRecoCollisionTrigger, "process correlation collision_extra and trigger table (reconstructed MC)", false); + + template + void fillProcessRecoHadronPipm(auto const& collisions, auto const& tracks) + { + for (auto const& collision : collisions) { + // skip non-triggered events + if (!jetderiveddatautilities::selectTrigger(collision, triggerMaskBits)) { + continue; + } + // event selection + if (!checkEventSelection(collision)) { + continue; + } + + // group collision + auto const tracksThisEvent = tracks.sliceBy(perColTracks, collision.globalIndex()); + + // hadron/pipm + for (auto const& track : tracksThisEvent) { + // track selection + if (!checkTrackCuts(track)) { + continue; + } + + // get possible overlap with triggers + std::vector const intersectTriggerIds = getIntersectTriggerIds({track}); + + // mc reco info + TruthLevelInfo const truthLevelInfoHadron = [&] { + if constexpr (IsCollisionMCD) { + return getMcRecoInfoHadronPipm(collision, track); + } else { + return TruthLevelInfo{}; + } + }(); + + // hadron info + if (track.pt() > ptMinHadron) { + histos.fill(HIST("reco/h3_ptPhiEta_hadron"), track.pt(), track.phi(), track.eta()); + tableProduction.hadron(jetToHpcCollisionMap.at(collision.globalIndex()), intersectTriggerIds, + track.pt(), track.phi(), track.eta(), + static_cast(truthLevelInfoHadron.truthLevel), truthLevelInfoHadron.ptTruePure); + tableProduction.hadronTrackId(track.globalIndex()); + } + + // pipm selection + auto const& trackPid = track.template track_as(); + if constexpr (requires { trackPid.tofNSigmaPi(); }) { + if (!checkPipmTPCTOF(trackPid)) { + continue; + } + } else { + if (!checkPipmTPC(trackPid)) { + continue; + } + } + + // mc reco info + TruthLevelInfo const truthLevelInfoPipm = [&] { + if constexpr (IsCollisionMCD) { + return getMcRecoInfoHadronPipm(collision, track); + } else { + return TruthLevelInfo{}; + } + }(); + + // pipm info + histos.fill(HIST("reco/h3_ptPhiEta_pipm"), track.pt(), track.phi(), track.eta()); + tableProduction.pipm(jetToHpcCollisionMap.at(collision.globalIndex()), intersectTriggerIds, + track.pt(), track.phi(), track.eta(), + static_cast(truthLevelInfoPipm.truthLevel), truthLevelInfoPipm.ptTruePure); + tableProduction.pipmTrackId(track.globalIndex()); + } + } + } + + void processRecoHadronPipmTPCTOF(aod::JetCollisions const& collisions, + soa::Join const& tracks, soa::Join const&) + { + fillProcessRecoHadronPipm>(collisions, tracks); + } + PROCESS_SWITCH(HadronPhotonProducer, processRecoHadronPipmTPCTOF, "process hadron and pipm (TPC-TOF) table (reconstructed)", false); + + void processMcRecoHadronPipmTPCTOF(aod::JetCollisionsMCD const& collisions, + soa::Join const& tracks, soa::Join const&, + aod::JetParticles const&) + { + fillProcessRecoHadronPipm>(collisions, tracks); + } + PROCESS_SWITCH(HadronPhotonProducer, processMcRecoHadronPipmTPCTOF, "process hadron and pipm (TPC-TOF) table (reconstructed MC)", false); + + void processRecoHadronPipmTPC(aod::JetCollisions const& collisions, + soa::Join const& tracks, soa::Join const&) + { + fillProcessRecoHadronPipm>(collisions, tracks); + } + PROCESS_SWITCH(HadronPhotonProducer, processRecoHadronPipmTPC, "process hadron and pipm (TPC) table (reconstructed)", false); + + void processMcRecoHadronPipmTPC(aod::JetCollisionsMCD const& collisions, + soa::Join const& tracks, soa::Join const&, + aod::JetParticles const&) + { + fillProcessRecoHadronPipm>(collisions, tracks); + } + PROCESS_SWITCH(HadronPhotonProducer, processMcRecoHadronPipmTPC, "process hadron and pipm (TPC) table (reconstructed MC)", false); + + void fillProcessRecoPhotonPcm(auto const& collisions, auto const& v0Photons, auto const& tracks) + { + for (auto const& collision : collisions) { + // skip non-triggered events + if (!jetderiveddatautilities::selectTrigger(collision, triggerMaskBits)) { + continue; + } + // event selection + if (!checkEventSelection(collision)) { + continue; + } + + // photonsPcm (for some reason collisionId not an index column (?)) + auto const v0PhotonsThisEvent = v0Photons.sliceBy(perColV0Photons, collision.collisionId()); + + // photonPcm + for (auto const& v0Photon : v0PhotonsThisEvent) { + // photon selection + if (!checkPhotonEtaDcaZ(v0Photon)) { + continue; + } + + // get legs and check v0Leg-jetTrack match + auto const [posTrack, negTrack] = getV0LegJetTracks(v0Photon, tracks); + + // get possible overlap with triggers + std::vector const intersectTriggerIds = getIntersectTriggerIds({posTrack, negTrack}); + + // mc reco info + auto const [truthLevelInfoPhotonPcm, impurityInfoPhotonPcm] = [&] { + if constexpr (IsCollisionMCD) { + return getMcRecoInfoPhoton(collision, v0Photon, tracks); + } else { + return std::tuple{TruthLevelInfo{}, PhotonImpurityInfo{}}; + } + }(); + + // photonPcm info + histos.fill(HIST("reco/h3_ptPhiEta_photonPcm"), v0Photon.pt(), v0Photon.phi(), v0Photon.eta()); + tableProduction.photonPcm(jetToHpcCollisionMap.at(collision.globalIndex()), intersectTriggerIds, + v0Photon.pt(), v0Photon.phi(), v0Photon.eta(), + static_cast(truthLevelInfoPhotonPcm.truthLevel), truthLevelInfoPhotonPcm.ptTruePure, + static_cast(impurityInfoPhotonPcm.impurity), impurityInfoPhotonPcm.ptTrueOrigin); + tableProduction.photonPcmTrackId(posTrack.globalIndex(), negTrack.globalIndex()); + tableProduction.photonPcmV0PhotonId(v0Photon.globalIndex()); + } + + // photonPcmPair + for (auto const& [v0Photon1, v0Photon2] : soa::combinations(soa::CombinationsStrictlyUpperIndexPolicy(v0PhotonsThisEvent, v0PhotonsThisEvent))) { + // get kinematics + ROOT::Math::PtEtaPhiMVector const p4V0Pcm1(v0Photon1.pt(), v0Photon1.eta(), v0Photon1.phi(), 0.); + ROOT::Math::PtEtaPhiMVector const p4V0Pcm2(v0Photon2.pt(), v0Photon2.eta(), v0Photon2.phi(), 0.); + ROOT::Math::PtEtaPhiMVector const p4V0PcmPair = p4V0Pcm1 + p4V0Pcm2; + + // pair selection + if (!checkPhotonEtaDcaZ(v0Photon1) || !checkPhotonEtaDcaZ(v0Photon2)) { + continue; + } + if (std::abs(p4V0PcmPair.Eta()) > absEtaMax) { + continue; + } + + // get legs and check v0Leg-jetTrack match + auto const [posTrack1, negTrack1] = getV0LegJetTracks(v0Photon1, tracks); + auto const [posTrack2, negTrack2] = getV0LegJetTracks(v0Photon2, tracks); + + // get possible overlap with triggers + std::vector const intersectTriggerIds = getIntersectTriggerIds({posTrack1, negTrack1, posTrack2, negTrack2}); + + // mc reco info + auto const [truthLevelInfoPi0Pcm, photonImpurityInfoPi0Pcm] = [&] { + if constexpr (IsCollisionMCD) { + return getMcRecoInfoDiPhoton(collision, v0Photon1, v0Photon2, tracks); + } else { + return std::tuple{TruthLevelInfo{}, PhotonImpurityInfo{}}; + } + }(); + TruthLevelInfo const truthLevelInfoEtaPcm = [&] { + if constexpr (IsCollisionMCD) { + return std::get<0>(getMcRecoInfoDiPhoton(collision, v0Photon1, v0Photon2, tracks)); + } else { + return TruthLevelInfo{}; + } + }(); + double const ptTruePurePhotonPcmPair = std::max(truthLevelInfoPi0Pcm.ptTruePure, truthLevelInfoEtaPcm.ptTruePure); + + // photonPcmPair info + histos.fill(HIST("reco/h3_ptPhiEta_photonPcmPair"), p4V0PcmPair.Pt(), RecoDecay::constrainAngle(p4V0PcmPair.Phi(), 0), p4V0PcmPair.Eta()); + tableProduction.photonPcmPair(jetToHpcCollisionMap.at(collision.globalIndex()), intersectTriggerIds, + p4V0PcmPair.Pt(), RecoDecay::constrainAngle(p4V0PcmPair.Phi(), 0), p4V0PcmPair.Eta(), p4V0PcmPair.M(), + static_cast(truthLevelInfoPi0Pcm.truthLevel), static_cast(truthLevelInfoEtaPcm.truthLevel), ptTruePurePhotonPcmPair, + static_cast(photonImpurityInfoPi0Pcm.impurity), photonImpurityInfoPi0Pcm.ptTrueOrigin); + tableProduction.photonPcmPairTrackId(posTrack1.globalIndex(), negTrack1.globalIndex(), posTrack2.globalIndex(), negTrack2.globalIndex()); + tableProduction.photonPcmPairV0PhotonId(v0Photon1.globalIndex(), v0Photon2.globalIndex()); + } + } + } + + void processRecoPhotonPcm(soa::Join const& collisions, + aod::V0PhotonsKF const& v0Photons, aod::V0Legs const&, soa::Join const& tracks) + { + fillProcessRecoPhotonPcm(collisions, v0Photons, tracks); + } + PROCESS_SWITCH(HadronPhotonProducer, processRecoPhotonPcm, "process photonPcm table (reconstructed)", false); + + void processMcRecoPhotonPcm(soa::Join const& collisions, + aod::V0PhotonsKF const& v0Photons, aod::V0Legs const&, soa::Join const& tracks, + aod::JetParticles const&) + { + fillProcessRecoPhotonPcm(collisions, v0Photons, tracks); + } + PROCESS_SWITCH(HadronPhotonProducer, processMcRecoPhotonPcm, "process photonPcm table (reconstructed MC)", false); + + void processMcCorrTables(aod::JetMcCollisions const& mcCollisions, aod::JetParticles const& mcParticles) + { + for (auto const& mcCollision : mcCollisions) { + // event selection true + bool const isSelectedEvent = !skipMBGapEvents || mcCollision.getSubGeneratorId() != jetderiveddatautilities::JCollisionSubGeneratorId::mbGap; + + // group collision + auto const mcParticlesThisEvent = mcParticles.sliceBy(perColMcParticles, mcCollision.globalIndex()); + + // mc split event selection + int const nSelectSplitMcEv = getThirdFourthDecimalTruePosZ(mcCollision) % nTimesSplitMcEv.value + 1; + // maximum charged particle pt + float maxChargedPt = -1; + int maxTriggerGlobalIndex = -1; + float maxTriggerPhi = 0; + float maxTriggerEta = 0; + // number charged particles in eta range + int nCharged = 0; + + // particle loop + for (auto const& mcParticle : mcParticlesThisEvent) { + // track selection + auto const pdgParticle = pdg->GetParticle(mcParticle.pdgCode()); + if (!pdgParticle || pdgParticle->Charge() == 0) { + continue; + } + if (!mcParticle.isPhysicalPrimary()) { + continue; + } + if (std::abs(mcParticle.eta()) > absEtaMax || mcParticle.pt() < ptMinTrack) { + continue; + } + + nCharged++; + if (mcParticle.pt() > maxChargedPt) { + maxChargedPt = mcParticle.pt(); + maxTriggerGlobalIndex = mcParticle.globalIndex(); + maxTriggerPhi = mcParticle.phi(); + maxTriggerEta = mcParticle.eta(); + } + + // trigger selection + if (mcParticle.pt() < ptTrigMin) { + continue; + } + if (oneTriggerPerEvent) { + continue; + } + + // trigger info + histos.fill(HIST("true/h3_ptPhiEta_trigger"), mcParticle.pt(), mcParticle.phi(), mcParticle.eta()); + tableProduction.trueTrigger(mcCollision.globalIndex(), mcParticle.globalIndex(), + mcParticle.pt(), mcParticle.phi(), mcParticle.eta()); + } + bool const isTriggerEvent = maxChargedPt > ptTrigMin; + if (oneTriggerPerEvent && isTriggerEvent) { + histos.fill(HIST("true/h3_ptPhiEta_trigger"), maxChargedPt, maxTriggerPhi, maxTriggerEta); + tableProduction.trueTrigger(mcCollision.globalIndex(), maxTriggerGlobalIndex, + maxChargedPt, maxTriggerPhi, maxTriggerEta); + } + + // collision info + histos.fill(HIST("true/h2_zPvMult"), mcCollision.posZ(), nCharged); + tableProduction.mcCollisionExtraCorr(isSelectedEvent, nSelectSplitMcEv, isTriggerEvent, maxChargedPt, nCharged); + } + } + PROCESS_SWITCH(HadronPhotonProducer, processMcCorrTables, "process table production (mc)", false); +}; + +WorkflowSpec defineDataProcessing(ConfigContext const& configContext) +{ + return WorkflowSpec{adaptAnalysisTask(configContext)}; +} diff --git a/PWGJE/Tasks/photonChargedTriggerCorrelation.cxx b/PWGJE/Tasks/photonChargedTriggerCorrelation.cxx deleted file mode 100644 index 943bc742517..00000000000 --- a/PWGJE/Tasks/photonChargedTriggerCorrelation.cxx +++ /dev/null @@ -1,2512 +0,0 @@ -// 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 photonChargedTriggerCorrelation.cxx -/// \author Julius Kinner -/// \brief photon-jet angular correlation analysis -/// -/// Analysis for angular correlations between jets and photons via two-particle correlations with charged high-pt triggers -/// Associated hadrons (tracks), pipm, photons (PCM), pi0 (PCM) -/// Also contains checks and monte-carlo (efficiency, purity, mc-true correlation,...) -/// End goal of studying correlations between direct photons and jets - -#include "PWGJE/DataModel/PhotonChargedTriggerCorrelation.h" - -#include "PWGJE/DataModel/Jet.h" -#include "PWGJE/DataModel/JetReducedData.h" -// -#include "PWGEM/PhotonMeson/DataModel/gammaTables.h" - -#include "Common/Core/RecoDecay.h" -#include "Common/Core/TableHelper.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include // IWYU pragma: keep (do not replace with Math/Vector4Dfwd.h) -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace o2; -using namespace o2::framework; - -using CorrCollisions = soa::Join; -using CorrCollision = CorrCollisions::iterator; -using CorrMcDCollisions = soa::Join; -using CorrMcDCollision = CorrMcDCollisions::iterator; -using CorrMcCollisions = soa::Join; -using CorrMcCollision = CorrMcCollisions::iterator; - -using BinningZPvMult = ColumnBinningPolicy; - -// correlation analysis /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// =/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/ - -const double absEtaMaxDefault = 0.8; - -struct PhotonChargedTriggerCorrelation { - // configurables - - // general (kenobi) - Configurable pathCcdbCorrection{"pathCcdbCorrection", "Users/j/jkinner/correction/set_in_config", "base path to the ccdb corrections"}; - Configurable urlCcdb{"urlCcdb", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; - Configurable noLaterThanCcdbConfig{"noLaterThanCcdbConfig", -1, "latest acceptable timestamp of creation for the object (-1 for task start time)"}; - Configurable splitMcEvN{"splitMcEvN", 1, "number of equal event fractions for selection in MC (max 10) | (select 1 for data)"}; - Configurable splitMcEvSelect{"splitMcEvSelect", 1, "selected event fraction number in MC (starts at 1) | (select 1 for data)"}; - - // analysis - Configurable applyCTotTrigger{"applyCTotTrigger", false, "whether to apply on-the-fly total correction factor for triggers"}; - Configurable doTrigEvMixing{"doTrigEvMixing", false, "whether to use trigger events for trigger mixing"}; - - Configurable nTriggerSavedForMixing{"nTriggerSavedForMixing", 8192, "number of triggers that are saved for mixing with other events"}; - Configurable nTriggerBinMinThreshold{"nTriggerBinMinThreshold", 128, "threshold minimum number of triggers in mixing bin required"}; - Configurable iTriggerStartFraction{"iTriggerStartFraction", 0.5, "ratio of bin size for randomised iTrigger start"}; - Configurable nTriggerScaleCoefficient{"nTriggerScaleCoefficient", 2, "coeffcient a in mixing-number pt power scaling"}; - Configurable nTriggerScaleExponent{"nTriggerScaleExponent", 2, "exponent a in mixing-number pt power scaling"}; - Configurable nMixingAt0McTrue{"nMixingAt0McTrue", 4, "number of triggers that are used for mc true mixing"}; - Configurable nMixingAt0Hadron{"nMixingAt0Hadron", 16, "number of triggers that are used for hadron mixing"}; - Configurable nMixingAt0Pipm{"nMixingAt0Pipm", 16, "number of triggers that are used for pipm mixing"}; - Configurable nMixingAt0PhotonPCM{"nMixingAt0PhotonPCM", 256, "number of triggers that are saved for photonPCM mixing"}; - Configurable nMixingAt0H0PCM{"nMixingAt0H0PCM", 1024, "number of triggers that are saved for h0PCM (pi0, eta) mixing"}; - - Configurable nNeighboursMixingPhotonPCMPair{"nNeighboursMixingPhotonPCMPair", 32, "number neighbours used for for photonPCM pair mixing"}; - Configurable> pi0PCMPeakMassRange{"pi0PCMPeakMassRange", {0.10, 0.15}, "photon-pair mass integration range for pi0PCM"}; - Configurable> pi0PCMSideMassRange{"pi0PCMSideMassRange", {0.16, 0.22}, "photon-pair mass integration range outside pi0PCM region"}; - Configurable> etaPCMPeakMassRange{"etaPCMPeakMassRange", {0.51, 0.56}, "photon-pair mass integration range for etaPCM"}; - Configurable> etaPCMLowSideMassRange{"etaPCMLowSideMassRange", {0.44, 0.48}, "photon-pair mass integration range below etaPCM region"}; - Configurable> etaPCMHighSideMassRange{"etaPCMHighSideMassRange", {0.58, 0.62}, "photon-pair mass integration range above etaPCM region"}; - - // for histograms - Configurable nBinsZPv{"nBinsZPv", 28, "number zPv bins in histos"}; - Configurable nBinsMult{"nBinsMult", 64, "number multiplicity bins in histos"}; - Configurable nBinsOccupancy{"nBinsOccupancy", 2000, "number occupancy bins in histos for QA"}; - - Configurable nBinsPhi{"nBinsPhi", 72, "number phi bins"}; - Configurable nBinsEta{"nBinsEta", 32, "number eta bins"}; - Configurable nBinsDCAz{"nBinsDCAz", 100, "number DCAz bins"}; - Configurable nBinsMgg{"nBinsMgg", 240, "number mass-photon-pair bins"}; - - Configurable> binsPtTrig{"binsPtTrig", {0, 5, 10, 25, 50, 100}, "correlation ptTrig bins"}; - Configurable> binsPtAssoc{"binsPtAssoc", - {0, 0.2, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 7.0, 8.0, 9.0, 10, - 12.5, 15, 17.5, 20, 25, 35, 50, 100}, - "correlation ptAssoc bins"}; - Configurable> binsDPhi{"binsDPhi", - {0.00 * constants::math::TwoPI - constants::math::PIHalf, - 0.05 * constants::math::TwoPI - constants::math::PIHalf, 0.10 * constants::math::TwoPI - constants::math::PIHalf, - 0.14 * constants::math::TwoPI - constants::math::PIHalf, 0.17 * constants::math::TwoPI - constants::math::PIHalf, - 0.20 * constants::math::TwoPI - constants::math::PIHalf, - 0.22 * constants::math::TwoPI - constants::math::PIHalf, 0.24 * constants::math::TwoPI - constants::math::PIHalf, - 0.26 * constants::math::TwoPI - constants::math::PIHalf, 0.28 * constants::math::TwoPI - constants::math::PIHalf, - 0.30 * constants::math::TwoPI - constants::math::PIHalf, - 0.33 * constants::math::TwoPI - constants::math::PIHalf, 0.36 * constants::math::TwoPI - constants::math::PIHalf, - 0.40 * constants::math::TwoPI - constants::math::PIHalf, 0.45 * constants::math::TwoPI - constants::math::PIHalf, - 0.50 * constants::math::TwoPI - constants::math::PIHalf, - 0.55 * constants::math::TwoPI - constants::math::PIHalf, 0.60 * constants::math::TwoPI - constants::math::PIHalf, - 0.64 * constants::math::TwoPI - constants::math::PIHalf, 0.68 * constants::math::TwoPI - constants::math::PIHalf, - 0.71 * constants::math::TwoPI - constants::math::PIHalf, - 0.74 * constants::math::TwoPI - constants::math::PIHalf, 0.76 * constants::math::TwoPI - constants::math::PIHalf, - 0.79 * constants::math::TwoPI - constants::math::PIHalf, - 0.82 * constants::math::TwoPI - constants::math::PIHalf, 0.86 * constants::math::TwoPI - constants::math::PIHalf, - 0.90 * constants::math::TwoPI - constants::math::PIHalf, 0.95 * constants::math::TwoPI - constants::math::PIHalf, - 1.00 * constants::math::TwoPI - constants::math::PIHalf}, - "correlation bins DeltaPhi"}; - Configurable> binsDEta{"binsDEta", - {0 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, - 2 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, 4 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, - 6 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, 8 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, - 9.5 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, 11 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, - 12.5 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, 14 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, - 15.5 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, 16.5 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, - 18 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, - 19.5 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, 21 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, - 22.5 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, 24 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, - 26 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, 28 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, - 30 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault, 32 / 32. * 4 * absEtaMaxDefault - 2 * absEtaMaxDefault}, - "correlation bins DeltaEta"}; - Configurable> binsZPvBinning{"binsZPvBinning", - {-7, -5, -3, -1, 1, 3, 5, 7}, - "zPv mixing bins"}; - Configurable> binsMultBinning{"binsMultBinning", - {-0.5, 10.5, 15.5, 20.5, 27.5, 42.5}, - "multiplicity mixing bins"}; - Configurable> binsZPvBinningMcTrue{"binsZPvBinningMcTrue", - {-10000, 10000}, - "zPv mixing bins for mc true"}; - Configurable> binsMultBinningMcTrue{"binsMultBinningMcTrue", - {-0.5, 16.5, 24.5, 31.5, 39.5, 64.5}, - "multiplicity mixing bins for mc true"}; - - // configurables from other tasks - - double absEtaMax = -1; - - // further variables - - std::mt19937 randomMt{3141u}; - int randomIntInInterval(int const lowEdgeInclusive, int const upEdgeInclusive) - { - return lowEdgeInclusive + (randomMt() % (upEdgeInclusive - lowEdgeInclusive + 1)); // speeds up task by factor > 2; modulo bias should not be relevant here - // return std::uniform_int_distribution(lowEdgeInclusive, upEdgeInclusive)(randomMt); - } - - // objects to hold histograms - HistogramRegistry histos{"histogramRegistry", {}, OutputObjHandlingPolicy::AnalysisObject, false, false}; - - // ccdb calls - int64_t noLaterThanCcdb = - noLaterThanCcdbConfig == -1 ? std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() : noLaterThanCcdbConfig; - Service ccdb{}; - // for mc - Service pdg{}; - - // partitions - SliceCache cache; - - // prepare for per collision slicing - Preslice perColTracks = aod::jtrack::collisionId; - Preslice perColTriggers = aod::corr_particle::jetCollisionId; - Preslice perColHadrons = aod::corr_particle::jetCollisionId; - Preslice perColPipms = aod::corr_particle::jetCollisionId; - Preslice perColPhotonPCMs = aod::corr_particle::jetCollisionId; - Preslice perColPhotonPCMPairs = aod::corr_particle::jetCollisionId; - Preslice perColMcParticles = aod::jmcparticle::mcCollisionId; - Preslice perColTriggerParticles = aod::corr_particle::jetMcCollisionId; - - // combinations binning - // cumbersome, but still better than having extra configurable or figuring out how to init binningZPvMult later while declaring it here - std::function(std::vector const&, double const)> prependValueToVector = - [](std::vector const& vec, double const value) { - std::vector resultVec = {value}; - resultVec.insert(resultVec.end(), vec.begin(), vec.end()); - return resultVec; - }; - BinningZPvMult binningZPvMult{{prependValueToVector(binsZPvBinning.value, VARIABLE_WIDTH), prependValueToVector(binsMultBinning.value, VARIABLE_WIDTH)}}; - - // declare analysis variables - - // correction histograms - TH1D* h1PtCorrectionTrigger = nullptr; - - // mixing trigger memory - struct MixingTrigger { - MixingTrigger(float pt, float phi, float eta) - : fPt(pt), fPhi(phi), fEta(eta) {} - float fPt, fPhi, fEta; - [[nodiscard]] float pt() const { return fPt; } - [[nodiscard]] float phi() const { return fPhi; } - [[nodiscard]] float eta() const { return fEta; } - }; - // class to handle trigger info from previous collisions (beyond single dataframe) - // organised as zPv- and mult-bin matrix of deque (pt, phi, eta) to save trigger info beyond single dataframe - // last mult bin open to account for overflow and adjusted zVtx limits to account for rounding errors -> all events accounted for - // (possibly replace by some advanced derived data method and O2 event mixing in future?) - class MixingTriggerMemory - { - public: - // finds bin that value belongs to (assumes ordered bin edges) (starts at 0; includes underflow (return -1) and overflow (return binEdges.size() - 1)) - // should be faster than some std binary search due to small number of bins (zPv, mult) - static int findIntervalBin(double value, const std::vector& binEdges) - { - if (binEdges.empty()) { - throw std::invalid_argument("binEdges in findIntervalBin"); - } - const int n = binEdges.size() - 1; - if (value < binEdges[0]) { - return -1; // underflow - } - for (int i_bin = 0; i_bin < n; i_bin++) { - if (value < binEdges[i_bin + 1]) { - return i_bin; - } - } - return n; // overflow - } - - MixingTriggerMemory(std::vector const& binEdgesZPvIn, std::vector const& binEdgesMultIn, size_t const nTriggerPerBinLimitIn) - : binEdgesZPv(binEdgesZPvIn), - nBinsZPv(binEdgesZPvIn.size() - 1), - binEdgesMult(binEdgesMultIn), - nBinsMult(binEdgesMultIn.size() - 1), - nTriggerPerBinLimit(nTriggerPerBinLimitIn) - { - int const nEdgesMin = 2; - if (binEdgesZPv.size() < nEdgesMin || binEdgesMult.size() < nEdgesMin) { - throw std::invalid_argument("too few bin edges to define zPv or mult bins"); - } - if (!std::is_sorted(binEdgesZPv.begin(), binEdgesZPv.end()) || !std::is_sorted(binEdgesMult.begin(), binEdgesMult.end())) { - throw std::invalid_argument("bin edges must be sorted"); - } - // prevent zPv over/underflow due to rounding errors - binEdgesZPv.front() = binEdgesZPv.front() < 0 ? binEdgesZPv.front() * zPvRoundingErrorAdjust : binEdgesZPv.front() / zPvRoundingErrorAdjust; - binEdgesZPv.back() = binEdgesZPv.back() > 0 ? binEdgesZPv.back() * zPvRoundingErrorAdjust : binEdgesZPv.back() / zPvRoundingErrorAdjust; - // init correct size of zPv-mult matrix - savedTriggersZPvMult.resize(nBinsZPv); - for (size_t i_zPv = 0; i_zPv < nBinsZPv; i_zPv++) { - savedTriggersZPvMult[i_zPv].resize(nBinsMult); - } - } - - // save trigger for mixing - // up to nTriggerPerBinLimit stored in rolling buffer for each zPv-mult bin - void saveTrigger(float const pt, float const phi, float const eta, double const zPv, double const mult) - { - int const iBinCorrZPv = getZPvBin(zPv); - int const iBinCorrMult = getMultBin(mult); - // fill - std::deque& triggerBin = savedTriggersZPvMult[iBinCorrZPv][iBinCorrMult]; - triggerBin.push_front(MixingTrigger{pt, phi, eta}); - if (triggerBin.size() > nTriggerPerBinLimit) { - triggerBin.pop_back(); - return; // skip nTriggerBinMin update when unnecessary - } - // update nTriggerBinMin - nTriggerBinMin = nTriggerPerBinLimit; - for (size_t i_zPv = 0; i_zPv < nBinsZPv; i_zPv++) { - for (size_t i_mult = 0; i_mult < nBinsMult; i_mult++) { - nTriggerBinMin = std::min(nTriggerBinMin, savedTriggersZPvMult[i_zPv][i_mult].size()); - } - } - } - - // return deques of trigger pt, phi, eta in the given zPv/mult bin - [[nodiscard]] std::deque const& getTriggers(double const zPv, double const mult) const - { - int const iBinCorrZPv = getZPvBin(zPv); - int const iBinCorrMult = getMultBin(mult); - return savedTriggersZPvMult[iBinCorrZPv][iBinCorrMult]; - } - - [[nodiscard]] size_t getBinSizeMin() const - { - return nTriggerBinMin; - } - - private: - double zPvRoundingErrorAdjust = 1.0001; - std::vector binEdgesZPv; - size_t nBinsZPv; - std::vector binEdgesMult; - size_t nBinsMult; - std::vector>> savedTriggersZPvMult; - size_t nTriggerPerBinLimit; - size_t nTriggerBinMin = 0; - - [[nodiscard]] size_t getZPvBin(double const zPv) const - { - int const iBinInit = findIntervalBin(zPv, binEdgesZPv); - if (iBinInit == -1 || iBinInit == static_cast(nBinsZPv)) { - throw std::runtime_error("zPv underflow or overflow in MixingTriggerMemory"); - } - return iBinInit; - } - [[nodiscard]] size_t getMultBin(double const mult) const - { - int const iBinInit = findIntervalBin(mult, binEdgesMult); - if (iBinInit == static_cast(nBinsMult)) { - return iBinInit - 1; - } - if (iBinInit == -1) { - throw std::runtime_error("mult underflow in MixingTriggerMemory"); - } - return iBinInit; - } - }; - - // different buffers for mixing modes - enum class TriggerMemoryMode { Reco, - True, - TrueAssocEv, - TrueAssocEvRecoPtTrig }; - - std::unique_ptr triggerMemoryReco; - std::unique_ptr triggerMemoryTrue; - std::unique_ptr triggerMemoryTrueAssocEv; - std::unique_ptr triggerMemoryTrueAssocEvRecoPtTrig; - - // functions //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ========================================================================================================================================================================================== - - // general (kenobi) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - - // get histograms from ccdb - // save corrections from ccdb in histogram registry - void initCcdbHistograms() - { - // trigger - h1PtCorrectionTrigger = nullptr; - if (applyCTotTrigger) { - h1PtCorrectionTrigger = ccdb->getForTimeStamp(pathCcdbCorrection.value + "/trigger", noLaterThanCcdb); - - const double* correctionBinsTrigger = h1PtCorrectionTrigger->GetXaxis()->GetXbins()->GetArray(); - const AxisSpec axisPtCorrectionTrigger{std::vector(correctionBinsTrigger, correctionBinsTrigger + h1PtCorrectionTrigger->GetNbinsX() + 1), "#it{p}_{T}"}; - histos.add("usedCorrection/h1_pt_correction_trigger_ccdb", "h1_pt_correction_trigger_ccdb", kTH1D, {axisPtCorrectionTrigger}, true); - for (int iBin = 1; iBin <= h1PtCorrectionTrigger->GetNbinsX(); iBin++) { - histos.get(HIST("usedCorrection/h1_pt_correction_trigger_ccdb"))->SetBinContent(iBin, h1PtCorrectionTrigger->GetBinContent(iBin)); - histos.get(HIST("usedCorrection/h1_pt_correction_trigger_ccdb"))->SetBinError(iBin, h1PtCorrectionTrigger->GetBinError(iBin)); - } - } - } - - // create histograms - void initHistograms() - { - // define axes - const AxisSpec axisN{1, 0., 1., "#it{N}_{something}"}; - const AxisSpec axisCategories{16, 0., 16., "categories"}; - - const AxisSpec axisZPv{nBinsZPv, -7, 7, "#it{z}_{pv}"}; - const AxisSpec axisMult{nBinsMult + 1, -0.5, nBinsMult + 0.5, "multiplicity"}; - const AxisSpec axisOccupancy{nBinsOccupancy + 1, -0.5, nBinsOccupancy + 0.5, "occupancy"}; - - const AxisSpec axisPhi{nBinsPhi, 0, constants::math::TwoPI, "#it{#varphi}"}; - const AxisSpec axisEta{nBinsEta, -absEtaMax, absEtaMax, "#it{#eta}"}; - const AxisSpec axisDCAz{nBinsDCAz, -5, 5, "DCA_{z}"}; - const AxisSpec axisMgg{nBinsMgg, 0, 0.8, "#it{m}_{#gamma#gamma}"}; - - const AxisSpec axisPtTrig{binsPtTrig, "#it{p}_{T}^{trig}"}; - const AxisSpec axisPtAssoc{binsPtAssoc, "#it{p}_{T}^{assoc}"}; - const AxisSpec axisDPhi{binsDPhi, "#Delta#it{#varphi}"}; - const AxisSpec axisDEta{binsDEta, "#Delta#it{#eta}"}; - const AxisSpec axisZPvBinning{binsZPvBinning, "#it{z}_{pv} correlation binning"}; - const AxisSpec axisMultBinning{binsMultBinning, "multiplicity correlation binning"}; - const AxisSpec axisZPvBinningMcTrue{binsZPvBinningMcTrue, "#it{z}_{pv} correlation binning for mc true"}; - const AxisSpec axisMultBinningMcTrue{binsMultBinningMcTrue, "multiplicity correlation binning for mc true"}; - - // reco info - histos.add("reco/info/h1_nEvents", "h1_nEvents", kTH1D, {axisCategories}, true); - histos.add("reco/info/h3_ptTrigZPvMult", "h3_ptTrigZPvMult", kTHnSparseD, {axisPtTrig, axisZPv, axisMult}, true); - histos.add("reco/info/h2_ptTrigOccupancy", "h2_ptTrigOccupancy", kTHnSparseD, {axisPtTrig, axisOccupancy}, true); - - // reco (correlation) analysis - histos.add("reco/corr/h3_ptPhiEta_trig", "h3_ptPhiEta_trig", kTHnSparseD, {axisPtAssoc, axisPhi, axisEta}, true); - - auto const add_corrHists = - [&](std::string const& name_id) { - histos.add(std::format("reco/corr/h4_ptTrigPtAssocPhiEta_assoc_{}", name_id).data(), std::format("h4_ptTrigPtAssocPhiEta_assoc_{}", name_id).data(), - kTHnSparseD, {axisPtTrig, axisPtAssoc, axisPhi, axisEta}, true); - histos.add(std::format("reco/corr/h6_corr_{}", name_id).data(), std::format("h6_corr_{}", name_id).data(), - kTHnSparseF, {axisDPhi, axisDEta, axisPtTrig, axisPtAssoc, axisZPvBinning, axisMultBinning}, true); - histos.add(std::format("reco/corr/h6_mix_{}", name_id).data(), std::format("h6_mix_{}", name_id).data(), - kTHnSparseF, {axisDPhi, axisDEta, axisPtTrig, axisPtAssoc, axisZPvBinning, axisMultBinning}, true); - }; - // hadron - histos.add("reco/plain/h3_ptPhiEta_hadron", "h3_ptPhiEta_hadron", kTHnSparseD, {axisPtAssoc, axisPhi, axisEta}, true); - add_corrHists("hadron"); - // pipm - histos.add("reco/plain/h3_ptPhiEta_pipm", "h3_ptPhiEta_pipm", kTHnSparseD, {axisPtAssoc, axisPhi, axisEta}, true); - add_corrHists("pipm"); - // photonPCM - histos.add("reco/plain/h3_ptPhiEta_photonPCM", "h3_ptPhiEta_photonPCM", kTHnSparseD, {axisPtAssoc, axisPhi, axisEta}, true); - add_corrHists("photonPCM"); - // photonPCM pairs - histos.add("reco/plain/h5_ptTrigPtAssocMggZPvMult_photonPCMPair", "h5_ptTrigPtAssocMggZPvMult_photonPCMPair", - kTHnSparseD, {axisPtTrig, axisPtAssoc, axisMgg, axisZPvBinning, axisMultBinning}, true); - histos.add("reco/corr/h5_ptTrigPtAssocMggZPvMult_assoc_photonPCMPair", "h5_ptTrigPtAssocMggZPvMult_assoc_photonPCMPair", - kTHnSparseD, {axisPtTrig, axisPtAssoc, axisMgg, axisZPvBinning, axisMultBinning}, true); - // pi0PCM - add_corrHists("pi0PCMPeak"); - add_corrHists("pi0PCMSide"); - // etaPCM - add_corrHists("etaPCMPeak"); - add_corrHists("etaPCMSide"); - - // event mixing for photon pairs - histos.add("reco/plain/h2_zPvMult_photonPCMPair_evMix", "h2_zPvMult_photonPCMPair_evMix", kTHnSparseD, {axisZPv, axisMult}, true); - histos.add("reco/plain/h4_ptMggZPvMult_photonPCMPair_evMix", "h4_ptMggZPvMult_photonPCMPair_evMix", kTHnSparseD, {axisPtAssoc, axisMgg, axisZPvBinning, axisMultBinning}, true); - - // mc info - histos.add("mc/info/h3_ptTrigZPvMult_true", "h3_ptTrigZPvMult_true", kTHnSparseD, {axisPtTrig, axisZPv, axisMult}, true); - histos.add("mc/info/h3_ptTrigZPvMult_trueAssocEv", "h3_ptTrigZPvMult_trueAssocEv", kTHnSparseD, {axisPtTrig, axisZPv, axisMult}, true); - histos.add("mc/info/h3_ptTrigZPvMult_trueAssocEvRecoPtTrig", "h3_ptTrigZPvMult_trueAssocEvRecoPtTrig", kTHnSparseD, {axisPtTrig, axisZPv, axisMult}, true); - - // reco and true collision correlations - const std::vector assocMcCorrNamesMcAll = {"hadron", "pipm", "photon", "pi0", "eta"}; - for (auto const& correlationType : {"true", "trueAssocEv", "trueAssocEvRecoPtTrig"}) { - histos.add(std::format("mc/corr/h3_ptPhiEta_trig_{}", correlationType).data(), std::format("h3_ptPhiEta_trig_{}", correlationType).data(), - kTHnSparseD, {axisPtAssoc, axisPhi, axisEta}, true); - for (auto const& assocName : assocMcCorrNamesMcAll) { - histos.add(std::format("mc/corr/h6_corr_{}_{}", correlationType, assocName).data(), std::format("h6_corr_{}_{}", correlationType, assocName).data(), - kTHnSparseD, {axisDPhi, axisDEta, axisPtTrig, axisPtAssoc, axisZPvBinningMcTrue, axisMultBinningMcTrue}, true); - histos.add(std::format("mc/corr/h6_mix_{}_{}", correlationType, assocName).data(), std::format("h6_mix_{}_{}", correlationType, assocName).data(), - kTHnSparseD, {axisDPhi, axisDEta, axisPtTrig, axisPtAssoc, axisZPvBinningMcTrue, axisMultBinningMcTrue}, true); - } - } - - // decay correlation extra info (just true level) - const std::vector assocMcCorrNamesMcDecayAddition = {"photonDecay", "photonDirect", "photonPi0", "photonEta", - "omega", "photonOmega", "etaPrime", "photonEtaPrime", "photonOtherMother"}; - for (auto const& assocName : assocMcCorrNamesMcDecayAddition) { - histos.add(std::format("mc/corr/h6_corr_true_{}", assocName).data(), std::format("h6_corr_true_{}", assocName).data(), - kTHnSparseD, {axisDPhi, axisDEta, axisPtTrig, axisPtAssoc, axisZPvBinningMcTrue, axisMultBinningMcTrue}, true); - histos.add(std::format("mc/corr/h6_mix_true_{}", assocName).data(), std::format("h6_mix_true_{}", assocName).data(), - kTHnSparseD, {axisDPhi, axisDEta, axisPtTrig, axisPtAssoc, axisZPvBinningMcTrue, axisMultBinningMcTrue}, true); - } - - // extra reco correlations with MC info - auto const addMcRecoCorrHists = - [&](std::string const& correlationType, std::string const& assocName) { - histos.add(std::format("mc/corr/h6_corr_{}_{}", correlationType, assocName).data(), std::format("h6_corr_{}_{}", correlationType, assocName).data(), - kTHnSparseD, {axisDPhi, axisDEta, axisPtTrig, axisPtAssoc, axisZPvBinning, axisMultBinning}, true); - histos.add(std::format("mc/corr/h6_mix_{}_{}", correlationType, assocName).data(), std::format("h6_mix_{}_{}", correlationType, assocName).data(), - kTHnSparseD, {axisDPhi, axisDEta, axisPtTrig, axisPtAssoc, axisZPvBinning, axisMultBinning}, true); - }; - // matchable associated particles - const std::vector assocCorrNamesMcExtra = {"hadron", "pipm", "photonPCM"}; - for (auto const& correlationType : {"recoAssocEv", "recoPure", "recoPureTruePtAssoc"}) { - for (auto const& assocName : assocCorrNamesMcExtra) { - addMcRecoCorrHists(correlationType, assocName); - } - } - // invariant mass associated particles - // mc pseudo yield - addMcRecoCorrHists("pseudoReco", "pi0PCM"); - addMcRecoCorrHists("pseudoRecoAssocEv", "pi0PCM"); - addMcRecoCorrHists("pseudoRecoPure", "pi0PCM"); - addMcRecoCorrHists("pseudoRecoPureTruePtAssoc", "pi0PCM"); - // efficiency advanced info - addMcRecoCorrHists("trueGeoAcc", "pi0"); - addMcRecoCorrHists("trueMeasDecay", "pi0"); - - // mc correction - auto const addCorrectionHistsResolved = - [&](std::string const& nameId) { - histos.add(std::format("mc/correction/resol/h4_ptTrigPtAssocPhiEta_{}", nameId).data(), std::format("h4_ptTrigPtAssocPhiEta_{}", nameId).data(), - kTHnSparseD, {axisPtTrig, axisPtAssoc, axisPhi, axisEta}, true); - histos.add(std::format("mc/correction/resol/h4_ptTrigPtAssocZPvMult_{}", nameId).data(), std::format("h4_ptTrigPtAssocZPvMult_{}", nameId).data(), - kTHnSparseD, {axisPtTrig, axisPtAssoc, axisZPv, axisMult}, true); - }; - auto const addCorrectionHistsResolvedBasicTypes = - [&](std::string const& nameReco, std::string const& nameTrue) { - std::vector const recoTypes = {"reco", "recoAssocEv", "recoPure"}; - std::vector const trueTypes = {"true", "trueAssocEv", "trueAssocEvRecoPtTrig"}; - for (std::string const& recoType : recoTypes) { - addCorrectionHistsResolved(std::format("{}_{}", recoType, nameReco)); - } - for (std::string const& trueType : trueTypes) { - addCorrectionHistsResolved(std::format("{}_{}", trueType, nameTrue)); - } - }; - - auto const addCorrectionHistPt = - [&](std::string const& nameId) { - histos.add(std::format("mc/correction/h2_ptTrigPtAssoc_{}", nameId).data(), std::format("h2_ptTrigPtAssoc_{}", nameId).data(), - kTHnSparseD, {axisPtTrig, axisPtAssoc}, true); - }; - auto const addCorrectionHistPtCategories = - [&](std::string const& nameId) { - histos.add(std::format("mc/correction/h3_ptTrigPtAssocCategory_{}", nameId).data(), std::format("h3_ptTrigPtAssocCategory_{}", nameId).data(), - kTHnSparseD, {axisPtTrig, axisPtAssoc, axisCategories}, true); - }; - auto const addCorrectionHistsV0 = - [&](std::string const& nameReco, std::string const& nameTrue) { - addCorrectionHistPt(std::format("true_{}", nameTrue)); - addCorrectionHistPt(std::format("trueAssocEv_{}", nameTrue)); - addCorrectionHistPt(std::format("trueAssocEvRecoPtTrig_{}", nameTrue)); - // mc pseudo yield - addCorrectionHistPt(std::format("pseudoReco_{}", nameReco)); - addCorrectionHistPt(std::format("pseudoRecoAssocEv_{}", nameReco)); - addCorrectionHistPt(std::format("pseudoRecoPure_{}", nameReco)); - // efficiency advanced info - addCorrectionHistPt(std::format("trueGeoAcc_{}", nameTrue)); - addCorrectionHistPt(std::format("trueMeasDecay_{}", nameTrue)); - }; - - // matchables - // tracks - addCorrectionHistsResolvedBasicTypes("hadron", "hadron"); - // pipm PID - addCorrectionHistsResolvedBasicTypes("pipm", "pipm"); - // photonPCM - addCorrectionHistsResolvedBasicTypes("photonPCM", "photon"); - // impurities - addCorrectionHistPtCategories("recoImpurities_photonPCM"); - - // invariant mass reconstruction - // pi0 - addCorrectionHistsV0("pi0PCM", "pi0"); - // impurities - addCorrectionHistPtCategories("pseudoRecoImpurities_pi0PCM"); - // eta - addCorrectionHistsV0("etaPCM", "eta"); - - // tests - - // DCAz - histos.add("reco/plain/h5_ptTrigPtAssocDCAzZPvMult_photonPCM", "h5_ptTrigPtAssocDCAzZPvMult_photonPCM", - kTHnSparseD, {axisPtTrig, axisPtAssoc, axisDCAz, axisZPvBinning, axisMultBinning}, true); - histos.add("mc/plain/h5_ptTrigPtAssocDCAzZPvMult_photonPCM", "h5_ptTrigPtAssocDCAzZPvMult_photonPCM", - kTHnSparseD, {axisPtTrig, axisPtAssoc, axisDCAz, axisZPvBinning, axisMultBinning}, true); - } - - // selections /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - - // mc split event selection based in the thrid decimal of mc-true posZ - template - bool checkSplitMcEventSelection(T_collision const& collision) - { - // select based on configurables - return collision.thirdDecimalTruePosZ() % splitMcEvN == splitMcEvSelect - 1; - } - - // total event selection (basic selections from producer and analysis level selections) - template - bool totalEvSel(T_collision const& collision) - { - bool isSelEv = true; - - if constexpr (requires { collision.selEv(); }) { - isSelEv = collision.selEv(); - } - return isSelEv && checkSplitMcEventSelection(collision); - } - - // checks if mcParticle is charged - template - bool checkChargedMc(T_mcParticle const& mcParticle) - { - auto const pdgParticle = pdg->GetParticle(mcParticle.pdgCode()); - return pdgParticle && pdgParticle->Charge() != 0; - } - // checks if fast decaying mcParticle is 'primary' - template - bool checkDecayPrimary(T_mcParticle const& mcParticle) - { - // identify decaying primary - return mcParticle.producedByGenerator(); - } - // checks if mcParticle daughters are two photons - template - bool checkToGG(T_mcParticle const& mcParticle) - { - auto const& daughters = mcParticle.template daughters_as(); - constexpr int NDaughtersToGG = 2; - if (daughters.size() != NDaughtersToGG) { - return false; - } - auto daughter = daughters.begin(); - auto daughterEnd = daughters.end(); - while (daughter != daughterEnd) { - if ((*daughter).pdgCode() != PDG_t::kGamma) { - return false; - } - daughter++; - } - return true; - } - // check if particle has mother in parent tree - template - bool checkForMother(T_mcParticle const& mcParticle, int const pdgCode, bool const checkAntiParticle) - { - if (!mcParticle.has_mothers()) { - return false; - } - auto const mothers = mcParticle.template mothers_as(); - auto mother = mothers.begin(); - auto motherEnd = mothers.end(); - while (mother != motherEnd) { - - // LOGF(info, "searchPdgCode: %i, current[ pdgCode: %i, status: %i, primary: %i ], mother[ pdgCode: %i, status: %i, primary: %i ]", - // pdgCode, - // mcParticle.pdgCode(), mcParticle.getGenStatusCode(), mcParticle.isPhysicalPrimary(), - // (*mother).pdgCode(), (*mother).getGenStatusCode(), (*mother).isPhysicalPrimary()); - - if ((*mother).pdgCode() == pdgCode || (checkAntiParticle && (*mother).pdgCode() == -pdgCode)) { - return true; - } - if (checkForMother(*mother, pdgCode, checkAntiParticle)) { - return true; - } - mother++; - } - return false; - } - - // checks if daughters are in acceptance - template - bool checkDaughtersInAcceptance(T_mcParticle const& mcParticle, std::pair const etaRange, std::pair const phiRange = {0, constants::math::TwoPI}) - { - auto const& daughterPhotons = mcParticle.template daughters_as(); - auto daughterPhoton = daughterPhotons.begin(); - auto daughterPhotonEnd = daughterPhotons.end(); - while (daughterPhoton != daughterPhotonEnd) { - if ((*daughterPhoton).eta() < etaRange.first || (*daughterPhoton).eta() > etaRange.second) { - return false; - } - if ((*daughterPhoton).phi() < phiRange.first || (*daughterPhoton).phi() > phiRange.second) { - return false; - } - daughterPhoton++; - } - return true; - } - - // checks if tracks come from photon conversion - template - bool isConversionPhoton(T_track const& posTrack, T_track const& negTrack) - { - // check same mother - auto const& posMothers = posTrack.mcParticle().template mothers_as(); - auto const& negMothers = negTrack.mcParticle().template mothers_as(); - if (posMothers.size() != 1 || negMothers.size() != 1) { - return false; - } - if (posMothers.begin()->globalIndex() != negMothers.begin()->globalIndex()) { - return false; - } - // check photon - if (posMothers.begin()->pdgCode() != PDG_t::kGamma) { - return false; - } - - return true; - }; - // checks if tracks come from double conversion - template - bool isGGFromDoubleConversion(T_track const& posTrack1, T_track const& negTrack1, T_track const& posTrack2, T_track const& negTrack2, int const pdgCode) - { - if (!isConversionPhoton(posTrack1, negTrack1) || !isConversionPhoton(posTrack2, negTrack2)) { - return false; - } - // check same mother - auto const& mothers1 = (*(posTrack1.mcParticle().template mothers_as().begin())).template mothers_as(); - auto const& mothers2 = (*(posTrack2.mcParticle().template mothers_as().begin())).template mothers_as(); - constexpr int NMothersPhotonFromH0 = 2; // for some reason two mothers (same particle) for h0 decays (contradicts PYTHIA documentation, but whatever) - if (mothers1.size() != NMothersPhotonFromH0 || mothers2.size() != NMothersPhotonFromH0) { - return false; - } - if (mothers1.begin()->globalIndex() != mothers2.begin()->globalIndex()) { - return false; - } - // check particle type - if (mothers1.begin()->pdgCode() != pdgCode) { - return false; - } - - return true; - }; - - // analysis helpers ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - - template - double getH1ValueAt(T_h1 const* const h1, double const value) - { - return h1->GetBinContent(h1->FindFixBin(value)); - } - // correction helpers - enum class CorrectionParticleType { Trigger, - Hadron, - Pipm, - PhotonPCM }; - - template - double getPtCorrection(double const value) - { - if constexpr (T_correctionParticleType == CorrectionParticleType::Trigger) { - return applyCTotTrigger ? getH1ValueAt(h1PtCorrectionTrigger, value) : 1; - } else { - return 1; - } - } - - // performs 'phi1 - phi2' and pushes it into the interval [-pi/2, 3pi/2] - inline double getDeltaPhi(double const phi1, double const phi2) - { - return RecoDecay::constrainAngle(phi1 - phi2, -1 * constants::math::PIHalf); - } - - // checks that two values belong to the same category (assumes ordered bins) - // returns -1 for negative result (also for under/overflow values) and bin number (starting at 0) otherwise - int checkSameBin(double const value1, double const value2, std::vector const& bins) - { - // reject underflow - if (value1 < bins[0]) { - return -1; - } - // loop over bins - const int n = bins.size() - 1; - for (int i_bin = 0; i_bin < n; i_bin++) { - if (value1 < bins[i_bin + 1]) { - if (value2 < bins[i_bin + 1] && value2 >= bins[i_bin]) { - return i_bin; - } - return -1; - } - } - // reject overflow - return -1; - } - - // check if invariant mass range - enum class MassRange { Pi0PCMPeak, - Pi0PCMSide, - EtaPCMPeak, - EtaPCMSide }; - - template - bool checkMassRange(double const mgg) - { - if constexpr (range == MassRange::Pi0PCMPeak) { - return mgg > pi0PCMPeakMassRange.value[0] && mgg < pi0PCMPeakMassRange.value[1]; - } else if constexpr (range == MassRange::Pi0PCMSide) { - return mgg > pi0PCMSideMassRange.value[0] && mgg < pi0PCMSideMassRange.value[1]; - } else if constexpr (range == MassRange::EtaPCMPeak) { - return mgg > etaPCMPeakMassRange.value[0] && mgg < etaPCMPeakMassRange.value[1]; - } else if constexpr (range == MassRange::EtaPCMSide) { - return (mgg > etaPCMLowSideMassRange.value[0] && mgg < etaPCMLowSideMassRange.value[1]) || - (mgg > etaPCMHighSideMassRange.value[0] && mgg < etaPCMHighSideMassRange.value[1]); - } - return false; - } - - // analysis ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - - // generalised correlation functions - // per collision - - // plain info - template - void corrProcessPlain(T_collision const& collision, T_associatedThisEvent const& associatedThisEvent, - T_funcPlain const& funcPlain) - { - // normal spectra (per event - not per trigger) - for (auto const& associated : associatedThisEvent) { - funcPlain(collision, associated); - } - } - - // correlation - template - void corrProcessCorrelation(T_collision const& collision, T_triggersThisEvent const& triggersThisEvent, T_associatedThisEvent const& associatedThisEvent, - T_funcCorrelation const& funcCorrelation) - { - // correlation combinations - for (auto const& [trigger, associated] : soa::combinations(soa::CombinationsFullIndexPolicy(triggersThisEvent, associatedThisEvent))) { - funcCorrelation(collision, trigger, associated); - } - } - - // mixing-number pt scaling with power law - size_t nMixingPtPowerScaling(double const pt, size_t const n0) - { - double const rawScale = 1 + nTriggerScaleCoefficient * std::pow(pt, nTriggerScaleExponent); - return n0 * static_cast(rawScale); - } - - // mixing - template - void corrProcessMixing(T_collision const& collision, T_associatedThisEvent const& associatedThisEvent, - T_funcMixing const& funcMixing, - size_t const nTriggerMixingAt0) - { - size_t triggerMemoryBinSizeMin = 0; - - // mixing loops (more dynamic than O2 mixing) - std::deque const& savedTriggers = - [&]() -> std::deque const& { - if constexpr (triggerMemoryMode == TriggerMemoryMode::Reco) { - triggerMemoryBinSizeMin = triggerMemoryReco->getBinSizeMin(); - return triggerMemoryReco->getTriggers(collision.posZ(), collision.nGlobalTracks()); - } else if constexpr (triggerMemoryMode == TriggerMemoryMode::True) { - triggerMemoryBinSizeMin = triggerMemoryTrue->getBinSizeMin(); - return triggerMemoryTrue->getTriggers(collision.posZ(), collision.nChargedInEtaRange()); - } else if constexpr (triggerMemoryMode == TriggerMemoryMode::TrueAssocEv) { - triggerMemoryBinSizeMin = triggerMemoryTrueAssocEv->getBinSizeMin(); - return triggerMemoryTrueAssocEv->getTriggers(collision.posZ(), collision.nChargedInEtaRange()); - } else if constexpr (triggerMemoryMode == TriggerMemoryMode::TrueAssocEvRecoPtTrig) { - triggerMemoryBinSizeMin = triggerMemoryTrueAssocEvRecoPtTrig->getBinSizeMin(); - return triggerMemoryTrueAssocEvRecoPtTrig->getTriggers(collision.posZ(), collision.nChargedInEtaRange()); - } - }(); - // require enough mixing statistics - if (triggerMemoryBinSizeMin < static_cast(nTriggerBinMinThreshold)) { - return; - } - const size_t nSavedTriggers = savedTriggers.size(); - const size_t iStartTriggerParticle = randomIntInInterval(0, iTriggerStartFraction * nSavedTriggers); - // associated loop - for (auto const& associated : associatedThisEvent) { - // trigger numbers - const size_t nTriggerMixing = nMixingPtPowerScaling(associated.pt(), nTriggerMixingAt0); - const size_t mixUpToTriggerN = std::min(nSavedTriggers, iStartTriggerParticle + nTriggerMixing); - const float perTriggerWeight = 1. / (mixUpToTriggerN - iStartTriggerParticle); // mixUpToTriggerN <= iStartTriggerParticle caught by break statement of loop - // trigger loop - for (size_t i_mixingTrigger = iStartTriggerParticle; i_mixingTrigger < mixUpToTriggerN; i_mixingTrigger++) { - MixingTrigger const& mixingTrigger = savedTriggers[i_mixingTrigger]; - funcMixing(collision, mixingTrigger, associated, perTriggerWeight); - } - } - } - - // analysis tasks /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // =/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/ - - void init(InitContext& initContext) - { - // analysis info - ccdb->setURL(urlCcdb); - // enabling object caching (otherwise each call goes to CCDB server) - ccdb->setCaching(true); - // ccdb->setLocalObjectValidityChecking(); - // not later than (avoids replacing objects while a train is running) - ccdb->setCreatedNotAfter(noLaterThanCcdb); - - // init analysis variables - - // get variables from other tasks - o2::common::core::getTaskOptionValue(initContext, "photon-charged-trigger-producer", "absEtaMax", absEtaMax, false); - - // histograms from ccdb - initCcdbHistograms(); - - // create analysis histograms - initHistograms(); - - // mixing trigger memory - triggerMemoryReco = std::make_unique(binsZPvBinning, binsMultBinning, nTriggerSavedForMixing); - triggerMemoryTrue = std::make_unique(binsZPvBinningMcTrue, binsMultBinningMcTrue, nTriggerSavedForMixing); - triggerMemoryTrueAssocEv = std::make_unique(binsZPvBinningMcTrue, binsMultBinningMcTrue, nTriggerSavedForMixing); - triggerMemoryTrueAssocEvRecoPtTrig = std::make_unique(binsZPvBinningMcTrue, binsMultBinningMcTrue, nTriggerSavedForMixing); - } - - // reconstructed //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ========================================================================================================================================================================================== - - void processCorrHadron(CorrCollisions const& collisions, aod::Triggers const& triggers, aod::Hadrons const& hadrons) - { - for (auto const& collision : collisions) { - // event selection - if (!totalEvSel(collision)) { - continue; - } - - // group collision - auto const triggersThisEvent = triggers.sliceBy(perColTriggers, collision.globalIndex()); - auto const hadronsThisEvent = hadrons.sliceBy(perColHadrons, collision.globalIndex()); - - auto const funcPlain = [this]([[maybe_unused]] auto const& collision, auto const& associated) { - histos.fill(HIST("reco/plain/h3_ptPhiEta_hadron"), - associated.pt(), associated.phi(), associated.eta()); - }; - corrProcessPlain(collision, hadronsThisEvent, funcPlain); - - auto const funcCorrelation = [this](auto const& collision, auto const& trigger, auto const& associated) { - // exclude self correlation - if (trigger.jetTrackId() == associated.jetTrackId()) { - return; - } - - histos.fill(HIST("reco/corr/h4_ptTrigPtAssocPhiEta_assoc_hadron"), - collision.ptMax(), associated.pt(), associated.phi(), associated.eta(), - getPtCorrection(trigger.pt())); - histos.fill(HIST("reco/corr/h6_corr_hadron"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - }; - corrProcessCorrelation(collision, triggersThisEvent, hadronsThisEvent, funcCorrelation); - - // select mixing events - if (doTrigEvMixing && !collision.trigEv()) { - continue; - } - - auto const funcMixing = [this](auto const& collision, auto const& trigger, auto const& associated, auto const perTriggerWeight) { - histos.fill(HIST("reco/corr/h6_mix_hadron"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - }; - corrProcessMixing(collision, hadronsThisEvent, funcMixing, nMixingAt0Hadron); - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processCorrHadron, "process standard correlation for associated hardons", false); - - void processCorrPipm(CorrCollisions const& collisions, aod::Triggers const& triggers, aod::Pipms const& pipms) - { - for (auto const& collision : collisions) { - // event selection - if (!totalEvSel(collision)) { - continue; - } - - // group collision - auto const triggersThisEvent = triggers.sliceBy(perColTriggers, collision.globalIndex()); - auto const pipmsThisEvent = pipms.sliceBy(perColPipms, collision.globalIndex()); - - auto const funcPlain = [this]([[maybe_unused]] auto const& collision, auto const& associated) { - histos.fill(HIST("reco/plain/h3_ptPhiEta_pipm"), - associated.pt(), associated.phi(), associated.eta()); - }; - corrProcessPlain(collision, pipmsThisEvent, funcPlain); - - auto const funcCorrelation = [this](auto const& collision, auto const& trigger, auto const& associated) { - // exclude self correlation - if (trigger.jetTrackId() == associated.jetTrackId()) { - return; - } - - histos.fill(HIST("reco/corr/h4_ptTrigPtAssocPhiEta_assoc_pipm"), - collision.ptMax(), associated.pt(), associated.phi(), associated.eta(), - getPtCorrection(trigger.pt())); - histos.fill(HIST("reco/corr/h6_corr_pipm"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - }; - corrProcessCorrelation(collision, triggersThisEvent, pipmsThisEvent, funcCorrelation); - - // select mixing events - if (doTrigEvMixing && !collision.trigEv()) { - continue; - } - - auto const funcMixing = [this](auto const& collision, auto const& trigger, auto const& associated, auto const perTriggerWeight) { - histos.fill(HIST("reco/corr/h6_mix_pipm"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - }; - corrProcessMixing(collision, pipmsThisEvent, funcMixing, nMixingAt0Pipm); - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processCorrPipm, "process standard correlation for associated pipm", false); - - void processCorrPhotonPCM(CorrCollisions const& collisions, aod::Triggers const& triggers, aod::PhotonPCMs const& photonPCMs) - { - for (auto const& collision : collisions) { - // event selection - if (!totalEvSel(collision)) { - continue; - } - - // group collision - auto const triggersThisEvent = triggers.sliceBy(perColTriggers, collision.globalIndex()); - auto const photonPCMsThisEvent = photonPCMs.sliceBy(perColPhotonPCMs, collision.globalIndex()); - - auto const funcPlain = [this]([[maybe_unused]] auto const& collision, auto const& associated) { - histos.fill(HIST("reco/plain/h3_ptPhiEta_photonPCM"), - associated.pt(), associated.phi(), associated.eta()); - }; - corrProcessPlain(collision, photonPCMsThisEvent, funcPlain); - - auto const funcCorrelation = [this](auto const& collision, auto const& trigger, auto const& associated) { - // exclude self correlation - if (trigger.jetTrackId() == associated.posJetTrackId() || trigger.jetTrackId() == associated.negJetTrackId()) { - return; - } - - histos.fill(HIST("reco/corr/h4_ptTrigPtAssocPhiEta_assoc_photonPCM"), - collision.ptMax(), associated.pt(), associated.phi(), associated.eta(), - getPtCorrection(trigger.pt())); - histos.fill(HIST("reco/corr/h6_corr_photonPCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - }; - corrProcessCorrelation(collision, triggersThisEvent, photonPCMsThisEvent, funcCorrelation); - - // select mixing events - if (doTrigEvMixing && !collision.trigEv()) { - continue; - } - - auto const funcMixing = [this](auto const& collision, auto const& trigger, auto const& associated, auto const perTriggerWeight) { - histos.fill(HIST("reco/corr/h6_mix_photonPCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - }; - corrProcessMixing(collision, photonPCMsThisEvent, funcMixing, nMixingAt0PhotonPCM); - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processCorrPhotonPCM, "process standard correlation for associated photonPCM", false); - - void processCorrPhotonPCMPair(CorrCollisions const& collisions, aod::Triggers const& triggers, aod::PhotonPCMPairs const& photonPCMPairs) - { - for (auto const& collision : collisions) { - // event selection - if (!totalEvSel(collision)) { - continue; - } - - // group collision - auto const triggersThisEvent = triggers.sliceBy(perColTriggers, collision.globalIndex()); - auto const photonPCMPairsThisEvent = photonPCMPairs.sliceBy(perColPhotonPCMPairs, collision.globalIndex()); - - auto const funcPlain = [this](auto const& collision, auto const& associated) { - histos.fill(HIST("reco/plain/h5_ptTrigPtAssocMggZPvMult_photonPCMPair"), collision.ptMax(), associated.pt(), associated.mgg(), collision.posZ(), collision.nGlobalTracks()); - }; - corrProcessPlain(collision, photonPCMPairsThisEvent, funcPlain); - - auto const funcCorrelation = [this](auto const& collision, auto const& trigger, auto const& associated) { - // exclude self correlation - if (trigger.jetTrackId() == associated.posJetTrack1Id() || trigger.jetTrackId() == associated.negJetTrack1Id() || - trigger.jetTrackId() == associated.negJetTrack2Id() || trigger.jetTrackId() == associated.posJetTrack2Id()) { - return; - } - - histos.fill(HIST("reco/corr/h5_ptTrigPtAssocMggZPvMult_assoc_photonPCMPair"), - trigger.pt(), associated.pt(), associated.mgg(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - - // pi0 - if (checkMassRange(associated.mgg())) { - histos.fill(HIST("reco/corr/h4_ptTrigPtAssocPhiEta_assoc_pi0PCMPeak"), - collision.ptMax(), associated.pt(), associated.phi(), associated.eta(), - getPtCorrection(trigger.pt())); - histos.fill(HIST("reco/corr/h6_corr_pi0PCMPeak"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - return; - } - if (checkMassRange(associated.mgg())) { - histos.fill(HIST("reco/corr/h4_ptTrigPtAssocPhiEta_assoc_pi0PCMSide"), - collision.ptMax(), associated.pt(), associated.phi(), associated.eta(), - getPtCorrection(trigger.pt())); - histos.fill(HIST("reco/corr/h6_corr_pi0PCMSide"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - return; - } - // eta - if (checkMassRange(associated.mgg())) { - histos.fill(HIST("reco/corr/h4_ptTrigPtAssocPhiEta_assoc_etaPCMPeak"), - collision.ptMax(), associated.pt(), associated.phi(), associated.eta(), - getPtCorrection(trigger.pt())); - histos.fill(HIST("reco/corr/h6_corr_etaPCMPeak"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - return; - } - if (checkMassRange(associated.mgg())) { - histos.fill(HIST("reco/corr/h4_ptTrigPtAssocPhiEta_assoc_etaPCMSide"), - collision.ptMax(), associated.pt(), associated.phi(), associated.eta(), - getPtCorrection(trigger.pt())); - histos.fill(HIST("reco/corr/h6_corr_etaPCMSide"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - return; - } - }; - corrProcessCorrelation(collision, triggersThisEvent, photonPCMPairsThisEvent, funcCorrelation); - - // select mixing events - if (doTrigEvMixing && !collision.trigEv()) { - continue; - } - - auto const funcMixing = [this](auto const& collision, auto const& trigger, auto const& associated, auto const perTriggerWeight) { - // pi0 - if (checkMassRange(associated.mgg())) { - histos.fill(HIST("reco/corr/h6_mix_pi0PCMPeak"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - return; - } - if (checkMassRange(associated.mgg())) { - histos.fill(HIST("reco/corr/h6_mix_pi0PCMSide"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - return; - } - // eta - if (checkMassRange(associated.mgg())) { - histos.fill(HIST("reco/corr/h6_mix_etaPCMPeak"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - return; - } - if (checkMassRange(associated.mgg())) { - histos.fill(HIST("reco/corr/h6_mix_etaPCMSide"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - return; - } - }; - corrProcessMixing(collision, photonPCMPairsThisEvent, funcMixing, nMixingAt0H0PCM); - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processCorrPhotonPCMPair, "process standard correlation for associated pi0PCM", false); - - void processCorrPhotonPCMPairMix(CorrCollisions const& collisions, aod::PhotonPCMs const& photonPCMs) - { - auto photonPCMsTuple = std::make_tuple(photonPCMs); - SameKindPair pairs{binningZPvMult, nNeighboursMixingPhotonPCMPair, -1, collisions, photonPCMsTuple, &cache}; - - // mixed events - for (auto pair = pairs.begin(); pair != pairs.end(); pair++) { - auto const& [collision1, photonPCMs1, collision2, photonPCMs2] = *pair; - - // // check that current und mixing-trigger event are from the same zPv/mult bins - // if (checkSameBin(collision1.posZ(), collision2.posZ(), binsZPvBinning) == -1) { - // std::printf("ERROR: zPv bins do not match\n"); continue; - // } - // if (checkSameBin(collision1.nGlobalTracks(), collision2.nGlobalTracks(), binsMultBinning) == -1) { - // std::printf("ERROR: multiplicity bins do not match\n"); continue; - // } - - // event selection - if (!totalEvSel(collision1) || !totalEvSel(collision2)) { - continue; - } - // event info - histos.fill(HIST("reco/plain/h2_zPvMult_photonPCMPair_evMix"), collision1.posZ(), collision1.nGlobalTracks()); - // mixing loop - for (auto const& [photonPCM1, photonPCM2] : soa::combinations(soa::CombinationsFullIndexPolicy(photonPCMs1, photonPCMs2))) { - ROOT::Math::PtEtaPhiMVector const p4photonPCM1(photonPCM1.pt(), photonPCM1.eta(), photonPCM1.phi(), 0.); - ROOT::Math::PtEtaPhiMVector const p4photonPCM2(photonPCM2.pt(), photonPCM2.eta(), photonPCM2.phi(), 0.); - ROOT::Math::PtEtaPhiMVector const p4photonPCMPair = p4photonPCM1 + p4photonPCM2; - - histos.fill(HIST("reco/plain/h4_ptMggZPvMult_photonPCMPair_evMix"), p4photonPCMPair.pt(), p4photonPCMPair.M(), collision1.posZ(), collision1.nGlobalTracks()); - } - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processCorrPhotonPCMPairMix, "process gamma-gamma mixing for photonPCM", false); - - void processPCMDCAz(CorrCollision const& collision, aod::PhotonPCMs const& photonPCMs, aod::V0PhotonsKF const&) - { - // event selection - if (!totalEvSel(collision)) { - return; - } - - for (auto const& photonPCM : photonPCMs) { - histos.fill(HIST("reco/plain/h5_ptTrigPtAssocDCAzZPvMult_photonPCM"), - collision.ptMax(), photonPCM.pt(), photonPCM.v0PhotonKF().dcaZtopv(), collision.posZ(), collision.nGlobalTracks()); - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processPCMDCAz, "process to test DCAz distribution of photons in trigger collisions", false); - - // MC /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ========================================================================================================================================================================================== - - // correlations ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - - // (sad) attempt at reducing code duplication - enum class McCorrTruthLevel : int { True = 0, - TrueAssocEv = 1, - TrueAssocEvRecoPtTrig = 2, - TrueMeasDecay = 3, - TrueGeoAcc = 4 }; - enum class McCorrCorrelationType : int { Correlation = 0, - Mixing = 1 }; - enum class McCorrAssocType : int { Hadron = 0, - Pipm = 1, - Photon = 2, - PhotonDecay = 3, - PhotonDirect = 4, - Pi0 = 5, - PhotonPi0 = 6, - Eta = 7, - PhotonEta = 8, - Omega = 9, - PhotonOmega = 10, - EtaPrime = 11, - PhotonEtaPrime = 12, - PhotonOtherMother = 13 }; - static constexpr std::array, 2>, 5> McTrueCorrHistPaths = {{{{{"mc/corr/h6_corr_true_hadron", "mc/corr/h6_corr_true_pipm", - "mc/corr/h6_corr_true_photon", "mc/corr/h6_corr_true_photonDecay", "mc/corr/h6_corr_true_photonDirect", - "mc/corr/h6_corr_true_pi0", "mc/corr/h6_corr_true_photonPi0", "mc/corr/h6_corr_true_eta", "mc/corr/h6_corr_true_photonEta", - "mc/corr/h6_corr_true_omega", "mc/corr/h6_corr_true_photonOmega", "mc/corr/h6_corr_true_etaPrime", "mc/corr/h6_corr_true_photonEtaPrime", "mc/corr/h6_corr_true_photonOtherMother"}, - {"mc/corr/h6_mix_true_hadron", "mc/corr/h6_mix_true_pipm", - "mc/corr/h6_mix_true_photon", "mc/corr/h6_mix_true_photonDecay", "mc/corr/h6_mix_true_photonDirect", - "mc/corr/h6_mix_true_pi0", "mc/corr/h6_mix_true_photonPi0", "mc/corr/h6_mix_true_eta", "mc/corr/h6_mix_true_photonEta", - "mc/corr/h6_mix_true_omega", "mc/corr/h6_mix_true_photonOmega", "mc/corr/h6_mix_true_etaPrime", "mc/corr/h6_mix_true_photonEtaPrime", "mc/corr/h6_mix_true_photonOtherMother"}}}, - {{{"mc/corr/h6_corr_trueAssocEv_hadron", "mc/corr/h6_corr_trueAssocEv_pipm", - "mc/corr/h6_corr_trueAssocEv_photon", "", "", - "mc/corr/h6_corr_trueAssocEv_pi0", "", "mc/corr/h6_corr_trueAssocEv_eta", "", - "", "", "", "", ""}, - {"mc/corr/h6_mix_trueAssocEv_hadron", "mc/corr/h6_mix_trueAssocEv_pipm", - "mc/corr/h6_mix_trueAssocEv_photon", "", "", - "mc/corr/h6_mix_trueAssocEv_pi0", "", "mc/corr/h6_mix_trueAssocEv_eta", "", - "", "", "", "", ""}}}, - {{{"mc/corr/h6_corr_trueAssocEvRecoPtTrig_hadron", "mc/corr/h6_corr_trueAssocEvRecoPtTrig_pipm", - "mc/corr/h6_corr_trueAssocEvRecoPtTrig_photon", "", "", - "mc/corr/h6_corr_trueAssocEvRecoPtTrig_pi0", "", "mc/corr/h6_corr_trueAssocEvRecoPtTrig_eta", "", - "", "", "", "", ""}, - {"mc/corr/h6_mix_trueAssocEvRecoPtTrig_hadron", "mc/corr/h6_mix_trueAssocEvRecoPtTrig_pipm", - "mc/corr/h6_mix_trueAssocEvRecoPtTrig_photon", "", "", - "mc/corr/h6_mix_trueAssocEvRecoPtTrig_pi0", "", "mc/corr/h6_mix_trueAssocEvRecoPtTrig_eta", "", - "", "", "", "", ""}}}, - {{{"", "", - "", "", "", - "mc/corr/h6_corr_trueMeasDecay_pi0", "", "", "", - "", "", "", "", ""}, - {"", "", - "", "", "", - "mc/corr/h6_mix_trueMeasDecay_pi0", "", "", "", - "", "", "", "", ""}}}, - {{{"", "", - "", "", "", - "mc/corr/h6_corr_trueGeoAcc_pi0", "", "", "", - "", "", "", "", ""}, - {"", "", - "", "", "", - "mc/corr/h6_mix_trueGeoAcc_pi0", "", "", "", - "", "", "", "", ""}}}}}; - static constexpr const char* getMcTrueCorrHistPath(McCorrTruthLevel truthLevel, McCorrCorrelationType correlationType, McCorrAssocType assocType) - { - return McTrueCorrHistPaths[static_cast(truthLevel)][static_cast(correlationType)][static_cast(assocType)]; - } - - // fill mc correlation histograms based on given associated mc particle - template - void fillMcCorrHists(auto const& mcCollision, auto const& triggerIn, auto const& associated, double const weight) - { - // check mc - if constexpr (requires { triggerIn.template jetTrack_as(); }) { - if (!triggerIn.template jetTrack_as().has_mcParticle()) { - return; - } - } - // trigger info separation - auto const triggerParticle = [&]() { - if constexpr (correlationType == McCorrCorrelationType::Correlation) { - if constexpr (truthLevel == McCorrTruthLevel::TrueAssocEvRecoPtTrig) { - static_assert(requires { triggerIn.template jetTrack_as(); }, "triggerIn must be reco level for TrueAssocEvRecoPtTrig"); - return triggerIn.template jetTrack_as().mcParticle(); - } else if constexpr (truthLevel == McCorrTruthLevel::TrueAssocEv || truthLevel == McCorrTruthLevel::True) { - static_assert(requires { triggerIn.template jetMcParticle_as(); }, "triggerIn must be true level for TrueAssocEv and True"); - return triggerIn; - } - } else if constexpr (correlationType == McCorrCorrelationType::Mixing) { - static_assert(std::same_as, MixingTrigger>, "triggerIn must be MixingTrigger for mixing"); - return triggerIn; - } - }(); - auto const& triggerForPt = triggerIn; - - // exclude self correlation - if constexpr (correlationType == McCorrCorrelationType::Correlation) { - if constexpr (truthLevel == McCorrTruthLevel::TrueAssocEvRecoPtTrig) { - if (triggerParticle.globalIndex() == associated.globalIndex()) { - return; - } - } else if constexpr (truthLevel == McCorrTruthLevel::TrueAssocEv || truthLevel == McCorrTruthLevel::True) { - if (triggerParticle.jetMcParticleId() == associated.globalIndex()) { - return; - } - } - } - - double const dPhi = getDeltaPhi(triggerParticle.phi(), associated.phi()); - double const dEta = triggerParticle.eta() - associated.eta(); - double const ptTrig = triggerForPt.pt(); - double const ptAssoc = associated.pt(); - double const posZ = mcCollision.posZ(); - double const mult = mcCollision.nChargedInEtaRange(); - - if (std::abs(associated.eta()) > absEtaMax) { - return; - } - - // standard particles (marked physical primary) - if (associated.isPhysicalPrimary()) { - // charged primary ('hadron') - if (checkChargedMc(associated)) { - histos.fill(HIST(getMcTrueCorrHistPath(truthLevel, correlationType, McCorrAssocType::Hadron)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, weight); - } - // pipm - if (std::abs(associated.pdgCode()) == PDG_t::kPiPlus) { - histos.fill(HIST(getMcTrueCorrHistPath(truthLevel, correlationType, McCorrAssocType::Pipm)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, weight); - return; - } - // photon - if (associated.pdgCode() == PDG_t::kGamma) { - histos.fill(HIST(getMcTrueCorrHistPath(truthLevel, correlationType, McCorrAssocType::Photon)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, weight); - - // extra info for decay correlation only for total true level - if constexpr (truthLevel != McCorrTruthLevel::True) { - return; - } - - // decay and direct - int const statusDecayLow = 91; - int const statusDecayUp = 99; - int const statusDirect = 62; - - if (associated.getGenStatusCode() >= statusDecayLow && associated.getGenStatusCode() <= statusDecayUp) { - histos.fill(HIST(getMcTrueCorrHistPath(truthLevel, correlationType, McCorrAssocType::PhotonDecay)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, - weight); - // decays from different mothers - int const pdgMother = associated.template mothers_as().begin()->pdgCode(); - switch (pdgMother) { - case PDG_t::kPi0: - histos.fill(HIST(getMcTrueCorrHistPath(truthLevel, correlationType, McCorrAssocType::PhotonPi0)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, weight); - break; - case constants::physics::Pdg::kEta: - histos.fill(HIST(getMcTrueCorrHistPath(truthLevel, correlationType, McCorrAssocType::PhotonEta)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, weight); - break; - case constants::physics::Pdg::kOmega: - histos.fill(HIST(getMcTrueCorrHistPath(truthLevel, correlationType, McCorrAssocType::PhotonOmega)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, weight); - break; - case constants::physics::Pdg::kEtaPrime: - histos.fill(HIST(getMcTrueCorrHistPath(truthLevel, correlationType, McCorrAssocType::PhotonEtaPrime)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, weight); - break; - default: - histos.fill(HIST(getMcTrueCorrHistPath(truthLevel, correlationType, McCorrAssocType::PhotonOtherMother)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, weight); - break; - } - } else { - histos.fill(HIST(getMcTrueCorrHistPath(truthLevel, correlationType, McCorrAssocType::PhotonDirect)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, - weight); - - if (associated.getGenStatusCode() != statusDirect) { - LOGF(info, "filled primary photon with status: %i", associated.getGenStatusCode()); - } - } - return; - } - return; - } - // decaying particles (not marked physical primary) - if (!checkDecayPrimary(associated)) { - return; - } - // pi0 - if (associated.pdgCode() == PDG_t::kPi0) { - histos.fill(HIST(getMcTrueCorrHistPath(truthLevel, correlationType, McCorrAssocType::Pi0)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, weight); - // efficincy extra info - if constexpr (truthLevel != McCorrTruthLevel::TrueAssocEvRecoPtTrig) { - return; - } - // chosen decay - if (!checkToGG(associated)) { - return; - } - histos.fill(HIST(getMcTrueCorrHistPath(McCorrTruthLevel::TrueMeasDecay, correlationType, McCorrAssocType::Pi0)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, weight); - // daughters in acceptance - if (!checkDaughtersInAcceptance(associated, {-absEtaMax, absEtaMax})) { - return; - } - histos.fill(HIST(getMcTrueCorrHistPath(McCorrTruthLevel::TrueGeoAcc, correlationType, McCorrAssocType::Pi0)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, weight); - return; - } - // eta - if (associated.pdgCode() == constants::physics::Pdg::kEta) { - histos.fill(HIST(getMcTrueCorrHistPath(truthLevel, correlationType, McCorrAssocType::Eta)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, weight); - return; - } - // extra info for decay correlation only for total true level - if constexpr (truthLevel != McCorrTruthLevel::True) { - return; - } - // omega - if (associated.pdgCode() == constants::physics::Pdg::kOmega) { - histos.fill(HIST(getMcTrueCorrHistPath(truthLevel, correlationType, McCorrAssocType::Omega)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, weight); - return; - } - // etaPrime - if (associated.pdgCode() == constants::physics::Pdg::kEtaPrime) { - histos.fill(HIST(getMcTrueCorrHistPath(truthLevel, correlationType, McCorrAssocType::EtaPrime)), - dPhi, dEta, ptTrig, ptAssoc, posZ, mult, weight); - return; - } - } - - void processMcTrueCorr(CorrMcCollisions const& mcCollisions, aod::TriggerParticles const& triggerParticles, aod::JetParticles const& mcParticles) - { - for (auto const& mcCollision : mcCollisions) { - // event selection - if (!totalEvSel(mcCollision)) { - continue; - } - - // group collision - auto const triggerParticlesThisEvent = triggerParticles.sliceBy(perColTriggerParticles, mcCollision.globalIndex()); - auto const mcParticlesThisEvent = mcParticles.sliceBy(perColMcParticles, mcCollision.globalIndex()); - - auto const funcCorrelation = [this](auto const& collision, auto const& trigger, auto const& associated) { - fillMcCorrHists(collision, trigger, associated, 1); - }; - corrProcessCorrelation(mcCollision, triggerParticlesThisEvent, mcParticlesThisEvent, funcCorrelation); - - // select mixing events - if (doTrigEvMixing && !mcCollision.trigEv()) { - continue; - } - - auto const funcMixing = [this](auto const& collision, auto const& trigger, auto const& associated, auto const perTriggerWeight) { - fillMcCorrHists(collision, trigger, associated, perTriggerWeight); - }; - corrProcessMixing(mcCollision, mcParticlesThisEvent, funcMixing, nMixingAt0McTrue); - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processMcTrueCorr, "process mc-true (all collisions) correlation for multiple associated particles", false); - - void processMcTrueAssocEvCorr(CorrMcDCollisions const& collisions, CorrMcCollisions const&, aod::TriggerParticles const& triggerParticles, aod::JetParticles const& mcParticles) - { - for (auto const& collision : collisions) { - // event selection - if (!totalEvSel(collision)) { - continue; - } - - auto const& mcCollision = collision.mcCollision_as(); - - // group collision - auto const triggerParticlesThisEvent = triggerParticles.sliceBy(perColTriggerParticles, collision.mcCollisionId()); - auto const mcParticlesThisEvent = mcParticles.sliceBy(perColMcParticles, collision.mcCollisionId()); - - auto const funcCorrelation = [this](auto const& collision, auto const& trigger, auto const& associated) { - fillMcCorrHists(collision, trigger, associated, 1); - }; - corrProcessCorrelation(mcCollision, triggerParticlesThisEvent, mcParticlesThisEvent, funcCorrelation); - - // select mixing events - if (doTrigEvMixing && !mcCollision.trigEv()) { - continue; - } - - auto const funcMixing = [this](auto const& collision, auto const& trigger, auto const& associated, auto const perTriggerWeight) { - fillMcCorrHists(collision, trigger, associated, perTriggerWeight); - }; - corrProcessMixing(mcCollision, mcParticlesThisEvent, funcMixing, nMixingAt0McTrue); - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processMcTrueAssocEvCorr, "process mc-true (reco collisions) correlation for multiple associated particles", false); - - void processMcTrueAssocEvRecoPtTrigCorr(CorrMcDCollisions const& collisions, aod::Triggers const& triggers, aod::JetTracksMCD const&, CorrMcCollisions const&, aod::JetParticles const& mcParticles) - { - for (auto const& collision : collisions) { - // event selection - if (!totalEvSel(collision)) { - continue; - } - - auto const& mcCollision = collision.mcCollision_as(); - - // group collision - auto const triggersThisEvent = triggers.sliceBy(perColTriggers, collision.globalIndex()); - auto const mcParticlesThisEvent = mcParticles.sliceBy(perColMcParticles, collision.mcCollisionId()); - - auto const funcCorrelation = [this](auto const& collision, auto const& trigger, auto const& associated) { - fillMcCorrHists(collision, trigger, associated, 1); - }; - corrProcessCorrelation(mcCollision, triggersThisEvent, mcParticlesThisEvent, funcCorrelation); - - // select mixing events - if (doTrigEvMixing && !mcCollision.trigEv()) { - continue; - } - - auto const funcMixing = [this](auto const& collision, auto const& trigger, auto const& associated, auto const perTriggerWeight) { - fillMcCorrHists(collision, trigger, associated, perTriggerWeight); - }; - corrProcessMixing(mcCollision, mcParticlesThisEvent, funcMixing, nMixingAt0McTrue); - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processMcTrueAssocEvRecoPtTrigCorr, "process mc-true (reco collisions with reco ptTrig) correlation for multiple associated particles", false); - - void processMcRecoCorrHadron(CorrMcDCollisions const& collisions, aod::Triggers const& triggers, aod::Hadrons const& hadrons, - aod::JetTracksMCD const&, aod::JetParticles const&) - { - for (auto const& collision : collisions) { - // event selection - if (!totalEvSel(collision)) { - continue; - } - - // group collision - auto const triggersThisEvent = triggers.sliceBy(perColTriggers, collision.globalIndex()); - auto const hadronsThisEvent = hadrons.sliceBy(perColHadrons, collision.globalIndex()); - - auto const funcCorrelation = [this](auto const& collision, auto const& trigger, auto const& associated) { - // exclude self correlation - if (trigger.jetTrackId() == associated.jetTrackId()) { - return; - } - - // check mc - if (!associated.template jetTrack_as().has_mcParticle()) { - return; - } - auto const& associatedMcParticle = associated.template jetTrack_as().mcParticle(); - // collision association - if (associatedMcParticle.mcCollisionId() != collision.mcCollisionId()) { - return; - } - histos.fill(HIST("mc/corr/h6_corr_recoAssocEv_hadron"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - // purity - if (!checkChargedMc(associatedMcParticle) || !associatedMcParticle.isPhysicalPrimary()) { - return; - } - histos.fill(HIST("mc/corr/h6_corr_recoPure_hadron"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - // true pt - histos.fill(HIST("mc/corr/h6_corr_recoPureTruePtAssoc_hadron"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associatedMcParticle.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - }; - corrProcessCorrelation(collision, triggersThisEvent, hadronsThisEvent, funcCorrelation); - - // select mixing events - if (doTrigEvMixing && !collision.trigEv()) { - continue; - } - - auto const funcMixing = [this](auto const& collision, auto const& trigger, auto const& associated, auto const perTriggerWeight) { - // check mc - if (!associated.template jetTrack_as().has_mcParticle()) { - return; - } - auto const& associatedMcParticle = associated.template jetTrack_as().mcParticle(); - // collision association - if (associatedMcParticle.mcCollisionId() != collision.mcCollisionId()) { - return; - } - histos.fill(HIST("mc/corr/h6_mix_recoAssocEv_hadron"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - // purity - if (!checkChargedMc(associatedMcParticle) || !associatedMcParticle.isPhysicalPrimary()) { - return; - } - histos.fill(HIST("mc/corr/h6_mix_recoPure_hadron"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - // true pt - histos.fill(HIST("mc/corr/h6_mix_recoPureTruePtAssoc_hadron"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associatedMcParticle.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - }; - corrProcessMixing(collision, hadronsThisEvent, funcMixing, nMixingAt0Hadron); - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processMcRecoCorrHadron, "process correlation for associated hardons with additional mc information", false); - - void processMcRecoCorrPipm(CorrMcDCollisions const& collisions, aod::Triggers const& triggers, aod::Pipms const& pipms, - aod::JetTracksMCD const&, aod::JetParticles const&) - { - for (auto const& collision : collisions) { - // event selection - if (!totalEvSel(collision)) { - continue; - } - - // group collision - auto const triggersThisEvent = triggers.sliceBy(perColTriggers, collision.globalIndex()); - auto const pipmsThisEvent = pipms.sliceBy(perColPipms, collision.globalIndex()); - - auto const funcCorrelation = [this](auto const& collision, auto const& trigger, auto const& associated) { - // exclude self correlation - if (trigger.jetTrackId() == associated.jetTrackId()) { - return; - } - - // check mc - if (!associated.template jetTrack_as().has_mcParticle()) { - return; - } - auto const& associatedMcParticle = associated.template jetTrack_as().mcParticle(); - // collision association - if (associatedMcParticle.mcCollisionId() != collision.mcCollisionId()) { - return; - } - histos.fill(HIST("mc/corr/h6_corr_recoAssocEv_pipm"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - // purity - if (std::abs(associatedMcParticle.pdgCode()) != PDG_t::kPiPlus || !associatedMcParticle.isPhysicalPrimary()) { - return; - } - histos.fill(HIST("mc/corr/h6_corr_recoPure_pipm"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - // true pt - histos.fill(HIST("mc/corr/h6_corr_recoPureTruePtAssoc_pipm"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associatedMcParticle.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - }; - corrProcessCorrelation(collision, triggersThisEvent, pipmsThisEvent, funcCorrelation); - - // select mixing events - if (doTrigEvMixing && !collision.trigEv()) { - continue; - } - - auto const funcMixing = [this](auto const& collision, auto const& trigger, auto const& associated, auto const perTriggerWeight) { - // check mc - if (!associated.template jetTrack_as().has_mcParticle()) { - return; - } - auto const& associatedMcParticle = associated.template jetTrack_as().mcParticle(); - // collision association - if (associatedMcParticle.mcCollisionId() != collision.mcCollisionId()) { - return; - } - histos.fill(HIST("mc/corr/h6_mix_recoAssocEv_pipm"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - // purity - if (std::abs(associatedMcParticle.pdgCode()) != PDG_t::kPiPlus || !associatedMcParticle.isPhysicalPrimary()) { - return; - } - histos.fill(HIST("mc/corr/h6_mix_recoPure_pipm"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - // true pt - histos.fill(HIST("mc/corr/h6_mix_recoPureTruePtAssoc_pipm"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associatedMcParticle.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - }; - corrProcessMixing(collision, pipmsThisEvent, funcMixing, nMixingAt0Pipm); - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processMcRecoCorrPipm, "process correlation for associated pipms with additional mc information", false); - - void processMcRecoCorrPhotonPCM(CorrMcDCollisions const& collisions, aod::Triggers const& triggers, aod::PhotonPCMs const& photonPCMs, - aod::JetTracksMCD const&, aod::JetParticles const&) - { - for (auto const& collision : collisions) { - // event selection - if (!totalEvSel(collision)) { - continue; - } - - // group collision - auto const triggersThisEvent = triggers.sliceBy(perColTriggers, collision.globalIndex()); - auto const photonPCMsThisEvent = photonPCMs.sliceBy(perColPhotonPCMs, collision.globalIndex()); - - auto const funcCorrelation = [this](auto const& collision, auto const& trigger, auto const& associated) { - // exclude self correlation - if (trigger.jetTrackId() == associated.posJetTrackId() || trigger.jetTrackId() == associated.negJetTrackId()) { - return; - } - - // check mc - auto const& posTrack = associated.template posJetTrack_as(); - auto const& negTrack = associated.template negJetTrack_as(); - if (!posTrack.has_mcParticle() || !negTrack.has_mcParticle()) { - return; - } - // collision association - if (posTrack.mcParticle().mcCollisionId() != collision.mcCollisionId() || negTrack.mcParticle().mcCollisionId() != collision.mcCollisionId()) { - return; - } - histos.fill(HIST("mc/corr/h6_corr_recoAssocEv_photonPCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - // purity - auto const& photons = posTrack.mcParticle().template mothers_as(); - if (!isConversionPhoton(posTrack, negTrack) || !photons.begin()->isPhysicalPrimary()) { - return; - } - histos.fill(HIST("mc/corr/h6_corr_recoPure_photonPCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - // true pt - histos.fill(HIST("mc/corr/h6_corr_recoPureTruePtAssoc_photonPCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), photons.begin()->pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - }; - corrProcessCorrelation(collision, triggersThisEvent, photonPCMsThisEvent, funcCorrelation); - - // select mixing events - if (doTrigEvMixing && !collision.trigEv()) { - continue; - } - - auto const funcMixing = [this](auto const& collision, auto const& trigger, auto const& associated, auto const perTriggerWeight) { - // check mc - auto const& posTrack = associated.template posJetTrack_as(); - auto const& negTrack = associated.template negJetTrack_as(); - if (!posTrack.has_mcParticle() || !negTrack.has_mcParticle()) { - return; - } - // collision association - if (posTrack.mcParticle().mcCollisionId() != collision.mcCollisionId() || negTrack.mcParticle().mcCollisionId() != collision.mcCollisionId()) { - return; - } - histos.fill(HIST("mc/corr/h6_mix_recoAssocEv_photonPCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - // purity - auto const& photons = posTrack.mcParticle().template mothers_as(); - if (!isConversionPhoton(posTrack, negTrack) || !photons.begin()->isPhysicalPrimary()) { - return; - } - histos.fill(HIST("mc/corr/h6_mix_recoPure_photonPCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - // true pt - histos.fill(HIST("mc/corr/h6_mix_recoPureTruePtAssoc_photonPCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), photons.begin()->pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - }; - corrProcessMixing(collision, photonPCMsThisEvent, funcMixing, nMixingAt0PhotonPCM); - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processMcRecoCorrPhotonPCM, "process correlation for associated photonPCMs with additional mc information", false); - - void processMcRecoCorrPi0PCM(CorrMcDCollisions const& collisions, aod::Triggers const& triggers, aod::PhotonPCMPairs const& photonPCMPairs, - aod::JetTracksMCD const&, aod::JetParticles const&) - { - for (auto const& collision : collisions) { - // event selection - if (!totalEvSel(collision)) { - continue; - } - - // group collision - auto const triggersThisEvent = triggers.sliceBy(perColTriggers, collision.globalIndex()); - auto const photonPCMPairsThisEvent = photonPCMPairs.sliceBy(perColPhotonPCMPairs, collision.globalIndex()); - - auto const funcCorrelation = [this](auto const& collision, auto const& trigger, auto const& associated) { - // exclude self correlation - if (trigger.jetTrackId() == associated.posJetTrack1Id() || trigger.jetTrackId() == associated.negJetTrack1Id() || - trigger.jetTrackId() == associated.posJetTrack2Id() || trigger.jetTrackId() == associated.negJetTrack2Id()) { - return; - } - - // check mc - auto const& posTrack1 = associated.template posJetTrack1_as(); - auto const& negTrack1 = associated.template negJetTrack1_as(); - auto const& posTrack2 = associated.template posJetTrack2_as(); - auto const& negTrack2 = associated.template negJetTrack2_as(); - if (!posTrack1.has_mcParticle() || !negTrack1.has_mcParticle() || !posTrack2.has_mcParticle() || !negTrack2.has_mcParticle()) { - return; - } - // pseudo yield - if (!isGGFromDoubleConversion(posTrack1, negTrack1, posTrack2, negTrack2, PDG_t::kPi0)) { - return; - } - histos.fill(HIST("mc/corr/h6_corr_pseudoReco_pi0PCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - // collision association - if (posTrack1.mcParticle().mcCollisionId() != collision.mcCollisionId()) { - return; - } - histos.fill(HIST("mc/corr/h6_corr_pseudoRecoAssocEv_pi0PCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - // purity (just secondaries) - auto const& photons1 = posTrack1.mcParticle().template mothers_as(); - auto const& mothersOfPhoton = photons1.begin()->template mothers_as(); - if (!checkDecayPrimary(*(mothersOfPhoton.begin()))) { - return; - } - histos.fill(HIST("mc/corr/h6_corr_pseudoRecoPure_pi0PCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - // true pt - histos.fill(HIST("mc/corr/h6_corr_pseudoRecoPureTruePtAssoc_pi0PCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), mothersOfPhoton.begin()->pt(), collision.posZ(), collision.nGlobalTracks(), - getPtCorrection(trigger.pt())); - }; - corrProcessCorrelation(collision, triggersThisEvent, photonPCMPairsThisEvent, funcCorrelation); - - // select mixing events - if (doTrigEvMixing && !collision.trigEv()) { - continue; - } - - auto const funcMixing = [this](auto const& collision, auto const& trigger, auto const& associated, auto const perTriggerWeight) { - // check mc - auto const& posTrack1 = associated.template posJetTrack1_as(); - auto const& negTrack1 = associated.template negJetTrack1_as(); - auto const& posTrack2 = associated.template posJetTrack2_as(); - auto const& negTrack2 = associated.template negJetTrack2_as(); - if (!posTrack1.has_mcParticle() || !negTrack1.has_mcParticle() || !posTrack2.has_mcParticle() || !negTrack2.has_mcParticle()) { - return; - } - // pseudo yield - if (!isGGFromDoubleConversion(posTrack1, negTrack1, posTrack2, negTrack2, PDG_t::kPi0)) { - return; - } - histos.fill(HIST("mc/corr/h6_mix_pseudoReco_pi0PCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - // collision association - if (posTrack1.mcParticle().mcCollisionId() != collision.mcCollisionId()) { - return; - } - histos.fill(HIST("mc/corr/h6_mix_pseudoRecoAssocEv_pi0PCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - // purity (just secondaries) - auto const& photons1 = posTrack1.mcParticle().template mothers_as(); - auto const& mothersOfPhoton = photons1.begin()->template mothers_as(); - if (!checkDecayPrimary(*(mothersOfPhoton.begin()))) { - return; - } - histos.fill(HIST("mc/corr/h6_mix_pseudoRecoPure_pi0PCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), associated.pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - // true pt - histos.fill(HIST("mc/corr/h6_mix_pseudoRecoPureTruePtAssoc_pi0PCM"), - getDeltaPhi(trigger.phi(), associated.phi()), - trigger.eta() - associated.eta(), - trigger.pt(), mothersOfPhoton.begin()->pt(), collision.posZ(), collision.nGlobalTracks(), - perTriggerWeight * getPtCorrection(trigger.pt())); - }; - corrProcessMixing(collision, photonPCMPairsThisEvent, funcMixing, nMixingAt0PhotonPCM); - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processMcRecoCorrPi0PCM, "process correlation for associated pi0PCMs with additional mc information", false); - - // other //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - - enum class McCorrectionObservable : int { PhiEta = 0, - ZPvMult = 1 }; - enum class McResolvedTruthLevel : int { Reco = 0, - RecoAssocEv = 1, - RecoPure = 2, - TrueAssocEvRecoPtTrig = 3, - TrueAssocEv = 4, - True = 5 }; - enum class CorrAssocType : int { Hadron = 0, - Pipm = 1, - PhotonPCM = 2 }; - static constexpr std::array, 6>, 2> McResolvedCorrectionHistPaths = { - {{{{"mc/correction/resol/h4_ptTrigPtAssocPhiEta_reco_hadron", - "mc/correction/resol/h4_ptTrigPtAssocPhiEta_reco_pipm", - "mc/correction/resol/h4_ptTrigPtAssocPhiEta_reco_photonPCM"}, - {"mc/correction/resol/h4_ptTrigPtAssocPhiEta_recoAssocEv_hadron", - "mc/correction/resol/h4_ptTrigPtAssocPhiEta_recoAssocEv_pipm", - "mc/correction/resol/h4_ptTrigPtAssocPhiEta_recoAssocEv_photonPCM"}, - {"mc/correction/resol/h4_ptTrigPtAssocPhiEta_recoPure_hadron", - "mc/correction/resol/h4_ptTrigPtAssocPhiEta_recoPure_pipm", - "mc/correction/resol/h4_ptTrigPtAssocPhiEta_recoPure_photonPCM"}, - {"mc/correction/resol/h4_ptTrigPtAssocPhiEta_trueAssocEvRecoPtTrig_hadron", - "mc/correction/resol/h4_ptTrigPtAssocPhiEta_trueAssocEvRecoPtTrig_pipm", - "mc/correction/resol/h4_ptTrigPtAssocPhiEta_trueAssocEvRecoPtTrig_photon"}, - {"mc/correction/resol/h4_ptTrigPtAssocPhiEta_trueAssocEv_hadron", - "mc/correction/resol/h4_ptTrigPtAssocPhiEta_trueAssocEv_pipm", - "mc/correction/resol/h4_ptTrigPtAssocPhiEta_trueAssocEv_photon"}, - {"mc/correction/resol/h4_ptTrigPtAssocPhiEta_true_hadron", - "mc/correction/resol/h4_ptTrigPtAssocPhiEta_true_pipm", - "mc/correction/resol/h4_ptTrigPtAssocPhiEta_true_photon"}}}, - {{{"mc/correction/resol/h4_ptTrigPtAssocZPvMult_reco_hadron", - "mc/correction/resol/h4_ptTrigPtAssocZPvMult_reco_pipm", - "mc/correction/resol/h4_ptTrigPtAssocZPvMult_reco_photonPCM"}, - {"mc/correction/resol/h4_ptTrigPtAssocZPvMult_recoAssocEv_hadron", - "mc/correction/resol/h4_ptTrigPtAssocZPvMult_recoAssocEv_pipm", - "mc/correction/resol/h4_ptTrigPtAssocZPvMult_recoAssocEv_photonPCM"}, - {"mc/correction/resol/h4_ptTrigPtAssocZPvMult_recoPure_hadron", - "mc/correction/resol/h4_ptTrigPtAssocZPvMult_recoPure_pipm", - "mc/correction/resol/h4_ptTrigPtAssocZPvMult_recoPure_photonPCM"}, - {"mc/correction/resol/h4_ptTrigPtAssocZPvMult_trueAssocEvRecoPtTrig_hadron", - "mc/correction/resol/h4_ptTrigPtAssocZPvMult_trueAssocEvRecoPtTrig_pipm", - "mc/correction/resol/h4_ptTrigPtAssocZPvMult_trueAssocEvRecoPtTrig_photon"}, - {"mc/correction/resol/h4_ptTrigPtAssocZPvMult_trueAssocEv_hadron", - "mc/correction/resol/h4_ptTrigPtAssocZPvMult_trueAssocEv_pipm", - "mc/correction/resol/h4_ptTrigPtAssocZPvMult_trueAssocEv_photon"}, - {"mc/correction/resol/h4_ptTrigPtAssocZPvMult_true_hadron", - "mc/correction/resol/h4_ptTrigPtAssocZPvMult_true_pipm", - "mc/correction/resol/h4_ptTrigPtAssocZPvMult_true_photon"}}}}}; - static constexpr char const* getMcResolvedCorrectionHistPath(McCorrectionObservable observable, McResolvedTruthLevel truthLevel, CorrAssocType assocType) - { - return McResolvedCorrectionHistPaths[static_cast(observable)][static_cast(truthLevel)][static_cast(assocType)]; - } - template - void fillResolvedCorrectionHists(auto const& collision, auto const& associated) - { - if constexpr (truthLevel == McResolvedTruthLevel::Reco || truthLevel == McResolvedTruthLevel::RecoAssocEv || truthLevel == McResolvedTruthLevel::RecoPure) { - histos.fill(HIST(getMcResolvedCorrectionHistPath(McCorrectionObservable::PhiEta, truthLevel, assocType)), - collision.ptMax(), associated.pt(), associated.phi(), associated.eta()); - histos.fill(HIST(getMcResolvedCorrectionHistPath(McCorrectionObservable::ZPvMult, truthLevel, assocType)), - collision.ptMax(), associated.pt(), collision.posZ(), collision.nGlobalTracks()); - } - if constexpr (truthLevel == McResolvedTruthLevel::TrueAssocEvRecoPtTrig) { - histos.fill(HIST(getMcResolvedCorrectionHistPath(McCorrectionObservable::PhiEta, truthLevel, assocType)), - collision.ptMax(), associated.pt(), associated.phi(), associated.eta()); - histos.fill(HIST(getMcResolvedCorrectionHistPath(McCorrectionObservable::ZPvMult, truthLevel, assocType)), - collision.ptMax(), associated.pt(), collision.template mcCollision_as().posZ(), collision.template mcCollision_as().nChargedInEtaRange()); - } - if constexpr (truthLevel == McResolvedTruthLevel::True || truthLevel == McResolvedTruthLevel::TrueAssocEv) { - histos.fill(HIST(getMcResolvedCorrectionHistPath(McCorrectionObservable::PhiEta, truthLevel, assocType)), - collision.ptMax(), associated.pt(), associated.phi(), associated.eta()); - histos.fill(HIST(getMcResolvedCorrectionHistPath(McCorrectionObservable::ZPvMult, truthLevel, assocType)), - collision.ptMax(), associated.pt(), collision.posZ(), collision.nChargedInEtaRange()); - } - } - - enum class PhotonImpurity { WrongEv, - Misid, - K0Short, - K0Long, - Lambda0, - Other }; - static constexpr double binValuePi0Impurities(PhotonImpurity const impurity) - { - return static_cast(impurity) + 0.5; - } - - void processMcRecoCorrection(CorrMcDCollision const& collision, aod::JetTracksMCD const&, - aod::Hadrons const& hadrons, aod::Pipms const& pipms, aod::PhotonPCMs const& photonPCMs, aod::PhotonPCMPairs const& photonPCMPairs, - CorrMcCollisions const&, aod::JetParticles const& mcParticles) - { - // event selection - if (!totalEvSel(collision)) { - return; - } - - auto const& mcCollision = collision.mcCollision_as(); - - // group collision - auto const mcParticlesThisEvent = mcParticles.sliceBy(perColMcParticles, collision.mcCollisionId()); - - // hadrons - for (auto const& hadron : hadrons) { - // reconstructed - fillResolvedCorrectionHists(collision, hadron); - // check mc - if (!hadron.jetTrack_as().has_mcParticle()) { - continue; - } - auto const& hadronParticle = hadron.jetTrack_as().mcParticle(); - // collision association - if (hadronParticle.mcCollisionId() != collision.mcCollisionId()) { - continue; - } - fillResolvedCorrectionHists(collision, hadron); - // purity - if (!checkChargedMc(hadronParticle) || !hadronParticle.isPhysicalPrimary()) { - continue; - } - fillResolvedCorrectionHists(collision, hadron); - } - - // pipm - for (auto const& pipm : pipms) { - // reconstructed - fillResolvedCorrectionHists(collision, pipm); - // check mc - if (!pipm.jetTrack_as().has_mcParticle()) { - continue; - } - auto const& pipmParticle = pipm.jetTrack_as().mcParticle(); - // collision association - if (pipmParticle.mcCollisionId() != collision.mcCollisionId()) { - continue; - } - fillResolvedCorrectionHists(collision, pipm); - // purity - if (std::abs(pipmParticle.pdgCode()) != PDG_t::kPiPlus || !pipmParticle.isPhysicalPrimary()) { - continue; - } - fillResolvedCorrectionHists(collision, pipm); - } - - // photonPCM - for (auto const& photonPCM : photonPCMs) { - // reconstructed - fillResolvedCorrectionHists(collision, photonPCM); - // check mc - auto const& posTrack = photonPCM.posJetTrack_as(); - auto const& negTrack = photonPCM.negJetTrack_as(); - if (!posTrack.has_mcParticle() || !negTrack.has_mcParticle()) { - continue; - } - // collision association - if (posTrack.mcParticle().mcCollisionId() != collision.mcCollisionId() || negTrack.mcParticle().mcCollisionId() != collision.mcCollisionId()) { - histos.fill(HIST("mc/correction/h3_ptTrigPtAssocCategory_recoImpurities_photonPCM"), - collision.ptMax(), photonPCM.pt(), binValuePi0Impurities(PhotonImpurity::WrongEv)); - continue; - } - fillResolvedCorrectionHists(collision, photonPCM); - // purity - if (!isConversionPhoton(posTrack, negTrack)) { - histos.fill(HIST("mc/correction/h3_ptTrigPtAssocCategory_recoImpurities_photonPCM"), - collision.ptMax(), photonPCM.pt(), binValuePi0Impurities(PhotonImpurity::Misid)); - continue; - } - auto const& photons = posTrack.mcParticle().mothers_as(); - if (!photons.begin()->isPhysicalPrimary()) { - if (checkForMother(*(photons.begin()), PDG_t::kK0Short, true)) { - histos.fill(HIST("mc/correction/h3_ptTrigPtAssocCategory_recoImpurities_photonPCM"), - collision.ptMax(), photonPCM.pt(), binValuePi0Impurities(PhotonImpurity::K0Short)); - continue; - } - if (checkForMother(*(photons.begin()), PDG_t::kK0Long, true)) { - histos.fill(HIST("mc/correction/h3_ptTrigPtAssocCategory_recoImpurities_photonPCM"), - collision.ptMax(), photonPCM.pt(), binValuePi0Impurities(PhotonImpurity::K0Long)); - continue; - } - if (checkForMother(*(photons.begin()), PDG_t::kLambda0, true)) { - histos.fill(HIST("mc/correction/h3_ptTrigPtAssocCategory_recoImpurities_photonPCM"), - collision.ptMax(), photonPCM.pt(), binValuePi0Impurities(PhotonImpurity::Lambda0)); - continue; - } - histos.fill(HIST("mc/correction/h3_ptTrigPtAssocCategory_recoImpurities_photonPCM"), - collision.ptMax(), photonPCM.pt(), binValuePi0Impurities(PhotonImpurity::Other)); - continue; - } - fillResolvedCorrectionHists(collision, photonPCM); - } - - // h0 PCM - for (auto const& photonPCMPair : photonPCMPairs) { - // check mc - auto const& posTrack1 = photonPCMPair.posJetTrack1_as(); - auto const& negTrack1 = photonPCMPair.negJetTrack1_as(); - auto const& posTrack2 = photonPCMPair.posJetTrack2_as(); - auto const& negTrack2 = photonPCMPair.negJetTrack2_as(); - if (!posTrack1.has_mcParticle() || !negTrack1.has_mcParticle() || !posTrack2.has_mcParticle() || !negTrack2.has_mcParticle()) { - continue; - } - - // pi0PCM - if (isGGFromDoubleConversion(posTrack1, negTrack1, posTrack2, negTrack2, PDG_t::kPi0)) { - // pseudo reconstructed - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_pseudoReco_pi0PCM"), collision.ptMax(), photonPCMPair.pt()); - // collision association - if (posTrack1.mcParticle().mcCollisionId() != collision.mcCollisionId()) { - histos.fill(HIST("mc/correction/h3_ptTrigPtAssocCategory_pseudoRecoImpurities_pi0PCM"), - collision.ptMax(), photonPCMPair.pt(), binValuePi0Impurities(PhotonImpurity::WrongEv)); - continue; - } - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_pseudoRecoAssocEv_pi0PCM"), collision.ptMax(), photonPCMPair.pt()); - // purity - // note: do not dereference 'mothers' and store element in 'const&' (leads to seg fault) - auto const& photons1 = posTrack1.mcParticle().mothers_as(); - auto const& mothersOfPhoton = photons1.begin()->mothers_as(); - auto const& grandmothersOfPhoton = mothersOfPhoton.begin()->mothers_as(); - if (!checkDecayPrimary(*(mothersOfPhoton.begin()))) { - if (std::abs(grandmothersOfPhoton.begin()->pdgCode()) == PDG_t::kK0Short) { - histos.fill(HIST("mc/correction/h3_ptTrigPtAssocCategory_pseudoRecoImpurities_pi0PCM"), - collision.ptMax(), photonPCMPair.pt(), binValuePi0Impurities(PhotonImpurity::K0Short)); - continue; - } - if (std::abs(grandmothersOfPhoton.begin()->pdgCode()) == PDG_t::kK0Long) { - histos.fill(HIST("mc/correction/h3_ptTrigPtAssocCategory_pseudoRecoImpurities_pi0PCM"), - collision.ptMax(), photonPCMPair.pt(), binValuePi0Impurities(PhotonImpurity::K0Long)); - continue; - } - if (std::abs(grandmothersOfPhoton.begin()->pdgCode()) == PDG_t::kLambda0) { - histos.fill(HIST("mc/correction/h3_ptTrigPtAssocCategory_pseudoRecoImpurities_pi0PCM"), - collision.ptMax(), photonPCMPair.pt(), binValuePi0Impurities(PhotonImpurity::Lambda0)); - continue; - } - histos.fill(HIST("mc/correction/h3_ptTrigPtAssocCategory_pseudoRecoImpurities_pi0PCM"), - collision.ptMax(), photonPCMPair.pt(), binValuePi0Impurities(PhotonImpurity::Other)); - continue; - } - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_pseudoRecoPure_pi0PCM"), - collision.ptMax(), photonPCMPair.pt()); - continue; - } - // etaPCM - if (isGGFromDoubleConversion(posTrack1, negTrack1, posTrack2, negTrack2, constants::physics::Pdg::kEta)) { - // pseudo reconstructed - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_pseudoReco_etaPCM"), collision.ptMax(), photonPCMPair.pt()); - // collision association - if (posTrack1.mcParticle().mcCollisionId() != collision.mcCollisionId()) { - continue; - } - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_pseudoRecoAssocEv_etaPCM"), collision.ptMax(), photonPCMPair.pt()); - // purity - auto const& photons1 = posTrack1.mcParticle().mothers_as(); - auto const& mothersOfPhoton = photons1.begin()->mothers_as(); - if (!checkDecayPrimary(*(mothersOfPhoton.begin()))) { - continue; - } - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_pseudoRecoPure_etaPCM"), collision.ptMax(), photonPCMPair.pt()); - continue; - } - } - - // mcParticle loop - for (auto const& mcParticle : mcParticlesThisEvent) { - if (std::abs(mcParticle.eta()) > absEtaMax) { - continue; - } - - // standard particles (marked physical primary) - if (mcParticle.isPhysicalPrimary()) { - // charged - // hadrons - if (checkChargedMc(mcParticle)) { - fillResolvedCorrectionHists(collision, mcParticle); - fillResolvedCorrectionHists(mcCollision, mcParticle); - } - // pipm - if (std::abs(mcParticle.pdgCode()) == PDG_t::kPiPlus) { - fillResolvedCorrectionHists(collision, mcParticle); - fillResolvedCorrectionHists(mcCollision, mcParticle); - continue; - } - // non charged - // photons - if (mcParticle.pdgCode() == PDG_t::kGamma) { - fillResolvedCorrectionHists(collision, mcParticle); - fillResolvedCorrectionHists(mcCollision, mcParticle); - continue; - } - continue; - } - - // decaying particles (not marked physical primary) - if (!checkDecayPrimary(mcParticle)) { - continue; - } - // pi0 - if (mcParticle.pdgCode() == PDG_t::kPi0) { - // true - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_trueAssocEv_pi0"), mcCollision.ptMax(), mcParticle.pt()); - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_trueAssocEvRecoPtTrig_pi0"), collision.ptMax(), mcParticle.pt()); - // chosen decay - if (!checkToGG(mcParticle)) { - continue; - } - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_trueMeasDecay_pi0"), collision.ptMax(), mcParticle.pt()); - // daughters in acceptance - if (!checkDaughtersInAcceptance(mcParticle, {-absEtaMax, absEtaMax})) { - continue; - } - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_trueGeoAcc_pi0"), collision.ptMax(), mcParticle.pt()); - continue; - } - // eta - if (mcParticle.pdgCode() == constants::physics::Pdg::kEta) { - // true - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_trueAssocEv_eta"), mcCollision.ptMax(), mcParticle.pt()); - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_trueAssocEvRecoPtTrig_eta"), collision.ptMax(), mcParticle.pt()); - // chosen decay - if (!checkToGG(mcParticle)) { - continue; - } - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_trueMeasDecay_eta"), collision.ptMax(), mcParticle.pt()); - // daughters in acceptance - if (!checkDaughtersInAcceptance(mcParticle, {-absEtaMax, absEtaMax})) { - continue; - } - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_trueGeoAcc_eta"), collision.ptMax(), mcParticle.pt()); - continue; - } - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processMcRecoCorrection, "process mc reconstruction to calculate corrections", false); - - void processMcTrueCorrection(CorrMcCollision const& mcCollision, aod::JetParticles const& mcParticles) - { - // event selection - if (!totalEvSel(mcCollision)) { - return; - } - - for (auto const& mcParticle : mcParticles) { - if (std::abs(mcParticle.eta()) > absEtaMax) { - continue; - } - - // standard particles (marked physical primary) - if (mcParticle.isPhysicalPrimary()) { - // charged - // hadrons - if (checkChargedMc(mcParticle)) { - fillResolvedCorrectionHists(mcCollision, mcParticle); - } - // pipm - if (std::abs(mcParticle.pdgCode()) == PDG_t::kPiPlus) { - fillResolvedCorrectionHists(mcCollision, mcParticle); - continue; - } - // non charged - // photons - if (mcParticle.pdgCode() == PDG_t::kGamma) { - fillResolvedCorrectionHists(mcCollision, mcParticle); - continue; - } - continue; - } - - // decaying particles (not marked physical primary) - if (!checkDecayPrimary(mcParticle)) { - continue; - } - // pi0 - if (mcParticle.pdgCode() == PDG_t::kPi0) { - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_true_pi0"), mcCollision.ptMax(), mcParticle.pt()); - continue; - } - // eta - if (mcParticle.pdgCode() == constants::physics::Pdg::kEta) { - histos.fill(HIST("mc/correction/h2_ptTrigPtAssoc_true_eta"), mcCollision.ptMax(), mcParticle.pt()); - continue; - } - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processMcTrueCorrection, "process mc true data to calculate corrections", false); - - void processPCMDCAzTrue(CorrMcDCollision const& collision, aod::PhotonPCMs const& photonPCMs, aod::V0PhotonsKF const&, aod::JetTracksMCD const&, - CorrMcCollisions const&, aod::JetParticles const&) - { - // event selection - if (!totalEvSel(collision)) { - return; - } - - for (auto const& photonPCM : photonPCMs) { - // check mc - auto const& posTrack = photonPCM.posJetTrack_as(); - auto const& negTrack = photonPCM.negJetTrack_as(); - if (!posTrack.has_mcParticle() || !negTrack.has_mcParticle()) { - continue; - } - // collision association - if (posTrack.mcParticle().mcCollisionId() != collision.mcCollisionId() || negTrack.mcParticle().mcCollisionId() != collision.mcCollisionId()) { - continue; - } - - histos.fill(HIST("mc/plain/h5_ptTrigPtAssocDCAzZPvMult_photonPCM"), - collision.ptMax(), photonPCM.pt(), photonPCM.v0PhotonKF().dcaZtopv(), collision.posZ(), collision.nGlobalTracks()); - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processPCMDCAzTrue, "process to test true DCAz distribution of photons in trigger collisions", false); - - // last ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - - void processRecoLast(CorrCollisions const& collisions, aod::Triggers const& triggers) - { - // do at end of each data frame (after other reco correlation process functions) - // (PROCESS_SWITCH of this process has to be declared last) - - for (auto const& collision : collisions) { - // all events - histos.fill(HIST("reco/info/h1_nEvents"), 0.5); - - // mc split - if (!checkSplitMcEventSelection(collision)) { - continue; - } - histos.fill(HIST("reco/info/h1_nEvents"), 1.5); - - // standard event selection - if (!collision.selEv()) { - continue; - } - histos.fill(HIST("reco/info/h1_nEvents"), 2.5); - - histos.fill(HIST("reco/info/h3_ptTrigZPvMult"), collision.ptMax(), collision.posZ(), collision.nGlobalTracks()); - histos.fill(HIST("reco/info/h2_ptTrigOccupancy"), collision.ptMax(), collision.trackOccupancyInTimeRange()); - - // group collision - auto const triggersThisEvent = triggers.sliceBy(perColTriggers, collision.globalIndex()); - - // trigger loop - for (auto const& trigger : triggersThisEvent) { - // trigger info - histos.fill(HIST("reco/corr/h3_ptPhiEta_trig"), trigger.pt(), trigger.phi(), trigger.eta(), - getPtCorrection(trigger.pt())); - - // save trigger for mixing - triggerMemoryReco->saveTrigger(trigger.pt(), trigger.phi(), trigger.eta(), collision.posZ(), collision.nGlobalTracks()); - } - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processRecoLast, "process general info for reconstructed collisions and later correlations last", true); - - void processMcLast(CorrMcDCollisions const& collisions, aod::Triggers const& triggers, aod::JetTracksMCD const&, - CorrMcCollisions const& mcCollisions, aod::TriggerParticles const& triggerParticles, aod::JetParticles const&) - { - for (auto const& mcCollision : mcCollisions) { - // event selection - if (!totalEvSel(mcCollision)) { - continue; - } - - // group collision - auto const triggerParticlesThisEvent = triggerParticles.sliceBy(perColTriggerParticles, mcCollision.globalIndex()); - - histos.fill(HIST("mc/info/h3_ptTrigZPvMult_true"), mcCollision.ptMax(), mcCollision.posZ(), mcCollision.nChargedInEtaRange()); - - // trigger loop - for (auto const& trigger : triggerParticlesThisEvent) { - // trigger info - histos.fill(HIST("mc/corr/h3_ptPhiEta_trig_true"), trigger.pt(), trigger.phi(), trigger.eta()); - - // save trigger for mixing - triggerMemoryTrue->saveTrigger(trigger.pt(), trigger.phi(), trigger.eta(), mcCollision.posZ(), mcCollision.nChargedInEtaRange()); - } - } - for (auto const& collision : collisions) { - // event selection - if (!totalEvSel(collision)) { - continue; - } - - auto const& mcCollision = collision.mcCollision_as(); - - // group collision - auto const triggerParticlesThisEvent = triggerParticles.sliceBy(perColTriggerParticles, mcCollision.globalIndex()); - auto const triggersThisEvent = triggers.sliceBy(perColTriggers, collision.globalIndex()); - - histos.fill(HIST("mc/info/h3_ptTrigZPvMult_trueAssocEv"), mcCollision.ptMax(), mcCollision.posZ(), mcCollision.nChargedInEtaRange()); - histos.fill(HIST("mc/info/h3_ptTrigZPvMult_trueAssocEvRecoPtTrig"), collision.ptMax(), mcCollision.posZ(), mcCollision.nChargedInEtaRange()); - - // trigger loops - for (auto const& triggerParticle : triggerParticlesThisEvent) { - // trigger info - histos.fill(HIST("mc/corr/h3_ptPhiEta_trig_trueAssocEv"), triggerParticle.pt(), triggerParticle.phi(), triggerParticle.eta()); - - // save trigger for mixing - triggerMemoryTrueAssocEv->saveTrigger(triggerParticle.pt(), triggerParticle.phi(), triggerParticle.eta(), mcCollision.posZ(), mcCollision.nChargedInEtaRange()); - } - for (auto const& trigger : triggersThisEvent) { - if (!trigger.jetTrack_as().has_mcParticle()) { - continue; - } - - auto const& triggerParticle = trigger.jetTrack_as().mcParticle(); - - // trigger info - histos.fill(HIST("mc/corr/h3_ptPhiEta_trig_trueAssocEvRecoPtTrig"), trigger.pt(), triggerParticle.phi(), triggerParticle.eta()); - - // save trigger for mixing - triggerMemoryTrueAssocEvRecoPtTrig->saveTrigger(trigger.pt(), triggerParticle.phi(), triggerParticle.eta(), mcCollision.posZ(), mcCollision.nChargedInEtaRange()); - } - } - } - PROCESS_SWITCH(PhotonChargedTriggerCorrelation, processMcLast, "process general MC info for collisions and later correlations last", false); -}; - -WorkflowSpec defineDataProcessing(ConfigContext const& configContext) -{ - return WorkflowSpec{adaptAnalysisTask(configContext)}; -} diff --git a/PWGJE/Tasks/photonChargedTriggerProducer.cxx b/PWGJE/Tasks/photonChargedTriggerProducer.cxx deleted file mode 100644 index 9e16a69e1cc..00000000000 --- a/PWGJE/Tasks/photonChargedTriggerProducer.cxx +++ /dev/null @@ -1,484 +0,0 @@ -// 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 photonChargedTriggerProducer.cxx -/// \author Julius Kinner -/// \brief photon-jet angular correlation table producer -/// -/// Table producer for photon-jet angular correlation analysis (see photonChargedTriggerCorrelation.cxx) - -#include "PWGJE/Core/JetDerivedDataUtilities.h" -#include "PWGJE/DataModel/Jet.h" -#include "PWGJE/DataModel/JetReducedData.h" -#include "PWGJE/DataModel/PhotonChargedTriggerCorrelation.h" -// -#include "PWGEM/PhotonMeson/DataModel/gammaTables.h" - -#include "Common/Core/RecoDecay.h" -#include "Common/DataModel/PIDResponseTOF.h" -#include "Common/DataModel/PIDResponseTPC.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include // IWYU pragma: keep (do not replace with Math/Vector4Dfwd.h) -#include - -#include -#include -#include -#include -#include - -using namespace o2; -using namespace o2::framework; - -// correlation derived data =================================================================================================================================================================== - -template -concept IsJetMcCollision = std::same_as, aod::JetMcCollision>; -template -concept IsJetCollisionMCD = std::same_as, aod::JetCollisionMCD>; -template -concept HasTrueCollision = IsJetMcCollision || IsJetCollisionMCD; - -struct PhotonChargedTriggerProducer { - struct : ProducesGroup { - // reco - Produces collisionExtraCorr; - Produces trigger; - Produces hadron; - Produces pipm; - Produces photonPCM; - Produces photonPCMPair; - // mc - Produces mcCollisionExtraCorr; - Produces triggerParticle; - } tableProduction; - - Configurable zPvMax{"zPvMax", 7, "maximum absZ primary-vertex cut"}; - Configurable occupancyMin{"occupancyMin", 0, "minimum occupancy cut"}; - Configurable occupancyMax{"occupancyMax", 2000, "maximum occupancy cut"}; - Configurable absEtaMax{"absEtaMax", 0.8, "maximum absEta cut"}; - - Configurable eventSelections{"eventSelections", "sel8", "JE framework - event selection"}; - Configurable skipMBGapEvents{"skipMBGapEvents", true, "skip MB gap events"}; - Configurable applyRctSelection{"applyRctSelection", true, "apply RCT selection"}; - Configurable rctLabel{"rctLabel", "CBT_hadronPID", "RCT selection label"}; - Configurable trackSelections{"trackSelections", "globalTracks", "JE framework - track selections"}; - Configurable triggerMasks{"triggerMasks", "", "JE framework - skimmed data trigger masks (relevent for correlation: fTrackLowPt,fTrackHighPt)"}; - - Configurable piPIDLowPt{"piPIDLowPt", 0.5, "max pt value for pipm PID without tof"}; - Configurable piPIDHighPt{"piPIDHighPt", 2.5, "min pt value for pipm PID without tof in relativistic rise of Bethe-Bloch"}; - Configurable> nSigmaPiTpcLowPt{"nSigmaPiTpcLowPt", {-2, 2}, "minimum-maximum nSigma for pipm in tpc at low pt"}; - Configurable> nSigmaPiTpcMidPt{"nSigmaPiTpcMidPt", {-1, 1}, "minimum-maximum nSigma for pipm in tpc at mid pt"}; - Configurable> nSigmaPiTof{"nSigmaPiTof", {-1, 2}, "minimum-maximum nSigma for pipm in tof"}; - Configurable> nSigmaPiRelRise{"nSigmaPiRelRise", {0, 2}, "minimum-maximum nSigma pipm tpc at high pt"}; - - Configurable> pcmAbsDcaZLim{"pcmAbsDcaZLim", {0, 5}, "absolute values of DCAz limits for PCM"}; - - Configurable ptTrigMin{"ptTrigMin", 5, "minimum pT of triggers"}; - Configurable oneTriggerPerEvent{"oneTriggerPerEvent", false, "use only one trigger (of highest pt) in an event"}; - - // derivatives of configurables - - std::vector eventSelectionBits; - int trackSelection = -1; - std::vector triggerMaskBits; - - HistogramRegistry histos{"histogramRegistry", {}, OutputObjHandlingPolicy::AnalysisObject, false, false}; - - // for mc - Service pdg{}; - - // partitions++ - SliceCache cache; - - Preslice perColTracks = aod::jtrack::collisionId; - Preslice perColMcParticles = aod::jmcparticle::mcCollisionId; - - Preslice perColV0Photons = aod::v0photonkf::collisionId; - - // functions ================================================================================================================================================================================ - - // selections /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - // event selection - template - bool checkEventSelection(T_collision const& collision) - { - if (!jetderiveddatautilities::selectTrigger(collision, triggerMaskBits)) { - return false; - } - if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits, skipMBGapEvents, applyRctSelection, rctLabel)) { - return false; - } - if (std::abs(collision.posZ()) > zPvMax) { - return false; - } - if (collision.trackOccupancyInTimeRange() < occupancyMin || collision.trackOccupancyInTimeRange() > occupancyMax) { - return false; - } - return true; - } - - // mc split event selection based in the thrid decimal of mc-true posZ - template - int getThirdDecimalTruePosZ(T_collision const& collision) - { - // get third decimal - double absPosZ = -1; - if constexpr (IsJetCollisionMCD) { - absPosZ = std::abs(collision.template mcCollision_as().posZ()); - } else { - absPosZ = std::abs(collision.posZ()); - } - int const thirdDecimalPosZ = static_cast(1000 * absPosZ) % 10; - return thirdDecimalPosZ; - } - - // checks global track cuts - template - bool checkGlobalTrackEta(T_track const& track) - { - if (!jetderiveddatautilities::selectTrack(track, trackSelection)) { - return false; - } - if (!jetderiveddatautilities::applyTrackKinematics(track, 0.1, 1000, -1 * absEtaMax, absEtaMax)) { - return false; - } - return true; - } - - // checks pipm selection (just PID (no additional track cuts)) - template - bool checkPipmTPCTOF(T_track const& track) - { - // too low for tof - if (track.pt() < piPIDLowPt) { - return (track.tpcNSigmaPi() > nSigmaPiTpcLowPt.value[0] && track.tpcNSigmaPi() < nSigmaPiTpcLowPt.value[1]); - } - // Bethe-Bloch overlap (-> tpc + tof) - if (track.pt() < piPIDHighPt) { - if (track.hasTOF()) { // has to stay inside pt-if due to return-layout of function - if (track.tpcNSigmaPi() > nSigmaPiTpcMidPt.value[0] && track.tpcNSigmaPi() < nSigmaPiTpcMidPt.value[1] && - track.tofNSigmaPi() > nSigmaPiTof.value[0] && track.tofNSigmaPi() < nSigmaPiTof.value[1]) { - return true; - } - } - return false; - } - // Bethe-Bloch rel rise (too high for tof) - return (track.tpcNSigmaPi() > nSigmaPiRelRise.value[0] && track.tpcNSigmaPi() < nSigmaPiRelRise.value[1]); - } - - // checks pipm selection (just PID (no additional track cuts)) - template - bool checkPipmTPC(T_track const& track) - { - // Bethe-Bloch rel rise - if (track.pt() > piPIDHighPt) { - if (track.tpcNSigmaPi() > nSigmaPiRelRise.value[0] && track.tpcNSigmaPi() < nSigmaPiRelRise.value[1]) { - return true; - } - } - return false; - } - - // analysis ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - void init(InitContext const&) - { - eventSelectionBits = jetderiveddatautilities::initialiseEventSelectionBits(eventSelections); - trackSelection = jetderiveddatautilities::initialiseTrackSelection(trackSelections); - triggerMaskBits = jetderiveddatautilities::initialiseTriggerMaskBits(triggerMasks); - - // histograms - AxisSpec const axisZPv{28, -7, 7, "#it{z}_{pv}"}; - AxisSpec const axisMult{65, -0.5, 64.5, "multiplicity"}; - AxisSpec const axisHadronicRate{1001, -0.5, 1000.5, "hadronicRate"}; - AxisSpec const axisPt{50, 0, 25, "#it{p}_{T}"}; - AxisSpec const axisPhi{72, 0, constants::math::TwoPI, "#varphi"}; - AxisSpec const axisEta{32, -absEtaMax, absEtaMax, "#eta"}; - // reco - histos.add("reco/h2_zPvMult", "h2_zPvMult", kTHnSparseD, {axisZPv, axisMult}, true); - histos.add("reco/h1_hadronicRate", "h1_hadronicRate", kTH1D, {axisHadronicRate}, true); - histos.add("reco/h3_ptPhiEta_trigger", "h3_ptPhiEta_trigger", kTHnSparseD, {axisPt, axisPhi, axisEta}, true); - histos.add("reco/h3_ptPhiEta_hadron", "h3_ptPhiEta_hadron", kTHnSparseD, {axisPt, axisPhi, axisEta}, true); - histos.add("reco/h3_ptPhiEta_pipm", "h3_ptPhiEta_pipm", kTHnSparseD, {axisPt, axisPhi, axisEta}, true); - histos.add("reco/h3_ptPhiEta_photonPCM", "h3_ptPhiEta_photonPCM", kTHnSparseD, {axisPt, axisPhi, axisEta}, true); - histos.add("reco/h3_ptPhiEta_photonPCMPair", "h3_ptPhiEta_photonPCMPair", kTHnSparseD, {axisPt, axisPhi, axisEta}, true); - // true - histos.add("true/h2_zPvMult", "h2_zPvMult", kTHnSparseD, {axisZPv, axisMult}, true); - histos.add("true/h3_ptPhiEta_trigger", "h3_ptPhiEta_trigger", kTHnSparseD, {axisPt, axisPhi, axisEta}, true); - } - - template - void fillRecoCollisionTrigger(T_collision const& collision, T_tracks const& tracks) - { - // event selection - bool isSelectedEvent = checkEventSelection(collision); - // mc split event selection - // default -1 for data reconstruction - int thirdDecimalTruePosZ = -1; - if constexpr (IsJetCollisionMCD) { - thirdDecimalTruePosZ = getThirdDecimalTruePosZ(collision); - } - // maximum track pt - float maxTrackPt = -1; - int maxTriggerCollisionId = -1; - int maxTriggerGlobalIndex = -1; - float maxTriggerPhi = 0; - float maxTriggerEta = 0; - // number global tracks - int nGlobalTracks = 0; - - // count global tracks (for independence of multiplicity task (uses only JE derieved data)) - for (auto const& track : tracks) { - // track selection - if (!checkGlobalTrackEta(track)) { - continue; - } - - nGlobalTracks++; - if (track.pt() > maxTrackPt) { - maxTrackPt = track.pt(); - maxTriggerCollisionId = track.collisionId(); - maxTriggerGlobalIndex = track.globalIndex(); - maxTriggerPhi = track.phi(); - maxTriggerEta = track.eta(); - } - - if (!isSelectedEvent) { - continue; - } - if (track.pt() < ptTrigMin) { - continue; - } - if (oneTriggerPerEvent) { - continue; - } - - // trigger info - histos.fill(HIST("reco/h3_ptPhiEta_trigger"), track.pt(), track.phi(), track.eta()); - tableProduction.trigger(track.collisionId(), track.globalIndex(), track.pt(), track.phi(), track.eta()); - } - bool const isTriggerEvent = maxTrackPt > ptTrigMin; - if (oneTriggerPerEvent && isSelectedEvent && isTriggerEvent) { - histos.fill(HIST("reco/h3_ptPhiEta_trigger"), maxTrackPt, maxTriggerPhi, maxTriggerEta); - tableProduction.trigger(maxTriggerCollisionId, maxTriggerGlobalIndex, maxTrackPt, maxTriggerPhi, maxTriggerEta); - } - - // collision info - histos.fill(HIST("reco/h2_zPvMult"), collision.posZ(), nGlobalTracks); - histos.fill(HIST("reco/h1_hadronicRate"), collision.hadronicRate()); - tableProduction.collisionExtraCorr(isSelectedEvent, thirdDecimalTruePosZ, isTriggerEvent, maxTrackPt, nGlobalTracks); - } - - void processRecoCollisionTrigger(aod::JetCollision const& collision, aod::JetTracks const& tracks) - { - fillRecoCollisionTrigger(collision, tracks); - } - PROCESS_SWITCH(PhotonChargedTriggerProducer, processRecoCollisionTrigger, "process correlation collision_extra and trigger table (reconstructed)", false); - - void processMcRecoCollisionTrigger(aod::JetCollisionMCD const& collision, aod::JetTracks const& tracks, aod::JetMcCollisions const&) - { - fillRecoCollisionTrigger(collision, tracks); - } - PROCESS_SWITCH(PhotonChargedTriggerProducer, processMcRecoCollisionTrigger, "process correlation collision_extra and trigger table (reconstructed MC)", false); - - void processRecoPipmTPCTOF(aod::JetCollision const& collision, - soa::Join const& tracks, soa::Join const&) - { - // event selection - if (!checkEventSelection(collision)) { - return; - } - - // hadron/pipm - for (auto const& track : tracks) { - // track selection - if (!checkGlobalTrackEta(track)) { - continue; - } - - // hadron - histos.fill(HIST("reco/h3_ptPhiEta_hadron"), track.pt(), track.phi(), track.eta()); - tableProduction.hadron(track.collisionId(), track.globalIndex(), track.pt(), track.phi(), track.eta()); - - // pipm selection - auto const& trackPID = track.track_as>(); - if (!checkPipmTPCTOF(trackPID)) { - continue; - } - - // pipm - histos.fill(HIST("reco/h3_ptPhiEta_pipm"), track.pt(), track.phi(), track.eta()); - tableProduction.pipm(track.collisionId(), track.globalIndex(), track.pt(), track.phi(), track.eta()); - } - } - PROCESS_SWITCH(PhotonChargedTriggerProducer, processRecoPipmTPCTOF, "process pipm (TPC-TOF) table (reconstructed)", false); - - void processRecoPipmTPC(aod::JetCollision const& collision, - soa::Join const& tracks, soa::Join const&) - { - // event selection - if (!checkEventSelection(collision)) { - return; - } - - // hadron/pipm - for (auto const& track : tracks) { - // track selection - if (!checkGlobalTrackEta(track)) { - continue; - } - - // hadron - histos.fill(HIST("reco/h3_ptPhiEta_hadron"), track.pt(), track.phi(), track.eta()); - tableProduction.hadron(track.collisionId(), track.globalIndex(), track.pt(), track.phi(), track.eta()); - - // pipm selection - auto const& trackPID = track.track_as>(); - if (!checkPipmTPC(trackPID)) { - continue; - } - - // pipm - histos.fill(HIST("reco/h3_ptPhiEta_pipm"), track.pt(), track.phi(), track.eta()); - tableProduction.pipm(track.collisionId(), track.globalIndex(), track.pt(), track.phi(), track.eta()); - } - } - PROCESS_SWITCH(PhotonChargedTriggerProducer, processRecoPipmTPC, "process pipm (TPC) table (reconstructed)", false); - - void processRecoPhotonPCM(soa::Join::iterator const& collision, - aod::V0PhotonsKF const& v0Photons, aod::V0Legs const&) - { - // event selection - if (!checkEventSelection(collision)) { - return; - } - - // photonsPCM (for some reason collsionId not an index column (?)) - auto const v0PhotonsThisEvent = v0Photons.sliceBy(perColV0Photons, collision.collisionId()); - - // photonPCM - for (auto const& v0Photon : v0PhotonsThisEvent) { - // photon selection - if (std::abs(v0Photon.eta()) > absEtaMax) { - continue; - } - if (std::abs(v0Photon.dcaZtopv()) < pcmAbsDcaZLim.value[0] || std::abs(v0Photon.dcaZtopv()) > pcmAbsDcaZLim.value[1]) { - continue; - } - - // photon PCM - histos.fill(HIST("reco/h3_ptPhiEta_photonPCM"), v0Photon.pt(), v0Photon.phi(), v0Photon.eta()); - tableProduction.photonPCM(v0Photon.collisionId(), v0Photon.globalIndex(), - v0Photon.posTrack().trackId(), v0Photon.negTrack().trackId(), v0Photon.pt(), v0Photon.phi(), v0Photon.eta()); - } - - // photonPCm pairs - for (auto const& [v0Photon1, v0Photon2] : soa::combinations(soa::CombinationsStrictlyUpperIndexPolicy(v0PhotonsThisEvent, v0PhotonsThisEvent))) { - // get kinematics - ROOT::Math::PtEtaPhiMVector const p4V0PCM1(v0Photon1.pt(), v0Photon1.eta(), v0Photon1.phi(), 0.); - ROOT::Math::PtEtaPhiMVector const p4V0PCM2(v0Photon2.pt(), v0Photon2.eta(), v0Photon2.phi(), 0.); - ROOT::Math::PtEtaPhiMVector const p4V0PCMPair = p4V0PCM1 + p4V0PCM2; - - // pi0 selection - if (std::abs(p4V0PCMPair.Eta()) > absEtaMax) { - continue; - } - - // save info - histos.fill(HIST("reco/h3_ptPhiEta_photonPCMPair"), p4V0PCMPair.Pt(), RecoDecay::constrainAngle(p4V0PCMPair.Phi(), 0), p4V0PCMPair.Eta()); - tableProduction.photonPCMPair(v0Photon1.collisionId(), v0Photon1.globalIndex(), v0Photon2.globalIndex(), - v0Photon1.posTrack().trackId(), v0Photon1.negTrack().trackId(), v0Photon2.posTrack().trackId(), v0Photon2.negTrack().trackId(), - p4V0PCMPair.Pt(), RecoDecay::constrainAngle(p4V0PCMPair.Phi(), 0), p4V0PCMPair.Eta(), p4V0PCMPair.M()); - } - } - PROCESS_SWITCH(PhotonChargedTriggerProducer, processRecoPhotonPCM, "process photonPCM table (reconstructed)", false); - - void processMcCorrTables(aod::JetMcCollision const& mcCollision, aod::JetParticles const& mcParticles) - { - // mc split event selection - int const thirdDecimalTruePosZ = getThirdDecimalTruePosZ(mcCollision); - // maximum charged particle pt - float maxChargedPt = -1; - int maxTriggerCollisionId = -1; - int maxTriggerGlobalIndex = -1; - float maxTriggerPhi = 0; - float maxTriggerEta = 0; - // number charged particles in eta range - int nCharged = 0; - - // particle loop - for (auto const& mcParticle : mcParticles) { - // track selection - auto const pdgParticle = pdg->GetParticle(mcParticle.pdgCode()); - if (!pdgParticle || pdgParticle->Charge() == 0) { - continue; - } - if (!mcParticle.isPhysicalPrimary()) { - continue; - } - if (std::abs(mcParticle.eta()) > absEtaMax) { - continue; - } - - nCharged++; - if (mcParticle.pt() > maxChargedPt) { - maxChargedPt = mcParticle.pt(); - maxTriggerCollisionId = mcParticle.mcCollisionId(); - maxTriggerGlobalIndex = mcParticle.globalIndex(); - maxTriggerPhi = mcParticle.phi(); - maxTriggerEta = mcParticle.eta(); - } - - // trigger selection - if (mcParticle.pt() < ptTrigMin) { - continue; - } - if (oneTriggerPerEvent) { - continue; - } - - // trigger info - histos.fill(HIST("true/h3_ptPhiEta_trigger"), mcParticle.pt(), mcParticle.phi(), mcParticle.eta()); - tableProduction.triggerParticle(mcParticle.mcCollisionId(), mcParticle.globalIndex(), mcParticle.pt(), mcParticle.phi(), mcParticle.eta()); - } - bool const isTriggerEvent = maxChargedPt > ptTrigMin; - if (oneTriggerPerEvent && isTriggerEvent) { - histos.fill(HIST("true/h3_ptPhiEta_trigger"), maxChargedPt, maxTriggerPhi, maxTriggerEta); - tableProduction.triggerParticle(maxTriggerCollisionId, maxTriggerGlobalIndex, maxChargedPt, maxTriggerPhi, maxTriggerEta); - } - - // collision info - histos.fill(HIST("true/h2_zPvMult"), mcCollision.posZ(), nCharged); - tableProduction.mcCollisionExtraCorr(thirdDecimalTruePosZ, isTriggerEvent, maxChargedPt, nCharged); - } - PROCESS_SWITCH(PhotonChargedTriggerProducer, processMcCorrTables, "process table production (mc)", false); -}; - -WorkflowSpec defineDataProcessing(ConfigContext const& configContext) -{ - return WorkflowSpec{adaptAnalysisTask(configContext)}; -}