CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/DQM/EcalBarrelMonitorTasks/src/EBRawDataTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EBRawDataTask.cc
00003  *
00004  * $Date: 2012/06/28 12:14:29 $
00005  * $Revision: 1.48 $
00006  * \author E. Di Marco
00007  *
00008 */
00009 
00010 #include <iostream>
00011 #include <vector>
00012 
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include "FWCore/Framework/interface/LuminosityBlock.h"
00016 
00017 #include "DQMServices/Core/interface/MonitorElement.h"
00018 
00019 #include "DQMServices/Core/interface/DQMStore.h"
00020 
00021 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00022 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00023 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
00024 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
00025 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00026 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00027 #include "DataFormats/FEDRawData/src/fed_header.h"
00028 
00029 #include "DQM/EcalCommon/interface/Numbers.h"
00030 
00031 #include "DQM/EcalBarrelMonitorTasks/interface/EBRawDataTask.h"
00032 
00033 EBRawDataTask::EBRawDataTask(const edm::ParameterSet& ps) {
00034 
00035   init_ = false;
00036 
00037   dqmStore_ = edm::Service<DQMStore>().operator->();
00038 
00039   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00040 
00041   subfolder_ = ps.getUntrackedParameter<std::string>("subfolder", "");
00042 
00043   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00044 
00045   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00046 
00047   FEDRawDataCollection_ = ps.getParameter<edm::InputTag>("FEDRawDataCollection");
00048   EcalRawDataCollection_ = ps.getParameter<edm::InputTag>("EcalRawDataCollection");
00049 
00050   meEBEventTypePreCalibrationBX_ = 0;
00051   meEBEventTypeCalibrationBX_ = 0;
00052   meEBEventTypePostCalibrationBX_ = 0;
00053   meEBCRCErrors_ = 0;
00054   meEBRunNumberErrors_ = 0;
00055   meEBOrbitNumberErrors_ = 0;
00056   meEBTriggerTypeErrors_ = 0;
00057   meEBCalibrationEventErrors_ = 0;
00058   meEBL1ADCCErrors_ = 0;
00059   meEBBunchCrossingDCCErrors_ = 0;
00060   meEBL1AFEErrors_ = 0;
00061   meEBBunchCrossingFEErrors_ = 0;
00062   meEBL1ATCCErrors_ = 0;
00063   meEBBunchCrossingTCCErrors_ = 0;
00064   meEBL1ASRPErrors_ = 0;
00065   meEBBunchCrossingSRPErrors_ = 0;
00066 
00067   meEBSynchronizationErrorsByLumi_ = 0;
00068 
00069   meEBSynchronizationErrorsTrend_ = 0;
00070 
00071   calibrationBX_ = 3490;
00072 
00073 }
00074 
00075 EBRawDataTask::~EBRawDataTask() {
00076 }
00077 
00078 void EBRawDataTask::beginJob(void){
00079 
00080   ievt_ = 0;
00081 
00082   if ( dqmStore_ ) {
00083     dqmStore_->setCurrentFolder(prefixME_ + "/EBRawDataTask");
00084     if(subfolder_.size())
00085       dqmStore_->setCurrentFolder(prefixME_ + "/EBRawDataTask/" + subfolder_);
00086     dqmStore_->rmdir(prefixME_ + "/EBRawDataTask");
00087   }
00088 
00089 }
00090 
00091 void EBRawDataTask::beginLuminosityBlock(const edm::LuminosityBlock& _lumi, const  edm::EventSetup&) {
00092 
00093   if ( ! init_ ) this->setup();
00094 
00095   ls_ = _lumi.luminosityBlock();
00096 
00097   if ( meEBSynchronizationErrorsByLumi_ ) meEBSynchronizationErrorsByLumi_->Reset();
00098 
00099   if ( meEBSynchronizationErrorsTrend_ ){
00100     int bin(meEBSynchronizationErrorsTrend_->getTH1()->GetXaxis()->FindBin(ls_ - 0.5));
00101     meEBSynchronizationErrorsTrend_->setBinContent(bin - 1, fatalErrors_);
00102     meEBSynchronizationErrorsTrend_->getTH1()->SetEntries(fatalErrors_);
00103   }
00104 
00105 }
00106 
00107 void EBRawDataTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00108 
00109   Numbers::initGeometry(c, false);
00110 
00111   if ( ! mergeRuns_ ) this->reset();
00112 
00113   fatalErrors_ = 0.;
00114 
00115   if ( meEBSynchronizationErrorsTrend_ ){
00116     meEBSynchronizationErrorsTrend_->getTH1()->GetXaxis()->SetLimits(0., 50.);
00117   }
00118 }
00119 
00120 void EBRawDataTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00121 }
00122 
00123 void EBRawDataTask::reset(void) {
00124 
00125   if ( meEBEventTypePreCalibrationBX_ ) meEBEventTypePreCalibrationBX_->Reset();
00126   if ( meEBEventTypeCalibrationBX_ ) meEBEventTypeCalibrationBX_->Reset();
00127   if ( meEBEventTypePostCalibrationBX_ ) meEBEventTypePostCalibrationBX_->Reset();
00128   if ( meEBCRCErrors_ ) meEBCRCErrors_->Reset();
00129   if ( meEBRunNumberErrors_ ) meEBRunNumberErrors_->Reset();
00130   if ( meEBOrbitNumberErrors_ ) meEBOrbitNumberErrors_->Reset();
00131   if ( meEBTriggerTypeErrors_ ) meEBTriggerTypeErrors_->Reset();
00132   if ( meEBCalibrationEventErrors_ ) meEBCalibrationEventErrors_->Reset();
00133   if ( meEBL1ADCCErrors_ ) meEBL1ADCCErrors_->Reset();
00134   if ( meEBBunchCrossingDCCErrors_ ) meEBBunchCrossingDCCErrors_->Reset();
00135   if ( meEBL1AFEErrors_ ) meEBL1AFEErrors_->Reset();
00136   if ( meEBBunchCrossingFEErrors_ ) meEBBunchCrossingFEErrors_->Reset();
00137   if ( meEBL1ATCCErrors_ ) meEBL1ATCCErrors_->Reset();
00138   if ( meEBBunchCrossingTCCErrors_ ) meEBBunchCrossingTCCErrors_->Reset();
00139   if ( meEBL1ASRPErrors_ ) meEBL1ASRPErrors_->Reset();
00140   if ( meEBBunchCrossingSRPErrors_ ) meEBBunchCrossingSRPErrors_->Reset();
00141   if ( meEBSynchronizationErrorsByLumi_ ) meEBSynchronizationErrorsByLumi_->Reset();
00142   if ( meEBSynchronizationErrorsTrend_ ) meEBSynchronizationErrorsTrend_->Reset();
00143 }
00144 
00145 void EBRawDataTask::setup(void){
00146 
00147   init_ = true;
00148 
00149   std::string name;
00150 
00151   if ( dqmStore_ ) {
00152     dqmStore_->setCurrentFolder(prefixME_ + "/EBRawDataTask");
00153     if(subfolder_.size())
00154       dqmStore_->setCurrentFolder(prefixME_ + "/EBRawDataTask/" + subfolder_);
00155 
00156     name = "EBRDT event type pre calibration BX";
00157     meEBEventTypePreCalibrationBX_ = dqmStore_->book1D(name, name, 31, -1., 30.);
00158     meEBEventTypePreCalibrationBX_->setBinLabel(1, "UNKNOWN", 1);
00159     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::COSMIC, "COSMIC", 1);
00160     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::BEAMH4, "BEAMH4", 1);
00161     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::BEAMH2, "BEAMH2", 1);
00162     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::MTCC, "MTCC", 1);
00163     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LASER_STD, "LASER_STD", 1);
00164     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LASER_POWER_SCAN, "LASER_POWER_SCAN", 1);
00165     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LASER_DELAY_SCAN, "LASER_DELAY_SCAN", 1);
00166     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::TESTPULSE_SCAN_MEM, "TESTPULSE_SCAN_MEM", 1);
00167     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::TESTPULSE_MGPA, "TESTPULSE_MGPA", 1);
00168     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_STD, "PEDESTAL_STD", 1);
00169     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN, "PEDESTAL_OFFSET_SCAN", 1);
00170     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_25NS_SCAN, "PEDESTAL_25NS_SCAN", 1);
00171     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LED_STD, "LED_STD", 1);
00172     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PHYSICS_GLOBAL, "PHYSICS_GLOBAL", 1);
00173     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::COSMICS_GLOBAL, "COSMICS_GLOBAL", 1);
00174     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::HALO_GLOBAL, "HALO_GLOBAL", 1);
00175     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LASER_GAP, "LASER_GAP", 1);
00176     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::TESTPULSE_GAP, "TESTPULSE_GAP");
00177     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_GAP, "PEDESTAL_GAP");
00178     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LED_GAP, "LED_GAP", 1);
00179     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PHYSICS_LOCAL, "PHYSICS_LOCAL", 1);
00180     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::COSMICS_LOCAL, "COSMICS_LOCAL", 1);
00181     meEBEventTypePreCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::HALO_LOCAL, "HALO_LOCAL", 1);
00182 
00183     name = "EBRDT event type calibration BX";
00184     meEBEventTypeCalibrationBX_ = dqmStore_->book1D(name, name, 31, -1., 30.);
00185     meEBEventTypeCalibrationBX_->setBinLabel(1, "UNKNOWN", 1);
00186     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::COSMIC, "COSMIC", 1);
00187     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::BEAMH4, "BEAMH4", 1);
00188     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::BEAMH2, "BEAMH2", 1);
00189     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::MTCC, "MTCC", 1);
00190     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LASER_STD, "LASER_STD", 1);
00191     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LASER_POWER_SCAN, "LASER_POWER_SCAN", 1);
00192     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LASER_DELAY_SCAN, "LASER_DELAY_SCAN", 1);
00193     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::TESTPULSE_SCAN_MEM, "TESTPULSE_SCAN_MEM", 1);
00194     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::TESTPULSE_MGPA, "TESTPULSE_MGPA", 1);
00195     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_STD, "PEDESTAL_STD", 1);
00196     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN, "PEDESTAL_OFFSET_SCAN", 1);
00197     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_25NS_SCAN, "PEDESTAL_25NS_SCAN", 1);
00198     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LED_STD, "LED_STD", 1);
00199     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PHYSICS_GLOBAL, "PHYSICS_GLOBAL", 1);
00200     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::COSMICS_GLOBAL, "COSMICS_GLOBAL", 1);
00201     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::HALO_GLOBAL, "HALO_GLOBAL", 1);
00202     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LASER_GAP, "LASER_GAP", 1);
00203     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::TESTPULSE_GAP, "TESTPULSE_GAP");
00204     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_GAP, "PEDESTAL_GAP");
00205     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LED_GAP, "LED_GAP", 1);
00206     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PHYSICS_LOCAL, "PHYSICS_LOCAL", 1);
00207     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::COSMICS_LOCAL, "COSMICS_LOCAL", 1);
00208     meEBEventTypeCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::HALO_LOCAL, "HALO_LOCAL", 1);
00209 
00210     name = "EBRDT event type post calibration BX";
00211     meEBEventTypePostCalibrationBX_ = dqmStore_->book1D(name, name, 31, -1., 30.);
00212     meEBEventTypePostCalibrationBX_->setBinLabel(1, "UNKNOWN", 1);
00213     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::COSMIC, "COSMIC", 1);
00214     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::BEAMH4, "BEAMH4", 1);
00215     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::BEAMH2, "BEAMH2", 1);
00216     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::MTCC, "MTCC", 1);
00217     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LASER_STD, "LASER_STD", 1);
00218     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LASER_POWER_SCAN, "LASER_POWER_SCAN", 1);
00219     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LASER_DELAY_SCAN, "LASER_DELAY_SCAN", 1);
00220     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::TESTPULSE_SCAN_MEM, "TESTPULSE_SCAN_MEM", 1);
00221     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::TESTPULSE_MGPA, "TESTPULSE_MGPA", 1);
00222     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_STD, "PEDESTAL_STD", 1);
00223     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN, "PEDESTAL_OFFSET_SCAN", 1);
00224     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_25NS_SCAN, "PEDESTAL_25NS_SCAN", 1);
00225     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LED_STD, "LED_STD", 1);
00226     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PHYSICS_GLOBAL, "PHYSICS_GLOBAL", 1);
00227     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::COSMICS_GLOBAL, "COSMICS_GLOBAL", 1);
00228     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::HALO_GLOBAL, "HALO_GLOBAL", 1);
00229     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LASER_GAP, "LASER_GAP", 1);
00230     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::TESTPULSE_GAP, "TESTPULSE_GAP");
00231     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_GAP, "PEDESTAL_GAP");
00232     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::LED_GAP, "LED_GAP", 1);
00233     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::PHYSICS_LOCAL, "PHYSICS_LOCAL", 1);
00234     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::COSMICS_LOCAL, "COSMICS_LOCAL", 1);
00235     meEBEventTypePostCalibrationBX_->setBinLabel(2+EcalDCCHeaderBlock::HALO_LOCAL, "HALO_LOCAL", 1);
00236 
00237     name = "EBRDT CRC errors";
00238     meEBCRCErrors_ = dqmStore_->book1D(name, name, 36, 1, 37);
00239     for (int i = 0; i < 36; i++) {
00240       meEBCRCErrors_->setBinLabel(i+1, Numbers::sEB(i+1), 1);
00241     }
00242 
00243     name = "EBRDT run number errors";
00244     meEBRunNumberErrors_ = dqmStore_->book1D(name, name, 36, 1, 37);
00245     for (int i = 0; i < 36; i++) {
00246       meEBRunNumberErrors_->setBinLabel(i+1, Numbers::sEB(i+1), 1);
00247     }
00248 
00249     name = "EBRDT orbit number errors";
00250     meEBOrbitNumberErrors_ = dqmStore_->book1D(name, name, 36, 1, 37);
00251     for (int i = 0; i < 36; i++) {
00252       meEBOrbitNumberErrors_->setBinLabel(i+1, Numbers::sEB(i+1), 1);
00253     }
00254 
00255     name = "EBRDT trigger type errors";
00256     meEBTriggerTypeErrors_ = dqmStore_->book1D(name, name, 36, 1, 37);
00257     for (int i = 0; i < 36; i++) {
00258       meEBTriggerTypeErrors_->setBinLabel(i+1, Numbers::sEB(i+1), 1);
00259     }
00260 
00261     name = "EBRDT calibration event errors";
00262     meEBCalibrationEventErrors_ = dqmStore_->book1D(name, name, 36, 1, 37);
00263     for (int i = 0; i < 36; i++) {
00264       meEBCalibrationEventErrors_->setBinLabel(i+1, Numbers::sEB(i+1), 1);
00265     }
00266 
00267     name = "EBRDT L1A DCC errors";
00268     meEBL1ADCCErrors_ = dqmStore_->book1D(name, name, 36, 1, 37);
00269     for (int i = 0; i < 36; i++) {
00270       meEBL1ADCCErrors_->setBinLabel(i+1, Numbers::sEB(i+1), 1);
00271     }
00272 
00273     name = "EBRDT bunch crossing DCC errors";
00274     meEBBunchCrossingDCCErrors_ = dqmStore_->book1D(name, name, 36, 1, 37);
00275     for (int i = 0; i < 36; i++) {
00276       meEBBunchCrossingDCCErrors_->setBinLabel(i+1, Numbers::sEB(i+1), 1);
00277     }
00278 
00279     name = "EBRDT L1A FE errors";
00280     meEBL1AFEErrors_ = dqmStore_->book1D(name, name, 36, 1, 37);
00281     for (int i = 0; i < 36; i++) {
00282       meEBL1AFEErrors_->setBinLabel(i+1, Numbers::sEB(i+1), 1);
00283     }
00284 
00285     name = "EBRDT bunch crossing FE errors";
00286     meEBBunchCrossingFEErrors_ = dqmStore_->book1D(name, name, 36, 1, 37);
00287     for (int i = 0; i < 36; i++) {
00288       meEBBunchCrossingFEErrors_->setBinLabel(i+1, Numbers::sEB(i+1), 1);
00289     }
00290 
00291     name = "EBRDT L1A TCC errors";
00292     meEBL1ATCCErrors_ = dqmStore_->book1D(name, name, 36, 1, 37);
00293     for (int i = 0; i < 36; i++) {
00294       meEBL1ATCCErrors_->setBinLabel(i+1, Numbers::sEB(i+1), 1);
00295     }
00296 
00297     name = "EBRDT bunch crossing TCC errors";
00298     meEBBunchCrossingTCCErrors_ = dqmStore_->book1D(name, name, 36, 1, 37);
00299     for (int i = 0; i < 36; i++) {
00300       meEBBunchCrossingTCCErrors_->setBinLabel(i+1, Numbers::sEB(i+1), 1);
00301     }
00302 
00303     name = "EBRDT L1A SRP errors";
00304     meEBL1ASRPErrors_ = dqmStore_->book1D(name, name, 36, 1, 37);
00305     for (int i = 0; i < 36; i++) {
00306       meEBL1ASRPErrors_->setBinLabel(i+1, Numbers::sEB(i+1), 1);
00307     }
00308 
00309     name = "EBRDT bunch crossing SRP errors";
00310     meEBBunchCrossingSRPErrors_ = dqmStore_->book1D(name, name, 36, 1, 37);
00311     for (int i = 0; i < 36; i++) {
00312       meEBBunchCrossingSRPErrors_->setBinLabel(i+1, Numbers::sEB(i+1), 1);
00313     }
00314 
00315     name = "EBRDT FE synchronization errors by lumi";
00316     meEBSynchronizationErrorsByLumi_ = dqmStore_->book1D(name, name, 36, 1, 37);
00317     meEBSynchronizationErrorsByLumi_->setLumiFlag();
00318     for (int i = 0; i < 36; i++) {
00319       meEBSynchronizationErrorsByLumi_->setBinLabel(i+1, Numbers::sEB(i+1), 1);
00320     }
00321 
00322     name = "EBRDT accumulated FE synchronization errors";
00323     meEBSynchronizationErrorsTrend_ = dqmStore_->book1D(name, name, 50, 0., 50.);
00324     meEBSynchronizationErrorsTrend_->setAxisTitle("LumiSection", 1);
00325 
00326   }
00327 
00328 }
00329 
00330 void EBRawDataTask::cleanup(void){
00331 
00332   if ( ! init_ ) return;
00333 
00334   if ( dqmStore_ ) {
00335     dqmStore_->setCurrentFolder(prefixME_ + "/EBRawDataTask");
00336     if(subfolder_.size())
00337       dqmStore_->setCurrentFolder(prefixME_ + "/EBRawDataTask/" + subfolder_);
00338 
00339     if ( meEBEventTypePreCalibrationBX_ ) dqmStore_->removeElement( meEBEventTypePreCalibrationBX_->getName() );
00340     meEBEventTypePreCalibrationBX_ = 0;
00341 
00342     if ( meEBEventTypeCalibrationBX_ ) dqmStore_->removeElement( meEBEventTypeCalibrationBX_->getName() );
00343     meEBEventTypeCalibrationBX_ = 0;
00344 
00345     if ( meEBEventTypePostCalibrationBX_ ) dqmStore_->removeElement( meEBEventTypePostCalibrationBX_->getName() );
00346     meEBEventTypePostCalibrationBX_ = 0;
00347 
00348     if ( meEBCRCErrors_ ) dqmStore_->removeElement( meEBCRCErrors_->getName() );
00349     meEBCRCErrors_ = 0;
00350 
00351     if ( meEBRunNumberErrors_ ) dqmStore_->removeElement( meEBRunNumberErrors_->getName() );
00352     meEBRunNumberErrors_ = 0;
00353 
00354     if ( meEBOrbitNumberErrors_ ) dqmStore_->removeElement( meEBOrbitNumberErrors_->getName() );
00355     meEBOrbitNumberErrors_ = 0;
00356 
00357     if ( meEBTriggerTypeErrors_ ) dqmStore_->removeElement( meEBTriggerTypeErrors_->getName() );
00358     meEBTriggerTypeErrors_ = 0;
00359 
00360     if ( meEBCalibrationEventErrors_ ) dqmStore_->removeElement( meEBCalibrationEventErrors_->getName() );
00361     meEBCalibrationEventErrors_ = 0;
00362 
00363     if ( meEBL1ADCCErrors_ ) dqmStore_->removeElement( meEBL1ADCCErrors_->getName() );
00364     meEBL1ADCCErrors_ = 0;
00365 
00366     if ( meEBBunchCrossingDCCErrors_ ) dqmStore_->removeElement( meEBBunchCrossingDCCErrors_->getName() );
00367     meEBBunchCrossingDCCErrors_ = 0;
00368 
00369     if ( meEBL1AFEErrors_ ) dqmStore_->removeElement( meEBL1AFEErrors_->getName() );
00370     meEBL1AFEErrors_ = 0;
00371 
00372     if ( meEBBunchCrossingFEErrors_ ) dqmStore_->removeElement( meEBBunchCrossingFEErrors_->getName() );
00373     meEBBunchCrossingFEErrors_ = 0;
00374 
00375     if ( meEBL1ATCCErrors_ ) dqmStore_->removeElement( meEBL1ATCCErrors_->getName() );
00376     meEBL1ATCCErrors_ = 0;
00377 
00378     if ( meEBBunchCrossingTCCErrors_ ) dqmStore_->removeElement( meEBBunchCrossingTCCErrors_->getName() );
00379     meEBBunchCrossingTCCErrors_ = 0;
00380 
00381     if ( meEBL1ASRPErrors_ ) dqmStore_->removeElement( meEBL1ASRPErrors_->getName() );
00382     meEBL1ASRPErrors_ = 0;
00383 
00384     if ( meEBBunchCrossingSRPErrors_ ) dqmStore_->removeElement( meEBBunchCrossingSRPErrors_->getName() );
00385     meEBBunchCrossingSRPErrors_ = 0;
00386 
00387     if ( meEBSynchronizationErrorsByLumi_ ) dqmStore_->removeElement( meEBSynchronizationErrorsByLumi_->getName() );
00388     meEBSynchronizationErrorsByLumi_ = 0;
00389 
00390     if ( meEBSynchronizationErrorsTrend_ ) dqmStore_->removeElement( meEBSynchronizationErrorsTrend_->getName() );
00391     meEBSynchronizationErrorsTrend_ = 0;
00392   }
00393 
00394   init_ = false;
00395 
00396 }
00397 
00398 void EBRawDataTask::endLuminosityBlock(const edm::LuminosityBlock&, const  edm::EventSetup&) {
00399 
00400   MonitorElement* me(meEBSynchronizationErrorsTrend_);
00401   if(!me) return;
00402   if(ls_ >= 50){
00403     for(int ix(1); ix <= 50; ix++)
00404       me->setBinContent(ix, me->getBinContent(ix + 1));
00405 
00406     me->getTH1()->GetXaxis()->SetLimits(ls_ - 49, ls_ + 1);
00407   }
00408 }
00409 
00410 void EBRawDataTask::endJob(void) {
00411 
00412   edm::LogInfo("EBRawDataTask") << "analyzed " << ievt_ << " events";
00413 
00414   if ( enableCleanup_ ) this->cleanup();
00415 
00416 }
00417 
00418 void EBRawDataTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00419 
00420   ievt_++;
00421 
00422   // fill bin 0 with number of events in the lumi
00423   if ( meEBSynchronizationErrorsByLumi_ ) meEBSynchronizationErrorsByLumi_->Fill(0.);
00424 
00425   float errorsInEvent(0.);
00426 
00427   int evt_runNumber = e.id().run();
00428 
00429   int GT_L1A=0, GT_OrbitNumber=0, GT_BunchCrossing=0, GT_TriggerType=0;
00430 
00431   edm::Handle<FEDRawDataCollection> allFedRawData;
00432 
00433   int gtFedDataSize = 0;
00434 
00435   int ECALDCC_L1A_MostFreqId = -1;
00436   int ECALDCC_OrbitNumber_MostFreqId = -1;
00437   int ECALDCC_BunchCrossing_MostFreqId = -1;
00438   int ECALDCC_TriggerType_MostFreqId = -1;
00439 
00440   if ( e.getByLabel(FEDRawDataCollection_, allFedRawData) ) {
00441 
00442     // GT FED data
00443     const FEDRawData& gtFedData = allFedRawData->FEDData(812);
00444 
00445     gtFedDataSize = gtFedData.size()/sizeof(uint64_t);
00446 
00447     if ( gtFedDataSize > 0 ) {
00448 
00449       FEDHeader header(gtFedData.data());
00450 
00451 #define  H_L1_MASK           0xFFFFFF
00452 #define  H_ORBITCOUNTER_MASK 0xFFFFFFFF
00453 #define  H_BX_MASK           0xFFF
00454 #define  H_TTYPE_MASK        0xF
00455 
00456       GT_L1A           = header.lvl1ID()    & H_L1_MASK;
00457       GT_OrbitNumber   = e.orbitNumber()    & H_ORBITCOUNTER_MASK;
00458       GT_BunchCrossing = e.bunchCrossing()  & H_BX_MASK;
00459       GT_TriggerType   = e.experimentType() & H_TTYPE_MASK;
00460 
00461     } else {
00462 
00463       // use the most frequent among the ECAL FEDs
00464 
00465       std::map<int,int> ECALDCC_L1A_FreqMap;
00466       std::map<int,int> ECALDCC_OrbitNumber_FreqMap;
00467       std::map<int,int> ECALDCC_BunchCrossing_FreqMap;
00468       std::map<int,int> ECALDCC_TriggerType_FreqMap;
00469 
00470       int ECALDCC_L1A_MostFreqCounts = 0;
00471       int ECALDCC_OrbitNumber_MostFreqCounts = 0;
00472       int ECALDCC_BunchCrossing_MostFreqCounts = 0;
00473       int ECALDCC_TriggerType_MostFreqCounts = 0;
00474 
00475       edm::Handle<EcalRawDataCollection> dcchs;
00476 
00477       if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
00478 
00479         for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
00480 
00481           if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
00482 
00483           int ECALDCC_L1A = dcchItr->getLV1();
00484           int ECALDCC_OrbitNumber = dcchItr->getOrbit();
00485           int ECALDCC_BunchCrossing = dcchItr->getBX();
00486           int ECALDCC_TriggerType = dcchItr->getBasicTriggerType();
00487 
00488           ++ECALDCC_L1A_FreqMap[ECALDCC_L1A];
00489           ++ECALDCC_OrbitNumber_FreqMap[ECALDCC_OrbitNumber];
00490           ++ECALDCC_BunchCrossing_FreqMap[ECALDCC_BunchCrossing];
00491           ++ECALDCC_TriggerType_FreqMap[ECALDCC_TriggerType];
00492 
00493           if ( ECALDCC_L1A_FreqMap[ECALDCC_L1A] > ECALDCC_L1A_MostFreqCounts ) {
00494             ECALDCC_L1A_MostFreqCounts = ECALDCC_L1A_FreqMap[ECALDCC_L1A];
00495             ECALDCC_L1A_MostFreqId = ECALDCC_L1A;
00496           }
00497 
00498           if ( ECALDCC_OrbitNumber_FreqMap[ECALDCC_OrbitNumber] > ECALDCC_OrbitNumber_MostFreqCounts ) {
00499             ECALDCC_OrbitNumber_MostFreqCounts = ECALDCC_OrbitNumber_FreqMap[ECALDCC_OrbitNumber];
00500             ECALDCC_OrbitNumber_MostFreqId = ECALDCC_OrbitNumber;
00501           }
00502 
00503           if ( ECALDCC_BunchCrossing_FreqMap[ECALDCC_BunchCrossing] > ECALDCC_BunchCrossing_MostFreqCounts ) {
00504             ECALDCC_BunchCrossing_MostFreqCounts = ECALDCC_BunchCrossing_FreqMap[ECALDCC_BunchCrossing];
00505             ECALDCC_BunchCrossing_MostFreqId = ECALDCC_BunchCrossing;
00506           }
00507 
00508           if ( ECALDCC_TriggerType_FreqMap[ECALDCC_TriggerType] > ECALDCC_TriggerType_MostFreqCounts ) {
00509             ECALDCC_TriggerType_MostFreqCounts = ECALDCC_TriggerType_FreqMap[ECALDCC_TriggerType];
00510             ECALDCC_TriggerType_MostFreqId = ECALDCC_TriggerType;
00511           }
00512 
00513         }
00514 
00515       } else {
00516         edm::LogWarning("EBRawDataTask") << EcalRawDataCollection_ << " not available";
00517       }
00518 
00519     }
00520 
00521     // ECAL barrel FEDs
00522     int EBFirstFED=610;
00523     for(int i=0; i<36; i++) {
00524 
00525       const FEDRawData& fedData = allFedRawData->FEDData(EBFirstFED+i);
00526 
00527       int length = fedData.size()/sizeof(uint64_t);
00528 
00529       if ( length > 0 ) {
00530 
00531         uint64_t * pData = (uint64_t *)(fedData.data());
00532         uint64_t * fedTrailer = pData + (length - 1);
00533         bool crcError = (*fedTrailer >> 2 ) & 0x1;
00534 
00535         if (crcError) meEBCRCErrors_->Fill( i+1 );
00536 
00537       }
00538 
00539     }
00540 
00541   } else {
00542     edm::LogWarning("EBRawDataTask") << FEDRawDataCollection_ << " not available";
00543   }
00544 
00545   edm::Handle<EcalRawDataCollection> dcchs;
00546 
00547   if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
00548 
00549     for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
00550 
00551       if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
00552 
00553       int ism = Numbers::iSM( *dcchItr, EcalBarrel );
00554       float xism = ism+0.5;
00555 
00556       int ECALDCC_runNumber     = dcchItr->getRunNumber();
00557 
00558       int ECALDCC_L1A           = dcchItr->getLV1();
00559       int ECALDCC_OrbitNumber   = dcchItr->getOrbit();
00560       int ECALDCC_BunchCrossing = dcchItr->getBX();
00561       int ECALDCC_TriggerType   = dcchItr->getBasicTriggerType();
00562 
00563       if ( evt_runNumber != ECALDCC_runNumber ) meEBRunNumberErrors_->Fill( xism );
00564 
00565       if ( gtFedDataSize > 0 ) {
00566 
00567         if ( GT_L1A != ECALDCC_L1A ) meEBL1ADCCErrors_->Fill( xism );
00568 
00569         if ( GT_BunchCrossing != ECALDCC_BunchCrossing ) meEBBunchCrossingDCCErrors_->Fill( xism );
00570 
00571         if ( GT_TriggerType != ECALDCC_TriggerType ) meEBTriggerTypeErrors_->Fill ( xism );
00572 
00573       } else {
00574 
00575         if ( ECALDCC_L1A_MostFreqId != ECALDCC_L1A ) meEBL1ADCCErrors_->Fill( xism );
00576 
00577         if ( ECALDCC_BunchCrossing_MostFreqId != ECALDCC_BunchCrossing ) meEBBunchCrossingDCCErrors_->Fill( xism );
00578 
00579         if ( ECALDCC_TriggerType_MostFreqId != ECALDCC_TriggerType ) meEBTriggerTypeErrors_->Fill ( xism );
00580 
00581       }
00582 
00583       if ( gtFedDataSize == 0 ) {
00584 
00585         if ( GT_OrbitNumber != ECALDCC_OrbitNumber ) meEBOrbitNumberErrors_->Fill ( xism );
00586 
00587       } else {
00588 
00589         if ( ECALDCC_OrbitNumber_MostFreqId != ECALDCC_OrbitNumber ) meEBOrbitNumberErrors_->Fill ( xism );
00590 
00591       }
00592 
00593       // DCC vs. FE,TCC, SRP syncronization
00594       const std::vector<short> feBxs = dcchItr->getFEBxs();
00595       const std::vector<short> tccBx = dcchItr->getTCCBx();
00596       const short srpBx = dcchItr->getSRPBx();
00597       const std::vector<short> status = dcchItr->getFEStatus();
00598 
00599       std::vector<int> BxSynchStatus;
00600       BxSynchStatus.reserve((int)feBxs.size());
00601 
00602       for(int fe=0; fe<(int)feBxs.size(); fe++) {
00603         // look for ACTIVE towers only
00604         if(status[fe] != 0) continue;
00605         if(feBxs[fe] != ECALDCC_BunchCrossing && feBxs[fe] != -1 && ECALDCC_BunchCrossing != -1) {
00606           meEBBunchCrossingFEErrors_->Fill( xism, 1/(float)feBxs.size() );
00607           BxSynchStatus[fe] = 0;
00608         } else BxSynchStatus[fe] = 1;
00609       }
00610 
00611       // vector of TCC channels has 4 elements for both EB and EE.
00612       // EB uses [0], EE uses [0-3].
00613       if(tccBx.size() == MAX_TCC_SIZE) {
00614         if(tccBx[0] != ECALDCC_BunchCrossing && tccBx[0] != -1 && ECALDCC_BunchCrossing != -1) meEBBunchCrossingTCCErrors_->Fill( xism );
00615       }
00616 
00617       if(srpBx != ECALDCC_BunchCrossing && srpBx != -1 && ECALDCC_BunchCrossing != -1) meEBBunchCrossingSRPErrors_->Fill( xism );
00618 
00619       const std::vector<short> feLv1 = dcchItr->getFELv1();
00620       const std::vector<short> tccLv1 = dcchItr->getTCCLv1();
00621       const short srpLv1 = dcchItr->getSRPLv1();
00622 
00623       // Lv1 in TCC,SRP,FE are limited to 12 bits(LSB), while in the DCC Lv1 has 24 bits
00624       int ECALDCC_L1A_12bit = ECALDCC_L1A & 0xfff;
00625       int feLv1Offset = ( e.isRealData() ) ? 1 : 0; // in MC FE Lv1A counter starts from 1, in data from 0
00626 
00627       for(int fe=0; fe<(int)feLv1.size(); fe++) {
00628         // look for ACTIVE towers only
00629         if(status[fe] != 0) continue;
00630         if(feLv1[fe]+feLv1Offset != ECALDCC_L1A_12bit && feLv1[fe] != -1 && ECALDCC_L1A_12bit - 1 != -1) {
00631           meEBL1AFEErrors_->Fill( xism, 1/(float)feLv1.size() );
00632           meEBSynchronizationErrorsByLumi_->Fill( xism, 1/(float)feLv1.size() );
00633           errorsInEvent += 1. / feLv1.size();
00634         } else if( BxSynchStatus[fe]==0 ){
00635           meEBSynchronizationErrorsByLumi_->Fill( xism, 1/(float)feLv1.size() );
00636           errorsInEvent += 1. / feLv1.size();
00637         }
00638       }
00639 
00640       // vector of TCC channels has 4 elements for both EB and EE.
00641       // EB uses [0], EE uses [0-3].
00642       if(tccLv1.size() == MAX_TCC_SIZE) {
00643         if(tccLv1[0] != ECALDCC_L1A_12bit && tccLv1[0] != -1 && ECALDCC_L1A_12bit - 1 != -1) meEBL1ATCCErrors_->Fill( xism );
00644       }
00645 
00646       if(srpLv1 != ECALDCC_L1A_12bit && srpLv1 != -1 && ECALDCC_L1A_12bit - 1 != -1) meEBL1ASRPErrors_->Fill( xism );
00647 
00648       if ( gtFedDataSize == 0 ) {
00649 
00650         if ( GT_OrbitNumber != ECALDCC_OrbitNumber ) meEBOrbitNumberErrors_->Fill ( xism );
00651 
00652       } else {
00653 
00654         if ( ECALDCC_OrbitNumber_MostFreqId != ECALDCC_OrbitNumber ) meEBOrbitNumberErrors_->Fill ( xism );
00655 
00656       }
00657 
00658       float evtType = dcchItr->getRunType();
00659 
00660       if ( evtType < 0 || evtType > 22 ) evtType = -1;
00661 
00662       if ( ECALDCC_BunchCrossing < calibrationBX_ ) meEBEventTypePreCalibrationBX_->Fill( evtType+0.5, 1./36. );
00663       if ( ECALDCC_BunchCrossing == calibrationBX_ ) meEBEventTypeCalibrationBX_->Fill( evtType+0.5, 1./36. );
00664       if ( ECALDCC_BunchCrossing > calibrationBX_ ) meEBEventTypePostCalibrationBX_->Fill ( evtType+0.5, 1./36. );
00665 
00666       if ( ECALDCC_BunchCrossing != calibrationBX_ ) {
00667         if ( evtType != EcalDCCHeaderBlock::COSMIC &&
00668              evtType != EcalDCCHeaderBlock::MTCC &&
00669              evtType != EcalDCCHeaderBlock::COSMICS_GLOBAL &&
00670              evtType != EcalDCCHeaderBlock::PHYSICS_GLOBAL &&
00671              evtType != EcalDCCHeaderBlock::COSMICS_LOCAL &&
00672              evtType != EcalDCCHeaderBlock::PHYSICS_LOCAL &&
00673              evtType != -1 ) meEBCalibrationEventErrors_->Fill( xism );
00674       } else {
00675         if ( evtType == EcalDCCHeaderBlock::COSMIC ||
00676              evtType == EcalDCCHeaderBlock::MTCC ||
00677              evtType == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
00678              evtType == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
00679              evtType == EcalDCCHeaderBlock::COSMICS_LOCAL ||
00680              evtType == EcalDCCHeaderBlock::PHYSICS_LOCAL ) meEBCalibrationEventErrors_->Fill( xism );
00681       }
00682 
00683     }
00684 
00685   } else {
00686     edm::LogWarning("EBRawDataTask") << EcalRawDataCollection_ << " not available";
00687   }
00688 
00689   if(errorsInEvent > 0.){
00690     meEBSynchronizationErrorsTrend_->Fill(ls_ - 0.5, errorsInEvent);
00691     fatalErrors_ += errorsInEvent;
00692   }
00693 }
00694