Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-26 03:51:37

0001 #ifndef DQM_HcalCommon_Utilities_h
0002 #define DQM_HcalCommon_Utilities_h
0003 
0004 /*
0005  *  file:           Utilities.h
0006  *  Author:         Viktor Khristenko
0007  *
0008  *  Description:
0009  *      Utility functions
0010  */
0011 
0012 #include "DQM/HcalCommon/interface/Constants.h"
0013 #include "DQM/HcalCommon/interface/HcalCommonHeaders.h"
0014 
0015 namespace hcaldqm {
0016   namespace utilities {
0017     /*
0018  * adc2fC lookup from conditions
0019  * fC values are stored in CaloSamples tool
0020  */
0021     template <class Digi>
0022     CaloSamples loadADC2fCDB(const edm::ESHandle<HcalDbService> &conditions, const HcalDetId did, const Digi &digi) {
0023       CaloSamples calo_samples;
0024       const HcalQIECoder *channelCoder = conditions->getHcalCoder(did);
0025       const HcalQIEShape *shape = conditions->getHcalShape(channelCoder);
0026       HcalCoderDb coder(*channelCoder, *shape);
0027       coder.adc2fC(digi, calo_samples);
0028       return calo_samples;
0029     }
0030 
0031     // Get pedestal-subtracted charge
0032     template <class Digi>
0033     double adc2fCDBMinusPedestal(const edm::ESHandle<HcalDbService> &conditions,
0034                                  const CaloSamples &calo_samples,
0035                                  const HcalDetId did,
0036                                  const Digi &digi,
0037                                  unsigned int n) {
0038       HcalCalibrations calibrations = conditions->getHcalCalibrations(did);
0039       int capid = digi[n].capid();
0040       return calo_samples[n] - calibrations.pedestal(capid);
0041     }
0042 
0043     template <class Digi>
0044     double aveTSDB(const edm::ESHandle<HcalDbService> &conditions,
0045                    const CaloSamples &calo_samples,
0046                    const HcalDetId did,
0047                    const Digi &digi,
0048                    unsigned int i_start,
0049                    unsigned int i_end,
0050                    bool dopedsubtr = true) {
0051       double sumQ = 0;
0052       double sumQT = 0;
0053       for (unsigned int i = i_start; i <= i_end; ++i) {
0054         double q = dopedsubtr ? adc2fCDBMinusPedestal(conditions, calo_samples, did, digi, i) : calo_samples[i];
0055         sumQ += q;
0056         sumQT += (i + 1) * q;
0057       }
0058       return (sumQ > 0 ? sumQT / sumQ - 1 : constants::GARBAGE_VALUE);
0059     }
0060 
0061     template <class Digi>
0062     double sumQDB(const edm::ESHandle<HcalDbService> &conditions,
0063                   const CaloSamples &calo_samples,
0064                   const HcalDetId did,
0065                   const Digi &digi,
0066                   unsigned int i_start,
0067                   unsigned int i_end) {
0068       double sumQ = 0;
0069       for (unsigned int i = i_start; i <= i_end; ++i) {
0070         sumQ += adc2fCDBMinusPedestal(conditions, calo_samples, did, digi, i);
0071       }
0072       return sumQ;
0073     }
0074 
0075     /*
0076  *  Some useful functions for QIE10/11 Data Frames
0077  */
0078     template <typename FRAME>
0079     double aveTS_v10(FRAME const &frame, double ped = 0, int i = 0, int j = 3) {
0080       double sumQ = 0;
0081       double sumQT = 0;
0082       for (int ii = i; ii <= j; ii++) {
0083         double q = constants::adc2fC[frame[ii].adc()] - ped;
0084         sumQ += q;
0085         sumQT += (ii + 1) * q;
0086       }
0087 
0088       return sumQ > 0 ? sumQT / sumQ - 1 : constants::GARBAGE_VALUE;
0089     }
0090 
0091     template <typename FRAME>
0092     double sumQ_v10(FRAME const &frame, double ped, int i = 0, int j = 3) {
0093       double sumQ = 0;
0094       for (int ii = i; ii <= j; ii++)
0095         sumQ += constants::adc2fC[frame[ii].adc()] - ped;
0096       return sumQ;
0097     }
0098 
0099     /*
0100  *  Some useful functions on QIE8 digis
0101  */
0102     template <typename DIGI>
0103     int maxTS(DIGI const &digi, double ped = 0) {
0104       int maxTS = -1;
0105       double maxQ = -100;
0106       for (int i = 0; i < digi.size(); i++)
0107         if ((digi.sample(i).nominal_fC() - ped) > maxQ) {
0108           maxQ = digi.sample(i).nominal_fC() - ped;
0109           maxTS = i;
0110         }
0111       return maxTS;
0112     }
0113 
0114     template <typename DIGI>
0115     double aveTS(DIGI const &digi, double ped = 0, int i = 0, int j = 3) {
0116       double sumQ = 0;
0117       double sumQT = 0;
0118       for (int ii = i; ii <= j; ii++) {
0119         sumQ += digi.sample(ii).nominal_fC() - ped;
0120         sumQT += (ii + 1) * (digi.sample(ii).nominal_fC() - ped);
0121       }
0122 
0123       return sumQ > 0 ? sumQT / sumQ - 1 : constants::GARBAGE_VALUE;
0124     }
0125 
0126     template <typename DIGI>
0127     double sumQ(DIGI const &digi, double ped, int i = 0, int j = 3) {
0128       double sum = 0;
0129       for (int ii = i; ii <= j; ii++)
0130         sum += (digi.sample(ii).nominal_fC() - ped);
0131       return sum;
0132     }
0133 
0134     template <typename DIGI>
0135     double aveQ(DIGI const &digi, double ped, int i = 0, int j = 3) {
0136       return sumQ<DIGI>(digi, ped, i, j) / (j - i + 1);
0137     }
0138 
0139     template <typename DIGI>
0140     double sumADC(DIGI const &digi, double ped, int i = 0, int j = 3) {
0141       double sum = 0;
0142       for (int ii = i; ii <= j; ii++)
0143         sum += digi.sample(ii).adc() - ped;
0144       return sum;
0145     }
0146 
0147     template <typename DIGI>
0148     double aveADC(DIGI const &digi, double ped, int i = 0, int j = 3) {
0149       return sumADC<DIGI>(digi, ped, i, j) / (j - i + 1);
0150     }
0151 
0152     /*
0153  *  Log Functions
0154  */
0155     template <typename STDTYPE>
0156     void dqmdebug(STDTYPE const &x, int debug = 0) {
0157       if (debug == 0)
0158         return;
0159       std::cout << "%MSG" << std::endl;
0160       std::cout << "%MSG-d HCALDQM::" << x;
0161       std::cout << std::endl;
0162     }
0163 
0164     /*
0165  *  Useful Detector/Electronics/TrigTower Functions.
0166  *  For Fast Detector Validity Check
0167  */
0168     int getTPSubDet(HcalTrigTowerDetId const &);
0169     int getTPSubDetPM(HcalTrigTowerDetId const &);
0170 
0171     // Get a list of all crates
0172     std::vector<int> getCrateList(HcalElectronicsMap const *emap);
0173     std::map<int, uint32_t> getCrateHashMap(HcalElectronicsMap const *emap);
0174 
0175     //  returns a list of FEDs sorted.
0176     std::vector<int> getFEDList(HcalElectronicsMap const *);
0177     std::vector<int> getFEDVMEList(HcalElectronicsMap const *);
0178     std::vector<int> getFEDuTCAList(HcalElectronicsMap const *);
0179 
0180     std::pair<uint16_t, uint16_t> fed2crate(int fed);
0181     uint16_t crate2fed(int crate, int slot);
0182     bool isFEDHBHE(HcalElectronicsId const &);
0183     bool isFEDHF(HcalElectronicsId const &);
0184     bool isFEDHO(HcalElectronicsId const &);
0185 
0186     /**
0187  *  This is wrap around in case hashing scheme changes in the future
0188  */
0189     uint32_t hash(HcalDetId const &);
0190     uint32_t hash(HcalElectronicsId const &);
0191     uint32_t hash(HcalTrigTowerDetId const &);
0192 
0193     /*
0194  *  Orbit Gap Related
0195  */
0196     std::string ogtype2string(constants::OrbitGapType type);
0197 
0198     int getRBX(uint32_t iphi);
0199   }  // namespace utilities
0200 }  // namespace hcaldqm
0201 
0202 #endif