diff --git a/PWGHF/Utils/utilsEvSelHf.h b/PWGHF/Utils/utilsEvSelHf.h index b3c2e4afefa..fcf4c389fe0 100644 --- a/PWGHF/Utils/utilsEvSelHf.h +++ b/PWGHF/Utils/utilsEvSelHf.h @@ -216,6 +216,13 @@ struct HfEventSelection : o2::framework::ConfigurableGroup { ctpRateFetcher irFetcher; std::string irSourceForCptFetcher; + // guard variable to guarantee full configuration + // important for RCT, Zorro + bool isInitCalled{false}; + + // guard variable to guarantee that histograms are added to the registry before filling them + bool areHistosInRegistry{false}; + /// Set standard preselection gap trigger (values taken from UD group) SGCutParHolder setSgPreselection() { @@ -250,6 +257,10 @@ struct HfEventSelection : o2::framework::ConfigurableGroup { hCollisionsCentOcc = registry.add(NameHistCollisionsCentOcc, "selected events;Centrality; Occupancy", {o2::framework::HistType::kTH2D, {th2AxisCent, th2AxisOccupancy}}); hCollisionsCentIR = registry.add(NameHistCollisionsCentIR, "selected events;Centrality; Interaction Rate [Hz]", {o2::framework::HistType::kTH2D, {th2AxisCent, th2AxisInteractionRate}}); + + // histograms in registry + // let's update the guard variable + areHistosInRegistry = true; } /// \brief Inits the HF event selection object @@ -277,6 +288,9 @@ struct HfEventSelection : o2::framework::ConfigurableGroup { if (!irSource.value.empty()) { irSourceForCptFetcher = irSource.value; } + + // full configuration complete: update the guard variable + isInitCalled = true; } /// \brief Applies event selection. @@ -304,8 +318,14 @@ struct HfEventSelection : o2::framework::ConfigurableGroup { if constexpr (UseEvSel) { /// RCT condition - if (requireGoodRct && !rctChecker.checkTable(collision)) { - SETBIT(rejectionMask, EventRejection::Rct); + if (requireGoodRct) { + if (!isInitCalled) { + // protect against incomplete configuration + LOG(fatal) << "Checking RCT flags w/o full HF event-selection configuration. Call the function HfEventSelection::init() to fix."; + } + if (!rctChecker.checkTable(collision)) { + SETBIT(rejectionMask, EventRejection::Rct); + } } /// trigger condition if ((useSel8Trigger && !collision.sel8()) || (!useSel8Trigger && triggerClass > -1 && !collision.alias_bit(triggerClass))) { @@ -368,6 +388,10 @@ struct HfEventSelection : o2::framework::ConfigurableGroup { } if (!softwareTrigger.value.empty()) { + if (!isInitCalled) { + // protect against incomplete configuration + LOG(fatal) << "Using Zorro utility w/o full HF event-selection configuration. Call the function HfEventSelection::init() to fix."; + } // we might have to update it from CCDB const auto bc = collision.template bc_as(); const auto runNumber = bc.runNumber(); @@ -428,6 +452,11 @@ struct HfEventSelection : o2::framework::ConfigurableGroup { const float occupancy = -1.f, const float ir = -1.f) { + if (!areHistosInRegistry) { + // protect against missing histograms in registry + LOG(fatal) << "You are trying to fill histograms, but they are not in the histogram registry. Call the function HfEventSelection::addHistograms() to fix."; + } + hCollisions->Fill(EventRejection::None); const auto posZ = collision.posZ(); hPosZBeforeEvSel->Fill(posZ); @@ -480,6 +509,8 @@ struct HfEventSelectionMc { std::string rctLabel; // RCT selection flag bool rctCheckZDC{false}; // require ZDC from RCT bool rctTreatLimitedAcceptanceAsBad{false}; // RCT flag to reject events with limited acceptance for selected detectors + bool isInitCalled{false}; // guard variable to guarantee full configuration, important for RCT + bool areHistosInRegistry{false}; // guard variable to guarantee that histograms are added to the registry before filling them // util to retrieve the RCT info from CCDB o2::aod::rctsel::RCTFlagsChecker rctChecker; @@ -505,6 +536,10 @@ struct HfEventSelectionMc { hGenCollisions = registry.add(NameHistGenCollisions, "HF event counter;;# of accepted collisions", {o2::framework::HistType::kTH1D, {axisEvents}}); // Puts labels on the collision monitoring histogram. setEventRejectionLabels(hGenCollisions); + + // histograms in registry + // let's update the guard variable + areHistosInRegistry = true; } /// \brief Configures the object from the reco workflow @@ -557,6 +592,9 @@ struct HfEventSelectionMc { // we initialise histograms addHistograms(registry); + + // full configuration complete: update the guard variable + isInitCalled = true; } /// \brief Function to apply event selections to generated MC collisions @@ -583,6 +621,10 @@ struct HfEventSelectionMc { /// RCT condition if (requireGoodRct) { + if (!isInitCalled) { + // protect against incomplete configuration + LOG(fatal) << "Checking RCT flags w/o full HF event-selection configuration (MC). Call the function HfEventSelectionMc::init() to fix."; + } if (!rctChecker.checkTable(bc)) { SETBIT(rejectionMask, EventRejection::Rct); } @@ -619,6 +661,11 @@ struct HfEventSelectionMc { const HfCollisionRejectionMask rejectionMask, const int nSplitColl = 0) { + if (!areHistosInRegistry) { + // protect against missing histograms in registry + LOG(fatal) << "You are trying to fill histograms, but they are not in the histogram registry. Call the function HfEventSelectionMc::addHistograms() to fix."; + } + hGenCollisions->Fill(EventRejection::None); if constexpr (CentEstimator == o2::hf_centrality::CentralityEstimator::FT0M) {