3030#include " PWGDQ/DataModel/ReducedInfoTables.h"
3131
3232#include " Common/CCDB/EventSelectionParams.h"
33+ #include " Common/CCDB/RCTSelectionFlags.h"
3334#include " Common/CCDB/ctpRateFetcher.h"
3435#include " Common/Core/RecoDecay.h"
3536#include " Common/Core/TableHelper.h"
@@ -339,6 +340,10 @@ struct AnalysisEventSelection {
339340 o2::framework::Configurable<bool > fConfigFetchInteractionRate {" cfgFetchInteractionRate" , false , " Fetch event-wise interaction rate from the CCDB" };
340341 o2::framework::Configurable<std::string> fConfigIRSource {" cfgIRSource" , " ZNC hadronic" , " Estimator of the interaction rate (Recommended: pp --> T0VTX, Pb-Pb --> ZNC hadronic)" };
341342
343+ o2::framework::Configurable<bool > cfgUseRCT{" cfgUseRCT" , false , " Apply RCT quality selection" };
344+ o2::framework::Configurable<std::string> cfgRCTLabel{" cfgRCTLabel" , " CBT" , " RCT selection label" };
345+ o2::framework::Configurable<bool > cfgCheckZDC{" cfgCheckZDC" , false , " Also check ZDC quality" };
346+
342347 HistogramManager* fHistMan = nullptr ;
343348 MixingHandler* fMixHandler = nullptr ;
344349 AnalysisCompositeCut* fEventCut = nullptr ;
@@ -351,6 +356,10 @@ struct AnalysisEventSelection {
351356 std::map<uint64_t , std::vector<int64_t >> fBCCollMap ; // key: global BC, value: vector of reduced event global indices
352357 int fCurrentRun = -1 ;
353358
359+ o2::aod::rctsel::RCTFlagsChecker rctChecker{" CBT" };
360+ std::map<uint64_t , uint32_t > rctFlags;
361+ int rctRun = -1 ;
362+
354363 void init (o2::framework::InitContext& context)
355364 {
356365
@@ -424,6 +433,48 @@ struct AnalysisEventSelection {
424433 fCCDB ->setLocalObjectValidityChecking ();
425434 fCCDB ->setCreatedNotAfter (fConfigNoLaterThan .value );
426435 fCCDBApi .init (fConfigCcdbUrl .value );
436+
437+ if (cfgUseRCT.value ) {
438+ rctChecker.init (cfgRCTLabel.value , cfgCheckZDC.value );
439+
440+ if (!rctChecker.any ()) {
441+ LOGF (fatal, " Empty RCT mask: check cfgRCTLabel" );
442+ }
443+ }
444+ }
445+
446+ void loadRCT (int run, uint64_t timestamp)
447+ {
448+ std::map<std::string, std::string> metadata{{" run" , std::to_string (run)}};
449+
450+ auto * flags = fCCDB ->getSpecific <std::map<uint64_t , uint32_t >>(" RCT/Flags/RunFlags" , timestamp, metadata);
451+ if (flags == nullptr || flags->empty ()) {
452+ LOGF (fatal, " Missing or empty RCT flags for run " + std::to_string (run));
453+ }
454+
455+ LOG (info) << " Requesting RCT/Flags/RunFlags" << " run=" << run << " timestamp=" << timestamp;
456+
457+ rctFlags = *flags;
458+ rctRun = run;
459+ }
460+
461+ bool passesRCT (int run, uint64_t timestamp)
462+ {
463+ if (!cfgUseRCT.value ) {
464+ return true ;
465+ }
466+
467+ if (run != rctRun) {
468+ loadRCT (run, timestamp);
469+ }
470+
471+ auto iterator = rctFlags.upper_bound (timestamp);
472+ if (iterator == rctFlags.begin ()) {
473+ return false ;
474+ }
475+
476+ const uint32_t flags = std::prev (iterator)->second ;
477+ return (static_cast <uint64_t >(flags) & rctChecker.value ()) == 0 ;
427478 }
428479
429480 template <uint32_t TEventFillMap, typename TEvents>
@@ -463,7 +514,7 @@ struct AnalysisEventSelection {
463514 }
464515
465516 // Apply event cuts and fill histograms after selection
466- if (fEventCut ->IsSelected (dqtablereader_helpers::varValues ())) {
517+ if (fEventCut ->IsSelected (dqtablereader_helpers::varValues ()) && passesRCT (event. runNumber (), event. timestamp ()) ) {
467518 if (fConfigRunZorro ) {
468519 if (event.tag_bit (56 )) { // This is the bit used for the software trigger event selections [TO BE DONE: find a more clear way to use it]
469520 if (fConfigQA ) {
0 commit comments