CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/DQM/L1TMonitorClient/src/L1TdeECALClient.cc

Go to the documentation of this file.
00001 #include "DQM/L1TMonitorClient/interface/L1TdeECALClient.h"
00002 
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "DQMServices/Core/interface/QReport.h"
00009 #include "DQMServices/Core/interface/DQMStore.h"
00010 #include "DQMServices/Core/interface/MonitorElement.h"
00011 #include "TRandom.h"
00012 #include <TF1.h>
00013 #include <stdio.h>
00014 #include <sstream>
00015 #include <math.h>
00016 #include <TProfile.h>
00017 #include <TProfile2D.h>
00018 using namespace edm;
00019 using namespace std;
00020 
00021 L1TdeECALClient::L1TdeECALClient(const edm::ParameterSet& ps)
00022 {
00023   parameters_=ps;
00024   initialize();
00025 }
00026 
00027 L1TdeECALClient::~L1TdeECALClient(){
00028  if(verbose_) cout <<"[TriggerDQM]: ending... " << endl;
00029 }
00030 
00031 //--------------------------------------------------------
00032 void L1TdeECALClient::initialize(){ 
00033 
00034   counterLS_=0; 
00035   counterEvt_=0; 
00036   
00037   // get back-end interface
00038   dbe_ = Service<DQMStore>().operator->();
00039   
00040   // base folder for the contents of this job
00041   verbose_ = parameters_.getUntrackedParameter<bool>("verbose", false);
00042   
00043   monitorDir_ = parameters_.getUntrackedParameter<string>("monitorDir","");
00044   if(verbose_) cout << "Monitor dir = " << monitorDir_ << endl;
00045     
00046   prescaleLS_ = parameters_.getUntrackedParameter<int>("prescaleLS", -1);
00047   if(verbose_) cout << "DQM lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< endl;
00048   
00049   prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1);
00050   if(verbose_) cout << "DQM event prescale = " << prescaleEvt_ << " events(s)"<< endl;
00051   
00052 
00053       
00054 }
00055 
00056 //--------------------------------------------------------
00057 void L1TdeECALClient::beginJob(void){
00058 
00059   if(verbose_) cout <<"[TriggerDQM]: Begin Job" << endl;
00060   // get backendinterface  
00061   dbe_ = Service<DQMStore>().operator->();
00062 
00063   // do your thing
00064   dbe_->setCurrentFolder(monitorDir_);
00065   
00066      ecalEtMapDiff1D_proj = dbe_->book1D("ecalEtMapDiff1D_proj","ecalEtMapDiff1D_proj",2520,0,2520.);
00067 
00068 
00069 //   bad channels from QTs results
00070      ecalEtMapDiff1D_proj_badChs = dbe_->book1D("ecalEtMapDiff1D_proj_badChs","ecalEtMapDiff1D_proj_badChs",2520,0,2520.);
00071      ecalEtMapDiff_badChs = dbe_->book2D("ecalEtMapDiff2D_badChs","ecalEtMapDiff2D_badChs",35, -17.5, 17.5,72, -10., 350.);
00072 
00073 }
00074 
00075 //--------------------------------------------------------
00076 void L1TdeECALClient::beginRun(const Run& r, const EventSetup& context) {
00077 }
00078 
00079 //--------------------------------------------------------
00080 void L1TdeECALClient::beginLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
00081    // optionally reset histograms here
00082 }
00083 
00084 void L1TdeECALClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, 
00085                           const edm::EventSetup& c){
00086 
00087 // retrieve all MEs in current dir
00088    vector<string> meVec = dbe_->getMEs();
00089    if(verbose_) cout << "meVec size = " << meVec.size() << endl;
00090    string currDir = dbe_->pwd();
00091    if(verbose_) cout << "currDir = " <<  currDir << endl;
00092     for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
00093      string full_path = currDir + "/" + (*it);
00094      if(verbose_) cout << "full path = " << full_path <<  endl;
00095      MonitorElement * me =dbe_->get(full_path);
00096      float me_entries=me->getEntries();
00097 
00098 // for this MEs, get list of associated QTs
00099 
00100      std::vector<QReport *> Qtest_map = me->getQReports();
00101    
00102        if (Qtest_map.size() > 0) {
00103           for (std::vector<QReport *>::const_iterator it = Qtest_map.begin(); it != Qtest_map.end(); it++) {
00104              cout << endl;
00105              string qt_name = (*it)->getQRName();
00106              int qt_status = (*it)->getStatus();
00107              
00108              switch(qt_status){
00109                case dqm::qstatus::WARNING:
00110                if(verbose_) cout << "****** QT name: " << qt_name << "; Status: WARNING; "<< " Message: " << (*it)->getMessage() <<endl;
00111                break;
00112                
00113                case dqm::qstatus::ERROR:
00114                if(verbose_) cout << "****** QT name: " << qt_name << "; Status: ERROR; "<< " Message: " << (*it)->getMessage() <<endl;
00115                break;
00116        
00117                case dqm::qstatus::DISABLED:
00118                if(verbose_) cout << "****** QT name: " << qt_name << "; Status: DISABLED; "<< " Message: " << (*it)->getMessage() <<endl;
00119                break;
00120        
00121                case dqm::qstatus::INVALID:
00122                if(verbose_) cout << "****** QT name: " << qt_name << "; Status: INVALID; "<< " Message: " << (*it)->getMessage() <<endl;
00123                break;
00124        
00125                case dqm::qstatus::INSUF_STAT:
00126                if(verbose_) cout << "****** QT name: " << qt_name << "; Status: NOT ENOUGH STATISTICS; "<< " Message: " <<(*it)->getMessage() <<endl;
00127                if(qt_status == dqm::qstatus::INSUF_STAT) cout <<  " entries = " << me_entries << endl;
00128                break;
00129        
00130                default:
00131                if(verbose_) cout << "****** Unknown QTest qith status="<<qt_status<< endl;
00132              }
00133        
00134 //   get bad channel list
00135 
00136                   std::vector<dqm::me_util::Channel> badChannels=(*it)->getBadChannels();                                                                                                                                                
00137                   if(!badChannels.empty() && verbose_ ) cout << " Number of channels that failed test " <<qt_name <<  " = " << badChannels.size()<< "\n";                                                                                                                                                                        
00138                   vector<dqm::me_util::Channel>::iterator badchsit = badChannels.begin();                                                                                                                                                
00139                   
00140                   while(badchsit != badChannels.end())                                                                                                                                                                                   
00141                   {                             
00142                     int ix = (*badchsit).getBinX();     
00143                     int iy = (*badchsit).getBinY();                                                                                                                                                                      
00144                    if(verbose_) cout <<" Bad channel ("<< ix<<"," << iy << ") with contents "<<(*badchsit).getContents() << endl;
00145                    if(qt_name=="testdeDiffInYRange") ecalEtMapDiff1D_proj_badChs->setBinContent(ix,(*badchsit).getContents());
00146                    if(qt_name=="testdeDiffInRange2DProfile") ecalEtMapDiff_badChs->setBinContent(ix,iy,(*badchsit).getContents());
00147                    ++badchsit;
00148                   }
00149          
00150        }
00151      }      
00152        
00153    }
00154 
00155 }
00156 
00157 //--------------------------------------------------------
00158 void L1TdeECALClient::analyze(const Event& e, const EventSetup& context){
00159    counterEvt_++;
00160    if (prescaleEvt_<1) return;
00161    if (prescaleEvt_>0 && counterEvt_%prescaleEvt_ != 0) return;
00162 
00163    if(verbose_) cout << "L1TdeECALClient::analyze" << endl;
00164 
00165 // Example: get ROOT object 
00166     TProfile2D * ecalEtMapDiffRoot_;   
00167     ecalEtMapDiffRoot_ = this->get2DProfile("L1TEMU/xpert/Ecal/EcalEtMapDiff",dbe_);
00168 
00169 
00170     if (ecalEtMapDiffRoot_) {
00171      int lastBinX=(*ecalEtMapDiffRoot_).GetNbinsX();
00172      int lastBinY=(*ecalEtMapDiffRoot_).GetNbinsY();
00173      for(int i=0; i<lastBinX ; i++){   
00174          for(int j=0; j<lastBinY ; j++){  
00175            int ibin=lastBinY*(i%lastBinX)+j; 
00176            if(ecalEtMapDiffRoot_->GetBinContent(i,j))
00177            ecalEtMapDiff1D_proj->setBinContent(ibin,ecalEtMapDiffRoot_->GetBinContent(i,j));
00178          }
00179      }
00180     
00181     }
00182     
00183    
00184 }
00185 
00186 //--------------------------------------------------------
00187 void L1TdeECALClient::endRun(const Run& r, const EventSetup& context){
00188 }
00189 
00190 //--------------------------------------------------------
00191 void L1TdeECALClient::endJob(){
00192 }
00193 
00194 
00195 
00196 TH1F * L1TdeECALClient::get1DHisto(string meName, DQMStore * dbi)
00197 {
00198 
00199   MonitorElement * me_ = dbi->get(meName);
00200 
00201   if (!me_) { 
00202     if(verbose_) cout << "ME NOT FOUND." << endl;
00203     return NULL;
00204   }
00205 
00206   return me_->getTH1F();
00207 }
00208 
00209 TH2F * L1TdeECALClient::get2DHisto(string meName, DQMStore * dbi)
00210 {
00211 
00212 
00213   MonitorElement * me_ = dbi->get(meName);
00214 
00215   if (!me_) { 
00216     if(verbose_) cout << "ME NOT FOUND." << endl;
00217     return NULL;
00218   }
00219 
00220   return me_->getTH2F();
00221 }
00222 
00223 
00224 
00225 TProfile2D *  L1TdeECALClient::get2DProfile(string meName, DQMStore * dbi)
00226 {
00227 
00228 
00229   MonitorElement * me_ = dbi->get(meName);
00230 
00231   if (!me_) { 
00232      if(verbose_) cout << "ME NOT FOUND." << endl;
00233    return NULL;
00234   }
00235 
00236   return me_->getTProfile2D();
00237 }
00238 
00239 
00240 TProfile *  L1TdeECALClient::get1DProfile(string meName, DQMStore * dbi)
00241 {
00242 
00243 
00244   MonitorElement * me_ = dbi->get(meName);
00245 
00246   if (!me_) { 
00247     if(verbose_) cout << "ME NOT FOUND." << endl;
00248     return NULL;
00249   }
00250 
00251   return me_->getTProfile();
00252 }
00253 
00254 
00255 
00256 
00257 
00258 
00259 
00260