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(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;
138  } else if (kind_ == MonitorElement::Kind::TPROFILE2D) {
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 
246  void MESet::fill_(unsigned _iME, int _bin, double _w) {
248  return;
249 
250  MonitorElement *me(mes_[_iME]);
251  if (!me)
252  return;
253 
254  TH1 *h(me->getTH1());
255 
256  int nbinsX(h->GetNbinsX());
257 
258  double x(h->GetXaxis()->GetBinCenter(_bin % (nbinsX + 2)));
259 
261  me->Fill(x, _w);
262  else {
263  double y(h->GetYaxis()->GetBinCenter(_bin / (nbinsX + 2)));
264  me->Fill(x, y, _w);
265  }
266  }
267 
268  void MESet::fill_(unsigned _iME, int _bin, double _y, double _w) {
270  return;
271 
272  MonitorElement *me(mes_[_iME]);
273  if (!me)
274  return;
275 
276  TH1 *h(me->getTH1());
277 
278  int nbinsX(h->GetNbinsX());
279 
280  double x(h->GetXaxis()->GetBinCenter(_bin % (nbinsX + 2)));
281  me->Fill(x, _y, _w);
282  }
283 
284  void MESet::fill_(unsigned _iME, double _x, double _wy, double _w) {
285  MonitorElement *me(mes_[_iME]);
286  if (!me)
287  return;
288 
290  me->Fill(_x);
292  me->Fill(_x, _wy);
293  else
294  me->Fill(_x, _wy, _w);
295  }
296 
297  MESet::ConstBin::ConstBin(MESet const &_meSet, unsigned _iME /* = 0*/, int _iBin /* = 1*/)
298  : meSet_(&_meSet), iME(_iME), iBin(_iBin), otype(binning::nObjType) {
299  if (iME == unsigned(-1))
300  return;
301 
302  // current internal bin numbering scheme does not allow 1D histograms
303  // (overflow & underflow in each y)
305  // if(kind != MonitorElement::Kind::TH1F && kind !=
306  // MonitorElement::Kind::TPROFILE &&
308  throw cms::Exception("InvalidOperation") << "MESet::ConstBin::Ctor: const_iterator only available for MESet of "
309  "2D histograms";
310 
311  MonitorElement const *me(meSet_->getME(iME));
312 
313  if (!me)
314  throw cms::Exception("InvalidOperation")
315  << "MESet::ConstBin::Ctor: ME " << iME << " does not exist for MESet " << meSet_->getPath();
316 
318  iBin = me->getNbinsX() + 3;
319 
321  }
322 
324  if (meSet_->getObjType() != _rhs.meSet_->getObjType() || meSet_->getBinType() != _rhs.meSet_->getBinType())
325  throw cms::Exception("IncompatibleAssignment")
326  << "Iterator of otype " << _rhs.meSet_->getObjType() << " and btype " << _rhs.meSet_->getBinType()
327  << " to otype " << meSet_->getObjType() << " and btype " << meSet_->getBinType() << " ("
328  << _rhs.meSet_->getPath() << " to " << meSet_->getPath() << ")";
329 
330  iME = _rhs.iME;
331  iBin = _rhs.iBin;
332  otype = _rhs.otype;
333 
334  return *this;
335  }
336 
337  MESet::const_iterator::const_iterator(MESet const &_meSet, DetId const &_id) : bin_() {
339  unsigned iME(binning::findPlotIndex(otype, _id));
340  if (iME == unsigned(-1))
341  return;
342 
344  int bin(binning::findBin2D(otype, btype, _id));
345  if (bin == 0)
346  return;
347 
348  bin_.setMESet(_meSet);
349  bin_.iME = iME;
350  bin_.iBin = bin;
351  bin_.otype = otype;
352  }
353 
355  unsigned &iME(bin_.iME);
356  MESet const *meSet(bin_.getMESet());
357 
358  if (iME == unsigned(-1))
359  return *this;
360 
361  int &bin(bin_.iBin);
362  binning::ObjectType &otype(bin_.otype);
363 
364  MonitorElement::Kind kind(meSet->getKind());
365  MonitorElement const *me(meSet->getME(iME));
366 
367  int nbinsX(me->getNbinsX());
368 
369  ++bin;
370  if (bin == 1) {
371  iME = 0;
372  me = meSet->getME(iME);
373  nbinsX = me->getNbinsX();
375  bin = nbinsX + 3;
376  otype = binning::getObject(meSet->getObjType(), iME);
377  }
378 
379  if (bin % (nbinsX + 2) == nbinsX + 1) {
381  bin / (nbinsX + 2) == me->getNbinsY()) {
382  iME += 1;
383  me = meSet->getME(iME);
384  if (!me) {
385  iME = unsigned(-1);
386  bin = -1;
388  } else {
389  nbinsX = me->getNbinsX();
391  bin = nbinsX + 3;
392  else
393  bin = 1;
394 
395  otype = binning::getObject(meSet->getObjType(), iME);
396  }
397  } else
398  bin += 2;
399  }
400 
401  return *this;
402  }
403 
405  if (!bin_.getMESet())
406  return *this;
407  do
408  operator++();
409  while (bin_.iME != unsigned(-1) && !bin_.isChannel());
410 
411  return *this;
412  }
413 
415  MESet const *meSet(bin_.getMESet());
416  if (bin_.iME == unsigned(-1) || bin_.iBin < 1)
417  return false;
418 
419  MonitorElement::Kind kind(meSet->getKind());
421  return false;
422 
423  MonitorElement const *me(meSet->getME(bin_.iME));
424 
425  if (bin_.iBin / (me->getNbinsX() + 2) >= me->getNbinsY())
426  return false;
427 
428  bin_.iBin += me->getNbinsX() + 2;
429 
430  return true;
431  }
432 
434  MESet const *meSet(bin_.getMESet());
435  if (bin_.iME == unsigned(-1) || bin_.iBin < 1)
436  return false;
437 
438  MonitorElement::Kind kind(meSet->getKind());
440  return false;
441 
442  MonitorElement const *me(meSet->getME(bin_.iME));
443 
444  if (bin_.iBin / (me->getNbinsX() + 2) <= 1)
445  return false;
446 
447  bin_.iBin -= me->getNbinsX() + 2;
448 
449  return true;
450  }
451 
453  MESet const *meSet(bin_.getMESet());
454  if (bin_.iME == unsigned(-1) || bin_.iBin < 1)
455  return false;
456 
457  MonitorElement::Kind kind(meSet->getKind());
459  return false;
460 
461  MonitorElement const *me(meSet->getME(bin_.iME));
462 
463  if (bin_.iBin % (me->getNbinsX() + 2) <= 1)
464  return false;
465 
466  bin_.iBin -= 1;
467 
468  return true;
469  }
470 
472  MESet const *meSet(bin_.getMESet());
473  if (bin_.iME == unsigned(-1) || bin_.iBin < 1)
474  return false;
475 
476  MonitorElement::Kind kind(meSet->getKind());
478  return false;
479 
480  MonitorElement const *me(meSet->getME(bin_.iME));
481 
482  if (bin_.iBin % (me->getNbinsX() + 2) >= me->getNbinsX())
483  return false;
484 
485  bin_.iBin += 1;
486 
487  return true;
488  }
489 } // namespace ecaldqm
490 
491 namespace boost {
492  template <>
493  inline ecaldqm::MESet *new_clone<ecaldqm::MESet>(ecaldqm::MESet const &_s) {
494  return _s.clone();
495  }
496  template <>
497  void delete_clone<ecaldqm::MESet>(ecaldqm::MESet const *_s) {
498  checked_delete(_s);
499  }
500 } // namespace boost
ecaldqm::MESet::throw_
void throw_(std::string const &_message) const
Definition: MESet.h:121
funct::false
false
Definition: Factorize.h:34
ecaldqm
Definition: DQWorker.h:24
ecaldqm::MESet::getObjType
binning::ObjectType getObjType() const
Definition: MESet.h:93
ecaldqm::MESet::fill_
virtual void fill_(unsigned, int, double)
Definition: MESet.cc:246
ecaldqm::binning::kSuperCrystal
Definition: MESetBinningUtils.h:43
ecaldqm::MESet::getME
virtual const MonitorElement * getME(unsigned _iME) const
Definition: MESet.h:98
ecaldqm::MESet::const_iterator::up
bool up()
Definition: MESet.cc:414
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
ecaldqm::MESet::const_iterator::down
bool down()
Definition: MESet.cc:433
ecaldqm::MESet::const_iterator::operator++
const_iterator & operator++()
Definition: MESet.cc:354
ecaldqm::MESet::const_iterator::right
bool right()
Definition: MESet.cc:471
MonitorElementData::Kind::TH1F
EBDetId
Definition: EBDetId.h:17
EcalScDetId::zside
int zside() const
Definition: EcalScDetId.h:64
ecaldqm::MESet::operator=
virtual MESet & operator=(MESet const &)
Definition: MESet.cc:64
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
ecaldqm::ttId
unsigned ttId(DetId const &)
Definition: EcalDQMCommonUtils.cc:101
hlt_dqm_clientPB-live_cfg.nbinsX
nbinsX
Definition: hlt_dqm_clientPB-live_cfg.py:60
MESet.h
ecaldqm::MESet::ConstBin::ConstBin
ConstBin()
Definition: MESet.h:145
dqm::legacy::MonitorElement
Definition: MonitorElement.h:461
EcalTrigTowerDetId
Definition: EcalTrigTowerDetId.h:14
boost
Definition: CLHEP.h:16
ecaldqm::MESet::ConstBin::otype
binning::ObjectType otype
Definition: MESet.h:143
EcalBarrel
Definition: EcalSubdetector.h:10
ecaldqm::MESet::const_iterator::toNextChannel
const_iterator & toNextChannel()
Definition: MESet.cc:404
ecaldqm::MESet::getBinType
binning::BinningType getBinType() const
Definition: MESet.h:94
ecaldqm::MESet::ConstBin::meSet_
const MESet * meSet_
Definition: MESet.h:138
MonitorElementData::Kind::TH2F
ecaldqm::MESet::ConstBin::iBin
int iBin
Definition: MESet.h:142
DetId
Definition: DetId.h:17
StatusManager.h
EBDetId::tower
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:57
ecaldqm::MESet::clone
virtual MESet * clone(std::string const &="") const
Definition: MESet.cc:75
ecaldqm::MESet::setAxisTitle
virtual void setAxisTitle(std::string const &, int=1)
Definition: MESet.cc:89
Service.h
cond::time::INVALID
static constexpr TimeType INVALID
Definition: Time.h:33
EcalScDetId
Definition: EcalScDetId.h:24
h
ecaldqm::binning::getObject
ObjectType getObject(ObjectType, unsigned)
Definition: MESetBinningUtils.cc:467
ecaldqm::MESet::otype_
binning::ObjectType otype_
Definition: MESet.h:126
ecaldqm::MESet::~MESet
virtual ~MESet()
Definition: MESet.cc:62
ParameterSetDescription.h
ecaldqm::MESet::active_
bool active_
Definition: MESet.h:133
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
EEDetId
Definition: EEDetId.h:14
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ecaldqm::MESet::const_iterator::const_iterator
const_iterator()
Definition: MESet.h:246
EcalEndcap
Definition: EcalSubdetector.h:10
hlt_dqm_clientPB-live_cfg.nbinsY
nbinsY
Definition: hlt_dqm_clientPB-live_cfg.py:64
listHistos.binning
binning
Definition: listHistos.py:43
ecaldqm::binning::ObjectType
ObjectType
Definition: MESetBinningUtils.h:17
ecaldqm::MESet::btype_
binning::BinningType btype_
Definition: MESet.h:127
MonitorElementData::Kind
Kind
Definition: MonitorElementCollection.h:129
ecaldqm::isEcalScDetId
bool isEcalScDetId(DetId const &)
Definition: EcalDQMCommonUtils.cc:266
ecaldqm::MESet::path_
std::string path_
Definition: MESet.h:125
EcalScDetId::iy
int iy() const
Definition: EcalScDetId.h:76
ecaldqm::binning::findPlotIndex
unsigned findPlotIndex(ObjectType, DetId const &)
Definition: MESetBinningUtils.cc:299
topSingleLeptonDQM_PU_cfi.pattern
pattern
Definition: topSingleLeptonDQM_PU_cfi.py:39
ecaldqm::MESet::reset
virtual void reset(double=0., double=0., double=0.)
Definition: MESet.cc:98
EEDetId::sc
EcalScDetId sc() const
Definition: EEDetId.h:89
CalibrationSummaryClient_cfi.kind
kind
Definition: CalibrationSummaryClient_cfi.py:37
ecaldqm::getTrigTowerMap
const EcalTrigTowerConstituentsMap * getTrigTowerMap()
Definition: EcalDQMCommonUtils.cc:458
HcalObjRepresent::Fill
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
Definition: HcalObjRepresent.h:1053
ecaldqm::MESet::mes_
std::vector< MonitorElement * > mes_
Definition: MESet.h:123
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
ecaldqm::StatusManager::getStatus
uint32_t getStatus(uint32_t) const
Definition: StatusManager.cc:246
CalibrationSummaryClient_cfi.btype
btype
Definition: CalibrationSummaryClient_cfi.py:39
ecaldqm::MESet::ConstBin
Definition: MESet.h:136
ecaldqm::StatusManager
Definition: StatusManager.h:14
CalibrationSummaryClient_cfi.otype
otype
Definition: CalibrationSummaryClient_cfi.py:38
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
EcalTriggerTower
Definition: EcalSubdetector.h:10
ecaldqm::MESet::const_iterator
Definition: MESet.h:245
MonitorElementData::Kind::TPROFILE2D
ecaldqm::MESet::clear
virtual void clear() const
Definition: MESet.cc:84
ecaldqm::MESet::const_iterator::bin_
ConstBin bin_
Definition: MESet.h:265
ecaldqm::MESet::ConstBin::iME
unsigned iME
Definition: MESet.h:141
ecaldqm::MESet::ConstBin::operator=
ConstBin & operator=(ConstBin const &)
Definition: MESet.cc:323
ecaldqm::binning::nObjType
Definition: MESetBinningUtils.h:37
Exception
Definition: hltDiff.cc:246
ecaldqm::MESet::formPath
std::string formPath(PathReplacements const &) const
Definition: MESet.cc:150
MESetUtils.h
ecaldqm::MESet::MESet
MESet()
Definition: MESet.cc:14
ecaldqm::MESet::const_iterator::left
bool left()
Definition: MESet.cc:452
ecaldqm::binning::nBinType
Definition: MESetBinningUtils.h:53
ecaldqm::MESet::getPath
virtual const std::string & getPath() const
Definition: MESet.h:92
EEDetId::validDetId
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
ecaldqm::binning::findBin2D
int findBin2D(ObjectType, BinningType, DetId const &)
Definition: MESetBinningUtils.cc:242
cms::Exception
Definition: Exception.h:70
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
ecaldqm::binning::BinningType
BinningType
Definition: MESetBinningUtils.h:40
path_
std::string & path_
Definition: PluginManager.cc:222
hlt_dqm_clientPB-live_cfg.me
me
Definition: hlt_dqm_clientPB-live_cfg.py:56
ecaldqm::MESet::resetAll
virtual void resetAll(double=0., double=0., double=0.)
Definition: MESet.cc:105
ecaldqm::MESet::maskMatches
virtual bool maskMatches(DetId const &, uint32_t, StatusManager const *) const
Definition: MESet.cc:167
ecaldqm::MESet::kind_
MonitorElement::Kind kind_
Definition: MESet.h:128
ecaldqm::binning::kTriggerTower
Definition: MESetBinningUtils.h:42
btvTracks_cfi._content
_content
Definition: btvTracks_cfi.py:5
MonitorElementData::Kind::TPROFILE
ecaldqm::MESet::getKind
MonitorElement::Kind getKind() const
Definition: MESet.h:95
EcalScDetId::ix
int ix() const
Definition: EcalScDetId.h:70
MonitorElementData::Kind::REAL
ecaldqm::MESet::ConstBin::setMESet
void setMESet(MESet const &_meSet)
Definition: MESet.h:188
EcalDQMCommonUtils.h
ecaldqm::binning::kChannel
Definition: MESetBinningUtils.h:36
ecaldqm::MESet
Definition: MESet.h:27