CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/L1TMonitorClient/src/L1TGMTClient.cc

Go to the documentation of this file.
00001 #include "DQM/L1TMonitorClient/interface/L1TGMTClient.h"
00002 
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "DQMServices/Core/interface/DQMStore.h"
00007 #include "DQMServices/Core/interface/MonitorElement.h"
00008 
00009 #include <sstream>
00010 
00011 using namespace edm;
00012 using namespace std;
00013 
00014 L1TGMTClient::L1TGMTClient(const edm::ParameterSet& ps)
00015 {
00016   parameters_=ps;
00017   initialize();
00018 }
00019 
00020 L1TGMTClient::~L1TGMTClient(){
00021   LogInfo("TriggerDQM")<<"[TriggerDQM]: ending... ";
00022 }
00023 
00024 //--------------------------------------------------------
00025 void L1TGMTClient::initialize(){ 
00026 
00027   counterLS_=0; 
00028   counterEvt_=0; 
00029   
00030   // get back-end interface
00031   dbe_ = Service<DQMStore>().operator->();
00032   
00033   // base folder for the contents of this job
00034   monitorName_ = parameters_.getUntrackedParameter<string>("monitorName","");
00035   cout << "Monitor name = " << monitorName_ << endl;
00036   prescaleLS_ = parameters_.getUntrackedParameter<int>("prescaleLS", -1);
00037   cout << "DQM lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< endl;
00038   prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1);
00039   cout << "DQM event prescale = " << prescaleEvt_ << " events(s)"<< endl;
00040   output_dir_ = parameters_.getUntrackedParameter<string>("output_dir","");
00041   cout << "DQM output dir = " << output_dir_ << endl;
00042   input_dir_ = parameters_.getUntrackedParameter<string>("input_dir","");
00043   cout << "DQM input dir = " << input_dir_ << endl;
00044   
00045   LogInfo( "TriggerDQM");
00046 
00047       
00048 }
00049 
00050 //--------------------------------------------------------
00051 void L1TGMTClient::beginJob(void){
00052 
00053   LogInfo("TriggerDQM")<<"[TriggerDQM]: Begin Job";
00054 
00055 }
00056 
00057 //--------------------------------------------------------
00058 void L1TGMTClient::beginRun(const Run& r, const EventSetup& context) {
00059 
00060   // get backendinterface
00061   dbe_ = Service<DQMStore>().operator->();  
00062 
00063   dbe_->setCurrentFolder(output_dir_);
00064 
00065   // booking
00066   eff_eta_dtcsc = bookClone1DVB("eff_eta_dtcsc","efficiency DTCSC vs eta","eta_DTCSC_and_RPC");
00067   eff_eta_dtcsc->setAxisTitle("eta",1);
00068   eff_eta_dtcsc->getTH1F()->Sumw2();
00069   
00070   eff_eta_rpc   = bookClone1DVB("eff_eta_rpc","efficiency RPC vs eta","eta_DTCSC_and_RPC");
00071   eff_eta_rpc->setAxisTitle("eta",1);
00072   eff_eta_rpc->getTH1F()->Sumw2();
00073 
00074   
00075   eff_phi_dtcsc = bookClone1D("eff_phi_dtcsc","efficiency DTCSC vs phi","phi_DTCSC_and_RPC");
00076   eff_phi_dtcsc->setAxisTitle("phi (deg)",1);
00077   eff_phi_dtcsc->getTH1F()->Sumw2();
00078   
00079   eff_phi_rpc   = bookClone1D("eff_phi_rpc","efficiency RPC vs phi","phi_DTCSC_and_RPC");
00080   eff_phi_rpc->setAxisTitle("phi (deg)",1);
00081   eff_phi_rpc->getTH1F()->Sumw2();
00082   
00083   
00084   eff_etaphi_dtcsc = bookClone2D("eff_etaphi_dtcsc","efficiency DTCSC vs eta and phi","etaphi_DTCSC_and_RPC");
00085   eff_etaphi_dtcsc->setAxisTitle("eta",1);
00086   eff_etaphi_dtcsc->setAxisTitle("phi (deg)",2);
00087   eff_etaphi_dtcsc->getTH2F()->Sumw2();
00088   
00089   eff_etaphi_rpc   = bookClone2D("eff_etaphi_rpc","efficiency RPC vs eta and phi","etaphi_DTCSC_and_RPC");
00090   eff_etaphi_rpc->setAxisTitle("eta",1);
00091   eff_etaphi_rpc->setAxisTitle("phi (deg)",2);
00092   eff_etaphi_rpc->getTH2F()->Sumw2();
00093   
00094 }
00095 
00096 //--------------------------------------------------------
00097 void L1TGMTClient::beginLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
00098    // optionally reset histograms here
00099    // clientHisto->Reset();
00100 }
00101 //--------------------------------------------------------
00102 
00103 void L1TGMTClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, 
00104                           const edm::EventSetup& c){
00105   counterLS_++;
00106   if (prescaleLS_<1) return;
00107   if (prescaleLS_>0 && counterLS_%prescaleLS_ != 0) return;
00108 //  cout << "L1TGMTClient::endLumi" << endl;
00109 
00110   process();
00111 }             
00112 //--------------------------------------------------------
00113 void L1TGMTClient::analyze(const Event& e, const EventSetup& context){
00114    counterEvt_++;
00115    if (prescaleEvt_<1) return;
00116    if (prescaleEvt_>0 && counterEvt_%prescaleEvt_ != 0) return;
00117    process();
00118 }
00119 
00120 //--------------------------------------------------------
00121 void L1TGMTClient::process() {
00122   
00123 //  cout << "L1TGMTClient: processing..." << endl;
00124   
00125   makeEfficiency1D(eff_eta_dtcsc,"eta_DTCSC_and_RPC","eta_RPC_only");
00126   makeEfficiency1D(eff_eta_rpc  ,"eta_DTCSC_and_RPC","eta_DTCSC_only");
00127   
00128   makeEfficiency1D(eff_phi_dtcsc,"phi_DTCSC_and_RPC","phi_RPC_only");
00129   makeEfficiency1D(eff_phi_rpc  ,"phi_DTCSC_and_RPC","phi_DTCSC_only");
00130   
00131   makeEfficiency2D(eff_etaphi_dtcsc,"etaphi_DTCSC_and_RPC","etaphi_RPC_only");
00132   makeEfficiency2D(eff_etaphi_rpc  ,"etaphi_DTCSC_and_RPC","etaphi_DTCSC_only");
00133   
00134 }
00135 //--------------------------------------------------------
00136 void L1TGMTClient::endRun(const Run& r, const EventSetup& context){
00137   process();
00138 }
00139 
00140 //--------------------------------------------------------
00141 void L1TGMTClient::endJob(){
00142 }
00143 
00145 void L1TGMTClient::makeRatio1D(MonitorElement* mer, string h1Name, string h2Name) {
00146    TH1F* h1 = get1DHisto(input_dir_+"/"+h1Name,dbe_);
00147    TH1F* h2 = get1DHisto(input_dir_+"/"+h2Name,dbe_);
00148    TH1F* hr = mer->getTH1F();
00149    
00150    if(hr && h1 && h2) {
00151      hr->Divide(h1,h2,1.,1.," ");
00152    }
00153 }
00154 
00156 void L1TGMTClient::makeEfficiency1D(MonitorElement* meeff, string heName, string hiName) {
00157    TH1F* he = get1DHisto(input_dir_+"/"+heName,dbe_);
00158    TH1F* hi = get1DHisto(input_dir_+"/"+hiName,dbe_);
00159    TH1F* heff = meeff->getTH1F();
00160    
00161    if(heff && he && hi) {
00162      TH1F* hall = (TH1F*) he->Clone("hall");
00163      hall->Add(hi);
00164      heff->Divide(he,hall,1.,1.,"B");
00165      delete hall;
00166    }
00167 }
00168 
00170 void L1TGMTClient::makeEfficiency2D(MonitorElement* meeff, string heName, string hiName) {
00171    TH2F* he = get2DHisto(input_dir_+"/"+heName,dbe_);
00172    TH2F* hi = get2DHisto(input_dir_+"/"+hiName,dbe_);
00173    TH2F* heff = meeff->getTH2F();
00174   
00175    if(heff && he && hi) {
00176      TH2F* hall = (TH2F*) he->Clone("hall");
00177      hall->Add(hi);
00178      heff->Divide(he,hall,1.,1.,"B");
00179      delete hall;
00180    }
00181 }
00182 
00184 TH1F* L1TGMTClient::get1DHisto(string meName, DQMStore* dbi) {
00185   MonitorElement * me_ = dbi->get(meName);
00186 
00187   if (!me_) { 
00188     LogInfo("TriggerDQM") << "L1TGMT: " << meName << " NOT FOUND.";
00189     return NULL;
00190   }
00191   return me_->getTH1F();
00192 }
00193 
00195 TH2F* L1TGMTClient::get2DHisto(string meName, DQMStore* dbi) {
00196   MonitorElement * me_ = dbi->get(meName);
00197 
00198   if (!me_) { 
00199     LogInfo("TriggerDQM") << "L1TGMT: " << meName << " NOT FOUND.";
00200     return NULL;
00201   }
00202   return me_->getTH2F();
00203 }
00205 MonitorElement* L1TGMTClient::bookClone1D(string name, string title, string hrefName) {
00206   MonitorElement* me;
00207   
00208   TH1F* href = get1DHisto(input_dir_+"/"+hrefName,dbe_);
00209   if(href) {
00210     const unsigned nbx = href->GetNbinsX();
00211     const double xmin = href->GetXaxis()->GetXmin();
00212     const double xmax = href->GetXaxis()->GetXmax();
00213     me = dbe_->book1D(name,title,nbx,xmin,xmax);
00214   } else {
00215     me = NULL;
00216   }
00217   
00218   return me;
00219 }
00221 MonitorElement* L1TGMTClient::bookClone1DVB(string name, string title, string hrefName) {
00222   MonitorElement* me;
00223   
00224   TH1F* href = get1DHisto(input_dir_+"/"+hrefName,dbe_);
00225   if(href) {
00226     int nbx = href->GetNbinsX();
00227     if(nbx>99) nbx=99;
00228     float xbins[100];
00229     for(int i=0; i<nbx; i++) {
00230       xbins[i]=href->GetBinLowEdge(i+1);
00231     }
00232     xbins[nbx]=href->GetXaxis()->GetXmax();
00233     me = dbe_->book1D(name,title,nbx,xbins);
00234   } else {
00235     me = NULL;
00236   }
00237   
00238   return me;
00239 }
00241 MonitorElement* L1TGMTClient::bookClone2D(string name, string title, string hrefName) {
00242   MonitorElement* me;
00243   
00244   TH2F* href = get2DHisto(input_dir_+"/"+hrefName,dbe_);
00245   if(href) {
00246     const unsigned nbx = href->GetNbinsX();
00247     const double xmin = href->GetXaxis()->GetXmin();
00248     const double xmax = href->GetXaxis()->GetXmax();
00249     const unsigned nby = href->GetNbinsY();
00250     const double ymin = href->GetYaxis()->GetXmin();
00251     const double ymax = href->GetYaxis()->GetXmax();
00252     me = dbe_->book2D(name,title,nbx,xmin,xmax,nby,ymin,ymax);
00253   } else {
00254     me = NULL;
00255   }
00256   
00257   return me;
00258 }
00260 
00261 
00262