CMS 3D CMS Logo

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 
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 
69  MonitorElement *me(nullptr);
70 
71  switch (kind_) {
73  me = _ibooker.bookFloat(name);
74  break;
75 
77  if (!xaxis_)
78  throw_("No xaxis found for MESetNonObject");
79 
80  if (xaxis_->edges)
81  me = _ibooker.book1D(name, name, xaxis_->nbins, xaxis_->edges);
82  else
83  me = _ibooker.book1D(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high);
84  } break;
85 
87  if (!xaxis_)
88  throw_("No xaxis found for MESetNonObject");
89 
90  double ylow, yhigh;
91  if (!yaxis_) {
94  } else {
95  ylow = yaxis_->low;
96  yhigh = yaxis_->high;
97  }
98  if (xaxis_->edges) {
99  // DQMStore bookProfile interface uses double* for bin edges
100  double *edges(new double[xaxis_->nbins + 1]);
101  std::copy(xaxis_->edges, xaxis_->edges + xaxis_->nbins + 1, edges);
102  me = _ibooker.bookProfile(name, name, xaxis_->nbins, edges, ylow, yhigh, "");
103  delete[] edges;
104  } else
105  me = _ibooker.bookProfile(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, ylow, yhigh, "");
106  } break;
107 
109  if (!xaxis_ || !yaxis_)
110  throw_("No x/yaxis found for MESetNonObject");
111 
112  if (!xaxis_->edges || !yaxis_->edges) // unlike MESetEcal, if either of X or Y is not set as
113  // variable, binning will be fixed
114  me = _ibooker.book2D(
116  else
117  me = _ibooker.book2D(name, name, xaxis_->nbins, xaxis_->edges, yaxis_->nbins, yaxis_->edges);
118  } break;
119 
121  if (!xaxis_ || !yaxis_)
122  throw_("No x/yaxis found for MESetNonObject");
123  if (xaxis_->edges || yaxis_->edges)
124  throw_("Variable bin size for 2D profile not implemented");
125 
126  double high(0.), low(0.);
127  if (zaxis_) {
128  low = zaxis_->low;
129  high = zaxis_->high;
130  } else {
133  }
134 
135  me = _ibooker.bookProfile2D(name,
136  name,
137  xaxis_->nbins,
138  xaxis_->low,
139  xaxis_->high,
140  yaxis_->nbins,
141  yaxis_->low,
142  yaxis_->high,
143  low,
144  high,
145  "");
146  } break;
147 
148  default:
149  throw_("Unsupported MonitorElement kind");
150  }
151 
152  if (xaxis_) {
153  me->setAxisTitle(xaxis_->title, 1);
154  if (xaxis_->labels) {
155  for (int iBin(1); iBin <= xaxis_->nbins; ++iBin)
156  me->setBinLabel(iBin, xaxis_->labels[iBin - 1], 1);
157  }
158  }
159  if (yaxis_) {
160  me->setAxisTitle(yaxis_->title, 2);
161  if (yaxis_->labels) {
162  for (int iBin(1); iBin <= yaxis_->nbins; ++iBin)
163  me->setBinLabel(iBin, yaxis_->labels[iBin - 1], 2);
164  }
165  }
166  if (zaxis_) {
167  me->setAxisTitle(zaxis_->title, 3);
168  if (zaxis_->labels) {
169  for (int iBin(1); iBin <= zaxis_->nbins; ++iBin)
170  me->setBinLabel(iBin, zaxis_->labels[iBin - 1], 3);
171  }
172  }
173 
174  if (lumiFlag_)
175  me->setLumiFlag();
176 
177  mes_.push_back(me);
178 
179  active_ = true;
180  }
181 
182  bool MESetNonObject::retrieve(DQMStore::IGetter &_igetter, std::string *_failedPath /* = 0*/) const {
183  mes_.clear();
184 
185  MonitorElement *me(_igetter.get(path_));
186  if (!me) {
187  if (_failedPath)
188  *_failedPath = path_;
189  return false;
190  }
191 
192  mes_.push_back(me);
193 
194  active_ = true;
195  return true;
196  }
197 
198  void MESetNonObject::fill(double _x, double _wy /* = 1.*/, double _w /* = 1.*/) {
199  if (!active_)
200  return;
201 
202  if (mes_.empty() || !mes_[0])
203  return;
204 
205  switch (kind_) {
207  mes_[0]->Fill(_x);
208  break;
211  mes_[0]->Fill(_x, _wy);
212  break;
215  mes_[0]->Fill(_x, _wy, _w);
216  break;
217  default:
218  break;
219  }
220  }
221 
222  void MESetNonObject::setBinContent(int _bin, double _content) {
223  if (!active_)
224  return;
226  return;
227 
228  if (mes_.empty() || !mes_[0])
229  return;
230 
231  mes_[0]->setBinContent(_bin, _content);
232  }
233 
234  void MESetNonObject::setBinError(int _bin, double _error) {
235  if (!active_)
236  return;
238  return;
239 
240  if (mes_.empty() || !mes_[0])
241  return;
242 
243  mes_[0]->setBinError(_bin, _error);
244  }
245 
246  void MESetNonObject::setBinEntries(int _bin, double _entries) {
247  if (!active_)
248  return;
250  return;
251 
252  if (mes_.empty() || !mes_[0])
253  return;
254 
255  mes_[0]->setBinEntries(_bin, _entries);
256  }
257 
258  double MESetNonObject::getBinContent(int _bin, int) const {
259  if (!active_)
260  return 0.;
262  return 0.;
263 
264  if (mes_.empty() || !mes_[0])
265  return 0.;
266 
267  return mes_[0]->getBinContent(_bin);
268  }
269 
272  return mes_[0]->getFloatValue();
273  else
274  return 0.;
275  }
276 
277  double MESetNonObject::getBinError(int _bin, int) const {
278  if (!active_)
279  return 0.;
281  return 0.;
282 
283  if (mes_.empty() || !mes_[0])
284  return 0.;
285 
286  return mes_[0]->getBinError(_bin);
287  }
288 
289  double MESetNonObject::getBinEntries(int _bin, int) const {
290  if (!active_)
291  return 0.;
293  return 0.;
294 
295  if (mes_.empty() || !mes_[0])
296  return 0.;
297 
298  return mes_[0]->getBinEntries(_bin);
299  }
300 
301  int MESetNonObject::findBin(double _x, double _y /* = 0.*/) const {
302  if (!active_)
303  return 0;
304 
305  if (mes_.empty() || !mes_[0])
306  return 0;
307 
309  return mes_[0]->getTH1()->FindBin(_x);
311  return mes_[0]->getTH1()->FindBin(_x, _y);
312  else
313  return 0;
314  }
315 
317  return (xaxis_ && xaxis_->edges) || (yaxis_ && yaxis_->edges) || (zaxis_ && zaxis_->edges);
318  }
319 } // namespace ecaldqm
binning::AxisSpecs const * zaxis_
MonitorElement::Kind kind_
Definition: MESet.h:129
MESet & operator=(MESet const &) override
void setBinEntries(int, double) override
bool retrieve(DQMStore::IGetter &, std::string *=0) const override
def copy(args, dbName)
virtual void clear() const
Definition: MESet.cc:84
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:113
binning::AxisSpecs const * xaxis_
#define nullptr
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)
binning::AxisSpecs const * yaxis_
void setBinError(int, double) override
double getBinEntries(int, int=0) const override
double getBinContent(int, int=0) const override
void book(DQMStore::IBooker &) override
void setLumiFlag()
this ME is meant to be stored for each luminosity section
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
void setBinContent(int, double) override
void throw_(std::string const &_message) const
Definition: MESet.h:122
MonitorElement * bookProfile2D(Args &&...args)
Definition: DQMStore.h:114
double getBinError(int, int=0) const override
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
int findBin(double, double=0.) const
bool lumiFlag_
Definition: MESet.h:130
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:303
bool isVariableBinning() const override
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
bool active_
Definition: MESet.h:134
MESetNonObject(std::string const &, binning::ObjectType, binning::BinningType, MonitorElement::Kind, binning::AxisSpecs const *=0, binning::AxisSpecs const *=0, binning::AxisSpecs const *=0)
double getFloatValue() const
void fill(double, double=1., double=1.) override
MonitorElement * bookFloat(Args &&...args)
Definition: DQMStore.h:105
virtual MESet & operator=(MESet const &)
Definition: MESet.cc:64
std::string path_
Definition: MESet.h:126
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
MESet * clone(std::string const &="") const override
std::vector< MonitorElement * > mes_
Definition: MESet.h:124