@@ -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) {
0 commit comments