CMS 3D CMS Logo

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