Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 132 additions & 7 deletions PWGLF/TableProducer/Nuspex/particleCompositionCorrection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ struct ParticleCompositionCorrection {
Configurable<bool> skipAll{"skipAll", false, "run table producer in dummy mode, i.e. skip all computations and fill with 1"};
Configurable<bool> skipSec{"skipSec", false, "dont calculate weights for secondaries"};
Configurable<bool> skipNeutralSec{"skipNeutralSec", true, "dont calculate weights for neutral secondaries"};
Configurable<bool> recoverSecWoWeights{"recoverSecWoWeights", true, "recalculate weights for secondaries with missing weights"};
Configurable<bool> skipNonPhysicalPrim{"skipNonPhysicalPrim", true, "dont calculate weights for particles that are not (originating from) physical primaries; i.e. reject (decays of) pi0 etc."};
Configurable<float> etaCut{"etaCut", 0.8f, "eta cut"};
Configurable<float> ptMinCut{"ptMinCut", 0.15f, "pt min cut"};
Configurable<float> ptMaxCut{"ptMaxCut", 10.f, "pt max cut"};
Configurable<uint32_t> maxMult{"maxMult", 100, "max multiplicity"};

Configurable<bool> enableQAHistos{"enableQAHistos", true, "enable qa histograms showing the effect of the PCC"};

Configurable<std::string> ccdbBasePath{"ccdbBasePath", "/Users/m/mcalmonb/", "ccdb directory contianing the particle fraction networks"};
Expand Down Expand Up @@ -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"};
Expand Down Expand Up @@ -147,7 +149,55 @@ std::tuple<float, float, float> ParticleCompositionCorrection::getWeights(aod::M
{
static const std::tuple<float, float, float> noWeights = {1.f, 1.f, 1.f};

static constexpr int kXi0PDG = 3322;
auto calculateDNNWeight = [this](int absPDGCode, float pt, float dNdEta)
-> std::tuple<float, float, float, bool> {
// 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<int, float> 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<std::vector<float>> 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;
Expand All @@ -166,16 +216,15 @@ std::tuple<float, float, float> 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<int, float> mapPID = {
{PDG_t::kPiPlus, 0.f},
Expand Down Expand Up @@ -231,8 +280,44 @@ std::tuple<float, float, float> ParticleCompositionCorrection::getWeights(aod::M
}

return weights;
} */

auto [weight, fracData, fracMC, validPDG] =
calculateDNNWeight(absPDGCode, particle.pt(), dNdEta);

std::tuple<float, float, float> 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();
Expand All @@ -247,6 +332,7 @@ std::tuple<float, float, float> ParticleCompositionCorrection::getWeights(aod::M
return noWeights;
}
}
// LOGP(info, "This secondary survived all cuts, PDG: ",particle.pdgCode());

while (particles.iteratorAt(refParticleID).has_mothers()) {

Expand All @@ -269,9 +355,48 @@ std::tuple<float, float, float> 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) {
Expand Down
5 changes: 5 additions & 0 deletions PWGLF/Tasks/Nuspex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
180 changes: 180 additions & 0 deletions PWGLF/Tasks/Nuspex/pccMcSpectra.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
// 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 <maria.calmon@cern.ch>

#include <Framework/AnalysisDataModel.h>
#include <Framework/AnalysisTask.h>
#include <Framework/Configurable.h>
#include <Framework/HistogramRegistry.h>
#include <Framework/O2DatabasePDGPlugin.h>
#include <Framework/runDataProcessing.h>

#include <cmath>
#include <cstdlib>
#include <vector>

using namespace o2;
using namespace o2::framework;

struct pccMcSpectra {

Service<o2::framework::O2DatabasePDG> pdg;

Configurable<float> etaINEL{"etaINEL", 1.f, "eta range for INEL>0"};
Configurable<float> etaNch{"etaNch", 0.5f, "eta range for Nch"};
Configurable<float> yMax{"yMax", 0.5f, "rapidity range for spectra"};
Configurable<uint32_t> 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<double> 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<pccMcSpectra>(cfgc)};
}
Loading
Loading