CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MESetEcal.cc
Go to the documentation of this file.
2 
4 
6 
7 #include <limits>
8 
9 namespace ecaldqm
10 {
11 
12  MESetEcal::MESetEcal(std::string const& _fullpath, MEData const& _data, int _logicalDimensions, bool _readOnly/* = false*/) :
13  MESet(_fullpath, _data, _readOnly),
14  logicalDimensions_(_logicalDimensions),
15  cacheId_(0),
16  cache_(std::make_pair(-1, std::vector<int>(0)))
17  {
19  throw cms::Exception("InvalidCall") << "Need axis specifications" << std::endl;
20  }
21 
23  {
24  }
25 
26  void
28  {
29  using namespace std;
30 
31  clear();
32 
34 
35  if(data_->btype == BinService::kReport && name_ == "")
36  name_ = dir_.substr(0, dir_.find_first_of('/'));
37 
38  std::vector<std::string> meNames(generateNames());
39 
40  for(unsigned iME(0); iME < meNames.size(); iME++){
41  unsigned iObj(iME);
42 
44 
45  BinService::AxisSpecs xaxis, yaxis, zaxis;
46 
47  if(logicalDimensions_ > 0){
48  if(data_->xaxis){
49  xaxis = *data_->xaxis;
50  }
51  else{ // uses preset
52  bool isMap(logicalDimensions_ > 1);
53  vector<BinService::AxisSpecs> presetAxes(binService_->getBinning(actualObject, data_->btype, isMap, iObj));
54  if(presetAxes.size() != logicalDimensions_)
55  throw cms::Exception("InvalidCall") << "Dimensionality mismatch " << data_->otype << " " << data_->btype << " " << iObj << std::endl;
56 
57  xaxis = presetAxes[0];
58  if(isMap) yaxis = presetAxes[1];
59  }
60 
61  if(data_->yaxis){
62  yaxis = *data_->yaxis;
63  }
64  if(logicalDimensions_ == 1 && yaxis.high - yaxis.low < 0.0001){
67  }
68 
69  if(data_->zaxis){
70  zaxis = *data_->zaxis;
71  }
72  if(logicalDimensions_ > 1 && zaxis.high - zaxis.low < 0.0001){
75  }
76  }
77 
78  MonitorElement* me(0);
79 
80  switch(data_->kind) {
82  me = dqmStore_->bookFloat(meNames[iME]);
83 
84  break;
85 
87  if(xaxis.edges){
88  float* edges(new float[xaxis.nbins + 1]);
89  for(int i(0); i < xaxis.nbins + 1; i++)
90  edges[i] = xaxis.edges[i];
91  me = dqmStore_->book1D(meNames[iME], meNames[iME], xaxis.nbins, edges);
92  delete [] edges;
93  }
94  else
95  me = dqmStore_->book1D(meNames[iME], meNames[iME], xaxis.nbins, xaxis.low, xaxis.high);
96 
97  break;
98 
100  if(xaxis.edges) {
101  me = dqmStore_->bookProfile(meNames[iME], meNames[iME], xaxis.nbins, xaxis.edges, yaxis.low, yaxis.high, "");
102  }
103  else
104  me = dqmStore_->bookProfile(meNames[iME], meNames[iME], xaxis.nbins, xaxis.low, xaxis.high, yaxis.low, yaxis.high, "");
105 
106  break;
107 
109  if(xaxis.edges || yaxis.edges) {
110  BinService::AxisSpecs* specs[] = {&xaxis, &yaxis};
111  float* edges[] = {new float[xaxis.nbins + 1], new float[yaxis.nbins + 1]};
112  for(int iSpec(0); iSpec < 2; iSpec++){
113  if(specs[iSpec]->edges){
114  for(int i(0); i < specs[iSpec]->nbins + 1; i++)
115  edges[iSpec][i] = specs[iSpec]->edges[i];
116  }
117  else{
118  int nbins(specs[iSpec]->nbins);
119  double low(specs[iSpec]->low), high(specs[iSpec]->high);
120  for(int i(0); i < nbins + 1; i++)
121  edges[iSpec][i] = low + (high - low) / nbins * i;
122  }
123  }
124  me = dqmStore_->book2D(meNames[iME], meNames[iME], xaxis.nbins, edges[0], yaxis.nbins, edges[1]);
125  for(int iSpec(0); iSpec < 2; iSpec++)
126  delete [] edges[iSpec];
127  }
128  else
129  me = dqmStore_->book2D(meNames[iME], meNames[iME], xaxis.nbins, xaxis.low, xaxis.high, yaxis.nbins, yaxis.low, yaxis.high);
130 
131  break;
132 
134  if(zaxis.edges) {
135  zaxis.low = zaxis.edges[0];
136  zaxis.high = zaxis.edges[zaxis.nbins];
137  }
138  if(xaxis.edges || yaxis.edges)
139  throw cms::Exception("InvalidCall") << "Variable bin size for 2D profile not implemented" << std::endl;
140  me = dqmStore_->bookProfile2D(meNames[iME], meNames[iME], xaxis.nbins, xaxis.low, xaxis.high, yaxis.nbins, yaxis.low, yaxis.high, zaxis.low, zaxis.high, "");
141 
142  break;
143 
144  default :
145  break;
146  }
147 
148  if(!me)
149  throw cms::Exception("InvalidCall") << "ME could not be booked" << std::endl;
150 
151  if(logicalDimensions_ > 0){
152  me->setAxisTitle(xaxis.title, 1);
153  me->setAxisTitle(yaxis.title, 2);
154  // For plot tagging in RenderPlugin; default values are 1 for both
155  me->getTH1()->SetMarkerStyle(actualObject + 2);
156  me->getTH1()->SetMarkerStyle(data_->btype + 2);
157  }
158 
160  if(actualObject == BinService::kEB){
161  for(int iBin(1); iBin <= me->getNbinsX(); iBin++)
162  me->setBinLabel(iBin, binService_->channelName(iBin + kEBmLow));
163  }
164  else if(actualObject == BinService::kEE){
165  for(int iBin(1); iBin <= me->getNbinsX() / 2; iBin++){
166  unsigned dccid((iBin + 2) % 9 + 1);
167  me->setBinLabel(iBin, binService_->channelName(dccid));
168  }
169  for(int iBin(1); iBin <= me->getNbinsX() / 2; iBin++){
170  unsigned dccid((iBin + 2) % 9 + 46);
171  me->setBinLabel(iBin + me->getNbinsX() / 2, binService_->channelName(dccid));
172  }
173  }
174  else if(actualObject == BinService::kEEm){
175  for(int iBin(1); iBin <= me->getNbinsX(); iBin++){
176  unsigned dccid((iBin + 2) % 9 + 1);
177  me->setBinLabel(iBin, binService_->channelName(dccid));
178  }
179  }
180  else if(actualObject == BinService::kEEp){
181  for(int iBin(1); iBin <= me->getNbinsX(); iBin++){
182  unsigned dccid((iBin + 2) % 9 + 46);
183  me->setBinLabel(iBin, binService_->channelName(dccid));
184  }
185  }
186  }
187 
188  mes_.push_back(me);
189  }
190 
191  // To avoid the ambiguity between "content == 0 because the mean is 0" and "content == 0 because the entry is 0"
192  // RenderPlugin must be configured accordingly
195 
196  active_ = true;
197  }
198 
199  bool
201  {
202  clear();
203 
204  std::vector<std::string> meNames(generateNames());
205  if(meNames.size() == 0) return false;
206 
207  for(unsigned iME(0); iME < meNames.size(); iME++){
208  MonitorElement* me(dqmStore_->get(dir_ + "/" + meNames[iME]));
209  if(me) mes_.push_back(me);
210  else{
211  clear();
212  return false;
213  }
214  }
215 
216  active_ = true;
217  return true;
218  }
219 
220  void
221  MESetEcal::fill(DetId const& _id, double _x/* = 1.*/, double _wy/* = 1.*/, double _w/* = 1.*/)
222  {
223  unsigned offset(binService_->findOffset(data_->otype, _id));
224  if(offset >= mes_.size() || !mes_[offset])
225  throw cms::Exception("InvalidCall") << "ME array index overflow" << std::endl;
226 
227  MESet::fill_(offset, _x, _wy, _w);
228  }
229 
230  void
231  MESetEcal::fill(unsigned _dcctccid, double _x/* = 1.*/, double _wy/* = 1.*/, double _w/* = 1.*/)
232  {
233  unsigned offset(binService_->findOffset(data_->otype, data_->btype, _dcctccid));
234 
235  if(offset >= mes_.size() || !mes_[offset])
236  throw cms::Exception("InvalidCall") << "ME array index overflow" << offset << std::endl;
237 
238  MESet::fill_(offset, _x, _wy, _w);
239  }
240 
241  void
242  MESetEcal::fill(double _x, double _wy/* = 1.*/, double _w/* = 1.*/)
243  {
244  if(mes_.size() != 1)
245  throw cms::Exception("InvalidCall") << "MESet type incompatible" << std::endl;
246 
247  MESet::fill_(0, _x, _wy, _w);
248  }
249 
250  void
251  MESetEcal::setBinContent(DetId const& _id, double _content, double _err/* = 0.*/)
252  {
253  find_(_id);
254 
255  std::vector<int>& bins(cache_.second);
256  for(std::vector<int>::iterator binItr(bins.begin()); binItr != bins.end(); ++binItr)
257  setBinContent_(cache_.first, *binItr, _content, _err);
258  }
259 
260  void
261  MESetEcal::setBinContent(unsigned _dcctccid, double _content, double _err/* = 0.*/)
262  {
263  find_(_dcctccid);
264 
265  std::vector<int>& bins(cache_.second);
266  for(std::vector<int>::iterator binItr(bins.begin()); binItr != bins.end(); ++binItr)
267  setBinContent_(cache_.first, *binItr, _content, _err);
268  }
269 
270  void
271  MESetEcal::setBinEntries(DetId const& _id, double _entries)
272  {
273  find_(_id);
274 
275  std::vector<int>& bins(cache_.second);
276  for(std::vector<int>::iterator binItr(bins.begin()); binItr != bins.end(); ++binItr)
277  setBinEntries_(cache_.first, *binItr, _entries);
278  }
279 
280  void
281  MESetEcal::setBinEntries(unsigned _dcctccid, double _entries)
282  {
283  find_(_dcctccid);
284 
285  std::vector<int>& bins(cache_.second);
286  for(std::vector<int>::iterator binItr(bins.begin()); binItr != bins.end(); ++binItr)
287  setBinEntries_(cache_.first, *binItr, _entries);
288  }
289 
290  double
291  MESetEcal::getBinContent(DetId const& _id, int) const
292  {
293  find_(_id);
294 
295  if(cache_.second.size() == 0) return 0.;
296 
297  return getBinContent_(cache_.first, cache_.second[0]);
298  }
299 
300  double
301  MESetEcal::getBinContent(unsigned _dcctccid, int) const
302  {
303  find_(_dcctccid);
304 
305  if(cache_.second.size() == 0) return 0.;
306 
307  return getBinContent_(cache_.first, cache_.second[0]);
308  }
309 
310  double
311  MESetEcal::getBinError(DetId const& _id, int) const
312  {
313  find_(_id);
314 
315  if(cache_.second.size() == 0) return 0.;
316 
317  return getBinError_(cache_.first, cache_.second[0]);
318  }
319 
320  double
321  MESetEcal::getBinError(unsigned _dcctccid, int) const
322  {
323  find_(_dcctccid);
324 
325  if(cache_.second.size() == 0) return 0.;
326 
327  return getBinError_(cache_.first, cache_.second[0]);
328  }
329 
330  double
331  MESetEcal::getBinEntries(DetId const& _id, int) const
332  {
333  find_(_id);
334 
335  if(cache_.second.size() == 0) return 0.;
336 
337  return getBinEntries_(cache_.first, cache_.second[0]);
338  }
339 
340  double
341  MESetEcal::getBinEntries(unsigned _dcctccid, int) const
342  {
343  find_(_dcctccid);
344 
345  if(cache_.second.size() == 0) return 0.;
346 
347  return getBinEntries_(cache_.first, cache_.second[0]);
348  }
349 
350  void
351  MESetEcal::reset(double _content/* = 0.*/, double _err/* = 0.*/, double _entries/* = 0.*/)
352  {
353  using namespace std;
354 
355  if(data_->btype >= unsigned(BinService::nPresetBinnings)){
356  MESet::reset(_content, _err, _entries);
357  return;
358  }
359 
360  unsigned nME(1);
361  switch(data_->otype){
362  case BinService::kSM:
363  nME = BinService::nDCC;
364  break;
365  case BinService::kSMMEM:
366  nME = BinService::nDCCMEM;
367  break;
368  case BinService::kEcal2P:
369  nME = 2;
370  break;
371  case BinService::kEcal3P:
372  nME = 3;
373  break;
375  nME = 2;
376  break;
377  default:
378  break;
379  }
380 
381  for(unsigned iME(0); iME < nME; iME++) {
382  unsigned iObj(iME);
383 
386  if(okey == BinService::nObjType)
387  throw cms::Exception("InvalidCall") << "Undefined object & bin type";
388 
389  std::vector<int> const* binMap(binService_->getBinMap(okey, bkey));
390  if(!binMap)
391  throw cms::Exception("InvalidCall") << "Cannot retrieve bin map";
392 
393  for(std::vector<int>::const_iterator binItr(binMap->begin()); binItr != binMap->end(); ++binItr){
394  int bin(*binItr - binService_->smOffsetBins(okey, bkey, iObj));
395  setBinContent_(iME, bin, _content, _err);
396  setBinEntries_(iME, bin, 0.);
397  }
398  }
399  }
400 
401  std::vector<std::string>
403  {
404  using namespace std;
405 
406  unsigned nME(1);
407  switch(data_->otype){
408  case BinService::kSM:
409  nME = BinService::nDCC;
410  break;
411  case BinService::kSMMEM:
412  nME = BinService::nDCCMEM;
413  break;
414  case BinService::kEcal2P:
415  nME = 2;
416  break;
417  case BinService::kEcal3P:
418  nME = 3;
419  break;
421  nME = 2;
422  break;
423  default:
424  break;
425  }
426 
427  std::vector<std::string> names(0);
428 
429  for(unsigned iME(0); iME < nME; iME++) {
430 
431  unsigned iObj(iME);
432 
434 
435  string name(name_);
436  string spacer(" ");
437 
438  if(data_->btype == BinService::kProjEta) name += " eta";
439  else if(data_->btype == BinService::kProjPhi) name += " phi";
440  else if(data_->btype == BinService::kReport) spacer = "_";
441 
442  switch(actualObject){
443  case BinService::kEB:
444  case BinService::kEBMEM:
445  name += spacer + "EB"; break;
446  case BinService::kEE:
447  case BinService::kEEMEM:
448  name += spacer + "EE"; break;
449  case BinService::kEEm:
450  name += spacer + "EE-"; break;
451  case BinService::kEEp:
452  name += spacer + "EE+"; break;
453  case BinService::kSM:
454  name += spacer + binService_->channelName(iObj + 1); break;
455  case BinService::kSMMEM:
456  //dccId(unsigned) skips DCCs without MEM
457  iObj = dccId(iME) - 1;
458  name += spacer + binService_->channelName(iObj + 1); break;
459  default:
460  break;
461  }
462 
463  names.push_back(name);
464  }
465 
466  return names;
467  }
468 
469  void
470  MESetEcal::find_(uint32_t _id) const
471  {
472  if(_id == cacheId_) return;
473 
474  DetId id(_id);
475  if(id.det() == DetId::Ecal)
477  else
478  cache_ = binService_->findBins(data_->otype, data_->btype, unsigned(_id));
479 
480  if(cache_.first >= mes_.size() || !mes_[cache_.first])
481  throw cms::Exception("InvalidCall") << "ME array index overflow" << std::endl;
482 
483  // some TTs are apparently empty..!
484 // if(cache_.second.size() == 0)
485 // throw cms::Exception("InvalidCall") << "No bins to get content from" << std::endl;
486 
487  cacheId_ = _id;
488  }
489 
490  void
491  MESetEcal::fill_(double _w)
492  {
493  for(unsigned iBin(0); iBin < cache_.second.size(); iBin++)
494  MESet::fill_(cache_.first, cache_.second[iBin], _w);
495  }
496 
497 }
const unsigned logicalDimensions_
Definition: MESetEcal.h:45
void fill(DetId const &, double _wx=1., double _wy=1., double _w=1.)
Definition: MESetEcal.cc:221
int i
Definition: DBlmapReader.cc:9
std::string channelName(uint32_t, BinningType _btype=kDCC) const
BinService::ObjectType otype
Definition: MESet.h:22
virtual void reset(double _content=0., double _err=0., double _entries=0.)
Definition: MESet.cc:87
uint32_t cacheId_
Definition: MESetEcal.h:47
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
virtual void clear() const
Definition: MESet.cc:59
std::vector< std::string > generateNames() const
Definition: MESetEcal.cc:402
BinService::AxisSpecs * yaxis
Definition: MESet.h:26
const std::vector< int > * getBinMap(ObjectType &, BinningType &) const
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)
double getBinEntries(DetId const &, int _bin=0) const
Definition: MESetEcal.cc:331
MonitorElement::Kind kind
Definition: MESet.h:24
virtual void fill_(double)
Definition: MESetEcal.cc:491
std::vector< AxisSpecs > getBinning(ObjectType, BinningType, bool _isMap=true, unsigned _objOffset=0) const
unsigned dccId(const DetId &)
dictionary edges
bool retrieve() const
Definition: MESetEcal.cc:200
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:654
ObjectType objectFromOffset(ObjectType, unsigned) const
BinService::AxisSpecs * xaxis
Definition: MESet.h:25
std::vector< MonitorElement * > mes_
Definition: MESet.h:129
MESetEcal(std::string const &, MEData const &, int logicalDimensions_, bool _readOnly=false)
Definition: MESetEcal.cc:12
static DQMStore * dqmStore_
Definition: MESet.h:127
const T & max(const T &a, const T &b)
std::string dir_
Definition: MESet.h:131
double getBinContent(DetId const &, int _bin=0) const
Definition: MESetEcal.cc:291
unsigned findOffset(ObjectType, const DetId &) const
BinService::BinningType btype
Definition: MESet.h:23
virtual void setBinEntries_(unsigned, int, double)
Definition: MESet.cc:313
TH1 * getTH1(void) const
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:1031
virtual void setBinContent_(unsigned, int, double, double)
Definition: MESet.cc:294
unsigned int offset(bool)
std::string name_
Definition: MESet.h:132
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1468
std::pair< unsigned, std::vector< int > > cache_
Definition: MESetEcal.h:48
void reset(double _content=0., double _err=0., double _entries=0.)
Definition: MESetEcal.cc:351
virtual void fill_(unsigned, int, double)
Definition: MESet.cc:262
Definition: DetId.h:20
virtual double getBinContent_(unsigned, int) const
Definition: MESet.cc:330
double getBinError(DetId const &, int _bin=0) const
Definition: MESetEcal.cc:311
virtual double getBinError_(unsigned, int) const
Definition: MESet.cc:346
static BinService const * binService_
Definition: MESet.h:126
BinService::AxisSpecs * zaxis
Definition: MESet.h:27
bool active_
Definition: MESet.h:135
void setBinContent(DetId const &, double, double _err=0.)
Definition: MESetEcal.cc:251
std::pair< unsigned, std::vector< int > > findBins(ObjectType, BinningType, const DetId &) const
MEData const * data_
Definition: MESet.h:133
void setBinEntries(DetId const &, double)
Definition: MESetEcal.cc:271
int getNbinsX(void) const
get # of bins in X-axis
virtual double getBinEntries_(unsigned, int) const
Definition: MESet.cc:362
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:845
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
static const HistoName names[]
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
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
int smOffsetBins(ObjectType, BinningType, unsigned) const
virtual void find_(uint32_t) const
Definition: MESetEcal.cc:470
MonitorElement * bookProfile2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, const char *option="s")
Definition: DQMStore.cc:1175