Skip to content

Commit d773c16

Browse files
committed
incapsulate fill Gen THns and histograms into function
1 parent 07a9d2b commit d773c16

File tree

1 file changed

+23
-35
lines changed

1 file changed

+23
-35
lines changed

PWGHF/D2H/Tasks/taskLc.cxx

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -469,35 +469,23 @@ struct HfTaskLc {
469469
const float gamma = std::sqrt(1 + p2m * p2m); // mother's particle Lorentz factor
470470
const float properLifetime = mcDaughter0.vt() * NanoToPico / gamma; // from ns to ps * from lab time to proper time
471471

472-
registry.fill(HIST("MC/generated/signal/hPtGen"), ptGen);
473-
registry.fill(HIST("MC/generated/signal/hEtaGen"), particle.eta());
474-
registry.fill(HIST("MC/generated/signal/hYGen"), yGen);
475-
registry.fill(HIST("MC/generated/signal/hPhiGen"), particle.phi());
476-
registry.fill(HIST("MC/generated/signal/hEtaVsPtGen"), particle.eta(), ptGen);
477-
registry.fill(HIST("MC/generated/signal/hYVsPtGen"), yGen, ptGen);
478-
registry.fill(HIST("MC/generated/signal/hPhiVsPtGen"), particle.phi(), ptGen);
472+
auto fillHistogramsGen = [&](const std::string& signalFolder, const std::string& signalSuffix) {
473+
registry.fill(HIST(("MC/generated/" + signalFolder + "/hPtGen" + signalSuffix).c_str()), ptGen);
474+
registry.fill(HIST(("MC/generated/" + signalFolder + "/hEtaGen" + signalSuffix).c_str()), particle.eta());
475+
registry.fill(HIST(("MC/generated/" + signalFolder + "/hYGen" + signalSuffix).c_str()), yGen);
476+
registry.fill(HIST(("MC/generated/" + signalFolder + "/hPhiGen" + signalSuffix).c_str()), particle.phi());
477+
registry.fill(HIST(("MC/generated/" + signalFolder + "/hEtaVsPtGen" + signalSuffix).c_str()), particle.eta(), ptGen);
478+
registry.fill(HIST(("MC/generated/" + signalFolder + "/hYVsPtGen" + signalSuffix).c_str()), yGen, ptGen);
479+
registry.fill(HIST(("MC/generated/" + signalFolder + "/hPhiVsPtGen" + signalSuffix).c_str()), particle.phi(), ptGen);
480+
};
481+
482+
fillHistogramsGen("signal", "");
483+
484+
auto fillHistogramsAndTHnGen = [&](bool isPrompt) {
485+
ptGenB = isPrompt ? -1. : mcParticles.rawIteratorAt(particle.idxBhadMotherPart()).pt();
486+
const std::string signalFolder = isPrompt ? "prompt" : "nonprompt";
487+
const std::string signalSuffix = isPrompt ? "Prompt" : "NonPrompt";
479488

480-
if (particle.originMcGen() == RecoDecay::OriginType::Prompt) {
481-
if (fillTHn) {
482-
std::vector<double> valuesToFill{ptGen, cent, yGen, static_cast<double>(numPvContributors), ptGenB, static_cast<double>(originType)};
483-
if (storeOccupancy && occEstimator != o2::hf_occupancy::OccupancyEstimator::None) {
484-
valuesToFill.push_back(occ);
485-
}
486-
if (storeProperLifetime) {
487-
valuesToFill.push_back(properLifetime);
488-
}
489-
registry.get<THnSparse>(HIST("hnLcVarsGen"))->Fill(valuesToFill.data());
490-
}
491-
registry.fill(HIST("MC/generated/prompt/hPtGenPrompt"), ptGen);
492-
registry.fill(HIST("MC/generated/prompt/hEtaGenPrompt"), particle.eta());
493-
registry.fill(HIST("MC/generated/prompt/hYGenPrompt"), yGen);
494-
registry.fill(HIST("MC/generated/prompt/hPhiGenPrompt"), particle.phi());
495-
registry.fill(HIST("MC/generated/prompt/hEtaVsPtGenPrompt"), particle.eta(), ptGen);
496-
registry.fill(HIST("MC/generated/prompt/hYVsPtGenPrompt"), yGen, ptGen);
497-
registry.fill(HIST("MC/generated/prompt/hPhiVsPtGenPrompt"), particle.phi(), ptGen);
498-
}
499-
if (particle.originMcGen() == RecoDecay::OriginType::NonPrompt) {
500-
ptGenB = mcParticles.rawIteratorAt(particle.idxBhadMotherPart()).pt();
501489
if (fillTHn) {
502490
std::vector<double> valuesToFill{ptGen, cent, yGen, static_cast<double>(numPvContributors), ptGenB, static_cast<double>(originType)};
503491
if (storeOccupancy && occEstimator != o2::hf_occupancy::OccupancyEstimator::None) {
@@ -508,13 +496,13 @@ struct HfTaskLc {
508496
}
509497
registry.get<THnSparse>(HIST("hnLcVarsGen"))->Fill(valuesToFill.data());
510498
}
511-
registry.fill(HIST("MC/generated/nonprompt/hPtGenNonPrompt"), ptGen);
512-
registry.fill(HIST("MC/generated/nonprompt/hEtaGenNonPrompt"), particle.eta());
513-
registry.fill(HIST("MC/generated/nonprompt/hYGenNonPrompt"), yGen);
514-
registry.fill(HIST("MC/generated/nonprompt/hPhiGenNonPrompt"), particle.phi());
515-
registry.fill(HIST("MC/generated/nonprompt/hEtaVsPtGenNonPrompt"), particle.eta(), ptGen);
516-
registry.fill(HIST("MC/generated/nonprompt/hYVsPtGenNonPrompt"), yGen, ptGen);
517-
registry.fill(HIST("MC/generated/nonprompt/hPhiVsPtGenNonPrompt"), particle.phi(), ptGen);
499+
fillHistogramsGen(signalFolder, signalSuffix);
500+
};
501+
502+
if (particle.originMcGen() == RecoDecay::OriginType::Prompt) {
503+
fillHistogramsAndTHnGen(true);
504+
} else if (particle.originMcGen() == RecoDecay::OriginType::NonPrompt) {
505+
fillHistogramsAndTHnGen(false);
518506
}
519507
}
520508
}

0 commit comments

Comments
 (0)