CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MESetNonObject.cc
Go to the documentation of this file.
2 
3 namespace ecaldqm {
5  binning::ObjectType _otype,
8  binning::AxisSpecs const *_xaxis /* = 0*/,
9  binning::AxisSpecs const *_yaxis /* = 0*/,
10  binning::AxisSpecs const *_zaxis /* = 0*/)
11  : MESet(_fullPath, _otype, _btype, _kind),
12  xaxis_(_xaxis ? new binning::AxisSpecs(*_xaxis) : nullptr),
13  yaxis_(_yaxis ? new binning::AxisSpecs(*_yaxis) : nullptr),
14  zaxis_(_zaxis ? new binning::AxisSpecs(*_zaxis) : nullptr) {}
15 
17  : MESet(_orig),
18  xaxis_(_orig.xaxis_ ? new binning::AxisSpecs(*_orig.xaxis_) : nullptr),
19  yaxis_(_orig.yaxis_ ? new binning::AxisSpecs(*_orig.yaxis_) : nullptr),
20  zaxis_(_orig.zaxis_ ? new binning::AxisSpecs(*_orig.zaxis_) : nullptr) {}
21 
23  delete xaxis_;
24  delete yaxis_;
25  delete zaxis_;
26  }
27 
29  delete xaxis_;
30  delete yaxis_;
31  delete zaxis_;
32  xaxis_ = nullptr;
33  yaxis_ = nullptr;
34  zaxis_ = nullptr;
35 
36  MESetNonObject const *pRhs(dynamic_cast<MESetNonObject const *>(&_rhs));
37  if (pRhs) {
38  if (pRhs->xaxis_)
39  xaxis_ = new binning::AxisSpecs(*pRhs->xaxis_);
40  if (pRhs->yaxis_)
41  yaxis_ = new binning::AxisSpecs(*pRhs->yaxis_);
42  if (pRhs->zaxis_)
43  zaxis_ = new binning::AxisSpecs(*pRhs->zaxis_);
44  }
45  return MESet::operator=(_rhs);
46  }
47 
48  MESet *MESetNonObject::clone(std::string const &_path /* = ""*/) const {
50  if (!_path.empty())
51  path_ = _path;
52  MESet *copy(new MESetNonObject(*this));
53  path_ = path;
54  return copy;
55  }
56 
57  void MESetNonObject::book(DQMStore::IBooker &_ibooker, EcalElectronicsMapping const *electronicsMap) {
58  using namespace std;
59 
60  clear();
61 
62  if (path_.find('%') != string::npos)
63  throw_("book() called with incompletely formed path");
64 
65  size_t slashPos(path_.find_last_of('/'));
66  string name(path_.substr(slashPos + 1));
67  _ibooker.setCurrentFolder(path_.substr(0, slashPos));
68  auto oldscope = MonitorElementData::Scope::RUN;
69  if (lumiFlag_)
70  oldscope = _ibooker.setScope(MonitorElementData::Scope::LUMI);
71 
72  MonitorElement *me(nullptr);
73 
74  switch (kind_) {
76  me = _ibooker.bookFloat(name);
77  break;
78 
80  if (!xaxis_)
81  throw_("No xaxis found for MESetNonObject");
82 
83  if (xaxis_->edges)
84  me = _ibooker.book1D(name, name, xaxis_->nbins, xaxis_->edges);
85  else
86  me = _ibooker.book1D(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high);
87  } break;
88 
90  if (!xaxis_)
91  throw_("No xaxis found for MESetNonObject");
92 
93  double ylow, yhigh;
94  if (!yaxis_) {
97  } else {
98  ylow = yaxis_->low;
99  yhigh = yaxis_->high;
100  }
101  if (xaxis_->edges) {
102  // DQMStore bookProfile interface uses double* for bin edges
103  double *edges(new double[xaxis_->nbins + 1]);
104  std::copy(xaxis_->edges, xaxis_->edges + xaxis_->nbins + 1, edges);
105  me = _ibooker.bookProfile(name, name, xaxis_->nbins, edges, ylow, yhigh, "");
106  delete[] edges;
107  } else
108  me = _ibooker.bookProfile(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, ylow, yhigh, "");
109  } break;
110 
112  if (!xaxis_ || !yaxis_)
113  throw_("No x/yaxis found for MESetNonObject");
114 
115  if (!xaxis_->edges || !yaxis_->edges) // unlike MESetEcal, if either of X or Y is not set as
116  // variable, binning will be fixed
117  me = _ibooker.book2D(
119  else
120  me = _ibooker.book2D(name, name, xaxis_->nbins, xaxis_->edges, yaxis_->nbins, yaxis_->edges);
121  } break;
122 
124  if (!xaxis_ || !yaxis_)
125  throw_("No x/yaxis found for MESetNonObject");
126  if (xaxis_->edges || yaxis_->edges)
127  throw_("Variable bin size for 2D profile not implemented");
128 
129  double high(0.), low(0.);
130  if (zaxis_) {
131  low = zaxis_->low;
132  high = zaxis_->high;
133  } else {
136  }
137 
138  me = _ibooker.bookProfile2D(name,
139  name,
140  xaxis_->nbins,
141  xaxis_->low,
142  xaxis_->high,
143  yaxis_->nbins,
144  yaxis_->low,
145  yaxis_->high,
146  low,
147  high,
148  "");
149  } break;
150 
151  default:
152  throw_("Unsupported MonitorElement kind");
153  }
154 
155  if (xaxis_) {
156  me->setAxisTitle(xaxis_->title, 1);
157  if (xaxis_->labels) {
158  for (int iBin(1); iBin <= xaxis_->nbins; ++iBin)
159  me->setBinLabel(iBin, xaxis_->labels[iBin - 1], 1);
160  }
161  }
162  if (yaxis_) {
163  me->setAxisTitle(yaxis_->title, 2);
164  if (yaxis_->labels) {
165  for (int iBin(1); iBin <= yaxis_->nbins; ++iBin)
166  me->setBinLabel(iBin, yaxis_->labels[iBin - 1], 2);
167  }
168  }
169  if (zaxis_) {
170  me->setAxisTitle(zaxis_->title, 3);
171  if (zaxis_->labels) {
172  for (int iBin(1); iBin <= zaxis_->nbins; ++iBin)
173  me->setBinLabel(iBin, zaxis_->labels[iBin - 1], 3);
174  }
175  }
176 
177  if (lumiFlag_)
178  _ibooker.setScope(oldscope);
179 
180  mes_.push_back(me);
181 
182  active_ = true;
183  }
184 
186  DQMStore::IGetter &_igetter,
187  std::string *_failedPath /* = 0*/) const {
188  mes_.clear();
189 
190  MonitorElement *me(_igetter.get(path_));
191  if (!me) {
192  if (_failedPath)
193  *_failedPath = path_;
194  return false;
195  }
196 
197  mes_.push_back(me);
198 
199  active_ = true;
200  return true;
201  }
202 
203  void MESetNonObject::fill(EcalDQMSetupObjects const edso, double _x, double _wy /* = 1.*/, double _w /* = 1.*/) {
204  if (!active_)
205  return;
206 
207  if (mes_.empty() || !mes_[0])
208  return;
209 
210  switch (kind_) {
212  mes_[0]->Fill(_x);
213  break;
216  mes_[0]->Fill(_x, _wy);
217  break;
220  mes_[0]->Fill(_x, _wy, _w);
221  break;
222  default:
223  break;
224  }
225  }
226 
227  void MESetNonObject::setBinContent(EcalDQMSetupObjects const edso, int _bin, double _content) {
228  if (!active_)
229  return;
231  return;
232 
233  if (mes_.empty() || !mes_[0])
234  return;
235 
236  mes_[0]->setBinContent(_bin, _content);
237  }
238 
239  void MESetNonObject::setBinError(EcalDQMSetupObjects const edso, int _bin, double _error) {
240  if (!active_)
241  return;
243  return;
244 
245  if (mes_.empty() || !mes_[0])
246  return;
247 
248  mes_[0]->setBinError(_bin, _error);
249  }
250 
251  void MESetNonObject::setBinEntries(EcalDQMSetupObjects const edso, int _bin, double _entries) {
252  if (!active_)
253  return;
255  return;
256 
257  if (mes_.empty() || !mes_[0])
258  return;
259 
260  mes_[0]->setBinEntries(_bin, _entries);
261  }
262 
263  double MESetNonObject::getBinContent(EcalDQMSetupObjects const edso, int _bin, int) const {
264  if (!active_)
265  return 0.;
267  return 0.;
268 
269  if (mes_.empty() || !mes_[0])
270  return 0.;
271 
272  return mes_[0]->getBinContent(_bin);
273  }
274 
277  return mes_[0]->getFloatValue();
278  else
279  return 0.;
280  }
281 
282  double MESetNonObject::getBinError(EcalDQMSetupObjects const edso, int _bin, int) const {
283  if (!active_)
284  return 0.;
286  return 0.;
287 
288  if (mes_.empty() || !mes_[0])
289  return 0.;
290 
291  return mes_[0]->getBinError(_bin);
292  }
293 
294  double MESetNonObject::getBinEntries(EcalDQMSetupObjects const edso, int _bin, int) const {
295  if (!active_)
296  return 0.;
298  return 0.;
299 
300  if (mes_.empty() || !mes_[0])
301  return 0.;
302 
303  return mes_[0]->getBinEntries(_bin);
304  }
305 
306  int MESetNonObject::findBin(EcalDQMSetupObjects const edso, double _x, double _y /* = 0.*/) const {
307  if (!active_)
308  return 0;
309 
310  if (mes_.empty() || !mes_[0])
311  return 0;
312 
314  return mes_[0]->getTH1()->FindBin(_x);
316  return mes_[0]->getTH1()->FindBin(_x, _y);
317  else
318  return 0;
319  }
320 
322  return (xaxis_ && xaxis_->edges) || (yaxis_ && yaxis_->edges) || (zaxis_ && zaxis_->edges);
323  }
324 } // namespace ecaldqm
binning::AxisSpecs const * zaxis_
MonitorElement::Kind kind_
Definition: MESet.h:156
MESet & operator=(MESet const &) override
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
MonitorElement * bookProfile2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, double lowZ, double highZ, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:476
double getBinContent(EcalDQMSetupObjects const, int, int=0) const override
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
virtual void clear() const
Definition: MESet.cc:84
void fill(EcalDQMSetupObjects const, double, double=1., double=1.) override
binning::AxisSpecs const * xaxis_
void setBinEntries(EcalDQMSetupObjects const, int, double) override
virtual MonitorElementData::Scope setScope(MonitorElementData::Scope newscope)
Definition: DQMStore.cc:46
binning::AxisSpecs const * yaxis_
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:399
void throw_(std::string const &_message) const
Definition: MESet.h:149
double getBinError(EcalDQMSetupObjects const, int, int=0) const override
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
double getBinEntries(EcalDQMSetupObjects const, int, int=0) const override
void book(DQMStore::IBooker &, EcalElectronicsMapping const *) override
bool lumiFlag_
Definition: MESet.h:157
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
MESetNonObject(std::string const &, binning::ObjectType, binning::BinningType, MonitorElement::Kind, binning::AxisSpecs const *=nullptr, binning::AxisSpecs const *=nullptr, binning::AxisSpecs const *=nullptr)
void setBinError(EcalDQMSetupObjects const, int, double) override
bool retrieve(EcalElectronicsMapping const *, DQMStore::IGetter &, std::string *=nullptr) const override
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
bool active_
Definition: MESet.h:161
tuple binning
Definition: pileupCalc.py:163
int findBin(EcalDQMSetupObjects const, double, double=0.) const
double getFloatValue() const
void setBinContent(EcalDQMSetupObjects const, int, double) override
virtual MESet & operator=(MESet const &)
Definition: MESet.cc:64
MESet * clone(std::string const &="") const override
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
std::string path_
Definition: MESet.h:153
bool isVariableBinning() const override
std::vector< MonitorElement * > mes_
Definition: MESet.h:151
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)