CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 /*
00002  * \file EBTimingTask.cc
00003  *
00004  * $Date: 2010/08/11 14:57:34 $
00005  * $Revision: 1.64 $
00006  * \author G. Della Ricca
00007  *
00008 */
00009 
00010 #include <iostream>
00011 #include <fstream>
00012 
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include "FWCore/Framework/interface/ESHandle.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/EBDetId.h"
00023 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.h"
00024 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00025 
00026 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
00027 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00028 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
00029 
00030 #include "DQM/EcalCommon/interface/Numbers.h"
00031 
00032 #include "DQM/EcalBarrelMonitorTasks/interface/EBTimingTask.h"
00033 
00034 EBTimingTask::EBTimingTask(const edm::ParameterSet& ps){
00035 
00036   init_ = false;
00037 
00038   dqmStore_ = edm::Service<DQMStore>().operator->();
00039 
00040   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00041 
00042   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00043 
00044   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00045 
00046   EcalRawDataCollection_ = ps.getParameter<edm::InputTag>("EcalRawDataCollection");
00047   EcalRecHitCollection_ = ps.getParameter<edm::InputTag>("EcalRecHitCollection");
00048 
00049   for (int i = 0; i < 36; i++) {
00050     meTime_[i] = 0;
00051     meTimeMap_[i] = 0;
00052     meTimeAmpli_[i] = 0;
00053   }
00054 
00055   meTimeAmpliSummary_ = 0;
00056   meTimeSummary1D_ = 0;
00057   meTimeSummaryMap_ = 0;
00058   meTimeSummaryMapProjEta_ = 0;
00059   meTimeSummaryMapProjPhi_ = 0;
00060 
00061 }
00062 
00063 EBTimingTask::~EBTimingTask(){
00064 
00065 }
00066 
00067 void EBTimingTask::beginJob(void){
00068 
00069   ievt_ = 0;
00070 
00071   if ( dqmStore_ ) {
00072     dqmStore_->setCurrentFolder(prefixME_ + "/EBTimingTask");
00073     dqmStore_->rmdir(prefixME_ + "/EBTimingTask");
00074   }
00075 
00076 }
00077 
00078 void EBTimingTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00079 
00080   Numbers::initGeometry(c, false);
00081 
00082   if ( ! mergeRuns_ ) this->reset();
00083 
00084 }
00085 
00086 void EBTimingTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00087 
00088 }
00089 
00090 void EBTimingTask::reset(void) {
00091 
00092   for (int i = 0; i < 36; i++) {
00093     if ( meTime_[i] ) meTime_[i]->Reset();
00094     if ( meTimeMap_[i] ) meTimeMap_[i]->Reset();
00095     if ( meTimeAmpli_[i] ) meTimeAmpli_[i]->Reset();
00096   }
00097 
00098   if ( meTimeAmpliSummary_ ) meTimeAmpliSummary_->Reset();
00099   if ( meTimeSummary1D_ ) meTimeSummary1D_->Reset();
00100   if ( meTimeSummaryMap_ ) meTimeSummaryMap_->Reset();
00101   if ( meTimeSummaryMapProjEta_ ) meTimeSummaryMapProjEta_->Reset();
00102   if ( meTimeSummaryMapProjPhi_ ) meTimeSummaryMapProjPhi_->Reset();
00103 
00104 }
00105 
00106 void EBTimingTask::setup(void){
00107 
00108   init_ = true;
00109 
00110   char histo[200];
00111 
00112   if ( dqmStore_ ) {
00113     dqmStore_->setCurrentFolder(prefixME_ + "/EBTimingTask");
00114 
00115     for (int i = 0; i < 36; i++) {
00116       sprintf(histo, "EBTMT timing 1D %s", Numbers::sEB(i+1).c_str());
00117       meTime_[i] = dqmStore_->book1D(histo, histo, 50, -50., 50.);
00118       meTime_[i]->setAxisTitle("time (ns)", 1);
00119       dqmStore_->tag(meTime_[i], i+1);
00120 
00121       sprintf(histo, "EBTMT timing %s", Numbers::sEB(i+1).c_str());
00122       meTimeMap_[i] = dqmStore_->bookProfile2D(histo, histo, 85, 0., 85., 20, 0., 20., 50, 25., 75., "s");
00123       meTimeMap_[i]->setAxisTitle("ieta", 1);
00124       meTimeMap_[i]->setAxisTitle("iphi", 2);
00125       meTimeMap_[i]->setAxisTitle("time (ns)", 3);
00126       dqmStore_->tag(meTimeMap_[i], i+1);
00127 
00128       sprintf(histo, "EBTMT timing vs amplitude %s", Numbers::sEB(i+1).c_str());
00129       meTimeAmpli_[i] = dqmStore_->book2D(histo, histo, 100, 0., 10., 50, -50., 50.);
00130       meTimeAmpli_[i]->setAxisTitle("energy (GeV)", 1);
00131       meTimeAmpli_[i]->setAxisTitle("time (ns)", 2);
00132       dqmStore_->tag(meTimeAmpli_[i], i+1);
00133     }
00134 
00135     sprintf(histo, "EBTMT timing vs amplitude summary");
00136     meTimeAmpliSummary_ = dqmStore_->book2D(histo, histo, 100, 0., 10., 50, -50., 50.);
00137     meTimeAmpliSummary_->setAxisTitle("energy (GeV)", 1);
00138     meTimeAmpliSummary_->setAxisTitle("time (ns)", 2);
00139 
00140     sprintf(histo, "EBTMT timing 1D summary");
00141     meTimeSummary1D_ = dqmStore_->book1D(histo, histo, 50, -50., 50.);
00142     meTimeSummary1D_->setAxisTitle("time (ns)", 1);
00143 
00144     sprintf(histo, "EBTMT timing map");
00145     meTimeSummaryMap_ = dqmStore_->bookProfile2D(histo, histo, 72, 0., 360., 34, -85, 85, 50, 25., 75., "s");
00146     meTimeSummaryMap_->setAxisTitle("jphi", 1);
00147     meTimeSummaryMap_->setAxisTitle("jeta", 2);
00148     meTimeSummaryMap_->setAxisTitle("time (ns)", 3);
00149 
00150     sprintf(histo, "EBTMT timing projection eta");
00151     meTimeSummaryMapProjEta_ = dqmStore_->bookProfile(histo, histo, 34, -85., 85., 50, -50., 50., "s");
00152     meTimeSummaryMapProjEta_->setAxisTitle("jeta", 1);
00153     meTimeSummaryMapProjEta_->setAxisTitle("time (ns)", 2);
00154 
00155     sprintf(histo, "EBTMT timing projection phi");
00156     meTimeSummaryMapProjPhi_ = dqmStore_->bookProfile(histo, histo, 72, 0., 360., 50, -50., 50., "s");
00157     meTimeSummaryMapProjPhi_->setAxisTitle("jphi", 1);
00158     meTimeSummaryMapProjPhi_->setAxisTitle("time (ns)", 2);
00159 
00160   }
00161 
00162 }
00163 
00164 void EBTimingTask::cleanup(void){
00165 
00166   if ( ! init_ ) return;
00167 
00168   if ( dqmStore_ ) {
00169     dqmStore_->setCurrentFolder(prefixME_ + "/EBTimingTask");
00170 
00171     for ( int i = 0; i < 36; i++ ) {
00172       if ( meTime_[i] ) dqmStore_->removeElement( meTime_[i]->getName() );
00173       meTime_[i] = 0;
00174 
00175       if ( meTimeMap_[i] ) dqmStore_->removeElement( meTimeMap_[i]->getName() );
00176       meTimeMap_[i] = 0;
00177 
00178       if ( meTimeAmpli_[i] ) dqmStore_->removeElement( meTimeAmpli_[i]->getName() );
00179       meTimeAmpli_[i] = 0;
00180     }
00181 
00182     if ( meTimeAmpliSummary_ ) dqmStore_->removeElement( meTimeAmpliSummary_->getName() );
00183     meTimeAmpliSummary_ = 0;
00184 
00185     if ( meTimeSummary1D_ ) dqmStore_->removeElement( meTimeSummary1D_->getName() );
00186     meTimeSummary1D_ = 0;
00187 
00188     if ( meTimeSummaryMap_ ) dqmStore_->removeElement( meTimeSummaryMap_->getName() );
00189     meTimeSummaryMap_ = 0;
00190 
00191     if ( meTimeSummaryMapProjEta_ ) dqmStore_->removeElement( meTimeSummaryMapProjEta_->getName() );
00192     meTimeSummaryMapProjEta_ = 0;
00193 
00194     if ( meTimeSummaryMapProjPhi_ ) dqmStore_->removeElement( meTimeSummaryMapProjPhi_->getName() );
00195     meTimeSummaryMapProjPhi_ = 0;
00196 
00197   }
00198 
00199   init_ = false;
00200 
00201 }
00202 
00203 void EBTimingTask::endJob(void){
00204 
00205   edm::LogInfo("EBTimingTask") << "analyzed " << ievt_ << " events";
00206 
00207   if ( enableCleanup_ ) this->cleanup();
00208 
00209 }
00210 
00211 void EBTimingTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00212 
00213   bool isData = true;
00214   bool enable = false;
00215   int runType[36];
00216   for (int i=0; i<36; i++) runType[i] = -1;
00217 
00218   edm::Handle<EcalRawDataCollection> dcchs;
00219 
00220   if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
00221 
00222     for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
00223 
00224       if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
00225 
00226       int ism = Numbers::iSM( *dcchItr, EcalBarrel );
00227 
00228       runType[ism-1] = dcchItr->getRunType();
00229 
00230       if ( dcchItr->getRunType() == EcalDCCHeaderBlock::COSMIC ||
00231            dcchItr->getRunType() == EcalDCCHeaderBlock::MTCC ||
00232            dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
00233            dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
00234            dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_LOCAL ||
00235            dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_LOCAL ) enable = true;
00236 
00237     }
00238 
00239   } else {
00240 
00241     isData = false; enable = true;
00242     edm::LogWarning("EBTimingTask") << EcalRawDataCollection_ << " not available";
00243 
00244   }
00245 
00246   if ( ! enable ) return;
00247 
00248   if ( ! init_ ) this->setup();
00249 
00250   ievt_++;
00251 
00252   // channel status
00253   edm::ESHandle<EcalChannelStatus> pChannelStatus;
00254   c.get<EcalChannelStatusRcd>().get(pChannelStatus);
00255   const EcalChannelStatus* chStatus = pChannelStatus.product();
00256 
00257   edm::Handle<EcalRecHitCollection> hits;
00258 
00259   if ( e.getByLabel(EcalRecHitCollection_, hits) ) {
00260 
00261     int neh = hits->size();
00262     LogDebug("EBTimingTask") << "event " << ievt_ << " hits collection size " << neh;
00263 
00264     for ( EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
00265 
00266       EBDetId id = hitItr->id();
00267 
00268       int ic = id.ic();
00269       int ie = (ic-1)/20 + 1;
00270       int ip = (ic-1)%20 + 1;
00271 
00272       int ism = Numbers::iSM( id );
00273 
00274       float xie = ie - 0.5;
00275       float xip = ip - 0.5;
00276 
00277       if ( isData ) {
00278 
00279         if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::COSMIC ||
00280                  runType[ism-1] == EcalDCCHeaderBlock::MTCC ||
00281                  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
00282                  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
00283                  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_LOCAL ||
00284                  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_LOCAL ) ) continue;
00285 
00286       }
00287 
00288       MonitorElement* meTime = 0;
00289       MonitorElement* meTimeMap = 0;
00290       MonitorElement* meTimeAmpli = 0;
00291 
00292       meTime = meTime_[ism-1];
00293       meTimeMap = meTimeMap_[ism-1];
00294       meTimeAmpli = meTimeAmpli_[ism-1];
00295 
00296       float xval = hitItr->energy();
00297       float yval = hitItr->time();
00298 
00299       uint32_t flag = hitItr->recoFlag();
00300       uint32_t sev = EcalSeverityLevelAlgo::severityLevel(id, *hits, *chStatus );
00301 
00302       if ( (flag == EcalRecHit::kGood || flag == EcalRecHit::kOutOfTime) && sev != EcalSeverityLevelAlgo::kWeird ) {
00303         if ( meTimeAmpli ) meTimeAmpli->Fill(xval, yval);
00304         if ( meTimeAmpliSummary_ ) meTimeAmpliSummary_->Fill(xval, yval);
00305 
00306         if ( xval > 0.480 ) {
00307           if ( meTime ) meTime->Fill(yval);
00308           if ( meTimeMap ) meTimeMap->Fill(xie, xip, yval+50.);
00309           if ( meTimeSummary1D_ ) meTimeSummary1D_->Fill(yval);
00310 
00311           float xebeta = id.ieta() - 0.5 * id.zside();
00312           float xebphi = id.iphi() - 0.5;
00313           if ( meTimeSummaryMap_ ) meTimeSummaryMap_->Fill(xebphi, xebeta, yval+50.);
00314           if ( meTimeSummaryMapProjEta_ ) meTimeSummaryMapProjEta_->Fill(xebeta, yval);
00315           if ( meTimeSummaryMapProjPhi_ ) meTimeSummaryMapProjPhi_->Fill(xebphi, yval);
00316         }
00317 
00318       }
00319     }
00320 
00321   } else {
00322 
00323     edm::LogWarning("EBTimingTask") << EcalRecHitCollection_ << " not available";
00324 
00325   }
00326 
00327 }
00328