CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ValueQuantity.h
Go to the documentation of this file.
1 #ifndef ValueQuantity_h
2 #define ValueQuantity_h
3 
6 #include <unordered_map>
7 
8 namespace hcaldqm {
9  namespace quantity {
11  fN,
23  fLS,
26  fFG,
47  fBX,
70  fADC_256_4, // ADC from 0-255, with 4 ADC granularity
71  fEtlog2, // scale log2(ET+1)
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  {fQIE10TDC_4, "TDC"},
109  {fDiffAbs, "Q"},
110  {fRatio_0to2, "Ratio"},
111  {fN_to8000, "N"},
112  {fEnergyTotal, "Energy"},
113  {fN_m0to10000, "N"},
114  {fEtCorr_256, "Et"},
115  {fEtCorr_data, "256*TS + Et (Data TP)"},
116  {fEtCorr_emul, "256*TS + Et (Emul TP)"},
117  {fADCCorr_128, "ADC"},
118  {fBX, "BX"},
119  {fEnergy_1TeV, "Energy"},
120  {fState, "State"},
121  {fDataSize, "FED Data Size (kB)"},
122  {fTime_ns_250, "Time (ns)"},
123  {fDualAnodeAsymmetry, "(q_{1}-q_{2})/(q_{1}+q_{2})"},
124  {fTimingRatio, "q_{SOI+1}/q_{SOI}"},
125  {fQIE10fC_100000Coarse, "fC"},
126  {fBadTDC, "TDC"},
127  {fRBX, "RBX"},
128  {fTimingDiff_ns, "#Delta timing [ns]"},
129  {ffC_1000000, "fC"},
130  {fTime_ns_250_coarse, "Time (ns)"},
131  {fCapidMinusBXmod4, "(CapId - BX) % 4"},
132  {fBX_36, "BX"},
133  {fADC_256_4, "ADC"},
134  {fEtlog2, "log_{2}(Et+1)"},
135  };
136  const std::map<ValueQuantityType, double> min_value = {
137  {fN, -0.05},
138  {fEvents, 0},
139  {fEnergy, 0},
140  {fTiming_ns, -50},
141  {fADC_128, -0.5},
142  {fADC_5, -0.5},
143  {fADC_15, -0.5},
144  {ffC_10000, 0},
145  {ffC_1000, 0},
146  {ffC_3000, 0},
147  {fTiming_TS, -0.5},
148  {fTiming_TS200, -0.5},
149  {fLS, 0.5},
150  {fEt_256, 0},
151  {fEt_128, 0},
152  {fFG, 0},
153  {fRatio, 0},
154  {fDigiSize, -0.5},
155  {fAroundZero, -1},
156  {fRatio2, 0.5},
157  {fdEtRatio, 0},
158  {fSumdEt, 0},
159  {fTiming_100TS, -0.5},
160  {fQIE10ADC_256, -0.5},
161  {fQIE10ADC_16, -0.5},
162  {fQIE10TDC_64, -0.5},
163  {fQIE10TDC_16, -0.5},
164  {fQIE10TDC_4, -0.5},
165  {fDiffAbs, 0},
166  {fRatio_0to2, 0},
167  {fN_to8000, 0},
168  {fEnergyTotal, 0},
169  {fN_m0to10000, -0.05},
170  {fEtCorr_256, -1},
171  {fEtCorr_data, -4},
172  {fEtCorr_emul, -4},
173  {fADCCorr_128, -2},
174  {fBX, -0.5},
175  {fEnergy_1TeV, 0},
176  {fState, flag::fNA},
177  {fQIE10fC_400000, 0},
178  {fDataSize, 0},
179  {fQIE10fC_2000, 0},
180  {fQIE10fC_10000, 0},
181  {fQIE8fC_1000_50, 0},
182  {fTime_ns_250, -0.5},
183  {fADC_256, -0.5},
184  {ffC_generic_10000, 0.},
185  {ffC_generic_400000, 0.},
186  {fDualAnodeAsymmetry, -1.},
187  {fTimingRatio, 0.},
189  {fBadTDC, 49.5},
190  {fRBX, 0.5},
191  {fTimingDiff_ns, -125.},
192  {ffC_1000000, 0.},
193  {fTime_ns_250_coarse, -0.5},
194  {fCapidMinusBXmod4, -0.5},
195  {fBX_36, -0.5},
196  {fADC_256_4, -0.5},
197  {fEtlog2, 0.},
198  };
199  const std::map<ValueQuantityType, double> max_value = {
200  {fN, 1000},
201  {fEvents, 1000},
202  {fEnergy, 200},
203  {fTiming_ns, 50},
204  {fADC_128, 127.5},
205  {fADC_5, 5},
206  {fADC_15, 15},
207  {ffC_10000, 10000},
208  {ffC_1000, 1000},
209  {ffC_3000, 3000},
210  {fTiming_TS, 9.5},
211  {fTiming_TS200, 9.5},
212  {fLS, 4000.5},
213  {fEt_256, 255.5},
214  {fEt_128, 255.5},
215  {fFG, 2},
216  {fRatio, 1},
217  {fDigiSize, 20.5},
218  {fAroundZero, 1},
219  {fRatio2, 1.5},
220  {fdEtRatio, 1},
221  {fSumdEt, 1000},
222  {fTiming_100TS, 99.5},
223  {fQIE10ADC_256, 255.5},
224  {fQIE10ADC_16, 15.5},
225  {fQIE10TDC_64, 63.5},
226  {fQIE10TDC_16, 15.5},
227  {fQIE10TDC_4, 3.5},
228  {fDiffAbs, 1},
229  {fRatio_0to2, 2},
230  {fN_to8000, 8000},
231  {fEnergyTotal, 100000},
232  {fN_m0to10000, 10000},
233  {fEtCorr_256, 257},
234  {fEtCorr_data, 1028},
235  {fEtCorr_emul, 1028},
236  {fADCCorr_128, 128},
237  {fBX, 3600.5},
238  {fEnergy_1TeV, 1000},
239  {fState, flag::nState},
240  {fQIE10fC_400000, 400000},
241  {fDataSize, 100},
242  {fQIE10fC_2000, 2000},
243  {fQIE10fC_10000, 10000},
244  {fQIE8fC_1000_50, 1000},
245  {fTime_ns_250, 249.5},
246  {fADC_256, 255.5},
247  {ffC_generic_10000, 10000},
248  {ffC_generic_400000, 400000},
249  {fDualAnodeAsymmetry, 1.},
250  {fTimingRatio, 2.5},
251  {fQIE10fC_100000Coarse, 100000},
252  {fBadTDC, 61.5},
253  {fRBX, 18.5},
254  {fTimingDiff_ns, 125.},
255  {ffC_1000000, 1.e6},
256  {fTime_ns_250_coarse, 249.5},
257  {fCapidMinusBXmod4, 3.5},
258  {fBX_36, 3564. - 0.5},
259  {fADC_256_4, 255},
260  {fEtlog2, 9.},
261  };
262  const std::map<ValueQuantityType, int> nbins_value = {
263  {fN, 200},
264  {fEvents, 200},
265  {fEnergy, 100},
266  {fTiming_ns, 200},
267  {fADC_128, 128},
268  {fADC_5, 100},
269  {fADC_15, 300},
270  {ffC_10000, 1000},
271  {ffC_1000, 200},
272  {ffC_3000, 600},
273  {fTiming_TS, 10},
274  {fTiming_TS200, 200},
275  {fLS, 4000},
276  {fEt_256, 256},
277  {fEt_128, 128},
278  {fFG, 2},
279  {fRatio, 100},
280  {fDigiSize, 21},
281  {fAroundZero, 100},
282  {fRatio2, 100},
283  {fdEtRatio, 100},
284  {fSumdEt, 100},
285  {fTiming_100TS, 100},
286  {fQIE10ADC_256, 256},
287  {fQIE10TDC_64, 64},
288  {fQIE10TDC_16, 16},
289  {fQIE10TDC_4, 4},
290  {fDiffAbs, 200},
291  {fRatio_0to2, 100},
292  {fN_to8000, 8000},
293  {fEnergyTotal, 500},
294  {fN_m0to10000, 100},
295  {fEtCorr_256, 258},
296  {fEtCorr_data, 258},
297  {fEtCorr_emul, 258},
298  {fADCCorr_128, 130},
299  {fBX, 3601},
300  {fEnergy_1TeV, 200},
301  {fState, flag::nState},
302  {fQIE10fC_400000, 1000},
303  {fDataSize, 100},
304  {fQIE10fC_2000, 100},
305  {fQIE10fC_10000, 500},
306  {fQIE8fC_1000_50, 50},
307  {fTime_ns_250, 250},
308  {fADC_256, 256},
309  {ffC_generic_10000, 10000},
310  {ffC_generic_400000, 10000},
311  {fDualAnodeAsymmetry, 40},
312  {fTimingRatio, 50},
313  {fQIE10fC_100000Coarse, 1000},
314  {fBadTDC, 12},
315  {fRBX, 18},
316  {fTimingDiff_ns, 40},
317  {ffC_1000000, 1000},
318  {fTime_ns_250_coarse, 100},
319  {fCapidMinusBXmod4, 4},
320  {fBX_36, 99},
321  {fADC_256_4, 64},
322  {fEtlog2, 9},
323  };
324  class ValueQuantity : public Quantity {
325  public:
327  ValueQuantity(ValueQuantityType type, bool isLog = false) : Quantity(name_value.at(type), isLog), _type(type) {}
328  ~ValueQuantity() override {}
329 
330  ValueQuantity *makeCopy() override { return new ValueQuantity(_type, _isLog); }
331 
332  // get Value to be overriden
333  int getValue(int x) override {
334  int ret_x = x;
335  if (_showOverflow) {
336  if (x < min()) {
337  ret_x = min();
338  } else if (x > max()) {
339  ret_x = max();
340  }
341  }
342  return ret_x;
343  }
344  double getValue(double x) override {
345  double ret_x = x;
346  if (_showOverflow) {
347  if (x < min()) {
348  ret_x = min();
349  } else if (x > max()) {
350  ret_x = max();
351  }
352  }
353  return ret_x;
354  }
355 
356  // standard properties
357  QuantityType type() override { return fValueQuantity; }
358  int nbins() override { return nbins_value.at(_type); }
359  double min() override { return min_value.at(_type); }
360  double max() override { return max_value.at(_type); }
361 
362  void setBits(TH1 *o) override {
364  setLS(o);
365  }
366  virtual void setLS(TH1 *o) {
367  if (_type == fLS) {
368  // for LS axis - set the bit
369  // set extendable axes.
371  // o->SetCanExtend(TH1::kXaxis);
372  }
373  }
374 
375  protected:
377  };
378 
379  class FlagQuantity : public ValueQuantity {
380  public:
382  FlagQuantity(std::vector<flag::Flag> const &flags) : _flags(flags) {}
383  ~FlagQuantity() override {}
384 
385  FlagQuantity *makeCopy() override { return new FlagQuantity(_flags); }
386 
387  std::string name() override { return "Flag"; }
388  int nbins() override { return _flags.size(); }
389  double min() override { return 0; }
390  double max() override { return _flags.size(); }
391  int getValue(int f) override { return f; }
392  uint32_t getBin(int f) override { return f + 1; }
393  std::vector<std::string> getLabels() override {
394  std::vector<std::string> vnames;
395  for (std::vector<flag::Flag>::const_iterator it = _flags.begin(); it != _flags.end(); ++it)
396  vnames.push_back(it->_name);
397 
398  return vnames;
399  }
400 
401  protected:
402  std::vector<flag::Flag> _flags;
403  };
404 
405  class LumiSection : public ValueQuantity {
406  public:
409  ~LumiSection() override {}
410 
411  LumiSection *makeCopy() override { return new LumiSection(_n); }
412 
413  std::string name() override { return "LS"; }
414  int nbins() override { return _n; }
415  double min() override { return 1; }
416  double max() override { return _n + 1; }
417  int getValue(int l) override { return l; }
418  uint32_t getBin(int l) override { return getValue(l); }
419  void setMax(double x) override { _n = x; }
420 
421  protected:
422  int _n;
423  };
424 
429  public:
431  LumiSectionCoarse(int n, int binning) : ValueQuantity(fLS), _n(n), _binning(binning) {}
432  ~LumiSectionCoarse() override {}
433 
435 
436  std::string name() override { return "LS"; }
437  int nbins() override { return (_n + _binning - 1) / _binning; }
438  double min() override { return 1; }
439  double max() override { return _n + 1; }
440  int getValue(int l) override { return l; }
441  uint32_t getBin(int l) override { return (l + _binning - 1) / _binning; }
442  void setMax(double x) override { _n = x; }
443 
444  protected:
445  int _n;
446  int _binning;
447  };
448 
449  class RunNumber : public ValueQuantity {
450  public:
452  RunNumber(std::vector<int> runs) : _runs(runs) {}
453  ~RunNumber() override {}
454 
455  std::string name() override { return "Run"; }
456  int nbins() override { return _runs.size(); }
457  double min() override { return 0; }
458  double max() override { return _runs.size(); }
459  std::vector<std::string> getLabels() override {
460  char name[10];
461  std::vector<std::string> labels;
462  for (uint32_t i = 0; i < _runs.size(); i++) {
463  sprintf(name, "%d", _runs[i]);
464  labels.push_back(name);
465  }
466  return labels;
467  }
468  int getValue(int run) override {
469  int ir = -1;
470  for (uint32_t i = 0; i < _runs.size(); i++)
471  if (_runs[i] == run) {
472  ir = (int)i;
473  break;
474  }
475 
476  if (ir == -1)
477  throw cms::Exception("HCALDQM") << "run number doens't exist " << run;
478 
479  return ir;
480  }
481 
482  uint32_t getBin(int run) override { return (this->getValue(run) + 1); }
483 
484  protected:
485  std::vector<int> _runs;
486  };
487 
488  class EventNumber : public ValueQuantity {
489  public:
492  ~EventNumber() override {}
493 
494  std::string name() override { return "Event"; }
495  int nbins() override { return _nevents; }
496  double min() override { return 0.5; }
497  double max() override { return _nevents + 0.5; }
498 
499  protected:
500  int _nevents;
501  };
502 
503  class EventType : public ValueQuantity {
504  public:
506  EventType(std::vector<uint32_t> const &vtypes) : ValueQuantity(fN) { this->setup(vtypes); }
507  ~EventType() override {}
508 
509  virtual void setup(std::vector<uint32_t> const &vtypes) {
510  std::cout << "SIZE = " << vtypes.size() << std::endl;
511  for (uint32_t i = 0; i < vtypes.size(); i++)
512  _types.insert(std::make_pair((uint32_t)vtypes[i], i));
513  }
514  int getValue(int v) override { return _types[(uint32_t)v]; }
515  uint32_t getBin(int v) override { return getValue(v) + 1; }
516 
517  int nbins() override { return _types.size(); }
518  double min() override { return 0; }
519  double max() override { return _types.size(); }
520  std::string name() override { return "Event Type"; }
521 
522  protected:
523  typedef std::unordered_map<uint32_t, int> TypeMap;
525 
526  public:
527  std::vector<std::string> getLabels() override {
528  std::vector<std::string> labels(_types.size());
529  std::cout << "SIZE = " << _types.size() << std::endl;
530  for (auto const &v : _types) {
532  }
533  return labels;
534  }
535  EventType *makeCopy() override {
536  std::vector<uint32_t> vtypes;
537  for (auto const &p : _types) {
538  vtypes.push_back(p.first);
539  }
540 
541  std::sort(vtypes.begin(), vtypes.end());
542  return new EventType(vtypes);
543  }
544  };
545  } // namespace quantity
546 } // namespace hcaldqm
547 
548 #endif
ValueQuantity(ValueQuantityType type, bool isLog=false)
const std::map< ValueQuantityType, int > nbins_value
virtual void setBits(TH1 *o)
Definition: Quantity.h:51
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
LumiSectionCoarse * makeCopy() override
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
tuple runs
Definition: gather_cfg.py:88
std::vector< flag::Flag > _flags
std::string name() override
int getValue(int v) override
std::string ogtype2string(constants::OrbitGapType type)
Definition: Utilities.cc:197
std::unordered_map< uint32_t, int > TypeMap
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
tuple binning
Definition: pileupCalc.py:163
int getValue(int l) override
uint32_t getBin(int l) override
virtual bool isLog()
Definition: Quantity.h:35
const std::map< ValueQuantityType, double > max_value
LumiSection * makeCopy() override
RunNumber(std::vector< int > runs)
int const BIT_OFFSET
Definition: Constants.h:282
std::vector< std::string > getLabels() override
uint32_t getBin(int f) override
ValueQuantity * makeCopy() override
int const BIT_AXIS_LS
Definition: Constants.h:286
tuple cout
Definition: gather_cfg.py:144
double getValue(double x) override
std::string name() override