CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DQM/EcalEndcapMonitorClient/src/EETrendClient.cc

Go to the documentation of this file.
00001 /*
00002  * \file EETrendClient.cc
00003  *
00004  * $Date: 2012/04/27 13:46:08 $
00005  * $Revision: 1.11 $
00006  * \author Dongwook Jang, Soon Yung Jun
00007  *
00008 */
00009 
00010 #include <iostream>
00011 #include <fstream>
00012 #include <math.h>
00013 
00014 #include "FWCore/ServiceRegistry/interface/Service.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 
00017 #include "DQMServices/Core/interface/MonitorElement.h"
00018 #include "DQMServices/Core/interface/DQMStore.h"
00019 
00020 #include "DQM/EcalEndcapMonitorClient/interface/EETrendClient.h"
00021 #include "DQM/EcalCommon/interface/UtilFunctions.h"
00022 #include "DQM/EcalCommon/interface/UtilsClient.h"
00023 
00024 EETrendClient::EETrendClient(const edm::ParameterSet& ps){
00025 
00026   init_ = false;
00027 
00028   dqmStore_ = edm::Service<DQMStore>().operator->();
00029 
00030   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00031 
00032   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00033 
00034   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00035 
00036   verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
00037 
00038   // histograms...
00039   for(int i=0; i<nHists_; i++) {
00040     meanMinutely_[i] = 0;
00041     sigmaMinutely_[i] = 0;
00042 
00043     meanHourly_[i] = 0;
00044     sigmaHourly_[i] = 0;
00045 
00046     previousHist_[i] = 0;
00047     currentHist_[i] = 0;
00048   } // for
00049 
00050 }
00051 
00052 
00053 EETrendClient::~EETrendClient(){
00054 }
00055 
00056 
00057 void EETrendClient::beginJob(void){
00058 
00059   ievt_ = 0;
00060 
00061   if ( dqmStore_ ) {
00062     dqmStore_->setCurrentFolder(prefixME_ + "/EETrendClient");
00063     dqmStore_->rmdir(prefixME_ + "/EETrendClient");
00064   }
00065 
00066   // noise,
00067   // entries of EBOT rec hit thr occupancy
00068   // entries of EBOT tp digi occupancy
00069   // rec hit energy
00070   // ebtmt timing mean ID summary
00071   // ebtmt timing RMS ID summary
00072   //
00073 
00074   int index = 0;
00075 
00076   moduleNames_[index] = "EEClusterTask"; // TH1
00077   histTitles_[index]  = "EECLT BC energy";
00078   index++;
00079 
00080   moduleNames_[index] = "EEClusterTask"; // TH1
00081   histTitles_[index]  = "EECLT SC energy";
00082   index++;
00083 
00084   moduleNames_[index] = "EESummaryClient"; // TProfile
00085   histTitles_[index]  = "EEPOT pedestal G12 mean";
00086   index++;
00087 
00088   moduleNames_[index] = "EESummaryClient"; // TProfile
00089   histTitles_[index]  = "EEPOT pedestal G12 rms";
00090   index++;
00091 
00092   moduleNames_[index] = "EEOccupancyTask"; // TH2
00093   histTitles_[index]  = "EEOT rec hit thr occupancy EE -";
00094   index++;
00095 
00096   moduleNames_[index] = "EEOccupancyTask"; // TH2
00097   histTitles_[index]  = "EEOT rec hit thr occupancy EE +";
00098   index++;
00099 
00100   moduleNames_[index] = "EEOccupancyTask"; // TH2
00101   histTitles_[index]  = "EEOT TP digi thr occupancy EE -";
00102   index++;
00103 
00104   moduleNames_[index] = "EEOccupancyTask"; // TH2
00105   histTitles_[index]  = "EEOT TP digi thr occupancy EE +";
00106   index++;
00107 
00108 }
00109 
00110 
00111 void EETrendClient::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00112 
00113   if ( ! mergeRuns_ ) this->reset();
00114 
00115   start_time_ = time(NULL);
00116 
00117 }
00118 
00119 
00120 void EETrendClient::endRun(const edm::Run& r, const edm::EventSetup& c) {
00121 
00122 }
00123 
00124 
00125 void EETrendClient::reset(void) {
00126 
00127   for(int i=0; i<nHists_; i++) {
00128     if(meanMinutely_[i]) meanMinutely_[i]->Reset();
00129     if(sigmaMinutely_[i]) sigmaMinutely_[i]->Reset();
00130 
00131     if(meanHourly_[i]) meanHourly_[i]->Reset();
00132     if(sigmaHourly_[i]) sigmaHourly_[i]->Reset();
00133   }// for
00134 
00135 }
00136 
00137 
00138 void EETrendClient::setup(void){
00139 
00140   init_ = true;
00141 
00142   std::string histo;
00143 
00144   if ( dqmStore_ ) {
00145     dqmStore_->setCurrentFolder(prefixME_ + "/EETrendClient");
00146 
00147     for(int i=0; i<nHists_; i++) {
00148 
00149       // minutely
00150 
00151       histo = "Average of " + histTitles_[i] + " Vs 5Minutes";
00152       meanMinutely_[i] = dqmStore_->bookProfile(histo.c_str(), histo.c_str(), 12, 0.0, 60.0, 100, 0.0, 1.0e6, "s");
00153       meanMinutely_[i]->setAxisTitle("Minutes", 1);
00154       histo = "Average of " + histTitles_[i] + " / 5 minutes";
00155       meanMinutely_[i]->setAxisTitle(histo.c_str(), 2);
00156 
00157       histo = "RMS of " + histTitles_[i] + " Vs 5Minutes";
00158       sigmaMinutely_[i] = dqmStore_->bookProfile(histo.c_str(), histo.c_str(), 12, 0.0, 60.0, 100, 0.0, 1.0e6, "s");
00159       sigmaMinutely_[i]->setAxisTitle("Minutes", 1);
00160       histo = "RMS of " + histTitles_[i] + " / 5 minutes";
00161       sigmaMinutely_[i]->setAxisTitle(histo.c_str(), 2);
00162 
00163 
00164       // hourly
00165 
00166       histo = "Average of " + histTitles_[i] + " Vs 1Hour";
00167       meanHourly_[i] = dqmStore_->bookProfile(histo.c_str(), histo.c_str(), 24, 0.0, 24.0, 100, 0.0, 1.0e6, "s");
00168       meanHourly_[i]->setAxisTitle("Hours", 1);
00169       histo = "Average of " + histTitles_[i] + " / hour";
00170       meanHourly_[i]->setAxisTitle(histo.c_str(), 2);
00171 
00172       histo = "RMS of " + histTitles_[i] + " Vs 1Hour";
00173       sigmaHourly_[i] = dqmStore_->bookProfile(histo.c_str(), histo.c_str(), 24, 0.0, 24.0, 100, 0.0, 1.0e6, "s");
00174       sigmaHourly_[i]->setAxisTitle("Hours", 1);
00175       histo = "RMS of " + histTitles_[i] + " / hour";
00176       sigmaHourly_[i]->setAxisTitle(histo.c_str(), 2);
00177 
00178     }// for i
00179 
00180   }// if
00181 
00182 }
00183 
00184 
00185 void EETrendClient::cleanup(void){
00186 
00187   if ( ! init_ ) return;
00188 
00189   if ( dqmStore_ ) {
00190     dqmStore_->setCurrentFolder(prefixME_ + "/EETrendClient");
00191 
00192     for(int i=0; i<nHists_; i++) {
00193       if(meanMinutely_[i]) dqmStore_->removeElement( meanMinutely_[i]->getName());
00194       meanMinutely_[i] = 0;
00195       if(sigmaMinutely_[i]) dqmStore_->removeElement( sigmaMinutely_[i]->getName());
00196       sigmaMinutely_[i] = 0;
00197 
00198       if(meanHourly_[i]) dqmStore_->removeElement( meanHourly_[i]->getName());
00199       meanHourly_[i] = 0;
00200       if(sigmaHourly_[i]) dqmStore_->removeElement( sigmaHourly_[i]->getName());
00201       sigmaHourly_[i] = 0;
00202 
00203       if(previousHist_[i]) delete previousHist_[i];
00204       previousHist_[i] = 0;
00205       if(currentHist_[i]) delete currentHist_[i];
00206       currentHist_[i] = 0;
00207 
00208     }// for
00209 
00210   }
00211 
00212   init_ = false;
00213 
00214 }
00215 
00216 
00217 void EETrendClient::endJob(void){
00218 
00219   edm::LogInfo("EETrendClient") << "analyzed " << ievt_ << " events";
00220 
00221   if ( enableCleanup_ ) this->cleanup();
00222 
00223 }
00224 
00225 
00226 void EETrendClient::analyze(const edm::Event& e, const edm::EventSetup& c){
00227 
00228   if ( ! init_ ) this->setup();
00229 
00230   ievt_++;
00231 
00232   // --------------------------------------------------
00233   // Collect time information
00234   // --------------------------------------------------
00235 
00236   updateTime();
00237 
00238   //  long int diff_time = (current_time_ - start_time_)/60;
00239 
00240   long int minuteBinDiff = -1;
00241   long int minuteDiff = -1;
00242   //  ecaldqm::calcBins(5,1,start_time_,last_time_,current_time_,minuteBinDiff,minuteDiff);
00243   ecaldqm::calcBins(5,60,start_time_,last_time_,current_time_,minuteBinDiff,minuteDiff);
00244 
00245   if(minuteBinDiff <= 0) return;
00246 
00247   long int hourBinDiff = -1;
00248   long int hourDiff = -1;
00249   ecaldqm::calcBins(1,3600,start_time_,last_time_,current_time_,hourBinDiff,hourDiff);
00250 
00251 
00252   for(int i=0; i<nHists_; i++){
00253 
00254     mean_[i] = rms_[i] = 0;
00255 
00256     // delete previous hists if any
00257     if(previousHist_[i]) delete previousHist_[i];
00258 
00259     // assign currentHists to previousHists
00260     previousHist_[i] = currentHist_[i];
00261 
00262   } // for i
00263 
00264 
00265   std::string histo;
00266 
00267   MonitorElement* me;
00268 
00269   // get clones of histograms from other tasks or clients
00270   // assign cloned histogrmas to currentHist_[i]
00271 
00272   for(int i=0; i<nHists_; i++) {
00273     histo = prefixME_ + "/" + moduleNames_[i] + "/" + histTitles_[i];
00274     me = dqmStore_->get(histo.c_str());
00275     currentHist_[i] = ecaldqm::cloneIt(me,histo);
00276   }
00277 
00278 
00279   // Get mean and rms and fill Profile
00280 
00281   for(int i=0; i<nHists_; i++){
00282 
00283     ecaldqm::getMeanRms(previousHist_[i],currentHist_[i],mean_[i],rms_[i]);
00284 
00285     if(verbose_) {
00286       std::cout << std::scientific;
00287       std::cout << "EETrendClient mean["<<i<<"] = " << mean_[i] << ", \t rms["<<i<<"] = " << rms_[i] << std::endl;
00288     }
00289 
00290     ecaldqm::shift2Right(meanMinutely_[i]->getTProfile(), minuteBinDiff);
00291     meanMinutely_[i]->Fill(minuteDiff,mean_[i]);
00292 
00293     ecaldqm::shift2Right(sigmaMinutely_[i]->getTProfile(), minuteBinDiff);
00294     sigmaMinutely_[i]->Fill(minuteDiff,rms_[i]);
00295 
00296     ecaldqm::shift2Right(meanHourly_[i]->getTProfile(), hourBinDiff);
00297     meanHourly_[i]->Fill(hourDiff,mean_[i]);
00298 
00299     ecaldqm::shift2Right(sigmaHourly_[i]->getTProfile(), hourBinDiff);
00300     sigmaHourly_[i]->Fill(hourDiff,rms_[i]);
00301   } // for i
00302 
00303 
00304 }
00305 
00306 
00307 void EETrendClient::updateTime(){
00308 
00309   last_time_ = current_time_;
00310   current_time_ = time(NULL);
00311 
00312 }
00313