CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DQM/EcalEndcapMonitorTasks/src/EEStatusFlagsTask.cc

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