CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DQM/EcalPreshowerMonitorModule/src/ESDaqInfoTask.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 #include "FWCore/Framework/interface/MakerMacros.h"
00006 #include "FWCore/Framework/interface/Frameworkfwd.h"
00007 
00008 #include "FWCore/Framework/interface/ESHandle.h"
00009 #include "FWCore/Framework/interface/EventSetup.h"
00010 
00011 #include <DataFormats/EcalDetId/interface/ESDetId.h>
00012 
00013 #include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
00014 #include "CondFormats/RunInfo/interface/RunSummary.h"
00015 #include "CondFormats/RunInfo/interface/RunInfo.h"
00016 
00017 #include "DQMServices/Core/interface/MonitorElement.h"
00018 #include "DQMServices/Core/interface/DQMStore.h"
00019 
00020 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00021 
00022 #include "Geometry/EcalMapping/interface/ESElectronicsMapper.h"
00023 
00024 #include "DQM/EcalPreshowerMonitorModule/interface/ESDaqInfoTask.h"
00025 
00026 using namespace cms;
00027 using namespace edm;
00028 using namespace std;
00029 
00030 ESDaqInfoTask::ESDaqInfoTask(const ParameterSet& ps) {
00031 
00032    dqmStore_ = Service<DQMStore>().operator->();
00033 
00034    prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
00035 
00036    enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00037 
00038    mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00039 
00040    ESFedRangeMin_ = ps.getUntrackedParameter<int>("ESFedRangeMin", 520);
00041    ESFedRangeMax_ = ps.getUntrackedParameter<int>("ESFedRangeMax", 575);
00042 
00043    meESDaqFraction_ = 0;
00044    meESDaqActiveMap_ = 0;
00045    meESDaqError_ = 0;
00046 
00047    for (int i = 0; i < 56; i++) {
00048       meESDaqActive_[i] = 0;
00049    }
00050 
00051    if (ps.exists("esMapping")){
00052       edm::ParameterSet esMap=ps.getParameter<edm::ParameterSet>("esMapping");
00053       es_mapping_ = new ESElectronicsMapper(esMap);
00054    }else{
00055       edm::LogError("ESDaqInfoTask")<<"preshower mapping pointer not initialized. Temporary.";
00056       es_mapping_=0;
00057    }
00058 
00059 
00060 
00061 }
00062 
00063 ESDaqInfoTask::~ESDaqInfoTask() {
00064    delete es_mapping_;
00065 }
00066 
00067 void ESDaqInfoTask::beginJob(void) {
00068 
00069    char histo[200];
00070 
00071    if ( dqmStore_ ) {
00072 
00073       dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo");
00074 
00075       sprintf(histo, "DAQSummary");
00076       meESDaqFraction_ = dqmStore_->bookFloat(histo);
00077       meESDaqFraction_->Fill(0.0);
00078 
00079       sprintf(histo, "DAQSummaryMap");
00080       meESDaqActiveMap_ = dqmStore_->book2D(histo,histo, 80, 0.5, 80.5, 80, 0.5, 80.5);
00081       meESDaqActiveMap_->setAxisTitle("Si X", 1);
00082       meESDaqActiveMap_->setAxisTitle("Si Y", 2);
00083 
00084       dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo/DAQContents");
00085 
00086       for (int i = 0; i < 56; i++) {
00087          sprintf(histo, "EcalPreshower_%d", ESFedRangeMin_+i);
00088          meESDaqActive_[i] = dqmStore_->bookFloat(histo);
00089          meESDaqActive_[i]->Fill(0.0);
00090 
00091          ESOnFed_[i] = false;
00092          for ( int x = 0; x < 80; x++ ) {
00093             for ( int y = 0; y < 80; y++ ) {
00094                int iz = (x<40)?  1:2;
00095                int ip = (y>=40)? 1:2;
00096                int ix = (x<40)? x:x-40;
00097                int iy = (y<40)?  y:y-40;
00098                int ifed = (*es_mapping_).getFED( iz, ip, ix, iy);
00099                if(ifed == ESFedRangeMin_+i){
00100                   ESOnFed_[i] = true;
00101                   break;
00102                }
00103             }
00104             if(ESOnFed_[i] == true) break;
00105          }
00106       }
00107 
00108       dqmStore_->setCurrentFolder(prefixME_ + "/ESIntegrityTask");
00109       sprintf(histo, "DAQError");
00110       meESDaqError_ = dqmStore_->book1D(histo, histo, 56, ESFedRangeMin_-0.5, ESFedRangeMax_+0.5);
00111       meESDaqError_->setAxisTitle("FedID", 1);
00112 
00113    }
00114 
00115 }
00116 
00117 void ESDaqInfoTask::endJob(void) {
00118 
00119    if ( enableCleanup_ ) this->cleanup();
00120 
00121 }
00122 
00123 void ESDaqInfoTask::beginLuminosityBlock(const edm::LuminosityBlock& lumiBlock, const  edm::EventSetup& iSetup){
00124 
00125    this->reset();
00126 
00127    for ( int x = 0; x < 80; x++ ) {
00128       for ( int y = 0; y < 80; y++ ) {
00129          int iz = (x<40)?  1:2;
00130          int ip = (y>=40)? 1:2;
00131          int ix = (x<40)? x:x-40;
00132          int iy = (y<40)?  y:y-40;
00133          int ifed = (*es_mapping_).getFED( iz, ip, ix, iy);
00134          if( ifed > 0 ) meESDaqActiveMap_->setBinContent( x+1, y+1, 0.0 );
00135          else meESDaqActiveMap_->setBinContent( x+1, y+1, -1.0 );
00136       }
00137    }
00138 
00139    for (int i = 0; i < 56; i++) {
00140       if ( meESDaqError_ ) meESDaqError_->setBinContent(i, 0.0);
00141    }
00142 
00143    edm::eventsetup::EventSetupRecordKey recordKey(edm::eventsetup::EventSetupRecordKey::TypeTag::findType("RunInfoRcd"));
00144 
00145    if( iSetup.find( recordKey ) ) {
00146 
00147       edm::ESHandle<RunInfo> sumFED;
00148       iSetup.get<RunInfoRcd>().get(sumFED);    
00149 
00150       std::vector<int> FedsInIds= sumFED->m_fed_in;   
00151 
00152       float ESFedCount = 0.;
00153 
00154       for( unsigned int fedItr=0; fedItr<FedsInIds.size(); ++fedItr ) {
00155 
00156          int fedID=FedsInIds[fedItr];
00157 
00158          if ( fedID >= ESFedRangeMin_ && fedID <= ESFedRangeMax_ ) {
00159 
00160             if( ESOnFed_[fedID - ESFedRangeMin_] ) ESFedCount++;
00161 
00162             if ( meESDaqActive_[fedID-ESFedRangeMin_] ) meESDaqActive_[fedID-ESFedRangeMin_]->Fill(1.0);
00163 
00164             if( meESDaqActiveMap_ ) {
00165 
00166                for( int x = 0; x < 80; x++ ) {
00167                   for( int y = 0; y < 80; y++ ) {
00168                      int iz = (x<40)?  1:2;
00169                      int ip = (y>=40)? 1:2;
00170                      int ix = (x<40) ?  x:x-40;
00171                      int iy = (x<40) ?  y:y-40;
00172                      int ifed = es_mapping_->getFED(iz, ip, ix, iy);
00173                      if( fedID==ifed ) meESDaqActiveMap_->setBinContent( x+1, y+1, 1.0 );
00174                   }
00175                }
00176 
00177             }
00178 
00179             if( meESDaqFraction_ ) meESDaqFraction_->Fill( ESFedCount/40. );
00180 
00181             if( meESDaqError_ ){
00182                for( int i = 0; i < 56; i++){
00183                   if( ESOnFed_[fedID-ESFedRangeMin_] ) meESDaqError_->setBinContent(i+1, 1.0);
00184                   else meESDaqError_->setBinContent(i+1, 2.0);
00185                }
00186             }
00187 
00188          }
00189 
00190       }
00191 
00192  } else {
00193 
00194       LogWarning("ESDaqInfoTask") << "Cannot find any RunInfoRcd" << endl;
00195 
00196    }
00197 
00198 }
00199 
00200 void ESDaqInfoTask::endLuminosityBlock(const edm::LuminosityBlock&  lumiBlock, const  edm::EventSetup& iSetup) {
00201 
00202 }
00203 
00204 void ESDaqInfoTask::reset(void) {
00205 
00206    if ( meESDaqFraction_ ) meESDaqFraction_->Reset();
00207 
00208    for (int i = 0; i < 56; i++) {
00209       if ( meESDaqActive_[i] ) meESDaqActive_[i]->Reset();
00210    }
00211 
00212    if ( meESDaqActiveMap_ ) meESDaqActiveMap_->Reset();
00213 
00214    if ( meESDaqError_ ) meESDaqError_->Reset();
00215 
00216 }
00217 
00218 
00219 void ESDaqInfoTask::cleanup(void){
00220 
00221    if ( dqmStore_ ) {
00222 
00223       dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo");
00224 
00225       if ( meESDaqFraction_ ) dqmStore_->removeElement( meESDaqFraction_->getName() );
00226 
00227       if ( meESDaqActiveMap_ ) dqmStore_->removeElement( meESDaqActiveMap_->getName() );
00228 
00229       if ( meESDaqError_ ) dqmStore_->removeElement( meESDaqError_->getName() );
00230 
00231       dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo/DAQContents");
00232 
00233       for (int i = 0; i < 56; i++) {
00234          if ( meESDaqActive_[i] ) dqmStore_->removeElement( meESDaqActive_[i]->getName() );
00235       }
00236 
00237    }
00238 
00239 }
00240 
00241 void ESDaqInfoTask::analyze(const Event& e, const EventSetup& c){ 
00242 
00243 }
00244 
00245 DEFINE_FWK_MODULE(ESDaqInfoTask);