CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/DQM/EcalEndcapMonitorTasks/src/EEPedestalOnlineTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EEPedestalOnlineTask.cc
00003  *
00004  * $Date: 2012/06/28 12:14:30 $
00005  * $Revision: 1.38 $
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/EEDetId.h"
00021 #include "DataFormats/EcalDigi/interface/EEDataFrame.h"
00022 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00023 
00024 #include "DQM/EcalCommon/interface/Numbers.h"
00025 
00026 #include "DQM/EcalEndcapMonitorTasks/interface/EEPedestalOnlineTask.h"
00027 
00028 EEPedestalOnlineTask::EEPedestalOnlineTask(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   EEDigiCollection_ = ps.getParameter<edm::InputTag>("EEDigiCollection");
00043 
00044   for (int i = 0; i < 18; i++) {
00045     mePedMapG12_[i] = 0;
00046   }
00047 
00048 }
00049 
00050 EEPedestalOnlineTask::~EEPedestalOnlineTask(){
00051 
00052 }
00053 
00054 void EEPedestalOnlineTask::beginJob(void){
00055 
00056   ievt_ = 0;
00057 
00058   if ( dqmStore_ ) {
00059     dqmStore_->setCurrentFolder(prefixME_ + "/EEPedestalOnlineTask");
00060     dqmStore_->rmdir(prefixME_ + "/EEPedestalOnlineTask");
00061   }
00062 
00063 }
00064 
00065 void EEPedestalOnlineTask::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 EEPedestalOnlineTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00074 
00075 }
00076 
00077 void EEPedestalOnlineTask::reset(void) {
00078 
00079   for (int i = 0; i < 18; i++) {
00080     if ( mePedMapG12_[i] ) mePedMapG12_[i]->Reset();
00081   }
00082 
00083 }
00084 
00085 void EEPedestalOnlineTask::setup(void){
00086 
00087   init_ = true;
00088 
00089   std::string name;
00090   std::string dir;
00091 
00092   if ( dqmStore_ ) {
00093     dir = prefixME_ + "/EEPedestalOnlineTask";
00094     if(subfolder_.size())
00095       dir += "/" + subfolder_;
00096 
00097     dqmStore_->setCurrentFolder(dir);
00098 
00099     dqmStore_->setCurrentFolder(dir + "/Gain12");
00100     for (int i = 0; i < 18; i++) {
00101       name = "EEPOT pedestal " + Numbers::sEE(i+1) + " G12";
00102       mePedMapG12_[i] = dqmStore_->bookProfile2D(name, name, 50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50., 50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50., 4096, 0., 4096., "s");
00103       mePedMapG12_[i]->setAxisTitle("ix", 1);
00104       if ( i+1 >= 1 && i+1 <= 9 ) mePedMapG12_[i]->setAxisTitle("101-ix", 1);
00105       mePedMapG12_[i]->setAxisTitle("iy", 2);
00106       dqmStore_->tag(mePedMapG12_[i], i+1);
00107     }
00108 
00109   }
00110 
00111 }
00112 
00113 void EEPedestalOnlineTask::cleanup(void){
00114 
00115   if ( ! init_ ) return;
00116 
00117   if ( dqmStore_ ) {
00118     std::string dir = prefixME_ + "/EEPedestalOnlineTask";
00119     if(subfolder_.size())
00120       dir += "/" + subfolder_;
00121 
00122     dqmStore_->setCurrentFolder(dir);
00123 
00124     dqmStore_->setCurrentFolder(dir + "/Gain12");
00125     for ( int i = 0; i < 18; i++ ) {
00126       if ( mePedMapG12_[i] ) dqmStore_->removeElement( mePedMapG12_[i]->getName() );
00127       mePedMapG12_[i] = 0;
00128     }
00129 
00130   }
00131 
00132   init_ = false;
00133 
00134 }
00135 
00136 void EEPedestalOnlineTask::endJob(void){
00137 
00138   edm::LogInfo("EEPedestalOnlineTask") << "analyzed " << ievt_ << " events";
00139 
00140   if ( enableCleanup_ ) this->cleanup();
00141 
00142 }
00143 
00144 void EEPedestalOnlineTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00145 
00146   if ( ! init_ ) this->setup();
00147 
00148   ievt_++;
00149 
00150   edm::Handle<EEDigiCollection> digis;
00151 
00152   if ( e.getByLabel(EEDigiCollection_, digis) ) {
00153 
00154     int need = digis->size();
00155     LogDebug("EEPedestalOnlineTask") << "event " << ievt_ << " digi collection size " << need;
00156 
00157     for ( EEDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr ) {
00158 
00159       EEDetId id = digiItr->id();
00160 
00161       int ix = id.ix();
00162       int iy = id.iy();
00163 
00164       int ism = Numbers::iSM( id );
00165 
00166       if ( ism >= 1 && ism <= 9 ) ix = 101 - ix;
00167 
00168       float xix = ix - 0.5;
00169       float xiy = iy - 0.5;
00170 
00171       EEDataFrame dataframe = (*digiItr);
00172 
00173       int iMax(-1);
00174       int maxADC(0);
00175       for(int i(0); i < 10; i++){
00176         if(dataframe.sample(i).gainId() != 1) break;
00177         int adc(dataframe.sample(i).adc());
00178         if(adc > maxADC){
00179           maxADC = adc;
00180           iMax = i;
00181         }
00182       }
00183 
00184       if(iMax != 5) continue;
00185 
00186       for (int i = 0; i < 3; i++) {
00187 
00188         int adc = dataframe.sample(i).adc();
00189 
00190         MonitorElement* mePedMap = 0;
00191 
00192         if ( dataframe.sample(i).gainId() == 1 ) mePedMap = mePedMapG12_[ism-1];
00193         if ( dataframe.sample(i).gainId() == 2 ) mePedMap = 0;
00194         if ( dataframe.sample(i).gainId() == 3 ) mePedMap = 0;
00195 
00196         float xval = float(adc);
00197 
00198         if ( mePedMap ) mePedMap->Fill(xix, xiy, xval);
00199 
00200       }
00201 
00202     }
00203 
00204   } else {
00205 
00206     edm::LogWarning("EEPedestalOnlineTask") << EEDigiCollection_ << " not available";
00207 
00208   }
00209 
00210 }
00211