CMS 3D CMS Logo

GEMDQMEfficiencySourceBase.cc
Go to the documentation of this file.
2 
4 
5 #include "TPRegexp.h"
6 
8  : kGEMOHStatusCollectionToken_(
9  consumes<GEMOHStatusCollection>(ps.getUntrackedParameter<edm::InputTag>("ohStatusTag"))),
10  kGEMVFATStatusCollectionToken_(
11  consumes<GEMVFATStatusCollection>(ps.getUntrackedParameter<edm::InputTag>("vfatStatusTag"))),
12  kMonitorGE11_(ps.getUntrackedParameter<bool>("monitorGE11")),
13  kMonitorGE21_(ps.getUntrackedParameter<bool>("monitorGE21")),
14  kMonitorGE0_(ps.getUntrackedParameter<bool>("monitorGE0")),
15  kMaskChamberWithError_(ps.getUntrackedParameter<bool>("maskChamberWithError")),
16  kLogCategory_(ps.getUntrackedParameter<std::string>("logCategory")) {}
17 
18 // NOTE GEMDQMEfficiencyClientBase::parseEfficiencySourceName
20  const bool success = TPRegexp("\\w+_GE\\d1-(P|M)[0-9\\-]*").MatchB(denominator);
21  if (not success) {
22  edm::LogError(kLogCategory_) << "denominator name not understood: " << denominator;
23  return std::string{};
24  }
25 
26  const std::string delimiter = "_";
27  const std::string::size_type delimiter_pos = denominator.find_last_of(delimiter);
28  const std::string var_name = denominator.substr(0, delimiter_pos);
29  const std::string gem_name = denominator.substr(delimiter_pos + 1);
30 
31  const std::string numerator = var_name + "_match" + delimiter + gem_name;
32  // e.g. denominator_name = "prop_GE11-P-L1"
33  // tokens = {"prop", "11-P-L1"}
34 
35  return numerator;
36 }
37 
38 // TODO doc
41  if (denominator == nullptr) {
42  edm::LogError(kLogCategory_) << "denominator is nullptr";
43  return nullptr;
44  }
45 
46  const std::string name = nameNumerator(denominator->getName());
47  if (name.empty()) {
48  edm::LogError(kLogCategory_) << "denominator's name is " << denominator->getName()
49  << " but nameNumerator returns an empty string";
50  return nullptr;
51  }
52  TH1F* hist = dynamic_cast<TH1F*>(denominator->getTH1F()->Clone(name.c_str()));
53  return ibooker.book1D(name, hist);
54 }
55 
56 // TODO doc
59  if (denominator == nullptr) {
60  edm::LogError(kLogCategory_) << "denominator is nullptr";
61  return nullptr;
62  }
63 
64  const std::string name = nameNumerator(denominator->getName());
65  if (name.empty()) {
66  edm::LogError(kLogCategory_) << "denominator's name is " << denominator->getName()
67  << " but nameNumerator returns an empty string";
68  return nullptr;
69  }
70 
71  // TODO check if getTH2F is not None
72  TH2F* hist = dynamic_cast<TH2F*>(denominator->getTH2F()->Clone(name.c_str()));
73  return ibooker.book2D(name, hist);
74 }
75 
76 // TODO docs
78  if (station == nullptr) {
79  return std::make_tuple(false, 0, 0);
80  }
81 
82  const std::vector<const GEMSuperChamber*> superchamber_vec = station->superChambers();
83  if (not checkRefs(superchamber_vec)) {
84  edm::LogError(kLogCategory_) << "GEMStation::superChambers"; // FIXME
85  return std::make_tuple(false, 0, 0);
86  }
87 
88  std::vector<int> id_vec;
89  std::transform(superchamber_vec.begin(),
90  superchamber_vec.end(),
91  std::back_inserter(id_vec),
92  [](const GEMSuperChamber* superchamber) -> int { return superchamber->id().chamber(); });
93  const auto [first_chamber, last_chamber] = std::minmax_element(id_vec.begin(), id_vec.end());
94  if ((first_chamber == id_vec.end()) or (last_chamber == id_vec.end())) {
95  edm::LogError(kLogCategory_) << ""; // TODO
96  return std::make_tuple(false, 0, 0);
97  }
98 
99  return std::make_tuple(true, *first_chamber, *last_chamber);
100 }
101 
102 // TODO docs
104  if (station == nullptr) {
105  return std::make_tuple(false, 0, 0);
106  }
107 
108  const std::vector<const GEMSuperChamber*> superchamber_vec = station->superChambers();
109  if (not checkRefs(superchamber_vec)) {
110  edm::LogError(kLogCategory_) << "GEMStation::superChambers"; // FIXME
111  return std::make_tuple(false, 0, 0);
112  }
113 
114  const std::vector<const GEMChamber*> chamber_vec = superchamber_vec.front()->chambers();
115  if (not checkRefs(chamber_vec)) {
116  edm::LogError(kLogCategory_) << ""; // TODO
117  return std::make_tuple(false, 0, 0);
118  }
119  const std::vector<const GEMEtaPartition*> eta_partition_vec = chamber_vec.front()->etaPartitions();
120  if (not checkRefs(eta_partition_vec)) {
121  edm::LogError(kLogCategory_) << ""; // TODO
122  return std::make_tuple(false, 0, 0);
123  }
124 
125  std::vector<int> ieta_vec;
126  std::transform(eta_partition_vec.begin(),
127  eta_partition_vec.end(),
128  std::back_inserter(ieta_vec),
129  [](const GEMEtaPartition* each) -> int { return each->id().ieta(); });
130  const auto [first_ieta, last_ieta] = std::minmax_element(ieta_vec.begin(), ieta_vec.end());
131  if ((first_ieta == ieta_vec.end()) or (last_ieta == ieta_vec.end())) {
132  edm::LogError(kLogCategory_) << "failed to find minmax";
133  return std::make_tuple(false, 0, 0);
134  }
135 
136  return std::make_tuple(true, *first_ieta, *last_ieta);
137 }
138 
139 // TODO docs
141  const TString& name,
142  const TString& title,
143  const GEMStation* station) {
144  if (station == nullptr) {
145  edm::LogError(kLogCategory_) << ""; // TODO
146  return nullptr;
147  }
148 
149  auto [success, first_chamber, last_chamber] = getChamberRange(station);
150  if (not success) {
151  edm::LogError(kLogCategory_) << "failed to get chambers: " << station->getName();
152  return nullptr;
153  }
154 
155  const double xlow = first_chamber - 0.5;
156  const double xup = last_chamber + 0.5;
157  const int nbinsx = last_chamber - first_chamber + 1;
158 
159  MonitorElement* me = ibooker.book1D(name, title, nbinsx, xlow, xup);
160  me->setAxisTitle("Chamber", 1);
161 
162  for (int chamber = first_chamber; chamber <= last_chamber; chamber++) {
164  me->setBinLabel(chamber, label, 1);
165  }
166 
167  return me;
168 }
169 
170 // TODO docs
172  const TString& name,
173  const TString& title,
174  const GEMStation* station) {
175  if (station == nullptr) {
176  edm::LogError(kLogCategory_) << "station is nullptr";
177  return nullptr;
178  }
179 
180  auto [chamber_success, first_chamber, last_chamber] = getChamberRange(station);
181  if (not chamber_success) {
182  edm::LogError(kLogCategory_) << "getChamberRange failed";
183  return nullptr;
184  }
185 
186  auto [ieta_success, first_ieta, last_ieta] = getEtaPartitionRange(station);
187  if (not ieta_success) {
188  edm::LogError(kLogCategory_) << "getEtaPartitionRange failed";
189  return nullptr;
190  }
191 
192  const double xlow = first_chamber - 0.5;
193  const double xup = last_chamber + 0.5;
194  const int nbinsx = last_chamber - first_chamber + 1;
195 
196  const double ylow = first_ieta - 0.5;
197  const double yup = last_ieta + 0.5;
198  const int nbinsy = last_ieta - first_ieta + 1;
199 
200  MonitorElement* me = ibooker.book2D(name, title, nbinsx, xlow, xup, nbinsy, ylow, yup);
201  me->setAxisTitle("Chamber", 1);
202  me->setAxisTitle("i#eta", 2);
203 
204  for (int chamber = first_chamber; chamber <= last_chamber; chamber++) {
206  me->setBinLabel(chamber, label, 1);
207  }
208 
209  for (int ieta = first_ieta; ieta <= last_ieta; ieta++) {
211  me->setBinLabel(ieta, label, 2);
212  }
213 
214  return me;
215 }
216 
217 // TODO docs
219  bool skip = false;
220 
221  if (station == 0) {
222  skip = not kMonitorGE0_;
223 
224  } else if (station == 1) {
225  skip = not kMonitorGE11_;
226 
227  } else if (station == 2) {
228  skip = not kMonitorGE21_;
229 
230  } else {
231  edm::LogError(kLogCategory_) << "got an unexpected GEM station " << station << ". skip this station.";
232  skip = true;
233  }
234 
235  return skip;
236 }
237 
239  const GEMOHStatusCollection* oh_status_collection,
240  const GEMVFATStatusCollection* vfat_status_collection) {
241  const bool mask = true;
242 
243  for (auto iter = oh_status_collection->begin(); iter != oh_status_collection->end(); iter++) {
244  const auto [oh_id, range] = (*iter);
245  if (chamber_id != oh_id) {
246  continue;
247  }
248 
249  for (auto oh_status = range.first; oh_status != range.second; oh_status++) {
250  if (oh_status->isBad()) {
251  // GEMOHStatus is bad. Mask this chamber.
252  return mask;
253  } // isBad
254  } // range
255  } // collection
256 
257  for (auto iter = vfat_status_collection->begin(); iter != vfat_status_collection->end(); iter++) {
258  const auto [vfat_id, range] = (*iter);
259  if (chamber_id != vfat_id.chamberId()) {
260  continue;
261  }
262  for (auto vfat_status = range.first; vfat_status != range.second; vfat_status++) {
263  if (vfat_status->isBad()) {
264  return mask;
265  }
266  } // range
267  } // collection
268 
269  return not mask;
270 }
271 
272 // TODO docs
274  const bool has_key = me_map.find(key) != me_map.end();
275 
276  if UNLIKELY (not has_key) {
277  const std::string hint = me_map.empty() ? "empty" : me_map.begin()->second->getName();
278  edm::LogError(kLogCategory_) << "got an invalid key: " << key << ", hint=" << hint;
279  }
280  return has_key;
281 }
282 
283 void GEMDQMEfficiencySourceBase::fillME(MEMap& me_map, const GEMDetId& key, const double x) {
284  if (hasMEKey(me_map, key)) {
285  me_map[key]->Fill(x);
286  }
287 }
288 
289 void GEMDQMEfficiencySourceBase::fillME(MEMap& me_map, const GEMDetId& key, const double x, const double y) {
290  if (hasMEKey(me_map, key)) {
291  me_map[key]->Fill(x, y);
292  }
293 }
294 
295 double GEMDQMEfficiencySourceBase::clampWithAxis(const double value, const TAxis* axis) {
296  const double first_bin_center = axis->GetBinCenter(1);
297  const double last_bin_center = axis->GetBinCenter(axis->GetNbins());
298  return std::clamp(value, first_bin_center, last_bin_center);
299 }
300 
301 // https://github.com/cms-sw/cmssw/blob/CMSSW_12_0_0_pre3/DQMOffline/L1Trigger/src/L1TFillWithinLimits.cc
303  if (me == nullptr) {
304  edm::LogError(kLogCategory_) << "MonitorElement is nullptr";
305  return;
306  }
307  // FIXME assume that GEMDQMEfficiencySourceBase uses only TH1F fo 1d histograms
308  const TAxis* x_axis = me->getTH1F()->GetXaxis();
309  me->Fill(clampWithAxis(x, x_axis));
310 }
311 
312 // https://github.com/cms-sw/cmssw/blob/CMSSW_12_0_0_pre3/DQMOffline/L1Trigger/src/L1TFillWithinLimits.cc
314  if (me == nullptr) {
315  edm::LogError(kLogCategory_) << "MonitorElement is nullptr";
316  return;
317  }
318  // FIXME assume that GEMDQMEfficiencySourceBase uses only TH2F fo 2d histograms
319  const TH2F* hist = me->getTH2F();
320  const TAxis* x_axis = hist->GetXaxis();
321  const TAxis* y_axis = hist->GetYaxis();
322 
323  me->Fill(clampWithAxis(x, x_axis), clampWithAxis(y, y_axis));
324 }
325 
327  if (hasMEKey(me_map, key)) {
328  fillMEWithinLimits(me_map[key], x);
329  }
330 }
331 
332 void GEMDQMEfficiencySourceBase::fillMEWithinLimits(MEMap& me_map, const GEMDetId& key, const double x, const double y) {
333  if (hasMEKey(me_map, key)) {
334  fillMEWithinLimits(me_map[key], x, y);
335  }
336 }
MonitorElement * bookChamberEtaPartition(DQMStore::IBooker &, const TString &, const TString &, const GEMStation *)
MonitorElement * bookNumerator2D(DQMStore::IBooker &, MonitorElement *)
void fillMEWithinLimits(MonitorElement *, const double)
std::string to_string(const V &value)
Definition: OMSAccess.h:71
std::tuple< bool, int, int > getEtaPartitionRange(const GEMStation *)
bool maskChamberWithError(const GEMDetId &chamber_id, const GEMOHStatusCollection *, const GEMVFATStatusCollection *)
Log< level::Error, false > LogError
uint16_t size_type
constexpr uint32_t mask
Definition: gpuClustering.h:26
std::map< GEMDetId, MonitorElement * > MEMap
void fillME(MEMap &, const GEMDetId &, const double)
char const * label
MonitorElement * bookNumerator1D(DQMStore::IBooker &, MonitorElement *)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
MonitorElement * bookChamber(DQMStore::IBooker &, const TString &, const TString &, const GEMStation *)
Definition: value.py:1
DigiRangeIterator begin() const
std::string nameNumerator(const std::string &)
std::tuple< bool, int, int > getChamberRange(const GEMStation *)
bool checkRefs(const std::vector< T *> &)
bool hasMEKey(const MEMap &, const GEMDetId &)
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
double clampWithAxis(const double, const TAxis *axis)
HLT enums.
float x
constexpr GEMDetId chamberId() const
Definition: GEMDetId.h:204
#define UNLIKELY(x)
Definition: Likely.h:21
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
GEMDQMEfficiencySourceBase(const edm::ParameterSet &)
DigiRangeIterator end() const
unsigned transform(const HcalDetId &id, unsigned transformCode)
A container for a generic type of digis indexed by some index, implemented with a map<IndexType...