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