00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011 #include <fstream>
00012 #include <vector>
00013
00014 #include "FWCore/ServiceRegistry/interface/Service.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.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 <DQM/EcalCommon/interface/Numbers.h>
00027
00028 #include <DQM/EcalBarrelMonitorTasks/interface/EBTimingTask.h>
00029
00030 using namespace cms;
00031 using namespace edm;
00032 using namespace std;
00033
00034 EBTimingTask::EBTimingTask(const ParameterSet& ps){
00035
00036 init_ = false;
00037
00038 dqmStore_ = Service<DQMStore>().operator->();
00039
00040 prefixME_ = ps.getUntrackedParameter<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 EcalUncalibratedRecHitCollection_ = ps.getParameter<edm::InputTag>("EcalUncalibratedRecHitCollection");
00048
00049 for (int i = 0; i < 36; i++) {
00050 meTimeMap_[i] = 0;
00051 meTimeAmpli_[i] = 0;
00052 }
00053
00054 }
00055
00056 EBTimingTask::~EBTimingTask(){
00057
00058 }
00059
00060 void EBTimingTask::beginJob(const EventSetup& c){
00061
00062 ievt_ = 0;
00063
00064 if ( dqmStore_ ) {
00065 dqmStore_->setCurrentFolder(prefixME_ + "/EBTimingTask");
00066 dqmStore_->rmdir(prefixME_ + "/EBTimingTask");
00067 }
00068
00069 Numbers::initGeometry(c, false);
00070
00071 }
00072
00073 void EBTimingTask::beginRun(const Run& r, const EventSetup& c) {
00074
00075 if ( ! mergeRuns_ ) this->reset();
00076
00077 }
00078
00079 void EBTimingTask::endRun(const Run& r, const EventSetup& c) {
00080
00081 }
00082
00083 void EBTimingTask::reset(void) {
00084
00085 for (int i = 0; i < 36; i++) {
00086 if ( meTimeMap_[i] ) meTimeMap_[i]->Reset();
00087 if ( meTimeAmpli_[i] ) meTimeAmpli_[i]->Reset();
00088 }
00089
00090 }
00091
00092 void EBTimingTask::setup(void){
00093
00094 init_ = true;
00095
00096 char histo[200];
00097
00098 if ( dqmStore_ ) {
00099 dqmStore_->setCurrentFolder(prefixME_ + "/EBTimingTask");
00100
00101 for (int i = 0; i < 36; i++) {
00102 sprintf(histo, "EBTMT timing %s", Numbers::sEB(i+1).c_str());
00103 meTimeMap_[i] = dqmStore_->bookProfile2D(histo, histo, 85, 0., 85., 20, 0., 20., 250, 0., 10., "s");
00104 meTimeMap_[i]->setAxisTitle("ieta", 1);
00105 meTimeMap_[i]->setAxisTitle("iphi", 2);
00106 dqmStore_->tag(meTimeMap_[i], i+1);
00107
00108 sprintf(histo, "EBTMT timing vs amplitude %s", Numbers::sEB(i+1).c_str());
00109 meTimeAmpli_[i] = dqmStore_->book2D(histo, histo, 200, 0., 200., 100, 0., 10.);
00110 meTimeAmpli_[i]->setAxisTitle("amplitude", 1);
00111 meTimeAmpli_[i]->setAxisTitle("jitter", 2);
00112 dqmStore_->tag(meTimeAmpli_[i], i+1);
00113 }
00114
00115 }
00116
00117 }
00118
00119 void EBTimingTask::cleanup(void){
00120
00121 if ( ! init_ ) return;
00122
00123 if ( dqmStore_ ) {
00124 dqmStore_->setCurrentFolder(prefixME_ + "/EBTimingTask");
00125
00126 for ( int i = 0; i < 36; i++ ) {
00127 if ( meTimeMap_[i] ) dqmStore_->removeElement( meTimeMap_[i]->getName() );
00128 meTimeMap_[i] = 0;
00129 }
00130
00131 }
00132
00133 init_ = false;
00134
00135 }
00136
00137 void EBTimingTask::endJob(void){
00138
00139 LogInfo("EBTimingTask") << "analyzed " << ievt_ << " events";
00140
00141 if ( enableCleanup_ ) this->cleanup();
00142
00143 }
00144
00145 void EBTimingTask::analyze(const Event& e, const EventSetup& c){
00146
00147 bool isData = true;
00148 bool enable = false;
00149 int runType[36] = { -1 };
00150
00151 Handle<EcalRawDataCollection> dcchs;
00152
00153 if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
00154
00155 for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
00156
00157 if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
00158
00159 int ism = Numbers::iSM( *dcchItr, EcalBarrel );
00160
00161 runType[ism-1] = dcchItr->getRunType();
00162
00163 if ( dcchItr->getRunType() == EcalDCCHeaderBlock::COSMIC ||
00164 dcchItr->getRunType() == EcalDCCHeaderBlock::MTCC ||
00165 dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
00166 dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
00167 dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_LOCAL ||
00168 dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_LOCAL ) enable = true;
00169
00170 }
00171
00172 } else {
00173
00174 isData = false; enable = true;
00175 LogWarning("EBTimingTask") << EcalRawDataCollection_ << " not available";
00176
00177 }
00178
00179 if ( ! enable ) return;
00180
00181 if ( ! init_ ) this->setup();
00182
00183 ievt_++;
00184
00185 Handle<EcalUncalibratedRecHitCollection> hits;
00186
00187 if ( e.getByLabel(EcalUncalibratedRecHitCollection_, hits) ) {
00188
00189 int neh = hits->size();
00190 LogDebug("EBTimingTask") << "event " << ievt_ << " hits collection size " << neh;
00191
00192 for ( EcalUncalibratedRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
00193
00194 EBDetId id = hitItr->id();
00195
00196 int ic = id.ic();
00197 int ie = (ic-1)/20 + 1;
00198 int ip = (ic-1)%20 + 1;
00199
00200 int ism = Numbers::iSM( id );
00201
00202 float xie = ie - 0.5;
00203 float xip = ip - 0.5;
00204
00205 if ( isData ) {
00206
00207 if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::COSMIC ||
00208 runType[ism-1] == EcalDCCHeaderBlock::MTCC ||
00209 runType[ism-1] == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
00210 runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
00211 runType[ism-1] == EcalDCCHeaderBlock::COSMICS_LOCAL ||
00212 runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_LOCAL ) ) continue;
00213
00214 }
00215
00216 LogDebug("EBTimingTask") << " det id = " << id;
00217 LogDebug("EBTimingTask") << " sm, ieta, iphi " << ism << " " << ie << " " << ip;
00218
00219 MonitorElement* meTimeMap = 0;
00220 MonitorElement* meTimeAmpli = 0;
00221
00222 meTimeMap = meTimeMap_[ism-1];
00223 meTimeAmpli = meTimeAmpli_[ism-1];
00224
00225 float xval = hitItr->amplitude();
00226 if ( xval <= 0. ) xval = 0.0;
00227 float yval = hitItr->jitter() + 5.0;
00228 if ( yval <= 0. ) yval = 0.0;
00229 float zval = hitItr->pedestal();
00230 if ( zval <= 0. ) zval = 0.0;
00231
00232 LogDebug("EBTimingTask") << " hit amplitude " << xval;
00233 LogDebug("EBTimingTask") << " hit jitter " << yval;
00234 LogDebug("EBTimingTask") << " hit pedestal " << zval;
00235
00236 if ( meTimeAmpli ) meTimeAmpli->Fill(xval, yval);
00237
00238 if ( xval > 12. ) {
00239 if ( meTimeMap ) meTimeMap->Fill(xie, xip, yval);
00240 }
00241
00242 }
00243
00244 } else {
00245
00246 LogWarning("EBTimingTask") << EcalUncalibratedRecHitCollection_ << " not available";
00247
00248 }
00249
00250 }
00251