CMS 3D CMS Logo

MESet.cc
Go to the documentation of this file.
2 
6 
9 
10 #include "TPRegexp.h"
11 #include "TString.h"
12 
13 namespace ecaldqm {
15  : mes_(0),
16  path_(""),
17  otype_(binning::nObjType),
18  btype_(binning::nBinType),
19  kind_(MonitorElement::Kind::INVALID),
20  lumiFlag_(false),
21  batchMode_(false),
22  active_(false) {}
23 
24  MESet::MESet(std::string const &_path,
25  binning::ObjectType _otype,
26  binning::BinningType _btype,
28  : mes_(0),
29  path_(_path),
30  otype_(_otype),
31  btype_(_btype),
32  kind_(_kind),
33  lumiFlag_(false),
34  batchMode_(false),
35  active_(false) {
36  if (path_.empty() || path_.find('/') == std::string::npos ||
37  (otype_ != binning::kChannel && path_.find('/') == path_.size() - 1))
38  throw_(_path + " cannot be used for ME path name");
39 
40  switch (kind_) {
46  break;
47  default:
48  throw_("Unsupported MonitorElement kind");
49  }
50  }
51 
52  MESet::MESet(MESet const &_orig)
53  : mes_(_orig.mes_),
54  path_(_orig.path_),
55  otype_(_orig.otype_),
56  btype_(_orig.btype_),
57  kind_(_orig.kind_),
58  lumiFlag_(_orig.lumiFlag_),
59  batchMode_(_orig.batchMode_),
60  active_(_orig.active_) {}
61 
63 
64  MESet &MESet::operator=(MESet const &_rhs) {
65  mes_ = _rhs.mes_;
66  path_ = _rhs.path_;
67  otype_ = _rhs.otype_;
68  btype_ = _rhs.btype_;
69  kind_ = _rhs.kind_;
70  active_ = _rhs.active_;
71 
72  return *this;
73  }
74 
75  MESet *MESet::clone(std::string const &_path /* = ""*/) const {
77  if (!_path.empty())
78  path_ = _path;
79  MESet *copy(new MESet(*this));
80  path_ = path;
81  return copy;
82  }
83 
84  void MESet::clear() const {
85  active_ = false;
86  mes_.clear();
87  }
88 
89  void MESet::setAxisTitle(std::string const &_title, int _axis /* = 1*/) {
90  if (!active_)
91  return;
92 
93  unsigned nME(mes_.size());
94  for (unsigned iME(0); iME < nME; iME++)
95  mes_[iME]->setAxisTitle(_title, _axis);
96  }
97 
98  void MESet::reset(EcalElectronicsMapping const *electronicsMap,
99  double _content /* = 0.*/,
100  double _err /* = 0.*/,
101  double _entries /* = 0.*/) {
102  if (!active_)
103  return;
104 
105  resetAll(_content, _err, _entries);
106  }
107 
108  void MESet::resetAll(double _content /* = 0.*/, double _err /* = 0.*/, double _entries /* = 0.*/) {
109  if (!active_)
110  return;
111 
112  unsigned nME(mes_.size());
113 
115  for (unsigned iME(0); iME < nME; iME++)
116  mes_[iME]->Fill(_content);
117  return;
118  }
119 
120  bool simple(true);
121  if (_content != 0. || _err != 0. || _entries != 0.)
122  simple = false;
123 
124  for (unsigned iME(0); iME < nME; iME++) {
125  TH1 *h(mes_[iME]->getTH1());
126  h->Reset();
127  if (simple)
128  continue;
129 
130  int nbinsX(h->GetNbinsX());
131  int nbinsY(h->GetNbinsY());
132  double entries(0.);
133  for (int ix(1); ix <= nbinsX; ix++) {
134  for (int iy(1); iy <= nbinsY; iy++) {
135  int bin(h->GetBin(ix, iy));
136  h->SetBinContent(bin, _content);
137  h->SetBinError(bin, _err);
139  static_cast<TProfile *>(h)->SetBinEntries(bin, _entries);
140  entries += _entries;
141  } else if (kind_ == MonitorElement::Kind::TPROFILE2D) {
142  static_cast<TProfile2D *>(h)->SetBinEntries(bin, _entries);
143  entries += _entries;
144  }
145  }
146  }
147  if (entries == 0.)
148  entries = _entries;
149  h->SetEntries(entries);
150  }
151  }
152 
153  std::string MESet::formPath(std::map<std::string, std::string> const &_replacements) const {
154  TString path(path_);
155 
156  for (typename MESet::PathReplacements::const_iterator repItr(_replacements.begin()); repItr != _replacements.end();
157  ++repItr) {
158  TString pattern("\\%\\(");
159  pattern += repItr->first;
160  pattern += "\\)s";
161 
162  TPRegexp re(pattern);
163 
164  re.Substitute(path, repItr->second, "g");
165  }
166 
167  return path.Data();
168  }
169 
170  bool MESet::maskMatches(DetId const &_id,
171  uint32_t _mask,
172  StatusManager const *_statusManager,
173  EcalTrigTowerConstituentsMap const *trigTowerMap) const {
174  if (!_statusManager)
175  return false;
176 
177  if ((_statusManager->getStatus(_id.rawId()) & _mask) != 0)
178  return true;
179 
180  int subdet(_id.subdetId());
181 
182  bool searchNeighborsInTower(btype_ == binning::kTriggerTower || btype_ == binning::kSuperCrystal);
183 
184  // turn off masking for good channel for the time being
185  // update the RenderPlugin then enable again
186 
187  switch (subdet) {
188  case EcalBarrel: // this is a DetId for single crystal in barrel
189  {
190  EBDetId ebId(_id);
191  EcalTrigTowerDetId ttId(ebId.tower());
192  if ((_statusManager->getStatus(ttId.rawId()) & _mask) != 0)
193  return true;
194 
195  if (searchNeighborsInTower) {
196  std::vector<DetId> ids(trigTowerMap->constituentsOf(ttId));
197  for (std::vector<DetId>::iterator idItr(ids.begin()); idItr != ids.end(); ++idItr)
198  if ((_statusManager->getStatus(idItr->rawId()) & _mask) != 0)
199  return true;
200  }
201  } break;
202 
203  case EcalEndcap:
204  if (isEcalScDetId(_id)) {
205  EcalScDetId scId(_id);
206  for (int ix(1); ix <= 5; ix++) {
207  for (int iy(1); iy <= 5; iy++) {
208  int iix((scId.ix() - 1) * 5 + ix);
209  int iiy((scId.iy() - 1) * 5 + iy);
210  if (!EEDetId::validDetId(iix, iiy, scId.zside()))
211  continue;
212  if ((_statusManager->getStatus(EEDetId(iix, iiy, scId.zside()).rawId()) & _mask) != 0)
213  return true;
214  }
215  }
216  } else {
217  EEDetId eeId(_id);
218  EcalScDetId scId(eeId.sc());
219  if ((_statusManager->getStatus(scId.rawId()) & _mask) != 0)
220  return true;
221 
222  if (searchNeighborsInTower) {
223  for (int ix(1); ix <= 5; ix++) {
224  for (int iy(1); iy <= 5; iy++) {
225  int iix((scId.ix() - 1) * 5 + ix);
226  int iiy((scId.iy() - 1) * 5 + iy);
227  if (!EEDetId::validDetId(iix, iiy, scId.zside()))
228  continue;
229  if ((_statusManager->getStatus(EEDetId(iix, iiy, scId.zside()).rawId()) & _mask) != 0)
230  return true;
231  }
232  }
233  }
234  }
235  break;
236 
237  case EcalTriggerTower: {
239  std::vector<DetId> ids(trigTowerMap->constituentsOf(ttId));
240  for (std::vector<DetId>::iterator idItr(ids.begin()); idItr != ids.end(); ++idItr)
241  if ((_statusManager->getStatus(idItr->rawId()) & _mask) != 0)
242  return true;
243  } break;
244 
245  default:
246  break;
247  }
248 
249  return false;
250  }
251 
252  void MESet::fill_(unsigned _iME, int _bin, double _w) {
254  return;
255 
256  MonitorElement *me(mes_[_iME]);
257  if (!me)
258  return;
259 
260  TH1 *h(me->getTH1());
261 
262  int nbinsX(h->GetNbinsX());
263 
264  double x(h->GetXaxis()->GetBinCenter(_bin % (nbinsX + 2)));
265 
267  me->Fill(x, _w);
268  else {
269  double y(h->GetYaxis()->GetBinCenter(_bin / (nbinsX + 2)));
270  me->Fill(x, y, _w);
271  }
272  }
273 
274  void MESet::fill_(unsigned _iME, int _bin, double _y, double _w) {
276  return;
277 
278  MonitorElement *me(mes_[_iME]);
279  if (!me)
280  return;
281 
282  TH1 *h(me->getTH1());
283 
284  int nbinsX(h->GetNbinsX());
285 
286  double x(h->GetXaxis()->GetBinCenter(_bin % (nbinsX + 2)));
287  me->Fill(x, _y, _w);
288  }
289 
290  void MESet::fill_(unsigned _iME, double _x, double _wy, double _w) {
291  MonitorElement *me(mes_[_iME]);
292  if (!me)
293  return;
294 
296  me->Fill(_x);
298  me->Fill(_x, _wy);
299  else
300  me->Fill(_x, _wy, _w);
301  }
302 
303  MESet::ConstBin::ConstBin(MESet const &_meSet, unsigned _iME /* = 0*/, int _iBin /* = 1*/)
304  : meSet_(&_meSet), iME(_iME), iBin(_iBin), otype(binning::nObjType) {
305  if (iME == unsigned(-1))
306  return;
307 
308  // current internal bin numbering scheme does not allow 1D histograms
309  // (overflow & underflow in each y)
311  // if(kind != MonitorElement::Kind::TH1F && kind !=
312  // MonitorElement::Kind::TPROFILE &&
314  throw cms::Exception("InvalidOperation") << "MESet::ConstBin::Ctor: const_iterator only available for MESet of "
315  "2D histograms";
316 
317  MonitorElement const *me(meSet_->getME(iME));
318 
319  if (!me)
320  throw cms::Exception("InvalidOperation")
321  << "MESet::ConstBin::Ctor: ME " << iME << " does not exist for MESet " << meSet_->getPath();
322 
324  iBin = me->getNbinsX() + 3;
325 
327  }
328 
330  if (meSet_->getObjType() != _rhs.meSet_->getObjType() || meSet_->getBinType() != _rhs.meSet_->getBinType())
331  throw cms::Exception("IncompatibleAssignment")
332  << "Iterator of otype " << _rhs.meSet_->getObjType() << " and btype " << _rhs.meSet_->getBinType()
333  << " to otype " << meSet_->getObjType() << " and btype " << meSet_->getBinType() << " ("
334  << _rhs.meSet_->getPath() << " to " << meSet_->getPath() << ")";
335 
336  iME = _rhs.iME;
337  iBin = _rhs.iBin;
338  otype = _rhs.otype;
339 
340  return *this;
341  }
342 
344  MESet const &_meSet,
345  DetId const &_id)
346  : bin_() {
348  unsigned iME(binning::findPlotIndex(electronicsMap, otype, _id));
349  if (iME == unsigned(-1))
350  return;
351 
353  int bin(binning::findBin2D(electronicsMap, otype, btype, _id));
354  if (bin == 0)
355  return;
356 
357  bin_.setMESet(_meSet);
358  bin_.iME = iME;
359  bin_.iBin = bin;
360  bin_.otype = otype;
361  }
362 
364  unsigned &iME(bin_.iME);
365  MESet const *meSet(bin_.getMESet());
366 
367  if (iME == unsigned(-1))
368  return *this;
369 
370  int &bin(bin_.iBin);
371  binning::ObjectType &otype(bin_.otype);
372 
373  MonitorElement::Kind kind(meSet->getKind());
374  MonitorElement const *me(meSet->getME(iME));
375 
376  int nbinsX(me->getNbinsX());
377 
378  ++bin;
379  if (bin == 1) {
380  iME = 0;
381  me = meSet->getME(iME);
382  nbinsX = me->getNbinsX();
384  bin = nbinsX + 3;
385  otype = binning::getObject(meSet->getObjType(), iME);
386  }
387 
388  if (bin % (nbinsX + 2) == nbinsX + 1) {
390  bin / (nbinsX + 2) == me->getNbinsY()) {
391  iME += 1;
392  me = meSet->getME(iME);
393  if (!me) {
394  iME = unsigned(-1);
395  bin = -1;
397  } else {
398  nbinsX = me->getNbinsX();
400  bin = nbinsX + 3;
401  else
402  bin = 1;
403 
404  otype = binning::getObject(meSet->getObjType(), iME);
405  }
406  } else
407  bin += 2;
408  }
409 
410  return *this;
411  }
412 
414  if (!bin_.getMESet())
415  return *this;
416  do
417  operator++();
418  while (bin_.iME != unsigned(-1) && !bin_.isChannel(electronicsMap));
419 
420  return *this;
421  }
422 
424  MESet const *meSet(bin_.getMESet());
425  if (bin_.iME == unsigned(-1) || bin_.iBin < 1)
426  return false;
427 
428  MonitorElement::Kind kind(meSet->getKind());
430  return false;
431 
432  MonitorElement const *me(meSet->getME(bin_.iME));
433 
434  if (bin_.iBin / (me->getNbinsX() + 2) >= me->getNbinsY())
435  return false;
436 
437  bin_.iBin += me->getNbinsX() + 2;
438 
439  return true;
440  }
441 
443  MESet const *meSet(bin_.getMESet());
444  if (bin_.iME == unsigned(-1) || bin_.iBin < 1)
445  return false;
446 
447  MonitorElement::Kind kind(meSet->getKind());
449  return false;
450 
451  MonitorElement const *me(meSet->getME(bin_.iME));
452 
453  if (bin_.iBin / (me->getNbinsX() + 2) <= 1)
454  return false;
455 
456  bin_.iBin -= me->getNbinsX() + 2;
457 
458  return true;
459  }
460 
462  MESet const *meSet(bin_.getMESet());
463  if (bin_.iME == unsigned(-1) || bin_.iBin < 1)
464  return false;
465 
466  MonitorElement::Kind kind(meSet->getKind());
468  return false;
469 
470  MonitorElement const *me(meSet->getME(bin_.iME));
471 
472  if (bin_.iBin % (me->getNbinsX() + 2) <= 1)
473  return false;
474 
475  bin_.iBin -= 1;
476 
477  return true;
478  }
479 
481  MESet const *meSet(bin_.getMESet());
482  if (bin_.iME == unsigned(-1) || bin_.iBin < 1)
483  return false;
484 
485  MonitorElement::Kind kind(meSet->getKind());
487  return false;
488 
489  MonitorElement const *me(meSet->getME(bin_.iME));
490 
491  if (bin_.iBin % (me->getNbinsX() + 2) >= me->getNbinsX())
492  return false;
493 
494  bin_.iBin += 1;
495 
496  return true;
497  }
498 } // namespace ecaldqm
virtual std::string const & getPath() const
Definition: MESet.h:120
MonitorElement::Kind kind_
Definition: MESet.h:156
MonitorElement::Kind getKind() const
Definition: MESet.h:123
virtual void setAxisTitle(std::string const &, int=1)
Definition: MESet.cc:89
const_iterator & operator++()
Definition: MESet.cc:363
int zside() const
Definition: EcalScDetId.h:64
std::vector< DetId > constituentsOf(const EcalTrigTowerDetId &id) const
Get the constituent detids for this tower id.
MESet const * meSet_
Definition: MESet.h:166
binning::ObjectType otype
Definition: MESet.h:171
constexpr Process operator++(Process p)
Definition: DataFormats.h:68
void throw_(std::string const &_message) const
Definition: MESet.h:149
ObjectType getObject(ObjectType, unsigned)
unsigned ttId(DetId const &, EcalElectronicsMapping const *)
virtual ~MESet()
Definition: MESet.cc:62
virtual bool maskMatches(DetId const &, uint32_t, StatusManager const *, EcalTrigTowerConstituentsMap const *) const
Definition: MESet.cc:170
virtual MonitorElement const * getME(unsigned _iME) const
Definition: MESet.h:126
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
virtual MESet * clone(std::string const &="") const
Definition: MESet.cc:75
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
int findBin2D(EcalElectronicsMapping const *, ObjectType, BinningType, DetId const &)
int iy() const
Definition: EcalScDetId.h:76
ConstBin & operator=(ConstBin const &)
Definition: MESet.cc:329
virtual void fill_(unsigned, int, double)
Definition: MESet.cc:252
bool isEcalScDetId(DetId const &)
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
Definition: DetId.h:17
unsigned findPlotIndex(EcalElectronicsMapping const *, ObjectType, DetId const &)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
std::string & path_
virtual void resetAll(double=0., double=0., double=0.)
Definition: MESet.cc:108
const_iterator & toNextChannel(EcalElectronicsMapping const *)
Definition: MESet.cc:413
bool active_
Definition: MESet.h:161
EcalScDetId sc() const
Definition: EEDetId.h:89
float x
void setMESet(MESet const &_meSet)
Definition: MESet.h:216
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)
binning::ObjectType otype_
Definition: MESet.h:154
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:57
uint32_t getStatus(uint32_t) const
binning::ObjectType getObjType() const
Definition: MESet.h:121
virtual MESet & operator=(MESet const &)
Definition: MESet.cc:64
binning::BinningType btype_
Definition: MESet.h:155
virtual void reset(EcalElectronicsMapping const *, double=0., double=0., double=0.)
Definition: MESet.cc:98
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
std::string path_
Definition: MESet.h:153
virtual void clear() const
Definition: MESet.cc:84
binning::BinningType getBinType() const
Definition: MESet.h:122
std::vector< MonitorElement * > mes_
Definition: MESet.h:151
std::string formPath(PathReplacements const &) const
Definition: MESet.cc:153
int ix() const
Definition: EcalScDetId.h:70