From b777c6939e05649b5f8ae85bf8f7eca7b7b98d0f Mon Sep 17 00:00:00 2001 From: Maria Calmon Behling Date: Tue, 17 Nov 2026 14:31:56 +0100 Subject: [PATCH 1/2] new task to obtain particle spectra, histos for secondary contamination, option to recover secondaries with mothers beyond kinematic cuts --- .../Nuspex/particleCompositionCorrection.cxx | 139 +++++++++++++- PWGLF/Tasks/Nuspex/CMakeLists.txt | 5 + PWGLF/Tasks/Nuspex/pccMcSpectra.cxx | 181 ++++++++++++++++++ PWGLF/Tasks/Nuspex/pccQa.cxx | 23 +++ 4 files changed, 341 insertions(+), 7 deletions(-) create mode 100644 PWGLF/Tasks/Nuspex/pccMcSpectra.cxx diff --git a/PWGLF/TableProducer/Nuspex/particleCompositionCorrection.cxx b/PWGLF/TableProducer/Nuspex/particleCompositionCorrection.cxx index a7ca20ded7d..b97f0498c63 100644 --- a/PWGLF/TableProducer/Nuspex/particleCompositionCorrection.cxx +++ b/PWGLF/TableProducer/Nuspex/particleCompositionCorrection.cxx @@ -67,10 +67,13 @@ struct ParticleCompositionCorrection { Configurable skipAll{"skipAll", false, "run table producer in dummy mode, i.e. skip all computations and fill with 1"}; Configurable skipSec{"skipSec", false, "dont calculate weights for secondaries"}; Configurable skipNeutralSec{"skipNeutralSec", true, "dont calculate weights for neutral secondaries"}; + Configurable recoverSecWoWeights{"recoverSecWoWeights", true, "recalculate weights for secondaries with missing weights"}; Configurable skipNonPhysicalPrim{"skipNonPhysicalPrim", true, "dont calculate weights for particles that are not (originating from) physical primaries; i.e. reject (decays of) pi0 etc."}; Configurable etaCut{"etaCut", 0.8f, "eta cut"}; Configurable ptMinCut{"ptMinCut", 0.15f, "pt min cut"}; Configurable ptMaxCut{"ptMaxCut", 10.f, "pt max cut"}; + Configurable maxMult{"maxMult", 100, "max multiplicity"}; + Configurable enableQAHistos{"enableQAHistos", true, "enable qa histograms showing the effect of the PCC"}; Configurable ccdbBasePath{"ccdbBasePath", "/Users/m/mcalmonb/", "ccdb directory contianing the particle fraction networks"}; @@ -118,7 +121,6 @@ void ParticleCompositionCorrection::init(InitContext const&) 6.0, 6.5, 7.0, 8.0, 9.0, 10.0}; const AxisSpec ptAxis{ptBinEdges, "#it{p}_{T} (GeV/#it{c})", "pt"}; - const int maxMult = 100; const int nBinsMult = maxMult + 1; const AxisSpec multAxis = {nBinsMult, -0.5, nBinsMult - 0.5, "#it{N}_{ch}", "mult"}; const AxisSpec processAxis = {51, -0.5, 50.5, "process", "process"}; @@ -147,7 +149,55 @@ std::tuple ParticleCompositionCorrection::getWeights(aod::M { static const std::tuple noWeights = {1.f, 1.f, 1.f}; - static constexpr int kXi0PDG = 3322; + auto calculateDNNWeight = [this](int absPDGCode, float pt, float dNdEta) + -> std::tuple { + // int absPDGCode = std::abs(pdgCode); + + // translate abs PDG code to PID variable of neural networks (0: pion, 1: kaon, 2: proton, 3: sigma) + + static constexpr int kXi0PDG = 3322; + + static const std::map mapPID = { + {PDG_t::kPiPlus, 0.f}, + {PDG_t::kPi0, 0.f}, + {PDG_t::kKPlus, 1.f}, + {PDG_t::kK0Short, 1.f}, + {PDG_t::kK0Long, 1.f}, + {PDG_t::kProton, 2.f}, + {PDG_t::kNeutron, 2.f}, + {PDG_t::kSigmaPlus, 3.f}, + {PDG_t::kSigmaMinus, 3.f}, + {PDG_t::kLambda0, 3.f}, + {PDG_t::kSigma0, 3.f}, + {PDG_t::kXiMinus, 3.f}, + {kXi0PDG, 3.f}, // Xi0 + {PDG_t::kOmegaMinus, 3.f}, + // TODO: potentially extend by eta/omega/rho/phi/Delta... + // pdg codes defined in AliceO2/Common/Constants/include/CommonConstants/PhysicsConstants.h + // e.g. o2::constants::physics::Pdg::kEta + }; + + if (auto iterMapPID = mapPID.find(absPDGCode); + iterMapPID != mapPID.end() && absPDGCode != PDG_t::kPiPlus && absPDGCode != PDG_t::kPi0) { + + float particleID = iterMapPID->second; + + std::vector> input = { + {dNdEta}, {pt}, {particleID}}; + + float fracData = particleFractionsData.evalModel(input)[0]; + float fracMC = particleFractionsMC.evalModel(input)[0]; + + float weight = (fracMC != 0.f) ? fracData / fracMC : 1.f; + + return {weight, fracData, fracMC, true}; + } + + // PDG code not found + return {1.f, 1.f, 1.f, false}; + }; + + // static constexpr int kXi0PDG = 3322; if (skipAll || std::abs(particle.eta()) > etaCut || particle.pt() < ptMinCut || particle.pt() > ptMaxCut) { return noWeights; @@ -166,16 +216,15 @@ std::tuple ParticleCompositionCorrection::getWeights(aod::M auto absPDGCode = std::abs(particle.pdgCode()); - if (absPDGCode == PDG_t::kPiPlus || absPDGCode == PDG_t::kPi0) { - + /* if (absPDGCode == PDG_t::kPiPlus || absPDGCode == PDG_t::kPi0) { return noWeights; - } + }*/ if (skipNonPhysicalPrim && !particle.isPhysicalPrimary()) { return noWeights; } - // translate abs PDG code to PID variable of neural networks (0: pion, 1: kaon, 2: proton, 3: sigma) + /* // translate abs PDG code to PID variable of neural networks (0: pion, 1: kaon, 2: proton, 3: sigma) static const std::map mapPID = { {PDG_t::kPiPlus, 0.f}, @@ -231,8 +280,44 @@ std::tuple ParticleCompositionCorrection::getWeights(aod::M } return weights; + } */ + + auto [weight, fracData, fracMC, validPDG] = + calculateDNNWeight(absPDGCode, particle.pt(), dNdEta); + + std::tuple weights = {weight, weight, weight}; + + if (!skipSec && particle.has_daughters()) { + storedWeights[particle.index()] = weights; + } + + if (enableQAHistos && particle.isPhysicalPrimary() && std::abs(particle.eta()) < etaCut) { + + if (absPDGCode == PDG_t::kKPlus) { + histos.fill(HIST("frac/data/kaon"), particle.pt(), fracData); + histos.fill(HIST("frac/mc/kaon"), particle.pt(), fracMC); + histos.fill(HIST("weight/kaon"), particle.pt(), weight); + + } else if (absPDGCode == PDG_t::kProton) { + histos.fill(HIST("frac/data/proton"), particle.pt(), fracData); + histos.fill(HIST("frac/mc/proton"), particle.pt(), fracMC); + histos.fill(HIST("weight/proton"), particle.pt(), weight); + + } else if (absPDGCode == PDG_t::kSigmaPlus || particle.pdgCode() == PDG_t::kSigmaMinus) { + histos.fill(HIST("frac/data/sigma"), particle.pt(), fracData); + histos.fill(HIST("frac/mc/sigma"), particle.pt(), fracMC); + histos.fill(HIST("weight/sigma"), particle.pt(), weight); + } + + histos.fill(HIST("weight/prim"), particle.pt(), weight); } + if (!validPDG) { + return noWeights; + } + + return weights; + } else if (!skipSec) { auto refParticleID = particle.index(); @@ -247,6 +332,7 @@ std::tuple ParticleCompositionCorrection::getWeights(aod::M return noWeights; } } + // LOGP(info, "This secondary survived all cuts, PDG: ",particle.pdgCode()); while (particles.iteratorAt(refParticleID).has_mothers()) { @@ -269,9 +355,48 @@ std::tuple ParticleCompositionCorrection::getWeights(aod::M LOGF(error, "GLOBAL MOTHER IS INCIDING PROTON"); } - if (!storedWeights.contains(refParticleID)) { + /* if (!storedWeights.contains(refParticleID)) { // LOGP(info, "MCB: no ref stored for mom {}, PDG: {}!!", particles.iteratorAt(refParticleID).index(),particles.iteratorAt(refParticleID).pdgCode()); return noWeights; + } */ + + if (!storedWeights.contains(refParticleID)) { + + // LOGP(info, "No weight stored for this secondary's mom"); + + // Retrieve the reference mother. + auto refParticle = particles.iteratorAt(refParticleID); + + if (recoverSecWoWeights && (!skipNonPhysicalPrim || refParticle.isPhysicalPrimary())) { + + // Calculate its DNN correction. + auto result = calculateDNNWeight( + std::abs(refParticle.pdgCode()), + refParticle.pt(), + dNdEta); + + float weight = std::get<0>(result); + bool validPDG = std::get<3>(result); + + if (!validPDG) { + // LOGP(info, "Mom PDG not valid, no weight calculated"); + return noWeights; + } + /* else { + if (weight == 1.f) { + LOGP(info, "Mom PDG valid, but weight is 1!"); + } else { + LOGP(info, "We have saved the secondary! Weight = {}", weight); + } + } */ + + // Store the newly calculated weight. + storedWeights[refParticleID] = {weight, weight, weight}; + + } else { + // No weight should be assigned to this reference mother. + return noWeights; + } } if (enableQAHistos) { diff --git a/PWGLF/Tasks/Nuspex/CMakeLists.txt b/PWGLF/Tasks/Nuspex/CMakeLists.txt index 43450b1a161..8522cd17f95 100644 --- a/PWGLF/Tasks/Nuspex/CMakeLists.txt +++ b/PWGLF/Tasks/Nuspex/CMakeLists.txt @@ -211,4 +211,9 @@ o2physics_add_dpl_workflow(deuteron-in-jets-trg-pt PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2Physics::PWGJECore FastJet::FastJet FastJet::Contrib O2Physics::EventFilteringUtils COMPONENT_NAME Analysis) +o2physics_add_dpl_workflow(pcc-mc-spectra + SOURCES pccMcSpectra.cxx + PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore + COMPONENT_NAME Analysis) + endif() diff --git a/PWGLF/Tasks/Nuspex/pccMcSpectra.cxx b/PWGLF/Tasks/Nuspex/pccMcSpectra.cxx new file mode 100644 index 00000000000..1bc27e50e17 --- /dev/null +++ b/PWGLF/Tasks/Nuspex/pccMcSpectra.cxx @@ -0,0 +1,181 @@ + +// 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 pccMcSpectra.cxx +/// \brief Task to extract the pt spectra of various particle species as input for a particle-composition correction. +/// \author Maria Calmon Behling + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace o2; +using namespace o2::framework; + +struct pccMcSpectra { + + Service pdg; + + Configurable etaINEL{"etaINEL", 1.f, "eta range for INEL>0"}; + Configurable etaNch{"etaNch", 0.5f, "eta range for Nch"}; + Configurable yMax{"yMax", 0.5f, "rapidity range for spectra"}; + Configurable maxMult{"maxMult", 100, "max multiplicity"}; + + HistogramRegistry histos{"histos"}; + + void init(InitContext const&) + { + // Integer multiplicity bins: Nch = 0, 1, ..., 199 + const int nBinsMult = maxMult + 1; + const AxisSpec multAxis = {nBinsMult, -0.5, nBinsMult - 0.5, "#it{N}_{ch}", "mult"}; + + // Transverse momentum: 0 - 10 GeV/c + + std::vector ptBinEdges = {0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, + 0.8, 0.85, 0.9, 0.95, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, + 2.0, 2.2, 2.4, 2.6, 2.8, 3.0, 3.2, 3.4, 3.6, 3.8, 4.0, 4.5, 5.0, 5.5, + 6.0, 6.5, 7.0, 8.0, 9.0, 10.0}; + const AxisSpec ptAxis{ptBinEdges, "#it{p}_{T} (GeV/#it{c})", "pt"}; + + histos.add("event/mult", + "multiplicity distribution;Nch;Events", + kTH1D, {multAxis}); + + histos.add("spectra/pion", + "Pion spectra;Nch;pT", + kTH2D, {multAxis, ptAxis}); + + histos.add("spectra/kaon", + "Kaon spectra;Nch;pT", + kTH2D, {multAxis, ptAxis}); + + histos.add("spectra/proton", + "Proton spectra;Nch;pT", + kTH2D, {multAxis, ptAxis}); + + histos.add("spectra/sigma", + "Sigma spectra;Nch;pT", + kTH2D, {multAxis, ptAxis}); + + histos.add("spectra/lambda", + "Lambda spectra;Nch;pT", + kTH2D, {multAxis, ptAxis}); + + histos.add("spectra/xi", + "Xi spectra;Nch;pT", + kTH2D, {multAxis, ptAxis}); + + histos.add("spectra/omega", + "Omega spectra;Nch;pT", + kTH2D, {multAxis, ptAxis}); + } + + void process(aod::McCollisions::iterator const&, + aod::McParticles const& particles) + { + int nch = 0; + bool isINELgt0 = false; + + // First loop: determine event multiplicity and INEL>0. + for (const auto& particle : particles) { + + if (!particle.isPhysicalPrimary()) { + continue; + } + + auto pdgParticle = pdg->GetParticle(particle.pdgCode()); + + if (!pdgParticle || pdgParticle->Charge() == 0.) { + continue; + } + + float absEta = std::abs(particle.eta()); + + if (absEta < etaINEL) { + isINELgt0 = true; + } + + if (absEta < etaNch) { + ++nch; + } + } + + // Reject events that do not satisfy INEL>0. + if (!isINELgt0) { + return; + } + + histos.fill(HIST("event/mult"), nch); + + // Second loop: fill identified-particle spectra. + for (const auto& particle : particles) { + + if (!particle.isPhysicalPrimary()) { + continue; + } + + if (std::abs(particle.y()) >= yMax) { + continue; + } + + int absPDG = std::abs(particle.pdgCode()); + float pt = particle.pt(); + + switch (absPDG) { + + case 211: // Pion + histos.fill(HIST("spectra/pion"), nch, pt); + break; + + case 321: // Kaon + histos.fill(HIST("spectra/kaon"), nch, pt); + break; + + case 2212: // Proton + histos.fill(HIST("spectra/proton"), nch, pt); + break; + + case 3222: // Sigma+ + case 3112: // Sigma- + histos.fill(HIST("spectra/sigma"), nch, pt); + break; + + case 3122: // Lambda + histos.fill(HIST("spectra/lambda"), nch, pt); + break; + + case 3312: // Xi + histos.fill(HIST("spectra/xi"), nch, pt); + break; + + case 3334: // Omega + histos.fill(HIST("spectra/omega"), nch, pt); + break; + + default: + break; + } + } + } +}; + +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +{ + return WorkflowSpec{adaptAnalysisTask(cfgc)}; +} diff --git a/PWGLF/Tasks/Nuspex/pccQa.cxx b/PWGLF/Tasks/Nuspex/pccQa.cxx index 4469c8cee2d..e8ef90e9849 100644 --- a/PWGLF/Tasks/Nuspex/pccQa.cxx +++ b/PWGLF/Tasks/Nuspex/pccQa.cxx @@ -151,6 +151,15 @@ void PccQa::init(InitContext const&) if (doprocessMC) { histos.add("DCAxyVsPtVsMult_weighted", "", kTH3D, {nchAxis, ptAxis, dcaAxis}); + histos.add("globalTracks", "", kTH1D, {ptAxis}); + histos.add("globalTracks_weighted", "", kTH1D, {ptAxis}); + histos.add("globalTracksSec", "", kTH1D, {ptAxis}); + histos.add("globalTracksSec_weighted", "", kTH1D, {ptAxis}); + + histos.add("globalTracksVsMult", "", kTH2D, {nchAxis, ptAxis}); + histos.add("globalTracksVsMult_weighted", "", kTH2D, {nchAxis, ptAxis}); + histos.add("globalTracksVsMultSec", "", kTH2D, {nchAxis, ptAxis}); + histos.add("globalTracksVsMultSec_weighted", "", kTH2D, {nchAxis, ptAxis}); histos.add("prim/DCAxyVsPtVsMult", "", kTH3D, {nchAxis, ptAxis, dcaAxis}); histos.add("prim/DCAxyVsPtVsMult_weighted", "", kTH3D, {nchAxis, ptAxis, dcaAxis}); @@ -265,6 +274,13 @@ void PccQa::processMeas(const C& collision, const T& tracks) histos.fill(HIST("DCAxyVsPtVsMult_weighted"), MultCounterMeas, track.pt(), track.dcaXY(), particle.pccWeight()); + if (TrackSelectionFlags::kGlobalTrack) { + histos.fill(HIST("globalTracks"), track.pt()); + histos.fill(HIST("globalTracks_weighted"), track.pt(), particle.pccWeight()); + histos.fill(HIST("globalTracksVsMult"), MultCounterMeas, track.pt()); + histos.fill(HIST("globalTracksVsMult_weighted"), MultCounterMeas, track.pt(), particle.pccWeight()); + } + if (particle.isPhysicalPrimary()) { histos.fill(HIST("prim/weights"), particle.pt(), particle.pccWeight()); @@ -282,6 +298,13 @@ void PccQa::processMeas(const C& collision, const T& tracks) histos.fill(HIST("sec/DCAxyVsPtVsMult"), MultCounterMeas, track.pt(), track.dcaXY()); histos.fill(HIST("sec/DCAxyVsPtVsMult_weighted"), MultCounterMeas, track.pt(), track.dcaXY(), particle.pccWeight()); + if (TrackSelectionFlags::kGlobalTrack) { + histos.fill(HIST("globalTracksSec"), track.pt()); + histos.fill(HIST("globalTracksSec_weighted"), track.pt(), particle.pccWeight()); + histos.fill(HIST("globalTracksVsMultSec"), MultCounterMeas, track.pt()); + histos.fill(HIST("globalTracksVsMultSec_weighted"), MultCounterMeas, track.pt(), particle.pccWeight()); + } + if (particle.getProcess() == TMCProcess::kPDecay || particle.getProcess() == TMCProcess::kPPrimary) { histos.fill(HIST("sec/dec/DCAxyVsPtVsMult"), From 7344d90e1c78b0b9a329d74db4561323ec2fba2d Mon Sep 17 00:00:00 2001 From: Maria Calmon Behling Date: Tue, 17 Nov 2026 15:06:01 +0100 Subject: [PATCH 2/2] Fix copyright header placement --- PWGLF/Tasks/Nuspex/pccMcSpectra.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/PWGLF/Tasks/Nuspex/pccMcSpectra.cxx b/PWGLF/Tasks/Nuspex/pccMcSpectra.cxx index 1bc27e50e17..49c627ba5d7 100644 --- a/PWGLF/Tasks/Nuspex/pccMcSpectra.cxx +++ b/PWGLF/Tasks/Nuspex/pccMcSpectra.cxx @@ -1,4 +1,3 @@ - // 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.