|
| 1 | +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +/// \file RCTSelectionFlags.h |
| 13 | +/// \brief RCT selection flags |
| 14 | +/// |
| 15 | +/// \author Andrea Ferrero <[email protected]> and Evgeny Kryshen <[email protected]> |
| 16 | + |
| 17 | +#ifndef COMMON_CCDB_RCTSELECTIONFLAGS_H_ |
| 18 | +#define COMMON_CCDB_RCTSELECTIONFLAGS_H_ |
| 19 | + |
| 20 | +#include <CommonUtils/EnumFlags.h> |
| 21 | +#include <Rtypes.h> |
| 22 | +#include <TMath.h> |
| 23 | + |
| 24 | +#include <stdexcept> |
| 25 | +#include <algorithm> |
| 26 | +#include <string> |
| 27 | +#include <vector> |
| 28 | + |
| 29 | +namespace o2::aod::rctsel |
| 30 | +{ |
| 31 | +/* |
| 32 | + * Bit mapping used for populating the CCDB objects from the RCT flags |
| 33 | + * From https://github.com/JianLIUhep/RCTutils/blob/main/CCDB/process_and_upload.C |
| 34 | +std::map<std::string, std::map<std::string, int>> detailedBitMapping = { |
| 35 | + {"CPV", { {"Bad", 0}, {"Invalid", 0} }}, |
| 36 | + {"EMC", { {"Bad", 1}, {"NoDetectorData", 1}, {"BadEMCalorimetry", 1}, {"LimitedAcceptanceMCReproducible", 2} }}, |
| 37 | + {"FDD", { {"Bad", 3}, {"Invalid", 3}, {"NoDetectorData", 3} }}, |
| 38 | + {"FT0", { {"Bad", 4}, {"UnknownQuality", 4}, {"Unknown", 4} }}, |
| 39 | + {"FV0", { {"Bad", 5} }}, |
| 40 | + {"HMP", { {"Bad", 6}, {"NoDetectorData", 6} }}, |
| 41 | + {"ITS", { {"Bad", 7}, {"UnknownQuality", 7}, {"BadTracking", 7}, {"LimitedAcceptanceMCReproducible", 8} }}, |
| 42 | + {"MCH", { {"Bad", 9}, {"NoDetectorData", 9}, {"Unknown", 9}, {"LimitedAcceptanceMCReproducible", 10} }}, |
| 43 | + {"MFT", { {"Bad", 11}, {"BadTracking", 11}, {"LimitedAcceptanceMCReproducible", 12} }}, |
| 44 | + {"MID", { {"Bad", 13}, {"BadTracking", 13}, {"LimitedAcceptanceMCReproducible", 14} }}, |
| 45 | + {"PHS", { {"Bad", 15}, {"Invalid", 15} }}, |
| 46 | + {"TOF", { {"Bad", 16}, {"NoDetectorData", 16}, {"BadPID", 16}, {"LimitedAcceptanceMCReproducible", 17} }}, |
| 47 | + {"TPC", { {"Bad", 18}, {"BadTracking", 18}, {"BadPID", 19}, {"LimitedAcceptanceMCNotReproducible", 18}, {"LimitedAcceptanceMCReproducible", 20} }}, |
| 48 | + {"TRD", { {"Bad", 21}, {"BadTracking", 21} }}, |
| 49 | + {"ZDC", { {"Bad", 22}, {"UnknownQuality", 22}, {"Unknown", 22}, {"NoDetectorData", 22} }} |
| 50 | +}; |
| 51 | +*/ |
| 52 | + |
| 53 | +// RCT selection flags |
| 54 | +enum RCTSelectionFlags { |
| 55 | + kCPVBad = 0, |
| 56 | + kEMCBad, |
| 57 | + kEMCLimAccMCRepr, |
| 58 | + kFDDBad, |
| 59 | + kFT0Bad, |
| 60 | + kFV0Bad, |
| 61 | + kHMPBad, |
| 62 | + kITSBad, |
| 63 | + kITSLimAccMCRepr, |
| 64 | + kMCHBad, |
| 65 | + kMCHLimAccMCRepr, |
| 66 | + kMFTBad, |
| 67 | + kMFTLimAccMCRepr, |
| 68 | + kMIDBad, |
| 69 | + kMIDLimAccMCRepr, |
| 70 | + kPHSBad, |
| 71 | + kTOFBad, |
| 72 | + kTOFLimAccMCRepr, |
| 73 | + kTPCBadTracking, |
| 74 | + kTPCBadPID, |
| 75 | + kTPCLimAccMCRepr, |
| 76 | + kTRDBad, |
| 77 | + kZDCBad, |
| 78 | + kNRCTSelectionFlags |
| 79 | +}; |
| 80 | + |
| 81 | +template <typename T> |
| 82 | +concept HasRCTFlags = requires(T a, int bit) { |
| 83 | + { a.rct_bit(bit) } -> std::convertible_to<bool>; |
| 84 | + { a.rct_raw() } -> std::convertible_to<uint64_t>; |
| 85 | +}; |
| 86 | + |
| 87 | +class RCTFlagsChecker : public o2::utils::EnumFlags<RCTSelectionFlags> |
| 88 | +{ |
| 89 | + public: |
| 90 | + RCTFlagsChecker() = default; |
| 91 | + |
| 92 | + // Construct the object from an initializer list, like this: |
| 93 | + // RCTFlagsChecker qualityFlagsChecker{ kFT0Bad, kITSBad, kMFTBad, kMFTLimAccMCRepr }; |
| 94 | + using o2::utils::EnumFlags<RCTSelectionFlags>::EnumFlags; |
| 95 | + |
| 96 | + // Construct the object from one of the pre-defined runlist selections. |
| 97 | + // The label parameter can take the following values: |
| 98 | + // - "CBT" |
| 99 | + // - "CBT_hadronPID" |
| 100 | + // - "CBT_electronPID" |
| 101 | + // - "CCBT_calo" |
| 102 | + // - "CBT_muon" |
| 103 | + // - "CBT_muon_glo" |
| 104 | + // The checkZDC boolean flag controls whether to iclude the ZDC quality in all the pre-defined selections (for Pb-Pb data) |
| 105 | + // The treatLimitedAcceptanceAsBad boolean flag controls whether "LimitedAcceptanceMCReproducible" flags should be |
| 106 | + // treated as Bad and the corresponding events excluded |
| 107 | + explicit RCTFlagsChecker(const std::string& label, bool checkZDC = false, bool treatLimitedAcceptanceAsBad = false) |
| 108 | + { |
| 109 | + init(label, checkZDC, treatLimitedAcceptanceAsBad); |
| 110 | + } |
| 111 | + |
| 112 | + // Initialize the object from an initializer list of RCTSelectionFlags values |
| 113 | + void init(std::initializer_list<RCTSelectionFlags> flags) |
| 114 | + { |
| 115 | + reset(); |
| 116 | + *this = RCTFlagsChecker(flags); |
| 117 | + } |
| 118 | + |
| 119 | + // Initialize the object from one of the pre-defined runlist selections. |
| 120 | + // The label parameter can take the following values: |
| 121 | + // - "CBT" |
| 122 | + // - "CBT_hadronPID" |
| 123 | + // - "CBT_electronPID" |
| 124 | + // - "CCBT_calo" |
| 125 | + // - "CBT_muon" |
| 126 | + // - "CBT_muon_glo" |
| 127 | + // The checkZDC boolean flag controls whether to iclude the ZDC quality in all the pre-defined selections (for Pb-Pb data) |
| 128 | + // The treatLimitedAcceptanceAsBad boolean flag controls whether "LimitedAcceptanceMCReproducible" flags should be |
| 129 | + // treated as Bad and the corresponding events excluded |
| 130 | + void init(const std::string& label, bool checkZDC = false, bool treatLimitedAcceptanceAsBad = false) |
| 131 | + { |
| 132 | + auto setFlags = [this](std::initializer_list<RCTSelectionFlags> flags) { |
| 133 | + std::for_each(flags.begin(), |
| 134 | + flags.end(), |
| 135 | + [this](const RCTSelectionFlags f) noexcept { set(f); }); |
| 136 | + }; |
| 137 | + |
| 138 | + reset(); |
| 139 | + |
| 140 | + if (label == "CBT") { |
| 141 | + setFlags({kFT0Bad, kITSBad, kTPCBadTracking, kTPCBadPID}); |
| 142 | + if (treatLimitedAcceptanceAsBad) { |
| 143 | + setFlags({kITSLimAccMCRepr, kTPCLimAccMCRepr}); |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + if (label == "CBT_hadronPID") { |
| 148 | + setFlags({kFT0Bad, kITSBad, kTPCBadTracking, kTPCBadPID, kTOFBad}); |
| 149 | + if (treatLimitedAcceptanceAsBad) { |
| 150 | + setFlags({kITSLimAccMCRepr, kTPCLimAccMCRepr, kTOFLimAccMCRepr}); |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + if (label == "CBT_electronPID") { |
| 155 | + setFlags({kFT0Bad, kITSBad, kTPCBadTracking, kTPCBadPID, kTRDBad}); |
| 156 | + if (treatLimitedAcceptanceAsBad) { |
| 157 | + setFlags({kITSLimAccMCRepr, kTPCLimAccMCRepr}); |
| 158 | + } |
| 159 | + } |
| 160 | + |
| 161 | + if (label == "CBT_calo") { |
| 162 | + setFlags({kFT0Bad, kITSBad, kTPCBadTracking, kTPCBadPID, kEMCBad}); |
| 163 | + if (treatLimitedAcceptanceAsBad) { |
| 164 | + setFlags({kITSLimAccMCRepr, kTPCLimAccMCRepr, kEMCLimAccMCRepr}); |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + if (label == "CBT_muon") { |
| 169 | + setFlags({kFT0Bad, kITSBad, kTPCBadTracking, kMCHBad, kMIDBad}); |
| 170 | + if (treatLimitedAcceptanceAsBad) { |
| 171 | + setFlags({kITSLimAccMCRepr, kTPCLimAccMCRepr, kMCHLimAccMCRepr, kMIDLimAccMCRepr}); |
| 172 | + } |
| 173 | + } |
| 174 | + |
| 175 | + if (label == "CBT_muon_glo") { |
| 176 | + setFlags({kFT0Bad, kITSBad, kTPCBadTracking, kMCHBad, kMIDBad, kMFTBad}); |
| 177 | + if (treatLimitedAcceptanceAsBad) { |
| 178 | + setFlags({kITSLimAccMCRepr, kTPCLimAccMCRepr, kMCHLimAccMCRepr, kMIDLimAccMCRepr, kMFTLimAccMCRepr}); |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + if (checkZDC) { |
| 183 | + set(kZDCBad); |
| 184 | + } |
| 185 | + } |
| 186 | + |
| 187 | + // Check the RCT column of a given event selection table. |
| 188 | + // The function returns true if none of the checked flags is set in the RCT column. |
| 189 | + bool checkTable(const HasRCTFlags auto& table) |
| 190 | + { |
| 191 | + if (!any()) { |
| 192 | + throw std::out_of_range("RCTFlagsCheckerAlt with empty RCTSelectionFlags bits mask"); |
| 193 | + } |
| 194 | + |
| 195 | + // bitmask of the current table |
| 196 | + uint64_t tableBits = table.rct_raw(); |
| 197 | + // bitmask of flags to be checked |
| 198 | + uint64_t flagsBits = value(); |
| 199 | + |
| 200 | + // return true if none of the checked bits is set in the table bitmask |
| 201 | + return ((tableBits & flagsBits) == 0); |
| 202 | + } |
| 203 | + |
| 204 | + bool operator()(const HasRCTFlags auto& table) |
| 205 | + { |
| 206 | + return checkTable(table); |
| 207 | + } |
| 208 | +}; |
| 209 | + |
| 210 | +} // namespace o2::aod::rctsel |
| 211 | +#endif // COMMON_CCDB_RCTSELECTIONFLAGS_H_ |
0 commit comments