Skip to content

Commit b2129c8

Browse files
authored
[PWGHF] Add protection against missing init in HF event selection. (#14298)
1 parent 209cdd6 commit b2129c8

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

PWGHF/Utils/utilsEvSelHf.h

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ struct HfEventSelection : o2::framework::ConfigurableGroup {
216216
ctpRateFetcher irFetcher;
217217
std::string irSourceForCptFetcher;
218218

219+
// guard variable to guarantee full configuration
220+
// important for RCT, Zorro
221+
bool isInitCalled{false};
222+
223+
// guard variable to guarantee that histograms are added to the registry before filling them
224+
bool areHistosInRegistry{false};
225+
219226
/// Set standard preselection gap trigger (values taken from UD group)
220227
SGCutParHolder setSgPreselection()
221228
{
@@ -250,6 +257,10 @@ struct HfEventSelection : o2::framework::ConfigurableGroup {
250257

251258
hCollisionsCentOcc = registry.add<TH2>(NameHistCollisionsCentOcc, "selected events;Centrality; Occupancy", {o2::framework::HistType::kTH2D, {th2AxisCent, th2AxisOccupancy}});
252259
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;
253264
}
254265

255266
/// \brief Inits the HF event selection object
@@ -277,6 +288,9 @@ struct HfEventSelection : o2::framework::ConfigurableGroup {
277288
if (!irSource.value.empty()) {
278289
irSourceForCptFetcher = irSource.value;
279290
}
291+
292+
// full configuration complete: update the guard variable
293+
isInitCalled = true;
280294
}
281295

282296
/// \brief Applies event selection.
@@ -304,8 +318,14 @@ struct HfEventSelection : o2::framework::ConfigurableGroup {
304318

305319
if constexpr (UseEvSel) {
306320
/// RCT condition
307-
if (requireGoodRct && !rctChecker.checkTable(collision)) {
308-
SETBIT(rejectionMask, EventRejection::Rct);
321+
if (requireGoodRct) {
322+
if (!isInitCalled) {
323+
// protect against incomplete configuration
324+
LOG(fatal) << "Checking RCT flags w/o full HF event-selection configuration. Call the function HfEventSelection::init() to fix.";
325+
}
326+
if (!rctChecker.checkTable(collision)) {
327+
SETBIT(rejectionMask, EventRejection::Rct);
328+
}
309329
}
310330
/// trigger condition
311331
if ((useSel8Trigger && !collision.sel8()) || (!useSel8Trigger && triggerClass > -1 && !collision.alias_bit(triggerClass))) {
@@ -368,6 +388,10 @@ struct HfEventSelection : o2::framework::ConfigurableGroup {
368388
}
369389

370390
if (!softwareTrigger.value.empty()) {
391+
if (!isInitCalled) {
392+
// protect against incomplete configuration
393+
LOG(fatal) << "Using Zorro utility w/o full HF event-selection configuration. Call the function HfEventSelection::init() to fix.";
394+
}
371395
// we might have to update it from CCDB
372396
const auto bc = collision.template bc_as<TBcs>();
373397
const auto runNumber = bc.runNumber();
@@ -428,6 +452,11 @@ struct HfEventSelection : o2::framework::ConfigurableGroup {
428452
const float occupancy = -1.f,
429453
const float ir = -1.f)
430454
{
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 HfEventSelection::addHistograms() to fix.";
458+
}
459+
431460
hCollisions->Fill(EventRejection::None);
432461
const auto posZ = collision.posZ();
433462
hPosZBeforeEvSel->Fill(posZ);
@@ -480,6 +509,8 @@ struct HfEventSelectionMc {
480509
std::string rctLabel; // RCT selection flag
481510
bool rctCheckZDC{false}; // require ZDC from RCT
482511
bool rctTreatLimitedAcceptanceAsBad{false}; // RCT flag to reject events with limited acceptance for selected detectors
512+
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
483514

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

510545
/// \brief Configures the object from the reco workflow
@@ -557,6 +592,9 @@ struct HfEventSelectionMc {
557592

558593
// we initialise histograms
559594
addHistograms(registry);
595+
596+
// full configuration complete: update the guard variable
597+
isInitCalled = true;
560598
}
561599

562600
/// \brief Function to apply event selections to generated MC collisions
@@ -583,6 +621,10 @@ struct HfEventSelectionMc {
583621

584622
/// RCT condition
585623
if (requireGoodRct) {
624+
if (!isInitCalled) {
625+
// protect against incomplete configuration
626+
LOG(fatal) << "Checking RCT flags w/o full HF event-selection configuration (MC). Call the function HfEventSelectionMc::init() to fix.";
627+
}
586628
if (!rctChecker.checkTable(bc)) {
587629
SETBIT(rejectionMask, EventRejection::Rct);
588630
}
@@ -619,6 +661,11 @@ struct HfEventSelectionMc {
619661
const HfCollisionRejectionMask rejectionMask,
620662
const int nSplitColl = 0)
621663
{
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+
622669
hGenCollisions->Fill(EventRejection::None);
623670

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

0 commit comments

Comments
 (0)