CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/DQM/L1TMonitorClient/src/L1TDTTPGClient.cc

Go to the documentation of this file.
00001 #include "DQM/L1TMonitorClient/interface/L1TDTTPGClient.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 
00013 #include <TF1.h>
00014 #include <stdio.h>
00015 #include <sstream>
00016 #include <math.h>
00017 #include <TProfile.h>
00018 #include <TProfile2D.h>
00019 
00020 using namespace edm;
00021 using namespace std;
00022 
00023 L1TDTTPGClient::L1TDTTPGClient(const edm::ParameterSet& ps)
00024 {
00025   parameters_=ps;
00026   initialize();
00027 }
00028 
00029 L1TDTTPGClient::~L1TDTTPGClient(){
00030  LogInfo("TriggerDQM")<<"[TriggerDQM]: ending... ";
00031 }
00032 
00033 //--------------------------------------------------------
00034 void L1TDTTPGClient::initialize(){ 
00035 
00036   counterLS_=0; 
00037   counterEvt_=0; 
00038   
00039   // get back-end interface
00040   dbe_ = Service<DQMStore>().operator->();
00041   
00042   // base folder for the contents of this job
00043   monitorName_ = parameters_.getUntrackedParameter<string>("monitorName","");
00044 //  cout << "Monitor name = " << monitorName_ << endl;
00045   prescaleLS_ = parameters_.getUntrackedParameter<int>("prescaleLS", -1);
00046 //  cout << "DQM lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< endl;
00047   prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1);
00048 //  cout << "DQM event prescale = " << prescaleEvt_ << " events(s)"<< endl;
00049   output_dir_ = parameters_.getUntrackedParameter<string>("output_dir","");
00050 //  cout << "DQM output dir = " << output_dir_ << endl;
00051   input_dir_ = parameters_.getUntrackedParameter<string>("input_dir","");
00052 //  cout << "DQM input dir = " << input_dir_ << endl;
00053   
00054   LogInfo( "TriggerDQM");
00055 
00056       
00057 }
00058 
00059 //--------------------------------------------------------
00060 void L1TDTTPGClient::beginJob(void){
00061 
00062   LogInfo("TriggerDQM")<<"[TriggerDQM]: Begin Job";
00063 
00064   // get backendinterface
00065   dbe_ = Service<DQMStore>().operator->();  
00066 
00067   dbe_->setCurrentFolder(output_dir_);
00068 
00069   // booking
00070   
00071   dttpgphmapcorrf = dbe_->book2D("DT_TPG_phi_map_corr_frac",
00072                                  "Fraction of correlated best triggers per station",20,1,21,12,0,12);
00073   dttpgphmap2ndf = dbe_->book2D("DT_TPG_phi_map_2nd_frac",
00074                                 "Fraction of second tracks per station",20,1,21,12,0,12);
00075   dttpgphmapbxf[0] = dbe_->book2D("DT_TPG_phi_map_bx-1_frac",
00076                                   "Fraction of triggers per station (BX=-1)",20,1,21,12,0,12);
00077   dttpgphmapbxf[1] = dbe_->book2D("DT_TPG_phi_map_bx0_frac",
00078                                   "Fraction of triggers per station (BX=0)",20,1,21,12,0,12);
00079   dttpgphmapbxf[2] = dbe_->book2D("DT_TPG_phi_map_bx+1_frac",
00080                                   "Fraction of triggers per station (BX=1)",20,1,21,12,0,12);
00081   setMapPhLabel(dttpgphmapcorrf);
00082   setMapPhLabel(dttpgphmap2ndf);
00083   setMapPhLabel(dttpgphmapbxf[0]);
00084   setMapPhLabel(dttpgphmapbxf[1]);
00085   setMapPhLabel(dttpgphmapbxf[2]);
00086 
00087   dttpgthmaphf = dbe_->book2D("DT_TPG_theta_map_corr_frac",
00088                                  "Fraction of H quality best triggers per station",15,1,16,12,0,12);
00089   dttpgthmapbxf[0] = dbe_->book2D("DT_TPG_theta_map_bx-1_frac",
00090                                   "Fraction of triggers per station (BX=-1)",15,1,16,12,0,12);
00091   dttpgthmapbxf[1] = dbe_->book2D("DT_TPG_theta_map_bx0_frac",
00092                                   "Fraction of triggers per station (BX=0)",15,1,16,12,0,12);
00093   dttpgthmapbxf[2] = dbe_->book2D("DT_TPG_theta_map_bx+1_frac",
00094                                   "Fraction of triggers per station (BX=1)",15,1,16,12,0,12);
00095   setMapThLabel(dttpgthmaphf);
00096   setMapThLabel(dttpgthmapbxf[0]);
00097   setMapThLabel(dttpgthmapbxf[1]);
00098   setMapThLabel(dttpgthmapbxf[2]);
00099 
00100   
00101 
00102 }
00103 
00104 //--------------------------------------------------------
00105 void L1TDTTPGClient::beginRun(const Run& r, const EventSetup& context) {
00106 }
00107 
00108 //--------------------------------------------------------
00109 void L1TDTTPGClient::beginLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
00110    // optionally reset histograms here
00111    // clientHisto->Reset();
00112 }
00113 //--------------------------------------------------------
00114 
00115 void L1TDTTPGClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, 
00116                           const edm::EventSetup& c){
00117                           
00118 }                         
00119 //--------------------------------------------------------
00120 void L1TDTTPGClient::analyze(const Event& e, const EventSetup& context){
00121 //   cout << "L1TDTTPGClient::analyze" << endl;
00122    counterEvt_++;
00123    if (prescaleEvt_<1) return;
00124    if (prescaleEvt_>0 && counterEvt_%prescaleEvt_ != 0) return;
00125 
00126    string nName = "DT_TPG_phi_best_map_corr";
00127    string dName = "DT_TPG_phi_best_map";
00128    makeRatioHisto(dttpgphmapcorrf,nName,dName);
00129    dName = "DT_TPG_phi_map";
00130    nName = "DT_TPG_phi_map_2nd";
00131    makeRatioHisto(dttpgphmap2ndf,nName,dName);
00132    nName = "DT_TPG_phi_map_bx-1";
00133    makeRatioHisto(dttpgphmapbxf[0],nName,dName);
00134    nName = "DT_TPG_phi_map_bx0";
00135    makeRatioHisto(dttpgphmapbxf[1],nName,dName);
00136    nName = "DT_TPG_phi_map_bx+1";
00137    makeRatioHisto(dttpgphmapbxf[2],nName,dName);
00138 
00139    nName = "DT_TPG_theta_best_map_h";
00140    dName = "DT_TPG_theta_best_map";
00141    makeRatioHisto(dttpgthmaphf,nName,dName);
00142    dName = "DT_TPG_theta_map";
00143    nName = "DT_TPG_theta_map_bx-1";
00144    makeRatioHisto(dttpgthmapbxf[0],nName,dName);
00145    nName = "DT_TPG_theta_map_bx0";
00146    makeRatioHisto(dttpgthmapbxf[1],nName,dName);
00147    nName = "DT_TPG_theta_map_bx+1";
00148    makeRatioHisto(dttpgthmapbxf[2],nName,dName);
00149 
00150 
00151 }
00152 
00153 //--------------------------------------------------------
00154 void L1TDTTPGClient::endRun(const Run& r, const EventSetup& context){
00155 }
00156 
00157 //--------------------------------------------------------
00158 void L1TDTTPGClient::endJob(){
00159 }
00160 
00161 void L1TDTTPGClient::makeRatioHisto(MonitorElement *ratioME, string &nName, string &dName)
00162 {
00163 
00164    TH2F *numerator;
00165    TH2F *denominator;
00166 
00167    denominator = this->get2DHisto(input_dir_+"/"+dName,dbe_);
00168    numerator   = this->get2DHisto(input_dir_+"/"+nName,dbe_);
00169 
00170    if (numerator && denominator) {
00171 
00172      TH2F * ratio = ratioME->getTH2F();
00173      if (ratio) {
00174        ratio->Divide(numerator,denominator);
00175      }
00176      else {
00177        LogInfo("TriggerDQM") << "[TriggerDQM]: ratio histo named \"" << ratioME->getName() << "\" not found!" << endl;
00178      }
00179    }
00180    else {
00181      if (!numerator)
00182        LogInfo("TriggerDQM") << "[TriggerDQM]: numerator histo \"" << nName << "\" not found!" << endl;
00183      if (!denominator)
00184        LogInfo("TriggerDQM") << "[TriggerDQM]: denominator histo \"" << dName << "\" not found!" << endl;
00185    }
00186 
00187 }
00188 
00189 TH1F * L1TDTTPGClient::get1DHisto(string meName, DQMStore * dbi)
00190 {
00191 
00192   MonitorElement * me_ = dbi->get(meName);
00193 
00194   if (!me_) { 
00195     LogInfo("TriggerDQM") << "ME NOT FOUND.";
00196     return NULL;
00197   }
00198 
00199   return me_->getTH1F();
00200 }
00201 
00202 TH2F * L1TDTTPGClient::get2DHisto(string meName, DQMStore * dbi)
00203 {
00204 
00205 
00206   MonitorElement * me_ = dbi->get(meName);
00207 
00208   if (!me_) { 
00209     LogInfo("TriggerDQM") << "ME NOT FOUND.";
00210     return NULL;
00211   }
00212 
00213   return me_->getTH2F();
00214 }
00215 
00216 
00217 
00218 TProfile2D * L1TDTTPGClient::get2DProfile(string meName, DQMStore * dbi)
00219 {
00220 
00221 
00222   MonitorElement * me_ = dbi->get(meName);
00223 
00224   if (!me_) { 
00225     LogInfo("TriggerDQM") << "ME NOT FOUND.";
00226     return NULL;
00227   }
00228 
00229   return me_->getTProfile2D();
00230 }
00231 
00232 
00233 TProfile * L1TDTTPGClient::get1DProfile(string meName, DQMStore * dbi)
00234 {
00235 
00236 
00237   MonitorElement * me_ = dbi->get(meName);
00238 
00239   if (!me_) { 
00240     LogInfo("TriggerDQM") << "ME NOT FOUND.";
00241     return NULL;
00242   }
00243 
00244   return me_->getTProfile();
00245 }
00246 
00247 
00248 void L1TDTTPGClient::setMapPhLabel(MonitorElement *me)
00249 {
00250 
00251   me->setAxisTitle("DTTF Sector",2);
00252       for(int i=0;i<5;i++){
00253         ostringstream wheel;
00254         wheel << i-2;
00255         me->setBinLabel(1+i*4,"Wheel "+ wheel.str(),1);
00256       }
00257   
00258 }
00259 
00260 
00261 void L1TDTTPGClient::setMapThLabel(MonitorElement *me)
00262 {
00263 
00264   me->setAxisTitle("DTTF Sector",2);
00265       for(int i=0;i<5;i++){
00266         ostringstream wheel;
00267         wheel << i-2;
00268         me->setBinLabel(1+i*3,"Wheel "+ wheel.str(),1);
00269       }
00270   
00271 }