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