CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQMOffline/L1Trigger/src/L1TEfficiency_Harvesting.cc

Go to the documentation of this file.
00001 /*
00002  * \file L1TEfficiency_Harvesting.cc
00003  *
00004  * $Date: 2013/03/18 17:17:53 $
00005  * $Revision: 1.2 $
00006  * \author J. Pela, C. Battilana
00007  *
00008  */
00009 
00010 // L1TMonitor includes
00011 #include "DQMOffline/L1Trigger/interface/L1TEfficiency_Harvesting.h"
00012 
00013 #include "DQMServices/Core/interface/DQMStore.h"
00014 
00015 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00016 #include "DataFormats/Common/interface/ConditionsInEdm.h" // Parameters associated to Run, LS and Event
00017 #include "DataFormats/Luminosity/interface/LumiDetails.h" // Luminosity Information
00018 #include "DataFormats/Luminosity/interface/LumiSummary.h" // Luminosity Information
00019 
00020 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
00021 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenuFwd.h"
00022 #include "CondFormats/L1TObjects/interface/L1GtPrescaleFactors.h"
00023 #include "CondFormats/L1TObjects/interface/L1GtTriggerMask.h"            // L1Gt - Masks
00024 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskAlgoTrigRcd.h" // L1Gt - Masks
00025 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
00026 #include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsAlgoTrigRcd.h"
00027 
00028 #include "DataFormats/Histograms/interface/MEtoEDMFormat.h"
00029 
00030 #include "TList.h"
00031 
00032 using namespace edm;
00033 using namespace std;
00034 
00035 //__________Efficiency_Plot_Handler_Helper_Class_______________________
00036 L1TEfficiencyPlotHandler::L1TEfficiencyPlotHandler(const L1TEfficiencyPlotHandler &handler) {
00037   
00038   m_dir      = handler.m_dir;
00039   m_plotName = handler.m_plotName;
00040   m_dbe      = handler.m_dbe;  
00041 
00042   m_effHisto = handler.m_effHisto;
00043 
00044 }
00045 
00046 
00047 void L1TEfficiencyPlotHandler::book(bool verbose) {
00048 
00049   if(verbose){
00050     cout << "[L1TEfficiencyMuons_Harvesting:] Booking efficiency histo for " 
00051          << m_dir << " and " << m_plotName << endl;
00052   }
00053   
00054   MonitorElement *num = m_dbe->get(m_dir+"/"+m_plotName+"Num");
00055   MonitorElement *den = m_dbe->get(m_dir+"/"+m_plotName+"Den");
00056 
00057   if (!num || !den) {
00058  
00059     if(verbose){
00060       cout << "[L1TEfficiencyMuons_Harvesting:] "
00061            << (!num && !den ? "Num && Den" : !num ? "Num" : "Den") 
00062            << " not gettable. Quitting booking" << endl;
00063     }
00064     return;
00065 
00066   }
00067 
00068   TH1F *numH = num->getTH1F();
00069   TH1F *denH = den->getTH1F();
00070 
00071   if (!numH || !denH) {
00072  
00073     if(verbose){
00074       cout << "[L1TEfficiencyMuons_Harvesting:] "
00075            << (!numH && !denH ? "Num && Den" : !numH ? "Num" : "Den") 
00076            << " is not TH1F. Quitting booking" << endl;
00077     }
00078     return;
00079 
00080   }
00081 
00082   int nBinsNum = numH->GetNbinsX();
00083   int nBinsDen = denH->GetNbinsX();
00084 
00085   if (nBinsNum != nBinsDen) {
00086  
00087     if(verbose){
00088       cout << "[L1TEfficiencyMuons_Harvesting:] # bins in num and den is different. Quitting booking" << endl;
00089     }
00090     return;
00091 
00092   }
00093 
00094   double min = numH->GetXaxis()->GetXmin();
00095   double max = numH->GetXaxis()->GetXmax();
00096 
00097   m_dbe->setCurrentFolder(m_dir);
00098   m_effHisto = m_dbe->book1D(m_plotName,m_plotName,nBinsNum,min,max);
00099 
00100 }
00101 
00102 
00103 void L1TEfficiencyPlotHandler::computeEfficiency(bool verbose) {
00104 
00105   if (!m_effHisto)
00106     return;
00107 
00108   if(verbose){
00109     cout << "[L1TEfficiencyMuons_Harvesting:] Computing efficiency for " 
00110          << m_plotName << endl;
00111   }
00112 
00113   MonitorElement *num = m_dbe->get(m_dir+"/"+m_plotName+"Num");
00114   MonitorElement *den = m_dbe->get(m_dir+"/"+m_plotName+"Den");
00115 
00116   TH1F *numH = num->getTH1F();
00117   TH1F *denH = den->getTH1F();
00118 
00119   numH->Sumw2();
00120   denH->Sumw2();
00121 
00122   TH1F *effH = m_effHisto->getTH1F();
00123 
00124   effH->Divide(numH,denH);
00125 
00126 }
00127 
00128   
00129 //___________DQM_analyzer_class________________________________________
00130 L1TEfficiency_Harvesting::L1TEfficiency_Harvesting(const ParameterSet & ps){
00131   
00132   // Initializing Variables
00133   if (m_verbose) {
00134     cout << "[L1TEfficiency_Harvesting:] ____________ Storage inicialization ____________ " << endl;
00135     cout << "[L1TEfficiency_Harvesting:] Setting up dbe folder: L1T/Efficiency" << endl;
00136   }
00137   
00138   DQMStore* dbe = Service <DQMStore>().operator->();
00139   dbe->setVerbose(0);
00140   
00141   // Initializing Variables
00142   if (m_verbose) {cout << "[L1TEfficiency_Harvesting:] Pointer for DQM Store: " << dbe << endl;}
00143 
00144   vector<ParameterSet> plotCfgs = ps.getUntrackedParameter<vector<ParameterSet>>("plotCfgs");
00145   
00146   vector<ParameterSet>::const_iterator plotCfgIt  = plotCfgs.begin();
00147   vector<ParameterSet>::const_iterator plotCfgEnd = plotCfgs.end();
00148 
00149   for (; plotCfgIt!=plotCfgEnd; ++plotCfgIt) {
00150     
00151     string dir = plotCfgIt->getUntrackedParameter<string>("dqmBaseDir");
00152     vector<string> plots = plotCfgIt->getUntrackedParameter<vector<string>>("plots");
00153     
00154     vector<string>::const_iterator plotIt  = plots.begin();
00155     vector<string>::const_iterator plotEnd = plots.end();
00156     
00157     for (; plotIt!=plotEnd; ++plotIt)
00158       m_plotHandlers.push_back(L1TEfficiencyPlotHandler(dir,(*plotIt),dbe));
00159                               
00160   }
00161   
00162 }
00163 
00164 
00165 //_____________________________________________________________________
00166 L1TEfficiency_Harvesting::~L1TEfficiency_Harvesting(){ m_plotHandlers.clear(); }
00167 
00168 
00169 //_____________________________________________________________________
00170 void L1TEfficiency_Harvesting::beginJob(void){
00171   
00172   if (m_verbose) {cout << "[L1TEfficiency_Harvesting:] Called beginJob." << endl;}
00173 
00174 }
00175 
00176 
00177 //_____________________________________________________________________
00178 void L1TEfficiency_Harvesting::endJob(void){
00179   
00180   if (m_verbose) {cout << "[L1TEfficiency_Harvesting:] Called endJob." << endl;}
00181 
00182 }
00183 
00184 //_____________________________________________________________________
00185 void L1TEfficiency_Harvesting::beginRun(const edm::Run& run, const edm::EventSetup& iSetup){
00186   
00187   if (m_verbose) {cout << "[L1TEfficiency_Harvesting:] Called beginRun." << endl;}    
00188 
00189 }  
00190 
00191 
00192 //_____________________________________________________________________
00193 void L1TEfficiency_Harvesting::endRun(const edm::Run& run, const edm::EventSetup& iSetup){
00194   
00195   if (m_verbose) {cout << "[L1TEfficiency_Harvesting:] Called endRun." << endl;}
00196 
00197   vector<L1TEfficiencyPlotHandler>::iterator plotHandlerIt  = m_plotHandlers.begin();
00198   vector<L1TEfficiencyPlotHandler>::iterator plotHandlerEnd = m_plotHandlers.end();
00199 
00200   for(; plotHandlerIt!=plotHandlerEnd; ++plotHandlerIt) {
00201     plotHandlerIt->book(m_verbose);
00202     plotHandlerIt->computeEfficiency(m_verbose);
00203   }
00204   
00205 }
00206 
00207 
00208 //_____________________________________________________________________
00209 void L1TEfficiency_Harvesting::beginLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) {
00210   
00211   if(m_verbose){
00212     cout << "[L1TEfficiency_Harvesting:] Called beginLuminosityBlock at LS=" 
00213          << lumiBlock.id().luminosityBlock() << endl;
00214   }
00215 }
00216 
00217 
00218 //_____________________________________________________________________
00219 void L1TEfficiency_Harvesting::endLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) {
00220   
00221   if(m_verbose){
00222     cout << "[L1TEfficiency_Harvesting:] Called endLuminosityBlock at LS=" 
00223          << lumiBlock.id().luminosityBlock() << endl;
00224   }
00225 }
00226 
00227 
00228 //_____________________________________________________________________
00229 void L1TEfficiency_Harvesting::analyze(const Event & iEvent, const EventSetup & eventSetup){
00230   
00231   
00232 }
00233 
00234 //define this as a plug-in
00235 DEFINE_FWK_MODULE(L1TEfficiency_Harvesting);