Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-27 23:05:58

0001 #include "DQM/HcalTasks/interface/DigiRunSummary.h"
0002 
0003 namespace hcaldqm {
0004   using namespace constants;
0005 
0006   DigiRunSummary::DigiRunSummary(std::string const& name,
0007                                  std::string const& taskname,
0008                                  edm::ParameterSet const& ps,
0009                                  edm::ConsumesCollector& iC)
0010       : DQClient(name, taskname, ps, iC), _booked(false) {
0011     _thresh_unihf = ps.getUntrackedParameter<double>("thresh_unihf", 0.2);
0012 
0013     std::vector<uint32_t> vrefDigiSize = ps.getUntrackedParameter<std::vector<uint32_t>>("refDigiSize");
0014     _refDigiSize[HcalBarrel] = vrefDigiSize[0];
0015     _refDigiSize[HcalEndcap] = vrefDigiSize[1];
0016     _refDigiSize[HcalOuter] = vrefDigiSize[2];
0017     _refDigiSize[HcalForward] = vrefDigiSize[3];
0018   }
0019 
0020   /* virtual */ void DigiRunSummary::beginRun(edm::Run const& r, edm::EventSetup const& es) {
0021     DQClient::beginRun(r, es);
0022 
0023     if (_ptype != fOffline)
0024       return;
0025 
0026     //  INITIALIZE WHAT NEEDS TO BE INITIALIZE ONLY ONCE!
0027     _ehashmap.initialize(_emap, electronicsmap::fD2EHashMap);
0028     _vhashVME.push_back(
0029         HcalElectronicsId(constants::FIBERCH_MIN, constants::FIBER_VME_MIN, SPIGOT_MIN, CRATE_VME_MIN).rawId());
0030     _vhashuTCA.push_back(HcalElectronicsId(CRATE_uTCA_MIN, SLOT_uTCA_MIN, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0031     _filter_VME.initialize(filter::fFilter, hashfunctions::fElectronics,
0032                            _vhashVME);  // filter out VME
0033     _filter_uTCA.initialize(filter::fFilter, hashfunctions::fElectronics,
0034                             _vhashuTCA);  // filter out uTCA
0035     _vhashFEDHF.push_back(HcalElectronicsId(22, SLOT_uTCA_MIN, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0036     _vhashFEDHF.push_back(HcalElectronicsId(29, SLOT_uTCA_MIN, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0037     _vhashFEDHF.push_back(HcalElectronicsId(32, SLOT_uTCA_MIN, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0038     _vhashFEDHF.push_back(HcalElectronicsId(22, SLOT_uTCA_MIN + 6, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0039     _vhashFEDHF.push_back(HcalElectronicsId(29, SLOT_uTCA_MIN + 6, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0040     _vhashFEDHF.push_back(HcalElectronicsId(32, SLOT_uTCA_MIN + 6, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0041     _filter_FEDHF.initialize(filter::fPreserver, hashfunctions::fFED,
0042                              _vhashFEDHF);  // preserve only HF FEDs
0043 
0044     _xDead.initialize(hashfunctions::fFED);
0045     _xDigiSize.initialize(hashfunctions::fFED);
0046     _xUni.initialize(hashfunctions::fFED);
0047     _xUniHF.initialize(hashfunctions::fFEDSlot);
0048 
0049     _xDead.book(_emap);
0050     _xDigiSize.book(_emap);
0051     _xUniHF.book(_emap);
0052     _xUni.book(_emap, _filter_FEDHF);
0053     _xNChs.initialize(hashfunctions::fFED);
0054     _xNChsNominal.initialize(hashfunctions::fFED);
0055     _xNChs.book(_emap);
0056     _xNChsNominal.book(_emap);
0057 
0058     _cOccupancy_depth.initialize(_name,
0059                                  "Occupancy",
0060                                  hashfunctions::fdepth,
0061                                  new quantity::DetectorQuantity(quantity::fieta),
0062                                  new quantity::DetectorQuantity(quantity::fiphi),
0063                                  new quantity::ValueQuantity(quantity::fN),
0064                                  0);
0065 
0066     //  GET THE NOMINAL NUMBER OF CHANNELS PER FED
0067     std::vector<HcalGenericDetId> gids = _emap->allPrecisionId();
0068     for (std::vector<HcalGenericDetId>::const_iterator it = gids.begin(); it != gids.end(); ++it) {
0069       if (!it->isHcalDetId())
0070         continue;
0071       HcalDetId did(it->rawId());
0072       HcalElectronicsId eid = HcalElectronicsId(_ehashmap.lookup(did));
0073       _xNChsNominal.get(eid)++;
0074     }
0075   }
0076 
0077   /*
0078      *  END LUMI. EVALUATE LUMI BASED FLAGS
0079      */
0080   /* virtual */ void DigiRunSummary::endLuminosityBlock(DQMStore::IBooker& ib,
0081                                                         DQMStore::IGetter& ig,
0082                                                         edm::LuminosityBlock const& lb,
0083                                                         edm::EventSetup const& es) {
0084     DQClient::endLuminosityBlock(ib, ig, lb, es);
0085 
0086     if (_ptype != fOffline)
0087       return;
0088 
0089     LSSummary lssum;
0090     lssum._LS = _currentLS;
0091 
0092     _xDigiSize.reset();
0093     _xNChs.reset();
0094 
0095     //  INITIALIZE LUMI BASED HISTOGRAMS
0096     Container2D cDigiSize_Crate, cOccupancy_depth;
0097     cDigiSize_Crate.initialize(_taskname,
0098                                "DigiSize",
0099                                hashfunctions::fCrate,
0100                                new quantity::ValueQuantity(quantity::fDigiSize),
0101                                new quantity::ValueQuantity(quantity::fN),
0102                                0);
0103     cOccupancy_depth.initialize(_taskname,
0104                                 "Occupancy",
0105                                 hashfunctions::fdepth,
0106                                 new quantity::DetectorQuantity(quantity::fieta),
0107                                 new quantity::DetectorQuantity(quantity::fiphi),
0108                                 new quantity::ValueQuantity(quantity::fN),
0109                                 0);
0110 
0111     //  LOAD LUMI BASED HISTOGRAMS
0112     cOccupancy_depth.load(ig, _emap, _subsystem);
0113     cDigiSize_Crate.load(ig, _emap, _subsystem);
0114     MonitorElement* meNumEvents = ig.get(_subsystem + "/RunInfo/NumberOfEvents");
0115     int numEvents = meNumEvents->getBinContent(1);
0116     bool unknownIdsPresent = ig.get(_subsystem + "/" + _taskname + "/UnknownIds")->getBinContent(1) > 0;
0117 
0118     //  book the Numer of Events - set axis extendable
0119     if (!_booked) {
0120       ib.setCurrentFolder(_subsystem + "/" + _taskname);
0121       _meNumEvents = ib.book1DD("NumberOfEvents", "NumberOfEvents", 1000, 1, 1001);  // 1000 to start with
0122       _meNumEvents->getTH1()->SetCanExtend(TH1::kXaxis);
0123 
0124       _cOccupancy_depth.book(ib, _emap, _subsystem);
0125       _booked = true;
0126     }
0127     _meNumEvents->setBinContent(_currentLS, numEvents);
0128 
0129     //  ANALYZE THIS LS for LS BASED FLAGS
0130     std::vector<HcalGenericDetId> gids = _emap->allPrecisionId();
0131     for (std::vector<HcalGenericDetId>::const_iterator it = gids.begin(); it != gids.end(); ++it) {
0132       if (!it->isHcalDetId())
0133         continue;
0134 
0135       HcalDetId did = HcalDetId(it->rawId());
0136       HcalElectronicsId eid = HcalElectronicsId(_ehashmap.lookup(did));
0137 
0138       cOccupancy_depth.getBinContent(did) > 0 ? _xNChs.get(eid)++ : _xNChs.get(eid) += 0;
0139       _cOccupancy_depth.fill(did, cOccupancy_depth.getBinContent(did));
0140       //    digi size
0141       cDigiSize_Crate.getMean(eid) != _refDigiSize[did.subdet()] ? _xDigiSize.get(eid)++ : _xDigiSize.get(eid) += 0;
0142       cDigiSize_Crate.getRMS(eid) != 0 ? _xDigiSize.get(eid)++ : _xDigiSize.get(eid) += 0;
0143     }
0144 
0145     //  GENERATE SUMMARY AND STORE IT
0146     std::vector<flag::Flag> vtmpflags;
0147     vtmpflags.resize(nLSFlags);
0148     vtmpflags[fDigiSize] = flag::Flag("DigiSize");
0149     vtmpflags[fNChsHF] = flag::Flag("NChsHF");
0150     vtmpflags[fUnknownIds] = flag::Flag("UnknownIds");
0151     vtmpflags[fLED] = flag::Flag("LEDMisfire");
0152     for (std::vector<uint32_t>::const_iterator it = _vhashCrates.begin(); it != _vhashCrates.end(); ++it) {
0153       HcalElectronicsId eid(*it);
0154       HcalDetId did = HcalDetId(_emap->lookup(eid));
0155 
0156       //    reset all the tmp flags to fNA
0157       //    MUST DO IT NOW! AS NCDAQ MIGHT OVERWRITE IT!
0158       for (std::vector<flag::Flag>::iterator ft = vtmpflags.begin(); ft != vtmpflags.end(); ++ft)
0159         ft->reset();
0160 
0161       if (_xDigiSize.get(eid) > 0)
0162         vtmpflags[fDigiSize]._state = flag::fBAD;
0163       else
0164         vtmpflags[fDigiSize]._state = flag::fGOOD;
0165 
0166       if (did.subdet() == HcalForward) {
0167         if (_xNChs.get(eid) != _xNChsNominal.get(eid))
0168           vtmpflags[fNChsHF]._state = flag::fBAD;
0169         else
0170           vtmpflags[fNChsHF]._state = flag::fGOOD;
0171       } else {
0172         vtmpflags[fNChsHF]._state = flag::fNA;
0173       }
0174       if (unknownIdsPresent)
0175         vtmpflags[fUnknownIds]._state = flag::fBAD;
0176       else
0177         vtmpflags[fUnknownIds]._state = flag::fGOOD;
0178 
0179       if ((did.subdet() == HcalBarrel) || (did.subdet() == HcalBarrel) || (did.subdet() == HcalBarrel) ||
0180           (did.subdet() == HcalBarrel)) {
0181         std::string ledHistName = _subsystem + "/" + _taskname + "/LED_CUCountvsLS/Subdet/";
0182         if (did.subdet() == HcalBarrel) {
0183           ledHistName += "HB";
0184         } else if (did.subdet() == HcalEndcap) {
0185           ledHistName += "HE";
0186         } else if (did.subdet() == HcalOuter) {
0187           ledHistName += "HO";
0188         } else if (did.subdet() == HcalForward) {
0189           ledHistName += "HF";
0190         }
0191         MonitorElement* ledHist = ig.get(ledHistName);
0192         if (ledHist) {
0193           bool ledSignalPresent = (ledHist->getEntries() > 0);
0194           if (ledSignalPresent)
0195             vtmpflags[fLED]._state = flag::fBAD;
0196           else
0197             vtmpflags[fLED]._state = flag::fGOOD;
0198         } else {
0199           vtmpflags[fLED]._state = flag::fNA;
0200         }
0201       } else {
0202         vtmpflags[fLED]._state = flag::fNA;
0203       }
0204 
0205       // push all the flags for this crate
0206       lssum._vflags.push_back(vtmpflags);
0207     }
0208 
0209     //  push all the flags for all FEDs for this LS
0210     _vflagsLS.push_back(lssum);
0211     cDigiSize_Crate.reset();
0212     cOccupancy_depth.reset();
0213   }
0214 
0215   /*
0216      *  End Job
0217      */
0218   /* virtual */ std::vector<flag::Flag> DigiRunSummary::endJob(DQMStore::IBooker& ib, DQMStore::IGetter& ig) {
0219     if (_ptype != fOffline)
0220       return std::vector<flag::Flag>();
0221 
0222     _xDead.reset();
0223     _xUniHF.reset();
0224     _xUni.reset();
0225 
0226     //  PREPARE LS AND RUN BASED FLAGS TO USE IT FOR BOOKING
0227     std::vector<flag::Flag> vflagsPerLS;
0228     std::vector<flag::Flag> vflagsPerRun;
0229     vflagsPerLS.resize(nLSFlags);
0230     vflagsPerRun.resize(nDigiFlag - nLSFlags + 1);
0231     vflagsPerLS[fDigiSize] = flag::Flag("DigiSize");
0232     vflagsPerLS[fNChsHF] = flag::Flag("NChsHF");
0233     vflagsPerLS[fUnknownIds] = flag::Flag("UnknownIds");
0234     vflagsPerLS[fLED] = flag::Flag("LEDMisfire");
0235     vflagsPerRun[fDigiSize] = flag::Flag("DigiSize");
0236     vflagsPerRun[fNChsHF] = flag::Flag("NChsHF");
0237     vflagsPerRun[fUniHF - nLSFlags + 1] = flag::Flag("UniSlotHF");
0238     vflagsPerRun[fDead - nLSFlags + 1] = flag::Flag("Dead");
0239 
0240     //  INITIALIZE SUMMARY CONTAINERS
0241     ContainerSingle2D cSummaryvsLS;
0242     Container2D cSummaryvsLS_Crate;
0243     cSummaryvsLS.initialize(_name,
0244                             "SummaryvsLS",
0245                             new quantity::LumiSection(_maxProcessedLS),
0246                             new quantity::CrateQuantity(_emap),
0247                             new quantity::ValueQuantity(quantity::fState),
0248                             0);
0249     cSummaryvsLS.book(ib, _subsystem);
0250     cSummaryvsLS_Crate.initialize(_name,
0251                                   "SummaryvsLS",
0252                                   hashfunctions::fCrate,
0253                                   new quantity::LumiSection(_maxProcessedLS),
0254                                   new quantity::FlagQuantity(vflagsPerLS),
0255                                   new quantity::ValueQuantity(quantity::fState),
0256                                   0);
0257     cSummaryvsLS_Crate.book(ib, _emap, _subsystem);
0258 
0259     // INITIALIZE CONTAINERS WE NEED TO LOAD or BOOK
0260     Container2D cOccupancyCut_depth;
0261     Container2D cDead_depth, cDead_Crate;
0262     cOccupancyCut_depth.initialize(_taskname,
0263                                    "OccupancyCut",
0264                                    hashfunctions::fdepth,
0265                                    new quantity::DetectorQuantity(quantity::fieta),
0266                                    new quantity::DetectorQuantity(quantity::fiphi),
0267                                    new quantity::ValueQuantity(quantity::fN),
0268                                    0);
0269     cDead_depth.initialize(_name,
0270                            "Dead",
0271                            hashfunctions::fdepth,
0272                            new quantity::DetectorQuantity(quantity::fieta),
0273                            new quantity::DetectorQuantity(quantity::fiphi),
0274                            new quantity::ValueQuantity(quantity::fN),
0275                            0);
0276     cDead_Crate.initialize(_name,
0277                            "Dead",
0278                            hashfunctions::fCrate,
0279                            new quantity::ElectronicsQuantity(quantity::fSpigot),
0280                            new quantity::ElectronicsQuantity(quantity::fFiberVMEFiberCh),
0281                            new quantity::ValueQuantity(quantity::fN),
0282                            0);
0283 
0284     //  LOAD
0285     cOccupancyCut_depth.load(ig, _emap, _subsystem);
0286     cDead_depth.book(ib, _emap, _subsystem);
0287     cDead_Crate.book(ib, _emap, _subsystem);
0288 
0289     //  ANALYZE RUN BASED QUANTITIES
0290     std::vector<HcalGenericDetId> gids = _emap->allPrecisionId();
0291     for (std::vector<HcalGenericDetId>::const_iterator it = gids.begin(); it != gids.end(); ++it) {
0292       if (!it->isHcalDetId())
0293         continue;
0294 
0295       HcalDetId did = HcalDetId(it->rawId());
0296       HcalElectronicsId eid = HcalElectronicsId(_ehashmap.lookup(did));
0297 
0298       if (_cOccupancy_depth.getBinContent(did) < 1) {
0299         _xDead.get(eid)++;
0300         cDead_depth.fill(did);
0301         cDead_Crate.fill(eid);
0302       }
0303       if (did.subdet() == HcalForward)
0304         _xUniHF.get(eid) += cOccupancyCut_depth.getBinContent(did);
0305     }
0306     //  ANALYZE FOR HF SLOT UNIFORMITY
0307     for (uintCompactMap::const_iterator it = _xUniHF.begin(); it != _xUniHF.end(); ++it) {
0308       uint32_t hash1 = it->first;
0309       HcalElectronicsId eid1(hash1);
0310       double x1 = it->second;
0311 
0312       for (uintCompactMap::const_iterator jt = _xUniHF.begin(); jt != _xUniHF.end(); ++jt) {
0313         if (jt == it)
0314           continue;
0315 
0316         double x2 = jt->second;
0317         if (x2 == 0)
0318           continue;
0319         if (x1 / x2 < _thresh_unihf)
0320           _xUni.get(eid1)++;
0321       }
0322     }
0323 
0324     /*
0325          *  Iterate over each crate
0326          *      Iterate over each LS Summary
0327          *          Iterate over all flags
0328          *              set...
0329          */
0330     //  iterate over all crates
0331     std::vector<flag::Flag> sumflags;
0332     int icrate = 0;
0333     for (auto& it_crate : _vhashCrates) {
0334       flag::Flag fSumRun("DIGI");  // summary flag for this FED
0335       flag::Flag ffDead("Dead");
0336       flag::Flag ffUniSlotHF("UniSlotHF");
0337       HcalElectronicsId eid(it_crate);
0338       HcalDetId did = HcalDetId(_emap->lookup(eid));
0339 
0340       //    ITERATE OVER EACH LS
0341       for (std::vector<LSSummary>::const_iterator itls = _vflagsLS.begin(); itls != _vflagsLS.end(); ++itls) {
0342         int iflag = 0;
0343         flag::Flag fSumLS("DIGI");
0344         for (std::vector<flag::Flag>::const_iterator ft = itls->_vflags[icrate].begin();
0345              ft != itls->_vflags[icrate].end();
0346              ++ft) {
0347           cSummaryvsLS_Crate.setBinContent(eid, itls->_LS, int(iflag), ft->_state);
0348           fSumLS += (*ft);
0349           iflag++;
0350         }
0351         cSummaryvsLS.setBinContent(eid, itls->_LS, fSumLS._state);
0352         fSumRun += fSumLS;
0353       }
0354 
0355       //    EVALUATE RUN BASED FLAGS
0356       if (_xDead.get(eid) > 0)
0357         ffDead._state = flag::fBAD;
0358       else
0359         ffDead._state = flag::fGOOD;
0360       if (did.subdet() == HcalForward) {
0361         if (_xUni.get(eid) > 0)
0362           ffUniSlotHF._state = flag::fBAD;
0363         else
0364           ffUniSlotHF._state = flag::fGOOD;
0365       }
0366       fSumRun += ffDead + ffUniSlotHF;
0367 
0368       // push the summary flag for this FED for the Whole Run
0369       sumflags.push_back(fSumRun);
0370 
0371       //     increment fed
0372       icrate++;
0373     }
0374 
0375     return sumflags;
0376   }
0377 }  // namespace hcaldqm