Skip to content

Commit a671bcb

Browse files
authored
[PWGLF] Added MC truth matching for nSigmaTPC histograms (#14342)
1 parent c9097c4 commit a671bcb

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

PWGLF/Tasks/Nuspex/spectraTOF.cxx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ std::array<std::shared_ptr<TH2>, NpCharge> hDecayLengthMCNotHF; // Decay Length
7878

7979
std::array<std::shared_ptr<TH2>, NpCharge> hPtNumTOFMatchWithPIDSignalPrm; // Pt distribution of particles with a hit in the TOF and a compatible signal
8080

81+
std::array<std::array<std::shared_ptr<TH3>, NpCharge>, 3> hMCpdg_nsigmaTPC; // 2D array of nsigmaTPC histograms [Selection: pi,K,p][True PDG: 18 species]
82+
8183
// Spectra task
8284
struct tofSpectra {
8385
struct : ConfigurableGroup {
@@ -585,6 +587,13 @@ struct tofSpectra {
585587
histos.add("MC/MultiplicityMCINELgt0", "MC multiplicity", kTH1D, {multAxis});
586588
histos.add("MC/MultiplicityMCINELgt1", "MC multiplicity", kTH1D, {multAxis});
587589
}
590+
if (doprocessTrackMCLabels) {
591+
for (int par = 2; par <= 4; par++) {
592+
for (int i = 0; i < NpCharge; i++) {
593+
hMCpdg_nsigmaTPC[par - 2][i] = histos.add<TH3>(Form("test_mclabels/nsigmatpc/%s/%s/pdg_%i", (i < Np) ? "pos" : "neg", pN[par], PDGs[i % Np]), Form("True %s (%i) in %s selection", pTCharge[i], PDGs[i], (i < Np) ? pTCharge[par] : pTCharge[par + Np]), kTH3D, {ptAxis, nsigmaTPCAxisOccupancy, multAxis});
594+
}
595+
}
596+
}
588597

589598
hMultiplicityvsPercentile = histos.add<TH2>("Mult/vsPercentile", "Multiplicity vs percentile", HistType::kTH2D, {{150, 0, 150}, {100, 0, 100, "Track multiplicity"}});
590599

@@ -2785,6 +2794,44 @@ struct tofSpectra {
27852794
}
27862795
}
27872796
PROCESS_SWITCH(tofSpectra, processMCgen_RecoEvs, "process generated MC (reconstructed events)", false);
2797+
void processTrackMCLabels(CollisionCandidates::iterator const& collisions,
2798+
soa::Join<TrackCandidates,
2799+
aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr,
2800+
aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr> const& tracks,
2801+
aod::McTrackLabels const& mcTrackLabels, aod::McParticles const& mcParticles)
2802+
{
2803+
const float multiplicity = getMultiplicity(collisions);
2804+
for (const auto& track : tracks) {
2805+
if (!track.has_collision()) {
2806+
continue;
2807+
}
2808+
const auto& collision = track.collision_as<CollisionCandidates>();
2809+
if (!isEventSelected<false, false>(collision)) {
2810+
continue;
2811+
}
2812+
if (!isTrackSelected<true>(track, collision)) {
2813+
continue;
2814+
}
2815+
const auto& mcLabel = mcTrackLabels.iteratorAt(track.globalIndex());
2816+
const auto& mcParticle = mcParticles.iteratorAt(mcLabel.mcParticleId());
2817+
int pdgCode = mcParticle.pdgCode();
2818+
static_for<2, 4>([&](auto par) {
2819+
const auto& nsigmaTPCpar = o2::aod::pidutils::tpcNSigma<par>(track);
2820+
bool isTPCpar = std::abs(nsigmaTPCpar) < trkselOptions.cfgCutNsigma;
2821+
// Precompute rapidity values to avoid redundant calculations
2822+
double rapiditypar = std::abs(track.rapidity(PID::getMass(par)));
2823+
// TPC Selection and histogram filling
2824+
if (isTPCpar && rapiditypar <= trkselOptions.cfgCutY) {
2825+
static_for<0, 17>([&](auto i) {
2826+
if (pdgCode == PDGs[i]) {
2827+
hMCpdg_nsigmaTPC[par - 2][i]->Fill(track.pt(), nsigmaTPCpar, multiplicity);
2828+
}
2829+
});
2830+
}
2831+
});
2832+
}
2833+
}
2834+
PROCESS_SWITCH(tofSpectra, processTrackMCLabels, "Fill track histograms using MC matched PDG labels", false);
27882835

27892836
}; // end of spectra task
27902837

0 commit comments

Comments
 (0)