Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DQM_GEM_INTERFACE_GEMDQMBase_h
0002 #define DQM_GEM_INTERFACE_GEMDQMBase_h
0003 
0004 #include <map>
0005 #include <tuple>
0006 
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/PluginManager/interface/ModuleDef.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 
0016 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0017 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0018 #include "DQMServices/Core/interface/DQMStore.h"
0019 #include "DQMServices/Core/interface/MonitorElement.h"
0020 
0021 #include "CondFormats/GEMObjects/interface/GEMeMap.h"
0022 #include "Validation/MuonGEMHits/interface/GEMValidationUtils.h"
0023 
0024 #include "DataFormats/GEMDigi/interface/GEMDigiCollection.h"
0025 
0026 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
0027 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0028 
0029 class GEMDQMBase : public DQMEDAnalyzer {
0030 public:
0031   // Borrwed from DQM/GEM/interface/GEMOfflineDQMBase.h
0032   class BookingHelper {
0033   public:
0034     BookingHelper(DQMStore::IBooker &ibooker, const TString &name_suffix, const TString &title_suffix)
0035         : ibooker_(&ibooker), name_suffix_(name_suffix), title_suffix_(title_suffix) {}
0036 
0037     ~BookingHelper() {}
0038 
0039     MonitorElement *book1D(TString name,
0040                            TString title,
0041                            int nbinsx,
0042                            double xlow,
0043                            double xup,
0044                            TString x_title = "",
0045                            TString y_title = "Entries") {
0046       name += name_suffix_;
0047       title += title_suffix_ + ";" + x_title + ";" + y_title;
0048       return ibooker_->book1D(name, title, nbinsx, xlow, xup);
0049     }
0050 
0051     MonitorElement *book1D(TString name,
0052                            TString title,
0053                            std::vector<double> &x_binning,
0054                            TString x_title = "",
0055                            TString y_title = "Entries") {
0056       name += name_suffix_;
0057       title += title_suffix_ + ";" + x_title + ";" + y_title;
0058       TH1F *h_obj = new TH1F(name, title, x_binning.size() - 1, &x_binning[0]);
0059       return ibooker_->book1D(name, h_obj);
0060     }
0061 
0062     MonitorElement *book2D(TString name,
0063                            TString title,
0064                            int nbinsx,
0065                            double xlow,
0066                            double xup,
0067                            int nbinsy,
0068                            double ylow,
0069                            double yup,
0070                            TString x_title = "",
0071                            TString y_title = "") {
0072       name += name_suffix_;
0073       title += title_suffix_ + ";" + x_title + ";" + y_title;
0074       return ibooker_->book2D(name, title, nbinsx, xlow, xup, nbinsy, ylow, yup);
0075     }
0076 
0077     MonitorElement *bookProfile2D(TString name,
0078                                   TString title,
0079                                   int nbinsx,
0080                                   double xlow,
0081                                   double xup,
0082                                   int nbinsy,
0083                                   double ylow,
0084                                   double yup,
0085                                   double zlow,
0086                                   double zup,
0087                                   TString x_title = "",
0088                                   TString y_title = "") {
0089       name += name_suffix_;
0090       title += title_suffix_ + ";" + x_title + ";" + y_title;
0091       return ibooker_->bookProfile2D(name, title, nbinsx, xlow, xup, nbinsy, ylow, yup, zlow, zup);
0092     }
0093 
0094     DQMStore::IBooker *getBooker() { return ibooker_; }
0095 
0096   private:
0097     DQMStore::IBooker *ibooker_;
0098     const TString name_suffix_;
0099     const TString title_suffix_;
0100   };  // BookingHelper
0101 
0102   template <class M, class K>
0103   class MEMapInfT {
0104   public:
0105     MEMapInfT() : bOperating_(false), bIsNoUnderOverflowBin_(false){};
0106 
0107     MEMapInfT(
0108         GEMDQMBase *pDQMBase, TString strName, TString strTitle, TString strTitleX = "", TString strTitleY = "Entries")
0109         : pDQMBase_(pDQMBase),
0110           strName_(strName),
0111           strTitle_(strTitle),
0112           strTitleX_(strTitleX),
0113           strTitleY_(strTitleY),
0114           log_category_own_(pDQMBase->log_category_){};
0115 
0116     MEMapInfT(GEMDQMBase *pDQMBase,
0117               TString strName,
0118               TString strTitle,
0119               Int_t nBinsX,
0120               Double_t dXL,
0121               Double_t dXH,
0122               TString strTitleX = "",
0123               TString strTitleY = "Entries")
0124         : pDQMBase_(pDQMBase),
0125           strName_(strName),
0126           strTitle_(strTitle),
0127           strTitleX_(strTitleX),
0128           strTitleY_(strTitleY),
0129           bOperating_(true),
0130           bIsProfile_(false),
0131           bIsNoUnderOverflowBin_(false),
0132           nBinsX_(nBinsX),
0133           dXL_(dXL),
0134           dXH_(dXH),
0135           nBinsY_(-1),
0136           log_category_own_(pDQMBase->log_category_){};
0137 
0138     MEMapInfT(GEMDQMBase *pDQMBase,
0139               TString strName,
0140               TString strTitle,
0141               std::vector<Double_t> &x_binning,
0142               TString strTitleX = "",
0143               TString strTitleY = "Entries")
0144         : pDQMBase_(pDQMBase),
0145           strName_(strName),
0146           strTitle_(strTitle),
0147           strTitleX_(strTitleX),
0148           strTitleY_(strTitleY),
0149           bOperating_(true),
0150           bIsProfile_(false),
0151           bIsNoUnderOverflowBin_(false),
0152           nBinsX_(-1),
0153           nBinsY_(-1),
0154           log_category_own_(pDQMBase->log_category_) {
0155       for (Int_t i = 0; i < (Int_t)x_binning.size(); i++)
0156         x_binning_.push_back(x_binning[i]);
0157     };
0158 
0159     MEMapInfT(GEMDQMBase *pDQMBase,
0160               TString strName,
0161               TString strTitle,
0162               Int_t nBinsX,
0163               Double_t dXL,
0164               Double_t dXH,
0165               Int_t nBinsY,
0166               Double_t dYL,
0167               Double_t dYH,
0168               TString strTitleX = "",
0169               TString strTitleY = "")
0170         : pDQMBase_(pDQMBase),
0171           strName_(strName),
0172           strTitle_(strTitle),
0173           strTitleX_(strTitleX),
0174           strTitleY_(strTitleY),
0175           bOperating_(true),
0176           bIsProfile_(false),
0177           bIsNoUnderOverflowBin_(false),
0178           nBinsX_(nBinsX),
0179           dXL_(dXL),
0180           dXH_(dXH),
0181           nBinsY_(nBinsY),
0182           dYL_(dYL),
0183           dYH_(dYH),
0184           dZL_(0),
0185           dZH_(1024),
0186           log_category_own_(pDQMBase->log_category_){};
0187 
0188     MEMapInfT(GEMDQMBase *pDQMBase,  // For TProfile2D
0189               TString strName,
0190               TString strTitle,
0191               Int_t nBinsX,
0192               Double_t dXL,
0193               Double_t dXH,
0194               Int_t nBinsY,
0195               Double_t dYL,
0196               Double_t dYH,
0197               Double_t dZL,
0198               Double_t dZH,
0199               TString strTitleX = "",
0200               TString strTitleY = "")
0201         : pDQMBase_(pDQMBase),
0202           strName_(strName),
0203           strTitle_(strTitle),
0204           strTitleX_(strTitleX),
0205           strTitleY_(strTitleY),
0206           bOperating_(true),
0207           bIsProfile_(true),
0208           bIsNoUnderOverflowBin_(false),
0209           nBinsX_(nBinsX),
0210           dXL_(dXL),
0211           dXH_(dXH),
0212           nBinsY_(nBinsY),
0213           dYL_(dYL),
0214           dYH_(dYH),
0215           dZL_(dZL),
0216           dZH_(dZH),
0217           log_category_own_(pDQMBase->log_category_){};
0218 
0219     //MEMapInfT(GEMDQMBase *pDQMBase,
0220     //          TString strName,
0221     //          TString strTitle,
0222     //          std::vector<Double_t> &x_binning,
0223     //          std::vector<Double_t> &y_binning,
0224     //          TString strTitleX = "",
0225     //          TString strTitleY = "")
0226     //    : pDQMBase_(pDQMBase),
0227     //      strName_(strName),
0228     //      strTitle_(strTitle),
0229     //      strTitleX_(strTitleX),
0230     //      strTitleY_(strTitleY),
0231     //      bOperating_(true),
0232     //      bIsNoUnderOverflowBin_(false),
0233     //      nBinsX_(nBinsX),
0234     //      dXL_(dXL),
0235     //      dXH_(dXH),
0236     //      nBinsY_(nBinsY),
0237     //      dYL_(dYL),
0238     //      dYH_(dYH),
0239     //      log_category_own_(pDQMBase->log_category_){};
0240 
0241     ~MEMapInfT(){};
0242 
0243     Bool_t isOperating() { return bOperating_; };
0244     void SetOperating(Bool_t bOperating) { bOperating_ = bOperating; };
0245     void TurnOn() { bOperating_ = true; };
0246     void TurnOff() { bOperating_ = false; };
0247     void SetNoUnderOverflowBin() { bIsNoUnderOverflowBin_ = true; };
0248 
0249     Bool_t isProfile() { return bIsProfile_; };
0250     void SetProfile(Bool_t bIsProfile) { bIsProfile_ = bIsProfile; };
0251 
0252     TString GetName() { return strName_; };
0253     void SetName(TString strName) { strName_ = strName; };
0254     TString GetTitle() { return strTitle_; };
0255     void SetTitle(TString strTitle) { strTitle_ = strTitle; };
0256     TString GetTitleX() { return strTitleX_; };
0257     void SetTitleX(TString strTitleX) { strTitleX_ = strTitleX; };
0258     TString GetTitleY() { return strTitleY_; };
0259     void SetTitleY(TString strTitleY) { strTitleY_ = strTitleY; };
0260 
0261     Int_t GetNbinsX() { return nBinsX_; };
0262     void SetNbinsX(Int_t nBinsX) { nBinsX_ = nBinsX; };
0263     Double_t GetBinLowEdgeX() { return dXL_; };
0264     void SetBinLowEdgeX(Double_t dXL) { dXL_ = dXL; };
0265     Double_t GetBinHighEdgeX() { return dXH_; };
0266     void SetBinHighEdgeX(Double_t dXH) { dXH_ = dXH; };
0267     // FIXME: x_binning_
0268 
0269     Int_t GetNbinsY() { return nBinsY_; };
0270     void SetNbinsY(Int_t nBinsY) { nBinsY_ = nBinsY; };
0271     Double_t GetBinLowEdgeY() { return dYL_; };
0272     void SetBinLowEdgeY(Double_t dYL) { dYL_ = dYL; };
0273     Double_t GetBinHighEdgeY() { return dYH_; };
0274     void SetBinHighEdgeY(Double_t dYH) { dYH_ = dYH; };
0275 
0276     Double_t GetBinLowEdgeZ() { return dZL_; };
0277     void SetBinLowEdgeZ(Double_t dZL) { dZL_ = dZL; };
0278     Double_t GetBinHighEdgeZ() { return dZH_; };
0279     void SetBinHighEdgeZ(Double_t dZH) { dZH_ = dZH; };
0280 
0281     void SetBinConfX(Int_t nBins, Double_t dL = 0.5, Double_t dH = -1048576.0) {
0282       nBinsX_ = nBins;
0283       dXL_ = dL;
0284       if (dH <= dL)
0285         dH = dL + nBins;
0286       dXH_ = dH;
0287     };
0288 
0289     void SetBinConfY(Int_t nBins, Double_t dL = 0.5, Double_t dH = -1048576.0) {
0290       nBinsY_ = nBins;
0291       dYL_ = dL;
0292       if (dH <= dL)
0293         dH = dL + nBins;
0294       dYH_ = dH;
0295     };
0296 
0297     void SetPointUOFlow() {
0298       dXU_ = dXL_ + (dXH_ - dXL_) / nBinsX_ * 0.5;
0299       dXO_ = dXL_ + (dXH_ - dXL_) / nBinsX_ * (nBinsX_ - 0.5);
0300       dYU_ = dYL_ + (dYH_ - dYL_) / nBinsY_ * 0.5;
0301       dYO_ = dYL_ + (dYH_ - dYL_) / nBinsY_ * (nBinsY_ - 0.5);
0302       dZU_ = dZL_ + (dZH_ - dZL_) / nBinsZ_ * 0.5;
0303       dZO_ = dZL_ + (dZH_ - dZL_) / nBinsZ_ * (nBinsZ_ - 0.5);
0304     };
0305 
0306     M &map() { return mapHist; }
0307     int bookND(BookingHelper &bh, K key) {
0308       if (!bOperating_)
0309         return 0;
0310       SetPointUOFlow();
0311       if (bIsProfile_) {
0312         mapHist[key] = bh.bookProfile2D(
0313             strName_, strTitle_, nBinsX_, dXL_, dXH_, nBinsY_, dYL_, dYH_, dZL_, dZH_, strTitleX_, strTitleY_);
0314       } else if (nBinsY_ > 0 && nBinsX_ > 0) {
0315         mapHist[key] = bh.book2D(strName_, strTitle_, nBinsX_, dXL_, dXH_, nBinsY_, dYL_, dYH_, strTitleX_, strTitleY_);
0316         return 0;
0317       } else if (!x_binning_.empty()) {
0318         mapHist[key] = bh.book1D(strName_, strTitle_, nBinsX_, dXL_, dXH_, strTitleX_, strTitleY_);
0319         return 0;
0320       } else if (nBinsX_ > 0) {
0321         mapHist[key] = bh.book1D(strName_, strTitle_, nBinsX_, dXL_, dXH_, strTitleX_, strTitleY_);
0322         return 0;
0323       }
0324 
0325       return -1;
0326     };
0327 
0328     dqm::impl::MonitorElement *FindHist(K key) {
0329       if (mapHist.find(key) == mapHist.end()) {
0330         edm::LogError(log_category_own_)
0331             << "WARNING: Cannot find the histogram corresponing to the given key\n";  // FIXME: It's about sending a message
0332         return nullptr;
0333       }
0334       return mapHist[key];
0335     };
0336 
0337     int SetLabelForChambers(K key, Int_t nAxis, Int_t nNumBin = -1, Int_t nIdxStart = 1) {
0338       if (!bOperating_)
0339         return 0;
0340       if (nNumBin <= 0) {
0341         if (nAxis == 1)
0342           nNumBin = nBinsX_;
0343         else if (nAxis == 2)
0344           nNumBin = nBinsY_;
0345         else
0346           return -1;
0347       }
0348       dqm::impl::MonitorElement *histCurr = FindHist(key);
0349       if (histCurr == nullptr)
0350         return -999;
0351       for (Int_t i = 1; i <= nNumBin; i++) {
0352         histCurr->setBinLabel(i, Form("%i", nIdxStart + i - 1), nAxis);
0353       }
0354       return 0;
0355     };
0356 
0357     int SetLabelForIEta(K key, Int_t nAxis, Int_t nNumBin = -1) { return SetLabelForChambers(key, nAxis, nNumBin); };
0358 
0359     int SetLabelForVFATs(K key, Int_t nNumEtaPartitions, Int_t nAxis, Int_t nNumBin = -1) {
0360       if (!bOperating_)
0361         return 0;
0362       if (nNumBin <= 0) {
0363         if (nAxis == 1)
0364           nNumBin = nBinsX_;
0365         else if (nAxis == 2)
0366           nNumBin = nBinsY_;
0367         else
0368           return -1;
0369       }
0370       dqm::impl::MonitorElement *histCurr = FindHist(key);
0371       if (histCurr == nullptr)
0372         return -999;
0373       if (std::get<1>(key) == 2) {
0374         Int_t nNumVFATPerModule = 12;  // FIXME: A better way to get this?
0375         if (nNumBin > nNumVFATPerModule) {
0376           for (Int_t i = 0; i < nNumBin; i++) {
0377             Int_t nIModule = i / nNumVFATPerModule + 1;
0378             histCurr->setBinLabel(
0379                 i + 1, Form((nAxis == 1 ? "#splitline{%i}{M%i}" : "%i (M%i)"), i % nNumVFATPerModule, nIModule), nAxis);
0380           }
0381         } else {
0382           for (Int_t i = 0; i < nNumBin; i++) {
0383             histCurr->setBinLabel(i + 1, Form("%i", i), nAxis);
0384           }
0385         }
0386       } else {
0387         for (Int_t i = 0; i < nNumBin; i++) {
0388           Int_t nIEta = pDQMBase_->getIEtaFromVFAT(std::get<1>(key), i);
0389           histCurr->setBinLabel(i + 1, Form("%i (%i)", i, nIEta), nAxis);
0390         }
0391       }
0392       return 0;
0393     };
0394 
0395     int Fill(K key, Double_t x) {
0396       if (!bOperating_)
0397         return 0;
0398       dqm::impl::MonitorElement *hist = FindHist(key);
0399       if (hist == nullptr)
0400         return -999;
0401       if (bIsNoUnderOverflowBin_) {
0402         if (x <= dXL_)
0403           x = dXU_;
0404         else if (x >= dXH_)
0405           x = dXO_;
0406       }
0407       hist->Fill(x);
0408       return 1;
0409     };
0410 
0411     int Fill(K key, Double_t x, Double_t y, Double_t w = 1.0) {
0412       if (!bOperating_)
0413         return 0;
0414       dqm::impl::MonitorElement *hist = FindHist(key);
0415       if (hist == nullptr)
0416         return -999;
0417       if (bIsNoUnderOverflowBin_) {
0418         if (x <= dXL_)
0419           x = dXU_;
0420         else if (x >= dXH_)
0421           x = dXO_;
0422         if (y <= dYL_)
0423           y = dYU_;
0424         else if (y >= dYH_)
0425           y = dYO_;
0426       }
0427       hist->Fill(x, y, w);
0428       return 1;
0429     };
0430 
0431     int FillBits(K key, Double_t x, UInt_t bits, Double_t w = 1.0) {
0432       if (!bOperating_)
0433         return 0;
0434       dqm::impl::MonitorElement *hist = FindHist(key);
0435       if (hist == nullptr)
0436         return -999;
0437 
0438       if (nBinsY_ <= 0)
0439         return -888;
0440       UInt_t unMask = 0x1;
0441       for (Int_t i = 1; i <= nBinsY_; i++) {
0442         if ((unMask & bits) != 0)
0443           hist->Fill(x, i, w);
0444         unMask <<= 1;
0445       }
0446 
0447       return 1;
0448     };
0449 
0450   private:
0451     GEMDQMBase *pDQMBase_;
0452 
0453     M mapHist;
0454     TString strName_, strTitle_, strTitleX_, strTitleY_;
0455     Bool_t bOperating_;
0456     Bool_t bIsProfile_;
0457     Bool_t bIsNoUnderOverflowBin_;
0458 
0459     std::vector<double> x_binning_;
0460     Int_t nBinsX_;
0461     Double_t dXL_, dXH_;
0462     Int_t nBinsY_;
0463     Double_t dYL_, dYH_;
0464     Int_t nBinsZ_;
0465     Double_t dZL_, dZH_;
0466     Double_t dXU_, dXO_;
0467     Double_t dYU_, dYO_;
0468     Double_t dZU_, dZO_;
0469 
0470     std::string log_category_own_;
0471   };
0472 
0473   typedef MEMapInfT<MEMap2Ids, ME2IdsKey> MEMap2Inf;
0474   typedef MEMapInfT<MEMap3Ids, ME3IdsKey> MEMap3Inf;
0475   typedef MEMapInfT<MEMap4Ids, ME4IdsKey> MEMap4Inf;
0476   typedef MEMapInfT<MEMap5Ids, ME5IdsKey> MEMap5Inf;
0477 
0478   class MEStationInfo {
0479   public:
0480     MEStationInfo() : nNumChambers_(-1){};
0481     MEStationInfo(Int_t nRegion,
0482                   Int_t nStation,
0483                   Int_t nLayer,
0484                   Int_t nNumChambers,
0485                   Int_t nNumModules,
0486                   Int_t nNumEtaPartitions,
0487                   Int_t nMaxVFAT,
0488                   Int_t nFirstStrip,
0489                   Int_t nNumDigi,
0490                   Int_t nMinIdxChamber,
0491                   Int_t nMaxIdxChamber)
0492         : nRegion_(nRegion),
0493           nStation_(nStation),
0494           nLayer_(nLayer),
0495           nNumChambers_(nNumChambers),
0496           nNumModules_(nNumModules),
0497           nNumEtaPartitions_(nNumEtaPartitions),
0498           nMaxVFAT_(nMaxVFAT),
0499           nFirstStrip_(nFirstStrip),
0500           nNumDigi_(nNumDigi),
0501           nMinIdxChamber_(nMinIdxChamber),
0502           nMaxIdxChamber_(nMaxIdxChamber),
0503           fMinPhi_(0){};
0504 
0505     bool operator==(const MEStationInfo &other) const {
0506       return (nRegion_ == other.nRegion_ && nStation_ == other.nStation_ && nLayer_ == other.nLayer_ &&
0507               nNumChambers_ == other.nNumChambers_ && nNumModules_ == other.nNumModules_ &&
0508               nNumEtaPartitions_ == other.nNumEtaPartitions_ && nMaxVFAT_ == other.nMaxVFAT_ &&
0509               nFirstStrip_ == other.nFirstStrip_ && nNumDigi_ == other.nNumDigi_);
0510     };
0511 
0512     Int_t nRegion_;            // the region index
0513     Int_t nStation_;           // the station index
0514     Int_t nLayer_;             // the layer
0515     Int_t nNumChambers_;       // the number of chambers in the current station
0516     Int_t nNumModules_;        // the number of modules in each chamber
0517     Int_t nNumEtaPartitions_;  // the number of eta partitions of the chambers
0518     Int_t nMaxVFAT_;     // the number of all VFATs in each chamber (= # of VFATs in eta partition * nNumEtaPartitions_)
0519     Int_t nFirstStrip_;  // the index of the first strip
0520     Int_t nNumDigi_;     // the number of digis of each VFAT
0521 
0522     Int_t nMinIdxChamber_;
0523     Int_t nMaxIdxChamber_;
0524     Float_t fMinPhi_;
0525 
0526     std::vector<Float_t> listRadiusEvenChamber_;
0527     std::vector<Float_t> listRadiusOddChamber_;
0528   };
0529 
0530   int readGeometryRadiusInfoChamber(const GEMStation *station, MEStationInfo &stationInfo);
0531   int readGeometryPhiInfoChamber(const GEMStation *station, MEStationInfo &stationInfo);
0532 
0533 public:
0534   explicit GEMDQMBase(const edm::ParameterSet &cfg);
0535   ~GEMDQMBase() override{};
0536 
0537   enum {
0538     GEMDQM_RUNTYPE_ONLINE,
0539     GEMDQM_RUNTYPE_OFFLINE,
0540     GEMDQM_RUNTYPE_RELVAL,
0541     GEMDQM_RUNTYPE_ALLPLOTS,
0542     GEMDQM_RUNTYPE_NONE = -1
0543   };
0544 
0545   Int_t nRunType_;
0546 
0547   std::string log_category_;
0548 
0549 protected:
0550   int initGeometry(edm::EventSetup const &iSetup);
0551   int loadChambers();
0552 
0553   int GenerateMEPerChamber(DQMStore::IBooker &ibooker);
0554   virtual int ProcessWithMEMap2(BookingHelper &bh, ME2IdsKey key) { return 0; };              // must be overrided
0555   virtual int ProcessWithMEMap2WithEta(BookingHelper &bh, ME3IdsKey key) { return 0; };       // must be overrided
0556   virtual int ProcessWithMEMap2AbsReWithEta(BookingHelper &bh, ME3IdsKey key) { return 0; };  // must be overrided
0557   virtual int ProcessWithMEMap3(BookingHelper &bh, ME3IdsKey key) { return 0; };              // must be overrided
0558   virtual int ProcessWithMEMap4(BookingHelper &bh, ME4IdsKey key) { return 0; };              // must be overrided
0559   virtual int ProcessWithMEMap5(BookingHelper &bh, ME5IdsKey key) { return 0; };              // must be overrided
0560   virtual int ProcessWithMEMap4WithChamber(BookingHelper &bh, ME4IdsKey key) { return 0; };   // must be overrided
0561   virtual int ProcessWithMEMap5WithChamber(BookingHelper &bh, ME5IdsKey key) { return 0; };   // must be overrided
0562 
0563   int keyToRegion(ME2IdsKey key) { return std::get<0>(key); };
0564   int keyToRegion(ME3IdsKey key) { return std::get<0>(key); };
0565   int keyToRegion(ME4IdsKey key) { return std::get<0>(key); };
0566   int keyToRegion(ME5IdsKey key) { return std::get<0>(key); };
0567   int keyToStation(ME2IdsKey key) { return std::get<1>(key); };
0568   int keyToStation(ME3IdsKey key) { return std::get<1>(key); };
0569   int keyToStation(ME4IdsKey key) { return std::get<1>(key); };
0570   int keyToStation(ME5IdsKey key) { return std::get<1>(key); };
0571   int keyToLayer(ME3IdsKey key) { return std::get<2>(key); };
0572   int keyToLayer(ME4IdsKey key) { return std::get<2>(key); };
0573   int keyToLayer(ME5IdsKey key) { return std::get<2>(key); };
0574   int keyToModule(ME4IdsKey key) { return std::get<3>(key); };
0575   int keyToModule(ME5IdsKey key) { return std::get<3>(key); };
0576   int keyToChamber(ME4IdsKey key) { return std::get<3>(key); };
0577   int keyToChamber(ME5IdsKey key) { return std::get<4>(key); };
0578   int keyToIEta(ME4IdsKey key) { return std::get<3>(key); };
0579   int keyToIEta(ME5IdsKey key) { return std::get<4>(key); };
0580 
0581   ME2IdsKey key3Tokey2(ME3IdsKey key) {
0582     auto keyNew = ME2IdsKey{keyToRegion(key), keyToStation(key)};
0583     return keyNew;
0584   };
0585 
0586   ME3IdsKey key4Tokey3(ME4IdsKey key) {
0587     auto keyNew = ME3IdsKey{keyToRegion(key), keyToStation(key), keyToLayer(key)};
0588     return keyNew;
0589   };
0590 
0591   ME4IdsKey key5Tokey4(ME5IdsKey key) {
0592     auto keyNew = ME4IdsKey{keyToRegion(key), keyToStation(key), keyToLayer(key), keyToModule(key)};
0593     return keyNew;
0594   };
0595 
0596   int SortingLayers(std::vector<ME4IdsKey> &listLayers);
0597   dqm::impl::MonitorElement *CreateSummaryHist(DQMStore::IBooker &ibooker, TString strName);
0598 
0599   template <typename T>
0600   inline bool checkRefs(const std::vector<T *> &);
0601 
0602   int getNumEtaPartitions(const GEMStation *);
0603   inline int getVFATNumber(const int, const int, const int);
0604   inline int getVFATNumberGE11(const int, const int, const int);
0605   inline int getVFATNumberByDigi(const int, const int, const int);
0606   inline int getIEtaFromVFAT(const int station, const int vfat);
0607   inline int getIEtaFromVFATGE0(const int vfat);
0608   inline int getIEtaFromVFATGE11(const int vfat);
0609   inline int getIEtaFromVFATGE21(const int vfat);
0610   inline int getMaxVFAT(const int);
0611   inline int getNumModule(const int);
0612   inline int getIdxModule(const int, const int);
0613   inline int getDetOccXBin(const int, const int, const int);
0614   inline Float_t restrictAngle(const Float_t fTheta, const Float_t fStart);
0615   inline std::string getNameDirLayer(ME3IdsKey key3);
0616   inline std::string getNameDirLayer(ME4IdsKey key4);
0617 
0618   const GEMGeometry *GEMGeometry_;
0619   edm::ESGetToken<GEMGeometry, MuonGeometryRecord> geomToken_;
0620 
0621   std::vector<GEMDetId> listChamberId_;
0622   std::map<GEMDetId, std::vector<const GEMEtaPartition *>> mapEtaPartition_;
0623 
0624   std::map<ME2IdsKey, bool> MEMap2Check_;
0625   std::map<ME3IdsKey, bool> MEMap2WithEtaCheck_;
0626   std::map<ME3IdsKey, bool> MEMap2AbsReWithEtaCheck_;
0627   std::map<ME3IdsKey, bool> MEMap3Check_;
0628   std::map<ME4IdsKey, bool> MEMap4Check_;
0629   std::map<ME4IdsKey, bool> MEMap4WithChCheck_;
0630   std::map<ME5IdsKey, bool> MEMap5WithChCheck_;
0631   std::map<ME5IdsKey, bool> MEMap5Check_;
0632 
0633   int nMaxNumCh_;
0634   std::map<ME3IdsKey, MEStationInfo> mapStationInfo_;
0635   std::map<ME4IdsKey, int> mapStationToIdx_;
0636 };
0637 
0638 // Borrwed from DQM/GEM/interface/GEMOfflineDQMBase.h
0639 template <typename T>
0640 inline bool GEMDQMBase::checkRefs(const std::vector<T *> &refs) {
0641   if (refs.empty())
0642     return false;
0643   if (refs.front() == nullptr)
0644     return false;
0645   return true;
0646 }
0647 
0648 // The 'get...' functions in the below are borrwed from DQM/GEM/interface/GEMOfflineDQMBase.h
0649 inline int GEMDQMBase::getMaxVFAT(const int station) {
0650   if (station == 0)
0651     return GEMeMap::maxVFatGE0_;
0652   if (station == 1)
0653     return GEMeMap::maxVFatGE11_;
0654   else if (station == 2)
0655     return GEMeMap::maxVFatGE21_ / 2;
0656   else
0657     return -1;
0658 }
0659 
0660 inline int GEMDQMBase::getNumModule(const int station) {
0661   if (station == 0)
0662     return 1;
0663   if (station == 1)
0664     return 1;
0665   else if (station == 2)
0666     return 4;
0667   else
0668     return -1;
0669 }
0670 
0671 inline int GEMDQMBase::getIdxModule(const int station, const int chamberType) {
0672   if (station == 0)
0673     return 1;
0674   if (station == 1)
0675     return 1;
0676   else if (station == 2)
0677     return chamberType - 20;
0678   else
0679     return -1;
0680 }
0681 
0682 inline int GEMDQMBase::getVFATNumber(const int station, const int ieta, const int vfat_phi) {
0683   if (station == 1)
0684     return getVFATNumberGE11(station, ieta, vfat_phi);
0685   return getVFATNumberGE11(station, ieta, vfat_phi);  // FIXME: What about GE21 and GE0?
0686 }
0687 
0688 inline int GEMDQMBase::getVFATNumberGE11(const int station, const int ieta, const int vfat_phi) {
0689   return vfat_phi * GEMeMap::maxiEtaIdGE11_ + (GEMeMap::maxiEtaIdGE11_ - ieta);
0690 }
0691 
0692 inline int GEMDQMBase::getVFATNumberByDigi(const int station, const int ieta, const int digi) {
0693   const int vfat_phi = digi / GEMeMap::maxChan_;
0694   return getVFATNumber(station, ieta, vfat_phi);
0695 }
0696 
0697 inline int GEMDQMBase::getIEtaFromVFAT(const int station, const int vfat) {
0698   if (station == 0)
0699     return getIEtaFromVFATGE0(vfat);
0700   if (station == 1)
0701     return getIEtaFromVFATGE11(vfat);
0702   if (station == 2)
0703     return getIEtaFromVFATGE21(vfat);
0704   return getIEtaFromVFATGE11(vfat);  // FIXME: What about GE21 and GE0?
0705 }
0706 
0707 inline int GEMDQMBase::getIEtaFromVFATGE0(const int vfat) {
0708   return GEMeMap::maxiEtaIdGE0_ - (vfat % GEMeMap::maxiEtaIdGE0_);
0709 }
0710 
0711 inline int GEMDQMBase::getIEtaFromVFATGE11(const int vfat) {
0712   return GEMeMap::maxiEtaIdGE11_ - (vfat % GEMeMap::maxiEtaIdGE11_);
0713 }
0714 
0715 inline int GEMDQMBase::getIEtaFromVFATGE21(const int vfat) {
0716   return GEMeMap::maxiEtaIdGE21_ - (vfat % GEMeMap::maxiEtaIdGE21_);
0717 }
0718 
0719 inline int GEMDQMBase::getDetOccXBin(const int chamber, const int layer, const int n_chambers) {
0720   return n_chambers * (chamber - 1) + layer;
0721 }
0722 
0723 inline Float_t GEMDQMBase::restrictAngle(const Float_t fTheta, const Float_t fStart) {
0724   Float_t fLoop = (fTheta - fStart) / (2 * M_PI);
0725   int nLoop = (fLoop >= 0 ? (int)fLoop : (int)fLoop - 1);
0726   return fTheta - nLoop * 2 * M_PI;
0727 }
0728 
0729 inline std::string GEMDQMBase::getNameDirLayer(ME3IdsKey key3) {
0730   auto nStation = keyToStation(key3);
0731   char cRegion = (keyToRegion(key3) > 0 ? 'P' : 'M');
0732   auto nLayer = keyToLayer(key3);
0733   return std::string(Form("GE%i1-%c-L%i", nStation, cRegion, nLayer));
0734 }
0735 
0736 inline std::string GEMDQMBase::getNameDirLayer(ME4IdsKey key4) {
0737   auto nStation = keyToStation(key4);
0738   char cRegion = (keyToRegion(key4) > 0 ? 'P' : 'M');
0739   auto nLayer = keyToLayer(key4);
0740   if (nStation == 2) {
0741     auto nModule = keyToModule(key4);
0742     return std::string(Form("GE%i1-%c-L%i-M%i", nStation, cRegion, nLayer, nModule));
0743   }
0744   return std::string(Form("GE%i1-%c-L%i", nStation, cRegion, nLayer));
0745 }
0746 
0747 #endif  // DQM_GEM_INTERFACE_GEMDQMBase_h