CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DQM/EcalPreshowerMonitorModule/src/ESRawDataTask.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include <vector>
00004 
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "FWCore/Framework/interface/MakerMacros.h"
00008 #include "FWCore/Framework/interface/Frameworkfwd.h"
00009 
00010 #include "DQMServices/Core/interface/MonitorElement.h"
00011 #include "DQMServices/Core/interface/DQMStore.h"
00012 
00013 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00014 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00015 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
00016 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
00017 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00018 #include "DataFormats/FEDRawData/src/fed_header.h"
00019 
00020 #include "DataFormats/DetId/interface/DetId.h"
00021 #include "DataFormats/EcalDetId/interface/ESDetId.h"
00022 #include "DataFormats/EcalDigi/interface/ESDataFrame.h"
00023 #include "DataFormats/EcalRawData/interface/ESDCCHeaderBlock.h"
00024 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00025 
00026 #include "DQM/EcalPreshowerMonitorModule/interface/ESRawDataTask.h"
00027 
00028 using namespace cms;
00029 using namespace edm;
00030 using namespace std;
00031 
00032 ESRawDataTask::ESRawDataTask(const ParameterSet& ps) {
00033 
00034    init_ = false;
00035 
00036    dqmStore_ = Service<DQMStore>().operator->();
00037 
00038    prefixME_      = ps.getUntrackedParameter<string>("prefixME", "");
00039    enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00040    mergeRuns_     = ps.getUntrackedParameter<bool>("mergeRuns", false);
00041 
00042    FEDRawDataCollection_ = ps.getParameter<InputTag>("FEDRawDataCollection");
00043    dccCollections_       = ps.getParameter<InputTag>("ESDCCCollections");
00044 
00045 }
00046 
00047 ESRawDataTask::~ESRawDataTask() {
00048 }
00049 
00050 void ESRawDataTask::beginJob(void) {
00051 
00052    ievt_ = 0;
00053 
00054    if ( dqmStore_ ) {
00055       dqmStore_->setCurrentFolder(prefixME_ + "/ESRawDataTask");
00056       dqmStore_->rmdir(prefixME_ + "/ESRawDataTask");
00057    }
00058 
00059 }
00060 
00061 void ESRawDataTask::beginRun(const Run& r, const EventSetup& c) {
00062 
00063    if ( ! mergeRuns_ ) this->reset();
00064 
00065 }
00066 
00067 void ESRawDataTask::endRun(const Run& r, const EventSetup& c) {
00068 
00069 }
00070 
00071 void ESRawDataTask::reset(void) {
00072 
00073 }
00074 
00075 void ESRawDataTask::setup(void){
00076 
00077    init_ = true;
00078 
00079    char histo[200];
00080 
00081    if (dqmStore_) {
00082       dqmStore_->setCurrentFolder(prefixME_ + "/ESRawDataTask");
00083 
00084       //sprintf(histo, "ES run number errors");
00085       //meRunNumberErrors_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5); 
00086       //meRunNumberErrors_->setAxisTitle("ES FED", 1);
00087       //meRunNumberErrors_->setAxisTitle("Num of Events", 2);
00088 
00089       sprintf(histo, "ES L1A DCC errors");
00090       meL1ADCCErrors_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5); 
00091       meL1ADCCErrors_->setAxisTitle("ES FED", 1);
00092       meL1ADCCErrors_->setAxisTitle("Num of Events", 2);
00093 
00094       sprintf(histo, "ES BX DCC errors");
00095       meBXDCCErrors_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5); 
00096       meBXDCCErrors_->setAxisTitle("ES FED", 1);
00097       meBXDCCErrors_->setAxisTitle("Num of Events", 2);
00098 
00099       sprintf(histo, "ES Orbit Number DCC errors");
00100       meOrbitNumberDCCErrors_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5); 
00101       meOrbitNumberDCCErrors_->setAxisTitle("ES FED", 1);
00102       meOrbitNumberDCCErrors_->setAxisTitle("Num of Events", 2);
00103       
00104       sprintf(histo, "Difference between ES and GT L1A");
00105       meL1ADiff_ = dqmStore_->book1D(histo, histo, 201, -100.5, 100.5);
00106       meL1ADiff_->setAxisTitle("ES - GT L1A", 1);
00107       meL1ADiff_->setAxisTitle("Num of Events", 2);
00108 
00109       sprintf(histo, "Difference between ES and GT BX");
00110       meBXDiff_ = dqmStore_->book1D(histo, histo, 201, -100.5, 100.5);
00111       meBXDiff_->setAxisTitle("ES - GT BX", 1);
00112       meBXDiff_->setAxisTitle("Num of Events", 2);
00113 
00114       sprintf(histo, "Difference between ES and GT Orbit Number");
00115       meOrbitNumberDiff_ = dqmStore_->book1D(histo, histo, 201, -100.5, 100.5);
00116       meOrbitNumberDiff_->setAxisTitle("ES - GT orbit number", 1);
00117       meOrbitNumberDiff_->setAxisTitle("Num of Events", 2);
00118    }
00119 
00120 }
00121 
00122 void ESRawDataTask::cleanup(void){
00123 
00124    if ( ! init_ ) return;
00125 
00126    if ( dqmStore_ ) {
00127      //if ( meRunNumberErrors_ ) dqmStore_->removeElement( meRunNumberErrors_->getName() );
00128      //meRunNumberErrors_ = 0;
00129 
00130      if ( meL1ADCCErrors_ ) dqmStore_->removeElement( meL1ADCCErrors_->getName() );
00131      meL1ADCCErrors_ = 0;
00132 
00133      if ( meBXDCCErrors_ ) dqmStore_->removeElement( meBXDCCErrors_->getName() );
00134      meBXDCCErrors_ = 0;
00135 
00136      if ( meOrbitNumberDCCErrors_ ) dqmStore_->removeElement( meOrbitNumberDCCErrors_->getName() );
00137      meOrbitNumberDCCErrors_ = 0;
00138 
00139      if ( meL1ADiff_ ) dqmStore_->removeElement( meL1ADiff_->getName() );
00140      meL1ADiff_ = 0;
00141 
00142      if ( meBXDiff_ ) dqmStore_->removeElement( meBXDiff_->getName() );
00143      meBXDiff_ = 0;
00144 
00145      if ( meOrbitNumberDiff_ ) dqmStore_->removeElement( meOrbitNumberDiff_->getName() );
00146      meOrbitNumberDiff_ = 0;
00147    }
00148 
00149    init_ = false;
00150 
00151 }
00152 
00153 void ESRawDataTask::endJob(void){
00154 
00155    LogInfo("ESRawDataTask") << "analyzed " << ievt_ << " events";
00156 
00157    if ( enableCleanup_ ) this->cleanup();
00158 
00159 }
00160 
00161 void ESRawDataTask::analyze(const Event& e, const EventSetup& c){
00162 
00163    if ( ! init_ ) this->setup();
00164 
00165    ievt_++;
00166    runNum_ = e.id().run();
00167 
00168    int gt_L1A = 0, gt_OrbitNumber = 0, gt_BX = 0;
00169    int esDCC_L1A_MostFreqCounts = 0;
00170    int esDCC_BX_MostFreqCounts = 0;
00171    int esDCC_OrbitNumber_MostFreqCounts = 0;
00172 
00173    Handle<ESRawDataCollection> dccs;
00174    Handle<FEDRawDataCollection> allFedRawData;
00175 
00176    int gtFedDataSize = 0;
00177    
00178    if ( e.getByLabel(FEDRawDataCollection_, allFedRawData) ) {
00179      
00180      // GT FED data
00181      const FEDRawData& gtFedData = allFedRawData->FEDData(812);
00182      
00183      gtFedDataSize = gtFedData.size()/sizeof(uint64_t);
00184      
00185      if ( gtFedDataSize > 0 ) {
00186        
00187        FEDHeader header(gtFedData.data());
00188        
00189        gt_L1A         = header.lvl1ID();
00190        gt_OrbitNumber = e.orbitNumber();
00191        gt_BX          = e.bunchCrossing();
00192      } else {
00193 
00194        map<int, int> esDCC_L1A_FreqMap;
00195        map<int, int> esDCC_BX_FreqMap;
00196        map<int, int> esDCC_OrbitNumber_FreqMap;
00197 
00198        if ( e.getByLabel(dccCollections_, dccs) ) {
00199          for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
00200            ESDCCHeaderBlock esdcc = (*dccItr);
00201            
00202            esDCC_L1A_FreqMap[esdcc.getLV1()]++;
00203            esDCC_BX_FreqMap[esdcc.getBX()]++;
00204            esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()]++;
00205            
00206            if (esDCC_L1A_FreqMap[esdcc.getLV1()] > esDCC_L1A_MostFreqCounts) {
00207              esDCC_L1A_MostFreqCounts = esDCC_L1A_FreqMap[esdcc.getLV1()];
00208              gt_L1A = esdcc.getLV1();
00209            } 
00210            
00211            if (esDCC_BX_FreqMap[esdcc.getBX()] > esDCC_BX_MostFreqCounts) {
00212              esDCC_BX_MostFreqCounts = esDCC_BX_FreqMap[esdcc.getBX()];
00213              gt_BX = esdcc.getBX();
00214            } 
00215            
00216            if (esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()] > esDCC_OrbitNumber_MostFreqCounts) {
00217              esDCC_OrbitNumber_MostFreqCounts = esDCC_OrbitNumber_FreqMap[esdcc.getOrbitNumber()];
00218              gt_OrbitNumber = esdcc.getOrbitNumber();
00219            } 
00220            
00221          }
00222        } else {
00223          LogWarning("ESRawDataTask") << dccCollections_ << " not available";
00224        }
00225 
00226      }
00227    } else {
00228      LogWarning("ESRawDataTask") << FEDRawDataCollection_ << " not available";
00229    }
00230 
00231    // DCC 
00232    vector<int> fiberStatus;
00233    if ( e.getByLabel(dccCollections_, dccs) ) {
00234      
00235      for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
00236        ESDCCHeaderBlock dcc = (*dccItr);
00237        
00238        //if (dcc.getRunNumber() != runNum_) {
00239        //meRunNumberErrors_->Fill(dcc.fedId());
00240        //cout<<"Run # err : "<<dcc.getRunNumber()<<" "<<runNum_<<endl;
00241        //}
00242        
00243        if (dcc.getLV1() != gt_L1A) {
00244          meL1ADCCErrors_->Fill(dcc.fedId());
00245          //cout<<"L1A err : "<<dcc.getLV1()<<" "<<gt_L1A<<endl;
00246          Float_t l1a_diff = dcc.getLV1() - gt_L1A;
00247          if (l1a_diff > 100) l1a_diff = 100;
00248          else if (l1a_diff < -100) l1a_diff = -100;
00249          meL1ADiff_->Fill(l1a_diff);
00250        }
00251        
00252        if (dcc.getBX() != gt_BX) {
00253          meBXDCCErrors_->Fill(dcc.fedId());
00254          //cout<<"BX err : "<<dcc.getBX()<<" "<<gt_BX<<endl;
00255          Float_t bx_diff = dcc.getBX() - gt_BX;
00256          if (bx_diff > 100) bx_diff = 100;
00257          else if (bx_diff < -100) bx_diff = -100;
00258          meBXDiff_->Fill(bx_diff);
00259        }
00260        if (dcc.getOrbitNumber() != gt_OrbitNumber) {
00261          meOrbitNumberDCCErrors_->Fill(dcc.fedId());
00262          //cout<<"Orbit err : "<<dcc.getOrbitNumber()<<" "<<gt_OrbitNumber<<endl;
00263          Float_t orbitnumber_diff = dcc.getOrbitNumber() - gt_OrbitNumber;
00264          if (orbitnumber_diff > 100) orbitnumber_diff = 100;
00265          else if (orbitnumber_diff < -100) orbitnumber_diff = -100;
00266          meOrbitNumberDiff_->Fill(orbitnumber_diff);
00267        }
00268      }
00269    }
00270 
00271 }
00272 
00273 DEFINE_FWK_MODULE(ESRawDataTask);