CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/EcalBarrelMonitorTasks/src/EBStatusFlagsTask.cc

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