CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DQM/EcalBarrelMonitorTasks/src/EBRawDataTask.cc

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