CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DQM/EcalBarrelMonitorTasks/src/EBStatusFlagsTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EBStatusFlagsTask.cc
00003  *
00004  * $Date: 2010/10/04 11:16:00 $
00005  * $Revision: 1.33 $
00006  * \author G. Della Ricca
00007  *
00008 */
00009 
00010 #include <iostream>
00011 #include <fstream>
00012 #include <vector>
00013 
00014 #include "FWCore/ServiceRegistry/interface/Service.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 
00017 #include "DQMServices/Core/interface/MonitorElement.h"
00018 
00019 #include "DQMServices/Core/interface/DQMStore.h"
00020 
00021 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00022 
00023 #include "DQM/EcalCommon/interface/Numbers.h"
00024 
00025 #include "DQM/EcalBarrelMonitorTasks/interface/EBStatusFlagsTask.h"
00026 
00027 EBStatusFlagsTask::EBStatusFlagsTask(const edm::ParameterSet& ps){
00028 
00029   init_ = false;
00030 
00031   dqmStore_ = edm::Service<DQMStore>().operator->();
00032 
00033   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00034 
00035   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00036 
00037   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00038 
00039   EcalRawDataCollection_ = ps.getParameter<edm::InputTag>("EcalRawDataCollection");
00040 
00041   for (int i = 0; i < 36; i++) {
00042     meEvtType_[i] = 0;
00043 
00044     meFEchErrors_[i][0] = 0;
00045     meFEchErrors_[i][1] = 0;
00046     meFEchErrors_[i][2] = 0;
00047   }
00048 
00049   meFEchErrorsByLumi_ = 0;
00050 
00051 }
00052 
00053 EBStatusFlagsTask::~EBStatusFlagsTask(){
00054 
00055 }
00056 
00057 void EBStatusFlagsTask::beginJob(void){
00058 
00059   ievt_ = 0;
00060 
00061   if ( dqmStore_ ) {
00062     dqmStore_->setCurrentFolder(prefixME_ + "/EBStatusFlagsTask");
00063     dqmStore_->rmdir(prefixME_ + "/EBStatusFlagsTask");
00064   }
00065 
00066 }
00067 
00068 void EBStatusFlagsTask::beginLuminosityBlock(const edm::LuminosityBlock& lumiBlock, const  edm::EventSetup& iSetup) {
00069 
00070   if ( meFEchErrorsByLumi_ ) meFEchErrorsByLumi_->Reset();
00071 
00072 }
00073 
00074 void EBStatusFlagsTask::endLuminosityBlock(const edm::LuminosityBlock&  lumiBlock, const  edm::EventSetup& iSetup) {
00075 }
00076 
00077 void EBStatusFlagsTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00078 
00079   Numbers::initGeometry(c, false);
00080 
00081   if ( ! mergeRuns_ ) this->reset();
00082 
00083 }
00084 
00085 void EBStatusFlagsTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00086 
00087 }
00088 
00089 void EBStatusFlagsTask::reset(void) {
00090 
00091   for (int i = 0; i < 36; i++) {
00092     if ( meEvtType_[i] ) meEvtType_[i]->Reset();
00093 
00094     if ( meFEchErrors_[i][0] ) meFEchErrors_[i][0]->Reset();
00095     if ( meFEchErrors_[i][1] ) meFEchErrors_[i][1]->Reset();
00096     if ( meFEchErrors_[i][2] ) meFEchErrors_[i][2]->Reset();
00097   }
00098   if ( meFEchErrorsByLumi_ ) meFEchErrorsByLumi_->Reset();
00099 }
00100 
00101 void EBStatusFlagsTask::setup(void){
00102 
00103   init_ = true;
00104 
00105   char histo[200];
00106 
00107   if ( dqmStore_ ) {
00108     dqmStore_->setCurrentFolder(prefixME_ + "/EBStatusFlagsTask");
00109 
00110     dqmStore_->setCurrentFolder(prefixME_ + "/EBStatusFlagsTask/EvtType");
00111     for (int i = 0; i < 36; i++) {
00112       sprintf(histo, "EBSFT EVTTYPE %s", Numbers::sEB(i+1).c_str());
00113       meEvtType_[i] = dqmStore_->book1D(histo, histo, 31, -1., 30.);
00114       meEvtType_[i]->setBinLabel(1, "UNKNOWN", 1);
00115       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::COSMIC, "COSMIC", 1);
00116       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::BEAMH4, "BEAMH4", 1);
00117       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::BEAMH2, "BEAMH2", 1);
00118       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::MTCC, "MTCC", 1);
00119       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::LASER_STD, "LASER_STD", 1);
00120       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::LASER_POWER_SCAN, "LASER_POWER_SCAN", 1);
00121       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::LASER_DELAY_SCAN, "LASER_DELAY_SCAN", 1);
00122       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::TESTPULSE_SCAN_MEM, "TESTPULSE_SCAN_MEM", 1);
00123       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::TESTPULSE_MGPA, "TESTPULSE_MGPA", 1);
00124       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_STD, "PEDESTAL_STD", 1);
00125       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN, "PEDESTAL_OFFSET_SCAN", 1);
00126       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_25NS_SCAN, "PEDESTAL_25NS_SCAN", 1);
00127       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::LED_STD, "LED_STD", 1);
00128       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::PHYSICS_GLOBAL, "PHYSICS_GLOBAL", 1);
00129       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::COSMICS_GLOBAL, "COSMICS_GLOBAL", 1);
00130       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::HALO_GLOBAL, "HALO_GLOBAL", 1);
00131       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::LASER_GAP, "LASER_GAP", 1);
00132       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::TESTPULSE_GAP, "TESTPULSE_GAP");
00133       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_GAP, "PEDESTAL_GAP");
00134       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::LED_GAP, "LED_GAP", 1);
00135       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::PHYSICS_LOCAL, "PHYSICS_LOCAL", 1);
00136       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::COSMICS_LOCAL, "COSMICS_LOCAL", 1);
00137       meEvtType_[i]->setBinLabel(2+EcalDCCHeaderBlock::HALO_LOCAL, "HALO_LOCAL", 1);
00138       dqmStore_->tag(meEvtType_[i], i+1);
00139     }
00140 
00141     dqmStore_->setCurrentFolder(prefixME_ + "/EBStatusFlagsTask/FEStatus");
00142     for (int i = 0; i < 36; i++) {
00143       sprintf(histo, "EBSFT front-end status %s", Numbers::sEB(i+1).c_str());
00144       meFEchErrors_[i][0] = dqmStore_->book2D(histo, histo, 17, 0., 17., 4, 0., 4.);
00145       meFEchErrors_[i][0]->setAxisTitle("ieta'", 1);
00146       meFEchErrors_[i][0]->setAxisTitle("iphi'", 2);
00147       dqmStore_->tag(meFEchErrors_[i][0], i+1);
00148 
00149       sprintf(histo, "EBSFT MEM front-end status %s", Numbers::sEB(i+1).c_str());
00150       meFEchErrors_[i][1] = dqmStore_->book2D(histo, histo, 2, 0., 2., 1, 0., 1.);
00151       meFEchErrors_[i][1]->setAxisTitle("pseudo-strip", 1);
00152       meFEchErrors_[i][1]->setAxisTitle("channel", 2);
00153       dqmStore_->tag(meFEchErrors_[i][1], i+1);
00154 
00155       sprintf(histo, "EBSFT front-end status bits %s", Numbers::sEB(i+1).c_str());
00156       meFEchErrors_[i][2] = dqmStore_->book1D(histo, histo, 16, 0., 16.);
00157       meFEchErrors_[i][2]->setBinLabel(1+0, "ACTIVE", 1);
00158       meFEchErrors_[i][2]->setBinLabel(1+1, "DISABLED", 1);
00159       meFEchErrors_[i][2]->setBinLabel(1+2, "TIMEOUT", 1);
00160       meFEchErrors_[i][2]->setBinLabel(1+3, "HEADER", 1);
00161       meFEchErrors_[i][2]->setBinLabel(1+4, "CHANNEL ID", 1);
00162       meFEchErrors_[i][2]->setBinLabel(1+5, "LINK", 1);
00163       meFEchErrors_[i][2]->setBinLabel(1+6, "BLOCKSIZE", 1);
00164       meFEchErrors_[i][2]->setBinLabel(1+7, "SUPPRESSED", 1);
00165       meFEchErrors_[i][2]->setBinLabel(1+8, "FORCED FS", 1);
00166       meFEchErrors_[i][2]->setBinLabel(1+9, "L1A SYNC", 1);
00167       meFEchErrors_[i][2]->setBinLabel(1+10, "BX SYNC", 1);
00168       meFEchErrors_[i][2]->setBinLabel(1+11, "L1A+BX SYNC", 1);
00169       meFEchErrors_[i][2]->setBinLabel(1+12, "FIFO FULL+L1A", 1);
00170       meFEchErrors_[i][2]->setBinLabel(1+13, "H PARITY", 1);
00171       meFEchErrors_[i][2]->setBinLabel(1+14, "V PARITY", 1);
00172       meFEchErrors_[i][2]->setBinLabel(1+15, "FORCED ZS", 1);
00173       dqmStore_->tag(meFEchErrors_[i][2], i+1);
00174     }
00175 
00176     // checking the number of front-end errors in each DCC for each lumi
00177     // tower error is weighted by 1/68
00178     // bin 0 contains the number of processed events in the lumi (for normalization)
00179     sprintf(histo, "EBSFT weighted frontend errors by lumi");
00180     meFEchErrorsByLumi_ = dqmStore_->book1D(histo, histo, 36, 1., 37.);
00181     meFEchErrorsByLumi_->setLumiFlag();
00182     for (int i = 0; i < 36; i++) {
00183       meFEchErrorsByLumi_->setBinLabel(i+1, Numbers::sEB(i+1).c_str(), 1);
00184     }
00185 
00186   }
00187 
00188 }
00189 
00190 void EBStatusFlagsTask::cleanup(void){
00191 
00192   if ( ! init_ ) return;
00193 
00194   if ( dqmStore_ ) {
00195     dqmStore_->setCurrentFolder(prefixME_ + "/EBStatusFlagsTask");
00196 
00197     dqmStore_->setCurrentFolder(prefixME_ + "/EBStatusFlagsTask/EvtType");
00198     for (int i = 0; i < 36; i++) {
00199       if ( meEvtType_[i] ) dqmStore_->removeElement( meEvtType_[i]->getName() );
00200       meEvtType_[i] = 0;
00201     }
00202 
00203     dqmStore_->setCurrentFolder(prefixME_ + "/EBStatusFlagsTask/FEStatus");
00204     for (int i = 0; i < 36; i++) {
00205       if ( meFEchErrors_[i][0] ) dqmStore_->removeElement( meFEchErrors_[i][0]->getName() );
00206       meFEchErrors_[i][0] = 0;
00207       if ( meFEchErrors_[i][1] ) dqmStore_->removeElement( meFEchErrors_[i][1]->getName() );
00208       meFEchErrors_[i][1] = 0;
00209       if ( meFEchErrors_[i][2] ) dqmStore_->removeElement( meFEchErrors_[i][2]->getName() );
00210       meFEchErrors_[i][2] = 0;
00211     }
00212 
00213     if ( meFEchErrorsByLumi_ ) dqmStore_->removeElement( meFEchErrorsByLumi_->getName() );
00214     meFEchErrorsByLumi_ = 0;
00215 
00216   }
00217 
00218   init_ = false;
00219 
00220 }
00221 
00222 void EBStatusFlagsTask::endJob(void){
00223 
00224   edm::LogInfo("EBStatusFlagsTask") << "analyzed " << ievt_ << " events";
00225 
00226   if ( enableCleanup_ ) this->cleanup();
00227 
00228 }
00229 
00230 void EBStatusFlagsTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00231 
00232   if ( ! init_ ) this->setup();
00233 
00234   ievt_++;
00235 
00236   // fill bin 0 with number of events in the lumi
00237   if ( meFEchErrorsByLumi_ ) meFEchErrorsByLumi_->Fill(0.);
00238 
00239   edm::Handle<EcalRawDataCollection> dcchs;
00240 
00241   if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
00242 
00243     for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
00244 
00245       if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
00246 
00247       int ism = Numbers::iSM( *dcchItr, EcalBarrel );
00248       float xism = ism + 0.5;
00249 
00250       if ( meEvtType_[ism-1] ) meEvtType_[ism-1]->Fill(dcchItr->getRunType()+0.5);
00251 
00252       const std::vector<short> status = dcchItr->getFEStatus();
00253 
00254       for ( unsigned int itt=1; itt<=status.size(); itt++ ) {
00255 
00256         if ( itt > 70 ) continue;
00257 
00258         if ( itt >= 1 && itt <= 68 ) {
00259 
00260           int iet = (itt-1)/4 + 1;
00261           int ipt = (itt-1)%4 + 1;
00262 
00263           float xiet = iet - 0.5;
00264           float xipt = ipt - 0.5;
00265 
00266           if ( ! ( status[itt-1] == 0 || status[itt-1] == 1 || status[itt-1] == 7 || status[itt-1] == 8 || status[itt-1] == 12 || status[itt-1] == 15 ) ) {
00267             if ( meFEchErrors_[ism-1][0] ) meFEchErrors_[ism-1][0]->Fill(xiet, xipt);
00268             if ( meFEchErrorsByLumi_ ) meFEchErrorsByLumi_->Fill(xism, 1./68.);
00269           }
00270 
00271         } else if ( itt == 69 || itt == 70 ) {
00272 
00273           if ( ! ( status[itt-1] == 0 || status[itt-1] == 1 || status[itt-1] == 7 || status[itt-1] == 8 || status[itt-1] == 12 || status[itt-1] == 15 ) ) {
00274             if ( meFEchErrors_[ism-1][1] ) meFEchErrors_[ism-1][1]->Fill(itt-68-0.5, 0);
00275           }
00276 
00277         }
00278 
00279         if ( meFEchErrors_[ism-1][2] ) meFEchErrors_[ism-1][2]->Fill(status[itt-1]+0.5);
00280 
00281       }
00282 
00283     }
00284 
00285   } else {
00286 
00287     edm::LogWarning("EBStatusFlagsTask") << EcalRawDataCollection_ << " not available";
00288 
00289   }
00290 
00291 }
00292