Skip to content

Commit 1166655

Browse files
authored
[PWGHF] Remove unnecessary gen bkg histos and add configurable to fill or not reco bkg histos (#9506)
1 parent 2b8976b commit 1166655

File tree

2 files changed

+41
-51
lines changed

2 files changed

+41
-51
lines changed

PWGHF/D2H/Tasks/taskDplus.cxx

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct HfTaskDplus {
5050
Configurable<std::vector<int>> classMl{"classMl", {0, 1, 2}, "Indexes of ML scores to be stored. Three indexes max."};
5151
Configurable<bool> storeCentrality{"storeCentrality", false, "Flag to store centrality information"};
5252
Configurable<bool> storeOccupancy{"storeOccupancy", false, "Flag to store occupancy information"};
53+
Configurable<bool> fillMcBkgHistos{"fillMcBkgHistos", false, "Flag to fill and store histograms for MC background"};
5354

5455
HfHelper hfHelper;
5556

@@ -200,7 +201,9 @@ struct HfTaskDplus {
200201
}
201202
registry.add("hSparseMassPrompt", "THn for Dplus Prompt", HistType::kTHnSparseF, axes);
202203
registry.add("hSparseMassFD", "THn for Dplus FD", HistType::kTHnSparseF, axesFD);
203-
registry.add("hSparseMassBkg", "THn for Dplus Bkg", HistType::kTHnSparseF, axes);
204+
if (fillMcBkgHistos) {
205+
registry.add("hSparseMassBkg", "THn for Dplus Bkg", HistType::kTHnSparseF, axes);
206+
}
204207
registry.add("hSparseMassNotMatched", "THn for Dplus not matched", HistType::kTHnSparseF, axes);
205208
registry.add("hSparseMassGenPrompt", "THn for gen Prompt Dplus", HistType::kTHnSparseF, axesGenPrompt);
206209
registry.add("hSparseMassGenFD", "THn for gen FD Dplus", HistType::kTHnSparseF, axesGenFD);
@@ -282,15 +285,16 @@ struct HfTaskDplus {
282285
}
283286

284287
} else { // Bkg
285-
286-
if (storeCentrality && storeOccupancy) {
287-
registry.fill(HIST("hSparseMassBkg"), hfHelper.invMassDplusToPiKPi(candidate), candidate.pt(), outputMl[0], outputMl[1], outputMl[2], centrality, occupancy);
288-
} else if (storeCentrality && !storeOccupancy) {
289-
registry.fill(HIST("hSparseMassBkg"), hfHelper.invMassDplusToPiKPi(candidate), candidate.pt(), outputMl[0], outputMl[1], outputMl[2], centrality);
290-
} else if (!storeCentrality && storeOccupancy) {
291-
registry.fill(HIST("hSparseMassBkg"), hfHelper.invMassDplusToPiKPi(candidate), candidate.pt(), outputMl[0], outputMl[1], outputMl[2], occupancy);
292-
} else {
293-
registry.fill(HIST("hSparseMassBkg"), hfHelper.invMassDplusToPiKPi(candidate), candidate.pt(), outputMl[0], outputMl[1], outputMl[2]);
288+
if (fillMcBkgHistos) {
289+
if (storeCentrality && storeOccupancy) {
290+
registry.fill(HIST("hSparseMassBkg"), hfHelper.invMassDplusToPiKPi(candidate), candidate.pt(), outputMl[0], outputMl[1], outputMl[2], centrality, occupancy);
291+
} else if (storeCentrality && !storeOccupancy) {
292+
registry.fill(HIST("hSparseMassBkg"), hfHelper.invMassDplusToPiKPi(candidate), candidate.pt(), outputMl[0], outputMl[1], outputMl[2], centrality);
293+
} else if (!storeCentrality && storeOccupancy) {
294+
registry.fill(HIST("hSparseMassBkg"), hfHelper.invMassDplusToPiKPi(candidate), candidate.pt(), outputMl[0], outputMl[1], outputMl[2], occupancy);
295+
} else {
296+
registry.fill(HIST("hSparseMassBkg"), hfHelper.invMassDplusToPiKPi(candidate), candidate.pt(), outputMl[0], outputMl[1], outputMl[2]);
297+
}
294298
}
295299
}
296300
} else {
@@ -482,11 +486,13 @@ struct HfTaskDplus {
482486
fillHistoMCRec<true>(candidate);
483487
}
484488
// Bkg
485-
for (const auto& candidate : recoBkgCandidates) {
486-
if ((yCandRecoMax >= 0. && std::abs(hfHelper.yDplus(candidate)) > yCandRecoMax)) {
487-
continue;
489+
if (fillMcBkgHistos) {
490+
for (const auto& candidate : recoBkgCandidates) {
491+
if ((yCandRecoMax >= 0. && std::abs(hfHelper.yDplus(candidate)) > yCandRecoMax)) {
492+
continue;
493+
}
494+
fillHistoMCRec<false>(candidate);
488495
}
489-
fillHistoMCRec<false>(candidate);
490496
}
491497
} else {
492498
for (const auto& candidate : recoDPlusCandidatesWithMl) {
@@ -513,19 +519,21 @@ struct HfTaskDplus {
513519
// Bkg
514520
ptBhad = -1;
515521
flagBHad = -1;
516-
for (const auto& candidate : recoBkgCandidatesWithMl) {
517-
if ((yCandRecoMax >= 0. && std::abs(hfHelper.yDplus(candidate)) > yCandRecoMax)) {
518-
continue;
519-
}
520-
auto collision = candidate.template collision_as<McRecoCollisionsCent>();
521-
if (storeCentrality && centEstimator != CentralityEstimator::None) {
522-
cent = getCentralityColl(collision, centEstimator);
523-
}
524-
if (storeOccupancy && occEstimator != OccupancyEstimator::None) {
525-
occ = getOccupancyColl(collision, occEstimator);
522+
if (fillMcBkgHistos) {
523+
for (const auto& candidate : recoBkgCandidatesWithMl) {
524+
if ((yCandRecoMax >= 0. && std::abs(hfHelper.yDplus(candidate)) > yCandRecoMax)) {
525+
continue;
526+
}
527+
auto collision = candidate.template collision_as<McRecoCollisionsCent>();
528+
if (storeCentrality && centEstimator != CentralityEstimator::None) {
529+
cent = getCentralityColl(collision, centEstimator);
530+
}
531+
if (storeOccupancy && occEstimator != OccupancyEstimator::None) {
532+
occ = getOccupancyColl(collision, occEstimator);
533+
}
534+
fillHistoMCRec<false>(candidate);
535+
fillSparseML<true, false>(candidate, ptBhad, flagBHad, cent, occ);
526536
}
527-
fillHistoMCRec<false>(candidate);
528-
fillSparseML<true, false>(candidate, ptBhad, flagBHad, cent, occ);
529537
}
530538
}
531539
}

PWGHF/D2H/Tasks/taskDs.cxx

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct HfTaskDs {
8080
Configurable<bool> fillPercentiles{"fillPercentiles", true, "Wheter to fill multiplicity axis with percentiles or raw information"};
8181
Configurable<bool> storeOccupancy{"storeOccupancy", false, "Flag to store occupancy information"};
8282
Configurable<int> occEstimator{"occEstimator", 0, "Occupancy estimation (None: 0, ITS: 1, FT0C: 2)"};
83+
Configurable<bool> fillMcBkgHistos{"fillMcBkgHistos", false, "Flag to fill and store histograms for MC background"};
8384

8485
struct : ConfigurableGroup {
8586
Configurable<std::string> ccdburl{"ccdburl", "http://alice-ccdb.cern.ch", "The CCDB endpoint url address"};
@@ -184,7 +185,6 @@ struct HfTaskDs {
184185
std::vector<AxisSpec> axesWithNpvMl = {massbins, ptbins, centralitybins, npvcontributorsbins, mlscore0bins, mlscore1bins, mlscore2bins};
185186
std::vector<AxisSpec> axesGenPrompt = {ptbins, ybins, npvcontributorsbins, centralitybins};
186187
std::vector<AxisSpec> axesGenFd = {ptbins, ybins, npvcontributorsbins, ptBHad, flagBHad, centralitybins};
187-
std::vector<AxisSpec> axesGenBkg = {ptbins, ybins, npvcontributorsbins, centralitybins};
188188

189189
if (storeOccupancy) {
190190
axes.insert(axes.end(), {occupancybins});
@@ -195,7 +195,6 @@ struct HfTaskDs {
195195
axesWithNpvMl.insert(axesWithNpvMl.end(), {occupancybins});
196196
axesGenPrompt.insert(axesGenPrompt.end(), {occupancybins});
197197
axesGenFd.insert(axesGenFd.end(), {occupancybins});
198-
axesGenBkg.insert(axesGenBkg.end(), {occupancybins});
199198
}
200199

201200
for (auto i = 0; i < DataType::kDataTypes; ++i) {
@@ -208,6 +207,10 @@ struct HfTaskDs {
208207
histosPtr[i]["hSparseMass"] = registry.add<THnSparse>((folders[i] + "hSparseMass").c_str(), "THn for Ds", HistType::kTHnSparseF, axesWithNpv);
209208
}
210209
} else if (doprocessDataWithMlAndCentFT0C || doprocessDataWithMlAndCentFT0M || doprocessDataWithMlAndCentNTracksPV || doprocessDataWithMl || doprocessMcWithMlAndCentFT0C || doprocessMcWithMlAndCentFT0M || doprocessMcWithMlAndCentNTracksPV || doprocessMcWithMl) {
210+
if (i == DataType::McBkg && !fillMcBkgHistos) {
211+
continue;
212+
}
213+
211214
if (i == DataType::Data) { // If data do not fill PV contributors in sparse
212215
histosPtr[i]["hSparseMass"] = registry.add<THnSparse>((folders[i] + "hSparseMass").c_str(), "THn for Ds", HistType::kTHnSparseF, axesMl);
213216
} else if (i == DataType::McDsNonPrompt) { // If data do not fill PV contributors in sparse
@@ -263,9 +266,6 @@ struct HfTaskDs {
263266
if (i == DataType::McDsNonPrompt || i == DataType::McDplusNonPrompt) {
264267
histosPtr[i]["hSparseGen"] = registry.add<THnSparse>((folders[i] + "hSparseGen").c_str(), "Thn for generated nonprompt candidates", HistType::kTHnSparseF, axesGenFd);
265268
}
266-
if (i == DataType::McBkg) {
267-
histosPtr[i]["hSparseGen"] = registry.add<THnSparse>((folders[i] + "hSparseGen").c_str(), "Thn for non-matched generated candidates", HistType::kTHnSparseF, axesGenBkg);
268-
}
269269
}
270270
}
271271
}
@@ -647,7 +647,7 @@ struct HfTaskDs {
647647
break;
648648
}
649649
}
650-
if (isBkg) {
650+
if (isBkg && fillMcBkgHistos) {
651651
if (yCandRecoMax >= 0. && std::abs(hfHelper.yDs(candidate)) > yCandRecoMax) {
652652
return;
653653
}
@@ -671,12 +671,11 @@ struct HfTaskDs {
671671
void fillMcGenHistosSparse(CandDsMcGen const& mcParticles,
672672
Coll const& recoCollisions)
673673
{
674-
675674
// MC gen.
676675
for (const auto& particle : mcParticles) {
677-
const auto& recoCollsPerMcColl = recoCollisions.sliceBy(colPerMcCollision, particle.mcCollision().globalIndex());
678676

679677
if (std::abs(particle.flagMcMatchGen()) == 1 << aod::hf_cand_3prong::DecayType::DsToKKPi) {
678+
const auto& recoCollsPerMcColl = recoCollisions.sliceBy(colPerMcCollision, particle.mcCollision().globalIndex());
680679
if (particle.flagMcDecayChanGen() == decayChannel || (fillDplusMc && particle.flagMcDecayChanGen() == (decayChannel + offsetDplusDecayChannel))) {
681680
auto pt = particle.pt();
682681
double y{0.f};
@@ -746,23 +745,6 @@ struct HfTaskDs {
746745
}
747746
}
748747
}
749-
} else { // not matched candidates
750-
auto pt = particle.pt();
751-
double y = RecoDecay::y(particle.pVector(), o2::constants::physics::MassDS);
752-
unsigned maxNumContrib = 0;
753-
for (const auto& recCol : recoCollsPerMcColl) {
754-
maxNumContrib = recCol.numContrib() > maxNumContrib ? recCol.numContrib() : maxNumContrib;
755-
}
756-
float cent = o2::hf_centrality::getCentralityGenColl(recoCollsPerMcColl);
757-
float occ{-1.};
758-
if (storeOccupancy && occEstimator != o2::hf_occupancy::OccupancyEstimator::None) {
759-
occ = o2::hf_occupancy::getOccupancyGenColl(recoCollsPerMcColl, occEstimator);
760-
}
761-
if (storeOccupancy && occEstimator != o2::hf_occupancy::OccupancyEstimator::None) {
762-
std::get<THnSparsePtr>(histosPtr[DataType::McBkg]["hSparseGen"])->Fill(pt, y, maxNumContrib, cent, occ);
763-
} else {
764-
std::get<THnSparsePtr>(histosPtr[DataType::McBkg]["hSparseGen"])->Fill(pt, y, maxNumContrib, cent);
765-
}
766748
}
767749
}
768750
}

0 commit comments

Comments
 (0)