Skip to content

Commit 1f26213

Browse files
committed
[PWGMM] dndeta-hi: add SD/DD/ND classification and fix linter issues
- Add kDD, kSD, kND enum values for diffractive event classification - Join McCollisions with HepMCXSections to access processId() in processMCCounting - Classify events by Pythia8 process code: 101=ND, 103/104=SD, 105/106=DD - Replace sliceByCached with sliceBy+Preslice for soa::Filtered tables (FiTracks, FiLTracks) - Fix std-prefix: use std::log, std::exp, std::fabs instead of bare C functions - Fix const-ref-in-for-loop: use const auto& in all range-based for loops - Fix pdg/explicit-code: replace 310 with kK0Short, 3122 with kLambda0 - Add TPDGCode.h include for ROOT PDG named constants
1 parent bbfac97 commit 1f26213

File tree

1 file changed

+52
-36
lines changed

1 file changed

+52
-36
lines changed

PWGMM/Mult/Tasks/dndeta-hi.cxx

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include <TH1.h>
3636
#include <TMath.h>
37+
#include <TPDGCode.h>
3738

3839
#include <RtypesCore.h>
3940

@@ -75,6 +76,9 @@ enum {
7576
kDATA = 1,
7677
kINEL,
7778
kINELg0,
79+
kDD,
80+
kSD,
81+
kND,
7882
kECend
7983
};
8084
enum {
@@ -173,9 +177,11 @@ static constexpr TrackSelectionFlags::flagtype trackSelectionTPC =
173177
static constexpr TrackSelectionFlags::flagtype trackSelectionDCA =
174178
TrackSelectionFlags::kDCAz | TrackSelectionFlags::kDCAxy;
175179

180+
176181
struct MultiplicityCounter {
177182
SliceCache cache;
178-
Preslice<aod::McParticles> perMCCol = aod::mcparticle::mcCollisionId;
183+
Preslice<Particles> perMCCol = aod::mcparticle::mcCollisionId;
184+
Preslice<FiTracks> perCol = aod::track::collisionId;
179185

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

@@ -236,9 +242,9 @@ struct MultiplicityCounter {
236242
std::vector<Double_t> logbins(nbins + 1, 0);
237243
Double_t low = 0.01;
238244
Double_t high = 10;
239-
Double_t logbw = (log(high) - log(low)) / nbins;
245+
Double_t logbw = (std::log(high) - std::log(low)) / nbins;
240246
for (int ij = 0; ij <= nbins; ij++) {
241-
logbins[ij] = low * exp(ij * logbw);
247+
logbins[ij] = low * std::exp(ij * logbw);
242248
}
243249
AxisSpec ptbins2 = {logbins, "pT (GeV/c)", "pt bin"};
244250

@@ -280,12 +286,12 @@ struct MultiplicityCounter {
280286
soa::Join<aod::Collisions, aod::EvSels> const& collisions)
281287
{
282288
std::vector<typename std::decay_t<decltype(collisions)>::iterator> cols;
283-
for (auto& bc : bcs) {
289+
for (const auto& bc : bcs) {
284290
if (!useEvSel || (bc.selection_bit(o2::aod::evsel::kIsBBT0A) &&
285291
bc.selection_bit(o2::aod::evsel::kIsBBT0C)) != 0) {
286292
registry.fill(HIST("Selection"), 5.);
287293
cols.clear();
288-
for (auto& collision : collisions) {
294+
for (const auto& collision : collisions) {
289295
if (collision.has_foundBC()) {
290296
if (collision.foundBCId() == bc.globalIndex()) {
291297
cols.emplace_back(collision);
@@ -314,11 +320,11 @@ struct MultiplicityCounter {
314320
FiTracks const& /*tracks*/)
315321
{
316322

317-
for (auto& collision : collisions) {
323+
for (const auto& collision : collisions) {
318324
Bool_1d btrigc(kTrigend, false);
319325
registry.fill(HIST("Selection"), 1.);
320326
auto z = collision.posZ();
321-
auto pertracks = tSample3->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache);
327+
auto pertracks = tSample3->sliceBy(perCol, collision.globalIndex());
322328
auto Ntrk = 0;
323329

324330
// if (collision.selection_bit(aod::evsel::kIsTriggerTVX) && collision.selection_bit(aod::evsel::kNoTimeFrameBorder) && collision.selection_bit(aod::evsel::kNoITSROFrameBorder)) {
@@ -333,7 +339,7 @@ struct MultiplicityCounter {
333339
if (btrigc[kSel8] && std::abs(z) < 10)
334340
registry.fill(HIST("hft0multiplicity"), collision.multFT0C());
335341

336-
for (auto& track : pertracks) {
342+
for (const auto& track : pertracks) {
337343
[[maybe_unused]] int dummy = track.globalIndex();
338344
if (std::abs(track.eta()) < 1)
339345
Ntrk++; // charged track check
@@ -370,7 +376,7 @@ struct MultiplicityCounter {
370376
registry.fill(HIST("hreczvtx"), Double_t(kDATA), Double_t(itrigc), z, cent);
371377
}
372378

373-
for (auto& track : pertracks) {
379+
for (const auto& track : pertracks) {
374380
if (btrigc[kSel8] && std::abs(track.eta()) < 0.8 && std::abs(z) < 10)
375381
registry.fill(HIST("hrecdndpt"), track.pt());
376382
if (btrigc[kSel8])
@@ -388,21 +394,31 @@ struct MultiplicityCounter {
388394

389395
PresliceUnsorted<soa::Join<MyCollisions, aod::McCollisionLabels>> perMcCol = o2::aod::mccollisionlabel::mcCollisionId;
390396
Preslice<aod::McParticles> perMCColparticles = aod::mcparticle::mcCollisionId;
397+
Preslice<FiLTracks> perColFiLTracks = aod::track::collisionId;
398+
using MCex = soa::Join<aod::McCollisions, aod::HepMCXSections>;
391399
void processMCCounting(
392-
aod::McCollisions const& mcCollisions, soa::Join<MyCollisionsCent, aod::McCollisionLabels> const& collisions, Particles const& mcParticles,
400+
MCex const& mcCollisions, soa::Join<MyCollisionsCent, aod::McCollisionLabels> const& collisions, Particles const& mcParticles,
393401
FiLTracks const& tracks)
394402
{
395-
for (auto& mcCollision : mcCollisions) {
403+
for (const auto& mcCollision : mcCollisions) {
396404
Bool_1d bevtc(kECend, false);
397405
bevtc[kINEL] = true;
406+
auto procId = mcCollision.processId();
407+
if (procId == 101) {
408+
bevtc[kND] = true;
409+
} else if (procId == 103 || procId == 104) {
410+
bevtc[kSD] = true;
411+
} else if (procId == 105 || procId == 106) {
412+
bevtc[kDD] = true;
413+
}
398414
registry.fill(HIST("Selection"), 1.);
399415

400416
auto mcz = mcCollision.posZ();
401417
auto genz = mcz;
402418

403419
auto Ntrk_gen = 0;
404420
auto particles = mcParticles.sliceByCached(aod::mcparticle::mcCollisionId, mcCollision.globalIndex(), cache);
405-
for (auto& particle : particles) {
421+
for (const auto& particle : particles) {
406422
if (!particle.isPhysicalPrimary())
407423
continue;
408424
auto kp = pdg->GetParticle(particle.pdgCode());
@@ -426,7 +442,7 @@ struct MultiplicityCounter {
426442
registry.fill(HIST("Selection"), 10);
427443
if (bevtc[kINELg0] && std::abs(mcz) < 10)
428444
registry.fill(HIST("Selection"), 12);
429-
for (auto& particle : particles) {
445+
for (const auto& particle : particles) {
430446
if (!particle.isPhysicalPrimary())
431447
continue;
432448
auto kp = pdg->GetParticle(particle.pdgCode());
@@ -452,7 +468,7 @@ struct MultiplicityCounter {
452468
if (collisionsample.size() != 1) {
453469
cent = -1.0;
454470
} else {
455-
for (auto& collision : collisionsample) {
471+
for (const auto& collision : collisionsample) {
456472
if (IsPbPb) {
457473
if constexpr (MyCollisionsCent::template contains<aod::CentFT0Cs>())
458474
cent = collision.centFT0C();
@@ -462,7 +478,7 @@ struct MultiplicityCounter {
462478

463479
// auto Ntrk_rec = 0;
464480
// auto trackspart = tracks.sliceByCached(aod::track::collisionId, collision.globalIndex(), cache);
465-
// for (auto& track : trackspart) {
481+
// for (const auto& track : trackspart) {
466482
// if (std::abs(track.eta()) < 1) {
467483
// Ntrk_rec++;
468484
// }
@@ -476,9 +492,9 @@ struct MultiplicityCounter {
476492
}
477493
Int_t pid = 0;
478494
std::vector<Double_t> particleetas;
479-
for (auto& particle : particles) {
495+
for (const auto& particle : particles) {
480496
auto p = pdg->GetParticle(particle.pdgCode());
481-
if (std::abs(particle.pdgCode()) == 310 && std::abs(particle.eta()) < 0.5 && std::abs(genz) < 10)
497+
if (std::abs(particle.pdgCode()) == kK0Short && std::abs(particle.eta()) < 0.5 && std::abs(genz) < 10)
482498
registry.fill(HIST("Selection"), 17.);
483499
if (!particle.isPhysicalPrimary()) {
484500
continue;
@@ -519,7 +535,7 @@ struct MultiplicityCounter {
519535
}
520536
}
521537

522-
for (auto& collision : collisionsample) {
538+
for (const auto& collision : collisionsample) {
523539
auto cent = -1.f;
524540
if (IsPbPb) {
525541
if constexpr (MyCollisionsCent::template contains<aod::CentFT0Cs>())
@@ -529,7 +545,7 @@ struct MultiplicityCounter {
529545
cent = collision.centFT0M();
530546
// auto Ntrk_rec = 0;
531547
// auto trackspart = tracks.sliceByCached(aod::track::collisionId, collision.globalIndex(), cache);
532-
// for (auto& track : trackspart) {
548+
// for (const auto& track : trackspart) {
533549
// if (std::abs(track.eta()) < 1) {
534550
// Ntrk_rec++;
535551
// }
@@ -550,23 +566,23 @@ struct MultiplicityCounter {
550566
if (bevtc[kINEL] && btrigc[kSel8] && std::abs(z) < 10)
551567
registry.fill(HIST("hft0multiplicity"), collision.multFT0C());
552568
if (collisionsample.size() == 1 && bevtc[kINELg0] && btrigc[kSel8]) {
553-
for (auto eta : particleetas) {
569+
for (const auto& eta : particleetas) {
554570
registry.fill(HIST("genetaINELg0Sel8recz10"), eta, z);
555571
registry.fill(HIST("genetaINELg0Sel8genz10"), eta, mcz);
556572
}
557573
registry.fill(HIST("reczINELg0Sel8"), z);
558574
registry.fill(HIST("genzINELg0Sel8"), genz);
559575
}
560576
if (collisionsample.size() == 1 && bevtc[kINELg0]) {
561-
for (auto eta : particleetas) {
577+
for (const auto& eta : particleetas) {
562578
registry.fill(HIST("genetaINELg0genz10"), eta, mcz);
563579
}
564580
registry.fill(HIST("genzINELg0"), genz);
565581
}
566582

567583
auto Ntrk_rec = 0;
568-
auto trackspart = tracks.sliceByCached(aod::track::collisionId, collision.globalIndex(), cache);
569-
for (auto& track : trackspart) {
584+
auto trackspart = tracks.sliceBy(perColFiLTracks, collision.globalIndex());
585+
for (const auto& track : trackspart) {
570586
if (std::abs(track.eta()) < 1) {
571587
Ntrk_rec++;
572588
}
@@ -601,7 +617,7 @@ struct MultiplicityCounter {
601617
}
602618
}
603619
std::vector<Int_t> mclabels;
604-
for (auto& track : trackspart) {
620+
for (const auto& track : trackspart) {
605621
if (track.has_mcParticle()) {
606622
Int_t pid = kBkg;
607623
auto particle = track.template mcParticle_as<Particles>();
@@ -626,7 +642,7 @@ struct MultiplicityCounter {
626642
for (auto MotherIDs = particle.mothersIds().front(); MotherIDs <= particle.mothersIds().back(); MotherIDs++) {
627643
auto mother = mcParticles.rawIteratorAt(MotherIDs);
628644
auto pdg_mother = mother.pdgCode();
629-
if (pdg_mother == 310 || std::abs(pdg_mother) == 3122) {
645+
if (pdg_mother == kK0Short || std::abs(pdg_mother) == kLambda0) {
630646
pid = kMotherStrange;
631647
}
632648
}
@@ -677,7 +693,7 @@ struct MultiplicityCounter {
677693
}
678694

679695
auto mcCollision = collision.mcCollision();
680-
auto particlesPerCol = particles.sliceByCached(aod::mcparticle::mcCollisionId, mcCollision.globalIndex(), cache);
696+
auto particlesPerCol = particles.sliceBy(perMCCol, mcCollision.globalIndex());
681697
}
682698

683699
PROCESS_SWITCH(MultiplicityCounter, processTrackEfficiencyGeneral, "MC Count tracks", false);
@@ -697,7 +713,7 @@ struct MultiplicityCounter {
697713
auto genz = mcCollision.posZ();
698714
Bool_1d bevtc(kECend, false);
699715
bevtc[kINEL] = true;
700-
for (auto& particle : mcParticles) {
716+
for (const auto& particle : mcParticles) {
701717
if (!particle.isPhysicalPrimary())
702718
continue;
703719
auto p = pdg->GetParticle(particle.pdgCode());
@@ -713,9 +729,9 @@ struct MultiplicityCounter {
713729
registry.fill(HIST("hgenzvtx"), Double_t(ievtc), genz, -1.0);
714730
}
715731
Int_t pid = 0;
716-
for (auto& particle : mcParticles) {
732+
for (const auto& particle : mcParticles) {
717733
auto p = pdg->GetParticle(particle.pdgCode());
718-
if (std::abs(particle.pdgCode()) == 310 && std::abs(particle.eta()) < 0.5 && std::abs(genz) < 10)
734+
if (std::abs(particle.pdgCode()) == kK0Short && std::abs(particle.eta()) < 0.5 && std::abs(genz) < 10)
719735
registry.fill(HIST("Selection"), 17.);
720736
if (!particle.isPhysicalPrimary()) {
721737
continue;
@@ -762,7 +778,7 @@ struct MultiplicityCounter {
762778
FiTracks const& /*tracks*/,
763779
DaughterTracks const& /*Dautrks*/)
764780
{
765-
for (auto& collision : collisions) {
781+
for (const auto& collision : collisions) {
766782
if (!collision.sel8())
767783
continue;
768784
auto z = collision.posZ();
@@ -777,7 +793,7 @@ struct MultiplicityCounter {
777793
}
778794

779795
auto v0s_per_coll = fullV0s.sliceBy(perCollisionV0, collision.globalIndex());
780-
for (auto& v0 : v0s_per_coll) {
796+
for (const auto& v0 : v0s_per_coll) {
781797

782798
auto pTrack = v0.template posTrack_as<DaughterTracks>();
783799
auto nTrack = v0.template negTrack_as<DaughterTracks>();
@@ -790,12 +806,12 @@ struct MultiplicityCounter {
790806
continue;
791807
if (v0.v0cosPA() < v0cospa)
792808
continue;
793-
if (fabs(pTrack.eta()) > 0.9)
809+
if (std::fabs(pTrack.eta()) > 0.9)
794810
continue;
795-
if (fabs(nTrack.eta()) > 0.9)
811+
if (std::fabs(nTrack.eta()) > 0.9)
796812
continue;
797813

798-
if (fabs(v0.eta()) < 0.5)
814+
if (std::fabs(v0.eta()) < 0.5)
799815
registry.fill(HIST("hv0k0s"), v0.mK0Short());
800816
registry.fill(HIST("hv0mass"), cent, Double_t(kK0short), v0.eta(), Double_t(v0.mK0Short()));
801817
registry.fill(HIST("hv0mass"), cent, Double_t(kLambda), v0.eta(), Double_t(v0.mLambda()));
@@ -814,7 +830,7 @@ struct MultiplicityCounter {
814830
soa::Filtered<LabeledTracksEx> const& /*tracks*/,
815831
DaughterTracks const& /*Dautrks*/)
816832
{
817-
for (auto& collision : collisions) {
833+
for (const auto& collision : collisions) {
818834
auto cent = -1.f;
819835

820836
if (IsPbPb) {
@@ -830,7 +846,7 @@ struct MultiplicityCounter {
830846
if (!collision.has_mcCollision()) // check mc particle
831847
continue;
832848

833-
for (auto& v0 : fullV0s) {
849+
for (const auto& v0 : fullV0s) {
834850

835851
auto pTrack = v0.template posTrack_as<DaughterTracks>();
836852
auto nTrack = v0.template negTrack_as<DaughterTracks>();

0 commit comments

Comments
 (0)