Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/HcalTasks/interface/DigiTask.h"
0002 
0003 using namespace hcaldqm;
0004 using namespace hcaldqm::constants;
0005 using namespace hcaldqm::filter;
0006 
0007 DigiTask::DigiTask(edm::ParameterSet const& ps)
0008     : DQTask(ps), hcalDbServiceToken_(esConsumes<HcalDbService, HcalDbRecord, edm::Transition::BeginRun>()) {
0009   _tagQIE11 = ps.getUntrackedParameter<edm::InputTag>("tagHE", edm::InputTag("hcalDigis"));
0010   _tagHO = ps.getUntrackedParameter<edm::InputTag>("tagHO", edm::InputTag("hcalDigis"));
0011   _tagQIE10 = ps.getUntrackedParameter<edm::InputTag>("tagHF", edm::InputTag("hcalDigis"));
0012 
0013   _tokQIE11 = consumes<QIE11DigiCollection>(_tagQIE11);
0014   _tokHO = consumes<HODigiCollection>(_tagHO);
0015   _tokQIE10 = consumes<QIE10DigiCollection>(_tagQIE10);
0016 
0017   _cutSumQ_HBHE = ps.getUntrackedParameter<double>("cutSumQ_HBHE", 20);
0018   _cutSumQ_HO = ps.getUntrackedParameter<double>("cutSumQ_HO", 20);
0019   _cutSumQ_HF = ps.getUntrackedParameter<double>("cutSumQ_HF", 20);
0020   _thresh_unihf = ps.getUntrackedParameter<double>("thresh_unihf", 0.2);
0021   _thresh_led = ps.getUntrackedParameter<double>("thresh_led", 20);
0022 
0023   _vflags.resize(nDigiFlag);
0024   _vflags[fUni] = hcaldqm::flag::Flag("UniSlotHF");
0025   _vflags[fDigiSize] = hcaldqm::flag::Flag("DigiSize");
0026   _vflags[fNChsHF] = hcaldqm::flag::Flag("NChsHF");
0027   _vflags[fUnknownIds] = hcaldqm::flag::Flag("UnknownIds");
0028   _vflags[fLED] = hcaldqm::flag::Flag("LEDMisfire");
0029   _vflags[fCapId] = hcaldqm::flag::Flag("BadCapId");
0030 
0031   _qie10InConditions = ps.getUntrackedParameter<bool>("qie10InConditions", true);
0032 
0033   // Get reference digi sizes. Convert from unsigned to signed int, because <digi>::size()/samples() return ints for some reason.
0034   std::vector<uint32_t> vrefDigiSize = ps.getUntrackedParameter<std::vector<uint32_t>>("refDigiSize");
0035   _refDigiSize[HcalBarrel] = (int)vrefDigiSize[0];
0036   _refDigiSize[HcalEndcap] = (int)vrefDigiSize[1];
0037   _refDigiSize[HcalOuter] = (int)vrefDigiSize[2];
0038   _refDigiSize[HcalForward] = (int)vrefDigiSize[3];
0039 
0040   // (capid - BX) % 4 to 1
0041   _capidmbx[HcalBarrel] = 1;
0042   _capidmbx[HcalEndcap] = 1;
0043   _capidmbx[HcalOuter] = 1;
0044   _capidmbx[HcalForward] = 1;
0045 }
0046 
0047 /* virtual */ void DigiTask::bookHistograms(DQMStore::IBooker& ib, edm::Run const& r, edm::EventSetup const& es) {
0048   DQTask::bookHistograms(ib, r, es);
0049 
0050   //    GET WHAT YOU NEED
0051   edm::ESHandle<HcalDbService> dbs = es.getHandle(hcalDbServiceToken_);
0052   _emap = dbs->getHcalMapping();
0053 
0054   // Book LED calibration channels from emap
0055   std::vector<HcalElectronicsId> eids = _emap->allElectronicsId();
0056   for (unsigned i = 0; i < eids.size(); i++) {
0057     HcalElectronicsId eid = eids[i];
0058     DetId id = _emap->lookup(eid);
0059     if (HcalGenericDetId(id.rawId()).isHcalCalibDetId()) {
0060       HcalCalibDetId calibId(id);
0061       if (calibId.calibFlavor() == HcalCalibDetId::CalibrationBox) {
0062         HcalSubdetector this_subdet = HcalEmpty;
0063         switch (calibId.hcalSubdet()) {
0064           case HcalBarrel:
0065             this_subdet = HcalBarrel;
0066             break;
0067           case HcalEndcap:
0068             this_subdet = HcalEndcap;
0069             break;
0070           case HcalOuter:
0071             this_subdet = HcalOuter;
0072             break;
0073           case HcalForward:
0074             this_subdet = HcalForward;
0075             break;
0076           default:
0077             this_subdet = HcalEmpty;
0078             break;
0079         }
0080         _ledCalibrationChannels[this_subdet].push_back(
0081             HcalDetId(HcalOther, calibId.ieta(), calibId.iphi(), calibId.cboxChannel()));
0082       }
0083     }
0084   }
0085 
0086   std::vector<uint32_t> vVME;
0087   std::vector<uint32_t> vuTCA;
0088   vVME.push_back(
0089       HcalElectronicsId(constants::FIBERCH_MIN, constants::FIBER_VME_MIN, SPIGOT_MIN, CRATE_VME_MIN).rawId());
0090   vuTCA.push_back(HcalElectronicsId(CRATE_uTCA_MIN, SLOT_uTCA_MIN, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0091   _filter_VME.initialize(filter::fFilter, hcaldqm::hashfunctions::fElectronics, vVME);
0092   _filter_uTCA.initialize(filter::fFilter, hcaldqm::hashfunctions::fElectronics, vuTCA);
0093 
0094   // Filters for QIE8 vs QIE10/11
0095   std::vector<uint32_t> vhashQIE8;
0096   vhashQIE8.push_back(hcaldqm::hashfunctions::hash_did[hcaldqm::hashfunctions::fSubdet](HcalDetId(HcalOuter, 1, 1, 4)));
0097   _filter_QIE8.initialize(filter::fPreserver, hcaldqm::hashfunctions::fSubdet, vhashQIE8);
0098 
0099   std::vector<uint32_t> vhashQIE1011;
0100   vhashQIE1011.push_back(
0101       hcaldqm::hashfunctions::hash_did[hcaldqm::hashfunctions::fSubdet](HcalDetId(HcalBarrel, 1, 1, 1)));
0102   vhashQIE1011.push_back(
0103       hcaldqm::hashfunctions::hash_did[hcaldqm::hashfunctions::fSubdet](HcalDetId(HcalEndcap, 20, 1, 1)));
0104   vhashQIE1011.push_back(
0105       hcaldqm::hashfunctions::hash_did[hcaldqm::hashfunctions::fSubdet](HcalDetId(HcalForward, 29, 1, 1)));
0106   _filter_QIE1011.initialize(filter::fPreserver, hcaldqm::hashfunctions::fSubdet, vhashQIE1011);
0107 
0108   std::vector<uint32_t> vhash_TDC2bit;
0109   vhash_TDC2bit.push_back(
0110       hcaldqm::hashfunctions::hash_did[hcaldqm::hashfunctions::fSubdetPM](HcalDetId(HcalBarrel, 1, 1, 1)));
0111   vhash_TDC2bit.push_back(
0112       hcaldqm::hashfunctions::hash_did[hcaldqm::hashfunctions::fSubdetPM](HcalDetId(HcalBarrel, -11, 1, 1)));
0113   _filter_TDC2bit.initialize(filter::fPreserver, hcaldqm::hashfunctions::fSubdetPM, vhash_TDC2bit);
0114 
0115   std::vector<uint32_t> vhash_TDC6bit;
0116   vhash_TDC6bit.push_back(
0117       hcaldqm::hashfunctions::hash_did[hcaldqm::hashfunctions::fSubdetPM](HcalDetId(HcalEndcap, 20, 1, 1)));
0118   vhash_TDC6bit.push_back(
0119       hcaldqm::hashfunctions::hash_did[hcaldqm::hashfunctions::fSubdetPM](HcalDetId(HcalEndcap, -20, 1, 1)));
0120   vhash_TDC6bit.push_back(
0121       hcaldqm::hashfunctions::hash_did[hcaldqm::hashfunctions::fSubdetPM](HcalDetId(HcalForward, 29, 1, 1)));
0122   vhash_TDC6bit.push_back(
0123       hcaldqm::hashfunctions::hash_did[hcaldqm::hashfunctions::fSubdetPM](HcalDetId(HcalForward, -29, 1, 1)));
0124   _filter_TDC6bit.initialize(filter::fPreserver, hcaldqm::hashfunctions::fSubdetPM, vhash_TDC6bit);
0125 
0126   //    INITIALIZE FIRST
0127   _cADC_SubdetPM.initialize(_name,
0128                             "ADC",
0129                             hcaldqm::hashfunctions::fSubdetPM,
0130                             new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fADC_128),
0131                             new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true),
0132                             0);
0133   _cfC_SubdetPM.initialize(_name,
0134                            "fC",
0135                            hcaldqm::hashfunctions::fSubdetPM,
0136                            new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::ffC_10000),
0137                            new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true),
0138                            0);
0139   _cSumQ_SubdetPM.initialize(_name,
0140                              "SumQ",
0141                              hcaldqm::hashfunctions::fSubdetPM,
0142                              new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::ffC_10000),
0143                              new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true),
0144                              0);
0145   _cSumQ_depth.initialize(_name,
0146                           "SumQ",
0147                           hcaldqm::hashfunctions::fdepth,
0148                           new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fieta),
0149                           new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fiphi),
0150                           new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::ffC_generic_400000, true),
0151                           0);
0152   _cSumQvsLS_SubdetPM.initialize(_name,
0153                                  "SumQvsLS",
0154                                  hcaldqm::hashfunctions::fSubdetPM,
0155                                  new hcaldqm::quantity::LumiSection(_maxLS),
0156                                  new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::ffC_10000),
0157                                  0);
0158 
0159   _cADC_SubdetPM_QIE1011.initialize(_name,
0160                                     "ADC",
0161                                     hcaldqm::hashfunctions::fSubdetPM,
0162                                     new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fQIE10ADC_256),
0163                                     new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true),
0164                                     0);
0165   _cfC_SubdetPM_QIE1011.initialize(_name,
0166                                    "fC",
0167                                    hcaldqm::hashfunctions::fSubdetPM,
0168                                    new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fQIE10fC_400000),
0169                                    new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true),
0170                                    0);
0171   _cSumQ_SubdetPM_QIE1011.initialize(_name,
0172                                      "SumQ",
0173                                      hcaldqm::hashfunctions::fSubdetPM,
0174                                      new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fQIE10fC_400000),
0175                                      new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true),
0176                                      0);
0177   _cSumQvsLS_SubdetPM_QIE1011.initialize(_name,
0178                                          "SumQvsLS",
0179                                          hcaldqm::hashfunctions::fSubdetPM,
0180                                          new hcaldqm::quantity::LumiSection(_maxLS),
0181                                          new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fQIE10fC_400000),
0182                                          0);
0183 
0184   _cTimingCut_SubdetPM.initialize(_name,
0185                                   "TimingCut",
0186                                   hcaldqm::hashfunctions::fSubdetPM,
0187                                   new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTiming_TS200),
0188                                   new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0189                                   0);
0190   _cTimingCutHTH_SubdetPM.initialize(_name,
0191                                      "TimingHighCut",
0192                                      hcaldqm::hashfunctions::fSubdetPM,
0193                                      new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTiming_TS200),
0194                                      new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0195                                      0);
0196   _cTimingCut_depth.initialize(_name,
0197                                "TimingCut",
0198                                hcaldqm::hashfunctions::fdepth,
0199                                new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fieta),
0200                                new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fiphi),
0201                                new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTiming_TS200),
0202                                0);
0203   _cTimingCutvsLS_SubdetPM.initialize(_name,
0204                                       "TimingvsLS",
0205                                       hcaldqm::hashfunctions::fSubdetPM,
0206                                       new hcaldqm::quantity::LumiSection(_maxLS),
0207                                       new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTiming_TS200),
0208                                       0);
0209 
0210   //    Occupancy w/o a cut
0211   _cOccupancyvsLS_Subdet.initialize(_name,
0212                                     "OccupancyvsLS",
0213                                     hcaldqm::hashfunctions::fSubdet,
0214                                     new hcaldqm::quantity::LumiSection(_maxLS),
0215                                     new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN_to8000),
0216                                     0);
0217   _cOccupancy_depth.initialize(_name,
0218                                "Occupancy",
0219                                hcaldqm::hashfunctions::fdepth,
0220                                new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fieta),
0221                                new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fiphi),
0222                                new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0223                                0);
0224 
0225   //    Occupancy w/ a cut
0226   _cOccupancyCutvsLS_Subdet.initialize(_name,
0227                                        "OccupancyCutvsLS",
0228                                        hcaldqm::hashfunctions::fSubdet,
0229                                        new hcaldqm::quantity::LumiSection(_maxLS),
0230                                        new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN_to8000),
0231                                        0);
0232   _cOccupancyCut_depth.initialize(_name,
0233                                   "OccupancyCut",
0234                                   hcaldqm::hashfunctions::fdepth,
0235                                   new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fieta),
0236                                   new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fiphi),
0237                                   new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0238                                   0);
0239 
0240   // Digi size
0241   _cDigiSize_Crate.initialize(_name,
0242                               "DigiSize",
0243                               hcaldqm::hashfunctions::fCrate,
0244                               new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fDigiSize),
0245                               new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0246                               0);
0247   _cADCvsTS_SubdetPM.initialize(_name,
0248                                 "ADCvsTS",
0249                                 hcaldqm::hashfunctions::fSubdetPM,
0250                                 new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTiming_TS),
0251                                 new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fADC_128),
0252                                 new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0253                                 0);
0254   _cADCvsTS_SubdetPM_QIE1011.initialize(_name,
0255                                         "ADCvsTS",
0256                                         hcaldqm::hashfunctions::fSubdetPM,
0257                                         new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTiming_TS),
0258                                         new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fQIE10ADC_256),
0259                                         new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0260                                         0);
0261 
0262   _cLETDCTimevsADC_SubdetPM.initialize(_name,
0263                                        "LETDCTimevsADC",
0264                                        hcaldqm::hashfunctions::fSubdetPM,
0265                                        new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fQIE10ADC_256),
0266                                        new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTime_ns_250_coarse),
0267                                        new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true));
0268   _cLETDCvsADC_2bit_SubdetPM.initialize(_name,
0269                                         "LETDCvsADC",
0270                                         hcaldqm::hashfunctions::fSubdetPM,
0271                                         new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fQIE10ADC_256),
0272                                         new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fQIE10TDC_4),
0273                                         new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true));
0274   _cLETDCvsADC_6bit_SubdetPM.initialize(_name,
0275                                         "LETDCvsADC",
0276                                         hcaldqm::hashfunctions::fSubdetPM,
0277                                         new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fQIE10ADC_256),
0278                                         new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fQIE10TDC_64),
0279                                         new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true));
0280   _cLETDCvsTS_2bit_SubdetPM.initialize(_name,
0281                                        "LETDCvsTS",
0282                                        hcaldqm::hashfunctions::fSubdetPM,
0283                                        new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTiming_TS),
0284                                        new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fQIE10TDC_4),
0285                                        new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true));
0286   _cLETDCvsTS_6bit_SubdetPM.initialize(_name,
0287                                        "LETDCvsTS",
0288                                        hcaldqm::hashfunctions::fSubdetPM,
0289                                        new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTiming_TS),
0290                                        new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fQIE10TDC_64),
0291                                        new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true));
0292 
0293   _cLETDCTime_SubdetPM.initialize(_name,
0294                                   "LETDCTime",
0295                                   hcaldqm::hashfunctions::fSubdetPM,
0296                                   new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTime_ns_250_coarse),
0297                                   new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true));
0298   _cLETDCTime_depth.initialize(_name,
0299                                "LETDCTime",
0300                                hcaldqm::hashfunctions::fdepth,
0301                                new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fieta),
0302                                new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fiphi),
0303                                new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0304                                0);
0305 
0306   _cBadTDCValues_SubdetPM.initialize(_name,
0307                                      "BadTDCValues",
0308                                      hcaldqm::hashfunctions::fSubdetPM,
0309                                      new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fBadTDC),
0310                                      new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true));
0311   _cBadTDCvsBX_SubdetPM.initialize(_name,
0312                                    "BadTDCvsBX",
0313                                    hcaldqm::hashfunctions::fSubdetPM,
0314                                    new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fBX),
0315                                    new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true));
0316   _cBadTDCvsLS_SubdetPM.initialize(_name,
0317                                    "BadTDCvsLS",
0318                                    hcaldqm::hashfunctions::fSubdetPM,
0319                                    new hcaldqm::quantity::LumiSection(_maxLS),
0320                                    new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true));
0321   _cBadTDCCount_depth.initialize(_name,
0322                                  "BadTDCCount",
0323                                  hcaldqm::hashfunctions::fdepth,
0324                                  new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fieta),
0325                                  new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fiphi),
0326                                  new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0327                                  0);
0328 
0329   if (_ptype == fOnline || _ptype == fLocal) {
0330     _cOccupancy_Crate.initialize(_name,
0331                                  "Occupancy",
0332                                  hashfunctions::fCrate,
0333                                  new quantity::ElectronicsQuantity(quantity::fSlotuTCA),
0334                                  new quantity::ElectronicsQuantity(quantity::fFiberuTCAFiberCh),
0335                                  new quantity::ValueQuantity(quantity::fN),
0336                                  0);
0337     _cOccupancy_CrateSlot.initialize(_name,
0338                                      "Occupancy",
0339                                      hashfunctions::fCrateSlot,
0340                                      new quantity::ElectronicsQuantity(quantity::fFiberuTCA),
0341                                      new quantity::ElectronicsQuantity(quantity::fFiberCh),
0342                                      new quantity::ValueQuantity(quantity::fN),
0343                                      0);
0344   }
0345 
0346   //    INITIALIZE HISTOGRAMS that are only for Online
0347   if (_ptype == fOnline) {
0348     //  Charge sharing
0349     _cQ2Q12CutvsLS_FEDHF.initialize(_name,
0350                                     "Q2Q12vsLS",
0351                                     hcaldqm::hashfunctions::fFED,
0352                                     new hcaldqm::quantity::LumiSection(_maxLS),
0353                                     new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fRatio_0to2),
0354                                     0);
0355     _cSumQvsBX_SubdetPM.initialize(_name,
0356                                    "SumQvsBX",
0357                                    hcaldqm::hashfunctions::fSubdetPM,
0358                                    new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fBX),
0359                                    new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::ffC_10000),
0360                                    0);
0361     _cSumQvsBX_SubdetPM_QIE1011.initialize(_name,
0362                                            "SumQvsBX",
0363                                            hcaldqm::hashfunctions::fSubdetPM,
0364                                            new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fBX),
0365                                            new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fQIE10fC_10000),
0366                                            0);
0367     _cDigiSizevsLS_FED.initialize(_name,
0368                                   "DigiSizevsLS",
0369                                   hcaldqm::hashfunctions::fFED,
0370                                   new hcaldqm::quantity::LumiSection(_maxLS),
0371                                   new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fDigiSize),
0372                                   0);
0373     _cTimingCutvsiphi_SubdetPM.initialize(_name,
0374                                           "TimingCutvsiphi",
0375                                           hcaldqm::hashfunctions::fSubdetPM,
0376                                           new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fiphi),
0377                                           new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTiming_TS200),
0378                                           0);
0379     _cTimingCutvsieta_Subdet.initialize(_name,
0380                                         "TimingCutvsieta",
0381                                         hcaldqm::hashfunctions::fSubdet,
0382                                         new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fieta),
0383                                         new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTiming_TS200),
0384                                         0);
0385     _cOccupancyvsiphi_SubdetPM.initialize(_name,
0386                                           "Occupancyvsiphi",
0387                                           hcaldqm::hashfunctions::fSubdetPM,
0388                                           new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fiphi),
0389                                           new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0390                                           0);
0391     _cOccupancyvsieta_Subdet.initialize(_name,
0392                                         "Occupancyvsieta",
0393                                         hcaldqm::hashfunctions::fSubdet,
0394                                         new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fieta),
0395                                         new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0396                                         0);
0397     _cOccupancyCutvsiphi_SubdetPM.initialize(_name,
0398                                              "OccupancyCutvsiphi",
0399                                              hcaldqm::hashfunctions::fSubdetPM,
0400                                              new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fiphi),
0401                                              new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0402                                              0);
0403     _cOccupancyCutvsieta_Subdet.initialize(_name,
0404                                            "OccupancyCutvsieta",
0405                                            hcaldqm::hashfunctions::fSubdet,
0406                                            new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fieta),
0407                                            new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0408                                            0);
0409     _cOccupancyCutvsLS_Subdet.initialize(_name,
0410                                          "OccupancyCutvsLS",
0411                                          hcaldqm::hashfunctions::fSubdet,
0412                                          new hcaldqm::quantity::LumiSection(_maxLS),
0413                                          new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN_to8000),
0414                                          0);
0415     _cOccupancyCutvsBX_Subdet.initialize(_name,
0416                                          "OccupancyCutvsBX",
0417                                          hcaldqm::hashfunctions::fSubdet,
0418                                          new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fBX),
0419                                          new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN_to8000),
0420                                          0);
0421     //      _cOccupancyCutvsSlotvsLS_HFPM.initialize(_name,
0422     //          "OccupancyCutvsSlotvsLS", hcaldqm::hashfunctions::fSubdetPM,
0423     //          new hcaldqm::quantity::LumiSection(_maxLS),
0424     //          new hcaldqm::quantity::ElectronicsQuantity(hcaldqm::quantity::fSlotuTCA),
0425     //          new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),0);
0426     _cOccupancyCutvsiphivsLS_SubdetPM.initialize(_name,
0427                                                  "OccupancyCutvsiphivsLS",
0428                                                  hcaldqm::hashfunctions::fSubdetPM,
0429                                                  new hcaldqm::quantity::LumiSection(_maxLS),
0430                                                  new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fiphi),
0431                                                  new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0432                                                  0);
0433   }
0434   _cCapidMinusBXmod4_SubdetPM.initialize(_name,
0435                                          "CapID",
0436                                          hcaldqm::hashfunctions::fSubdetPM,
0437                                          new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fCapidMinusBXmod4),
0438                                          new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true));
0439 
0440   for (int i = 0; i < 4; ++i) {
0441     _cCapidMinusBXmod4_CrateSlotuTCA[i].initialize(_name,
0442                                                    "CapID",
0443                                                    new quantity::ElectronicsQuantity(quantity::fCrateuTCA),
0444                                                    new quantity::ElectronicsQuantity(quantity::fSlotuTCA),
0445                                                    new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true),
0446                                                    0);
0447   }
0448 
0449   if (_ptype != fOffline) {  // hidefed2crate
0450     std::vector<int> vFEDs = hcaldqm::utilities::getFEDList(_emap);
0451     std::vector<int> vFEDsVME = hcaldqm::utilities::getFEDVMEList(_emap);
0452     std::vector<int> vFEDsuTCA = hcaldqm::utilities::getFEDuTCAList(_emap);
0453 
0454     if (_ptype == fOnline) {
0455       _cCapid_BadvsFEDvsLS.initialize(_name,
0456                                       "CapID",
0457                                       new hcaldqm::quantity::LumiSectionCoarse(_maxLS, 10),
0458                                       new hcaldqm::quantity::FEDQuantity(vFEDs),
0459                                       new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true),
0460                                       0);
0461 
0462       _cCapid_BadvsFEDvsLSmod60.initialize(_name,
0463                                            "CapID",
0464                                            new hcaldqm::quantity::LumiSection(60),
0465                                            new hcaldqm::quantity::FEDQuantity(vFEDs),
0466                                            new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true),
0467                                            0);
0468     }
0469 
0470     std::vector<uint32_t> vFEDHF;
0471     vFEDHF.push_back(HcalElectronicsId(22, SLOT_uTCA_MIN, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0472     vFEDHF.push_back(HcalElectronicsId(22, SLOT_uTCA_MIN + 6, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0473     vFEDHF.push_back(HcalElectronicsId(29, SLOT_uTCA_MIN, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0474     vFEDHF.push_back(HcalElectronicsId(29, SLOT_uTCA_MIN + 6, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0475     vFEDHF.push_back(HcalElectronicsId(32, SLOT_uTCA_MIN, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0476     vFEDHF.push_back(HcalElectronicsId(32, SLOT_uTCA_MIN + 6, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0477 
0478     //  initialize filters
0479     _filter_FEDHF.initialize(filter::fPreserver, hcaldqm::hashfunctions::fFED, vFEDHF);
0480 
0481     //  push the rawIds of each fed into the vector...
0482     for (std::vector<int>::const_iterator it = vFEDsVME.begin(); it != vFEDsVME.end(); ++it)
0483       _vhashFEDs.push_back(
0484           HcalElectronicsId(constants::FIBERCH_MIN, FIBER_VME_MIN, SPIGOT_MIN, (*it) - FED_VME_MIN).rawId());
0485     for (std::vector<int>::const_iterator it = vFEDsuTCA.begin(); it != vFEDsuTCA.end(); ++it) {
0486       std::pair<uint16_t, uint16_t> cspair = utilities::fed2crate(*it);
0487       _vhashFEDs.push_back(HcalElectronicsId(cspair.first, cspair.second, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0488     }
0489 
0490     _cShapeCut_FED.initialize(_name,
0491                               "ShapeCut",
0492                               hcaldqm::hashfunctions::fFED,
0493                               new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTiming_TS),
0494                               new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::ffC_10000),
0495                               0);
0496 
0497     _cTimingCut_FEDuTCA.initialize(_name,
0498                                    "TimingCut",
0499                                    hcaldqm::hashfunctions::fFED,
0500                                    new hcaldqm::quantity::ElectronicsQuantity(hcaldqm::quantity::fSlotuTCA),
0501                                    new hcaldqm::quantity::ElectronicsQuantity(hcaldqm::quantity::fFiberuTCAFiberCh),
0502                                    new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTiming_TS200),
0503                                    0);
0504     _cTimingCut_ElectronicsuTCA.initialize(_name,
0505                                            "TimingCut",
0506                                            hcaldqm::hashfunctions::fElectronics,
0507                                            new hcaldqm::quantity::FEDQuantity(vFEDsuTCA),
0508                                            new hcaldqm::quantity::ElectronicsQuantity(hcaldqm::quantity::fSlotuTCA),
0509                                            new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTiming_TS200),
0510                                            0);
0511     _cTimingCutvsLS_FED.initialize(_name,
0512                                    "TimingvsLS",
0513                                    hcaldqm::hashfunctions::fFED,
0514                                    new hcaldqm::quantity::LumiSection(_maxLS),
0515                                    new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fTiming_TS200),
0516                                    0);
0517 
0518     _cOccupancy_FEDuTCA.initialize(_name,
0519                                    "Occupancy",
0520                                    hcaldqm::hashfunctions::fFED,
0521                                    new hcaldqm::quantity::ElectronicsQuantity(hcaldqm::quantity::fSlotuTCA),
0522                                    new hcaldqm::quantity::ElectronicsQuantity(hcaldqm::quantity::fFiberuTCAFiberCh),
0523                                    new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0524                                    0);
0525     _cOccupancy_ElectronicsuTCA.initialize(_name,
0526                                            "Occupancy",
0527                                            hcaldqm::hashfunctions::fElectronics,
0528                                            new hcaldqm::quantity::FEDQuantity(vFEDsuTCA),
0529                                            new hcaldqm::quantity::ElectronicsQuantity(hcaldqm::quantity::fSlotuTCA),
0530                                            new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0531                                            0);
0532 
0533     _cOccupancyCut_FEDuTCA.initialize(_name,
0534                                       "OccupancyCut",
0535                                       hcaldqm::hashfunctions::fFED,
0536                                       new hcaldqm::quantity::ElectronicsQuantity(hcaldqm::quantity::fSlotuTCA),
0537                                       new hcaldqm::quantity::ElectronicsQuantity(hcaldqm::quantity::fFiberuTCAFiberCh),
0538                                       new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0539                                       0);
0540     _cOccupancyCut_ElectronicsuTCA.initialize(_name,
0541                                               "OccupancyCut",
0542                                               hcaldqm::hashfunctions::fElectronics,
0543                                               new hcaldqm::quantity::FEDQuantity(vFEDsuTCA),
0544                                               new hcaldqm::quantity::ElectronicsQuantity(hcaldqm::quantity::fSlotuTCA),
0545                                               new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0546                                               0);
0547 
0548     _cDigiSize_FED.initialize(_name,
0549                               "DigiSize",
0550                               hcaldqm::hashfunctions::fFED,
0551                               new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fDigiSize),
0552                               new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0553                               0);
0554 
0555     if (_ptype == fOnline) {
0556       _cSummaryvsLS_FED.initialize(_name,
0557                                    "SummaryvsLS",
0558                                    hcaldqm::hashfunctions::fFED,
0559                                    new hcaldqm::quantity::LumiSection(_maxLS),
0560                                    new hcaldqm::quantity::FlagQuantity(_vflags),
0561                                    new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fState),
0562                                    0);
0563       _cSummaryvsLS.initialize(_name,
0564                                "SummaryvsLS",
0565                                new hcaldqm::quantity::LumiSection(_maxLS),
0566                                new hcaldqm::quantity::FEDQuantity(vFEDs),
0567                                new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fState),
0568                                0);
0569 
0570       _xUniHF.initialize(hcaldqm::hashfunctions::fFEDSlot);
0571       _xUni.initialize(hcaldqm::hashfunctions::fFED);
0572       _xDigiSize.initialize(hcaldqm::hashfunctions::fFED);
0573       _xNChs.initialize(hcaldqm::hashfunctions::fFED);
0574       _xNChsNominal.initialize(hcaldqm::hashfunctions::fFED);
0575       _xBadCapid.initialize(hcaldqm::hashfunctions::fFED);
0576     }
0577   }
0578   if (_ptype != fLocal) {
0579     _LED_ADCvsBX_Subdet.initialize(_name,
0580                                    "LED_ADCvsBX",
0581                                    hcaldqm::hashfunctions::fSubdet,
0582                                    new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fBX_36),
0583                                    new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fADC_256_4),
0584                                    new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0585                                    0);
0586 
0587     _LED_CUCountvsLS_Subdet.initialize(_name,
0588                                        "LED_CUCountvsLS",
0589                                        hcaldqm::hashfunctions::fSubdet,
0590                                        new hcaldqm::quantity::LumiSection(_maxLS),
0591                                        new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0592                                        0);
0593     if (_ptype == fOnline) {
0594       _LED_CUCountvsLSmod60_Subdet.initialize(_name,
0595                                               "LED_CUCountvsLSmod60",
0596                                               hcaldqm::hashfunctions::fSubdet,
0597                                               new hcaldqm::quantity::LumiSection(60),
0598                                               new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0599                                               0);
0600     }
0601   }
0602 
0603   //    BOOK HISTOGRAMS
0604   char cutstr[200];
0605   sprintf(cutstr, "_SumQHBHE%dHO%dHF%d", int(_cutSumQ_HBHE), int(_cutSumQ_HO), int(_cutSumQ_HF));
0606   char cutstr2[200];
0607   sprintf(cutstr2, "_SumQHF%d", int(_cutSumQ_HF));
0608 
0609   _cADC_SubdetPM.book(ib, _emap, _filter_QIE8, _subsystem);
0610   _cADC_SubdetPM_QIE1011.book(ib, _emap, _filter_QIE1011, _subsystem);
0611   _cfC_SubdetPM.book(ib, _emap, _filter_QIE8, _subsystem);
0612   _cfC_SubdetPM_QIE1011.book(ib, _emap, _filter_QIE1011, _subsystem);
0613   _cSumQ_SubdetPM.book(ib, _emap, _filter_QIE8, _subsystem);
0614   _cSumQ_SubdetPM_QIE1011.book(ib, _emap, _filter_QIE1011, _subsystem);
0615   _cSumQ_depth.book(ib, _emap, _subsystem);
0616   _cSumQvsLS_SubdetPM.book(ib, _emap, _filter_QIE8, _subsystem);
0617   _cSumQvsLS_SubdetPM_QIE1011.book(ib, _emap, _filter_QIE1011, _subsystem);
0618   _cADCvsTS_SubdetPM.book(ib, _emap, _filter_QIE8, _subsystem);
0619   _cADCvsTS_SubdetPM_QIE1011.book(ib, _emap, _filter_QIE1011, _subsystem);
0620 
0621   if (_ptype != fOffline) {  // hidefed2crate
0622     _cShapeCut_FED.book(ib, _emap, _subsystem);
0623     _cTimingCut_FEDuTCA.book(ib, _emap, _filter_VME, _subsystem);
0624     _cTimingCut_ElectronicsuTCA.book(ib, _emap, _filter_VME, _subsystem);
0625     _cTimingCutvsLS_FED.book(ib, _emap, _subsystem);
0626     _cOccupancy_FEDuTCA.book(ib, _emap, _filter_VME, _subsystem);
0627     _cOccupancy_ElectronicsuTCA.book(ib, _emap, _filter_VME, _subsystem);
0628     _cOccupancyCut_FEDuTCA.book(ib, _emap, _filter_VME, _subsystem);
0629     _cOccupancyCut_ElectronicsuTCA.book(ib, _emap, _filter_VME, _subsystem);
0630     _cDigiSize_FED.book(ib, _emap, _subsystem);
0631   }
0632   if (_ptype != fOffline) {  // else book per-lumi later.
0633     _cDigiSize_Crate.book(ib, _emap, _subsystem);
0634     _cOccupancy_depth.book(ib, _emap, _subsystem);
0635   }
0636 
0637   _cTimingCut_SubdetPM.book(ib, _emap, _subsystem);
0638   _cTimingCutHTH_SubdetPM.book(ib, _emap, _subsystem);
0639   _cTimingCut_depth.book(ib, _emap, _subsystem);
0640   _cTimingCutvsLS_SubdetPM.book(ib, _emap, _subsystem);
0641 
0642   _cOccupancyvsLS_Subdet.book(ib, _emap, _subsystem);
0643   _cOccupancyCut_depth.book(ib, _emap, _subsystem);
0644 
0645   _cLETDCTimevsADC_SubdetPM.book(ib, _emap, _subsystem);
0646   _cLETDCvsADC_2bit_SubdetPM.book(ib, _emap, _filter_TDC2bit, _subsystem);
0647   _cLETDCvsADC_6bit_SubdetPM.book(ib, _emap, _filter_TDC6bit, _subsystem);
0648   _cLETDCvsTS_2bit_SubdetPM.book(ib, _emap, _filter_TDC2bit, _subsystem);
0649   _cLETDCvsTS_6bit_SubdetPM.book(ib, _emap, _filter_TDC6bit, _subsystem);
0650   _cLETDCTime_SubdetPM.book(ib, _emap, _subsystem);
0651   _cLETDCTime_depth.book(ib, _emap, _subsystem);
0652 
0653   _cBadTDCValues_SubdetPM.book(ib, _emap, _subsystem);
0654   _cBadTDCvsBX_SubdetPM.book(ib, _emap, _subsystem);
0655   _cBadTDCvsLS_SubdetPM.book(ib, _emap, _subsystem);
0656   _cBadTDCCount_depth.book(ib, _emap, _subsystem);
0657 
0658   _cCapidMinusBXmod4_SubdetPM.book(ib, _emap, _subsystem);
0659   if (_ptype == fOnline) {
0660     _cCapid_BadvsFEDvsLS.book(ib, _subsystem, "BadvsLS");
0661     _cCapid_BadvsFEDvsLSmod60.book(ib, _subsystem, "BadvsLSmod60");
0662   }
0663   for (int i = 0; i < 4; ++i) {
0664     constexpr unsigned int kSize = 32;
0665     char aux[kSize];
0666     snprintf(aux, kSize, "%d_uTCA", i);
0667     _cCapidMinusBXmod4_CrateSlotuTCA[i].book(ib, _subsystem, aux);
0668   }
0669 
0670   if (_ptype != fLocal) {
0671     _LED_ADCvsBX_Subdet.book(ib, _emap, _subsystem);
0672     _LED_CUCountvsLS_Subdet.book(ib, _emap, _subsystem);
0673     if (_ptype == fOnline) {
0674       _LED_CUCountvsLSmod60_Subdet.book(ib, _emap, _subsystem);
0675     }
0676   }
0677 
0678   //    BOOK HISTOGRAMS that are only for Online
0679   _ehashmap.initialize(_emap, electronicsmap::fD2EHashMap);
0680   _dhashmap.initialize(_emap, electronicsmap::fE2DHashMap);
0681 
0682   if (_ptype == fOnline || _ptype == fLocal) {
0683     _cOccupancy_Crate.book(ib, _emap, _subsystem);
0684     _cOccupancy_CrateSlot.book(ib, _emap, _subsystem);
0685   }
0686 
0687   if (_ptype == fOnline) {
0688     _cQ2Q12CutvsLS_FEDHF.book(ib, _emap, _filter_FEDHF, _subsystem);
0689     _cSumQvsBX_SubdetPM.book(ib, _emap, _filter_QIE8, _subsystem);
0690     _cSumQvsBX_SubdetPM_QIE1011.book(ib, _emap, _filter_QIE1011, _subsystem);
0691     _cDigiSizevsLS_FED.book(ib, _emap, _subsystem);
0692     _cTimingCutvsiphi_SubdetPM.book(ib, _emap, _subsystem);
0693     _cTimingCutvsieta_Subdet.book(ib, _emap, _subsystem);
0694     _cOccupancyCutvsLS_Subdet.book(ib, _emap, _subsystem);
0695     _cOccupancyCutvsBX_Subdet.book(ib, _emap, _subsystem);
0696     _cOccupancyvsiphi_SubdetPM.book(ib, _emap, _subsystem);
0697     _cOccupancyvsieta_Subdet.book(ib, _emap, _subsystem);
0698     _cOccupancyCutvsiphi_SubdetPM.book(ib, _emap, _subsystem);
0699     _cOccupancyCutvsieta_Subdet.book(ib, _emap, _subsystem);
0700     //      _cOccupancyCutvsSlotvsLS_HFPM.book(ib, _emap, _filter_QIE1011, _subsystem);
0701     _cOccupancyCutvsiphivsLS_SubdetPM.book(ib, _emap, _subsystem);
0702     _cSummaryvsLS_FED.book(ib, _emap, _subsystem);
0703     _cSummaryvsLS.book(ib, _subsystem);
0704 
0705     _xUniHF.book(_emap, _filter_FEDHF);
0706     _xNChs.book(_emap);
0707     _xNChsNominal.book(_emap);
0708     _xUni.book(_emap);
0709     _xDigiSize.book(_emap);
0710     _xBadCapid.book(_emap);
0711 
0712     // just PER HF FED RECORD THE #CHANNELS
0713     // ONLY WAY TO DO THAT AUTOMATICALLY AND W/O HARDCODING 1728
0714     // or ANY OTHER VALUES LIKE 2592, 2192
0715     std::vector<HcalGenericDetId> gids = _emap->allPrecisionId();
0716     for (std::vector<HcalGenericDetId>::const_iterator it = gids.begin(); it != gids.end(); ++it) {
0717       if (!it->isHcalDetId())
0718         continue;
0719       HcalDetId did(it->rawId());
0720       if (_xQuality.exists(did)) {
0721         HcalChannelStatus cs(it->rawId(), _xQuality.get(HcalDetId(*it)));
0722         if (cs.isBitSet(HcalChannelStatus::HcalCellMask) || cs.isBitSet(HcalChannelStatus::HcalCellDead))
0723           continue;
0724       }
0725       HcalElectronicsId eid = HcalElectronicsId(_ehashmap.lookup(did));
0726       _xNChsNominal.get(eid)++;  // he will know the nominal #channels per FED
0727     }
0728   }
0729 
0730   {
0731     //  MARK THESE HISTOGRAMS AS LUMI BASED FOR OFFLINE PROCESSING
0732     auto scope = DQMStore::IBooker::UseLumiScope(ib);
0733     if (_ptype == fOffline) {
0734       //_cDigiSize_FED.setLumiFlag();
0735       _cDigiSize_Crate.book(ib, _emap, _subsystem);
0736       _cOccupancy_depth.book(ib, _emap, _subsystem);
0737     }
0738 
0739     //  book Number of Events vs LS histogram
0740     ib.setCurrentFolder(_subsystem + "/RunInfo");
0741     meNumEvents1LS = ib.book1DD("NumberOfEvents", "NumberOfEvents", 1, 0, 1);
0742 
0743     //  book the flag for unknown ids and the online guy as well
0744     ib.setCurrentFolder(_subsystem + "/" + _name);
0745     meUnknownIds1LS = ib.book1DD("UnknownIds", "UnknownIds", 1, 0, 1);
0746     _unknownIdsPresent = false;
0747   }
0748 }
0749 
0750 /* virtual */ void DigiTask::_resetMonitors(hcaldqm::UpdateFreq uf) {
0751   DQTask::_resetMonitors(uf);
0752 
0753   switch (uf) {
0754     case hcaldqm::f1LS:
0755       _unknownIdsPresent = false;
0756       break;
0757     case hcaldqm::f50LS:
0758       //    ^^^ONLINE ONLY!
0759       if (_ptype == fOnline)
0760         _cOccupancyvsiphi_SubdetPM.reset();
0761       //    ^^^
0762       break;
0763     default:
0764       break;
0765   }
0766 }
0767 
0768 /* virtual */ void DigiTask::_process(edm::Event const& e, edm::EventSetup const&) {
0769   edm::Handle<QIE11DigiCollection> c_QIE11;
0770   edm::Handle<HODigiCollection> c_ho;
0771   edm::Handle<QIE10DigiCollection> c_QIE10;
0772 
0773   if (!e.getByToken(_tokQIE11, c_QIE11))
0774     _logger.dqmthrow("Collection QIE11DigiCollection isn't available" + _tagQIE11.label() + " " + _tagQIE11.instance());
0775   if (!e.getByToken(_tokHO, c_ho))
0776     _logger.dqmthrow("Collection HODigiCollection isn't available" + _tagHO.label() + " " + _tagHO.instance());
0777   if (!e.getByToken(_tokQIE10, c_QIE10))
0778     _logger.dqmthrow("Collection QIE10DigiCollection isn't available" + _tagQIE10.label() + " " + _tagQIE10.instance());
0779 
0780   //    extract some info per event
0781   int bx = e.bunchCrossing();
0782   meNumEvents1LS->Fill(0.5);  // just increment
0783 
0784   auto lumiCache = luminosityBlockCache(e.getLuminosityBlock().index());
0785   _currentLS = lumiCache->currentLS;
0786   _xQuality.reset();
0787   _xQuality = lumiCache->xQuality;
0788 
0789   if (_ptype == fOnline &&
0790       lumiCache->EvtCntLS == 1) {  // Reset the bin for _cCapid_BadvsFEDvsLSmod60 at the beginning of each new LS
0791     for (std::vector<uint32_t>::const_iterator it = _vhashFEDs.begin(); it != _vhashFEDs.end(); ++it) {
0792       HcalElectronicsId eid = HcalElectronicsId(*it);
0793       _cCapid_BadvsFEDvsLSmod60.setBinContent(eid, _currentLS % 50, 0);
0794     }
0795   }
0796 
0797   //    To fill histograms outside of the loop, you need to determine if there were
0798   //    any valid det ids first
0799   uint32_t rawidValid = 0;
0800   uint32_t rawidHBValid = 0;
0801   uint32_t rawidHEValid = 0;
0802 
0803   //    HB collection
0804   int numChs = 0;
0805   int numChsCut = 0;
0806   int numChsHE = 0;
0807   int numChsCutHE = 0;
0808 
0809   // HB+HE QIE11 collection
0810   for (QIE11DigiCollection::const_iterator it = c_QIE11->begin(); it != c_QIE11->end(); ++it) {
0811     const QIE11DataFrame digi = static_cast<const QIE11DataFrame>(*it);
0812 
0813     //  Explicit check on the DetIds present in the Collection
0814     HcalDetId const& did = digi.detid();
0815     if ((did.subdet() != HcalBarrel) && (did.subdet() != HcalEndcap)) {
0816       // LED monitoring from calibration channels
0817       if (_ptype != fLocal) {
0818         if (did.subdet() == HcalOther) {
0819           HcalOtherDetId hodid(digi.detid());
0820           if (hodid.subdet() == HcalCalibration) {
0821             if (std::find(_ledCalibrationChannels[HcalEndcap].begin(),
0822                           _ledCalibrationChannels[HcalEndcap].end(),
0823                           did) != _ledCalibrationChannels[HcalEndcap].end()) {
0824               bool channelLEDSignalPresent = false;
0825               for (int i = 0; i < digi.samples(); i++) {
0826                 _LED_ADCvsBX_Subdet.fill(HcalDetId(HcalEndcap, 16, 1, 1), bx, digi[i].adc());
0827 
0828                 if (digi[i].adc() > _thresh_led) {
0829                   channelLEDSignalPresent = true;
0830                 }
0831               }
0832               if (channelLEDSignalPresent) {
0833                 _LED_CUCountvsLS_Subdet.fill(HcalDetId(HcalEndcap, 16, 1, 1), _currentLS);
0834                 if (_ptype == fOnline) {
0835                   _LED_CUCountvsLSmod60_Subdet.fill(HcalDetId(HcalEndcap, 16, 1, 1), _currentLS % 60);
0836                 }
0837               }
0838             } else if (std::find(_ledCalibrationChannels[HcalBarrel].begin(),
0839                                  _ledCalibrationChannels[HcalBarrel].end(),
0840                                  did) != _ledCalibrationChannels[HcalBarrel].end()) {
0841               bool channelLEDSignalPresent = false;
0842               for (int i = 0; i < digi.samples(); i++) {
0843                 _LED_ADCvsBX_Subdet.fill(HcalDetId(HcalBarrel, 1, 1, 1), bx, digi[i].adc());
0844 
0845                 if (digi[i].adc() > _thresh_led) {
0846                   channelLEDSignalPresent = true;
0847                 }
0848               }
0849               if (channelLEDSignalPresent) {
0850                 _LED_CUCountvsLS_Subdet.fill(HcalDetId(HcalBarrel, 1, 1, 1), _currentLS);
0851                 if (_ptype == fOnline) {
0852                   _LED_CUCountvsLSmod60_Subdet.fill(HcalDetId(HcalBarrel, 1, 1, 1), _currentLS % 60);
0853                 }
0854               }
0855             }
0856           }
0857         }
0858       }
0859       continue;
0860     }
0861 
0862     uint32_t rawid = _ehashmap.lookup(did);
0863     if (rawid == 0) {
0864       meUnknownIds1LS->Fill(1);
0865       _unknownIdsPresent = true;
0866       continue;
0867     } else {
0868       if (did.subdet() == HcalBarrel) {
0869         rawidHBValid = did.rawId();
0870       } else if (did.subdet() == HcalEndcap) {
0871         rawidHEValid = did.rawId();
0872       }
0873     }
0874     HcalElectronicsId const& eid(rawid);
0875 
0876     //  filter out channels that are masked out
0877     if (_xQuality.exists(did)) {
0878       HcalChannelStatus cs(did.rawId(), _xQuality.get(did));
0879       if (cs.isBitSet(HcalChannelStatus::HcalCellMask) || cs.isBitSet(HcalChannelStatus::HcalCellDead))
0880         continue;
0881     }
0882 
0883     // (capid - BX) % 4
0884     if (_ptype == fOnline) {
0885       short soi = -1;
0886       for (int i = 0; i < digi.samples(); i++) {
0887         if (digi[i].soi()) {
0888           soi = i;
0889           break;
0890         }
0891       }
0892       short this_capidmbx = (digi[soi].capid() - bx) % 4;
0893       if (this_capidmbx < 0) {
0894         this_capidmbx += 4;
0895       }
0896       _cCapidMinusBXmod4_SubdetPM.fill(did, this_capidmbx);
0897       bool good_capidmbx = (_capidmbx[did.subdet()] == this_capidmbx);
0898       if (!good_capidmbx) {
0899         _xBadCapid.get(eid)++;
0900         _cCapid_BadvsFEDvsLS.fill(eid, _currentLS);
0901         _cCapid_BadvsFEDvsLSmod60.fill(eid, _currentLS % 60);
0902       }
0903       if (!eid.isVMEid()) {
0904         _cCapidMinusBXmod4_CrateSlotuTCA[this_capidmbx].fill(eid);
0905       }
0906     }
0907 
0908     CaloSamples digi_fC = hcaldqm::utilities::loadADC2fCDB<QIE11DataFrame>(_dbService, did, digi);
0909     double sumQ = hcaldqm::utilities::sumQDB<QIE11DataFrame>(_dbService, digi_fC, did, digi, 0, digi.samples() - 1);
0910 
0911     _cSumQ_SubdetPM_QIE1011.fill(did, sumQ);
0912     _cOccupancy_depth.fill(did);
0913     if (_ptype == fOnline || _ptype == fLocal) {
0914       _cOccupancy_Crate.fill(eid);
0915       _cOccupancy_CrateSlot.fill(eid);
0916     }
0917     if (_ptype == fOnline) {
0918       _cDigiSizevsLS_FED.fill(eid, _currentLS, digi.samples());
0919       digi.samples() != _refDigiSize[did.subdet()] ? _xDigiSize.get(eid)++ : _xDigiSize.get(eid) += 0;
0920       _cOccupancyvsiphi_SubdetPM.fill(did);
0921       _cOccupancyvsieta_Subdet.fill(did);
0922     }
0923     _cDigiSize_Crate.fill(eid, digi.samples());
0924     if (_ptype != fOffline) {  // hidefed2crate
0925       _cDigiSize_FED.fill(eid, digi.samples());
0926       if (!eid.isVMEid()) {
0927         _cOccupancy_FEDuTCA.fill(eid);
0928         _cOccupancy_ElectronicsuTCA.fill(eid);
0929         /*
0930                 if (!digi.validate(0, digi.size()))
0931                 {
0932                     _cCapIdRots_depth.fill(did);
0933                     _cCapIdRots_FEDuTCA.fill(eid, 1);
0934                 }*/
0935       }
0936     }
0937     for (int i = 0; i < digi.samples(); i++) {
0938       double q = hcaldqm::utilities::adc2fCDBMinusPedestal<QIE11DataFrame>(_dbService, digi_fC, did, digi, i);
0939       _cADC_SubdetPM_QIE1011.fill(did, digi[i].adc());
0940       _cfC_SubdetPM_QIE1011.fill(did, q);
0941 
0942       if (did.subdet() == HcalBarrel) {
0943         _cLETDCvsADC_2bit_SubdetPM.fill(did, digi[i].adc(), digi[i].tdc());
0944         _cLETDCvsTS_2bit_SubdetPM.fill(did, (int)i, digi[i].tdc());
0945 
0946         if (digi[i].tdc() < 2) {
0947           double time = i * 25. + (digi[i].tdc() * 12.5);
0948           _cLETDCTime_SubdetPM.fill(did, time);
0949           _cLETDCTime_depth.fill(did, time);
0950           _cLETDCTimevsADC_SubdetPM.fill(did, digi[i].adc(), time);
0951         }
0952       } else if (did.subdet() == HcalEndcap) {
0953         _cLETDCvsADC_6bit_SubdetPM.fill(did, digi[i].adc(), digi[i].tdc());
0954         _cLETDCvsTS_6bit_SubdetPM.fill(did, (int)i, digi[i].tdc());
0955         if (digi[i].tdc() < 50) {
0956           double time = i * 25. + (digi[i].tdc() / 2.);
0957           _cLETDCTime_SubdetPM.fill(did, time);
0958           _cLETDCTime_depth.fill(did, time);
0959           _cLETDCTimevsADC_SubdetPM.fill(did, digi[i].adc(), time);
0960         }
0961         // Bad TDC values: 50-61 should never happen in QIE10 or QIE11, but we saw some in 2017 data.
0962         if ((50 <= digi[i].tdc()) && (digi[i].tdc() <= 61)) {
0963           _cBadTDCValues_SubdetPM.fill(did, digi[i].tdc());
0964           _cBadTDCvsBX_SubdetPM.fill(did, bx);
0965           _cBadTDCvsLS_SubdetPM.fill(did, _currentLS);
0966           _cBadTDCCount_depth.fill(did);
0967         }
0968       }
0969       if (_ptype != fOffline) {  // hidefed2crate
0970         _cADCvsTS_SubdetPM_QIE1011.fill(did, i, digi[i].adc());
0971         if (sumQ > _cutSumQ_HBHE) {
0972           _cShapeCut_FED.fill(eid, i, q);
0973         }
0974       }
0975     }
0976 
0977     if (sumQ > _cutSumQ_HBHE) {
0978       //double timing = hcaldqm::utilities::aveTS_v10<QIE11DataFrame>(digi, 2.5, 0,digi.samples()-1);
0979       // without pedestal substraction, request from https://gitlab.cern.ch/cmshcal/docs/-/issues/106
0980       double timing =
0981           hcaldqm::utilities::aveTSDB<QIE11DataFrame>(_dbService, digi_fC, did, digi, 0, digi.samples() - 1, false);
0982       _cTimingCut_SubdetPM.fill(did, timing);
0983       // with pedestal substraction for energetic hits
0984       if (sumQ > 100. * _cutSumQ_HBHE)
0985         _cTimingCutHTH_SubdetPM.fill(
0986             did, hcaldqm::utilities::aveTSDB<QIE11DataFrame>(_dbService, digi_fC, did, digi, 0, digi.samples() - 1));
0987       _cTimingCut_depth.fill(did, timing);
0988       _cOccupancyCut_depth.fill(did);
0989       _cTimingCutvsLS_SubdetPM.fill(did, _currentLS, timing);
0990       if (_ptype != fOffline) {  // hidefed2crate
0991         _cTimingCutvsLS_FED.fill(eid, _currentLS, timing);
0992       }
0993       _cSumQ_depth.fill(did, sumQ);
0994       _cSumQvsLS_SubdetPM_QIE1011.fill(did, _currentLS, sumQ);
0995       if (_ptype == fOnline) {
0996         _cSumQvsBX_SubdetPM_QIE1011.fill(did, bx, sumQ);
0997         _cTimingCutvsiphi_SubdetPM.fill(did, timing);
0998         _cTimingCutvsieta_Subdet.fill(did, timing);
0999         _cOccupancyCutvsiphi_SubdetPM.fill(did);
1000         _cOccupancyCutvsieta_Subdet.fill(did);
1001         _cOccupancyCutvsiphivsLS_SubdetPM.fill(did, _currentLS);
1002       }
1003       if (_ptype != fOffline) {  // hidefed2crate
1004         if (!eid.isVMEid()) {
1005           _cTimingCut_FEDuTCA.fill(eid, timing);
1006           _cTimingCut_ElectronicsuTCA.fill(eid, timing);
1007           _cOccupancyCut_FEDuTCA.fill(eid);
1008           _cOccupancyCut_ElectronicsuTCA.fill(eid);
1009         }
1010       }
1011       did.subdet() == HcalBarrel ? numChsCut++ : numChsCutHE++;
1012     }
1013     did.subdet() == HcalBarrel ? numChs++ : numChsHE++;
1014   }
1015 
1016   if (rawidHBValid != 0 && rawidHEValid != 0) {
1017     _cOccupancyvsLS_Subdet.fill(HcalDetId(rawidHBValid), _currentLS, numChs);
1018     _cOccupancyvsLS_Subdet.fill(HcalDetId(rawidHEValid), _currentLS, numChsHE);
1019     //  ONLINE ONLY!
1020     if (_ptype == fOnline) {
1021       _cOccupancyCutvsLS_Subdet.fill(HcalDetId(rawidHBValid), _currentLS, numChsCut);
1022       _cOccupancyCutvsBX_Subdet.fill(HcalDetId(rawidHBValid), bx, numChsCut);
1023       _cOccupancyCutvsLS_Subdet.fill(HcalDetId(rawidHEValid), _currentLS, numChsCutHE);
1024       _cOccupancyCutvsBX_Subdet.fill(HcalDetId(rawidHEValid), bx, numChsCutHE);
1025     }
1026     //  ^^^ONLINE ONLY!
1027   }
1028   numChs = 0;
1029   numChsCut = 0;
1030 
1031   //    reset
1032   rawidValid = 0;
1033 
1034   //    HO collection
1035   for (HODigiCollection::const_iterator it = c_ho->begin(); it != c_ho->end(); ++it) {
1036     const HODataFrame digi = (const HODataFrame)(*it);
1037     //  Explicit check on the DetIds present in the Collection
1038     HcalDetId const& did = it->id();
1039     if (did.subdet() != HcalOuter) {
1040       // LED monitoring from calibration channels
1041       if (_ptype != fLocal) {
1042         if (did.subdet() == HcalOther) {
1043           HcalOtherDetId hodid(did);
1044           if (hodid.subdet() == HcalCalibration) {
1045             if (std::find(_ledCalibrationChannels[HcalOuter].begin(), _ledCalibrationChannels[HcalOuter].end(), did) !=
1046                 _ledCalibrationChannels[HcalOuter].end()) {
1047               bool channelLEDSignalPresent = false;
1048               for (int i = 0; i < digi.size(); i++) {
1049                 _LED_ADCvsBX_Subdet.fill(HcalDetId(HcalOuter, 1, 1, 4), bx, digi[i].adc());
1050 
1051                 if (digi[i].adc() > _thresh_led) {
1052                   channelLEDSignalPresent = true;
1053                 }
1054               }
1055               if (channelLEDSignalPresent) {
1056                 _LED_CUCountvsLS_Subdet.fill(HcalDetId(HcalOuter, 1, 1, 4), _currentLS);
1057                 if (_ptype == fOnline) {
1058                   _LED_CUCountvsLSmod60_Subdet.fill(HcalDetId(HcalOuter, 1, 1, 4), _currentLS % 60);
1059                 }
1060               }
1061             }
1062           }
1063         }
1064       }
1065       continue;
1066     }
1067     uint32_t rawid = _ehashmap.lookup(did);
1068     if (rawid == 0) {
1069       meUnknownIds1LS->Fill(1);
1070       _unknownIdsPresent = true;
1071       continue;
1072     } else {
1073       rawidValid = did.rawId();
1074     }
1075     HcalElectronicsId const& eid(rawid);
1076 
1077     //  filter out channels that are masked out
1078     if (_xQuality.exists(did)) {
1079       HcalChannelStatus cs(did.rawId(), _xQuality.get(did));
1080       if (cs.isBitSet(HcalChannelStatus::HcalCellMask) || cs.isBitSet(HcalChannelStatus::HcalCellDead))
1081         continue;
1082     }
1083 
1084     if (_ptype == fOnline) {
1085       short this_capidmbx = (it->sample(it->presamples()).capid() - bx) % 4;
1086       if (this_capidmbx < 0) {
1087         this_capidmbx += 4;
1088       }
1089       _cCapidMinusBXmod4_SubdetPM.fill(did, this_capidmbx);
1090       bool good_capidmbx = (_capidmbx[did.subdet()] == this_capidmbx);
1091       if (!good_capidmbx) {
1092         _xBadCapid.get(eid)++;
1093         _cCapid_BadvsFEDvsLS.fill(eid, _currentLS);
1094         _cCapid_BadvsFEDvsLSmod60.fill(eid, _currentLS % 60);
1095       }
1096       if (!eid.isVMEid()) {
1097         _cCapidMinusBXmod4_CrateSlotuTCA[this_capidmbx].fill(eid);
1098       }
1099     }
1100 
1101     //double sumQ = hcaldqm::utilities::sumQ<HODataFrame>(*it, 8.5, 0, it->size()-1);
1102     CaloSamples digi_fC = hcaldqm::utilities::loadADC2fCDB<HODataFrame>(_dbService, did, *it);
1103     double sumQ = hcaldqm::utilities::sumQDB<HODataFrame>(_dbService, digi_fC, did, *it, 0, it->size() - 1);
1104 
1105     _cSumQ_SubdetPM.fill(did, sumQ);
1106     _cOccupancy_depth.fill(did);
1107     if (_ptype == fOnline) {
1108       _cDigiSizevsLS_FED.fill(eid, _currentLS, it->size());
1109       it->size() != _refDigiSize[did.subdet()] ? _xDigiSize.get(eid)++ : _xDigiSize.get(eid) += 0;
1110       _cOccupancyvsiphi_SubdetPM.fill(did);
1111       _cOccupancyvsieta_Subdet.fill(did);
1112     }
1113     _cDigiSize_Crate.fill(eid, it->size());
1114     if (_ptype != fOffline) {  // hidefed2crate
1115       _cDigiSize_FED.fill(eid, it->size());
1116       if (!eid.isVMEid()) {
1117         _cOccupancy_FEDuTCA.fill(eid);
1118         _cOccupancy_ElectronicsuTCA.fill(eid);
1119         /*
1120                 if (!it->validate(0, it->size()))
1121                     _cCapIdRots_FEDuTCA.fill(eid, 1);*/
1122       }
1123     }
1124 
1125     for (int i = 0; i < it->size(); i++) {
1126       _cADC_SubdetPM.fill(did, it->sample(i).adc());
1127       _cfC_SubdetPM.fill(did, it->sample(i).nominal_fC());
1128       if (_ptype != fOffline) {  // hidefed2crate
1129         _cADCvsTS_SubdetPM.fill(did, i, it->sample(i).adc());
1130         if (sumQ > _cutSumQ_HO)
1131           _cShapeCut_FED.fill(eid, i, it->sample(i).nominal_fC());
1132       }
1133     }
1134 
1135     if (sumQ > _cutSumQ_HO) {
1136       //double timing = hcaldqm::utilities::aveTS<HODataFrame>(*it, 8.5, 0,it->size()-1);
1137       // without pedestal substraction, request from https://gitlab.cern.ch/cmshcal/docs/-/issues/106
1138       double timing = hcaldqm::utilities::aveTSDB<HODataFrame>(_dbService, digi_fC, did, *it, 0, it->size() - 1, false);
1139       _cSumQ_depth.fill(did, sumQ);
1140       _cSumQvsLS_SubdetPM.fill(did, _currentLS, sumQ);
1141       _cOccupancyCut_depth.fill(did);
1142       _cTimingCut_SubdetPM.fill(did, timing);
1143       // with pedestal substraction for energetic hits
1144       if (sumQ > 100. * _cutSumQ_HO)
1145         _cTimingCutHTH_SubdetPM.fill(
1146             did, hcaldqm::utilities::aveTSDB<HODataFrame>(_dbService, digi_fC, did, *it, 0, it->size() - 1));
1147       _cTimingCut_depth.fill(did, timing);
1148       _cTimingCutvsLS_SubdetPM.fill(did, _currentLS, timing);
1149       if (_ptype != fOffline) {  // hidefed2crate
1150         _cTimingCutvsLS_FED.fill(eid, _currentLS, timing);
1151       }
1152       if (_ptype == fOnline) {
1153         _cSumQvsBX_SubdetPM.fill(did, bx, sumQ);
1154         _cTimingCutvsiphi_SubdetPM.fill(did, timing);
1155         _cTimingCutvsieta_Subdet.fill(did, timing);
1156         _cOccupancyCutvsiphi_SubdetPM.fill(did);
1157         _cOccupancyCutvsieta_Subdet.fill(did);
1158         _cOccupancyCutvsiphivsLS_SubdetPM.fill(did, _currentLS);
1159       }
1160       if (_ptype != fOffline) {  // hidefed2crate
1161         if (!eid.isVMEid()) {
1162           _cTimingCut_FEDuTCA.fill(eid, timing);
1163           _cTimingCut_ElectronicsuTCA.fill(eid, timing);
1164           _cOccupancyCut_FEDuTCA.fill(eid);
1165           _cOccupancyCut_ElectronicsuTCA.fill(eid);
1166         }
1167       }
1168       numChsCut++;
1169     }
1170     numChs++;
1171   }
1172 
1173   if (rawidValid != 0) {
1174     _cOccupancyvsLS_Subdet.fill(HcalDetId(rawidValid), _currentLS, numChs);
1175 
1176     if (_ptype == fOnline) {
1177       _cOccupancyCutvsLS_Subdet.fill(HcalDetId(rawidValid), _currentLS, numChsCut);
1178       _cOccupancyCutvsBX_Subdet.fill(HcalDetId(rawidValid), bx, numChsCut);
1179     }
1180   }
1181   numChs = 0;
1182   numChsCut = 0;
1183 
1184   //    reset
1185   rawidValid = 0;
1186 
1187   //    HF collection
1188   if (_qie10InConditions) {
1189     for (QIE10DigiCollection::const_iterator it = c_QIE10->begin(); it != c_QIE10->end(); ++it) {
1190       const QIE10DataFrame digi = static_cast<const QIE10DataFrame>(*it);
1191 
1192       //    Explicit check on the DetIds present in the Collection
1193       HcalDetId const& did = digi.detid();
1194       if (did.subdet() != HcalForward) {
1195         // LED monitoring from calibration channels
1196         if (_ptype != fLocal) {
1197           if (did.subdet() == HcalOther) {
1198             HcalOtherDetId hodid(digi.detid());
1199             if (hodid.subdet() == HcalCalibration) {
1200               if (std::find(_ledCalibrationChannels[HcalForward].begin(),
1201                             _ledCalibrationChannels[HcalForward].end(),
1202                             did) != _ledCalibrationChannels[HcalForward].end()) {
1203                 bool channelLEDSignalPresent = false;
1204                 for (int i = 0; i < digi.samples(); i++) {
1205                   _LED_ADCvsBX_Subdet.fill(HcalDetId(HcalForward, 29, 1, 1), bx, digi[i].adc());
1206 
1207                   if (digi[i].adc() > _thresh_led) {
1208                     channelLEDSignalPresent = true;
1209                   }
1210                 }
1211                 if (channelLEDSignalPresent) {
1212                   _LED_CUCountvsLS_Subdet.fill(HcalDetId(HcalForward, 29, 1, 1), _currentLS);
1213                   if (_ptype == fOnline) {
1214                     _LED_CUCountvsLSmod60_Subdet.fill(HcalDetId(HcalForward, 29, 1, 1), _currentLS % 60);
1215                   }
1216                 }
1217               }
1218             }
1219           }
1220         }
1221         continue;
1222       }
1223 
1224       uint32_t rawid = _ehashmap.lookup(did);
1225       if (rawid == 0) {
1226         meUnknownIds1LS->Fill(1);
1227         _unknownIdsPresent = true;
1228         continue;
1229       } else {
1230         rawidValid = did.rawId();
1231       }
1232       HcalElectronicsId const& eid(rawid);
1233 
1234       //    filter out channels that are masked out
1235       if (_xQuality.exists(did)) {
1236         HcalChannelStatus cs(did.rawId(), _xQuality.get(did));
1237         if (cs.isBitSet(HcalChannelStatus::HcalCellMask) || cs.isBitSet(HcalChannelStatus::HcalCellDead))
1238           continue;
1239       }
1240 
1241       // (capid - BX) % 4
1242       if (_ptype == fOnline) {
1243         short soi = -1;
1244         for (int i = 0; i < digi.samples(); i++) {
1245           if (digi[i].soi()) {
1246             soi = i;
1247             break;
1248           }
1249         }
1250         short this_capidmbx = (digi[soi].capid() - bx) % 4;
1251         if (this_capidmbx < 0) {
1252           this_capidmbx += 4;
1253         }
1254         _cCapidMinusBXmod4_SubdetPM.fill(did, this_capidmbx);
1255         bool good_capidmbx = (_capidmbx[did.subdet()] == this_capidmbx);
1256         if (!good_capidmbx) {
1257           _xBadCapid.get(eid)++;
1258           _cCapid_BadvsFEDvsLS.fill(eid, _currentLS);
1259           _cCapid_BadvsFEDvsLSmod60.fill(eid, _currentLS % 60);
1260         }
1261         if (!eid.isVMEid()) {
1262           _cCapidMinusBXmod4_CrateSlotuTCA[this_capidmbx].fill(eid);
1263         }
1264       }
1265 
1266       CaloSamples digi_fC = hcaldqm::utilities::loadADC2fCDB<QIE10DataFrame>(_dbService, did, digi);
1267       double sumQ = hcaldqm::utilities::sumQDB<QIE10DataFrame>(_dbService, digi_fC, did, digi, 0, digi.samples() - 1);
1268       //double sumQ = hcaldqm::utilities::sumQ_v10<QIE10DataFrame>(digi, 2.5, 0, digi.samples()-1);
1269 
1270       //if (!_filter_QIE1011.filter(did)) {
1271       _cSumQ_SubdetPM_QIE1011.fill(did, sumQ);
1272       //}
1273 
1274       _cOccupancy_depth.fill(did);
1275       if (_ptype == fOnline) {
1276         _xNChs.get(eid)++;
1277         _cDigiSizevsLS_FED.fill(eid, _currentLS, digi.samples());
1278         digi.samples() != _refDigiSize[did.subdet()] ? _xDigiSize.get(eid)++ : _xDigiSize.get(eid) += 0;
1279         _cOccupancyvsiphi_SubdetPM.fill(did);
1280         _cOccupancyvsieta_Subdet.fill(did);
1281       }
1282       _cDigiSize_Crate.fill(eid, digi.samples());
1283       if (_ptype != fOffline) {  // hidefed2crate
1284         _cDigiSize_FED.fill(eid, digi.samples());
1285         if (!eid.isVMEid()) {
1286           _cOccupancy_FEDuTCA.fill(eid);
1287           _cOccupancy_ElectronicsuTCA.fill(eid);
1288           /*
1289                 if (!it->validate(0, it->size()))
1290                     _cCapIdRots_FEDuTCA.fill(eid, 1);*/
1291         }
1292       }
1293 
1294       for (int i = 0; i < digi.samples(); i++) {
1295         double q = hcaldqm::utilities::adc2fCDBMinusPedestal<QIE10DataFrame>(_dbService, digi_fC, did, digi, i);
1296         //if (!_filter_QIE1011.filter(did)) {
1297         _cADC_SubdetPM_QIE1011.fill(did, digi[i].adc());
1298         _cfC_SubdetPM_QIE1011.fill(did, q);
1299         _cLETDCvsADC_6bit_SubdetPM.fill(did, digi[i].adc(), digi[i].le_tdc());
1300         _cLETDCvsTS_6bit_SubdetPM.fill(did, (int)i, digi[i].le_tdc());
1301         if (digi[i].le_tdc() < 50) {
1302           double time = i * 25. + (digi[i].le_tdc() / 2.);
1303           _cLETDCTime_SubdetPM.fill(did, time);
1304           _cLETDCTime_depth.fill(did, time);
1305           _cLETDCTimevsADC_SubdetPM.fill(did, digi[i].adc(), time);
1306         }
1307 
1308         // Bad TDC values: 50-61 should never happen in QIE10 or QIE11, but we are seeing some in 2017 data.
1309         if ((50 <= digi[i].le_tdc()) && (digi[i].le_tdc() <= 61)) {
1310           _cBadTDCValues_SubdetPM.fill(did, digi[i].le_tdc());
1311           _cBadTDCvsBX_SubdetPM.fill(did, bx);
1312           _cBadTDCvsLS_SubdetPM.fill(did, _currentLS);
1313           _cBadTDCCount_depth.fill(did);
1314         }
1315         if (_ptype != fOffline) {  // hidefed2crate
1316           _cADCvsTS_SubdetPM_QIE1011.fill(did, (int)i, digi[i].adc());
1317           if (sumQ > _cutSumQ_HF)
1318             _cShapeCut_FED.fill(eid, (int)i, q);
1319         }
1320         //}
1321       }
1322 
1323       if (sumQ > _cutSumQ_HF) {
1324         double timing = hcaldqm::utilities::aveTS_v10<QIE10DataFrame>(digi, 2.5, 0, digi.samples() - 1);
1325         double q1 = hcaldqm::utilities::adc2fCDBMinusPedestal<QIE10DataFrame>(_dbService, digi_fC, did, digi, 1);
1326         double q2 = hcaldqm::utilities::adc2fCDBMinusPedestal<QIE10DataFrame>(_dbService, digi_fC, did, digi, 2);
1327         double q2q12 = q2 / (q1 + q2);
1328         _cSumQ_depth.fill(did, sumQ);
1329         //if (!_filter_QIE1011.filter(did)) {
1330         _cSumQvsLS_SubdetPM_QIE1011.fill(did, _currentLS, sumQ);
1331         //}
1332         _cTimingCut_SubdetPM.fill(did, hcaldqm::utilities::aveTS_v10<QIE10DataFrame>(digi, 0., 0, digi.samples() - 1));
1333         if (sumQ > 100. * _cutSumQ_HF)
1334           _cTimingCutHTH_SubdetPM.fill(did, timing);
1335         _cTimingCut_depth.fill(did, timing);
1336         _cTimingCutvsLS_SubdetPM.fill(did, _currentLS, timing);
1337         if (_ptype == fOnline) {
1338           //if (!_filter_QIE1011.filter(did)) {
1339           _cSumQvsBX_SubdetPM_QIE1011.fill(did, bx, sumQ);
1340           //}
1341           _cTimingCutvsiphi_SubdetPM.fill(did, timing);
1342           _cTimingCutvsieta_Subdet.fill(did, timing);
1343           _cOccupancyCutvsiphi_SubdetPM.fill(did);
1344           _cOccupancyCutvsieta_Subdet.fill(did);
1345           _cOccupancyCutvsiphivsLS_SubdetPM.fill(did, _currentLS);
1346           //                _cOccupancyCutvsSlotvsLS_HFPM.fill(did, _currentLS);
1347           _xUniHF.get(eid)++;
1348         }
1349         if (_ptype != fOffline) {  // hidefed2crate
1350           _cTimingCutvsLS_FED.fill(eid, _currentLS, timing);
1351         }
1352         _cOccupancyCut_depth.fill(did);
1353         if (!eid.isVMEid())
1354           if (_ptype == fOnline)
1355             _cQ2Q12CutvsLS_FEDHF.fill(eid, _currentLS, q2q12);
1356         if (_ptype != fOffline) {  // hidefed2crate
1357           if (!eid.isVMEid()) {
1358             _cTimingCut_FEDuTCA.fill(eid, timing);
1359             _cTimingCut_ElectronicsuTCA.fill(eid, timing);
1360             _cOccupancyCut_FEDuTCA.fill(eid);
1361             _cOccupancyCut_ElectronicsuTCA.fill(eid);
1362           }
1363         }
1364         numChsCut++;
1365       }
1366       numChs++;
1367     }
1368   }
1369 
1370   if (rawidValid != 0) {
1371     _cOccupancyvsLS_Subdet.fill(HcalDetId(rawidValid), _currentLS, numChs);
1372 
1373     if (_ptype == fOnline) {
1374       _cOccupancyCutvsLS_Subdet.fill(HcalDetId(rawidValid), _currentLS, numChsCut);
1375       _cOccupancyCutvsBX_Subdet.fill(HcalDetId(rawidValid), bx, numChsCut);
1376     }
1377   }
1378 }
1379 
1380 std::shared_ptr<hcaldqm::Cache> DigiTask::globalBeginLuminosityBlock(edm::LuminosityBlock const& lb,
1381                                                                      edm::EventSetup const& es) const {
1382   return DQTask::globalBeginLuminosityBlock(lb, es);
1383 }
1384 
1385 /* virtual */ void DigiTask::globalEndLuminosityBlock(edm::LuminosityBlock const& lb, edm::EventSetup const& es) {
1386   auto lumiCache = luminosityBlockCache(lb.index());
1387   _currentLS = lumiCache->currentLS;
1388   _evsPerLS = lumiCache->EvtCntLS;
1389 
1390   if (_ptype != fOnline)
1391     return;
1392 
1393   for (uintCompactMap::const_iterator it = _xUniHF.begin(); it != _xUniHF.end(); ++it) {
1394     uint32_t hash1 = it->first;
1395     HcalElectronicsId eid1(hash1);
1396     double x1 = it->second;
1397 
1398     for (uintCompactMap::const_iterator jt = _xUniHF.begin(); jt != _xUniHF.end(); ++jt) {
1399       if (jt == it)
1400         continue;
1401       double x2 = jt->second;
1402       if (x2 == 0)
1403         continue;
1404       if (x1 / x2 < _thresh_unihf)
1405         _xUni.get(eid1)++;
1406     }
1407   }
1408 
1409   if (_ptype != fOffline) {  // hidefed2crate
1410     for (std::vector<uint32_t>::const_iterator it = _vhashFEDs.begin(); it != _vhashFEDs.end(); ++it) {
1411       hcaldqm::flag::Flag fSum("DIGI");
1412       HcalElectronicsId eid = HcalElectronicsId(*it);
1413 
1414       std::vector<uint32_t>::const_iterator cit = std::find(_vcdaqEids.begin(), _vcdaqEids.end(), *it);
1415       if (cit == _vcdaqEids.end()) {
1416         //  not @cDAQ
1417         for (uint32_t iflag = 0; iflag < _vflags.size(); iflag++)
1418           _cSummaryvsLS_FED.setBinContent(eid, _currentLS, int(iflag), int(hcaldqm::flag::fNCDAQ));
1419         _cSummaryvsLS.setBinContent(eid, _currentLS, int(hcaldqm::flag::fNCDAQ));
1420         continue;
1421       }
1422 
1423       //    FED is @cDAQ
1424       if (hcaldqm::utilities::isFEDHBHE(eid) || hcaldqm::utilities::isFEDHF(eid) || hcaldqm::utilities::isFEDHO(eid)) {
1425         if (_xDigiSize.get(eid) > 0)
1426           _vflags[fDigiSize]._state = hcaldqm::flag::fBAD;
1427         else
1428           _vflags[fDigiSize]._state = hcaldqm::flag::fGOOD;
1429 
1430         if (_xBadCapid.get(eid) > 0) {
1431           _vflags[fCapId]._state = hcaldqm::flag::fBAD;
1432         } else {
1433           _vflags[fCapId]._state = hcaldqm::flag::fGOOD;
1434         }
1435 
1436         if (hcaldqm::utilities::isFEDHF(eid)) {
1437           double fr = double(_xNChs.get(eid)) / double(_xNChsNominal.get(eid) * _evsPerLS);
1438           if (_runkeyVal == 0 || _runkeyVal == 4) {
1439             //  only for pp or hi
1440             if (_xUni.get(eid) > 0)
1441               _vflags[fUni]._state = hcaldqm::flag::fPROBLEMATIC;
1442             else
1443               _vflags[fUni]._state = hcaldqm::flag::fGOOD;
1444           }
1445           if (fr < 0.95)
1446             _vflags[fNChsHF]._state = hcaldqm::flag::fBAD;
1447           else if (fr < 1.0)
1448             _vflags[fNChsHF]._state = hcaldqm::flag::fPROBLEMATIC;
1449           else
1450             _vflags[fNChsHF]._state = hcaldqm::flag::fGOOD;
1451         }
1452       }
1453       if (_unknownIdsPresent)
1454         _vflags[fUnknownIds]._state = hcaldqm::flag::fBAD;
1455       else
1456         _vflags[fUnknownIds]._state = hcaldqm::flag::fGOOD;
1457 
1458       // LED misfires
1459       if (_ptype != fLocal) {
1460         if (hcaldqm::utilities::isFEDHBHE(eid)) {
1461           HcalDetId did_hb(hcaldqm::hashfunctions::hash_Subdet(HcalDetId(HcalBarrel, 1, 1, 1)));
1462           HcalDetId did_he(hcaldqm::hashfunctions::hash_Subdet(HcalDetId(HcalEndcap, 16, 1, 1)));
1463 
1464           if (_LED_CUCountvsLS_Subdet.getBinContent(did_hb, _currentLS) > 0 ||
1465               _LED_CUCountvsLS_Subdet.getBinContent(did_he, _currentLS) > 0) {
1466             _vflags[fLED]._state = hcaldqm::flag::fBAD;
1467           } else {
1468             _vflags[fLED]._state = hcaldqm::flag::fGOOD;
1469           }
1470         } else if (hcaldqm::utilities::isFEDHF(eid)) {
1471           HcalDetId did_hf(hcaldqm::hashfunctions::hash_Subdet(HcalDetId(HcalForward, 29, 1, 1)));
1472           if (_LED_CUCountvsLS_Subdet.getBinContent(did_hf, _currentLS) > 0) {
1473             _vflags[fLED]._state = hcaldqm::flag::fBAD;
1474           } else {
1475             _vflags[fLED]._state = hcaldqm::flag::fGOOD;
1476           }
1477         } else if (hcaldqm::utilities::isFEDHO(eid)) {
1478           HcalDetId did_ho(hcaldqm::hashfunctions::hash_Subdet(HcalDetId(HcalOuter, 1, 1, 1)));
1479           if (_LED_CUCountvsLS_Subdet.getBinContent(did_ho, _currentLS) > 0) {
1480             _vflags[fLED]._state = hcaldqm::flag::fBAD;
1481           } else {
1482             _vflags[fLED]._state = hcaldqm::flag::fGOOD;
1483           }
1484         }
1485       }
1486 
1487       int iflag = 0;
1488       for (std::vector<hcaldqm::flag::Flag>::iterator ft = _vflags.begin(); ft != _vflags.end(); ++ft) {
1489         _cSummaryvsLS_FED.setBinContent(eid, _currentLS, iflag, int(ft->_state));
1490         fSum += (*ft);
1491         iflag++;
1492 
1493         //  reset!
1494         ft->reset();
1495       }
1496       _cSummaryvsLS.setBinContent(eid, _currentLS, fSum._state);
1497     }
1498   }
1499 
1500   _xDigiSize.reset();
1501   _xUniHF.reset();
1502   _xUni.reset();
1503   _xNChs.reset();
1504   _xBadCapid.reset();
1505 
1506   //    in the end always do the DQTask::endLumi
1507   DQTask::globalEndLuminosityBlock(lb, es);
1508 }
1509 
1510 DEFINE_FWK_MODULE(DigiTask);