Skip to content

Commit 2ddea00

Browse files
authored
Refactor histogram registration and filling logic
1 parent 1c2bc09 commit 2ddea00

File tree

1 file changed

+49
-33
lines changed

1 file changed

+49
-33
lines changed

ALICE3/Tasks/alice3HfTask3Prong.cxx

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,16 @@ struct Alice3HfTask3Prong {
171171
addHistogramsGen("hMass", "inv. mass (p K #pi) (GeV/#it{c}^{2})", "", {HistType::kTH1F, {{600, 1.98, 2.58}}});
172172

173173
/// selection status
174-
registry.add("hSelectionStatus", "3-prong cands;selection status;entries", {HistType::kTH2F, {{5, -0.5, 4.5}, {vbins, "#it{p}_{T} (GeV/#it{c})"}}});
175-
registry.add("hCandidateCounter", "Candidate counter;entries", {HistType::kTH1D, {{1, -0.5, 0.5}}});
174+
auto h2 = registry.add<TH2>("hSelectionStatus", "3-prong cands;selection status;entries", {HistType::kTH2F, {{5, -0.5, 4.5}, {vbins, "#it{p}_{T} (GeV/#it{c})"}}});
175+
h2->GetXaxis()->SetBinLabel(1, "mass hypo 0");
176+
h2->GetXaxis()->SetBinLabel(2, "mass hypo 1");
177+
auto h = registry.add<TH1>("MC/rec/hCandidateCounter", "Candidate counter;entries", {HistType::kTH1D, {{2, -0.5, 1.5}}});
178+
h->GetXaxis()->SetBinLabel(1, "Calls");
179+
h->GetXaxis()->SetBinLabel(2, "Candidates");
176180
// Number of events processed
177-
registry.add("hNEventsProcessed", "number of events processed;entries;", {HistType::kTH1F, {{2, 0.5, 2.5}}});
178-
registry.get<TH1>(HIST("hNEventsProcessed"))->GetXaxis()->SetBinLabel(1, "Generated");
179-
registry.get<TH1>(HIST("hNEventsProcessed"))->GetXaxis()->SetBinLabel(2, "Reconstructed");
181+
h = registry.add<TH1>("hNEventsProcessed", "number of events processed;entries;", {HistType::kTH1F, {{2, 0.5, 2.5}}});
182+
h->GetXaxis()->SetBinLabel(1, "Generated");
183+
h->GetXaxis()->SetBinLabel(2, "Reconstructed");
180184

181185
if (fillThn) {
182186
const AxisSpec thnAxisMass{thnConfigAxisMass, "inv. mass (p K #pi) (GeV/#it{c}^{2})"};
@@ -254,15 +258,27 @@ struct Alice3HfTask3Prong {
254258
/// \tparam SaveMl indicates whether ML scores are saved in the THnSparse
255259
/// \tparam CandsRec is the type of the reconstructed candidates collection
256260
/// \param candidates is the collection of reconstructed candidates
257-
template <CharmHadAlice3 CharmHad, bool SaveMl, typename CandsRec>
258-
void fillHistosMcRec(CandsRec const& candidates)
261+
template <CharmHadAlice3 CharmHad, bool SaveMl, typename CandsRec, typename AllParticles>
262+
void fillHistosMcRec(CandsRec const& candidates, AllParticles const& allParticles)
259263
{
264+
registry.fill(HIST("MC/rec/hCandidateCounter"), 0.);
260265
for (const auto& candidate : candidates) {
261-
registry.fill(HIST("hCandidateCounter"), 0.);
266+
registry.fill(HIST("MC/rec/hCandidateCounter"), 1.);
262267
/// rapidity selection
263268
if (yCandRecoMax >= 0. && std::abs(hfHelper.getCandY<CharmHad>(candidate)) > yCandRecoMax) {
264269
continue;
265270
}
271+
auto mcParticle = allParticles.iteratorAt(candidate.particleMcRec());
272+
if (candidate.particleMcRec() > 0) {
273+
if (mcParticle.has_daughters()) {
274+
auto daughters = mcParticle.daughtersIds();
275+
LOG(info) << "Reco candidate matched to MC particle with PDG " << mcParticle.pdgCode() << " daughters: " << daughters.size();
276+
for (auto dauId : daughters) {
277+
auto dau = allParticles.iteratorAt(dauId);
278+
LOG(info) << " dauId: " << dauId << " PDG: " << dau.pdgCode();
279+
}
280+
}
281+
}
266282

267283
if (candidate.flagMcRec() != 0) {
268284
// Get the corresponding MC particle.
@@ -274,11 +290,11 @@ struct Alice3HfTask3Prong {
274290
registry.fill(HIST("hSelectionStatus"), 0., pt);
275291
double mass = hfHelper.getCandMass<CharmHad, false>(candidate);
276292
/// Fill histograms
277-
fillHistogramsRecSig<CharmHad, Signal>(candidate, mass);
293+
fillHistogramsRecSig<CharmHad, Signal>(candidate, mass, false);
278294
if (originType == RecoDecay::OriginType::Prompt) {
279-
fillHistogramsRecSig<CharmHad, Prompt>(candidate, mass);
295+
fillHistogramsRecSig<CharmHad, Prompt>(candidate, mass, false);
280296
} else if (originType == RecoDecay::OriginType::NonPrompt) {
281-
fillHistogramsRecSig<CharmHad, NonPrompt>(candidate, mass);
297+
fillHistogramsRecSig<CharmHad, NonPrompt>(candidate, mass, false);
282298
}
283299
if (fillThn) {
284300
std::vector<double> valuesToFill{mass, pt};
@@ -291,27 +307,27 @@ struct Alice3HfTask3Prong {
291307
valuesToFill.push_back(static_cast<double>(originType));
292308
registry.get<THnSparse>(HIST("hSparseRec"))->Fill(valuesToFill.data());
293309
}
294-
if (candidate.isSelMassHypo1()) {
295-
registry.fill(HIST("hSelectionStatus"), 1., pt);
296-
double mass = hfHelper.getCandMass<CharmHad, true>(candidate);
297-
/// Fill histograms
298-
fillHistogramsRecSig<CharmHad, Signal>(candidate, mass, true);
299-
if (originType == RecoDecay::OriginType::Prompt) {
300-
fillHistogramsRecSig<CharmHad, Prompt>(candidate, mass, true);
301-
} else if (originType == RecoDecay::OriginType::NonPrompt) {
302-
fillHistogramsRecSig<CharmHad, NonPrompt>(candidate, mass, true);
303-
}
304-
if (fillThn) {
305-
std::vector<double> valuesToFill{mass, pt};
306-
if constexpr (SaveMl) {
307-
LOGP(fatal, "Trying to access ML scores, but SaveMl is false!");
308-
valuesToFill.push_back(candidate.mlScore0());
309-
valuesToFill.push_back(candidate.mlScore1());
310-
valuesToFill.push_back(candidate.mlScore2());
311-
}
312-
valuesToFill.push_back(static_cast<double>(originType));
313-
registry.get<THnSparse>(HIST("hSparseRec"))->Fill(valuesToFill.data());
310+
}
311+
if (candidate.isSelMassHypo1()) {
312+
registry.fill(HIST("hSelectionStatus"), 1., pt);
313+
double mass = hfHelper.getCandMass<CharmHad, true>(candidate);
314+
/// Fill histograms
315+
fillHistogramsRecSig<CharmHad, Signal>(candidate, mass, true);
316+
if (originType == RecoDecay::OriginType::Prompt) {
317+
fillHistogramsRecSig<CharmHad, Prompt>(candidate, mass, true);
318+
} else if (originType == RecoDecay::OriginType::NonPrompt) {
319+
fillHistogramsRecSig<CharmHad, NonPrompt>(candidate, mass, true);
320+
}
321+
if (fillThn) {
322+
std::vector<double> valuesToFill{mass, pt};
323+
if constexpr (SaveMl) {
324+
LOGP(fatal, "Trying to access ML scores, but SaveMl is false!");
325+
valuesToFill.push_back(candidate.mlScore0());
326+
valuesToFill.push_back(candidate.mlScore1());
327+
valuesToFill.push_back(candidate.mlScore2());
314328
}
329+
valuesToFill.push_back(static_cast<double>(originType));
330+
registry.get<THnSparse>(HIST("hSparseRec"))->Fill(valuesToFill.data());
315331
}
316332
}
317333
}
@@ -410,15 +426,15 @@ struct Alice3HfTask3Prong {
410426
collision.posX(); // to avoid unused variable warning
411427
registry.fill(HIST("hNEventsProcessed"), 2.); // Reconstructed
412428
}
413-
fillHistosMcRec<CharmHadAlice3::Lc, false>(candsLc);
429+
fillHistosMcRec<CharmHadAlice3::Lc, false>(candsLc, mcParticles);
414430
fillHistosMcGen<CharmHadAlice3::Lc>(candsGenLcs, mcParticles);
415431
}
416432
PROCESS_SWITCH(Alice3HfTask3Prong, processLc, "Process Lc w/o ML sels", true);
417433

418434
void processLcWMl(Cands3PRecoWMl const& candsLcWMl,
419435
Cands3PGen const& mcParticles)
420436
{
421-
fillHistosMcRec<CharmHadAlice3::Lc, true>(candsLcWMl);
437+
fillHistosMcRec<CharmHadAlice3::Lc, true>(candsLcWMl, mcParticles);
422438
fillHistosMcGen<CharmHadAlice3::Lc>(candsGenLcs, mcParticles);
423439
}
424440
PROCESS_SWITCH(Alice3HfTask3Prong, processLcWMl, "Process Lc with ML sels", false);

0 commit comments

Comments
 (0)