CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MESetNonObject.cc
Go to the documentation of this file.
2 
3 namespace ecaldqm
4 {
5  MESetNonObject::MESetNonObject(std::string const& _fullPath, binning::ObjectType _otype, binning::BinningType _btype, MonitorElement::Kind _kind, binning::AxisSpecs const* _xaxis/* = 0*/, binning::AxisSpecs const* _yaxis/* = 0*/, binning::AxisSpecs const* _zaxis/* = 0*/) :
6  MESet(_fullPath, _otype, _btype, _kind),
7  xaxis_(_xaxis ? new binning::AxisSpecs(*_xaxis) : 0),
8  yaxis_(_yaxis ? new binning::AxisSpecs(*_yaxis) : 0),
9  zaxis_(_zaxis ? new binning::AxisSpecs(*_zaxis) : 0)
10  {
11  }
12 
14  MESet(_orig),
15  xaxis_(_orig.xaxis_ ? new binning::AxisSpecs(*_orig.xaxis_) : 0),
16  yaxis_(_orig.yaxis_ ? new binning::AxisSpecs(*_orig.yaxis_) : 0),
17  zaxis_(_orig.zaxis_ ? new binning::AxisSpecs(*_orig.zaxis_) : 0)
18  {
19  }
20 
22  {
23  delete xaxis_;
24  delete yaxis_;
25  delete zaxis_;
26  }
27 
28  MESet&
30  {
31  delete xaxis_;
32  delete yaxis_;
33  delete zaxis_;
34  xaxis_ = 0;
35  yaxis_ = 0;
36  zaxis_ = 0;
37 
38  MESetNonObject const* pRhs(dynamic_cast<MESetNonObject const*>(&_rhs));
39  if(pRhs){
40  if(pRhs->xaxis_) xaxis_ = new binning::AxisSpecs(*pRhs->xaxis_);
41  if(pRhs->yaxis_) yaxis_ = new binning::AxisSpecs(*pRhs->yaxis_);
42  if(pRhs->zaxis_) zaxis_ = new binning::AxisSpecs(*pRhs->zaxis_);
43  }
44  return MESet::operator=(_rhs);
45  }
46 
47  MESet*
48  MESetNonObject::clone(std::string const& _path/* = ""*/) const
49  {
51  if(_path != "") path_ = _path;
52  MESet* copy(new MESetNonObject(*this));
53  path_ = path;
54  return copy;
55  }
56 
57  void
59  {
60  using namespace std;
61 
62  clear();
63 
64  if(path_.find('%') != string::npos)
65  throw_("book() called with incompletely formed path");
66 
67  size_t slashPos(path_.find_last_of('/'));
68  string name(path_.substr(slashPos + 1));
69  _ibooker.setCurrentFolder(path_.substr(0, slashPos));
70 
71  MonitorElement* me(0);
72 
73  switch(kind_) {
75  me = _ibooker.bookFloat(name);
76  break;
77 
79  {
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  }
88  break;
89 
91  {
92  if(!xaxis_)
93  throw_("No xaxis found for MESetNonObject");
94 
95  double ylow, yhigh;
96  if(!yaxis_){
99  }
100  else{
101  ylow = yaxis_->low;
102  yhigh = yaxis_->high;
103  }
104  if(xaxis_->edges){
105  // DQMStore bookProfile interface uses double* for bin edges
106  double* edges(new double[xaxis_->nbins + 1]);
107  std::copy(xaxis_->edges, xaxis_->edges + xaxis_->nbins + 1, edges);
108  me = _ibooker.bookProfile(name, name, xaxis_->nbins, edges, ylow, yhigh, "");
109  delete edges;
110  }
111  else
112  me = _ibooker.bookProfile(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, ylow, yhigh, "");
113  }
114  break;
115 
117  {
118  if(!xaxis_ || !yaxis_)
119  throw_("No x/yaxis found for MESetNonObject");
120 
121  if(!xaxis_->edges || !yaxis_->edges) // unlike MESetEcal, if either of X or Y is not set as variable, binning will be fixed
122  me = _ibooker.book2D(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, yaxis_->nbins, yaxis_->low, yaxis_->high);
123  else
124  me = _ibooker.book2D(name, name, xaxis_->nbins, xaxis_->edges, yaxis_->nbins, yaxis_->edges);
125  }
126  break;
127 
129  {
130  if(!xaxis_ || !yaxis_)
131  throw_("No x/yaxis found for MESetNonObject");
132  if(xaxis_->edges || yaxis_->edges)
133  throw_("Variable bin size for 2D profile not implemented");
134 
135  double high(0.), low(0.);
136  if(zaxis_){
137  low = zaxis_->low;
138  high = zaxis_->high;
139  }
140  else{
143  }
144 
145  me = _ibooker.bookProfile2D(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, yaxis_->nbins, yaxis_->low, yaxis_->high, low, high, "");
146  }
147  break;
148 
149  default :
150  throw_("Unsupported MonitorElement kind");
151  }
152 
153  if(xaxis_){
154  me->setAxisTitle(xaxis_->title, 1);
155  if(xaxis_->labels){
156  for(int iBin(1); iBin <= xaxis_->nbins; ++iBin)
157  me->setBinLabel(iBin, xaxis_->labels[iBin - 1], 1);
158  }
159  }
160  if(yaxis_){
161  me->setAxisTitle(yaxis_->title, 2);
162  if(yaxis_->labels){
163  for(int iBin(1); iBin <= yaxis_->nbins; ++iBin)
164  me->setBinLabel(iBin, yaxis_->labels[iBin - 1], 2);
165  }
166  }
167  if(zaxis_){
168  me->setAxisTitle(zaxis_->title, 3);
169  if(zaxis_->labels){
170  for(int iBin(1); iBin <= zaxis_->nbins; ++iBin)
171  me->setBinLabel(iBin, zaxis_->labels[iBin - 1], 3);
172  }
173  }
174 
175  if(lumiFlag_) me->setLumiFlag();
176 
177  mes_.push_back(me);
178 
179  active_ = true;
180  }
181 
182  bool
183  MESetNonObject::retrieve(DQMStore::IGetter& _igetter, std::string* _failedPath/* = 0*/) const
184  {
185  mes_.clear();
186 
187  MonitorElement* me(_igetter.get(path_));
188  if(!me){
189  if(_failedPath) *_failedPath = path_;
190  return false;
191  }
192 
193  mes_.push_back(me);
194 
195  active_ = true;
196  return true;
197  }
198 
199  void
200  MESetNonObject::fill(double _x, double _wy/* = 1.*/, double _w/* = 1.*/)
201  {
202  if(!active_) return;
203 
204  if(mes_.size() == 0 || !mes_[0]) return;
205 
206  switch(kind_) {
208  mes_[0]->Fill(_x);
209  break;
212  mes_[0]->Fill(_x, _wy);
213  break;
216  mes_[0]->Fill(_x, _wy, _w);
217  break;
218  default :
219  break;
220  }
221  }
222 
223  void
225  {
226  if(!active_) return;
227  if(kind_ == MonitorElement::DQM_KIND_REAL) return;
228 
229  if(mes_.size() == 0 || !mes_[0]) return;
230 
231  mes_[0]->setBinContent(_bin, _content);
232  }
233 
234  void
235  MESetNonObject::setBinError(int _bin, double _error)
236  {
237  if(!active_) return;
238  if(kind_ == MonitorElement::DQM_KIND_REAL) return;
239 
240  if(mes_.size() == 0 || !mes_[0]) return;
241 
242  mes_[0]->setBinError(_bin, _error);
243  }
244 
245  void
246  MESetNonObject::setBinEntries(int _bin, double _entries)
247  {
248  if(!active_) return;
250 
251  if(mes_.size() == 0 || !mes_[0]) return;
252 
253  mes_[0]->setBinEntries(_bin, _entries);
254  }
255 
256  double
257  MESetNonObject::getBinContent(int _bin, int) const
258  {
259  if(!active_) return 0.;
260  if(kind_ == MonitorElement::DQM_KIND_REAL) return 0.;
261 
262  if(mes_.size() == 0 || !mes_[0]) return 0.;
263 
264  return mes_[0]->getBinContent(_bin);
265  }
266 
267  double
268  MESetNonObject::getBinError(int _bin, int) const
269  {
270  if(!active_) return 0.;
271  if(kind_ == MonitorElement::DQM_KIND_REAL) return 0.;
272 
273  if(mes_.size() == 0 || !mes_[0]) return 0.;
274 
275  return mes_[0]->getBinError(_bin);
276  }
277 
278  double
279  MESetNonObject::getBinEntries(int _bin, int) const
280  {
281  if(!active_) return 0.;
283 
284  if(mes_.size() == 0 || !mes_[0]) return 0.;
285 
286  return mes_[0]->getBinEntries(_bin);
287  }
288 
289  int
290  MESetNonObject::findBin(double _x, double _y/* = 0.*/) const
291  {
292  if(!active_) return 0;
293 
294  if(mes_.size() == 0 || !mes_[0]) return 0;
295 
297  return mes_[0]->getTH1()->FindBin(_x);
299  return mes_[0]->getTH1()->FindBin(_x, _y);
300  else
301  return 0;
302  }
303 
304  bool
306  {
307  return (xaxis_ && xaxis_->edges) || (yaxis_ && yaxis_->edges) || (zaxis_ && zaxis_->edges);
308  }
309 }
binning::AxisSpecs const * zaxis_
MonitorElement::Kind kind_
Definition: MESet.h:134
MESet & operator=(MESet const &) override
void setBinEntries(int, double) override
double getBinError(int, int=0) const override
double getBinEntries(int, int=0) const override
virtual void clear() const
Definition: MESet.cc:93
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:157
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:301
binning::AxisSpecs const * xaxis_
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
std::vector< MonitorElement * > mes_
Definition: MESet.h:129
void book(DQMStore::IBooker &) override
void setBinContent(int, double) override
void throw_(std::string const &_message) const
Definition: MESet.h:124
MonitorElement * bookProfile2D(Args &&...args)
Definition: DQMStore.h:163
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
int findBin(double, double=0.) const
bool lumiFlag_
Definition: MESet.h:135
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:273
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
bool retrieve(DQMStore::IGetter &, std::string *=0) const override
bool active_
Definition: MESet.h:138
MESetNonObject(std::string const &, binning::ObjectType, binning::BinningType, MonitorElement::Kind, binning::AxisSpecs const *=0, binning::AxisSpecs const *=0, binning::AxisSpecs const *=0)
void fill(double, double=1., double=1.) override
MonitorElement * bookFloat(Args &&...args)
Definition: DQMStore.h:109
virtual MESet & operator=(MESet const &)
Definition: MESet.cc:70
void setLumiFlag(void)
this ME is meant to be stored for each luminosity section
MESet * clone(std::string const &="") const override
std::string path_
Definition: MESet.h:131
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
double getBinContent(int, int=0) const override
bool isVariableBinning() const override