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