CMS 3D CMS Logo

ValueQuantity.h
Go to the documentation of this file.
1 #ifndef ValueQuantity_h
2 #define ValueQuantity_h
3 
6 #include "boost/unordered_map.hpp"
7 #include "boost/foreach.hpp"
8 
9 namespace hcaldqm
10 {
11  namespace quantity
12  {
14  {
15  fN = 0,
16  fEvents = 1,
17  fEnergy = 2,
19  fADC_128 = 4,
20  fADC_5 = 5,
21  fADC_15 = 6,
22  ffC_10000 = 7,
23  ffC_1000 = 8,
24  ffC_3000 = 9,
25  fTiming_TS = 10,
27  fLS = 12,
28  fEt_256 = 13,
29  fEt_128 = 14,
30  fFG = 15,
31  fRatio = 16,
32  fDigiSize = 17,
34  fRatio2 = 19,
35  fdEtRatio = 20,
36  fSumdEt = 21,
41  fDiffAbs = 26,
43  fN_to8000 = 28,
48  fBX = 33,
50  fState = 35,
52  fDataSize = 37,
57  fADC_256 = 42,
64  fBadTDC = 49,
65  fRBX = 50,
70  fBX_36 = 55,
71  fADC_256_4 = 56, // ADC from 0-255, with 4 ADC granularity
72  };
73  const std::map<ValueQuantityType, std::string> name_value = {
74  {fN,"N"},
75  {fEvents,"Events"},
76  {fEnergy,"Energy"},
77  {fTiming_ns,"Timing"},
78  {fADC_5,"ADC (QIE8)"},
79  {fADC_15,"ADC (QIE8)"},
80  {fADC_128,"ADC (QIE8)"},
81  {fADC_256,"ADC"},
82  {fQIE10ADC_256,"ADC (QIE10/11)"},
83  {fQIE10ADC_16,"ADC (QIE10/11)"},
84  {ffC_1000,"fC (QIE8)"},
85  {ffC_3000,"fC (QIE8)"},
86  {ffC_10000,"fC (QIE8)"},
87  {fQIE8fC_1000_50,"fC"},
88  {fQIE10fC_2000,"fC"},
89  {fQIE10fC_10000,"fC"},
90  {fQIE10fC_400000,"fC"},
91  {ffC_generic_10000,"fC (QIE8/10/11)"},
92  {ffC_generic_400000,"fC (QIE8/10/11)"},
93  {fTiming_TS,"Timing"},
94  {fTiming_TS200,"Timing"},
95  {fLS,"LS"},
96  {fEt_256,"Et"},
97  {fEt_128,"Et"},
98  {fFG,"FG"},
99  {fRatio,"Ratio"},
100  {fDigiSize,"DigiSize"},
101  {fAroundZero,"Q"},
102  {fRatio2,"Ratio"},
103  {fdEtRatio,"dEtRatio"},
104  {fSumdEt,"SumdEt"},
105  {fTiming_100TS,"Timing"},
106  {fQIE10TDC_64,"TDC"},
107  {fQIE10TDC_16,"TDC"},
108  {fDiffAbs,"Q"},
109  {fRatio_0to2,"Ratio"},
110  {fN_to8000,"N"},
111  {fEnergyTotal,"Energy"},
112  {fN_m0to10000,"N"},
113  {fEtCorr_256,"Et"},
114  {fADCCorr_128,"ADC"},
115  {fBX,"BX"},
116  {fEnergy_1TeV,"Energy"},
117  {fState,"State"},
118  {fDataSize,"FED Data Size (kB)"},
119  {fTime_ns_250,"Time (ns)"},
120  {fDualAnodeAsymmetry, "(q_{1}-q_{2})/(q_{1}+q_{2})"},
121  {fTimingRatio, "q_{SOI+1}/q_{SOI}"},
122  {fQIE10fC_100000Coarse,"fC"},
123  {fBadTDC, "TDC"},
124  {fRBX, "RBX"},
125  {fTimingDiff_ns, "#Delta timing [ns]"},
126  {ffC_1000000, "fC"},
127  {fTime_ns_250_coarse, "Time (ns)"},
128  {fCapidMinusBXmod4, "(CapId - BX) % 4"},
129  {fBX_36, "BX"},
130  {fADC_256_4, "ADC"},
131  };
132  const std::map<ValueQuantityType, double> min_value = {
133  {fN,-0.05},
134  {fEvents,0},
135  {fEnergy,0},
136  {fTiming_ns,-50},
137  {fADC_128,-0.5},
138  {fADC_5,-0.5},
139  {fADC_15,-0.5},
140  {ffC_10000,0},
141  {ffC_1000,0},
142  {ffC_3000,0},
143  {fTiming_TS,-0.5},
144  {fTiming_TS200,-0.5},
145  {fLS,0.5},
146  {fEt_256,0},
147  {fEt_128,0},
148  {fFG,0},
149  {fRatio,0},
150  {fDigiSize,-0.5},
151  {fAroundZero,-1},
152  {fRatio2,0.5},
153  {fdEtRatio,0},
154  {fSumdEt,0},
155  {fTiming_100TS,-0.5},
156  {fQIE10ADC_256,-0.5},
157  {fQIE10ADC_16,-0.5},
158  {fQIE10TDC_64,-0.5},
159  {fQIE10TDC_16,-0.5},
160  {fDiffAbs,0},
161  {fRatio_0to2,0},
162  {fN_to8000,0},
163  {fEnergyTotal,0},
164  {fN_m0to10000,-0.05},
165  {fEtCorr_256,-1},
166  {fADCCorr_128,-2},
167  {fBX,-0.5},
168  {fEnergy_1TeV,0},
169  {fState,flag::fNA},
170  {fQIE10fC_400000,0},
171  {fDataSize,0},
172  {fQIE10fC_2000,0},
173  {fQIE10fC_10000,0},
174  {fQIE8fC_1000_50,0},
175  {fTime_ns_250,-0.5},
176  {fADC_256,-0.5},
177  {ffC_generic_10000,0.},
178  {ffC_generic_400000,0.},
179  {fDualAnodeAsymmetry,-1.},
180  {fTimingRatio,0.},
182  {fBadTDC,49.5},
183  {fRBX, 0.5},
184  {fTimingDiff_ns, -125.},
185  {ffC_1000000,0.},
186  {fTime_ns_250_coarse, -0.5},
187  {fCapidMinusBXmod4, -0.5},
188  {fBX_36, -0.5},
189  {fADC_256_4, -0.5},
190  };
191  const std::map<ValueQuantityType, double> max_value = {
192  {fN,1000},
193  {fEvents,1000},
194  {fEnergy,200},
195  {fTiming_ns,50},
196  {fADC_128,127.5},
197  {fADC_5,5},
198  {fADC_15,15},
199  {ffC_10000,10000},
200  {ffC_1000,1000},
201  {ffC_3000,3000},
202  {fTiming_TS,9.5},
203  {fTiming_TS200,9.5},
204  {fLS,4000.5},
205  {fEt_256,255.5},
206  {fEt_128,255.5},
207  {fFG,2},
208  {fRatio,1},
209  {fDigiSize,20.5},
210  {fAroundZero,1},
211  {fRatio2,1.5},
212  {fdEtRatio,1},
213  {fSumdEt,1000},
214  {fTiming_100TS,99.5},
215  {fQIE10ADC_256,255.5},
216  {fQIE10ADC_16,15.5},
217  {fQIE10TDC_64,63.5},
218  {fQIE10TDC_16,15.5},
219  {fDiffAbs,1},
220  {fRatio_0to2,2},
221  {fN_to8000,8000},
222  {fEnergyTotal,100000},
223  {fN_m0to10000,10000},
224  {fEtCorr_256,257},
225  {fADCCorr_128,128},
226  {fBX,3600.5},
227  {fEnergy_1TeV,1000},
229  {fQIE10fC_400000,400000},
230  {fDataSize,100},
231  {fQIE10fC_2000,2000},
232  {fQIE10fC_10000,10000},
233  {fQIE8fC_1000_50,1000},
234  {fTime_ns_250,249.5},
235  {fADC_256,255.5},
236  {ffC_generic_10000,10000},
237  {ffC_generic_400000,400000},
238  {fDualAnodeAsymmetry,1.},
239  {fTimingRatio,2.5},
240  {fQIE10fC_100000Coarse,100000},
241  {fBadTDC,61.5},
242  {fRBX, 18.5},
243  {fTimingDiff_ns, 125.},
244  {ffC_1000000,1.e6},
245  {fTime_ns_250_coarse, 249.5},
246  {fCapidMinusBXmod4, 3.5},
247  {fBX_36, 3564.-0.5},
248  {fADC_256_4, 255},
249  };
250  const std::map<ValueQuantityType, int> nbins_value = {
251  {fN,200},
252  {fEvents,200},
253  {fEnergy,100},
254  {fTiming_ns,200},
255  {fADC_128,128},
256  {fADC_5,100},
257  {fADC_15,300},
258  {ffC_10000,1000},
259  {ffC_1000,200},
260  {ffC_3000,600},
261  {fTiming_TS,10},
262  {fTiming_TS200,200},
263  {fLS,4000},
264  {fEt_256,256},
265  {fEt_128,128},
266  {fFG,2},
267  {fRatio,100},
268  {fDigiSize,21},
269  {fAroundZero,100},
270  {fRatio2,100},
271  {fdEtRatio,100},
272  {fSumdEt,100},
273  {fTiming_100TS,100},
274  {fQIE10ADC_256,256},
275  {fQIE10TDC_64,64},
276  {fQIE10TDC_16,16},
277  {fDiffAbs,200},
278  {fRatio_0to2,100},
279  {fN_to8000,8000},
280  {fEnergyTotal,500},
281  {fN_m0to10000,100},
282  {fEtCorr_256,258},
283  {fADCCorr_128,130},
284  {fBX,3601},
285  {fEnergy_1TeV,200},
287  {fQIE10fC_400000,1000},
288  {fDataSize,100},
289  {fQIE10fC_2000,100},
290  {fQIE10fC_10000,500},
291  {fQIE8fC_1000_50,50},
292  {fTime_ns_250,250},
293  {fADC_256,256},
294  {ffC_generic_10000,10000},
295  {ffC_generic_400000,10000},
296  {fDualAnodeAsymmetry,40},
297  {fTimingRatio,50},
298  {fQIE10fC_100000Coarse,1000},
299  {fBadTDC,12},
300  {fRBX, 18},
301  {fTimingDiff_ns, 40},
302  {ffC_1000000,1000},
303  {fTime_ns_250_coarse, 100},
304  {fCapidMinusBXmod4, 4},
305  {fBX_36, 99},
306  {fADC_256_4, 64},
307  };
308  class ValueQuantity : public Quantity
309  {
310  public:
313  Quantity(name_value.at(type), isLog), _type(type)
314  {}
315  ~ValueQuantity() override {}
316 
318  {return new ValueQuantity(_type, _isLog);}
319 
320  // get Value to be overriden
321  int getValue(int x) override
322  {
323  int ret_x = x;
324  if (_showOverflow) {
325  if (x < min()) {
326  ret_x = min();
327  } else if (x > max()) {
328  ret_x = max();
329  }
330  }
331  return ret_x;
332  }
333  double getValue(double x) override
334  {
335  double ret_x = x;
336  if (_showOverflow) {
337  if (x < min()) {
338  ret_x = min();
339  } else if (x > max()) {
340  ret_x = max();
341  }
342  }
343  return ret_x;
344  }
345 
346  // standard properties
347  QuantityType type() override {return fValueQuantity;}
348  int nbins() override {return nbins_value.at(_type);}
349  double min() override {return min_value.at(_type);}
350  double max() override {return max_value.at(_type);}
351 
352  void setBits(TH1* o) override
353  {Quantity::setBits(o);setLS(o);}
354  virtual void setLS(TH1* o)
355  {
356  if (_type==fLS)
357  {
358  // for LS axis - set the bit
359  // set extendable axes.
361  // o->SetCanExtend(TH1::kXaxis);
362  }
363  }
364 
365  protected:
367  };
368 
370  {
371  public:
373  FlagQuantity(std::vector<flag::Flag> const& flags) :
374  _flags(flags) {}
375  ~FlagQuantity() override {}
376 
377  FlagQuantity* makeCopy() override
378  {return new FlagQuantity(_flags);}
379 
380  std::string name() override {return "Flag";}
381  int nbins() override {return _flags.size();}
382  double min() override {return 0;}
383  double max() override {return _flags.size();}
384  int getValue(int f) override {return f;}
385  uint32_t getBin(int f) override {return f+1;}
386  std::vector<std::string> getLabels() override
387  {
388  std::vector<std::string> vnames;
389  for (std::vector<flag::Flag>::const_iterator
390  it=_flags.begin(); it!=_flags.end(); ++it)
391  vnames.push_back(it->_name);
392 
393  return vnames;
394  }
395  protected:
396 
397  std::vector<flag::Flag> _flags;
398  };
399 
400  class LumiSection : public ValueQuantity
401  {
402  public:
403  LumiSection() : ValueQuantity(fLS), _n(4000) {}
404  LumiSection(int n) : ValueQuantity(fLS), _n(n) {}
405  ~LumiSection() override {}
406 
407  LumiSection* makeCopy() override
408  {return new LumiSection(_n);}
409 
410  std::string name() override {return "LS";}
411  int nbins() override {return _n;}
412  double min() override {return 1;}
413  double max() override {return _n+1;}
414  int getValue(int l) override {
415  return l;
416  }
417  uint32_t getBin(int l) override
418  {return getValue(l);}
419  void setMax(double x) override {_n=x;}
420 
421  protected:
422  int _n;
423  };
424 
429  {
430  public:
431  LumiSectionCoarse() : ValueQuantity(fLS), _n(4000), _binning(10)
432  {}
434  _n(n), _binning(binning)
435  {}
436  ~LumiSectionCoarse() override {}
437 
439  {return new LumiSectionCoarse(_n, _binning);}
440 
441  std::string name() override {return "LS";}
442  int nbins() override {return (_n + _binning - 1) / _binning;}
443  double min() override {return 1;}
444  double max() override {return _n+1;}
445  int getValue(int l) override {return l;}
446  uint32_t getBin(int l) override
447  {
448  return (l + _binning - 1) / _binning;
449  }
450  void setMax(double x) override {_n=x;}
451 
452  protected:
453  int _n;
454  int _binning;
455  };
456 
457  class RunNumber : public ValueQuantity
458  {
459  public:
461  RunNumber(std::vector<int> runs) :
462  _runs(runs)
463  {}
464  ~RunNumber() override {}
465 
466  std::string name() override {return "Run";}
467  int nbins() override {return _runs.size();}
468  double min() override {return 0;}
469  double max() override {return _runs.size();}
470  std::vector<std::string> getLabels() override
471  {
472  char name[10];
473  std::vector<std::string> labels;
474  for (uint32_t i=0; i<_runs.size(); i++)
475  {
476  sprintf(name, "%d", _runs[i]);
477  labels.push_back(name);
478  }
479  return labels;
480  }
481  int getValue(int run) override
482  {
483  int ir = -1;
484  for (uint32_t i=0; i<_runs.size(); i++)
485  if (_runs[i]==run)
486  {
487  ir = (int)i;
488  break;
489  }
490 
491  if (ir==-1)
492  throw cms::Exception("HCALDQM")
493  << "run number doens't exist " << run;
494 
495  return ir;
496  }
497 
498  uint32_t getBin(int run) override
499  {
500  return (this->getValue(run)+1);
501  }
502 
503  protected:
504  std::vector<int> _runs;
505  };
506 
507  class EventNumber : public ValueQuantity
508  {
509  public:
511  EventNumber(int nevents) :
512  ValueQuantity(fN), _nevents(nevents)
513  {}
514  ~EventNumber() override {}
515 
516  std::string name() override {return "Event";}
517  int nbins() override {return _nevents;}
518  double min() override {return 0.5;}
519  double max() override {return _nevents+0.5;}
520 
521  protected:
522  int _nevents;
523  };
524 
525  class EventType : public ValueQuantity
526  {
527  public:
529  EventType(std::vector<uint32_t> const& vtypes):
531  {this->setup(vtypes);}
532  ~EventType() override {}
533 
534  virtual void setup(std::vector<uint32_t> const& vtypes)
535  {
536  std::cout << "SIZE = " << vtypes.size() << std::endl;
537  for (uint32_t i=0; i<vtypes.size(); i++)
538  _types.insert(std::make_pair((uint32_t)vtypes[i], i));
539  }
540  int getValue(int v) override
541  {
542  return _types[(uint32_t)v];
543  }
544  uint32_t getBin(int v) override
545  {
546  return getValue(v)+1;
547  }
548 
549  int nbins() override {return _types.size();}
550  double min() override {return 0;}
551  double max() override {return _types.size();}
552  std::string name() override {return "Event Type";}
553 
554  protected:
555  typedef boost::unordered_map<uint32_t, int> TypeMap;
556  TypeMap _types;
557 
558  public:
559  std::vector<std::string> getLabels() override
560  {
561  std::vector<std::string> labels(_types.size());
562  std::cout << "SIZE = " << _types.size() << std::endl;
563  BOOST_FOREACH(TypeMap::value_type &v, _types)
564  {
566  }
567  return labels;
568  }
569  EventType* makeCopy() override
570  {
571  std::vector<uint32_t> vtypes;
572  BOOST_FOREACH(TypeMap::value_type &p, _types)
573  {
574  vtypes.push_back(p.first);
575  }
576 
577  std::sort(vtypes.begin(), vtypes.end());
578  return new EventType(vtypes);
579  }
580  };
581  }
582 }
583 
584 #endif
ValueQuantity(ValueQuantityType type, bool isLog=false)
type
Definition: HCALResponse.h:21
const std::map< ValueQuantityType, int > nbins_value
virtual void setBits(TH1 *o)
Definition: Quantity.h:65
virtual std::string name()
Definition: Quantity.h:47
std::string name() override
uint32_t getBin(int run) override
FlagQuantity(std::vector< flag::Flag > const &flags)
std::vector< std::string > getLabels() override
uint32_t getBin(int v) override
void setBits(TH1 *o) override
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
LumiSectionCoarse * makeCopy() override
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
std::vector< int > _runs
virtual void setup(std::vector< uint32_t > const &vtypes)
int getValue(int run) override
const std::map< ValueQuantityType, double > min_value
uint32_t getBin(int l) override
std::string name() override
int getValue(int f) override
FlagQuantity * makeCopy() override
boost::unordered_map< uint32_t, int > TypeMap
std::vector< flag::Flag > _flags
double f[11][100]
std::string name() override
int getValue(int v) override
std::string ogtype2string(constants::OrbitGapType type)
Definition: Utilities.cc:229
void setMax(double x) override
std::vector< std::string > getLabels() override
const std::map< ValueQuantityType, std::string > name_value
Definition: ValueQuantity.h:73
EventType * makeCopy() override
void setMax(double x) override
std::string name() override
EventType(std::vector< uint32_t > const &vtypes)
QuantityType type() override
int getValue(int l) override
uint32_t getBin(int l) override
virtual bool isLog()
Definition: Quantity.h:48
const std::map< ValueQuantityType, double > max_value
LumiSection * makeCopy() override
RunNumber(std::vector< int > runs)
int const BIT_OFFSET
Definition: Constants.h:313
std::vector< std::string > getLabels() override
uint32_t getBin(int f) override
ValueQuantity * makeCopy() override
int const BIT_AXIS_LS
Definition: Constants.h:317
double getValue(double x) override
std::string name() override