Skip to content

Commit 910e1ef

Browse files
[PWGLF] new task to obtain particle spectra, histos for secondary contaminati… (#18789)
1 parent 14739fa commit 910e1ef

4 files changed

Lines changed: 344 additions & 7 deletions

File tree

‎PWGLF/TableProducer/Nuspex/particleCompositionCorrection.cxx‎

Lines changed: 132 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ struct ParticleCompositionCorrection {
6767
Configurable<bool> skipAll{"skipAll", false, "run table producer in dummy mode, i.e. skip all computations and fill with 1"};
6868
Configurable<bool> skipSec{"skipSec", false, "dont calculate weights for secondaries"};
6969
Configurable<bool> skipNeutralSec{"skipNeutralSec", true, "dont calculate weights for neutral secondaries"};
70+
Configurable<bool> recoverSecWoWeights{"recoverSecWoWeights", true, "recalculate weights for secondaries with missing weights"};
7071
Configurable<bool> skipNonPhysicalPrim{"skipNonPhysicalPrim", true, "dont calculate weights for particles that are not (originating from) physical primaries; i.e. reject (decays of) pi0 etc."};
7172
Configurable<float> etaCut{"etaCut", 0.8f, "eta cut"};
7273
Configurable<float> ptMinCut{"ptMinCut", 0.15f, "pt min cut"};
7374
Configurable<float> ptMaxCut{"ptMaxCut", 10.f, "pt max cut"};
75+
Configurable<uint32_t> maxMult{"maxMult", 100, "max multiplicity"};
76+
7477
Configurable<bool> enableQAHistos{"enableQAHistos", true, "enable qa histograms showing the effect of the PCC"};
7578

7679
Configurable<std::string> ccdbBasePath{"ccdbBasePath", "/Users/m/mcalmonb/", "ccdb directory contianing the particle fraction networks"};
@@ -118,7 +121,6 @@ void ParticleCompositionCorrection::init(InitContext const&)
118121
6.0, 6.5, 7.0, 8.0, 9.0, 10.0};
119122
const AxisSpec ptAxis{ptBinEdges, "#it{p}_{T} (GeV/#it{c})", "pt"};
120123

121-
const int maxMult = 100;
122124
const int nBinsMult = maxMult + 1;
123125
const AxisSpec multAxis = {nBinsMult, -0.5, nBinsMult - 0.5, "#it{N}_{ch}", "mult"};
124126
const AxisSpec processAxis = {51, -0.5, 50.5, "process", "process"};
@@ -147,7 +149,55 @@ std::tuple<float, float, float> ParticleCompositionCorrection::getWeights(aod::M
147149
{
148150
static const std::tuple<float, float, float> noWeights = {1.f, 1.f, 1.f};
149151

150-
static constexpr int kXi0PDG = 3322;
152+
auto calculateDNNWeight = [this](int absPDGCode, float pt, float dNdEta)
153+
-> std::tuple<float, float, float, bool> {
154+
// int absPDGCode = std::abs(pdgCode);
155+
156+
// translate abs PDG code to PID variable of neural networks (0: pion, 1: kaon, 2: proton, 3: sigma)
157+
158+
static constexpr int kXi0PDG = 3322;
159+
160+
static const std::map<int, float> mapPID = {
161+
{PDG_t::kPiPlus, 0.f},
162+
{PDG_t::kPi0, 0.f},
163+
{PDG_t::kKPlus, 1.f},
164+
{PDG_t::kK0Short, 1.f},
165+
{PDG_t::kK0Long, 1.f},
166+
{PDG_t::kProton, 2.f},
167+
{PDG_t::kNeutron, 2.f},
168+
{PDG_t::kSigmaPlus, 3.f},
169+
{PDG_t::kSigmaMinus, 3.f},
170+
{PDG_t::kLambda0, 3.f},
171+
{PDG_t::kSigma0, 3.f},
172+
{PDG_t::kXiMinus, 3.f},
173+
{kXi0PDG, 3.f}, // Xi0
174+
{PDG_t::kOmegaMinus, 3.f},
175+
// TODO: potentially extend by eta/omega/rho/phi/Delta...
176+
// pdg codes defined in AliceO2/Common/Constants/include/CommonConstants/PhysicsConstants.h
177+
// e.g. o2::constants::physics::Pdg::kEta
178+
};
179+
180+
if (auto iterMapPID = mapPID.find(absPDGCode);
181+
iterMapPID != mapPID.end() && absPDGCode != PDG_t::kPiPlus && absPDGCode != PDG_t::kPi0) {
182+
183+
float particleID = iterMapPID->second;
184+
185+
std::vector<std::vector<float>> input = {
186+
{dNdEta}, {pt}, {particleID}};
187+
188+
float fracData = particleFractionsData.evalModel(input)[0];
189+
float fracMC = particleFractionsMC.evalModel(input)[0];
190+
191+
float weight = (fracMC != 0.f) ? fracData / fracMC : 1.f;
192+
193+
return {weight, fracData, fracMC, true};
194+
}
195+
196+
// PDG code not found
197+
return {1.f, 1.f, 1.f, false};
198+
};
199+
200+
// static constexpr int kXi0PDG = 3322;
151201

152202
if (skipAll || std::abs(particle.eta()) > etaCut || particle.pt() < ptMinCut || particle.pt() > ptMaxCut) {
153203
return noWeights;
@@ -166,16 +216,15 @@ std::tuple<float, float, float> ParticleCompositionCorrection::getWeights(aod::M
166216

167217
auto absPDGCode = std::abs(particle.pdgCode());
168218

169-
if (absPDGCode == PDG_t::kPiPlus || absPDGCode == PDG_t::kPi0) {
170-
219+
/* if (absPDGCode == PDG_t::kPiPlus || absPDGCode == PDG_t::kPi0) {
171220
return noWeights;
172-
}
221+
}*/
173222

174223
if (skipNonPhysicalPrim && !particle.isPhysicalPrimary()) {
175224
return noWeights;
176225
}
177226

178-
// translate abs PDG code to PID variable of neural networks (0: pion, 1: kaon, 2: proton, 3: sigma)
227+
/* // translate abs PDG code to PID variable of neural networks (0: pion, 1: kaon, 2: proton, 3: sigma)
179228
180229
static const std::map<int, float> mapPID = {
181230
{PDG_t::kPiPlus, 0.f},
@@ -231,8 +280,44 @@ std::tuple<float, float, float> ParticleCompositionCorrection::getWeights(aod::M
231280
}
232281
233282
return weights;
283+
} */
284+
285+
auto [weight, fracData, fracMC, validPDG] =
286+
calculateDNNWeight(absPDGCode, particle.pt(), dNdEta);
287+
288+
std::tuple<float, float, float> weights = {weight, weight, weight};
289+
290+
if (!skipSec && particle.has_daughters()) {
291+
storedWeights[particle.index()] = weights;
292+
}
293+
294+
if (enableQAHistos && particle.isPhysicalPrimary() && std::abs(particle.eta()) < etaCut) {
295+
296+
if (absPDGCode == PDG_t::kKPlus) {
297+
histos.fill(HIST("frac/data/kaon"), particle.pt(), fracData);
298+
histos.fill(HIST("frac/mc/kaon"), particle.pt(), fracMC);
299+
histos.fill(HIST("weight/kaon"), particle.pt(), weight);
300+
301+
} else if (absPDGCode == PDG_t::kProton) {
302+
histos.fill(HIST("frac/data/proton"), particle.pt(), fracData);
303+
histos.fill(HIST("frac/mc/proton"), particle.pt(), fracMC);
304+
histos.fill(HIST("weight/proton"), particle.pt(), weight);
305+
306+
} else if (absPDGCode == PDG_t::kSigmaPlus || particle.pdgCode() == PDG_t::kSigmaMinus) {
307+
histos.fill(HIST("frac/data/sigma"), particle.pt(), fracData);
308+
histos.fill(HIST("frac/mc/sigma"), particle.pt(), fracMC);
309+
histos.fill(HIST("weight/sigma"), particle.pt(), weight);
310+
}
311+
312+
histos.fill(HIST("weight/prim"), particle.pt(), weight);
234313
}
235314

315+
if (!validPDG) {
316+
return noWeights;
317+
}
318+
319+
return weights;
320+
236321
} else if (!skipSec) {
237322

238323
auto refParticleID = particle.index();
@@ -247,6 +332,7 @@ std::tuple<float, float, float> ParticleCompositionCorrection::getWeights(aod::M
247332
return noWeights;
248333
}
249334
}
335+
// LOGP(info, "This secondary survived all cuts, PDG: ",particle.pdgCode());
250336

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

@@ -269,9 +355,48 @@ std::tuple<float, float, float> ParticleCompositionCorrection::getWeights(aod::M
269355
LOGF(error, "GLOBAL MOTHER IS INCIDING PROTON");
270356
}
271357

272-
if (!storedWeights.contains(refParticleID)) {
358+
/* if (!storedWeights.contains(refParticleID)) {
273359
// LOGP(info, "MCB: no ref stored for mom {}, PDG: {}!!", particles.iteratorAt(refParticleID).index(),particles.iteratorAt(refParticleID).pdgCode());
274360
return noWeights;
361+
} */
362+
363+
if (!storedWeights.contains(refParticleID)) {
364+
365+
// LOGP(info, "No weight stored for this secondary's mom");
366+
367+
// Retrieve the reference mother.
368+
auto refParticle = particles.iteratorAt(refParticleID);
369+
370+
if (recoverSecWoWeights && (!skipNonPhysicalPrim || refParticle.isPhysicalPrimary())) {
371+
372+
// Calculate its DNN correction.
373+
auto result = calculateDNNWeight(
374+
std::abs(refParticle.pdgCode()),
375+
refParticle.pt(),
376+
dNdEta);
377+
378+
float weight = std::get<0>(result);
379+
bool validPDG = std::get<3>(result);
380+
381+
if (!validPDG) {
382+
// LOGP(info, "Mom PDG not valid, no weight calculated");
383+
return noWeights;
384+
}
385+
/* else {
386+
if (weight == 1.f) {
387+
LOGP(info, "Mom PDG valid, but weight is 1!");
388+
} else {
389+
LOGP(info, "We have saved the secondary! Weight = {}", weight);
390+
}
391+
} */
392+
393+
// Store the newly calculated weight.
394+
storedWeights[refParticleID] = {weight, weight, weight};
395+
396+
} else {
397+
// No weight should be assigned to this reference mother.
398+
return noWeights;
399+
}
275400
}
276401

277402
if (enableQAHistos) {

‎PWGLF/Tasks/Nuspex/CMakeLists.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,9 @@ o2physics_add_dpl_workflow(deuteron-in-jets-trg-pt
211211
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2Physics::PWGJECore FastJet::FastJet FastJet::Contrib O2Physics::EventFilteringUtils
212212
COMPONENT_NAME Analysis)
213213

214+
o2physics_add_dpl_workflow(pcc-mc-spectra
215+
SOURCES pccMcSpectra.cxx
216+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
217+
COMPONENT_NAME Analysis)
218+
214219
endif()
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \file pccMcSpectra.cxx
13+
/// \brief Task to extract the pt spectra of various particle species as input for a particle-composition correction.
14+
/// \author Maria Calmon Behling <[email protected]>
15+
16+
#include <Framework/AnalysisDataModel.h>
17+
#include <Framework/AnalysisHelpers.h>
18+
#include <Framework/AnalysisTask.h>
19+
#include <Framework/Configurable.h>
20+
#include <Framework/HistogramRegistry.h>
21+
#include <Framework/HistogramSpec.h>
22+
#include <Framework/InitContext.h>
23+
#include <Framework/O2DatabasePDGPlugin.h>
24+
#include <Framework/runDataProcessing.h>
25+
26+
#include <cmath>
27+
#include <cstdint>
28+
#include <cstdlib>
29+
#include <vector>
30+
31+
using namespace o2;
32+
using namespace o2::framework;
33+
34+
struct pccMcSpectra {
35+
36+
Service<o2::framework::O2DatabasePDG> pdg;
37+
38+
Configurable<float> etaINEL{"etaINEL", 1.f, "eta range for INEL>0"};
39+
Configurable<float> etaNch{"etaNch", 0.5f, "eta range for Nch"};
40+
Configurable<float> yMax{"yMax", 0.5f, "rapidity range for spectra"};
41+
Configurable<uint32_t> maxMult{"maxMult", 100, "max multiplicity"};
42+
43+
HistogramRegistry histos{"histos"};
44+
45+
void init(InitContext const&)
46+
{
47+
// Integer multiplicity bins: Nch = 0, 1, ..., 199
48+
const int nBinsMult = maxMult + 1;
49+
const AxisSpec multAxis = {nBinsMult, -0.5, nBinsMult - 0.5, "#it{N}_{ch}", "mult"};
50+
51+
// Transverse momentum: 0 - 10 GeV/c
52+
53+
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,
54+
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,
55+
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,
56+
6.0, 6.5, 7.0, 8.0, 9.0, 10.0, 20.0, 30.0};
57+
const AxisSpec ptAxis{ptBinEdges, "#it{p}_{T} (GeV/#it{c})", "pt"};
58+
59+
histos.add("event/mult",
60+
"multiplicity distribution;Nch;Events",
61+
kTH1D, {multAxis});
62+
63+
histos.add("spectra/pion",
64+
"Pion spectra;Nch;pT",
65+
kTH2D, {multAxis, ptAxis});
66+
67+
histos.add("spectra/kaon",
68+
"Kaon spectra;Nch;pT",
69+
kTH2D, {multAxis, ptAxis});
70+
71+
histos.add("spectra/proton",
72+
"Proton spectra;Nch;pT",
73+
kTH2D, {multAxis, ptAxis});
74+
75+
histos.add("spectra/sigma",
76+
"Sigma spectra;Nch;pT",
77+
kTH2D, {multAxis, ptAxis});
78+
79+
histos.add("spectra/lambda",
80+
"Lambda spectra;Nch;pT",
81+
kTH2D, {multAxis, ptAxis});
82+
83+
histos.add("spectra/xi",
84+
"Xi spectra;Nch;pT",
85+
kTH2D, {multAxis, ptAxis});
86+
87+
histos.add("spectra/omega",
88+
"Omega spectra;Nch;pT",
89+
kTH2D, {multAxis, ptAxis});
90+
}
91+
92+
void process(aod::McCollisions::iterator const&,
93+
aod::McParticles const& particles)
94+
{
95+
int nch = 0;
96+
bool isINELgt0 = false;
97+
98+
// First loop: determine event multiplicity and INEL>0.
99+
for (const auto& particle : particles) {
100+
101+
if (!particle.isPhysicalPrimary()) {
102+
continue;
103+
}
104+
105+
auto pdgParticle = pdg->GetParticle(particle.pdgCode());
106+
107+
if (!pdgParticle || pdgParticle->Charge() == 0.) {
108+
continue;
109+
}
110+
111+
float absEta = std::abs(particle.eta());
112+
113+
if (absEta < etaINEL) {
114+
isINELgt0 = true;
115+
}
116+
117+
if (absEta < etaNch) {
118+
++nch;
119+
}
120+
}
121+
122+
// Reject events that do not satisfy INEL>0.
123+
if (!isINELgt0) {
124+
return;
125+
}
126+
127+
histos.fill(HIST("event/mult"), nch);
128+
129+
// Second loop: fill identified-particle spectra.
130+
for (const auto& particle : particles) {
131+
132+
if (!particle.isPhysicalPrimary()) {
133+
continue;
134+
}
135+
136+
if (std::abs(particle.y()) >= yMax) {
137+
continue;
138+
}
139+
140+
int absPDG = std::abs(particle.pdgCode());
141+
float pt = particle.pt();
142+
143+
switch (absPDG) {
144+
145+
case 211: // Pion
146+
histos.fill(HIST("spectra/pion"), nch, pt);
147+
break;
148+
149+
case 321: // Kaon
150+
histos.fill(HIST("spectra/kaon"), nch, pt);
151+
break;
152+
153+
case 2212: // Proton
154+
histos.fill(HIST("spectra/proton"), nch, pt);
155+
break;
156+
157+
case 3222: // Sigma+
158+
case 3112: // Sigma-
159+
histos.fill(HIST("spectra/sigma"), nch, pt);
160+
break;
161+
162+
case 3122: // Lambda
163+
histos.fill(HIST("spectra/lambda"), nch, pt);
164+
break;
165+
166+
case 3312: // Xi
167+
histos.fill(HIST("spectra/xi"), nch, pt);
168+
break;
169+
170+
case 3334: // Omega
171+
histos.fill(HIST("spectra/omega"), nch, pt);
172+
break;
173+
174+
default:
175+
break;
176+
}
177+
}
178+
}
179+
};
180+
181+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
182+
{
183+
return WorkflowSpec{adaptAnalysisTask<pccMcSpectra>(cfgc)};
184+
}

0 commit comments

Comments
 (0)