From 56fb255c836bac2a03d71203b9df62b8f8b59ea9 Mon Sep 17 00:00:00 2001 From: Banajit Barman <113376372+BanajitBarman@users.noreply.github.com> Date: Wed, 13 May 2026 18:17:37 +0530 Subject: [PATCH 1/4] Changed to include FT0C --- PWGLF/TableProducer/Common/mcCentrality.cxx | 81 +++++++++++++-------- 1 file changed, 51 insertions(+), 30 deletions(-) diff --git a/PWGLF/TableProducer/Common/mcCentrality.cxx b/PWGLF/TableProducer/Common/mcCentrality.cxx index e7ccd4d59fb..cf89c7682d0 100644 --- a/PWGLF/TableProducer/Common/mcCentrality.cxx +++ b/PWGLF/TableProducer/Common/mcCentrality.cxx @@ -35,6 +35,7 @@ #include #include +#include #include #include @@ -48,12 +49,14 @@ using namespace o2::framework::expressions; struct McCentrality { // Tables to produce - Produces centFV0A; Produces centFT0M; Produces centFT0A; Produces centFT0C; - Produces centFDDM; - Produces centNTPV; + + // NOTE: Commented out unused produces to prevent garbage columns in AOD + // Produces centFV0A; + // Produces centFDDM; + // Produces centNTPV; // Input parameters Service ccdb; @@ -64,6 +67,9 @@ struct McCentrality { Service pdgDB; ConfigurableAxis binsPercentile{"binsPercentile", {VARIABLE_WIDTH, 0, 0.001, 0.01, 1.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0}, "Binning of the percentile axis"}; ConfigurableAxis binsMultiplicity{"binsMultiplicity", {1000, 0, 5000}, "Binning of the multiplicity axis"}; + + // Added fillFt0M to allow running strictly on A/C without crashing on missing M + Configurable fillFt0M{"fillFt0M", true, "Fills the FT0M histogram"}; Configurable fillFt0A{"fillFt0A", false, "Fills the FT0A histogram"}; Configurable fillFt0C{"fillFt0C", false, "Fills the FT0C histogram"}; Configurable doNotCrashOnNull{"doNotCrashOnNull", false, "If ccdb object does not exist, fill with dummy values"}; @@ -73,8 +79,6 @@ struct McCentrality { TH1F* h1dFT0M = nullptr; TH1F* h1dFT0A = nullptr; TH1F* h1dFT0C = nullptr; - // TH1F* h1dFDD; - // TH1F* h1dNTP; o2::pwglf::ParticleCounter mCounter; @@ -89,8 +93,11 @@ struct McCentrality { mCounter.mPdgDatabase = pdgDB.service; mCounter.mSelectPrimaries = selectPrimaries.value; - histos.add("FT0M/percentile", "FT0M percentile.", HistType::kTH1D, {{binsPercentile, "FT0M percentile"}}); - histos.add("FT0M/percentilevsMult", "FT0M percentile.", HistType::kTH2D, {{binsPercentile, "FT0M percentile"}, {binsMultiplicity, "FT0M mult."}}); + + if (fillFt0M) { + histos.add("FT0M/percentile", "FT0M percentile.", HistType::kTH1D, {{binsPercentile, "FT0M percentile"}}); + histos.add("FT0M/percentilevsMult", "FT0M percentile.", HistType::kTH2D, {{binsPercentile, "FT0M percentile"}, {binsMultiplicity, "FT0M mult."}}); + } if (fillFt0A) { histos.add("FT0A/percentile", "FT0A percentile.", HistType::kTH1D, {{binsPercentile, "FT0A percentile"}}); histos.add("FT0A/percentilevsMult", "FT0A percentile.", HistType::kTH2D, {{binsPercentile, "FT0A percentile"}, {binsMultiplicity, "FT0A mult."}}); @@ -101,6 +108,8 @@ struct McCentrality { } TList* lOfInput = nullptr; + TFile* f = nullptr; // Track file to close later + if (path.value.rfind("ccdb://", 0) == 0) { // Getting post calib. from CCDB path.value.replace(0, 7, ""); lOfInput = ccdb->get(path); @@ -113,12 +122,9 @@ struct McCentrality { } } } else { // Getting post calib. from file - TFile* f = TFile::Open(path.value.c_str(), "READ"); - if (!f) { - LOG(fatal) << "The input file " << path << " is not valid"; - } - if (!f->IsOpen()) { - LOG(fatal) << "The input file " << f->GetName() << " is not open"; + f = TFile::Open(path.value.c_str(), "READ"); + if (!f || !f->IsOpen()) { + LOG(fatal) << "The input file " << path << " is not valid or open"; } lOfInput = static_cast(f->Get("ccdb_object")); if (!lOfInput) { @@ -126,60 +132,75 @@ struct McCentrality { LOG(fatal) << "The input file " << path.value << " does not contain the TList ccdb_object"; } } + auto getHist = [this, lOfInput](const char* name) -> TH1F* { if (!lOfInput) { return nullptr; } - auto hist = static_cast(lOfInput->FindObject(name)); - if (!hist) { - lOfInput->ls(); + auto obj = lOfInput->FindObject(name); + if (!obj) { if (this->doNotCrashOnNull) { LOG(info) << "Could not open histogram " << name << " from TList, will fill tables with dummy values"; } else { LOG(fatal) << "Could not open histogram " << name << " from TList"; } + return nullptr; } + // Clone to detach from TFile directory so we can safely close the file + auto hist = static_cast(obj->Clone(Form("%s_clone", name))); + hist->SetDirectory(nullptr); return hist; }; - h1dFT0M = getHist("h1dFT0M"); + + if (fillFt0M) { + h1dFT0M = getHist("h1dFT0M"); + } if (fillFt0A) { h1dFT0A = getHist("h1dFT0A"); } if (fillFt0C) { h1dFT0C = getHist("h1dFT0C"); } + + // Safely close the file to prevent memory leaks + if (f) { + f->Close(); + delete f; + } } - // Full tables (independent on central calibrations) void process(aod::McCollision const& /*mcCollision*/, aod::McParticles const& mcParticles) { const float nFT0A = mCounter.countFT0A(mcParticles); const float nFT0C = mCounter.countFT0C(mcParticles); const float nFT0M = nFT0A + nFT0C; - // const float nFV0A = mCounter.countFV0A(mcParticles); - float valueCentFT0M = 105.0f; - if (h1dFT0M) - valueCentFT0M = h1dFT0M->GetBinContent(h1dFT0M->FindBin(nFT0M)); + if (fillFt0M) { + float valueCentFT0M = 105.0f; + if (h1dFT0M) { + valueCentFT0M = h1dFT0M->GetBinContent(h1dFT0M->FindBin(nFT0M)); + } + centFT0M(valueCentFT0M); + histos.fill(HIST("FT0M/percentile"), valueCentFT0M); + histos.fill(HIST("FT0M/percentilevsMult"), valueCentFT0M, nFT0M); + } + if (fillFt0A) { float valueCentFT0A = 105.0f; - if (h1dFT0A) + if (h1dFT0A) { valueCentFT0A = h1dFT0A->GetBinContent(h1dFT0A->FindBin(nFT0A)); + } centFT0A(valueCentFT0A); } + if (fillFt0C) { float valueCentFT0C = 105.0f; - if (h1dFT0C) + if (h1dFT0C) { valueCentFT0C = h1dFT0C->GetBinContent(h1dFT0C->FindBin(nFT0C)); + } centFT0C(valueCentFT0C); } - // const float valueCentFV0A = h1dFT0M->GetBinContent(h1dFT0M->FindBin(nFV0A)); - - centFT0M(valueCentFT0M); - // centFV0A(valueCentFV0A); - histos.fill(HIST("FT0M/percentile"), valueCentFT0M); - histos.fill(HIST("FT0M/percentilevsMult"), valueCentFT0M, nFT0M); } }; From 78db3ce7d96e15ca8c208b392f5d6b1838d41dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Wed, 13 May 2026 16:46:32 +0200 Subject: [PATCH 2/4] Refactor McCentrality to include additional produces --- PWGLF/TableProducer/Common/mcCentrality.cxx | 56 ++++++++------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/PWGLF/TableProducer/Common/mcCentrality.cxx b/PWGLF/TableProducer/Common/mcCentrality.cxx index cf89c7682d0..76dd80def99 100644 --- a/PWGLF/TableProducer/Common/mcCentrality.cxx +++ b/PWGLF/TableProducer/Common/mcCentrality.cxx @@ -49,14 +49,12 @@ using namespace o2::framework::expressions; struct McCentrality { // Tables to produce + Produces centFV0A; Produces centFT0M; Produces centFT0A; Produces centFT0C; - - // NOTE: Commented out unused produces to prevent garbage columns in AOD - // Produces centFV0A; - // Produces centFDDM; - // Produces centNTPV; + Produces centFDDM; + Produces centNTPV; // Input parameters Service ccdb; @@ -67,8 +65,6 @@ struct McCentrality { Service pdgDB; ConfigurableAxis binsPercentile{"binsPercentile", {VARIABLE_WIDTH, 0, 0.001, 0.01, 1.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0}, "Binning of the percentile axis"}; ConfigurableAxis binsMultiplicity{"binsMultiplicity", {1000, 0, 5000}, "Binning of the multiplicity axis"}; - - // Added fillFt0M to allow running strictly on A/C without crashing on missing M Configurable fillFt0M{"fillFt0M", true, "Fills the FT0M histogram"}; Configurable fillFt0A{"fillFt0A", false, "Fills the FT0A histogram"}; Configurable fillFt0C{"fillFt0C", false, "Fills the FT0C histogram"}; @@ -79,6 +75,8 @@ struct McCentrality { TH1F* h1dFT0M = nullptr; TH1F* h1dFT0A = nullptr; TH1F* h1dFT0C = nullptr; + // TH1F* h1dFDD; + // TH1F* h1dNTP; o2::pwglf::ParticleCounter mCounter; @@ -108,8 +106,6 @@ struct McCentrality { } TList* lOfInput = nullptr; - TFile* f = nullptr; // Track file to close later - if (path.value.rfind("ccdb://", 0) == 0) { // Getting post calib. from CCDB path.value.replace(0, 7, ""); lOfInput = ccdb->get(path); @@ -122,9 +118,12 @@ struct McCentrality { } } } else { // Getting post calib. from file - f = TFile::Open(path.value.c_str(), "READ"); - if (!f || !f->IsOpen()) { - LOG(fatal) << "The input file " << path << " is not valid or open"; + TFile* f = TFile::Open(path.value.c_str(), "READ"); + if (!f) { + LOG(fatal) << "The input file " << path << " is not valid"; + } + if (!f->IsOpen()) { + LOG(fatal) << "The input file " << f->GetName() << " is not open"; } lOfInput = static_cast(f->Get("ccdb_object")); if (!lOfInput) { @@ -132,26 +131,22 @@ struct McCentrality { LOG(fatal) << "The input file " << path.value << " does not contain the TList ccdb_object"; } } - auto getHist = [this, lOfInput](const char* name) -> TH1F* { if (!lOfInput) { return nullptr; } - auto obj = lOfInput->FindObject(name); - if (!obj) { + auto hist = static_cast(lOfInput->FindObject(name)); + if (!hist) { + lOfInput->ls(); if (this->doNotCrashOnNull) { LOG(info) << "Could not open histogram " << name << " from TList, will fill tables with dummy values"; } else { LOG(fatal) << "Could not open histogram " << name << " from TList"; } - return nullptr; } - // Clone to detach from TFile directory so we can safely close the file - auto hist = static_cast(obj->Clone(Form("%s_clone", name))); - hist->SetDirectory(nullptr); + hist->SetDirectory(0); return hist; }; - if (fillFt0M) { h1dFT0M = getHist("h1dFT0M"); } @@ -161,46 +156,39 @@ struct McCentrality { if (fillFt0C) { h1dFT0C = getHist("h1dFT0C"); } - - // Safely close the file to prevent memory leaks - if (f) { - f->Close(); - delete f; - } } + // Full tables (independent on central calibrations) void process(aod::McCollision const& /*mcCollision*/, aod::McParticles const& mcParticles) { const float nFT0A = mCounter.countFT0A(mcParticles); const float nFT0C = mCounter.countFT0C(mcParticles); const float nFT0M = nFT0A + nFT0C; + // const float nFV0A = mCounter.countFV0A(mcParticles); if (fillFt0M) { float valueCentFT0M = 105.0f; - if (h1dFT0M) { + if (h1dFT0M) valueCentFT0M = h1dFT0M->GetBinContent(h1dFT0M->FindBin(nFT0M)); - } centFT0M(valueCentFT0M); histos.fill(HIST("FT0M/percentile"), valueCentFT0M); histos.fill(HIST("FT0M/percentilevsMult"), valueCentFT0M, nFT0M); } - if (fillFt0A) { float valueCentFT0A = 105.0f; - if (h1dFT0A) { + if (h1dFT0A) valueCentFT0A = h1dFT0A->GetBinContent(h1dFT0A->FindBin(nFT0A)); - } centFT0A(valueCentFT0A); } - if (fillFt0C) { float valueCentFT0C = 105.0f; - if (h1dFT0C) { + if (h1dFT0C) valueCentFT0C = h1dFT0C->GetBinContent(h1dFT0C->FindBin(nFT0C)); - } centFT0C(valueCentFT0C); } + // const float valueCentFV0A = h1dFT0M->GetBinContent(h1dFT0M->FindBin(nFV0A)); + // centFV0A(valueCentFV0A); } }; From 1234d5aa911ca547f607d580a1b1979179b30109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Wed, 13 May 2026 16:47:14 +0200 Subject: [PATCH 3/4] Add missing TH1.h include to mcCentrality.cxx --- PWGLF/TableProducer/Common/mcCentrality.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PWGLF/TableProducer/Common/mcCentrality.cxx b/PWGLF/TableProducer/Common/mcCentrality.cxx index 76dd80def99..283f7a63ef1 100644 --- a/PWGLF/TableProducer/Common/mcCentrality.cxx +++ b/PWGLF/TableProducer/Common/mcCentrality.cxx @@ -34,8 +34,8 @@ #include #include -#include #include +#include #include #include From d6cb94710d93ce8833ee86d18b195480c767fd58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Wed, 13 May 2026 16:49:12 +0200 Subject: [PATCH 4/4] Refactor FT0M, FT0A, and FT0C centrality calculations Refactor centrality calculation to use conditional initialization for percentile values. --- PWGLF/TableProducer/Common/mcCentrality.cxx | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/PWGLF/TableProducer/Common/mcCentrality.cxx b/PWGLF/TableProducer/Common/mcCentrality.cxx index 283f7a63ef1..a55ac09ef44 100644 --- a/PWGLF/TableProducer/Common/mcCentrality.cxx +++ b/PWGLF/TableProducer/Common/mcCentrality.cxx @@ -168,24 +168,22 @@ struct McCentrality { // const float nFV0A = mCounter.countFV0A(mcParticles); if (fillFt0M) { - float valueCentFT0M = 105.0f; - if (h1dFT0M) - valueCentFT0M = h1dFT0M->GetBinContent(h1dFT0M->FindBin(nFT0M)); + const float valueCentFT0M = h1dFT0M ? h1dFT0M->GetBinContent(h1dFT0M->FindBin(nFT0M)) : 105.0f; centFT0M(valueCentFT0M); histos.fill(HIST("FT0M/percentile"), valueCentFT0M); histos.fill(HIST("FT0M/percentilevsMult"), valueCentFT0M, nFT0M); } if (fillFt0A) { - float valueCentFT0A = 105.0f; - if (h1dFT0A) - valueCentFT0A = h1dFT0A->GetBinContent(h1dFT0A->FindBin(nFT0A)); + const float valueCentFT0A = h1dFT0A ? h1dFT0A->GetBinContent(h1dFT0A->FindBin(nFT0A)) : 105.0f; centFT0A(valueCentFT0A); + histos.fill(HIST("FT0A/percentile"), valueCentFT0A); + histos.fill(HIST("FT0A/percentilevsMult"), valueCentFT0A, nFT0A); } if (fillFt0C) { - float valueCentFT0C = 105.0f; - if (h1dFT0C) - valueCentFT0C = h1dFT0C->GetBinContent(h1dFT0C->FindBin(nFT0C)); + const float valueCentFT0C = h1dFT0C ? h1dFT0C->GetBinContent(h1dFT0C->FindBin(nFT0C)) : 105.0f; centFT0C(valueCentFT0C); + histos.fill(HIST("FT0C/percentile"), valueCentFT0C); + histos.fill(HIST("FT0C/percentilevsMult"), valueCentFT0C, nFT0C); } // const float valueCentFV0A = h1dFT0M->GetBinContent(h1dFT0M->FindBin(nFV0A)); // centFV0A(valueCentFV0A);