CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/DQM/EcalBarrelMonitorTasks/src/EBPedestalOnlineTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EBPedestalOnlineTask.cc
00003  *
00004  * $Date: 2012/06/28 12:14:29 $
00005  * $Revision: 1.51 $
00006  * \author G. Della Ricca
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/EcalDetId/interface/EBDetId.h"
00021 #include "DataFormats/EcalDigi/interface/EBDataFrame.h"
00022 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00023 
00024 #include "DQM/EcalCommon/interface/Numbers.h"
00025 
00026 #include "DQM/EcalBarrelMonitorTasks/interface/EBPedestalOnlineTask.h"
00027 
00028 EBPedestalOnlineTask::EBPedestalOnlineTask(const edm::ParameterSet& ps){
00029 
00030   init_ = false;
00031 
00032   dqmStore_ = edm::Service<DQMStore>().operator->();
00033 
00034   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00035 
00036   subfolder_ = ps.getUntrackedParameter<std::string>("subfolder", "");
00037 
00038   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00039 
00040   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00041 
00042   EBDigiCollection_ = ps.getParameter<edm::InputTag>("EBDigiCollection");
00043 
00044   for (int i = 0; i < 36; i++) {
00045     mePedMapG12_[i] = 0;
00046   }
00047 
00048 }
00049 
00050 EBPedestalOnlineTask::~EBPedestalOnlineTask(){
00051 
00052 }
00053 
00054 void EBPedestalOnlineTask::beginJob(void){
00055 
00056   ievt_ = 0;
00057 
00058   if ( dqmStore_ ) {
00059     dqmStore_->setCurrentFolder(prefixME_ + "/EBPedestalOnlineTask");
00060     dqmStore_->rmdir(prefixME_ + "/EBPedestalOnlineTask");
00061   }
00062 
00063 }
00064 
00065 void EBPedestalOnlineTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00066 
00067   Numbers::initGeometry(c, false);
00068 
00069   if ( ! mergeRuns_ ) this->reset();
00070 
00071 }
00072 
00073 void EBPedestalOnlineTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00074 
00075 }
00076 
00077 void EBPedestalOnlineTask::reset(void) {
00078 
00079   for (int i = 0; i < 36; i++) {
00080     if ( mePedMapG12_[i] ) mePedMapG12_[i]->Reset();
00081   }
00082 
00083 }
00084 
00085 void EBPedestalOnlineTask::setup(void){
00086 
00087   init_ = true;
00088 
00089   std::string name;
00090   std::string dir;
00091 
00092   if ( dqmStore_ ) {
00093     dir = prefixME_ + "/EBPedestalOnlineTask";
00094     if(subfolder_.size())
00095       dir += "/" + subfolder_;
00096 
00097     dqmStore_->setCurrentFolder(dir);
00098 
00099     dqmStore_->setCurrentFolder(dir + "/Gain12");
00100     for (int i = 0; i < 36; i++) {
00101       name = "EBPOT pedestal " + Numbers::sEB(i+1) + " G12";
00102       mePedMapG12_[i] = dqmStore_->bookProfile2D(name, name, 85, 0., 85., 20, 0., 20., 4096, 0., 4096., "s");
00103       mePedMapG12_[i]->setAxisTitle("ieta", 1);
00104       mePedMapG12_[i]->setAxisTitle("iphi", 2);
00105       dqmStore_->tag(mePedMapG12_[i], i+1);
00106     }
00107 
00108   }
00109 
00110 }
00111 
00112 void EBPedestalOnlineTask::cleanup(void){
00113 
00114   if ( ! init_ ) return;
00115 
00116   if ( dqmStore_ ) {
00117     std::string dir = prefixME_ + "/EBPedestalOnlineTask";
00118     if(subfolder_.size())
00119       dir += "/" + subfolder_;
00120 
00121     dqmStore_->setCurrentFolder(dir);
00122 
00123     dqmStore_->setCurrentFolder(dir + "/Gain12");
00124     for ( int i = 0; i < 36; i++ ) {
00125       if ( mePedMapG12_[i] ) dqmStore_->removeElement( mePedMapG12_[i]->getName() );
00126       mePedMapG12_[i] = 0;
00127     }
00128 
00129   }
00130 
00131   init_ = false;
00132 
00133 }
00134 
00135 void EBPedestalOnlineTask::endJob(void){
00136 
00137   edm::LogInfo("EBPedestalOnlineTask") << "analyzed " << ievt_ << " events";
00138 
00139   if ( enableCleanup_ ) this->cleanup();
00140 
00141 }
00142 
00143 void EBPedestalOnlineTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00144 
00145   if ( ! init_ ) this->setup();
00146 
00147   ievt_++;
00148 
00149   edm::Handle<EBDigiCollection> digis;
00150 
00151   if ( e.getByLabel(EBDigiCollection_, digis) ) {
00152 
00153     int nebd = digis->size();
00154     LogDebug("EBPedestalOnlineTask") << "event " << ievt_ << " digi collection size " << nebd;
00155 
00156     for ( EBDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr ) {
00157 
00158       EBDetId id = digiItr->id();
00159 
00160       int ic = id.ic();
00161       int ie = (ic-1)/20 + 1;
00162       int ip = (ic-1)%20 + 1;
00163 
00164       int ism = Numbers::iSM( id );
00165 
00166       float xie = ie - 0.5;
00167       float xip = ip - 0.5;
00168 
00169       EBDataFrame dataframe = (*digiItr);
00170 
00171       int iMax(-1);
00172       int maxADC(0);
00173       for(int i(0); i < 10; i++){
00174         if(dataframe.sample(i).gainId() != 1) break;
00175         int adc(dataframe.sample(i).adc());
00176         if(adc > maxADC){
00177           maxADC = adc;
00178           iMax = i;
00179         }
00180       }
00181 
00182       if(iMax != 5) continue;
00183 
00184       for (int i = 0; i < 3; i++) {
00185 
00186         int adc = dataframe.sample(i).adc();
00187 
00188         MonitorElement* mePedMap = 0;
00189 
00190         if ( dataframe.sample(i).gainId() == 1 ) mePedMap = mePedMapG12_[ism-1];
00191         if ( dataframe.sample(i).gainId() == 2 ) mePedMap = 0;
00192         if ( dataframe.sample(i).gainId() == 3 ) mePedMap = 0;
00193 
00194         float xval = float(adc);
00195 
00196         if ( mePedMap ) mePedMap->Fill(xie, xip, xval);
00197 
00198       }
00199 
00200     }
00201 
00202   } else {
00203 
00204     edm::LogWarning("EBPedestalOnlineTask") << EBDigiCollection_ << " not available";
00205 
00206   }
00207 
00208 }
00209