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