CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MESet.cc
Go to the documentation of this file.
2 
4 
7 
8 #include "TString.h"
9 #include "TPRegexp.h"
10 
11 namespace ecaldqm
12 {
15 
16  MESet::MESet(std::string const& _fullpath, MEData const& _data, bool _readOnly/* = false*/) :
17  mes_(0),
18  dir_(_fullpath.substr(0, _fullpath.find_last_of('/'))),
19  name_(_fullpath.substr(_fullpath.find_last_of('/') + 1)),
20  data_(&_data),
21  active_(false),
22  readOnly_(_readOnly)
23  {
24  if (!binService_) {
26  if(!binService_)
27  throw cms::Exception("Service") << "EcalDQMBinningService not found" << std::endl;
28  }
29 
30  if (!dqmStore_) {
32  if(!dqmStore_)
33  throw cms::Exception("Service") << "DQMStore not found" << std::endl;
34  }
35 
36  // expand full path into dir & name
37  if(_fullpath.size() == 0)
38  throw cms::Exception("InvalidConfiguration") << "MonitorElement path empty";
39  }
40 
42  {
43  }
44 
45  void
47  {
48  clear();
49  active_ = true;
50  }
51 
52  bool
54  {
55  return false;
56  }
57 
58  void
59  MESet::clear() const
60  {
61  active_ = false;
62  mes_.clear();
63  }
64 
65  void
66  MESet::setAxisTitle(std::string const& _title, int _axis/* = 1*/)
67  {
68  for(std::vector<MonitorElement*>::iterator meItr(mes_.begin()); meItr != mes_.end(); ++meItr)
69  (*meItr)->setAxisTitle(_title, _axis);
70  }
71 
72  void
73  MESet::setBinLabel(unsigned _offset, int _bin, std::string const& _label, int _axis/* = 1*/)
74  {
75  if(_offset == unsigned(-1)){
76  for(std::vector<MonitorElement*>::iterator meItr(mes_.begin()); meItr != mes_.end(); ++meItr)
77  (*meItr)->setBinLabel(_bin, _label, _axis);
78 
79  return;
80  }
81 
82  if(_offset >= mes_.size() || !mes_[_offset]) return;
83  mes_[_offset]->setBinLabel(_bin, _label, _axis);
84  }
85 
86  void
87  MESet::reset(double _content/* = 0.*/, double _err/* = 0.*/, double _entries/* = 0.*/)
88  {
89  resetAll(_content, _err, _entries);
90  }
91 
92  void
93  MESet::resetAll(double _content/* = 0.*/, double _err/* = 0.*/, double _entries/* = 0.*/)
94  {
96  for(std::vector<MonitorElement*>::iterator meItr(mes_.begin()); meItr != mes_.end(); ++meItr)
97  (*meItr)->Fill(_content);
98  return;
99  }
100 
101  bool simple(true);
102  if(_content != 0. || _err != 0. || _entries != 0.) simple = false;
103 
104  for(std::vector<MonitorElement*>::iterator meItr(mes_.begin()); meItr != mes_.end(); ++meItr){
105  TH1* h((*meItr)->getTH1());
106  h->Reset();
107  if(simple) continue;
108 
109  int nbinsX(h->GetNbinsX());
110  int nbinsY(h->GetNbinsY());
111  double entries(0.);
112  for(int ix(1); ix <= nbinsX; ix++){
113  for(int iy(1); iy <= nbinsY; iy++){
114  int bin(h->GetBin(ix, iy));
115  h->SetBinContent(bin, _content);
116  h->SetBinError(bin, _err);
118  static_cast<TProfile*>(h)->SetBinEntries(bin, _entries);
119  entries += _entries;
120  }
122  static_cast<TProfile2D*>(h)->SetBinEntries(bin, _entries);
123  entries += _entries;
124  }
125  }
126  }
127  if(entries == 0.) entries = _entries;
128  h->SetEntries(_entries);
129  }
130  }
131 
132  void
133  MESet::fill(DetId const&, double, double, double)
134  {
135  }
136 
137  void
138  MESet::fill(EcalElectronicsId const& _id, double _wx/* = 1.*/,double _wy/* = 1.*/, double _w/* = 1.*/)
139  {
140  fill(getElectronicsMap()->getDetId(_id), _wx, _wy, _w);
141  }
142 
143  void
144  MESet::fill(unsigned _dcctccid, double _wx/* = 1.*/, double _wy/* = 1.*/, double _w/* = 1.*/)
145  {
146  }
147 
148  void
149  MESet::fill(double, double, double)
150  {
151  }
152 
153  void
154  MESet::setBinContent(DetId const&, double, double)
155  {
156  }
157 
158  void
159  MESet::setBinContent(EcalElectronicsId const& _id, double _content, double _err/* = 0.*/)
160  {
161  setBinContent(getElectronicsMap()->getDetId(_id), _content, _err);
162  }
163 
164  void
165  MESet::setBinContent(unsigned, double, double)
166  {
167  }
168 
169  void
170  MESet::setBinEntries(DetId const&, double)
171  {
172  }
173 
174  void
175  MESet::setBinEntries(EcalElectronicsId const& _id, double _entries)
176  {
177  setBinEntries(getElectronicsMap()->getDetId(_id), _entries);
178  }
179 
180  void
181  MESet::setBinEntries(unsigned, double)
182  {
183  }
184 
185  double
186  MESet::getBinContent(DetId const&, int) const
187  {
188  return 0.;
189  }
190 
191  double
192  MESet::getBinContent(EcalElectronicsId const& _id, int _bin/* = 0*/) const
193  {
194  return getBinContent(getElectronicsMap()->getDetId(_id), _bin);
195  }
196 
197  double
198  MESet::getBinContent(unsigned, int) const
199  {
200  return 0.;
201  }
202 
203  double
204  MESet::getBinError(DetId const&, int) const
205  {
206  return 0.;
207  }
208 
209  double
210  MESet::getBinError(EcalElectronicsId const& _id, int _bin/* = 0*/) const
211  {
212  return getBinError(getElectronicsMap()->getDetId(_id), _bin);
213  }
214 
215  double
216  MESet::getBinError(unsigned, int) const
217  {
218  return 0.;
219  }
220 
221  double
222  MESet::getBinEntries(DetId const&, int) const
223  {
224  return 0.;
225  }
226 
227  double
228  MESet::getBinEntries(EcalElectronicsId const& _id, int _bin/* = 0*/) const
229  {
230  return getBinEntries(getElectronicsMap()->getDetId(_id), _bin);
231  }
232 
233  double
234  MESet::getBinEntries(unsigned, int) const
235  {
236  return 0.;
237  }
238 
239  void
240  MESet::name(std::map<std::string, std::string> const& _replacements) const
241  {
242  TString dir(dir_);
243  TString name(name_);
244 
245  for(std::map<std::string, std::string>::const_iterator repItr(_replacements.begin()); repItr != _replacements.end(); ++repItr){
246 
247  TString pattern("\\%\\(");
248  pattern += repItr->first;
249  pattern += "\\)s";
250 
251  TPRegexp re(pattern);
252 
253  re.Substitute(dir, repItr->second, "g");
254  re.Substitute(name, repItr->second, "g");
255  }
256 
257  dir_ = dir.Data();
258  name_ = name.Data();
259  }
260 
261  void
262  MESet::fill_(unsigned _index, int _bin, double _w)
263  {
264  MonitorElement* me(mes_.at(_index));
265 
266  TH1* h(me->getTH1());
267 
268  int nbinsX(h->GetNbinsX());
269 
270  double x(h->GetXaxis()->GetBinCenter((_bin - 1) % nbinsX + 1));
271 
273  me->Fill(x, _w);
274  return;
275  }
276 
277  double y(h->GetYaxis()->GetBinCenter((_bin - 1) / nbinsX + 1));
278 
279  me->Fill(x, y, _w);
280  }
281 
282  void
283  MESet::fill_(unsigned _offset, double _x, double _wy, double _w)
284  {
286  mes_.at(_offset)->Fill(_x);
288  mes_.at(_offset)->Fill(_x, _wy);
289  else
290  mes_.at(_offset)->Fill(_x, _wy, _w);
291  }
292 
293  void
294  MESet::setBinContent_(unsigned _index, int _bin, double _content, double _err)
295  {
296  MonitorElement* me(mes_.at(_index));
297 
299  me->setBinContent(_bin, _content);
300  me->setBinError(_bin, _err);
301  }
302  else{
303  TH1* h(me->getTH1());
304  int nbinsX(h->GetNbinsX());
305  int ix((_bin - 1) % nbinsX + 1);
306  int iy((_bin - 1) / nbinsX + 1);
307  me->setBinContent(ix, iy, _content);
308  me->setBinError(ix, iy, _err);
309  }
310  }
311 
312  void
313  MESet::setBinEntries_(unsigned _index, int _bin, double _entries)
314  {
315  MonitorElement* me(mes_.at(_index));
316 
318  me->setBinEntries(_bin, _entries);
319  }
321  TH1* h(me->getTH1());
322  int nbinsX(h->GetNbinsX());
323  int ix((_bin - 1) % nbinsX + 1);
324  int iy((_bin - 1) / nbinsX + 1);
325  me->setBinEntries(h->GetBin(ix, iy), _entries);
326  }
327  }
328 
329  double
330  MESet::getBinContent_(unsigned _index, int _bin) const
331  {
332  MonitorElement* me(mes_.at(_index));
333 
335  return me->getBinContent(_bin);
336  else{
337  TH1* h(me->getTH1());
338  int nbinsX(h->GetNbinsX());
339  int ix((_bin - 1) % nbinsX + 1);
340  int iy((_bin - 1) / nbinsX + 1);
341  return h->GetBinContent(ix, iy);
342  }
343  }
344 
345  double
346  MESet::getBinError_(unsigned _index, int _bin) const
347  {
348  MonitorElement* me(mes_.at(_index));
349 
351  return me->getBinError(_bin);
352  else{
353  TH1* h(me->getTH1());
354  int nbinsX(h->GetNbinsX());
355  int ix((_bin - 1) % nbinsX + 1);
356  int iy((_bin - 1) / nbinsX + 1);
357  return h->GetBinError(ix, iy);
358  }
359  }
360 
361  double
362  MESet::getBinEntries_(unsigned _index, int _bin) const
363  {
364  MonitorElement* me(mes_.at(_index));
365 
366  switch(data_->kind){
368  return me->getBinContent(_bin);
370  return me->getBinEntries(_bin);
372  {
373  TH1* h(me->getTH1());
374  int nbinsX(h->GetNbinsX());
375  int ix((_bin - 1) % nbinsX + 1);
376  int iy((_bin - 1) / nbinsX + 1);
377  int bin(h->GetBin(ix, iy));
378  return me->getBinContent(bin);
379  }
381  {
382  TH1* h(me->getTH1());
383  int nbinsX(h->GetNbinsX());
384  int ix((_bin - 1) % nbinsX + 1);
385  int iy((_bin - 1) / nbinsX + 1);
386  int bin(h->GetBin(ix, iy));
387  return me->getBinEntries(bin);
388  }
389  default:
390  return 0.;
391  }
392  }
393 
394 }
void setBinContent(int binx, double content)
set content of bin (1-D)
const EcalElectronicsMapping * getElectronicsMap()
virtual void reset(double _content=0., double _err=0., double _entries=0.)
Definition: MESet.cc:87
static const char dir_[]
virtual void clear() const
Definition: MESet.cc:59
virtual void book()
Definition: MESet.cc:46
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
MonitorElement::Kind kind
Definition: MESet.h:24
virtual ~MESet()
Definition: MESet.cc:41
virtual void setBinContent(DetId const &, double, double _err=0.)
Definition: MESet.cc:154
virtual double getBinContent(DetId const &, int _bin=0) const
Definition: MESet.cc:186
std::vector< MonitorElement * > mes_
Definition: MESet.h:129
virtual void setBinEntries(DetId const &, double)
Definition: MESet.cc:170
virtual bool retrieve() const
Definition: MESet.cc:53
static DQMStore * dqmStore_
Definition: MESet.h:127
std::string dir_
Definition: MESet.h:131
virtual void setBinEntries_(unsigned, int, double)
Definition: MESet.cc:313
virtual void setBinContent_(unsigned, int, double, double)
Definition: MESet.cc:294
std::string name_
Definition: MESet.h:132
virtual void fill_(unsigned, int, double)
Definition: MESet.cc:262
virtual void setBinLabel(unsigned, int, std::string const &, int _axis=1)
Definition: MESet.cc:73
Definition: DetId.h:20
MESet(std::string const &, MEData const &, bool _readOnly=false)
Definition: MESet.cc:16
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
virtual double getBinContent_(unsigned, int) const
Definition: MESet.cc:330
double getBinError(int binx) const
get uncertainty on content of bin (1-D) - See TH1::GetBinError for details
virtual double getBinError_(unsigned, int) const
Definition: MESet.cc:346
static BinService const * binService_
Definition: MESet.h:126
virtual void setAxisTitle(std::string const &, int _axis=1)
Definition: MESet.cc:66
bool active_
Definition: MESet.h:135
virtual void fill(DetId const &, double _wx=1., double _wy=1., double _w=1.)
Definition: MESet.cc:133
double getBinContent(int binx) const
get content of bin (1-D)
MEData const * data_
Definition: MESet.h:133
virtual double getBinError(DetId const &, int _bin=0) const
Definition: MESet.cc:204
dbl *** dir
Definition: mlp_gen.cc:35
Definition: DDAxes.h:10
virtual double getBinEntries_(unsigned, int) const
Definition: MESet.cc:362
void setBinEntries(int bin, double nentries)
set # of bin entries (to be used for profiles)
virtual void resetAll(double _content=0., double _err=0., double _entries=0.)
Definition: MESet.cc:93
void name(std::map< std::string, std::string > const &) const
Definition: MESet.cc:240
virtual double getBinEntries(DetId const &, int _bin=0) const
Definition: MESet.cc:222