CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DQM/EcalBarrelMonitorClient/src/EBTrendClient.cc

Go to the documentation of this file.
00001 /*
00002  * \file EBTrendClient.cc
00003  *
00004  * $Date: 2010/08/11 15:01:48 $
00005  * $Revision: 1.7 $
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/EcalBarrelMonitorClient/interface/EBTrendClient.h"
00021 #include "DQM/EcalCommon/interface/UtilFunctions.h"
00022 #include "DQM/EcalCommon/interface/UtilsClient.h"
00023 
00024 EBTrendClient::EBTrendClient(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 EBTrendClient::~EBTrendClient(){
00054 }
00055 
00056 
00057 void EBTrendClient::beginJob(void){
00058 
00059   ievt_ = 0;
00060 
00061   if ( dqmStore_ ) {
00062     dqmStore_->setCurrentFolder(prefixME_ + "/EBTrendClient");
00063     dqmStore_->rmdir(prefixME_ + "/EBTrendClient");
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] = "EBClusterTask"; // TH1
00077   histTitles_[index]  = "EBCLT BC energy";
00078   index++;
00079 
00080   moduleNames_[index] = "EBClusterTask"; // TH1
00081   histTitles_[index]  = "EBCLT SC energy";
00082   index++;
00083 
00084   moduleNames_[index] = "EBSummaryClient"; // TProfile
00085   histTitles_[index]  = "EBPOT pedestal G12 mean";
00086   index++;
00087 
00088   moduleNames_[index] = "EBSummaryClient"; // TProfile
00089   histTitles_[index]  = "EBPOT pedestal G12 rms";
00090   index++;
00091 
00092   moduleNames_[index] = "EBOccupancyTask"; // TH2
00093   histTitles_[index]  = "EBOT rec hit thr occupancy";
00094   index++;
00095 
00096   moduleNames_[index] = "EBOccupancyTask"; // TH2
00097   histTitles_[index]  = "EBOT TP digi thr occupancy";
00098   index++;
00099 
00100 }
00101 
00102 
00103 void EBTrendClient::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00104 
00105   if ( ! mergeRuns_ ) this->reset();
00106 
00107   start_time_ = time(NULL);
00108 
00109 }
00110 
00111 
00112 void EBTrendClient::endRun(const edm::Run& r, const edm::EventSetup& c) {
00113 
00114 }
00115 
00116 
00117 void EBTrendClient::reset(void) {
00118 
00119   for(int i=0; i<nHists_; i++) {
00120     if(meanMinutely_[i]) meanMinutely_[i]->Reset();
00121     if(sigmaMinutely_[i]) sigmaMinutely_[i]->Reset();
00122 
00123     if(meanHourly_[i]) meanHourly_[i]->Reset();
00124     if(sigmaHourly_[i]) sigmaHourly_[i]->Reset();
00125   }// for
00126 
00127 }
00128 
00129 
00130 void EBTrendClient::setup(void){
00131 
00132   init_ = true;
00133 
00134   std::string histo;
00135 
00136   if ( dqmStore_ ) {
00137     dqmStore_->setCurrentFolder(prefixME_ + "/EBTrendClient");
00138 
00139     for(int i=0; i<nHists_; i++) {
00140 
00141       // minutely
00142 
00143       histo = "Average of " + histTitles_[i] + " Vs 5Minutes";
00144       meanMinutely_[i] = dqmStore_->bookProfile(histo.c_str(), histo.c_str(), 12, 0.0, 60.0, 100, 0.0, 1.0e6, "s");
00145       meanMinutely_[i]->setAxisTitle("Minutes", 1);
00146       histo = "Average of " + histTitles_[i] + " / 5 minutes";
00147       meanMinutely_[i]->setAxisTitle(histo.c_str(), 2);
00148 
00149       histo = "RMS of " + histTitles_[i] + " Vs 5Minutes";
00150       sigmaMinutely_[i] = dqmStore_->bookProfile(histo.c_str(), histo.c_str(), 12, 0.0, 60.0, 100, 0.0, 1.0e6, "s");
00151       sigmaMinutely_[i]->setAxisTitle("Minutes", 1);
00152       histo = "RMS of " + histTitles_[i] + " / 5 minutes";
00153       sigmaMinutely_[i]->setAxisTitle(histo.c_str(), 2);
00154 
00155 
00156       // hourly
00157 
00158       histo = "Average of " + histTitles_[i] + " Vs 1Hour";
00159       meanHourly_[i] = dqmStore_->bookProfile(histo.c_str(), histo.c_str(), 24, 0.0, 24.0, 100, 0.0, 1.0e6, "s");
00160       meanHourly_[i]->setAxisTitle("Hours", 1);
00161       histo = "Average of " + histTitles_[i] + " / hour";
00162       meanHourly_[i]->setAxisTitle(histo.c_str(), 2);
00163 
00164       histo = "RMS of " + histTitles_[i] + " Vs 1Hour";
00165       sigmaHourly_[i] = dqmStore_->bookProfile(histo.c_str(), histo.c_str(), 24, 0.0, 24.0, 100, 0.0, 1.0e6, "s");
00166       sigmaHourly_[i]->setAxisTitle("Hours", 1);
00167       histo = "RMS of " + histTitles_[i] + " / hour";
00168       sigmaHourly_[i]->setAxisTitle(histo.c_str(), 2);
00169 
00170     }// for i
00171 
00172   }// if
00173 
00174 }
00175 
00176 
00177 void EBTrendClient::cleanup(void){
00178 
00179   if ( ! init_ ) return;
00180 
00181   if ( dqmStore_ ) {
00182     dqmStore_->setCurrentFolder(prefixME_ + "/EBTrendClient");
00183 
00184     for(int i=0; i<nHists_; i++) {
00185       if(meanMinutely_[i]) dqmStore_->removeElement( meanMinutely_[i]->getName());
00186       meanMinutely_[i] = 0;
00187       if(sigmaMinutely_[i]) dqmStore_->removeElement( sigmaMinutely_[i]->getName());
00188       sigmaMinutely_[i] = 0;
00189 
00190       if(meanHourly_[i]) dqmStore_->removeElement( meanHourly_[i]->getName());
00191       meanHourly_[i] = 0;
00192       if(sigmaHourly_[i]) dqmStore_->removeElement( sigmaHourly_[i]->getName());
00193       sigmaHourly_[i] = 0;
00194 
00195       if(previousHist_[i]) delete previousHist_[i];
00196       previousHist_[i] = 0;
00197       if(currentHist_[i]) delete currentHist_[i];
00198       currentHist_[i] = 0;
00199 
00200     }// for
00201 
00202   }
00203 
00204   init_ = false;
00205 
00206 }
00207 
00208 
00209 void EBTrendClient::endJob(void){
00210 
00211   edm::LogInfo("EBTrendClient") << "analyzed " << ievt_ << " events";
00212 
00213   if ( enableCleanup_ ) this->cleanup();
00214 
00215 }
00216 
00217 
00218 void EBTrendClient::analyze(const edm::Event& e, const edm::EventSetup& c){
00219 
00220   if ( ! init_ ) this->setup();
00221 
00222   ievt_++;
00223 
00224   // --------------------------------------------------
00225   // Collect time information
00226   // --------------------------------------------------
00227 
00228   updateTime();
00229 
00230   //  long int diff_time = (current_time_ - start_time_)/60;
00231 
00232   long int minuteBinDiff = -1;
00233   long int minuteDiff = -1;
00234   //  ecaldqm::calcBins(5,1,start_time_,last_time_,current_time_,minuteBinDiff,minuteDiff);
00235   ecaldqm::calcBins(5,60,start_time_,last_time_,current_time_,minuteBinDiff,minuteDiff);
00236 
00237   if(minuteBinDiff <= 0) return;
00238 
00239   long int hourBinDiff = -1;
00240   long int hourDiff = -1;
00241   ecaldqm::calcBins(1,3600,start_time_,last_time_,current_time_,hourBinDiff,hourDiff);
00242 
00243 
00244   for(int i=0; i<nHists_; i++){
00245 
00246     mean_[i] = rms_[i] = 0;
00247 
00248     // delete previous hists if any
00249     if(previousHist_[i]) delete previousHist_[i];
00250 
00251     // assign currentHists to previousHists
00252     previousHist_[i] = currentHist_[i];
00253 
00254   } // for i
00255 
00256 
00257   std::string histo;
00258 
00259   MonitorElement* me;
00260 
00261   // get clones of histograms from other tasks or clients
00262   // assign cloned histogrmas to currentHist_[i]
00263 
00264   for(int i=0; i<nHists_; i++) {
00265     histo = prefixME_ + "/" + moduleNames_[i] + "/" + histTitles_[i];
00266     me = dqmStore_->get(histo.c_str());
00267     currentHist_[i] = ecaldqm::cloneIt(me,histo);
00268   }
00269 
00270 
00271   // Get mean and rms and fill Profile
00272 
00273   for(int i=0; i<nHists_; i++){
00274 
00275     ecaldqm::getMeanRms(previousHist_[i],currentHist_[i],mean_[i],rms_[i]);
00276 
00277     if(verbose_) {
00278       std::cout << std::scientific;
00279       std::cout << "EBTrendClient mean["<<i<<"] = " << mean_[i] << ", \t rms["<<i<<"] = " << rms_[i] << std::endl;
00280     }
00281 
00282     ecaldqm::shift2Right(meanMinutely_[i]->getTProfile(), minuteBinDiff);
00283     meanMinutely_[i]->Fill(minuteDiff,mean_[i]);
00284 
00285     ecaldqm::shift2Right(sigmaMinutely_[i]->getTProfile(), minuteBinDiff);
00286     sigmaMinutely_[i]->Fill(minuteDiff,rms_[i]);
00287 
00288     ecaldqm::shift2Right(meanHourly_[i]->getTProfile(), hourBinDiff);
00289     meanHourly_[i]->Fill(hourDiff,mean_[i]);
00290 
00291     ecaldqm::shift2Right(sigmaHourly_[i]->getTProfile(), hourBinDiff);
00292     sigmaHourly_[i]->Fill(hourDiff,rms_[i]);
00293   } // for i
00294 
00295 
00296 }
00297 
00298 
00299 void EBTrendClient::updateTime(){
00300 
00301   last_time_ = current_time_;
00302   current_time_ = time(NULL);
00303 
00304 }
00305