Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:09:26

0001 #include "DQMServices/Core/interface/DQMStore.h"
0002 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include <DQM/CastorMonitor/interface/CastorMonitorModule.h>
0007 //#include "CondFormats/CastorObjects/interface/CastorChannelQuality.h"
0008 #include <string>
0009 
0010 //**************************************************************//
0011 //***************** CastorMonitorModule       ******************//
0012 //***************** Author: Dmytro Volyanskyy ******************//
0013 //***************** Date  : 22.11.2008 (first version) *********//
0014 ////---- simple event filter which directs events to monitoring tasks:
0015 ////---- access unpacked data from each event and pass them to monitoring tasks
0016 ////---- revision: 06.10.2010 (Dima Volyanskyy)
0017 ////---- last revision: 31.05.2011 (Panos Katsas)
0018 ////---- LS1 upgrade: 04.06.2013 (Pedro Cipriano)
0019 //**************************************************************//
0020 
0021 //---- critical revision 26.06.2014 (Vladimir Popov)
0022 
0023 //**************************************************************//
0024 
0025 using namespace std;
0026 using namespace edm;
0027 
0028 CastorMonitorModule::CastorMonitorModule(const edm::ParameterSet &ps)
0029     : castorDbServiceToken_{esConsumes<CastorDbService, CastorDbRecord>()} {
0030   fVerbosity = ps.getUntrackedParameter<int>("debug", 0);
0031   subsystemname_ = ps.getUntrackedParameter<std::string>("subSystemFolder", "Castor");
0032   inputTokenRaw_ = consumes<FEDRawDataCollection>(ps.getParameter<edm::InputTag>("rawLabel"));
0033   inputTokenReport_ = consumes<HcalUnpackerReport>(ps.getParameter<edm::InputTag>("unpackerReportLabel"));
0034   inputTokenDigi_ = consumes<CastorDigiCollection>(ps.getParameter<edm::InputTag>("digiLabel"));
0035   inputTokenRecHitCASTOR_ = consumes<CastorRecHitCollection>(ps.getParameter<edm::InputTag>("CastorRecHitLabel"));
0036   inputTokenCastorTowers_ = consumes<CastorTowerCollection>(ps.getParameter<edm::InputTag>("CastorTowerLabel"));
0037   JetAlgorithm = consumes<BasicJetCollection>(ps.getParameter<edm::InputTag>("CastorBasicJetsLabel"));
0038   tokenTriggerResults = consumes<edm::TriggerResults>(ps.getParameter<edm::InputTag>("tagTriggerResults"));
0039 
0040   showTiming_ = ps.getUntrackedParameter<bool>("showTiming", false);
0041 
0042   if (ps.getUntrackedParameter<bool>("DigiMonitor", false))
0043     DigiMon_ = std::make_unique<CastorDigiMonitor>(ps, consumesCollector());
0044 
0045   if (ps.getUntrackedParameter<bool>("RecHitMonitor", false))
0046     RecHitMon_ = std::make_unique<CastorRecHitMonitor>(ps);
0047 
0048   if (ps.getUntrackedParameter<bool>("LEDMonitor", false))
0049     LedMon_ = std::make_unique<CastorLEDMonitor>(ps);
0050 
0051   ievt_ = 0;
0052 }
0053 
0054 CastorMonitorModule::~CastorMonitorModule() {}
0055 
0056 void CastorMonitorModule::dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &) {
0057   if (fVerbosity > 0)
0058     LogPrint("CastorMonitorModule") << "dqmBeginRun(start)";
0059 }
0060 
0061 void CastorMonitorModule::bookHistograms(DQMStore::IBooker &ibooker,
0062                                          const edm::Run &iRun,
0063                                          const edm::EventSetup &iSetup) {
0064   if (DigiMon_) {
0065     // Run histos only since there is endRun processing.
0066     auto scope = DQMStore::IBooker::UseRunScope(ibooker);
0067     DigiMon_->bookHistograms(ibooker, iRun, iSetup);
0068   }
0069   if (RecHitMon_) {
0070     RecHitMon_->bookHistograms(ibooker, iRun);
0071   }
0072   if (LedMon_) {
0073     LedMon_->bookHistograms(ibooker, iRun);
0074   }
0075 
0076   ibooker.setCurrentFolder(subsystemname_);
0077   char s[60];
0078   sprintf(s, "CastorEventProducts");
0079   CastorEventProduct = ibooker.book1DD(s, s, 6, -0.5, 5.5);
0080   CastorEventProduct->setAxisTitle("Events", /* axis */ 2);
0081   CastorEventProduct->setBinLabel(1, "FEDs/3");
0082   CastorEventProduct->setBinLabel(2, "RawData");
0083   CastorEventProduct->setBinLabel(3, "Digi");
0084   CastorEventProduct->setBinLabel(4, "RecHits");
0085   CastorEventProduct->setBinLabel(5, "Towers");
0086   CastorEventProduct->setBinLabel(6, "Jets");
0087 
0088   sprintf(s, "CASTORUnpackReport");
0089   hunpkrep = ibooker.bookProfile(s, s, 6, -0.5, 5.5, 100, 0, 1.e10, "");
0090   hunpkrep->setBinLabel(1, "N_FEDs");
0091   hunpkrep->setBinLabel(2, "SPIGOT_Err");
0092   hunpkrep->setBinLabel(3, "empty");
0093   hunpkrep->setBinLabel(4, "busy");
0094   hunpkrep->setBinLabel(5, "OvF");
0095   hunpkrep->setBinLabel(6, "BadDigis");
0096   return;
0097 }
0098 
0099 void CastorMonitorModule::dqmEndRun(const edm::Run &r, const edm::EventSetup &) {
0100   if (DigiMon_) {
0101     DigiMon_->endRun();
0102   }
0103 }
0104 
0105 void CastorMonitorModule::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0106   if (fVerbosity > 1)
0107     LogPrint("CastorMonitorModule") << "analyze (start)";
0108 
0109   ievt_++;
0110 
0111   bool rawOK_ = true;
0112   bool digiOK_ = true;
0113   bool rechitOK_ = true, towerOK_ = true, jetsOK_ = true;
0114   int nDigi = 0, nrecHits = 0, nTowers = 0, nJets = 0;
0115 
0116   edm::Handle<edm::TriggerResults> TrigResults;
0117   iEvent.getByToken(tokenTriggerResults, TrigResults);
0118 
0119   edm::Handle<FEDRawDataCollection> RawData;
0120   iEvent.getByToken(inputTokenRaw_, RawData);
0121   if (!RawData.isValid())
0122     rawOK_ = false;
0123 
0124   float fedsUnpacked = 0.;
0125   edm::Handle<HcalUnpackerReport> report;
0126   iEvent.getByToken(inputTokenReport_, report);
0127   if (!report.isValid())
0128     rawOK_ = false;
0129   else {
0130     const std::vector<int> feds = (*report).getFedsUnpacked();
0131     fedsUnpacked = float(feds.size());
0132     hunpkrep->Fill(0, fedsUnpacked);
0133     hunpkrep->Fill(1, report->spigotFormatErrors());
0134     hunpkrep->Fill(2, report->emptyEventSpigots());
0135     hunpkrep->Fill(3, report->busySpigots());
0136     hunpkrep->Fill(4, report->OFWSpigots());
0137     hunpkrep->Fill(5, report->badQualityDigis());
0138   }
0139 
0140   edm::Handle<CastorDigiCollection> CastorDigi;
0141   iEvent.getByToken(inputTokenDigi_, CastorDigi);
0142   if (CastorDigi.isValid())
0143     nDigi = CastorDigi->size();
0144   else
0145     digiOK_ = false;
0146 
0147   edm::Handle<CastorRecHitCollection> CastorHits;
0148   iEvent.getByToken(inputTokenRecHitCASTOR_, CastorHits);
0149   if (CastorHits.isValid())
0150     nrecHits = CastorHits->size();
0151   else
0152     rechitOK_ = false;
0153 
0154   edm::Handle<reco::CastorTowerCollection> castorTowers;
0155   iEvent.getByToken(inputTokenCastorTowers_, castorTowers);
0156   if (castorTowers.isValid())
0157     nTowers = castorTowers->size();
0158   else
0159     towerOK_ = false;
0160 
0161   edm::Handle<reco::BasicJetCollection> jets;
0162   iEvent.getByToken(JetAlgorithm, jets);
0163   if (jets.isValid())
0164     nJets = jets->size();
0165   else
0166     jetsOK_ = false;
0167 
0168   if (fVerbosity > 0)
0169     LogPrint("CastorMonitorModule") << "CastorProductValid(size): RawDataValid=" << RawData.isValid()
0170                                     << " Digi=" << digiOK_ << "(" << nDigi << ") Hits=" << rechitOK_ << "(" << nrecHits
0171                                     << ")"
0172                                     << " Towers=" << towerOK_ << "(" << nTowers << ")"
0173                                     << " Jets=" << jetsOK_ << "(" << nJets << ")";
0174 
0175   CastorEventProduct->Fill(0, fedsUnpacked / 3.);
0176   CastorEventProduct->Fill(1, rawOK_);
0177   CastorEventProduct->Fill(2, digiOK_);
0178   CastorEventProduct->Fill(3, rechitOK_);
0179   CastorEventProduct->Fill(4, towerOK_);
0180   CastorEventProduct->Fill(5, jetsOK_);
0181 
0182   if (digiOK_) {
0183     const CastorDbService &conditions = iSetup.getData(castorDbServiceToken_);
0184     DigiMon_->processEvent(iEvent, *CastorDigi, *TrigResults, conditions);
0185   }
0186   if (showTiming_) {
0187     cpu_timer.stop();
0188     if (DigiMon_ != nullptr)
0189       std::cout << "TIMER:: DIGI MONITOR ->" << cpu_timer.cpuTime() << std::endl;
0190     cpu_timer.reset();
0191     cpu_timer.start();
0192   }
0193 
0194   if (rechitOK_)
0195     RecHitMon_->processEvent(*CastorHits);
0196   if (showTiming_) {
0197     cpu_timer.stop();
0198     if (RecHitMon_ != nullptr)
0199       std::cout << "TIMER:: RECHIT MONITOR->" << cpu_timer.cpuTime() << std::endl;
0200     cpu_timer.reset();
0201     cpu_timer.start();
0202   }
0203 
0204   if (towerOK_)
0205     RecHitMon_->processEventTowers(*castorTowers);
0206   if (jetsOK_)
0207     RecHitMon_->processEventJets(*jets);
0208 
0209   if (fVerbosity > 0 && ievt_ % 100 == 0)
0210     LogPrint("CastorMonitorModule") << "processed " << ievt_ << " events";
0211   return;
0212 }
0213 
0214 DEFINE_FWK_MODULE(CastorMonitorModule);