Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 92 additions & 67 deletions PWGLF/Tasks/Nuspex/spectraTOF.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.

Check failure on line 1 in PWGLF/Tasks/Nuspex/spectraTOF.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[name/workflow-file]

Name of a workflow file must match the name of the main struct in it (without the PWG prefix). (Class implementation files should be in "Core" directories.)
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
Expand Down Expand Up @@ -632,6 +632,8 @@
hh->GetXaxis()->SetBinLabel(4, "INEL>1");
hh->GetXaxis()->SetBinLabel(5, "hasParticleInFT0C && hasParticleInFT0A");
histos.add("MC/MultiplicityRecoEv", "MC multiplicity", kTH1D, {multAxis});
histos.add("MC/CentFT0CVsTrueMult", "MC Centrality vs True Multiplicity", kTH2D, {multAxis, {150, 0, 150, "Track multiplicity"}});

histos.add("MC/Multiplicity", "MC multiplicity", kTH1D, {multAxis});
histos.add("MC/MultiplicityMCINELgt0", "MC multiplicity", kTH1D, {multAxis});
histos.add("MC/MultiplicityMCINELgt1", "MC multiplicity", kTH1D, {multAxis});
Expand All @@ -645,7 +647,7 @@
}
}

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

for (int i = 0; i < NpCharge; i++) {
switch (i) {
Expand Down Expand Up @@ -1532,7 +1534,7 @@
}

// trackwCut++;
const auto& mcLabel = mcTrackLabels.iteratorAt(track.globalIndex());

Check failure on line 1537 in PWGLF/Tasks/Nuspex/spectraTOF.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
const auto& mcParticle = mcParticles.iteratorAt(mcLabel.mcParticleId());
int pdgCode = mcParticle.pdgCode();
const auto& nsigmaTPCPi = o2::aod::pidutils::tpcNSigma<2>(track);
Expand Down Expand Up @@ -2487,26 +2489,27 @@
}
}

// ==============================================================================
// HELPER 1: For Reconstructed Events
// Accepts 'eventMultiplicity' (which will be the actual Reco Centrality)
// ==============================================================================
template <std::size_t i, typename ParticleType>
void fillParticleHistogramsMCRecoEvs(ParticleType const& mcParticle, RecoMCCollisions::iterator const& collision)
void fillParticleHistogramsMCRecoEvs(ParticleType const& mcParticle, RecoMCCollisions::iterator const& collision, float eventMultiplicity)
{
if (!isParticleEnabled<i>()) { // Check if the particle is enabled
if (!isParticleEnabled<i>()) {
return;
}

if (mcParticle.pdgCode() != PDGs[i]) {
return;
}

const auto& mcCollision = collision.mcCollision_as<GenMCCollisions>();
const float multiplicity = getMultiplicityMC(mcCollision);

if (mcParticle.isPhysicalPrimary()) {
if (isEventSelected<false, false>(collision)) {
if (includeCentralityMC) {
histos.fill(HIST(hpt_den_prm_goodev[i]), mcParticle.pt(), multiplicity, mcParticle.eta());
histos.fill(HIST(hpt_den_prm_goodev[i]), mcParticle.pt(), eventMultiplicity, mcParticle.eta());
} else {
histos.fill(HIST(hpt_den_prm_goodev[i]), mcParticle.pt(), multiplicity);
histos.fill(HIST(hpt_den_prm_goodev[i]), mcParticle.pt(), eventMultiplicity);
}
} else {
bool isSelected = collision.sel8();
Expand All @@ -2529,40 +2532,43 @@
}
if (isSelected) {
if (includeCentralityMC) {
histos.fill(HIST(hpt_den_prm_evsel[i]), mcParticle.pt(), multiplicity, mcParticle.eta());
histos.fill(HIST(hpt_den_prm_evsel[i]), mcParticle.pt(), eventMultiplicity, mcParticle.eta());
} else {
histos.fill(HIST(hpt_den_prm_evsel[i]), mcParticle.pt(), multiplicity);
histos.fill(HIST(hpt_den_prm_evsel[i]), mcParticle.pt(), eventMultiplicity);
}
}
} else {
if (includeCentralityMC) {
histos.fill(HIST(hpt_den_prm_recoev[i]), mcParticle.pt(), multiplicity, mcParticle.eta());
histos.fill(HIST(hpt_den_prm_recoev[i]), mcParticle.pt(), eventMultiplicity, mcParticle.eta());
} else {
histos.fill(HIST(hpt_den_prm_recoev[i]), mcParticle.pt(), multiplicity);
histos.fill(HIST(hpt_den_prm_recoev[i]), mcParticle.pt(), eventMultiplicity);
}
}
}
}
}

// ==============================================================================
// HELPER 2: For All Generated Events (Signal Loss Denominator)
// Accepts 'eventMultiplicity' (which will be the True Multiplicity |eta| < 0.5)
// ==============================================================================
template <std::size_t i, typename ParticleType>
void fillParticleHistogramsMCGenEvs(ParticleType const& mcParticle, GenMCCollisions::iterator const& mcCollision)
void fillParticleHistogramsMCGenEvs(ParticleType const& mcParticle, float eventMultiplicity)
{

if (!isParticleEnabled<i>()) { // Check if the particle is enabled
if (!isParticleEnabled<i>()) {
return;
}

if (mcParticle.pdgCode() != PDGs[i]) {
return;
}

const float multiplicity = getMultiplicityMC(mcCollision);
if (mcParticle.isPhysicalPrimary()) {
if (std::abs(mcCollision.posZ()) < evselOptions.cfgCutVertex) {
histos.fill(HIST(hpt_den_prm_mcgoodev[i]), mcParticle.pt(), multiplicity);
// Ensure this matches the array name for your generated denominator histograms!
if (includeCentralityMC) {
histos.fill(HIST(hpt_den_prm_mcgoodev[i]), mcParticle.pt(), eventMultiplicity);
} else {
histos.fill(HIST(hpt_den_prm_mcbadev[i]), mcParticle.pt(), multiplicity);
histos.fill(HIST(hpt_den_prm_mcbadev[i]), mcParticle.pt(), eventMultiplicity);
}
}
}
Expand All @@ -2584,6 +2590,9 @@
histos.fill(HIST("MC/GenRecoCollisions"), 1.f, mcCollisions.size());
histos.fill(HIST("MC/GenRecoCollisions"), 2.f, collisions.size());

// ==============================================================================
// 1. RECONSTRUCTED TRACKS LOOP
// ==============================================================================
for (const auto& track : tracks) {
if (!track.has_collision()) {
if (track.sign() > 0) {
Expand Down Expand Up @@ -2613,107 +2622,123 @@
fillTrackHistogramsMC<i>(track, mcParticle, track.collision_as<RecoMCCollisions>(), mcParticles);
});
}

// (Keeping your original includeCentralityMC legacy block intact to avoid breaking other parts of your code)
if (includeCentralityMC) {
for (const auto& collision : collisions) {
if (!collision.has_mcCollision()) {
continue;
}
if (!collision.has_mcCollision()) continue;
const auto& mcCollision = collision.mcCollision_as<GenMCCollisions>();
const auto& particlesInCollision = mcParticles.sliceByCached(aod::mcparticle::mcCollisionId, mcCollision.globalIndex(), cache);
const float multiplicity = getMultiplicity(collision);
for (const auto& mcParticle : particlesInCollision) {

if (std::abs(mcParticle.y()) > trkselOptions.cfgCutY) {
continue;
}
static_for<0, 17>([&](auto i) {
fillParticleHistogramsMC<i>(multiplicity, mcParticle);
});
if (std::abs(mcParticle.y()) > trkselOptions.cfgCutY) continue;
static_for<0, 17>([&](auto i) { fillParticleHistogramsMC<i>(multiplicity, mcParticle); });
}
}
} else {
for (const auto& mcParticle : mcParticles) {
if (std::abs(mcParticle.y()) > trkselOptions.cfgCutY) {
continue;
}

if (std::abs(mcParticle.y()) > trkselOptions.cfgCutY) continue;
const auto& mcCollision = mcParticle.mcCollision_as<GenMCCollisions>();
const float multiplicity = getMultiplicityMC(mcCollision);

static_for<0, 17>([&](auto i) {
fillParticleHistogramsMC<i>(multiplicity, mcParticle);
});
static_for<0, 17>([&](auto i) { fillParticleHistogramsMC<i>(multiplicity, mcParticle); });
}
}
// Loop on reconstructed collisions

// ==============================================================================
// 2. RECONSTRUCTED COLLISIONS LOOP (Builds the 2D Calibration Map)
// ==============================================================================
for (const auto& collision : collisions) {
if (!collision.has_mcCollision()) {
continue;
}
const auto& mcCollision = collision.mcCollision_as<GenMCCollisions>();
const auto& particlesInCollision = mcParticles.sliceByCached(aod::mcparticle::mcCollisionId, mcCollision.globalIndex(), cache);

if (evselOptions.cfgINELCut.value == 1) {
if (!o2::pwglf::isINELgt0mc(particlesInCollision, pdgDB)) {
continue;
}
if (!o2::pwglf::isINELgt0mc(particlesInCollision, pdgDB)) continue;
}
if (evselOptions.cfgINELCut.value == 2) {
if (!o2::pwglf::isINELgt1mc(particlesInCollision, pdgDB)) {
continue;
if (!o2::pwglf::isINELgt1mc(particlesInCollision, pdgDB)) continue;
}

// -- Get Actual Reconstructed Centrality --
float recoCentrality = collision.centFT0C();

Check failure on line 2665 in PWGLF/Tasks/Nuspex/spectraTOF.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.

// -- Calculate True Multiplicity in |eta| < 0.5 --
int trueMultEta05 = 0;
for (const auto& mcParticle : particlesInCollision) {
if (!mcParticle.isPhysicalPrimary()) continue;
auto* pdgParticle = pdgDB->GetParticle(mcParticle.pdgCode());
if (pdgParticle != nullptr && std::abs(pdgParticle->Charge()) > 0.01) {
if (std::abs(mcParticle.eta()) < 0.5f) {
trueMultEta05++;
}
}
}

Check failure on line 2677 in PWGLF/Tasks/Nuspex/spectraTOF.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.

Check failure on line 2678 in PWGLF/Tasks/Nuspex/spectraTOF.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
if (isEventSelected<false, false>(collision)) {
histos.fill(HIST("MC/MultiplicityRecoEv"), getMultiplicityMC(mcCollision));
histos.fill(HIST("MC/MultiplicityRecoEv"), recoCentrality);
// -- Fill the 2D map to extract the 1D calibration profile later! --
histos.fill(HIST("MC/CentFT0CVsTrueMult"), recoCentrality, trueMultEta05);
}

for (const auto& mcParticle : particlesInCollision) {
if (std::abs(mcParticle.y()) > trkselOptions.cfgCutY) {
continue;
}
if (std::abs(mcParticle.y()) > trkselOptions.cfgCutY) continue;
static_for<0, 17>([&](auto i) {
fillParticleHistogramsMCRecoEvs<i>(mcParticle, collision);
// Pass the actual Reco Centrality to the helper function
fillParticleHistogramsMCRecoEvs<i>(mcParticle, collision, recoCentrality);
});
}
}

// Loop on generated collisions
// ==============================================================================
// 3. GENERATED COLLISIONS LOOP (Builds the Signal Loss Denominator)
// ==============================================================================
for (const auto& mcCollision : mcCollisions) {
if (std::abs(mcCollision.posZ()) > evselOptions.cfgCutVertex) {
continue;
}
histos.fill(HIST("MC/Multiplicity"), getMultiplicityMC(mcCollision));

const auto& particlesInCollision = mcParticles.sliceByCached(aod::mcparticle::mcCollisionId, mcCollision.globalIndex(), cache);
bool hasParticleInFT0C = false;
bool hasParticleInFT0A = false;
if (evselOptions.cfgINELCut.value == EvSelInelGt0Cut) {
if (!o2::pwglf::isINELgt0mc(particlesInCollision, pdgDB)) {
continue;

// -- Calculate True Multiplicity in |eta| < 0.5 --
int trueMultEta05 = 0;
for (const auto& mcParticle : particlesInCollision) {
if (!mcParticle.isPhysicalPrimary()) continue;
auto* pdgParticle = pdgDB->GetParticle(mcParticle.pdgCode());
if (pdgParticle != nullptr && std::abs(pdgParticle->Charge()) > 0.01) {
if (std::abs(mcParticle.eta()) < 0.5f) {
trueMultEta05++;
}
}
}

Check failure on line 2714 in PWGLF/Tasks/Nuspex/spectraTOF.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
histos.fill(HIST("MC/MultiplicityMCINELgt0"), getMultiplicityMC(mcCollision));

Check failure on line 2715 in PWGLF/Tasks/Nuspex/spectraTOF.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
histos.fill(HIST("MC/Multiplicity"), trueMultEta05);

if (evselOptions.cfgINELCut.value == EvSelInelGt0Cut) {
if (!o2::pwglf::isINELgt0mc(particlesInCollision, pdgDB)) continue;
}
histos.fill(HIST("MC/MultiplicityMCINELgt0"), trueMultEta05);

if (evselOptions.cfgINELCut.value == EvSelInelGt1Cut) {
if (!o2::pwglf::isINELgt1mc(particlesInCollision, pdgDB)) {
continue;
}
if (!o2::pwglf::isINELgt1mc(particlesInCollision, pdgDB)) continue;
}
histos.fill(HIST("MC/MultiplicityMCINELgt1"), getMultiplicityMC(mcCollision));
histos.fill(HIST("MC/MultiplicityMCINELgt1"), trueMultEta05);

for (const auto& mcParticle : particlesInCollision) {
if (std::abs(mcParticle.y()) > trkselOptions.cfgCutY) {
continue;
}
if (std::abs(mcParticle.y()) > trkselOptions.cfgCutY) continue;
static_for<0, 17>([&](auto i) {
fillParticleHistogramsMCGenEvs<i>(mcParticle, mcCollision);
// Pass True Multiplicity directly so it plots generated particles against it
fillParticleHistogramsMCGenEvs<i>(mcParticle, trueMultEta05);
});
}

if (mcCollision.isInelGt0()) {
histos.fill(HIST("MC/GenRecoCollisions"), 3.f);
}
if (mcCollision.isInelGt1()) {
histos.fill(HIST("MC/GenRecoCollisions"), 4.f);
}
if (hasParticleInFT0C && hasParticleInFT0A) {
histos.fill(HIST("MC/GenRecoCollisions"), 5.f);
}
}
}
PROCESS_SWITCH(tofSpectra, processMC, "Process MC", false);
Expand Down
Loading