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 
8 namespace hcaldqm {
9  namespace quantity {
11  fN,
23  fLS,
26  fFG,
45  fBX,
68  fADC_256_4, // ADC from 0-255, with 4 ADC granularity
69  };
70  const std::map<ValueQuantityType, std::string> name_value = {
71  {fN, "N"},
72  {fEvents, "Events"},
73  {fEnergy, "Energy"},
74  {fTiming_ns, "Timing"},
75  {fADC_5, "ADC (QIE8)"},
76  {fADC_15, "ADC (QIE8)"},
77  {fADC_128, "ADC (QIE8)"},
78  {fADC_256, "ADC"},
79  {fQIE10ADC_256, "ADC (QIE10/11)"},
80  {fQIE10ADC_16, "ADC (QIE10/11)"},
81  {ffC_1000, "fC (QIE8)"},
82  {ffC_3000, "fC (QIE8)"},
83  {ffC_10000, "fC (QIE8)"},
84  {fQIE8fC_1000_50, "fC"},
85  {fQIE10fC_2000, "fC"},
86  {fQIE10fC_10000, "fC"},
87  {fQIE10fC_400000, "fC"},
88  {ffC_generic_10000, "fC (QIE8/10/11)"},
89  {ffC_generic_400000, "fC (QIE8/10/11)"},
90  {fTiming_TS, "Timing"},
91  {fTiming_TS200, "Timing"},
92  {fLS, "LS"},
93  {fEt_256, "Et"},
94  {fEt_128, "Et"},
95  {fFG, "FG"},
96  {fRatio, "Ratio"},
97  {fDigiSize, "DigiSize"},
98  {fAroundZero, "Q"},
99  {fRatio2, "Ratio"},
100  {fdEtRatio, "dEtRatio"},
101  {fSumdEt, "SumdEt"},
102  {fTiming_100TS, "Timing"},
103  {fQIE10TDC_64, "TDC"},
104  {fQIE10TDC_16, "TDC"},
105  {fQIE10TDC_4, "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  {fBX_36, "BX"},
128  {fADC_256_4, "ADC"},
129  };
130  const std::map<ValueQuantityType, double> min_value = {
131  {fN, -0.05},
132  {fEvents, 0},
133  {fEnergy, 0},
134  {fTiming_ns, -50},
135  {fADC_128, -0.5},
136  {fADC_5, -0.5},
137  {fADC_15, -0.5},
138  {ffC_10000, 0},
139  {ffC_1000, 0},
140  {ffC_3000, 0},
141  {fTiming_TS, -0.5},
142  {fTiming_TS200, -0.5},
143  {fLS, 0.5},
144  {fEt_256, 0},
145  {fEt_128, 0},
146  {fFG, 0},
147  {fRatio, 0},
148  {fDigiSize, -0.5},
149  {fAroundZero, -1},
150  {fRatio2, 0.5},
151  {fdEtRatio, 0},
152  {fSumdEt, 0},
153  {fTiming_100TS, -0.5},
154  {fQIE10ADC_256, -0.5},
155  {fQIE10ADC_16, -0.5},
156  {fQIE10TDC_64, -0.5},
157  {fQIE10TDC_16, -0.5},
158  {fQIE10TDC_4, -0.5},
159  {fDiffAbs, 0},
160  {fRatio_0to2, 0},
161  {fN_to8000, 0},
162  {fEnergyTotal, 0},
163  {fN_m0to10000, -0.05},
164  {fEtCorr_256, -1},
165  {fADCCorr_128, -2},
166  {fBX, -0.5},
167  {fEnergy_1TeV, 0},
168  {fState, flag::fNA},
169  {fQIE10fC_400000, 0},
170  {fDataSize, 0},
171  {fQIE10fC_2000, 0},
172  {fQIE10fC_10000, 0},
173  {fQIE8fC_1000_50, 0},
174  {fTime_ns_250, -0.5},
175  {fADC_256, -0.5},
176  {ffC_generic_10000, 0.},
177  {ffC_generic_400000, 0.},
178  {fDualAnodeAsymmetry, -1.},
179  {fTimingRatio, 0.},
181  {fBadTDC, 49.5},
182  {fRBX, 0.5},
183  {fTimingDiff_ns, -125.},
184  {ffC_1000000, 0.},
185  {fTime_ns_250_coarse, -0.5},
186  {fCapidMinusBXmod4, -0.5},
187  {fBX_36, -0.5},
188  {fADC_256_4, -0.5},
189  };
190  const std::map<ValueQuantityType, double> max_value = {
191  {fN, 1000},
192  {fEvents, 1000},
193  {fEnergy, 200},
194  {fTiming_ns, 50},
195  {fADC_128, 127.5},
196  {fADC_5, 5},
197  {fADC_15, 15},
198  {ffC_10000, 10000},
199  {ffC_1000, 1000},
200  {ffC_3000, 3000},
201  {fTiming_TS, 9.5},
202  {fTiming_TS200, 9.5},
203  {fLS, 4000.5},
204  {fEt_256, 255.5},
205  {fEt_128, 255.5},
206  {fFG, 2},
207  {fRatio, 1},
208  {fDigiSize, 20.5},
209  {fAroundZero, 1},
210  {fRatio2, 1.5},
211  {fdEtRatio, 1},
212  {fSumdEt, 1000},
213  {fTiming_100TS, 99.5},
214  {fQIE10ADC_256, 255.5},
215  {fQIE10ADC_16, 15.5},
216  {fQIE10TDC_64, 63.5},
217  {fQIE10TDC_16, 15.5},
218  {fQIE10TDC_4, 3.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},
228  {fState, flag::nState},
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  {fQIE10TDC_4, 4},
278  {fDiffAbs, 200},
279  {fRatio_0to2, 100},
280  {fN_to8000, 8000},
281  {fEnergyTotal, 500},
282  {fN_m0to10000, 100},
283  {fEtCorr_256, 258},
284  {fADCCorr_128, 130},
285  {fBX, 3601},
286  {fEnergy_1TeV, 200},
287  {fState, flag::nState},
288  {fQIE10fC_400000, 1000},
289  {fDataSize, 100},
290  {fQIE10fC_2000, 100},
291  {fQIE10fC_10000, 500},
292  {fQIE8fC_1000_50, 50},
293  {fTime_ns_250, 250},
294  {fADC_256, 256},
295  {ffC_generic_10000, 10000},
296  {ffC_generic_400000, 10000},
297  {fDualAnodeAsymmetry, 40},
298  {fTimingRatio, 50},
299  {fQIE10fC_100000Coarse, 1000},
300  {fBadTDC, 12},
301  {fRBX, 18},
302  {fTimingDiff_ns, 40},
303  {ffC_1000000, 1000},
304  {fTime_ns_250_coarse, 100},
305  {fCapidMinusBXmod4, 4},
306  {fBX_36, 99},
307  {fADC_256_4, 64},
308  };
309  class ValueQuantity : public Quantity {
310  public:
312  ValueQuantity(ValueQuantityType type, bool isLog = false) : Quantity(name_value.at(type), isLog), _type(type) {}
313  ~ValueQuantity() override {}
314 
315  ValueQuantity *makeCopy() override { return new ValueQuantity(_type, _isLog); }
316 
317  // get Value to be overriden
318  int getValue(int x) override {
319  int ret_x = x;
320  if (_showOverflow) {
321  if (x < min()) {
322  ret_x = min();
323  } else if (x > max()) {
324  ret_x = max();
325  }
326  }
327  return ret_x;
328  }
329  double getValue(double x) override {
330  double ret_x = x;
331  if (_showOverflow) {
332  if (x < min()) {
333  ret_x = min();
334  } else if (x > max()) {
335  ret_x = max();
336  }
337  }
338  return ret_x;
339  }
340 
341  // standard properties
342  QuantityType type() override { return fValueQuantity; }
343  int nbins() override { return nbins_value.at(_type); }
344  double min() override { return min_value.at(_type); }
345  double max() override { return max_value.at(_type); }
346 
347  void setBits(TH1 *o) override {
349  setLS(o);
350  }
351  virtual void setLS(TH1 *o) {
352  if (_type == fLS) {
353  // for LS axis - set the bit
354  // set extendable axes.
356  // o->SetCanExtend(TH1::kXaxis);
357  }
358  }
359 
360  protected:
362  };
363 
364  class FlagQuantity : public ValueQuantity {
365  public:
367  FlagQuantity(std::vector<flag::Flag> const &flags) : _flags(flags) {}
368  ~FlagQuantity() override {}
369 
370  FlagQuantity *makeCopy() override { return new FlagQuantity(_flags); }
371 
372  std::string name() override { return "Flag"; }
373  int nbins() override { return _flags.size(); }
374  double min() override { return 0; }
375  double max() override { return _flags.size(); }
376  int getValue(int f) override { return f; }
377  uint32_t getBin(int f) override { return f + 1; }
378  std::vector<std::string> getLabels() override {
379  std::vector<std::string> vnames;
380  for (std::vector<flag::Flag>::const_iterator it = _flags.begin(); it != _flags.end(); ++it)
381  vnames.push_back(it->_name);
382 
383  return vnames;
384  }
385 
386  protected:
387  std::vector<flag::Flag> _flags;
388  };
389 
390  class LumiSection : public ValueQuantity {
391  public:
392  LumiSection() : ValueQuantity(fLS), _n(4000) {}
393  LumiSection(int n) : ValueQuantity(fLS), _n(n) {}
394  ~LumiSection() override {}
395 
396  LumiSection *makeCopy() override { return new LumiSection(_n); }
397 
398  std::string name() override { return "LS"; }
399  int nbins() override { return _n; }
400  double min() override { return 1; }
401  double max() override { return _n + 1; }
402  int getValue(int l) override { return l; }
403  uint32_t getBin(int l) override { return getValue(l); }
404  void setMax(double x) override { _n = x; }
405 
406  protected:
407  int _n;
408  };
409 
414  public:
415  LumiSectionCoarse() : ValueQuantity(fLS), _n(4000), _binning(10) {}
416  LumiSectionCoarse(int n, int binning) : ValueQuantity(fLS), _n(n), _binning(binning) {}
417  ~LumiSectionCoarse() override {}
418 
419  LumiSectionCoarse *makeCopy() override { return new LumiSectionCoarse(_n, _binning); }
420 
421  std::string name() override { return "LS"; }
422  int nbins() override { return (_n + _binning - 1) / _binning; }
423  double min() override { return 1; }
424  double max() override { return _n + 1; }
425  int getValue(int l) override { return l; }
426  uint32_t getBin(int l) override { return (l + _binning - 1) / _binning; }
427  void setMax(double x) override { _n = x; }
428 
429  protected:
430  int _n;
431  int _binning;
432  };
433 
434  class RunNumber : public ValueQuantity {
435  public:
437  RunNumber(std::vector<int> runs) : _runs(runs) {}
438  ~RunNumber() override {}
439 
440  std::string name() override { return "Run"; }
441  int nbins() override { return _runs.size(); }
442  double min() override { return 0; }
443  double max() override { return _runs.size(); }
444  std::vector<std::string> getLabels() override {
445  char name[10];
446  std::vector<std::string> labels;
447  for (uint32_t i = 0; i < _runs.size(); i++) {
448  sprintf(name, "%d", _runs[i]);
449  labels.push_back(name);
450  }
451  return labels;
452  }
453  int getValue(int run) override {
454  int ir = -1;
455  for (uint32_t i = 0; i < _runs.size(); i++)
456  if (_runs[i] == run) {
457  ir = (int)i;
458  break;
459  }
460 
461  if (ir == -1)
462  throw cms::Exception("HCALDQM") << "run number doens't exist " << run;
463 
464  return ir;
465  }
466 
467  uint32_t getBin(int run) override { return (this->getValue(run) + 1); }
468 
469  protected:
470  std::vector<int> _runs;
471  };
472 
473  class EventNumber : public ValueQuantity {
474  public:
476  EventNumber(int nevents) : ValueQuantity(fN), _nevents(nevents) {}
477  ~EventNumber() override {}
478 
479  std::string name() override { return "Event"; }
480  int nbins() override { return _nevents; }
481  double min() override { return 0.5; }
482  double max() override { return _nevents + 0.5; }
483 
484  protected:
485  int _nevents;
486  };
487 
488  class EventType : public ValueQuantity {
489  public:
491  EventType(std::vector<uint32_t> const &vtypes) : ValueQuantity(fN) { this->setup(vtypes); }
492  ~EventType() override {}
493 
494  virtual void setup(std::vector<uint32_t> const &vtypes) {
495  std::cout << "SIZE = " << vtypes.size() << std::endl;
496  for (uint32_t i = 0; i < vtypes.size(); i++)
497  _types.insert(std::make_pair((uint32_t)vtypes[i], i));
498  }
499  int getValue(int v) override { return _types[(uint32_t)v]; }
500  uint32_t getBin(int v) override { return getValue(v) + 1; }
501 
502  int nbins() override { return _types.size(); }
503  double min() override { return 0; }
504  double max() override { return _types.size(); }
505  std::string name() override { return "Event Type"; }
506 
507  protected:
508  typedef boost::unordered_map<uint32_t, int> TypeMap;
509  TypeMap _types;
510 
511  public:
512  std::vector<std::string> getLabels() override {
513  std::vector<std::string> labels(_types.size());
514  std::cout << "SIZE = " << _types.size() << std::endl;
515  for (auto const &v : _types) {
517  }
518  return labels;
519  }
520  EventType *makeCopy() override {
521  std::vector<uint32_t> vtypes;
522  for (auto const &p : _types) {
523  vtypes.push_back(p.first);
524  }
525 
526  std::sort(vtypes.begin(), vtypes.end());
527  return new EventType(vtypes);
528  }
529  };
530  } // namespace quantity
531 } // namespace hcaldqm
532 
533 #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:51
virtual std::string name()
Definition: Quantity.h:34
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:196
void setMax(double x) override
std::vector< std::string > getLabels() override
const std::map< ValueQuantityType, std::string > name_value
Definition: ValueQuantity.h:70
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
RunNumber(std::vector< int > runs)
int const BIT_OFFSET
Definition: Constants.h:277
std::vector< std::string > getLabels() override
uint32_t getBin(int f) override
ValueQuantity * makeCopy() override
int const BIT_AXIS_LS
Definition: Constants.h:281
double getValue(double x) override
std::string name() override