Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-14 22:39:36

0001 #include <iostream>
0002 #include <fstream>
0003 #include <vector>
0004 
0005 #include "FWCore/ServiceRegistry/interface/Service.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 
0010 #include "DQMServices/Core/interface/DQMStore.h"
0011 
0012 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0013 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
0014 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
0015 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0016 
0017 #include "DataFormats/DetId/interface/DetId.h"
0018 #include "DataFormats/EcalDetId/interface/ESDetId.h"
0019 #include "DataFormats/EcalDigi/interface/ESDataFrame.h"
0020 #include "DataFormats/EcalRawData/interface/ESDCCHeaderBlock.h"
0021 
0022 #include "DQM/EcalPreshowerMonitorModule/interface/ESRawDataTask.h"
0023 
0024 using namespace cms;
0025 using namespace edm;
0026 using namespace std;
0027 
0028 ESRawDataTask::ESRawDataTask(const ParameterSet& ps) {
0029   prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
0030 
0031   FEDRawDataCollection_ = consumes<FEDRawDataCollection>(ps.getParameter<InputTag>("FEDRawDataCollection"));
0032   dccCollections_ = consumes<ESRawDataCollection>(ps.getParameter<InputTag>("ESDCCCollections"));
0033 
0034   ievt_ = 0;
0035 }
0036 
0037 std::shared_ptr<ESRawLSCache> ESRawDataTask::globalBeginLuminosityBlock(const edm::LuminosityBlock& lumi,
0038                                                                         const edm::EventSetup& c) const {
0039   auto lumiCache = std::make_shared<ESRawLSCache>();
0040   lumiCache->ievtLS_ = 0;
0041 
0042   meL1ADCCErrorsByLS_->Reset();
0043   meBXDCCErrorsByLS_->Reset();
0044   meOrbitNumberDCCErrorsByLS_->Reset();
0045 
0046   return lumiCache;
0047 }
0048 
0049 void ESRawDataTask::globalEndLuminosityBlock(const edm::LuminosityBlock& lumi, const edm::EventSetup& c) {}
0050 
0051 void ESRawDataTask::bookHistograms(DQMStore::IBooker& iBooker, Run const&, EventSetup const&) {
0052   char histo[200];
0053 
0054   iBooker.setCurrentFolder(prefixME_ + "/ESRawDataTask");
0055 
0056   //sprintf(histo, "ES run number errors");
0057   //meRunNumberErrors_ = iBooker.book1D(histo, histo, 56, 519.5, 575.5);
0058   //meRunNumberErrors_->setAxisTitle("ES FED", 1);
0059   //meRunNumberErrors_->setAxisTitle("Num of Events", 2);
0060 
0061   sprintf(histo, "ES L1A DCC errors");
0062   meL1ADCCErrors_ = iBooker.book1D(histo, histo, 56, 519.5, 575.5);
0063   meL1ADCCErrors_->setAxisTitle("ES FED", 1);
0064   meL1ADCCErrors_->setAxisTitle("Num of Events", 2);
0065 
0066   sprintf(histo, "ES BX DCC errors");
0067   meBXDCCErrors_ = iBooker.book1D(histo, histo, 56, 519.5, 575.5);
0068   meBXDCCErrors_->setAxisTitle("ES FED", 1);
0069   meBXDCCErrors_->setAxisTitle("Num of Events", 2);
0070 
0071   sprintf(histo, "ES Orbit Number DCC errors");
0072   meOrbitNumberDCCErrors_ = iBooker.book1D(histo, histo, 56, 519.5, 575.5);
0073   meOrbitNumberDCCErrors_->setAxisTitle("ES FED", 1);
0074   meOrbitNumberDCCErrors_->setAxisTitle("Num of Events", 2);
0075 
0076   sprintf(histo, "Difference between ES and GT L1A");
0077   meL1ADiff_ = iBooker.book1D(histo, histo, 201, -100.5, 100.5);
0078   meL1ADiff_->setAxisTitle("ES - GT L1A", 1);
0079   meL1ADiff_->setAxisTitle("Num of Events", 2);
0080 
0081   sprintf(histo, "Difference between ES and GT BX");
0082   meBXDiff_ = iBooker.book1D(histo, histo, 201, -100.5, 100.5);
0083   meBXDiff_->setAxisTitle("ES - GT BX", 1);
0084   meBXDiff_->setAxisTitle("Num of Events", 2);
0085 
0086   sprintf(histo, "Difference between ES and GT Orbit Number");
0087   meOrbitNumberDiff_ = iBooker.book1D(histo, histo, 201, -100.5, 100.5);
0088   meOrbitNumberDiff_->setAxisTitle("ES - GT orbit number", 1);
0089   meOrbitNumberDiff_->setAxisTitle("Num of Events", 2);
0090 
0091   // LS-based histos
0092   iBooker.setCurrentFolder(prefixME_ + "/ByLumiSection");
0093 
0094   sprintf(histo, "ES L1A DCC errors");
0095   meL1ADCCErrorsByLS_ = iBooker.book1D(histo, histo, 56, 519.5, 575.5);
0096   meL1ADCCErrorsByLS_->setAxisTitle("ES FED", 1);
0097   meL1ADCCErrorsByLS_->setAxisTitle("Num of Events", 2);
0098 
0099   sprintf(histo, "ES BX DCC errors");
0100   meBXDCCErrorsByLS_ = iBooker.book1D(histo, histo, 56, 519.5, 575.5);
0101   meBXDCCErrorsByLS_->setAxisTitle("ES FED", 1);
0102   meBXDCCErrorsByLS_->setAxisTitle("Num of Events", 2);
0103 
0104   sprintf(histo, "ES Orbit Number DCC errors");
0105   meOrbitNumberDCCErrorsByLS_ = iBooker.book1D(histo, histo, 56, 519.5, 575.5);
0106   meOrbitNumberDCCErrorsByLS_->setAxisTitle("ES FED", 1);
0107   meOrbitNumberDCCErrorsByLS_->setAxisTitle("Num of Events", 2);
0108 }
0109 
0110 void ESRawDataTask::analyze(const Event& e, const EventSetup& c) {
0111   ievt_++;
0112   runNum_ = e.id().run();
0113 
0114   int gt_L1A = 0, gt_OrbitNumber = 0, gt_BX = 0;
0115   int esDCC_L1A_MostFreqCounts = 0;
0116   int esDCC_BX_MostFreqCounts = 0;
0117   int esDCC_OrbitNumber_MostFreqCounts = 0;
0118 
0119   Handle<ESRawDataCollection> dccs;
0120   Handle<FEDRawDataCollection> allFedRawData;
0121 
0122   int gtFedDataSize = 0;
0123 
0124   if (e.getByToken(FEDRawDataCollection_, allFedRawData)) {
0125     // GT FED data
0126     const FEDRawData& gtFedData = allFedRawData->FEDData(812);
0127 
0128     gtFedDataSize = gtFedData.size() / sizeof(uint64_t);
0129 
0130     if (gtFedDataSize > 0) {
0131       FEDHeader header(gtFedData.data());
0132 
0133       gt_L1A = header.lvl1ID();
0134       gt_OrbitNumber = e.orbitNumber();
0135       gt_BX = e.bunchCrossing();
0136     } else {
0137       map<int, int> esDCC_L1A_FreqMap;
0138       map<int, int> esDCC_BX_FreqMap;
0139       map<int, int> esDCC_OrbitNumber_FreqMap;
0140 
0141       if (e.getByToken(dccCollections_, dccs)) {
0142         for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
0143           const ESDCCHeaderBlock& esdcc = (*dccItr);
0144 
0145           esDCC_L1A_FreqMap[esdcc.getLV1()]++;
0146           esDCC_BX_FreqMap[esdcc.getBX()]++;
0147           esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()]++;
0148 
0149           if (esDCC_L1A_FreqMap[esdcc.getLV1()] > esDCC_L1A_MostFreqCounts) {
0150             esDCC_L1A_MostFreqCounts = esDCC_L1A_FreqMap[esdcc.getLV1()];
0151             gt_L1A = esdcc.getLV1();
0152           }
0153 
0154           if (esDCC_BX_FreqMap[esdcc.getBX()] > esDCC_BX_MostFreqCounts) {
0155             esDCC_BX_MostFreqCounts = esDCC_BX_FreqMap[esdcc.getBX()];
0156             gt_BX = esdcc.getBX();
0157           }
0158 
0159           if (esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()] > esDCC_OrbitNumber_MostFreqCounts) {
0160             esDCC_OrbitNumber_MostFreqCounts = esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()];
0161             gt_OrbitNumber = esdcc.getOrbitNumber();
0162           }
0163         }
0164       } else {
0165         LogWarning("ESRawDataTask") << "dccCollections not available";
0166       }
0167     }
0168   } else {
0169     LogWarning("ESRawDataTask") << "FEDRawDataCollection not available";
0170   }
0171 
0172   // DCC
0173   vector<int> fiberStatus;
0174   if (e.getByToken(dccCollections_, dccs)) {
0175     for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
0176       const ESDCCHeaderBlock& dcc = (*dccItr);
0177 
0178       //if (dcc.getRunNumber() != runNum_) {
0179       //meRunNumberErrors_->Fill(dcc.fedId());
0180       //cout<<"Run # err : "<<dcc.getRunNumber()<<" "<<runNum_<<endl;
0181       //}
0182 
0183       if (dcc.getLV1() != gt_L1A) {
0184         meL1ADCCErrors_->Fill(dcc.fedId());
0185         meL1ADCCErrorsByLS_->Fill(dcc.fedId());
0186         Float_t l1a_diff = dcc.getLV1() - gt_L1A;
0187         if (l1a_diff > 100)
0188           l1a_diff = 100;
0189         else if (l1a_diff < -100)
0190           l1a_diff = -100;
0191         meL1ADiff_->Fill(l1a_diff);
0192       }
0193 
0194       if (dcc.getBX() != gt_BX) {
0195         meBXDCCErrors_->Fill(dcc.fedId());
0196         meBXDCCErrorsByLS_->Fill(dcc.fedId());
0197         Float_t bx_diff = dcc.getBX() - gt_BX;
0198         if (bx_diff > 100)
0199           bx_diff = 100;
0200         else if (bx_diff < -100)
0201           bx_diff = -100;
0202         meBXDiff_->Fill(bx_diff);
0203       }
0204       if (dcc.getOrbitNumber() != gt_OrbitNumber) {
0205         meOrbitNumberDCCErrors_->Fill(dcc.fedId());
0206         meOrbitNumberDCCErrorsByLS_->Fill(dcc.fedId());
0207         Float_t orbitnumber_diff = dcc.getOrbitNumber() - gt_OrbitNumber;
0208         if (orbitnumber_diff > 100)
0209           orbitnumber_diff = 100;
0210         else if (orbitnumber_diff < -100)
0211           orbitnumber_diff = -100;
0212         meOrbitNumberDiff_->Fill(orbitnumber_diff);
0213       }
0214     }
0215   }
0216 }
0217 
0218 DEFINE_FWK_MODULE(ESRawDataTask);