Skip to content

Commit b777c69

Browse files
author
Maria Calmon Behling
committed
new task to obtain particle spectra, histos for secondary contamination, option to recover secondaries with mothers beyond kinematic cuts
1 parent 8a6e896 commit b777c69

4 files changed

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

0 commit comments

Comments
 (0)