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