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