Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:12:27

0001 #include <iostream>
0002 
0003 // FW
0004 #include "FWCore/Framework/interface/Event.h"
0005 
0006 #include "FWCore/ServiceRegistry/interface/Service.h"
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 
0012 // L1
0013 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0014 
0015 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuRegionalCand.h"
0016 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTCand.h"
0017 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTExtendedCand.h"
0018 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutCollection.h"
0019 
0020 #include "FWCore/Framework/interface/LuminosityBlock.h"
0021 
0022 #include "DataFormats/Scalers/interface/L1TriggerScalers.h"
0023 #include "DataFormats/Scalers/interface/L1TriggerRates.h"
0024 #include "DataFormats/Scalers/interface/LumiScalers.h"
0025 #include "DQM/TrigXMonitor/interface/L1Scalers.h"
0026 #include "DataFormats/Common/interface/Handle.h"
0027 #include "DQMServices/Core/interface/DQMStore.h"
0028 
0029 // HACK START
0030 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0031 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
0032 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
0033 // HACK END
0034 
0035 using namespace edm;
0036 
0037 L1Scalers::L1Scalers(const edm::ParameterSet& ps)
0038     : nev_(0),
0039       verbose_(ps.getUntrackedParameter<bool>("verbose", false)),
0040       l1GtDataSource_(consumes<L1GlobalTriggerReadoutRecord>(ps.getParameter<edm::InputTag>("l1GtData"))),
0041       l1GmtDataSource_(consumes<L1MuGMTReadoutCollection>(ps.getParameter<edm::InputTag>("l1GtData"))),
0042       denomIsTech_(ps.getUntrackedParameter<bool>("denomIsTech", true)),
0043       denomBit_(ps.getUntrackedParameter<unsigned int>("denomBit", 40)),
0044       tfIsTech_(ps.getUntrackedParameter<bool>("tfIsTech", true)),
0045       tfBit_(ps.getUntrackedParameter<unsigned int>("tfBit", 41)),
0046       algoSelected_(
0047           ps.getUntrackedParameter<std::vector<unsigned int> >("algoMonitorBits", std::vector<unsigned int>())),
0048       techSelected_(
0049           ps.getUntrackedParameter<std::vector<unsigned int> >("techMonitorBits", std::vector<unsigned int>())),
0050       folderName_(ps.getUntrackedParameter<std::string>("dqmFolder", std::string("L1T/L1Scalers_EvF"))),
0051       l1scalers_(nullptr),
0052       l1techScalers_(nullptr),
0053       l1Correlations_(nullptr),
0054       bxNum_(nullptr),
0055       l1scalersBx_(nullptr),
0056       l1techScalersBx_(nullptr),
0057       nLumiBlock_(nullptr),
0058       l1AlgoCounter_(nullptr),
0059       l1TtCounter_(nullptr),
0060       fedStart_(ps.getUntrackedParameter<unsigned int>("firstFED", 0)),
0061       fedStop_(ps.getUntrackedParameter<unsigned int>("lastFED", 931)),
0062       rateAlgoCounter_(0),
0063       rateTtCounter_(0),
0064       fedRawCollection_(ps.getParameter<edm::InputTag>("fedRawData")),
0065       maskedList_(ps.getUntrackedParameter<std::vector<int> >("maskedChannels",
0066                                                               std::vector<int>())),  // this is using the ashed index
0067       HcalRecHitCollection_(ps.getParameter<edm::InputTag>("HFRecHitCollection")) {
0068   LogDebug("Status") << "constructor";
0069 }
0070 
0071 void L1Scalers::bookHistograms(DQMStore::IBooker& iBooker, edm::Run const&, edm::EventSetup const&) {
0072   iBooker.setCurrentFolder(folderName_);
0073   l1scalers_ = iBooker.book1D("l1AlgoBits", "L1 Algorithm Bits", 128, -0.5, 127.5);
0074   l1scalersBx_ = iBooker.book2D("l1AlgoBits_Vs_Bx",
0075                                 "L1 Algorithm Bits vs "
0076                                 "Bunch Number",
0077                                 3600,
0078                                 -0.5,
0079                                 3599.5,
0080                                 128,
0081                                 -0.5,
0082                                 127.5);
0083   l1Correlations_ = iBooker.book2D("l1Correlations",
0084                                    "L1 Algorithm Bits "
0085                                    "Correlations",
0086                                    128,
0087                                    -0.5,
0088                                    127.5,
0089                                    128,
0090                                    -0.5,
0091                                    127.5);
0092   l1techScalers_ = iBooker.book1D("l1TechBits", "L1 Tech. Trigger Bits", 64, -0.5, 63.5);
0093   l1techScalersBx_ = iBooker.book2D("l1TechBits_Vs_Bx",
0094                                     "L1 Technical "
0095                                     "Trigger "
0096                                     "Bits vs Bunch Number",
0097                                     3600,
0098                                     -0.5,
0099                                     3599.5,
0100                                     64,
0101                                     -0.5,
0102                                     63.5);
0103   bxNum_ = iBooker.book1D("bxNum", "Bunch number from GTFE", 3600, -0.5, 3599.5);
0104 
0105   nLumiBlock_ = iBooker.bookInt("nLumiBlock");
0106 
0107   //  l1 total rate
0108   l1AlgoCounter_ = iBooker.bookInt("l1AlgoCounter");
0109   l1TtCounter_ = iBooker.bookInt("l1TtCounter");
0110 
0111   // timing plots
0112   std::stringstream sdenom;
0113   if (denomIsTech_)
0114     sdenom << "tech";
0115   else
0116     sdenom << "algo";
0117 
0118   iBooker.setCurrentFolder(folderName_ + "/Synch");
0119   algoBxDiff_.clear();
0120   algoBxDiff_.clear();
0121   algoBxDiffLumi_.clear();
0122   techBxDiffLumi_.clear();
0123   for (uint ibit = 0; ibit < algoSelected_.size(); ibit++) {
0124     std::stringstream ss;
0125     ss << algoSelected_[ibit] << "_" << sdenom.str() << denomBit_;
0126     algoBxDiff_.push_back(iBooker.book1D("BX_diff_algo" + ss.str(), "BX_diff_algo" + ss.str(), 9, -4, 5));
0127     algoBxDiffLumi_.push_back(iBooker.book2D("BX_diffvslumi_algo" + ss.str(),
0128                                              "BX_diff_algo" + ss.str(),
0129                                              MAX_LUMI_BIN,
0130                                              -0.5,
0131                                              double(MAX_LUMI_SEG) - 0.5,
0132                                              9,
0133                                              -4,
0134                                              5));
0135     // algoBxDiffLumi_[ibit]->setAxisTitle("Lumi Section", 1);
0136   }
0137   for (uint ibit = 0; ibit < techSelected_.size(); ibit++) {
0138     std::stringstream ss;
0139     ss << techSelected_[ibit] << "_" << sdenom.str() << denomBit_;
0140     techBxDiff_.push_back(iBooker.book1D("BX_diff_tech" + ss.str(), "BX_diff_tech" + ss.str(), 9, -4, 5));
0141     techBxDiffLumi_.push_back(iBooker.book2D("BX_diffvslumi_tech" + ss.str(),
0142                                              "BX_diff_tech" + ss.str(),
0143                                              MAX_LUMI_BIN,
0144                                              -0.5,
0145                                              double(MAX_LUMI_SEG) - 0.5,
0146                                              9,
0147                                              -4,
0148                                              5));
0149     // techBxDiffLumi_[ibit]->setAxisTitle("Lumi Section", 1);
0150   }
0151 
0152   // GMT timing plots
0153   std::stringstream ss1;
0154   ss1 << "_" << sdenom.str() << denomBit_;
0155   dtBxDiff_ = iBooker.book1D("BX_diff_DT" + ss1.str(), "BX_diff_DT" + ss1.str(), 9, -4, 5);
0156   dtBxDiffLumi_ = iBooker.book2D("BX_diffvslumi_DT" + ss1.str(),
0157                                  "BX_diffvslumi_DT" + ss1.str(),
0158                                  MAX_LUMI_BIN,
0159                                  -0.5,
0160                                  double(MAX_LUMI_SEG) - 0.5,
0161                                  9,
0162                                  -4,
0163                                  5);
0164   cscBxDiff_ = iBooker.book1D("BX_diff_CSC" + ss1.str(), "BX_diff_CSC" + ss1.str(), 9, -4, 5);
0165   cscBxDiffLumi_ = iBooker.book2D("BX_diffvslumi_CSC" + ss1.str(),
0166                                   "BX_diffvslumi_CSC" + ss1.str(),
0167                                   MAX_LUMI_BIN,
0168                                   -0.5,
0169                                   double(MAX_LUMI_SEG) - 0.5,
0170                                   9,
0171                                   -4,
0172                                   5);
0173   rpcbBxDiff_ = iBooker.book1D("BX_diff_RPCb" + ss1.str(), "BX_diff_RPCb" + ss1.str(), 9, -4, 5);
0174   rpcbBxDiffLumi_ = iBooker.book2D("BX_diffvslumi_RPCb" + ss1.str(),
0175                                    "BX_diffvslumi_RPCb" + ss1.str(),
0176                                    MAX_LUMI_BIN,
0177                                    -0.5,
0178                                    double(MAX_LUMI_SEG) - 0.5,
0179                                    9,
0180                                    -4,
0181                                    5);
0182   rpcfBxDiff_ = iBooker.book1D("BX_diff_RPCf" + ss1.str(), "BX_diff_RPCf" + ss1.str(), 9, -4, 5);
0183   rpcfBxDiffLumi_ = iBooker.book2D("BX_diffvslumi_RPCf" + ss1.str(),
0184                                    "BX_diffvslumi_RPCf" + ss1.str(),
0185                                    MAX_LUMI_BIN,
0186                                    -0.5,
0187                                    double(MAX_LUMI_SEG) - 0.5,
0188                                    9,
0189                                    -4,
0190                                    5);
0191 }
0192 
0193 void L1Scalers::analyze(const edm::Event& e, const edm::EventSetup& iSetup) {
0194   nev_++;
0195 
0196   LogDebug("Status") << "L1Scalers::analyze  event " << nev_;
0197 
0198   // int myGTFEbx = -1;
0199   // get Global Trigger decision and the decision word
0200   // these are locally derived
0201   edm::Handle<L1GlobalTriggerReadoutRecord> gtRecord;
0202   bool t = e.getByToken(l1GtDataSource_, gtRecord);
0203 
0204   if (!t) {
0205     LogDebug("Product") << "can't find L1GlobalTriggerReadoutRecord";
0206   } else {
0207     L1GtfeWord gtfeWord = gtRecord->gtfeWord();
0208     int gtfeBx = gtfeWord.bxNr();
0209     bxNum_->Fill(gtfeBx);
0210 
0211     bool tfBitGood = false;
0212 
0213     // First, the default
0214     // vector of bool
0215     for (int iebx = 0; iebx <= 4; iebx++) {
0216       // Algorithm Bits
0217       DecisionWord gtDecisionWord = gtRecord->decisionWord(iebx - 2);
0218       //    DecisionWord gtDecisionWord = gtRecord->decisionWord();
0219       if (!gtDecisionWord.empty()) {  // if board not there this is zero
0220         // loop over dec. bit to get total rate (no overlap)
0221         for (uint i = 0; i < gtDecisionWord.size(); ++i) {
0222           if (gtDecisionWord[i]) {
0223             rateAlgoCounter_++;
0224             l1AlgoCounter_->Fill(rateAlgoCounter_);
0225             break;
0226           }
0227         }
0228         // loop over decision bits
0229         for (uint i = 0; i < gtDecisionWord.size(); ++i) {
0230           if (gtDecisionWord[i]) {
0231             l1scalers_->Fill(i);
0232             l1scalersBx_->Fill(gtfeBx - 2 + iebx, i);
0233             for (uint j = i + 1; j < gtDecisionWord.size(); ++j) {
0234               if (gtDecisionWord[j]) {
0235                 l1Correlations_->Fill(i, j);
0236                 l1Correlations_->Fill(j, i);
0237               }
0238             }
0239           }
0240         }
0241       }  //!empty DecisionWord
0242 
0243       // loop over technical triggers
0244       // vector of bool again.
0245       TechnicalTriggerWord tw = gtRecord->technicalTriggerWord(iebx - 2);
0246       //    TechnicalTriggerWord tw = gtRecord->technicalTriggerWord();
0247       if (!tw.empty()) {
0248         // loop over dec. bit to get total rate (no overlap)
0249         for (uint i = 0; i < tw.size(); ++i) {
0250           if (tw[i]) {
0251             rateTtCounter_++;
0252             l1TtCounter_->Fill(rateTtCounter_);
0253             break;
0254           }
0255         }
0256         for (uint i = 0; i < tw.size(); ++i) {
0257           if (tw[i]) {
0258             l1techScalers_->Fill(i);
0259             l1techScalersBx_->Fill(gtfeBx - 2 + iebx, i);
0260           }
0261         }
0262 
0263         // check if bit used to filter timing plots fired in this event
0264         // (anywhere in the bx window)
0265         if (tfIsTech_) {
0266           if (tfBit_ < tw.size()) {
0267             if (tw[tfBit_])
0268               tfBitGood = true;
0269           }
0270         }
0271       }  // ! tw.empty
0272 
0273     }  // bx
0274 
0275     // timing plots
0276     earliestDenom_ = 9;
0277     earliestAlgo_.clear();
0278     earliestTech_.clear();
0279     for (uint i = 0; i < techSelected_.size(); i++)
0280       earliestTech_.push_back(9);
0281     for (uint i = 0; i < algoSelected_.size(); i++)
0282       earliestAlgo_.push_back(9);
0283 
0284     // GMT information
0285     edm::Handle<L1MuGMTReadoutCollection> gmtCollection;
0286     e.getByToken(l1GmtDataSource_, gmtCollection);
0287 
0288     if (!gmtCollection.isValid()) {
0289       edm::LogInfo("DataNotFound") << "can't find L1MuGMTReadoutCollection with label";
0290     }
0291 
0292     // remember the bx of 1st candidate of each system (9=none)
0293     int bx1st[4] = {9, 9, 9, 9};
0294 
0295     if (tfBitGood) {  // to avoid single BSC hits
0296 
0297       for (int iebx = 0; iebx <= 4; iebx++) {
0298         TechnicalTriggerWord tw = gtRecord->technicalTriggerWord(iebx - 2);
0299         DecisionWord gtDecisionWord = gtRecord->decisionWord(iebx - 2);
0300 
0301         bool denomBitGood = false;
0302 
0303         // check if reference bit is valid
0304         if (denomIsTech_) {
0305           if (!tw.empty()) {
0306             if (denomBit_ < tw.size()) {
0307               denomBitGood = true;
0308               if (tw[denomBit_] && earliestDenom_ == 9)
0309                 earliestDenom_ = iebx;
0310             }
0311           }
0312         } else {
0313           if (!gtDecisionWord.empty()) {
0314             if (denomBit_ < gtDecisionWord.size()) {
0315               denomBitGood = true;
0316               if (gtDecisionWord[denomBit_] && earliestDenom_ == 9)
0317                 earliestDenom_ = iebx;
0318             }
0319           }
0320         }
0321 
0322         if (denomBitGood) {
0323           // get earliest tech bx's
0324           if (!tw.empty()) {
0325             for (uint ibit = 0; ibit < techSelected_.size(); ibit++) {
0326               if (techSelected_[ibit] < tw.size()) {
0327                 if (tw[techSelected_[ibit]] && earliestTech_[ibit] == 9)
0328                   earliestTech_[ibit] = iebx;
0329               }
0330             }
0331           }
0332 
0333           // get earliest algo bx's
0334           if (!gtDecisionWord.empty()) {
0335             for (uint ibit = 0; ibit < algoSelected_.size(); ibit++) {
0336               if (algoSelected_[ibit] < gtDecisionWord.size()) {
0337                 if (gtDecisionWord[algoSelected_[ibit]] && earliestAlgo_[ibit] == 9)
0338                   earliestAlgo_[ibit] = iebx;
0339               }
0340             }
0341           }
0342         }  // denomBitGood
0343       }    // bx
0344 
0345       // get earliest single muon trigger system bx's
0346       if (gmtCollection.isValid()) {
0347         // get GMT readout collection
0348         L1MuGMTReadoutCollection const* gmtrc = gmtCollection.product();
0349         // get record vector
0350         std::vector<L1MuGMTReadoutRecord> gmt_records = gmtrc->getRecords();
0351         // loop over records of individual bx's
0352         std::vector<L1MuGMTReadoutRecord>::const_iterator RRItr;
0353 
0354         for (RRItr = gmt_records.begin(); RRItr != gmt_records.end(); RRItr++) {  // loop from BX=-2 to BX=2
0355           std::vector<L1MuRegionalCand> INPCands[4] = {
0356               RRItr->getDTBXCands(), RRItr->getBrlRPCCands(), RRItr->getCSCCands(), RRItr->getFwdRPCCands()};
0357           std::vector<L1MuRegionalCand>::const_iterator INPItr;
0358           int BxInEvent = RRItr->getBxInEvent();
0359 
0360           // find the first non-empty candidate in this bx
0361           for (int i = 0; i < 4; i++) {  // for each single muon trigger system
0362             for (INPItr = INPCands[i].begin(); INPItr != INPCands[i].end(); ++INPItr) {
0363               if (!INPItr->empty()) {
0364                 if (bx1st[i] == 9)
0365                   bx1st[i] = BxInEvent + 2;  // must go from 0 to 4 (consistent with above)
0366               }
0367             }
0368           }
0369         }
0370       }  // gmtCollection.isValid
0371       // calculated bx difference
0372       if (earliestDenom_ != 9) {
0373         for (uint ibit = 0; ibit < techSelected_.size(); ibit++) {
0374           if (earliestTech_[ibit] != 9) {
0375             int diff = earliestTech_[ibit] - earliestDenom_;
0376             techBxDiff_[ibit]->Fill(diff);
0377             techBxDiffLumi_[ibit]->Fill(e.luminosityBlock(), diff);
0378           }
0379         }
0380         for (uint ibit = 0; ibit < algoSelected_.size(); ibit++) {
0381           if (earliestAlgo_[ibit] != 9) {
0382             int diff = earliestAlgo_[ibit] - earliestDenom_;
0383             algoBxDiff_[ibit]->Fill(diff);
0384             algoBxDiffLumi_[ibit]->Fill(e.luminosityBlock(), diff);
0385           }
0386         }
0387 
0388         if (bx1st[0] != 9) {
0389           int diff = bx1st[0] - earliestDenom_;
0390           dtBxDiff_->Fill(diff);
0391           dtBxDiffLumi_->Fill(e.luminosityBlock(), diff);
0392         }
0393         if (bx1st[1] != 9) {
0394           int diff = bx1st[1] - earliestDenom_;
0395           rpcbBxDiff_->Fill(diff);
0396           rpcbBxDiffLumi_->Fill(e.luminosityBlock(), diff);
0397         }
0398         if (bx1st[2] != 9) {
0399           int diff = bx1st[2] - earliestDenom_;
0400           cscBxDiff_->Fill(diff);
0401           cscBxDiffLumi_->Fill(e.luminosityBlock(), diff);
0402         }
0403         if (bx1st[3] != 9) {
0404           int diff = bx1st[3] - earliestDenom_;
0405           rpcfBxDiff_->Fill(diff);
0406           rpcfBxDiffLumi_->Fill(e.luminosityBlock(), diff);
0407         }
0408       }
0409     }  // tt41Good
0410   }
0411   return;
0412 }
0413 
0414 std::shared_ptr<l1s::Empty> L1Scalers::globalBeginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
0415                                                                   const edm::EventSetup& c) const {
0416   return std::shared_ptr<l1s::Empty>();
0417 }
0418 
0419 void L1Scalers::globalEndLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& iSetup) {
0420   nLumiBlock_->Fill(lumiSeg.id().luminosityBlock());
0421 }