Skip to content

Commit bb42c89

Browse files
committed
Add guard variable also for histo filling.
1 parent 52c7cc3 commit bb42c89

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

PWGHF/Utils/utilsEvSelHf.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ struct HfEventSelection : o2::framework::ConfigurableGroup {
220220
// important for RCT, Zorro
221221
bool isInitCalled{false};
222222

223+
// guard variable to guarantee that histograms are added to the registry before filling them
224+
bool areHistosInRegistry{false};
225+
223226
/// Set standard preselection gap trigger (values taken from UD group)
224227
SGCutParHolder setSgPreselection()
225228
{
@@ -254,6 +257,10 @@ struct HfEventSelection : o2::framework::ConfigurableGroup {
254257

255258
hCollisionsCentOcc = registry.add<TH2>(NameHistCollisionsCentOcc, "selected events;Centrality; Occupancy", {o2::framework::HistType::kTH2D, {th2AxisCent, th2AxisOccupancy}});
256259
hCollisionsCentIR = registry.add<TH2>(NameHistCollisionsCentIR, "selected events;Centrality; Interaction Rate [Hz]", {o2::framework::HistType::kTH2D, {th2AxisCent, th2AxisInteractionRate}});
260+
261+
// histograms in registry
262+
// let's update the guard variable
263+
areHistosInRegistry = true;
257264
}
258265

259266
/// \brief Inits the HF event selection object
@@ -445,6 +452,11 @@ struct HfEventSelection : o2::framework::ConfigurableGroup {
445452
const float occupancy = -1.f,
446453
const float ir = -1.f)
447454
{
455+
if (!areHistosInRegistry) {
456+
// protect against missing histograms in registry
457+
LOG(fatal) << "You are trying to fill histograms, but they are not in the histogram registry. Call the function HfEventSelectionMc::addHistograms() to fix.";
458+
}
459+
448460
hCollisions->Fill(EventRejection::None);
449461
const auto posZ = collision.posZ();
450462
hPosZBeforeEvSel->Fill(posZ);
@@ -498,6 +510,7 @@ struct HfEventSelectionMc {
498510
bool rctCheckZDC{false}; // require ZDC from RCT
499511
bool rctTreatLimitedAcceptanceAsBad{false}; // RCT flag to reject events with limited acceptance for selected detectors
500512
bool isInitCalled{false}; // guard variable to guarantee full configuration, important for RCT
513+
bool areHistosInRegistry{false}; // guard variable to guarantee that histograms are added to the registry before filling them
501514

502515
// util to retrieve the RCT info from CCDB
503516
o2::aod::rctsel::RCTFlagsChecker rctChecker;
@@ -523,6 +536,10 @@ struct HfEventSelectionMc {
523536
hGenCollisions = registry.add<TH1>(NameHistGenCollisions, "HF event counter;;# of accepted collisions", {o2::framework::HistType::kTH1D, {axisEvents}});
524537
// Puts labels on the collision monitoring histogram.
525538
setEventRejectionLabels(hGenCollisions);
539+
540+
// histograms in registry
541+
// let's update the guard variable
542+
areHistosInRegistry = true;
526543
}
527544

528545
/// \brief Configures the object from the reco workflow
@@ -644,6 +661,11 @@ struct HfEventSelectionMc {
644661
const HfCollisionRejectionMask rejectionMask,
645662
const int nSplitColl = 0)
646663
{
664+
if (!areHistosInRegistry) {
665+
// protect against missing histograms in registry
666+
LOG(fatal) << "You are trying to fill histograms, but they are not in the histogram registry. Call the function HfEventSelectionMc::addHistograms() to fix.";
667+
}
668+
647669
hGenCollisions->Fill(EventRejection::None);
648670

649671
if constexpr (CentEstimator == o2::hf_centrality::CentralityEstimator::FT0M) {

0 commit comments

Comments
 (0)