Skip to content

Commit abd09b6

Browse files
committed
Implement possibility to select RCT Flags in tableReader_withAssoc and dqEfficiency_withAssoc.
1 parent 31acdb7 commit abd09b6

2 files changed

Lines changed: 104 additions & 2 deletions

File tree

‎PWGDQ/Tasks/dqEfficiency_withAssoc.cxx‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "PWGDQ/Core/VarManager.h"
2525
#include "PWGDQ/DataModel/ReducedInfoTables.h"
2626

27+
#include "Common/CCDB/RCTSelectionFlags.h"
2728
#include "Common/Core/TableHelper.h"
2829

2930
#include <CCDB/BasicCCDBManager.h>
@@ -309,6 +310,10 @@ struct AnalysisEventSelection {
309310
Configurable<std::string> fConfigCcdbUrl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
310311
Configurable<int64_t> fConfigNoLaterThan{"ccdb-no-later-than", std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(), "latest acceptable timestamp of creation for the object"};
311312

313+
Configurable<bool> cfgUseRCT{"cfgUseRCT", false, "Apply RCT quality selection"};
314+
Configurable<std::string> cfgRCTLabel{"cfgRCTLabel", "CBT", "RCT selection label"};
315+
Configurable<bool> cfgCheckZDC{"cfgCheckZDC", false, "Also check ZDC quality"};
316+
312317
HistogramManager* fHistMan = nullptr;
313318
MixingHandler* fMixHandler = nullptr;
314319

@@ -322,6 +327,10 @@ struct AnalysisEventSelection {
322327
std::map<std::string, std::string> fMetadataRCT, fHeader;
323328
int fCurrentRun = -1;
324329

330+
o2::aod::rctsel::RCTFlagsChecker rctChecker{"CBT"};
331+
std::map<uint64_t, uint32_t> rctFlags;
332+
int rctRun = -1;
333+
325334
void init(o2::framework::InitContext& context)
326335
{
327336
if (context.mOptions.get<bool>("processDummy")) {
@@ -378,6 +387,48 @@ struct AnalysisEventSelection {
378387
fCCDB->setLocalObjectValidityChecking();
379388
fCCDB->setCreatedNotAfter(fConfigNoLaterThan.value);
380389
fCCDBApi.init(fConfigCcdbUrl.value);
390+
391+
if (cfgUseRCT.value) {
392+
rctChecker.init(cfgRCTLabel.value, cfgCheckZDC.value);
393+
394+
if (!rctChecker.any()) {
395+
LOGF(fatal, "Empty RCT mask: check cfgRCTLabel");
396+
}
397+
}
398+
}
399+
400+
void loadRCT(int run, uint64_t timestamp)
401+
{
402+
std::map<std::string, std::string> metadata{{"run", std::to_string(run)}};
403+
404+
auto* flags = fCCDB->getSpecific<std::map<uint64_t, uint32_t>>("RCT/Flags/RunFlags", timestamp, metadata);
405+
if (flags == nullptr || flags->empty()) {
406+
LOGF(fatal, "Missing or empty RCT flags for run " + std::to_string(run));
407+
}
408+
409+
LOG(info) << "Requesting RCT/Flags/RunFlags" << " run=" << run << " timestamp=" << timestamp;
410+
411+
rctFlags = *flags;
412+
rctRun = run;
413+
}
414+
415+
bool passesRCT(int run, uint64_t timestamp)
416+
{
417+
if (!cfgUseRCT.value) {
418+
return true;
419+
}
420+
421+
if (run != rctRun) {
422+
loadRCT(run, timestamp);
423+
}
424+
425+
auto iterator = rctFlags.upper_bound(timestamp);
426+
if (iterator == rctFlags.begin()) {
427+
return false;
428+
}
429+
430+
const uint32_t flags = std::prev(iterator)->second;
431+
return (static_cast<uint64_t>(flags) & rctChecker.value()) == 0;
381432
}
382433

383434
template <uint32_t TEventFillMap, typename TEvents, typename TEventsMC>
@@ -406,7 +457,7 @@ struct AnalysisEventSelection {
406457
if (fConfigQA) {
407458
fHistMan->FillHistClass("Event_BeforeCuts", dqefficiency_helpers::varValues()); // automatically fill all the histograms in the class Event
408459
}
409-
if (fEventCut->IsSelected(dqefficiency_helpers::varValues())) {
460+
if (fEventCut->IsSelected(dqefficiency_helpers::varValues()) && passesRCT(event.runNumber(), event.timestamp())) {
410461
if (fConfigQA) {
411462
fHistMan->FillHistClass("Event_AfterCuts", dqefficiency_helpers::varValues());
412463
}

‎PWGDQ/Tasks/tableReader_withAssoc.h‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
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

Comments
 (0)