CMS 3D CMS Logo

EBCosmicTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EBCosmicTask.cc
00003  *
00004  * $Date: 2008/12/04 06:22:48 $
00005  * $Revision: 1.109 $
00006  * \author G. Della Ricca
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/EBCosmicTask.h>
00029 
00030 using namespace cms;
00031 using namespace edm;
00032 using namespace std;
00033 
00034 EBCosmicTask::EBCosmicTask(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   EcalRecHitCollection_ = ps.getParameter<edm::InputTag>("EcalRecHitCollection");
00049 
00050   lowThreshold_  = 0.06125; // 7 ADC counts at G200
00051   highThreshold_ = 0.12500; // typical muon energy deposit is 250 MeV
00052 
00053   minJitter_ = -2.0;
00054   maxJitter_ =  1.5;
00055 
00056   for (int i = 0; i < 36; i++) {
00057     meCutMap_[i] = 0;
00058     meSelMap_[i] = 0;
00059     meSpectrum_[0][i] = 0;
00060     meSpectrum_[1][i] = 0;
00061   }
00062 
00063 }
00064 
00065 EBCosmicTask::~EBCosmicTask(){
00066 
00067 }
00068 
00069 void EBCosmicTask::beginJob(const EventSetup& c){
00070 
00071   ievt_ = 0;
00072 
00073   if ( dqmStore_ ) {
00074     dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask");
00075     dqmStore_->rmdir(prefixME_ + "/EBCosmicTask");
00076   }
00077 
00078   Numbers::initGeometry(c, false);
00079 
00080 }
00081 
00082 void EBCosmicTask::beginRun(const Run& r, const EventSetup& c) {
00083 
00084   if ( ! mergeRuns_ ) this->reset();
00085 
00086 }
00087 
00088 void EBCosmicTask::endRun(const Run& r, const EventSetup& c) {
00089 
00090 }
00091 
00092 void EBCosmicTask::reset(void) {
00093 
00094   for (int i = 0; i < 36; i++) {
00095     if ( meCutMap_[i] ) meCutMap_[i]->Reset();
00096     if ( meSelMap_[i] ) meSelMap_[i]->Reset();
00097     if ( meSpectrum_[0][i] ) meSpectrum_[0][i]->Reset();
00098     if ( meSpectrum_[1][i] ) meSpectrum_[1][i]->Reset();
00099   }
00100 
00101 }
00102 
00103 void EBCosmicTask::setup(void){
00104 
00105   init_ = true;
00106 
00107   char histo[200];
00108 
00109   if ( dqmStore_ ) {
00110     dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask");
00111 
00112     dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Cut");
00113     for (int i = 0; i < 36; i++) {
00114       sprintf(histo, "EBCT energy cut %s", Numbers::sEB(i+1).c_str());
00115       meCutMap_[i] = dqmStore_->bookProfile2D(histo, histo, 85, 0., 85., 20, 0., 20., 4096, 0., 4096., "s");
00116       meCutMap_[i]->setAxisTitle("ieta", 1);
00117       meCutMap_[i]->setAxisTitle("iphi", 2);
00118     }
00119 
00120     dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Sel");
00121     for (int i = 0; i < 36; i++) {
00122       sprintf(histo, "EBCT energy sel %s", Numbers::sEB(i+1).c_str());
00123       meSelMap_[i] = dqmStore_->bookProfile2D(histo, histo, 85, 0., 85., 20, 0., 20., 4096, 0., 4096., "s");
00124       meSelMap_[i]->setAxisTitle("ieta", 1);
00125       meSelMap_[i]->setAxisTitle("iphi", 2);
00126     }
00127 
00128     dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Spectrum");
00129     for (int i = 0; i < 36; i++) {
00130       sprintf(histo, "EBCT 1x1 energy spectrum %s", Numbers::sEB(i+1).c_str());
00131       meSpectrum_[0][i] = dqmStore_->book1D(histo, histo, 100, 0., 1.5);
00132       meSpectrum_[0][i]->setAxisTitle("energy (GeV)", 1);
00133       sprintf(histo, "EBCT 3x3 energy spectrum %s", Numbers::sEB(i+1).c_str());
00134       meSpectrum_[1][i] = dqmStore_->book1D(histo, histo, 100, 0., 1.5);
00135       meSpectrum_[1][i]->setAxisTitle("energy (GeV)", 1);
00136     }
00137 
00138   }
00139 
00140 }
00141 
00142 void EBCosmicTask::cleanup(void){
00143 
00144   if ( ! init_ ) return;
00145 
00146   if ( dqmStore_ ) {
00147     dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask");
00148 
00149     dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Cut");
00150     for (int i = 0; i < 36; i++) {
00151       if ( meCutMap_[i] ) dqmStore_->removeElement( meCutMap_[i]->getName() );
00152       meCutMap_[i] = 0;
00153     }
00154 
00155     dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Sel");
00156     for (int i = 0; i < 36; i++) {
00157       if ( meSelMap_[i] ) dqmStore_->removeElement( meSelMap_[i]->getName() );
00158       meSelMap_[i] = 0;
00159     }
00160 
00161     dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Spectrum");
00162     for (int i = 0; i < 36; i++) {
00163       if ( meSpectrum_[0][i] ) dqmStore_->removeElement( meSpectrum_[0][i]->getName() );
00164       meSpectrum_[0][i] = 0;
00165       if ( meSpectrum_[1][i] ) dqmStore_->removeElement( meSpectrum_[1][i]->getName() );
00166       meSpectrum_[1][i] = 0;
00167     }
00168 
00169   }
00170 
00171   init_ = false;
00172 
00173 }
00174 
00175 void EBCosmicTask::endJob(void){
00176 
00177   LogInfo("EBCosmicTask") << "analyzed " << ievt_ << " events";
00178 
00179   if ( enableCleanup_ ) this->cleanup();
00180 
00181 }
00182 
00183 void EBCosmicTask::analyze(const Event& e, const EventSetup& c){
00184 
00185   bool isData = true;
00186   bool enable = false;
00187   int runType[36] = { -1 };
00188 
00189   Handle<EcalRawDataCollection> dcchs;
00190 
00191   if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
00192 
00193     for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
00194 
00195       if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
00196 
00197       int ism = Numbers::iSM( *dcchItr, EcalBarrel );
00198 
00199       runType[ism-1] = dcchItr->getRunType();
00200 
00201       if ( dcchItr->getRunType() == EcalDCCHeaderBlock::COSMIC ||
00202            dcchItr->getRunType() == EcalDCCHeaderBlock::MTCC ||
00203            dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
00204            dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
00205            dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_LOCAL ||
00206            dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_LOCAL ) enable = true;
00207 
00208     }
00209 
00210   } else {
00211 
00212     isData = false; enable = true;
00213     LogWarning("EBCosmicTask") << EcalRawDataCollection_ << " not available";
00214 
00215   }
00216 
00217   if ( ! enable ) return;
00218 
00219   if ( ! init_ ) this->setup();
00220 
00221   ievt_++;
00222 
00223   Handle<EcalRecHitCollection> hits;
00224 
00225   if ( e.getByLabel(EcalRecHitCollection_, hits) ) {
00226 
00227     int nebh = hits->size();
00228     LogDebug("EBCosmicTask") << "event " << ievt_ << " hits collection size " << nebh;
00229 
00230     Handle<EcalUncalibratedRecHitCollection> uhits;
00231 
00232     if ( ! e.getByLabel(EcalUncalibratedRecHitCollection_, uhits) ) {
00233       LogWarning("EBCosmicTask") << EcalUncalibratedRecHitCollection_ << " not available";
00234     }
00235 
00236     for ( EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
00237 
00238       EBDetId id = hitItr->id();
00239 
00240       int ic = id.ic();
00241       int ie = (ic-1)/20 + 1;
00242       int ip = (ic-1)%20 + 1;
00243 
00244       int ism = Numbers::iSM( id );
00245 
00246       float xie = ie - 0.5;
00247       float xip = ip - 0.5;
00248 
00249       if ( isData ) {
00250 
00251         if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::COSMIC ||
00252                  runType[ism-1] == EcalDCCHeaderBlock::MTCC ||
00253                  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
00254                  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
00255                  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_LOCAL ||
00256                  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_LOCAL ) ) continue;
00257 
00258       }
00259 
00260       LogDebug("EBCosmicTask") << " det id = " << id;
00261       LogDebug("EBCosmicTask") << " sm, ieta, iphi " << ism << " " << ie << " " << ip;
00262 
00263       float xval = hitItr->energy();
00264       if ( xval <= 0. ) xval = 0.0;
00265       
00266       LogDebug("EBCosmicTask") << " hit energy " << xval;
00267 
00268       // look for the seeds 
00269       float e3x3 = 0.;
00270       bool isSeed = true;
00271 
00272       // evaluate 3x3 matrix around a seed
00273       for(int icry=0; icry<9; ++icry) {
00274         unsigned int row    = icry/3;
00275         unsigned int column = icry%3;
00276         int icryEta = id.ieta()+column-1;
00277         int icryPhi = id.iphi()+row-1;
00278         if ( EBDetId::validDetId(icryEta, icryPhi) ) {
00279           EBDetId id3x3 = EBDetId(icryEta, icryPhi, EBDetId::ETAPHIMODE);
00280           if ( hits->find(id3x3) != hits->end() ) {
00281             float neighbourEnergy = hits->find(id3x3)->energy();
00282             e3x3 += neighbourEnergy;
00283             if ( neighbourEnergy > xval ) isSeed = false;
00284           }
00285         }
00286       }
00287 
00288       // find the jitter of the seed
00289       float jitter = -999.;
00290       if ( isSeed ) {
00291         if ( uhits.isValid() ) {
00292           if ( uhits->find(id) != uhits->end() ) {
00293             jitter = uhits->find(id)->jitter();
00294           }
00295         }
00296       }
00297 
00298       if ( xval >= lowThreshold_ ) {
00299         if ( meCutMap_[ism-1] ) meCutMap_[ism-1]->Fill(xie, xip, xval);
00300       }
00301 
00302       if ( isSeed && e3x3 >= highThreshold_ && jitter > minJitter_ && jitter < maxJitter_ ) {
00303         if ( meSelMap_[ism-1] ) meSelMap_[ism-1]->Fill(xie, xip, e3x3);
00304       }
00305 
00306       if ( meSpectrum_[0][ism-1] ) meSpectrum_[0][ism-1]->Fill(xval);
00307 
00308       if ( isSeed && xval >= lowThreshold_ && jitter > minJitter_ && jitter < maxJitter_ ) {
00309         if ( meSpectrum_[1][ism-1] ) meSpectrum_[1][ism-1]->Fill(e3x3);
00310       }
00311 
00312     }
00313 
00314   } else {
00315 
00316     LogWarning("EBCosmicTask") << EcalRecHitCollection_ << " not available";
00317 
00318   }
00319 
00320 }
00321 

Generated on Tue Jun 9 17:32:46 2009 for CMSSW by  doxygen 1.5.4