Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/HcalTasks/interface/RawRunSummary.h"
0002 
0003 namespace hcaldqm {
0004   using namespace constants;
0005   RawRunSummary::RawRunSummary(std::string const& name,
0006                                std::string const& taskname,
0007                                edm::ParameterSet const& ps,
0008                                edm::ConsumesCollector& iC)
0009       : DQClient(name, taskname, ps, iC), _booked(false) {}
0010 
0011   /* virtual */ void RawRunSummary::beginRun(edm::Run const& r, edm::EventSetup const& es) {
0012     DQClient::beginRun(r, es);
0013 
0014     if (_ptype != fOffline)
0015       return;
0016 
0017     //  INITIALIZE WHAT NEEDS TO BE INITIALIZE ONLY ONCE!
0018     _ehashmap.initialize(_emap, electronicsmap::fD2EHashMap);
0019     _vhashVME.push_back(
0020         HcalElectronicsId(constants::FIBERCH_MIN, constants::FIBER_VME_MIN, SPIGOT_MIN, CRATE_VME_MIN).rawId());
0021     _vhashuTCA.push_back(HcalElectronicsId(CRATE_uTCA_MIN, SLOT_uTCA_MIN, FIBER_uTCA_MIN1, FIBERCH_MIN, false).rawId());
0022     _filter_VME.initialize(filter::fFilter, hashfunctions::fElectronics,
0023                            _vhashVME);  // filter out VME
0024     _filter_uTCA.initialize(filter::fFilter, hashfunctions::fElectronics,
0025                             _vhashuTCA);  // filter out uTCA
0026 
0027     //  INTIALIZE CONTAINERS ACTING AS HOLDERS OF RUN INFORAMTION
0028     _cEvnMsm_ElectronicsuTCA.initialize(_name,
0029                                         "EvnMsm",
0030                                         hashfunctions::fElectronics,
0031                                         new quantity::FEDQuantity(_vFEDsuTCA),
0032                                         new quantity::ElectronicsQuantity(quantity::fSlotuTCA),
0033                                         new quantity::ValueQuantity(quantity::fN),
0034                                         0);
0035     _cBcnMsm_ElectronicsuTCA.initialize(_name,
0036                                         "BcnMsm",
0037                                         hashfunctions::fElectronics,
0038                                         new quantity::FEDQuantity(_vFEDsuTCA),
0039                                         new quantity::ElectronicsQuantity(quantity::fSlotuTCA),
0040                                         new quantity::ValueQuantity(quantity::fN),
0041                                         0);
0042     _cBadQuality_depth.initialize(_name,
0043                                   "BadQuality",
0044                                   hashfunctions::fdepth,
0045                                   new quantity::DetectorQuantity(quantity::fieta),
0046                                   new quantity::DetectorQuantity(quantity::fiphi),
0047                                   new quantity::ValueQuantity(quantity::fN),
0048                                   0);
0049 
0050     _xEvn.initialize(hashfunctions::fFED);
0051     _xBcn.initialize(hashfunctions::fFED);
0052     _xBadQ.initialize(hashfunctions::fFED);
0053     //  BOOK CONTAINERSXXX
0054     _xEvn.book(_emap);
0055     _xBcn.book(_emap);
0056     _xBadQ.book(_emap);
0057   }
0058 
0059   /*
0060      *  END OF LUMINOSITY HARVESTING 
0061      *  RAW FORMAT HAS ONLY LUMI BASED FLAGS!
0062      *  THEREFORE STEPS ARE:
0063      *  1) LOAD CONTAINERS YOU NEED (MUST BE LUMI BASED)
0064      *  2) ANALYZE 
0065      *  3) GENERATE SUMMARY FLAGS AND PUSH THEM
0066      */
0067   /* virtual */ void RawRunSummary::endLuminosityBlock(DQMStore::IBooker& ib,
0068                                                        DQMStore::IGetter& ig,
0069                                                        edm::LuminosityBlock const& lb,
0070                                                        edm::EventSetup const& es) {
0071     DQClient::endLuminosityBlock(ib, ig, lb, es);
0072 
0073     if (_ptype != fOffline)
0074       return;
0075 
0076     //  INITIALIZE WHAT YOU NEED
0077     LSSummary lssum;         // summary for this LS
0078     lssum._LS = _currentLS;  // set the LS
0079 
0080     //  RESET CONTAINERS USED FOR ANALYSIS OF THIS LS
0081     _xEvn.reset();
0082     _xBcn.reset();
0083     _xBadQ.reset();
0084 
0085     //  INITIALIZE LUMI BASED HISTOGRAMS
0086     Container2D cEvnMsm_ElectronicsuTCA;
0087     Container2D cBcnMsm_ElectronicsuTCA;
0088     Container2D cBadQuality_depth;
0089     cEvnMsm_ElectronicsuTCA.initialize(_taskname,
0090                                        "EvnMsm",
0091                                        hashfunctions::fElectronics,
0092                                        new quantity::FEDQuantity(_vFEDsuTCA),
0093                                        new quantity::ElectronicsQuantity(quantity::fSlotuTCA),
0094                                        new quantity::ValueQuantity(quantity::fN),
0095                                        0);
0096     cBcnMsm_ElectronicsuTCA.initialize(_taskname,
0097                                        "BcnMsm",
0098                                        hashfunctions::fElectronics,
0099                                        new quantity::FEDQuantity(_vFEDsuTCA),
0100                                        new quantity::ElectronicsQuantity(quantity::fSlotuTCA),
0101                                        new quantity::ValueQuantity(quantity::fN),
0102                                        0);
0103     cBadQuality_depth.initialize(_taskname,
0104                                  "BadQuality",
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     cEvnMsm_ElectronicsuTCA.load(ig, _emap, _filter_VME, _subsystem);
0113     cBcnMsm_ElectronicsuTCA.load(ig, _emap, _filter_VME, _subsystem);
0114     cBadQuality_depth.load(ig, _emap, _subsystem);
0115     MonitorElement* meNumEvents = ig.get(_subsystem + "/RunInfo/NumberOfEvents");
0116     int numEvents = meNumEvents->getBinContent(1);
0117 
0118     //  BOOK for the very first time
0119     if (!_booked) {
0120       _cEvnMsm_ElectronicsuTCA.book(ib, _emap, _filter_VME, _subsystem);
0121       _cBcnMsm_ElectronicsuTCA.book(ib, _emap, _filter_VME, _subsystem);
0122       _cBadQuality_depth.book(ib, _emap, _subsystem);
0123       _booked = true;
0124     }
0125 
0126     // ANALYZE THIS LS
0127     // iterate over all channels
0128     std::vector<HcalGenericDetId> gids = _emap->allPrecisionId();
0129     for (std::vector<HcalGenericDetId>::const_iterator it = gids.begin(); it != gids.end(); ++it) {
0130       if (!it->isHcalDetId())
0131         continue;
0132       HcalDetId did = HcalDetId(it->rawId());
0133       HcalElectronicsId eid = HcalElectronicsId(_ehashmap.lookup(did));
0134 
0135       _xBadQ.get(eid) += cBadQuality_depth.getBinContent(did);
0136       _cBadQuality_depth.fill(did, cBadQuality_depth.getBinContent(did));
0137       if (!eid.isVMEid()) {
0138         _xEvn.get(eid) += cEvnMsm_ElectronicsuTCA.getBinContent(eid);
0139         _xBcn.get(eid) += cBcnMsm_ElectronicsuTCA.getBinContent(eid);
0140 
0141         _cEvnMsm_ElectronicsuTCA.fill(eid, cEvnMsm_ElectronicsuTCA.getBinContent(eid));
0142         _cBcnMsm_ElectronicsuTCA.fill(eid, cBcnMsm_ElectronicsuTCA.getBinContent(eid));
0143       }
0144     }
0145 
0146     //  GENERATE THE SUMMARY FOR THIS LS AND STORE IT
0147     std::vector<flag::Flag> vtmpflags;  // tmp summary flags vector
0148     vtmpflags.resize(nRawFlag);
0149     vtmpflags[fEvnMsm] = flag::Flag("EvnMsm");
0150     vtmpflags[fBcnMsm] = flag::Flag("BcnMsm");
0151     vtmpflags[fBadQ] = flag::Flag("BadQ");
0152     for (std::vector<uint32_t>::const_iterator it = _vhashFEDs.begin(); it != _vhashFEDs.end(); ++it) {
0153       HcalElectronicsId eid(*it);
0154 
0155       //    reset all the tmp flags to fNA
0156       //    MUST DO IT NOW! AS NCDAQ MIGHT OVERWRITE IT!
0157       for (std::vector<flag::Flag>::iterator ft = vtmpflags.begin(); ft != vtmpflags.end(); ++ft)
0158         ft->reset();
0159 
0160       //    check if this FED was @cDAQ
0161       std::vector<uint32_t>::const_iterator cit = std::find(_vcdaqEids.begin(), _vcdaqEids.end(), *it);
0162       if (cit == _vcdaqEids.end()) {
0163         //  was not @cDAQ, set all the flags for this FED as fNCDAQ
0164         for (std::vector<flag::Flag>::iterator ft = vtmpflags.begin(); ft != vtmpflags.end(); ++ft)
0165           ft->_state = flag::fNCDAQ;
0166 
0167         // push all the flags for this FED
0168         // IMPORTANT!!!
0169         lssum._vflags.push_back(vtmpflags);
0170         continue;
0171       }
0172 
0173       //    here only if was registered at cDAQ
0174       if (utilities::isFEDHBHE(eid) || utilities::isFEDHF(eid) || utilities::isFEDHO(eid)) {
0175         if (_xEvn.get(eid) > 0)
0176           vtmpflags[fEvnMsm]._state = flag::fBAD;
0177         else
0178           vtmpflags[fEvnMsm]._state = flag::fGOOD;
0179         if (_xBcn.get(eid) > 0)
0180           vtmpflags[fBcnMsm]._state = flag::fBAD;
0181         else
0182           vtmpflags[fBcnMsm]._state = flag::fGOOD;
0183         if (double(_xBadQ.get(eid)) > double(12 * numEvents))
0184           vtmpflags[fBadQ]._state = flag::fBAD;
0185         else if (_xBadQ.get(eid) > 0)
0186           vtmpflags[fBadQ]._state = flag::fPROBLEMATIC;
0187         else
0188           vtmpflags[fBadQ]._state = flag::fGOOD;
0189       }
0190 
0191       // push all the flags for this FED
0192       lssum._vflags.push_back(vtmpflags);
0193     }
0194 
0195     //  push all flags for all FEDs for this LS
0196     _vflagsLS.push_back(lssum);
0197   }
0198 
0199   /*
0200      * END JOB
0201      * BOOK THE SUMMARY CONTAINERS, SET THE FLAGS
0202      * RETURN THE LIST OF FLAGS FOR THIS DATATIER
0203      */
0204   /* virtual */ std::vector<flag::Flag> RawRunSummary::endJob(DQMStore::IBooker& ib, DQMStore::IGetter& ig) {
0205     if (_ptype != fOffline)
0206       return std::vector<flag::Flag>();
0207 
0208     //  PREPARE LS BASED FLAGS to use it for booking
0209     std::vector<flag::Flag> vflagsLS;
0210     vflagsLS.resize(nRawFlag);
0211     vflagsLS[fEvnMsm] = flag::Flag("EvnMsm");
0212     vflagsLS[fBcnMsm] = flag::Flag("BcnMsm");
0213     vflagsLS[fBadQ] = flag::Flag("BadQ");
0214 
0215     //  INITIALIZE AND BOOK SUMMARY CONTAINERS
0216     ContainerSingle2D cSummaryvsLS;  // summary per FED: flag vs LS
0217     Container2D cSummaryvsLS_FED;    // LS based flags vs LS for each FED
0218     cSummaryvsLS.initialize(_name,
0219                             "SummaryvsLS",
0220                             new quantity::LumiSection(_maxProcessedLS),
0221                             new quantity::FEDQuantity(_vFEDs),
0222                             new quantity::ValueQuantity(quantity::fState),
0223                             0);
0224     cSummaryvsLS_FED.initialize(_name,
0225                                 "SummaryvsLS",
0226                                 hashfunctions::fFED,
0227                                 new quantity::LumiSection(_maxProcessedLS),
0228                                 new quantity::FlagQuantity(vflagsLS),
0229                                 new quantity::ValueQuantity(quantity::fState),
0230                                 0);
0231     cSummaryvsLS_FED.book(ib, _emap, _subsystem);
0232     cSummaryvsLS.book(ib, _subsystem);
0233 
0234     /*
0235          *  Iterate over each FED
0236          *      Iterate over each LS SUmmary
0237          *          Iterate over all flags
0238          *              set...
0239          */
0240 
0241     std::vector<flag::Flag> sumflags;  // flag per FED
0242     int ifed = 0;
0243     for (std::vector<uint32_t>::const_iterator it = _vhashFEDs.begin(); it != _vhashFEDs.end(); ++it) {
0244       flag::Flag fSumRun("RAW");  // summary flag for this FED
0245       HcalElectronicsId eid(*it);
0246 
0247       //    ITERATE OVER EACH LS
0248       for (std::vector<LSSummary>::const_iterator itls = _vflagsLS.begin(); itls != _vflagsLS.end(); ++itls) {
0249         //  fill histograms per LS
0250         int iflag = 0;
0251         flag::Flag fSumLS("RAW");
0252         for (std::vector<flag::Flag>::const_iterator ft = itls->_vflags[ifed].begin(); ft != itls->_vflags[ifed].end();
0253              ++ft) {
0254           //    Flag vs LS per FEd
0255           cSummaryvsLS_FED.setBinContent(eid, itls->_LS, int(iflag), ft->_state);
0256           fSumLS += (*ft);
0257           iflag++;
0258         }
0259         //  FED vs LS
0260         cSummaryvsLS.setBinContent(eid, itls->_LS, fSumLS._state);
0261         fSumRun += fSumLS;
0262       }
0263 
0264       //    push the summary flag for this FED for the whole RUN
0265       sumflags.push_back(fSumRun);
0266 
0267       //    increment the fed counter
0268       ifed++;
0269     }
0270 
0271     return sumflags;
0272   }
0273 }  // namespace hcaldqm