Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:28

0001 #ifndef ValueQuantity_h
0002 #define ValueQuantity_h
0003 
0004 #include "DQM/HcalCommon/interface/Flag.h"
0005 #include "DQM/HcalCommon/interface/Quantity.h"
0006 #include <unordered_map>
0007 
0008 namespace hcaldqm {
0009   namespace quantity {
0010     enum ValueQuantityType {
0011       fN,
0012       fEvents,
0013       fEnergy,
0014       fTiming_ns,
0015       fADC_128,
0016       fADC_5,
0017       fADC_15,
0018       ffC_10000,
0019       ffC_1000,
0020       ffC_3000,
0021       fTiming_TS,
0022       fTiming_TS200,
0023       fLS,
0024       fEt_256,
0025       fEt_128,
0026       fFG,
0027       fRatio,
0028       fDigiSize,
0029       fAroundZero,
0030       fRatio2,
0031       fdEtRatio,
0032       fSumdEt,
0033       fTiming_100TS,
0034       fQIE10ADC_256,
0035       fQIE10TDC_64,
0036       fQIE10TDC_16,
0037       fQIE10TDC_4,
0038       fDiffAbs,
0039       fRatio_0to2,
0040       fN_to8000,
0041       fEnergyTotal,
0042       fN_m0to10000,
0043       fEtCorr_256,
0044       fEtCorr_data,
0045       fEtCorr_emul,
0046       fADCCorr_128,
0047       fBX,
0048       fEnergy_1TeV,
0049       fState,
0050       fQIE10fC_400000,
0051       fDataSize,
0052       fQIE10fC_2000,
0053       fQIE10fC_10000,
0054       fQIE8fC_1000_50,
0055       fTime_ns_250,
0056       fADC_256,
0057       ffC_generic_10000,
0058       ffC_generic_400000,
0059       fQIE10ADC_16,
0060       fDualAnodeAsymmetry,
0061       fTimingRatio,
0062       fQIE10fC_100000Coarse,
0063       fBadTDC,
0064       fRBX,
0065       fTimingDiff_ns,
0066       ffC_1000000,
0067       fTime_ns_250_coarse,
0068       fCapidMinusBXmod4,
0069       fBX_36,
0070       fADC_256_4,  // ADC from 0-255, with 4 ADC granularity
0071       fEtlog2,     // scale log2(ET+1)
0072       fDiffRatio,  // (v2-v1)/v1
0073       fCPUenergy,
0074       fGPUenergy,
0075     };
0076     const std::map<ValueQuantityType, std::string> name_value = {
0077         {fN, "N"},
0078         {fEvents, "Events"},
0079         {fEnergy, "Energy"},
0080         {fTiming_ns, "Timing"},
0081         {fADC_5, "ADC (QIE8)"},
0082         {fADC_15, "ADC (QIE8)"},
0083         {fADC_128, "ADC (QIE8)"},
0084         {fADC_256, "ADC"},
0085         {fQIE10ADC_256, "ADC (QIE10/11)"},
0086         {fQIE10ADC_16, "ADC (QIE10/11)"},
0087         {ffC_1000, "fC (QIE8/10/11)"},
0088         {ffC_3000, "fC (QIE8/10/11)"},
0089         {ffC_10000, "fC (QIE8/10/11)"},
0090         {fQIE8fC_1000_50, "fC"},
0091         {fQIE10fC_2000, "fC"},
0092         {fQIE10fC_10000, "fC"},
0093         {fQIE10fC_400000, "fC"},
0094         {ffC_generic_10000, "fC (QIE8/10/11)"},
0095         {ffC_generic_400000, "fC (QIE8/10/11)"},
0096         {fTiming_TS, "Timing"},
0097         {fTiming_TS200, "Timing"},
0098         {fLS, "LS"},
0099         {fEt_256, "Et"},
0100         {fEt_128, "Et"},
0101         {fFG, "FG"},
0102         {fRatio, "Ratio"},
0103         {fDigiSize, "DigiSize"},
0104         {fAroundZero, "Q"},
0105         {fRatio2, "Ratio"},
0106         {fdEtRatio, "dEtRatio"},
0107         {fSumdEt, "SumdEt"},
0108         {fTiming_100TS, "Timing"},
0109         {fQIE10TDC_64, "TDC"},
0110         {fQIE10TDC_16, "TDC"},
0111         {fQIE10TDC_4, "TDC"},
0112         {fDiffAbs, "Q"},
0113         {fRatio_0to2, "Ratio"},
0114         {fN_to8000, "N"},
0115         {fEnergyTotal, "Energy"},
0116         {fN_m0to10000, "N"},
0117         {fEtCorr_256, "Et"},
0118         {fEtCorr_data, "256*TS + Et (Data TP)"},
0119         {fEtCorr_emul, "256*TS + Et (Emul TP)"},
0120         {fADCCorr_128, "ADC"},
0121         {fBX, "BX"},
0122         {fEnergy_1TeV, "Energy"},
0123         {fState, "State"},
0124         {fDataSize, "FED Data Size (kB)"},
0125         {fTime_ns_250, "Time (ns)"},
0126         {fDualAnodeAsymmetry, "(q_{1}-q_{2})/(q_{1}+q_{2})"},
0127         {fTimingRatio, "q_{SOI+1}/q_{SOI}"},
0128         {fQIE10fC_100000Coarse, "fC"},
0129         {fBadTDC, "TDC"},
0130         {fRBX, "RBX"},
0131         {fTimingDiff_ns, "#Delta timing [ns]"},
0132         {ffC_1000000, "fC"},
0133         {fTime_ns_250_coarse, "Time (ns)"},
0134         {fCapidMinusBXmod4, "(CapId - BX) % 4"},
0135         {fBX_36, "BX"},
0136         {fADC_256_4, "ADC"},
0137         {fEtlog2, "log_{2}(Et+1)"},
0138         {fDiffRatio, "(GPU energy - CPU energy)/CPU energy"},
0139         {fCPUenergy, "CPU energy"},
0140         {fGPUenergy, "GPU energy"},
0141     };
0142     const std::map<ValueQuantityType, double> min_value = {
0143         {fN, -0.05},
0144         {fEvents, 0},
0145         {fEnergy, 0},
0146         {fTiming_ns, -50},
0147         {fADC_128, -0.5},
0148         {fADC_5, -0.5},
0149         {fADC_15, -0.5},
0150         {ffC_10000, 0},
0151         {ffC_1000, 0},
0152         {ffC_3000, 0},
0153         {fTiming_TS, -0.5},
0154         {fTiming_TS200, -0.5},
0155         {fLS, 0.5},
0156         {fEt_256, 0},
0157         {fEt_128, 0},
0158         {fFG, 0},
0159         {fRatio, 0},
0160         {fDigiSize, -0.5},
0161         {fAroundZero, -1},
0162         {fRatio2, 0.5},
0163         {fdEtRatio, 0},
0164         {fSumdEt, 0},
0165         {fTiming_100TS, -0.5},
0166         {fQIE10ADC_256, -0.5},
0167         {fQIE10ADC_16, -0.5},
0168         {fQIE10TDC_64, -0.5},
0169         {fQIE10TDC_16, -0.5},
0170         {fQIE10TDC_4, -0.5},
0171         {fDiffAbs, 0},
0172         {fRatio_0to2, 0},
0173         {fN_to8000, 0},
0174         {fEnergyTotal, 0},
0175         {fN_m0to10000, -0.05},
0176         {fEtCorr_256, -1},
0177         {fEtCorr_data, -4},
0178         {fEtCorr_emul, -4},
0179         {fADCCorr_128, -2},
0180         {fBX, -0.5},
0181         {fEnergy_1TeV, 0},
0182         {fState, flag::fNA},
0183         {fQIE10fC_400000, 0},
0184         {fDataSize, 0},
0185         {fQIE10fC_2000, 0},
0186         {fQIE10fC_10000, 0},
0187         {fQIE8fC_1000_50, 0},
0188         {fTime_ns_250, -0.5},
0189         {fADC_256, -0.5},
0190         {ffC_generic_10000, 0.},
0191         {ffC_generic_400000, 0.},
0192         {fDualAnodeAsymmetry, -1.},
0193         {fTimingRatio, 0.},
0194         {fQIE10fC_100000Coarse, 0},
0195         {fBadTDC, 49.5},
0196         {fRBX, 0.5},
0197         {fTimingDiff_ns, -125.},
0198         {ffC_1000000, 0.},
0199         {fTime_ns_250_coarse, -0.5},
0200         {fCapidMinusBXmod4, -0.5},
0201         {fBX_36, -0.5},
0202         {fADC_256_4, -0.5},
0203         {fEtlog2, 0.},
0204         {fDiffRatio, -2.5},
0205         {fCPUenergy, 0},
0206         {fGPUenergy, 0},
0207     };
0208     const std::map<ValueQuantityType, double> max_value = {
0209         {fN, 1000},
0210         {fEvents, 1000},
0211         {fEnergy, 200},
0212         {fTiming_ns, 50},
0213         {fADC_128, 127.5},
0214         {fADC_5, 5},
0215         {fADC_15, 15},
0216         {ffC_10000, 10000},
0217         {ffC_1000, 1000},
0218         {ffC_3000, 3000},
0219         {fTiming_TS, 9.5},
0220         {fTiming_TS200, 9.5},
0221         {fLS, 4000.5},
0222         {fEt_256, 255.5},
0223         {fEt_128, 255.5},
0224         {fFG, 2},
0225         {fRatio, 1},
0226         {fDigiSize, 20.5},
0227         {fAroundZero, 1},
0228         {fRatio2, 1.5},
0229         {fdEtRatio, 1},
0230         {fSumdEt, 1000},
0231         {fTiming_100TS, 99.5},
0232         {fQIE10ADC_256, 255.5},
0233         {fQIE10ADC_16, 15.5},
0234         {fQIE10TDC_64, 63.5},
0235         {fQIE10TDC_16, 15.5},
0236         {fQIE10TDC_4, 3.5},
0237         {fDiffAbs, 1},
0238         {fRatio_0to2, 2},
0239         {fN_to8000, 8000},
0240         {fEnergyTotal, 100000},
0241         {fN_m0to10000, 10000},
0242         {fEtCorr_256, 257},
0243         {fEtCorr_data, 1028},
0244         {fEtCorr_emul, 1028},
0245         {fADCCorr_128, 128},
0246         {fBX, 3600.5},
0247         {fEnergy_1TeV, 1000},
0248         {fState, flag::nState},
0249         {fQIE10fC_400000, 400000},
0250         {fDataSize, 100},
0251         {fQIE10fC_2000, 2000},
0252         {fQIE10fC_10000, 10000},
0253         {fQIE8fC_1000_50, 1000},
0254         {fTime_ns_250, 249.5},
0255         {fADC_256, 255.5},
0256         {ffC_generic_10000, 10000},
0257         {ffC_generic_400000, 400000},
0258         {fDualAnodeAsymmetry, 1.},
0259         {fTimingRatio, 2.5},
0260         {fQIE10fC_100000Coarse, 100000},
0261         {fBadTDC, 61.5},
0262         {fRBX, 18.5},
0263         {fTimingDiff_ns, 125.},
0264         {ffC_1000000, 1.e6},
0265         {fTime_ns_250_coarse, 249.5},
0266         {fCapidMinusBXmod4, 3.5},
0267         {fBX_36, 3564. - 0.5},
0268         {fADC_256_4, 255},
0269         {fEtlog2, 9.},
0270         {fDiffRatio, 2.5},
0271         {fCPUenergy, 200},
0272         {fGPUenergy, 200},
0273     };
0274     const std::map<ValueQuantityType, int> nbins_value = {
0275         {fN, 200},
0276         {fEvents, 200},
0277         {fEnergy, 100},
0278         {fTiming_ns, 200},
0279         {fADC_128, 128},
0280         {fADC_5, 100},
0281         {fADC_15, 300},
0282         {ffC_10000, 1000},
0283         {ffC_1000, 200},
0284         {ffC_3000, 600},
0285         {fTiming_TS, 10},
0286         {fTiming_TS200, 200},
0287         {fLS, 4000},
0288         {fEt_256, 256},
0289         {fEt_128, 128},
0290         {fFG, 2},
0291         {fRatio, 100},
0292         {fDigiSize, 21},
0293         {fAroundZero, 100},
0294         {fRatio2, 100},
0295         {fdEtRatio, 100},
0296         {fSumdEt, 100},
0297         {fTiming_100TS, 100},
0298         {fQIE10ADC_256, 256},
0299         {fQIE10TDC_64, 64},
0300         {fQIE10TDC_16, 16},
0301         {fQIE10TDC_4, 4},
0302         {fDiffAbs, 200},
0303         {fRatio_0to2, 100},
0304         {fN_to8000, 8000},
0305         {fEnergyTotal, 500},
0306         {fN_m0to10000, 100},
0307         {fEtCorr_256, 258},
0308         {fEtCorr_data, 258},
0309         {fEtCorr_emul, 258},
0310         {fADCCorr_128, 130},
0311         {fBX, 3601},
0312         {fEnergy_1TeV, 200},
0313         {fState, flag::nState},
0314         {fQIE10fC_400000, 1000},
0315         {fDataSize, 100},
0316         {fQIE10fC_2000, 100},
0317         {fQIE10fC_10000, 500},
0318         {fQIE8fC_1000_50, 50},
0319         {fTime_ns_250, 250},
0320         {fADC_256, 256},
0321         {ffC_generic_10000, 10000},
0322         {ffC_generic_400000, 10000},
0323         {fDualAnodeAsymmetry, 40},
0324         {fTimingRatio, 50},
0325         {fQIE10fC_100000Coarse, 1000},
0326         {fBadTDC, 12},
0327         {fRBX, 18},
0328         {fTimingDiff_ns, 40},
0329         {ffC_1000000, 1000},
0330         {fTime_ns_250_coarse, 100},
0331         {fCapidMinusBXmod4, 4},
0332         {fBX_36, 99},
0333         {fADC_256_4, 64},
0334         {fEtlog2, 9},
0335         {fDiffRatio, 50},
0336         {fCPUenergy, 1000},
0337         {fGPUenergy, 1000},
0338     };
0339     class ValueQuantity : public Quantity {
0340     public:
0341       ValueQuantity() : _type() {}
0342       ValueQuantity(ValueQuantityType type, bool isLog = false) : Quantity(name_value.at(type), isLog), _type(type) {}
0343       ~ValueQuantity() override {}
0344 
0345       ValueQuantity *makeCopy() override { return new ValueQuantity(_type, _isLog); }
0346 
0347       //    get Value to be overriden
0348       int getValue(int x) override {
0349         int ret_x = x;
0350         if (_showOverflow) {
0351           if (x < min()) {
0352             ret_x = min();
0353           } else if (x > max()) {
0354             ret_x = max();
0355           }
0356         }
0357         return ret_x;
0358       }
0359       double getValue(double x) override {
0360         double ret_x = x;
0361         if (_showOverflow) {
0362           if (x < min()) {
0363             ret_x = min();
0364           } else if (x > max()) {
0365             ret_x = max();
0366           }
0367         }
0368         return ret_x;
0369       }
0370 
0371       //    standard properties
0372       QuantityType type() override { return fValueQuantity; }
0373       int nbins() override { return nbins_value.at(_type); }
0374       double min() override { return min_value.at(_type); }
0375       double max() override { return max_value.at(_type); }
0376 
0377       void setBits(TH1 *o) override {
0378         Quantity::setBits(o);
0379         setLS(o);
0380       }
0381       virtual void setLS(TH1 *o) {
0382         if (_type == fLS) {
0383           //    for LS axis - set the bit
0384           //    set extendable axes.
0385           o->SetBit(BIT(constants::BIT_OFFSET + constants::BIT_AXIS_LS));
0386           //                o->SetCanExtend(TH1::kXaxis);
0387         }
0388       }
0389 
0390     protected:
0391       ValueQuantityType _type;
0392     };
0393 
0394     class FlagQuantity : public ValueQuantity {
0395     public:
0396       FlagQuantity() {}
0397       FlagQuantity(std::vector<flag::Flag> const &flags) : _flags(flags) {}
0398       ~FlagQuantity() override {}
0399 
0400       FlagQuantity *makeCopy() override { return new FlagQuantity(_flags); }
0401 
0402       std::string name() override { return "Flag"; }
0403       int nbins() override { return _flags.size(); }
0404       double min() override { return 0; }
0405       double max() override { return _flags.size(); }
0406       int getValue(int f) override { return f; }
0407       uint32_t getBin(int f) override { return f + 1; }
0408       std::vector<std::string> getLabels() override {
0409         std::vector<std::string> vnames;
0410         for (std::vector<flag::Flag>::const_iterator it = _flags.begin(); it != _flags.end(); ++it)
0411           vnames.push_back(it->_name);
0412 
0413         return vnames;
0414       }
0415 
0416     protected:
0417       std::vector<flag::Flag> _flags;
0418     };
0419 
0420     class LumiSection : public ValueQuantity {
0421     public:
0422       LumiSection() : ValueQuantity(fLS), _n(4000) {}
0423       LumiSection(int n) : ValueQuantity(fLS), _n(n) {}
0424       ~LumiSection() override {}
0425 
0426       LumiSection *makeCopy() override { return new LumiSection(_n); }
0427 
0428       std::string name() override { return "LS"; }
0429       int nbins() override { return _n; }
0430       double min() override { return 1; }
0431       double max() override { return _n + 1; }
0432       int getValue(int l) override { return l; }
0433       uint32_t getBin(int l) override { return getValue(l); }
0434       void setMax(double x) override { _n = x; }
0435 
0436     protected:
0437       int _n;
0438     };
0439 
0440     /**
0441  * Coarse LumiSection axis. Specify binning (default=10 LS)
0442  */
0443     class LumiSectionCoarse : public ValueQuantity {
0444     public:
0445       LumiSectionCoarse() : ValueQuantity(fLS), _n(4000), _binning(10) {}
0446       LumiSectionCoarse(int n, int binning) : ValueQuantity(fLS), _n(n), _binning(binning) {}
0447       ~LumiSectionCoarse() override {}
0448 
0449       LumiSectionCoarse *makeCopy() override { return new LumiSectionCoarse(_n, _binning); }
0450 
0451       std::string name() override { return "LS"; }
0452       int nbins() override { return (_n + _binning - 1) / _binning; }
0453       double min() override { return 1; }
0454       double max() override { return _n + 1; }
0455       int getValue(int l) override { return l; }
0456       uint32_t getBin(int l) override { return (l + _binning - 1) / _binning; }
0457       void setMax(double x) override { _n = x; }
0458 
0459     protected:
0460       int _n;
0461       int _binning;
0462     };
0463 
0464     class RunNumber : public ValueQuantity {
0465     public:
0466       RunNumber() {}
0467       RunNumber(std::vector<int> runs) : _runs(runs) {}
0468       ~RunNumber() override {}
0469 
0470       std::string name() override { return "Run"; }
0471       int nbins() override { return _runs.size(); }
0472       double min() override { return 0; }
0473       double max() override { return _runs.size(); }
0474       std::vector<std::string> getLabels() override {
0475         char name[10];
0476         std::vector<std::string> labels;
0477         for (uint32_t i = 0; i < _runs.size(); i++) {
0478           sprintf(name, "%d", _runs[i]);
0479           labels.push_back(name);
0480         }
0481         return labels;
0482       }
0483       int getValue(int run) override {
0484         int ir = -1;
0485         for (uint32_t i = 0; i < _runs.size(); i++)
0486           if (_runs[i] == run) {
0487             ir = (int)i;
0488             break;
0489           }
0490 
0491         if (ir == -1)
0492           throw cms::Exception("HCALDQM") << "run number doens't exist " << run;
0493 
0494         return ir;
0495       }
0496 
0497       uint32_t getBin(int run) override { return (this->getValue(run) + 1); }
0498 
0499     protected:
0500       std::vector<int> _runs;
0501     };
0502 
0503     class EventNumber : public ValueQuantity {
0504     public:
0505       EventNumber() {}
0506       EventNumber(int nevents) : ValueQuantity(fN), _nevents(nevents) {}
0507       ~EventNumber() override {}
0508 
0509       std::string name() override { return "Event"; }
0510       int nbins() override { return _nevents; }
0511       double min() override { return 0.5; }
0512       double max() override { return _nevents + 0.5; }
0513 
0514     protected:
0515       int _nevents;
0516     };
0517 
0518     class EventType : public ValueQuantity {
0519     public:
0520       EventType() {}
0521       EventType(std::vector<uint32_t> const &vtypes) : ValueQuantity(fN) { this->setup(vtypes); }
0522       ~EventType() override {}
0523 
0524       virtual void setup(std::vector<uint32_t> const &vtypes) {
0525         std::cout << "SIZE = " << vtypes.size() << std::endl;
0526         for (uint32_t i = 0; i < vtypes.size(); i++)
0527           _types.insert(std::make_pair((uint32_t)vtypes[i], i));
0528       }
0529       int getValue(int v) override { return _types[(uint32_t)v]; }
0530       uint32_t getBin(int v) override { return getValue(v) + 1; }
0531 
0532       int nbins() override { return _types.size(); }
0533       double min() override { return 0; }
0534       double max() override { return _types.size(); }
0535       std::string name() override { return "Event Type"; }
0536 
0537     protected:
0538       typedef std::unordered_map<uint32_t, int> TypeMap;
0539       TypeMap _types;
0540 
0541     public:
0542       std::vector<std::string> getLabels() override {
0543         std::vector<std::string> labels(_types.size());
0544         std::cout << "SIZE = " << _types.size() << std::endl;
0545         for (auto const &v : _types) {
0546           labels[v.second] = utilities::ogtype2string((constants::OrbitGapType)v.first);
0547         }
0548         return labels;
0549       }
0550       EventType *makeCopy() override {
0551         std::vector<uint32_t> vtypes;
0552         for (auto const &p : _types) {
0553           vtypes.push_back(p.first);
0554         }
0555 
0556         std::sort(vtypes.begin(), vtypes.end());
0557         return new EventType(vtypes);
0558       }
0559     };
0560   }  // namespace quantity
0561 }  // namespace hcaldqm
0562 
0563 #endif