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::DQM_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),
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(double _content /* = 0.*/, double _err /* = 0.*/, double _entries /* = 0.*/) {
99  if (!active_)
100  return;
101 
102  resetAll(_content, _err, _entries);
103  }
104 
105  void MESet::resetAll(double _content /* = 0.*/, double _err /* = 0.*/, double _entries /* = 0.*/) {
106  if (!active_)
107  return;
108 
109  unsigned nME(mes_.size());
110 
112  for (unsigned iME(0); iME < nME; iME++)
113  mes_[iME]->Fill(_content);
114  return;
115  }
116 
117  bool simple(true);
118  if (_content != 0. || _err != 0. || _entries != 0.)
119  simple = false;
120 
121  for (unsigned iME(0); iME < nME; iME++) {
122  TH1 *h(mes_[iME]->getTH1());
123  h->Reset();
124  if (simple)
125  continue;
126 
127  int nbinsX(h->GetNbinsX());
128  int nbinsY(h->GetNbinsY());
129  double entries(0.);
130  for (int ix(1); ix <= nbinsX; ix++) {
131  for (int iy(1); iy <= nbinsY; iy++) {
132  int bin(h->GetBin(ix, iy));
133  h->SetBinContent(bin, _content);
134  h->SetBinError(bin, _err);
136  static_cast<TProfile *>(h)->SetBinEntries(bin, _entries);
137  entries += _entries;
139  static_cast<TProfile2D *>(h)->SetBinEntries(bin, _entries);
140  entries += _entries;
141  }
142  }
143  }
144  if (entries == 0.)
145  entries = _entries;
146  h->SetEntries(_entries);
147  }
148  }
149 
150  std::string MESet::formPath(std::map<std::string, std::string> const &_replacements) const {
151  TString path(path_);
152 
153  for (typename MESet::PathReplacements::const_iterator repItr(_replacements.begin()); repItr != _replacements.end();
154  ++repItr) {
155  TString pattern("\\%\\(");
156  pattern += repItr->first;
157  pattern += "\\)s";
158 
159  TPRegexp re(pattern);
160 
161  re.Substitute(path, repItr->second, "g");
162  }
163 
164  return path.Data();
165  }
166 
167  bool MESet::maskMatches(DetId const &_id, uint32_t _mask, StatusManager const *_statusManager) const {
168  if (!_statusManager)
169  return false;
170 
171  if ((_statusManager->getStatus(_id.rawId()) & _mask) != 0)
172  return true;
173 
174  int subdet(_id.subdetId());
175 
176  bool searchNeighborsInTower(btype_ == binning::kTriggerTower || btype_ == binning::kSuperCrystal);
177 
178  // turn off masking for good channel for the time being
179  // update the RenderPlugin then enable again
180 
181  switch (subdet) {
182  case EcalBarrel: // this is a DetId for single crystal in barrel
183  {
184  EBDetId ebId(_id);
185  EcalTrigTowerDetId ttId(ebId.tower());
186  if ((_statusManager->getStatus(ttId.rawId()) & _mask) != 0)
187  return true;
188 
189  if (searchNeighborsInTower) {
190  std::vector<DetId> ids(getTrigTowerMap()->constituentsOf(ttId));
191  for (std::vector<DetId>::iterator idItr(ids.begin()); idItr != ids.end(); ++idItr)
192  if ((_statusManager->getStatus(idItr->rawId()) & _mask) != 0)
193  return true;
194  }
195  } break;
196 
197  case EcalEndcap:
198  if (isEcalScDetId(_id)) {
199  EcalScDetId scId(_id);
200  for (int ix(1); ix <= 5; ix++) {
201  for (int iy(1); iy <= 5; iy++) {
202  int iix((scId.ix() - 1) * 5 + ix);
203  int iiy((scId.iy() - 1) * 5 + iy);
204  if (!EEDetId::validDetId(iix, iiy, scId.zside()))
205  continue;
206  if ((_statusManager->getStatus(EEDetId(iix, iiy, scId.zside()).rawId()) & _mask) != 0)
207  return true;
208  }
209  }
210  } else {
211  EEDetId eeId(_id);
212  EcalScDetId scId(eeId.sc());
213  if ((_statusManager->getStatus(scId.rawId()) & _mask) != 0)
214  return true;
215 
216  if (searchNeighborsInTower) {
217  for (int ix(1); ix <= 5; ix++) {
218  for (int iy(1); iy <= 5; iy++) {
219  int iix((scId.ix() - 1) * 5 + ix);
220  int iiy((scId.iy() - 1) * 5 + iy);
221  if (!EEDetId::validDetId(iix, iiy, scId.zside()))
222  continue;
223  if ((_statusManager->getStatus(EEDetId(iix, iiy, scId.zside()).rawId()) & _mask) != 0)
224  return true;
225  }
226  }
227  }
228  }
229  break;
230 
231  case EcalTriggerTower: {
233  std::vector<DetId> ids(getTrigTowerMap()->constituentsOf(ttId));
234  for (std::vector<DetId>::iterator idItr(ids.begin()); idItr != ids.end(); ++idItr)
235  if ((_statusManager->getStatus(idItr->rawId()) & _mask) != 0)
236  return true;
237  } break;
238 
239  default:
240  break;
241  }
242 
243  return false;
244  }
245 
247  if (!active_)
248  return;
249 
250  DQMStore &store(*edm::Service<DQMStore>());
251 
252  for (unsigned iME(0); iME < mes_.size(); ++iME)
253  store.softReset(mes_[iME]);
254  }
255 
257  if (!active_)
258  return;
259 
260  DQMStore &store(*edm::Service<DQMStore>());
261 
262  for (unsigned iME(0); iME < mes_.size(); ++iME)
263  store.disableSoftReset(mes_[iME]);
264  }
265 
266  void MESet::fill_(unsigned _iME, int _bin, double _w) {
268  return;
269 
270  MonitorElement *me(mes_[_iME]);
271  if (!me)
272  return;
273 
274  TH1 *h(me->getTH1());
275 
276  int nbinsX(h->GetNbinsX());
277 
278  double x(h->GetXaxis()->GetBinCenter(_bin % (nbinsX + 2)));
279 
281  me->Fill(x, _w);
282  else {
283  double y(h->GetYaxis()->GetBinCenter(_bin / (nbinsX + 2)));
284  me->Fill(x, y, _w);
285  }
286  }
287 
288  void MESet::fill_(unsigned _iME, int _bin, double _y, double _w) {
290  return;
291 
292  MonitorElement *me(mes_[_iME]);
293  if (!me)
294  return;
295 
296  TH1 *h(me->getTH1());
297 
298  int nbinsX(h->GetNbinsX());
299 
300  double x(h->GetXaxis()->GetBinCenter(_bin % (nbinsX + 2)));
301  me->Fill(x, _y, _w);
302  }
303 
304  void MESet::fill_(unsigned _iME, double _x, double _wy, double _w) {
305  MonitorElement *me(mes_[_iME]);
306  if (!me)
307  return;
308 
310  me->Fill(_x);
312  me->Fill(_x, _wy);
313  else
314  me->Fill(_x, _wy, _w);
315  }
316 
317  MESet::ConstBin::ConstBin(MESet const &_meSet, unsigned _iME /* = 0*/, int _iBin /* = 1*/)
318  : meSet_(&_meSet), iME(_iME), iBin(_iBin), otype(binning::nObjType) {
319  if (iME == unsigned(-1))
320  return;
321 
322  // current internal bin numbering scheme does not allow 1D histograms
323  // (overflow & underflow in each y)
325  // if(kind != MonitorElement::DQM_KIND_TH1F && kind !=
326  // MonitorElement::DQM_KIND_TPROFILE &&
328  throw cms::Exception("InvalidOperation") << "MESet::ConstBin::Ctor: const_iterator only available for MESet of "
329  "2D histograms";
330 
331  MonitorElement const *me(meSet_->getME(iME));
332 
333  if (!me)
334  throw cms::Exception("InvalidOperation")
335  << "MESet::ConstBin::Ctor: ME " << iME << " does not exist for MESet " << meSet_->getPath();
336 
338  iBin = me->getNbinsX() + 3;
339 
341  }
342 
344  if (meSet_->getObjType() != _rhs.meSet_->getObjType() || meSet_->getBinType() != _rhs.meSet_->getBinType())
345  throw cms::Exception("IncompatibleAssignment")
346  << "Iterator of otype " << _rhs.meSet_->getObjType() << " and btype " << _rhs.meSet_->getBinType()
347  << " to otype " << meSet_->getObjType() << " and btype " << meSet_->getBinType() << " ("
348  << _rhs.meSet_->getPath() << " to " << meSet_->getPath() << ")";
349 
350  iME = _rhs.iME;
351  iBin = _rhs.iBin;
352  otype = _rhs.otype;
353 
354  return *this;
355  }
356 
357  MESet::const_iterator::const_iterator(MESet const &_meSet, DetId const &_id) : bin_() {
358  binning::ObjectType otype(_meSet.getObjType());
359  unsigned iME(binning::findPlotIndex(otype, _id));
360  if (iME == unsigned(-1))
361  return;
362 
363  binning::BinningType btype(_meSet.getBinType());
364  int bin(binning::findBin2D(otype, btype, _id));
365  if (bin == 0)
366  return;
367 
368  bin_.setMESet(_meSet);
369  bin_.iME = iME;
370  bin_.iBin = bin;
371  bin_.otype = otype;
372  }
373 
375  unsigned &iME(bin_.iME);
376  MESet const *meSet(bin_.getMESet());
377 
378  if (iME == unsigned(-1))
379  return *this;
380 
381  int &bin(bin_.iBin);
383 
384  MonitorElement::Kind kind(meSet->getKind());
385  MonitorElement const *me(meSet->getME(iME));
386 
387  int nbinsX(me->getNbinsX());
388 
389  ++bin;
390  if (bin == 1) {
391  iME = 0;
392  me = meSet->getME(iME);
393  nbinsX = me->getNbinsX();
395  bin = nbinsX + 3;
396  otype = binning::getObject(meSet->getObjType(), iME);
397  }
398 
399  if (bin % (nbinsX + 2) == nbinsX + 1) {
401  bin / (nbinsX + 2) == me->getNbinsY()) {
402  iME += 1;
403  me = meSet->getME(iME);
404  if (!me) {
405  iME = unsigned(-1);
406  bin = -1;
407  otype = binning::nObjType;
408  } else {
409  nbinsX = me->getNbinsX();
411  bin = nbinsX + 3;
412  else
413  bin = 1;
414 
415  otype = binning::getObject(meSet->getObjType(), iME);
416  }
417  } else
418  bin += 2;
419  }
420 
421  return *this;
422  }
423 
425  if (!bin_.getMESet())
426  return *this;
427  do
428  operator++();
429  while (bin_.iME != unsigned(-1) && !bin_.isChannel());
430 
431  return *this;
432  }
433 
435  MESet const *meSet(bin_.getMESet());
436  if (bin_.iME == unsigned(-1) || bin_.iBin < 1)
437  return false;
438 
439  MonitorElement::Kind kind(meSet->getKind());
441  return false;
442 
443  MonitorElement const *me(meSet->getME(bin_.iME));
444 
445  if (bin_.iBin / (me->getNbinsX() + 2) >= me->getNbinsY())
446  return false;
447 
448  bin_.iBin += me->getNbinsX() + 2;
449 
450  return true;
451  }
452 
454  MESet const *meSet(bin_.getMESet());
455  if (bin_.iME == unsigned(-1) || bin_.iBin < 1)
456  return false;
457 
458  MonitorElement::Kind kind(meSet->getKind());
460  return false;
461 
462  MonitorElement const *me(meSet->getME(bin_.iME));
463 
464  if (bin_.iBin / (me->getNbinsX() + 2) <= 1)
465  return false;
466 
467  bin_.iBin -= me->getNbinsX() + 2;
468 
469  return true;
470  }
471 
473  MESet const *meSet(bin_.getMESet());
474  if (bin_.iME == unsigned(-1) || bin_.iBin < 1)
475  return false;
476 
477  MonitorElement::Kind kind(meSet->getKind());
479  return false;
480 
481  MonitorElement const *me(meSet->getME(bin_.iME));
482 
483  if (bin_.iBin % (me->getNbinsX() + 2) <= 1)
484  return false;
485 
486  bin_.iBin -= 1;
487 
488  return true;
489  }
490 
492  MESet const *meSet(bin_.getMESet());
493  if (bin_.iME == unsigned(-1) || bin_.iBin < 1)
494  return false;
495 
496  MonitorElement::Kind kind(meSet->getKind());
498  return false;
499 
500  MonitorElement const *me(meSet->getME(bin_.iME));
501 
502  if (bin_.iBin % (me->getNbinsX() + 2) >= me->getNbinsX())
503  return false;
504 
505  bin_.iBin += 1;
506 
507  return true;
508  }
509 } // namespace ecaldqm
510 
511 namespace boost {
512  template <>
513  inline ecaldqm::MESet *new_clone<ecaldqm::MESet>(ecaldqm::MESet const &_s) {
514  return _s.clone();
515  }
516  template <>
517  void delete_clone<ecaldqm::MESet>(ecaldqm::MESet const *_s) {
518  checked_delete(_s);
519  }
520 } // namespace boost
virtual std::string const & getPath() const
Definition: MESet.h:91
MonitorElement::Kind kind_
Definition: MESet.h:129
virtual MonitorElement const * getME(unsigned _iME) const
Definition: MESet.h:97
MonitorElement::Kind getKind() const
Definition: MESet.h:94
virtual void setAxisTitle(std::string const &, int=1)
Definition: MESet.cc:89
const_iterator & operator++()
Definition: MESet.cc:374
Definition: CLHEP.h:16
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
def copy(args, dbName)
virtual void clear() const
Definition: MESet.cc:84
uint32_t getStatus(uint32_t) const
bool isChannel() const
Definition: MESet.h:153
MESet const * meSet_
Definition: MESet.h:139
binning::ObjectType otype
Definition: MESet.h:144
TH1 * getTH1() const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
virtual MESet * clone(std::string const &="") const
Definition: MESet.cc:75
bool batchMode_
Definition: MESet.h:132
ObjectType getObject(ObjectType, unsigned)
virtual bool maskMatches(DetId const &, uint32_t, StatusManager const *) const
Definition: MESet.cc:167
unsigned ttId(DetId const &)
virtual ~MESet()
Definition: MESet.cc:62
void Fill(long long x)
void disableSoftReset(MonitorElement *me)
Definition: DQMStore.cc:3288
binning::ObjectType getObjType() const
Definition: MESet.h:92
int ix() const
Definition: EcalScDetId.h:70
void throw_(std::string const &_message) const
Definition: MESet.h:122
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
EcalTrigTowerConstituentsMap const * getTrigTowerMap()
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
virtual void reset(double=0., double=0., double=0.)
Definition: MESet.cc:98
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:57
void softReset(MonitorElement *me)
Definition: DQMStore.cc:3280
bool lumiFlag_
Definition: MESet.h:130
int iy() const
Definition: EcalScDetId.h:76
ConstBin & operator=(ConstBin const &)
Definition: MESet.cc:343
virtual void fill_(unsigned, int, double)
Definition: MESet.cc:266
std::string formPath(PathReplacements const &) const
Definition: MESet.cc:150
bin
set the eta bin as selection string.
bool isEcalScDetId(DetId const &)
Definition: DetId.h:18
MESet const * getMESet() const
Definition: MESet.h:190
int findBin2D(ObjectType, BinningType, DetId const &)
virtual void softReset()
Definition: MESet.cc:246
unsigned findPlotIndex(ObjectType, DetId const &)
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
std::string & path_
EcalScDetId sc() const
Definition: EEDetId.h:89
int zside() const
Definition: EcalScDetId.h:64
binning::BinningType getBinType() const
Definition: MESet.h:93
virtual void resetAll(double=0., double=0., double=0.)
Definition: MESet.cc:105
bool active_
Definition: MESet.h:134
virtual void recoverStats()
Definition: MESet.cc:256
void setMESet(MESet const &_meSet)
Definition: MESet.h:189
binning::ObjectType otype_
Definition: MESet.h:127
const_iterator & toNextChannel()
Definition: MESet.cc:424
virtual MESet & operator=(MESet const &)
Definition: MESet.cc:64
binning::BinningType btype_
Definition: MESet.h:128
std::string path_
Definition: MESet.h:126
std::vector< MonitorElement * > mes_
Definition: MESet.h:124