Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:10:04

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 void ESRawDataTask::bookHistograms(DQMStore::IBooker& iBooker, Run const&, EventSetup const&) {
0038   char histo[200];
0039 
0040   iBooker.setCurrentFolder(prefixME_ + "/ESRawDataTask");
0041 
0042   //sprintf(histo, "ES run number errors");
0043   //meRunNumberErrors_ = iBooker.book1D(histo, histo, 56, 519.5, 575.5);
0044   //meRunNumberErrors_->setAxisTitle("ES FED", 1);
0045   //meRunNumberErrors_->setAxisTitle("Num of Events", 2);
0046 
0047   sprintf(histo, "ES L1A DCC errors");
0048   meL1ADCCErrors_ = iBooker.book1D(histo, histo, 56, 519.5, 575.5);
0049   meL1ADCCErrors_->setAxisTitle("ES FED", 1);
0050   meL1ADCCErrors_->setAxisTitle("Num of Events", 2);
0051 
0052   sprintf(histo, "ES BX DCC errors");
0053   meBXDCCErrors_ = iBooker.book1D(histo, histo, 56, 519.5, 575.5);
0054   meBXDCCErrors_->setAxisTitle("ES FED", 1);
0055   meBXDCCErrors_->setAxisTitle("Num of Events", 2);
0056 
0057   sprintf(histo, "ES Orbit Number DCC errors");
0058   meOrbitNumberDCCErrors_ = iBooker.book1D(histo, histo, 56, 519.5, 575.5);
0059   meOrbitNumberDCCErrors_->setAxisTitle("ES FED", 1);
0060   meOrbitNumberDCCErrors_->setAxisTitle("Num of Events", 2);
0061 
0062   sprintf(histo, "Difference between ES and GT L1A");
0063   meL1ADiff_ = iBooker.book1D(histo, histo, 201, -100.5, 100.5);
0064   meL1ADiff_->setAxisTitle("ES - GT L1A", 1);
0065   meL1ADiff_->setAxisTitle("Num of Events", 2);
0066 
0067   sprintf(histo, "Difference between ES and GT BX");
0068   meBXDiff_ = iBooker.book1D(histo, histo, 201, -100.5, 100.5);
0069   meBXDiff_->setAxisTitle("ES - GT BX", 1);
0070   meBXDiff_->setAxisTitle("Num of Events", 2);
0071 
0072   sprintf(histo, "Difference between ES and GT Orbit Number");
0073   meOrbitNumberDiff_ = iBooker.book1D(histo, histo, 201, -100.5, 100.5);
0074   meOrbitNumberDiff_->setAxisTitle("ES - GT orbit number", 1);
0075   meOrbitNumberDiff_->setAxisTitle("Num of Events", 2);
0076 }
0077 
0078 void ESRawDataTask::analyze(const Event& e, const EventSetup& c) {
0079   ievt_++;
0080   runNum_ = e.id().run();
0081 
0082   int gt_L1A = 0, gt_OrbitNumber = 0, gt_BX = 0;
0083   int esDCC_L1A_MostFreqCounts = 0;
0084   int esDCC_BX_MostFreqCounts = 0;
0085   int esDCC_OrbitNumber_MostFreqCounts = 0;
0086 
0087   Handle<ESRawDataCollection> dccs;
0088   Handle<FEDRawDataCollection> allFedRawData;
0089 
0090   int gtFedDataSize = 0;
0091 
0092   if (e.getByToken(FEDRawDataCollection_, allFedRawData)) {
0093     // GT FED data
0094     const FEDRawData& gtFedData = allFedRawData->FEDData(812);
0095 
0096     gtFedDataSize = gtFedData.size() / sizeof(uint64_t);
0097 
0098     if (gtFedDataSize > 0) {
0099       FEDHeader header(gtFedData.data());
0100 
0101       gt_L1A = header.lvl1ID();
0102       gt_OrbitNumber = e.orbitNumber();
0103       gt_BX = e.bunchCrossing();
0104     } else {
0105       map<int, int> esDCC_L1A_FreqMap;
0106       map<int, int> esDCC_BX_FreqMap;
0107       map<int, int> esDCC_OrbitNumber_FreqMap;
0108 
0109       if (e.getByToken(dccCollections_, dccs)) {
0110         for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
0111           ESDCCHeaderBlock esdcc = (*dccItr);
0112 
0113           esDCC_L1A_FreqMap[esdcc.getLV1()]++;
0114           esDCC_BX_FreqMap[esdcc.getBX()]++;
0115           esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()]++;
0116 
0117           if (esDCC_L1A_FreqMap[esdcc.getLV1()] > esDCC_L1A_MostFreqCounts) {
0118             esDCC_L1A_MostFreqCounts = esDCC_L1A_FreqMap[esdcc.getLV1()];
0119             gt_L1A = esdcc.getLV1();
0120           }
0121 
0122           if (esDCC_BX_FreqMap[esdcc.getBX()] > esDCC_BX_MostFreqCounts) {
0123             esDCC_BX_MostFreqCounts = esDCC_BX_FreqMap[esdcc.getBX()];
0124             gt_BX = esdcc.getBX();
0125           }
0126 
0127           if (esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()] > esDCC_OrbitNumber_MostFreqCounts) {
0128             esDCC_OrbitNumber_MostFreqCounts = esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()];
0129             gt_OrbitNumber = esdcc.getOrbitNumber();
0130           }
0131         }
0132       } else {
0133         LogWarning("ESRawDataTask") << "dccCollections not available";
0134       }
0135     }
0136   } else {
0137     LogWarning("ESRawDataTask") << "FEDRawDataCollection not available";
0138   }
0139 
0140   // DCC
0141   vector<int> fiberStatus;
0142   if (e.getByToken(dccCollections_, dccs)) {
0143     for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
0144       ESDCCHeaderBlock dcc = (*dccItr);
0145 
0146       //if (dcc.getRunNumber() != runNum_) {
0147       //meRunNumberErrors_->Fill(dcc.fedId());
0148       //cout<<"Run # err : "<<dcc.getRunNumber()<<" "<<runNum_<<endl;
0149       //}
0150 
0151       if (dcc.getLV1() != gt_L1A) {
0152         meL1ADCCErrors_->Fill(dcc.fedId());
0153         //cout<<"L1A err : "<<dcc.getLV1()<<" "<<gt_L1A<<endl;
0154         Float_t l1a_diff = dcc.getLV1() - gt_L1A;
0155         if (l1a_diff > 100)
0156           l1a_diff = 100;
0157         else if (l1a_diff < -100)
0158           l1a_diff = -100;
0159         meL1ADiff_->Fill(l1a_diff);
0160       }
0161 
0162       if (dcc.getBX() != gt_BX) {
0163         meBXDCCErrors_->Fill(dcc.fedId());
0164         //cout<<"BX err : "<<dcc.getBX()<<" "<<gt_BX<<endl;
0165         Float_t bx_diff = dcc.getBX() - gt_BX;
0166         if (bx_diff > 100)
0167           bx_diff = 100;
0168         else if (bx_diff < -100)
0169           bx_diff = -100;
0170         meBXDiff_->Fill(bx_diff);
0171       }
0172       if (dcc.getOrbitNumber() != gt_OrbitNumber) {
0173         meOrbitNumberDCCErrors_->Fill(dcc.fedId());
0174         //cout<<"Orbit err : "<<dcc.getOrbitNumber()<<" "<<gt_OrbitNumber<<endl;
0175         Float_t orbitnumber_diff = dcc.getOrbitNumber() - gt_OrbitNumber;
0176         if (orbitnumber_diff > 100)
0177           orbitnumber_diff = 100;
0178         else if (orbitnumber_diff < -100)
0179           orbitnumber_diff = -100;
0180         meOrbitNumberDiff_->Fill(orbitnumber_diff);
0181       }
0182     }
0183   }
0184 }
0185 
0186 DEFINE_FWK_MODULE(ESRawDataTask);