Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions PWGHF/Utils/utilsEvSelHf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -250,6 +257,10 @@ struct HfEventSelection : o2::framework::ConfigurableGroup {

hCollisionsCentOcc = registry.add<TH2>(NameHistCollisionsCentOcc, "selected events;Centrality; Occupancy", {o2::framework::HistType::kTH2D, {th2AxisCent, th2AxisOccupancy}});
hCollisionsCentIR = registry.add<TH2>(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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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))) {
Expand Down Expand Up @@ -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<TBcs>();
const auto runNumber = bc.runNumber();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -505,6 +536,10 @@ struct HfEventSelectionMc {
hGenCollisions = registry.add<TH1>(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
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down
Loading