00001
00002
00003
00004
00005
00006
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/EEDetId.h"
00023 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.h"
00024 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00025
00026 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
00027 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
00028
00029 #include "DQM/EcalCommon/interface/Numbers.h"
00030
00031 #include "DQM/EcalEndcapMonitorTasks/interface/EETimingTask.h"
00032
00033 EETimingTask::EETimingTask(const edm::ParameterSet& ps){
00034
00035 init_ = false;
00036
00037 initCaloGeometry_ = false;
00038
00039 dqmStore_ = edm::Service<DQMStore>().operator->();
00040
00041 prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00042
00043 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00044
00045 mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00046
00047 EcalRawDataCollection_ = ps.getParameter<edm::InputTag>("EcalRawDataCollection");
00048 EcalRecHitCollection_ = ps.getParameter<edm::InputTag>("EcalRecHitCollection");
00049
00050 for (int i = 0; i < 18; i++) {
00051 meTime_[i] = 0;
00052 meTimeMap_[i] = 0;
00053 meTimeAmpli_[i] = 0;
00054 }
00055
00056 for (int i = 0; i < 2; i++) {
00057 meTimeAmpliSummary_[i] = 0;
00058 meTimeSummary1D_[i] = 0;
00059 meTimeSummaryMap_[i] = 0;
00060 meTimeSummaryMapProjEta_[i] = 0;
00061 meTimeSummaryMapProjPhi_[i] = 0;
00062 }
00063
00064 meTimeDelta_ = 0;
00065 meTimeDelta2D_ = 0;
00066
00067 }
00068
00069 EETimingTask::~EETimingTask(){
00070
00071 }
00072
00073 void EETimingTask::beginJob(void){
00074
00075 ievt_ = 0;
00076
00077 if ( dqmStore_ ) {
00078 dqmStore_->setCurrentFolder(prefixME_ + "/EETimingTask");
00079 dqmStore_->rmdir(prefixME_ + "/EETimingTask");
00080 }
00081
00082 }
00083
00084 void EETimingTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00085
00086 Numbers::initGeometry(c, true);
00087
00088 if( !initCaloGeometry_ ) {
00089 c.get<CaloGeometryRecord>().get(pGeometry_);
00090 initCaloGeometry_ = true;
00091 }
00092
00093 if ( ! mergeRuns_ ) this->reset();
00094
00095 }
00096
00097 void EETimingTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00098
00099 }
00100
00101 void EETimingTask::reset(void) {
00102
00103 for (int i = 0; i < 18; i++) {
00104 if ( meTime_[i] ) meTime_[i]->Reset();
00105 if ( meTimeMap_[i] ) meTimeMap_[i]->Reset();
00106 if ( meTimeAmpli_[i] ) meTimeAmpli_[i]->Reset();
00107 }
00108
00109 for (int i = 0; i < 2; i++) {
00110 if ( meTimeAmpliSummary_[i] ) meTimeAmpliSummary_[i]->Reset();
00111 if ( meTimeSummary1D_[i] ) meTimeSummary1D_[i]->Reset();
00112 if ( meTimeSummaryMap_[i] ) meTimeSummaryMap_[i]->Reset();
00113 if ( meTimeSummaryMapProjEta_[i] ) meTimeSummaryMapProjEta_[i]->Reset();
00114 if ( meTimeSummaryMapProjPhi_[i] ) meTimeSummaryMapProjPhi_[i]->Reset();
00115 }
00116
00117 if ( meTimeDelta_ ) meTimeDelta_->Reset();
00118 if ( meTimeDelta2D_ ) meTimeDelta2D_->Reset();
00119
00120 }
00121
00122 void EETimingTask::setup(void){
00123
00124 init_ = true;
00125
00126 char histo[200];
00127
00128 if ( dqmStore_ ) {
00129 dqmStore_->setCurrentFolder(prefixME_ + "/EETimingTask");
00130
00131 for (int i = 0; i < 18; i++) {
00132 sprintf(histo, "EETMT timing 1D %s", Numbers::sEE(i+1).c_str());
00133 meTime_[i] = dqmStore_->book1D(histo, histo, 50, -50., 50.);
00134 meTime_[i]->setAxisTitle("time (ns)", 1);
00135 dqmStore_->tag(meTime_[i], i+1);
00136
00137 sprintf(histo, "EETMT timing %s", Numbers::sEE(i+1).c_str());
00138 meTimeMap_[i] = dqmStore_->bookProfile2D(histo, histo, 50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50., 50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50., -25.+shiftProf2D, 25.+shiftProf2D, "s");
00139 meTimeMap_[i]->setAxisTitle("ix", 1);
00140 if ( i+1 >= 1 && i+1 <= 9 ) meTimeMap_[i]->setAxisTitle("101-ix", 1);
00141 meTimeMap_[i]->setAxisTitle("iy", 2);
00142 meTimeMap_[i]->setAxisTitle("time (ns)", 3);
00143 dqmStore_->tag(meTimeMap_[i], i+1);
00144
00145 sprintf(histo, "EETMT timing vs amplitude %s", Numbers::sEE(i+1).c_str());
00146 meTimeAmpli_[i] = dqmStore_->book2D(histo, histo, 100, 0., 10., 50, -50., 50.);
00147 meTimeAmpli_[i]->setAxisTitle("energy (GeV)", 1);
00148 meTimeAmpli_[i]->setAxisTitle("time (ns)", 2);
00149 dqmStore_->tag(meTimeAmpli_[i], i+1);
00150 }
00151
00152 sprintf(histo, "EETMT timing vs amplitude summary EE -");
00153 meTimeAmpliSummary_[0] = dqmStore_->book2D(histo, histo, 100, 0., 10., 50, -50., 50.);
00154 meTimeAmpliSummary_[0]->setAxisTitle("energy (GeV)", 1);
00155 meTimeAmpliSummary_[0]->setAxisTitle("time (ns)", 2);
00156
00157 sprintf(histo, "EETMT timing vs amplitude summary EE +");
00158 meTimeAmpliSummary_[1] = dqmStore_->book2D(histo, histo, 100, 0., 10., 50, -50., 50.);
00159 meTimeAmpliSummary_[1]->setAxisTitle("energy (GeV)", 1);
00160 meTimeAmpliSummary_[1]->setAxisTitle("time (ns)", 2);
00161
00162 sprintf(histo, "EETMT timing 1D summary EE -");
00163 meTimeSummary1D_[0] = dqmStore_->book1D(histo, histo, 50, -50., 50.);
00164 meTimeSummary1D_[0]->setAxisTitle("time (ns)", 1);
00165
00166 sprintf(histo, "EETMT timing 1D summary EE +");
00167 meTimeSummary1D_[1] = dqmStore_->book1D(histo, histo, 50, -50., 50.);
00168 meTimeSummary1D_[1]->setAxisTitle("time (ns)", 1);
00169
00170 sprintf(histo, "EETMT timing map EE -");
00171 meTimeSummaryMap_[0] = dqmStore_->bookProfile2D(histo, histo, 20, 0., 100., 20, 0., 100., 50, -25.+shiftProf2D, 25.+shiftProf2D, "s");
00172 meTimeSummaryMap_[0]->setAxisTitle("ix'", 1);
00173 meTimeSummaryMap_[0]->setAxisTitle("101-iy'", 2);
00174 meTimeSummaryMap_[0]->setAxisTitle("time (ns)", 3);
00175
00176 sprintf(histo, "EETMT timing map EE +");
00177 meTimeSummaryMap_[1] = dqmStore_->bookProfile2D(histo, histo, 20, 0., 100., 20, 0., 100., 50, -25.+shiftProf2D, 25.+shiftProf2D, "s");
00178 meTimeSummaryMap_[1]->setAxisTitle("ix'", 1);
00179 meTimeSummaryMap_[1]->setAxisTitle("iy'", 2);
00180 meTimeSummaryMap_[1]->setAxisTitle("time (ns)", 3);
00181
00182 sprintf(histo, "EETMT timing projection eta EE -");
00183 meTimeSummaryMapProjEta_[0] = dqmStore_->bookProfile(histo, histo, 20, -3.0, -1.479, 50, -25., 25., "s");
00184 meTimeSummaryMapProjEta_[0]->setAxisTitle("eta", 1);
00185 meTimeSummaryMapProjEta_[0]->setAxisTitle("time (ns)", 2);
00186
00187 sprintf(histo, "EETMT timing projection eta EE +");
00188 meTimeSummaryMapProjEta_[1] = dqmStore_->bookProfile(histo, histo, 20, 1.479, 3.0, 50, -25., 25., "s");
00189 meTimeSummaryMapProjEta_[1]->setAxisTitle("eta", 1);
00190 meTimeSummaryMapProjEta_[1]->setAxisTitle("time (ns)", 2);
00191
00192 sprintf(histo, "EETMT timing projection phi EE -");
00193 meTimeSummaryMapProjPhi_[0] = dqmStore_->bookProfile(histo, histo, 50, -M_PI, M_PI, 50, -25., 25., "s");
00194 meTimeSummaryMapProjPhi_[0]->setAxisTitle("phi", 1);
00195 meTimeSummaryMapProjPhi_[0]->setAxisTitle("time (ns)", 2);
00196
00197 sprintf(histo, "EETMT timing projection phi EE +");
00198 meTimeSummaryMapProjPhi_[1] = dqmStore_->bookProfile(histo, histo, 50, -M_PI, M_PI, 50, -25., 25., "s");
00199 meTimeSummaryMapProjPhi_[1]->setAxisTitle("phi", 1);
00200 meTimeSummaryMapProjPhi_[1]->setAxisTitle("time (ns)", 2);
00201
00202 sprintf(histo, "EETMT timing EE+ - EE-");
00203 meTimeDelta_ = dqmStore_->book1D(histo, histo, 100, -3., 3.);
00204 meTimeDelta_->setAxisTitle("time (ns)", 1);
00205
00206 sprintf(histo, "EETMT timing EE+ vs EE-");
00207 meTimeDelta2D_ = dqmStore_->book2D(histo, histo, 50, -50., 50., 50, -50., 50.);
00208 meTimeDelta2D_->setAxisTitle("EE+ average time (ns)", 1);
00209 meTimeDelta2D_->setAxisTitle("EE- average time (ns)", 2);
00210
00211 }
00212
00213 }
00214
00215 void EETimingTask::cleanup(void){
00216
00217 if ( ! init_ ) return;
00218
00219 if ( dqmStore_ ) {
00220 dqmStore_->setCurrentFolder(prefixME_ + "/EETimingTask");
00221
00222 for ( int i = 0; i < 18; i++ ) {
00223 if ( meTime_[i] ) dqmStore_->removeElement( meTime_[i]->getName() );
00224 meTime_[i] = 0;
00225
00226 if ( meTimeMap_[i] ) dqmStore_->removeElement( meTimeMap_[i]->getName() );
00227 meTimeMap_[i] = 0;
00228
00229 if ( meTimeAmpli_[i] ) dqmStore_->removeElement( meTimeAmpli_[i]->getName() );
00230 meTimeAmpli_[i] = 0;
00231 }
00232
00233 for (int i = 0; i < 2; i++) {
00234 if ( meTimeAmpliSummary_[i] ) dqmStore_->removeElement( meTimeAmpliSummary_[i]->getName() );
00235 meTimeAmpliSummary_[i] = 0;
00236
00237 if ( meTimeSummary1D_[i] ) dqmStore_->removeElement( meTimeSummary1D_[i]->getName() );
00238 meTimeSummary1D_[i] = 0;
00239
00240 if ( meTimeSummaryMap_[i] ) dqmStore_->removeElement( meTimeSummaryMap_[i]->getName() );
00241 meTimeSummaryMap_[i] = 0;
00242
00243 if ( meTimeSummaryMapProjEta_[i] ) dqmStore_->removeElement( meTimeSummaryMapProjEta_[i]->getName() );
00244 meTimeSummaryMapProjEta_[i] = 0;
00245
00246 if ( meTimeSummaryMapProjPhi_[i] ) dqmStore_->removeElement( meTimeSummaryMapProjPhi_[i]->getName() );
00247 meTimeSummaryMapProjPhi_[i] = 0;
00248 }
00249
00250 if ( meTimeDelta_ ) dqmStore_->removeElement( meTimeDelta_->getName() );
00251 meTimeDelta_ = 0;
00252
00253 if ( meTimeDelta2D_ ) dqmStore_->removeElement( meTimeDelta2D_->getName() );
00254 meTimeDelta2D_ = 0;
00255
00256 }
00257
00258 init_ = false;
00259
00260 }
00261
00262 void EETimingTask::endJob(void){
00263
00264 edm::LogInfo("EETimingTask") << "analyzed " << ievt_ << " events";
00265
00266 if ( enableCleanup_ ) this->cleanup();
00267
00268 }
00269
00270 void EETimingTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00271
00272 bool isData = true;
00273 bool enable = false;
00274 int runType[18];
00275 for (int i=0; i<18; i++) runType[i] = -1;
00276
00277 edm::Handle<EcalRawDataCollection> dcchs;
00278
00279 if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
00280
00281 for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
00282
00283 if ( Numbers::subDet( *dcchItr ) != EcalEndcap ) continue;
00284
00285 int ism = Numbers::iSM( *dcchItr, EcalEndcap );
00286
00287 runType[ism-1] = dcchItr->getRunType();
00288
00289 if ( dcchItr->getRunType() == EcalDCCHeaderBlock::COSMIC ||
00290 dcchItr->getRunType() == EcalDCCHeaderBlock::MTCC ||
00291 dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
00292 dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
00293 dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_LOCAL ||
00294 dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_LOCAL ) enable = true;
00295
00296 }
00297
00298 } else {
00299
00300 isData = false; enable = true;
00301 edm::LogWarning("EETimingTask") << EcalRawDataCollection_ << " not available";
00302
00303 }
00304
00305 if ( ! enable ) return;
00306
00307 if ( ! init_ ) this->setup();
00308
00309 ievt_++;
00310
00311 float sumTime_hithr[2] = {0.,0.};
00312 int n_hithr[2] = {0,0};
00313
00314 edm::ESHandle<EcalSeverityLevelAlgo> sevlv;
00315 c.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
00316
00317 edm::Handle<EcalRecHitCollection> hits;
00318
00319 if ( e.getByLabel(EcalRecHitCollection_, hits) ) {
00320
00321 int neh = hits->size();
00322 LogDebug("EETimingTask") << "event " << ievt_ << " hits collection size " << neh;
00323
00324 for ( EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
00325
00326 EEDetId id = hitItr->id();
00327
00328 int ix = id.ix();
00329 int iy = id.iy();
00330 int iz = ( id.positiveZ() ) ? 1 : 0;
00331
00332 int ism = Numbers::iSM( id );
00333
00334 if ( ism >= 1 && ism <= 9 ) ix = 101 - ix;
00335
00336 float xix = ix - 0.5;
00337 float xiy = iy - 0.5;
00338
00339 if ( isData ) {
00340
00341 if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::COSMIC ||
00342 runType[ism-1] == EcalDCCHeaderBlock::MTCC ||
00343 runType[ism-1] == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
00344 runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
00345 runType[ism-1] == EcalDCCHeaderBlock::COSMICS_LOCAL ||
00346 runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_LOCAL ) ) continue;
00347
00348 }
00349
00350 MonitorElement* meTime = 0;
00351 MonitorElement* meTimeMap = 0;
00352 MonitorElement* meTimeAmpli = 0;
00353
00354 meTime = meTime_[ism-1];
00355 meTimeMap = meTimeMap_[ism-1];
00356 meTimeAmpli = meTimeAmpli_[ism-1];
00357
00358 float xval = hitItr->energy();
00359 float yval = hitItr->time();
00360
00361 uint32_t flag = hitItr->recoFlag();
00362
00363 uint32_t sev = sevlv->severityLevel(id, *hits );
00364
00365 const GlobalPoint& pos = pGeometry_->getGeometry(id)->getPosition();
00366
00367 float theta = pos.theta();
00368 float eta = pos.eta();
00369 float phi = pos.phi();
00370
00371 float et = hitItr->energy() * std::abs(sin(theta));
00372
00373 if ( (flag == EcalRecHit::kGood || flag == EcalRecHit::kOutOfTime) && sev != EcalSeverityLevelAlgo::kWeird ) {
00374 if ( meTimeAmpli ) meTimeAmpli->Fill(xval, yval);
00375 if ( meTimeAmpliSummary_[iz] ) meTimeAmpliSummary_[iz]->Fill(xval, yval);
00376 if ( et > 0.600 ) {
00377 if ( meTimeMap ) meTimeMap->Fill(xix, xiy, yval+shiftProf2D);
00378 if ( meTime ) meTime->Fill(yval);
00379 if ( meTimeSummary1D_[iz] ) meTimeSummary1D_[iz]->Fill(yval);
00380
00381 if ( meTimeSummaryMap_[iz] ) meTimeSummaryMap_[iz]->Fill(id.ix()-0.5, xiy, yval+shiftProf2D);
00382 if ( meTimeSummaryMapProjEta_[iz] ) meTimeSummaryMapProjEta_[iz]->Fill(eta, yval);
00383 if ( meTimeSummaryMapProjPhi_[iz] ) meTimeSummaryMapProjPhi_[iz]->Fill(phi, yval);
00384
00385 sumTime_hithr[iz] += yval;
00386 n_hithr[iz]++;
00387 }
00388 }
00389 }
00390
00391 if (n_hithr[0] > 0 && n_hithr[1] > 0 ) {
00392 if ( meTimeDelta_ ) meTimeDelta_->Fill( sumTime_hithr[1]/n_hithr[1] - sumTime_hithr[0]/n_hithr[0] );
00393 if ( meTimeDelta2D_ ) meTimeDelta2D_->Fill( sumTime_hithr[1]/n_hithr[1], sumTime_hithr[0]/n_hithr[0] );
00394 }
00395
00396 } else {
00397
00398 edm::LogWarning("EETimingTask") << EcalRecHitCollection_ << " not available";
00399
00400 }
00401
00402 }
00403