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
00016 #include "DQMServices/Core/interface/MonitorElement.h"
00017
00018 #include "DQMServices/Core/interface/DQMStore.h"
00019
00020 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00021 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00022 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.h"
00023 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00024
00025 #include "DQM/EcalCommon/interface/Numbers.h"
00026
00027 #include "DQM/EcalBarrelMonitorTasks/interface/EBCosmicTask.h"
00028
00029 EBCosmicTask::EBCosmicTask(const edm::ParameterSet& ps){
00030
00031 init_ = false;
00032
00033 dqmStore_ = edm::Service<DQMStore>().operator->();
00034
00035 prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00036
00037 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00038
00039 mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00040
00041 EcalRawDataCollection_ = ps.getParameter<edm::InputTag>("EcalRawDataCollection");
00042 EcalUncalibratedRecHitCollection_ = ps.getParameter<edm::InputTag>("EcalUncalibratedRecHitCollection");
00043 EcalRecHitCollection_ = ps.getParameter<edm::InputTag>("EcalRecHitCollection");
00044
00045 threshold_ = 0.12500;
00046
00047 minJitter_ = -2.0;
00048 maxJitter_ = 1.5;
00049
00050 for (int i = 0; i < 36; i++) {
00051 meSelMap_[i] = 0;
00052 meSpectrum_[0][i] = 0;
00053 meSpectrum_[1][i] = 0;
00054 }
00055
00056 }
00057
00058 EBCosmicTask::~EBCosmicTask(){
00059
00060 }
00061
00062 void EBCosmicTask::beginJob(void){
00063
00064 ievt_ = 0;
00065
00066 if ( dqmStore_ ) {
00067 dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask");
00068 dqmStore_->rmdir(prefixME_ + "/EBCosmicTask");
00069 }
00070
00071 }
00072
00073 void EBCosmicTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00074
00075 Numbers::initGeometry(c, false);
00076
00077 if ( ! mergeRuns_ ) this->reset();
00078
00079 }
00080
00081 void EBCosmicTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00082
00083 }
00084
00085 void EBCosmicTask::reset(void) {
00086
00087 for (int i = 0; i < 36; i++) {
00088 if ( meSelMap_[i] ) meSelMap_[i]->Reset();
00089 if ( meSpectrum_[0][i] ) meSpectrum_[0][i]->Reset();
00090 if ( meSpectrum_[1][i] ) meSpectrum_[1][i]->Reset();
00091 }
00092
00093 }
00094
00095 void EBCosmicTask::setup(void){
00096
00097 init_ = true;
00098
00099 char histo[200];
00100
00101 if ( dqmStore_ ) {
00102 dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask");
00103
00104 dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Sel");
00105 for (int i = 0; i < 36; i++) {
00106 sprintf(histo, "EBCT energy sel %s", Numbers::sEB(i+1).c_str());
00107 meSelMap_[i] = dqmStore_->bookProfile2D(histo, histo, 85, 0., 85., 20, 0., 20., 4096, 0., 4096., "s");
00108 meSelMap_[i]->setAxisTitle("ieta", 1);
00109 meSelMap_[i]->setAxisTitle("iphi", 2);
00110 meSelMap_[i]->setAxisTitle("energy (GeV)", 3);
00111 }
00112
00113 dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Spectrum");
00114 for (int i = 0; i < 36; i++) {
00115 sprintf(histo, "EBCT 1x1 energy spectrum %s", Numbers::sEB(i+1).c_str());
00116 meSpectrum_[0][i] = dqmStore_->book1D(histo, histo, 100, 0., 1.5);
00117 meSpectrum_[0][i]->setAxisTitle("energy (GeV)", 1);
00118 sprintf(histo, "EBCT 3x3 energy spectrum %s", Numbers::sEB(i+1).c_str());
00119 meSpectrum_[1][i] = dqmStore_->book1D(histo, histo, 100, 0., 1.5);
00120 meSpectrum_[1][i]->setAxisTitle("energy (GeV)", 1);
00121 }
00122
00123 }
00124
00125 }
00126
00127 void EBCosmicTask::cleanup(void){
00128
00129 if ( ! init_ ) return;
00130
00131 if ( dqmStore_ ) {
00132 dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask");
00133
00134 dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Cut");
00135 for (int i = 0; i < 36; i++) {
00136 if ( meCutMap_[i] ) dqmStore_->removeElement( meCutMap_[i]->getName() );
00137 meCutMap_[i] = 0;
00138 }
00139
00140 dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Sel");
00141 for (int i = 0; i < 36; i++) {
00142 if ( meSelMap_[i] ) dqmStore_->removeElement( meSelMap_[i]->getName() );
00143 meSelMap_[i] = 0;
00144 }
00145
00146 dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Spectrum");
00147 for (int i = 0; i < 36; i++) {
00148 if ( meSpectrum_[0][i] ) dqmStore_->removeElement( meSpectrum_[0][i]->getName() );
00149 meSpectrum_[0][i] = 0;
00150 if ( meSpectrum_[1][i] ) dqmStore_->removeElement( meSpectrum_[1][i]->getName() );
00151 meSpectrum_[1][i] = 0;
00152 }
00153
00154 }
00155
00156 init_ = false;
00157
00158 }
00159
00160 void EBCosmicTask::endJob(void){
00161
00162 edm::LogInfo("EBCosmicTask") << "analyzed " << ievt_ << " events";
00163
00164 if ( enableCleanup_ ) this->cleanup();
00165
00166 }
00167
00168 void EBCosmicTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00169
00170 bool isData = true;
00171 bool enable = false;
00172 int runType[36];
00173 for (int i=0; i<36; i++) runType[i] = -1;
00174
00175 edm::Handle<EcalRawDataCollection> dcchs;
00176
00177 if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
00178
00179 for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
00180
00181 if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
00182
00183 int ism = Numbers::iSM( *dcchItr, EcalBarrel );
00184
00185 runType[ism-1] = dcchItr->getRunType();
00186
00187 if ( dcchItr->getRunType() == EcalDCCHeaderBlock::COSMIC ||
00188 dcchItr->getRunType() == EcalDCCHeaderBlock::MTCC ||
00189 dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
00190 dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
00191 dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_LOCAL ||
00192 dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_LOCAL ) enable = true;
00193
00194 }
00195
00196 } else {
00197
00198 isData = false; enable = true;
00199 edm::LogWarning("EBCosmicTask") << EcalRawDataCollection_ << " not available";
00200
00201 }
00202
00203 if ( ! enable ) return;
00204
00205 if ( ! init_ ) this->setup();
00206
00207 ievt_++;
00208
00209 edm::Handle<EcalRecHitCollection> hits;
00210
00211 if ( e.getByLabel(EcalRecHitCollection_, hits) ) {
00212
00213 int nebh = hits->size();
00214 LogDebug("EBCosmicTask") << "event " << ievt_ << " hits collection size " << nebh;
00215
00216 edm::Handle<EcalUncalibratedRecHitCollection> uhits;
00217
00218 if ( ! e.getByLabel(EcalUncalibratedRecHitCollection_, uhits) ) {
00219 edm::LogWarning("EBCosmicTask") << EcalUncalibratedRecHitCollection_ << " not available";
00220 }
00221
00222 for ( EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
00223
00224 EBDetId id = hitItr->id();
00225
00226 int ic = id.ic();
00227 int ie = (ic-1)/20 + 1;
00228 int ip = (ic-1)%20 + 1;
00229
00230 int ism = Numbers::iSM( id );
00231
00232 float xie = ie - 0.5;
00233 float xip = ip - 0.5;
00234
00235 if ( isData ) {
00236
00237 if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::COSMIC ||
00238 runType[ism-1] == EcalDCCHeaderBlock::MTCC ||
00239 runType[ism-1] == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
00240 runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
00241 runType[ism-1] == EcalDCCHeaderBlock::COSMICS_LOCAL ||
00242 runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_LOCAL ) ) continue;
00243
00244 }
00245
00246 float xval = hitItr->energy();
00247 if ( xval <= 0. ) xval = 0.0;
00248
00249
00250 float e3x3 = 0.;
00251 bool isSeed = true;
00252
00253
00254 for(int icry=0; icry<9; ++icry) {
00255 unsigned int row = icry/3;
00256 unsigned int column = icry%3;
00257 int icryEta = id.ieta()+column-1;
00258 int icryPhi = id.iphi()+row-1;
00259 if ( EBDetId::validDetId(icryEta, icryPhi) ) {
00260 EBDetId id3x3 = EBDetId(icryEta, icryPhi, EBDetId::ETAPHIMODE);
00261 if ( hits->find(id3x3) != hits->end() ) {
00262 float neighbourEnergy = hits->find(id3x3)->energy();
00263 e3x3 += neighbourEnergy;
00264 if ( neighbourEnergy > xval ) isSeed = false;
00265 }
00266 }
00267 }
00268
00269
00270 float jitter = -999.;
00271 if ( isSeed ) {
00272 if ( uhits.isValid() ) {
00273 if ( uhits->find(id) != uhits->end() ) {
00274 jitter = uhits->find(id)->jitter();
00275 }
00276 }
00277 }
00278
00279 if ( isSeed && e3x3 >= threshold_ && jitter > minJitter_ && jitter < maxJitter_ ) {
00280 if ( meSelMap_[ism-1] ) meSelMap_[ism-1]->Fill(xie, xip, e3x3);
00281 }
00282
00283 if ( meSpectrum_[0][ism-1] ) meSpectrum_[0][ism-1]->Fill(xval);
00284
00285 if ( isSeed && xval >= threshold_ && jitter > minJitter_ && jitter < maxJitter_ ) {
00286 if ( meSpectrum_[1][ism-1] ) meSpectrum_[1][ism-1]->Fill(e3x3);
00287 }
00288
00289 }
00290
00291 } else {
00292
00293 edm::LogWarning("EBCosmicTask") << EcalRecHitCollection_ << " not available";
00294
00295 }
00296
00297 }
00298