CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DQMOffline/Trigger/src/FourVectorHLTClient.cc

Go to the documentation of this file.
00001 /*
00002 
00003    FourVectorHLTClient.cc
00004    author:  Vladimir Rekovic, U Minn. 
00005    date of first version: Sept 2008
00006 
00007 */
00008 //$Id: FourVectorHLTClient.cc,v 1.29 2011/09/27 16:29:40 bjk Exp $
00009 
00010 #include "DQMOffline/Trigger/interface/FourVectorHLTClient.h"
00011 
00012 #include "DQMServices/Core/interface/QTest.h"
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018 #include "DQMServices/Core/interface/QReport.h"
00019 #include "DQMServices/Core/interface/DQMStore.h"
00020 #include "DQMServices/Core/interface/MonitorElement.h"
00021 #include "TRandom.h"
00022 #include <TF1.h>
00023 #include <TGraphAsymmErrors.h>
00024 #include <TGraph.h>
00025 #include <stdio.h>
00026 #include <sstream>
00027 #include <math.h>
00028 #include <TProfile.h>
00029 #include <TProfile2D.h>
00030 #include <memory>
00031 #include <iostream>
00032 #include <iomanip>
00033 #include <map>
00034 #include <vector>
00035 #include <string>
00036 #include <fstream>
00037 #include "TROOT.h"
00038 
00039 
00040 using namespace edm;
00041 using namespace std;
00042 
00043 FourVectorHLTClient::FourVectorHLTClient(const edm::ParameterSet& ps)
00044 {
00045 
00046   parameters_=ps;
00047   initialize();
00048 
00049 }
00050 
00051 FourVectorHLTClient::~FourVectorHLTClient(){
00052 
00053   LogDebug("FourVectorHLTClient")<< "FourVectorHLTClient: ending...." ;
00054 
00055 }
00056 
00057 //--------------------------------------------------------
00058 void FourVectorHLTClient::initialize(){ 
00059 
00060   counterLS_=0; 
00061   counterEvt_=0; 
00062   
00063   // get back-end interface
00064   dbe_ = Service<DQMStore>().operator->();
00065 
00066   processname_ = parameters_.getUntrackedParameter<std::string>("processname","HLT");
00067   
00068 
00069   // base folder for the contents of this job
00070   sourceDir_ = TString(parameters_.getUntrackedParameter<string>("hltSourceDir",""));
00071 
00072 
00073 
00074   // remove trainling "/" from dirname
00075   while(sourceDir_.Last('/') == sourceDir_.Length()-1) {
00076     sourceDir_.Remove(sourceDir_.Length()-1);
00077   }
00078   LogDebug("FourVectorHLTClient")<< "Source dir = " << sourceDir_ << endl;
00079     
00080   clientDir_ = TString(parameters_.getUntrackedParameter<string>("hltClientDir",""));
00081 
00082   // remove trainling "/" from dirname
00083   while(clientDir_.Last('/') == clientDir_.Length()-1) {
00084     clientDir_.Remove(clientDir_.Length()-1);
00085   }
00086   LogDebug("FourVectorHLTClient")<< "Client dir = " << clientDir_ << endl;
00087     
00088   prescaleLS_ = parameters_.getUntrackedParameter<int>("prescaleLS", -1);
00089   LogDebug("FourVectorHLTClient")<< "DQM lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< endl;
00090   
00091   prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1);
00092   LogDebug("FourVectorHLTClient")<< "DQM event prescale = " << prescaleEvt_ << " events(s)"<< endl;
00093   
00094   customEffDir_ = TString(parameters_.getUntrackedParameter<string>("customEffDir","custom-efficiencies"));
00095   LogDebug("FourVectorHLTClient")<< "Custom Efficiencies dir = " << customEffDir_ << endl;
00096     
00097   std::vector<edm::ParameterSet> effpaths = parameters_.getParameter<std::vector<edm::ParameterSet> >("effpaths");
00098 
00099   std::pair<std::string, std::string> custompathnamepair;
00100   for(std::vector<edm::ParameterSet>::iterator pathconf = effpaths.begin() ; pathconf != effpaths.end(); 
00101       pathconf++) {
00102        custompathnamepair.first =pathconf->getParameter<std::string>("pathname"); 
00103        custompathnamepair.second = pathconf->getParameter<std::string>("denompathname");   
00104        custompathnamepairs_.push_back(custompathnamepair);
00105        //    customdenompathnames_.push_back(pathconf->getParameter<std::string>("denompathname"));  
00106        // custompathnames_.push_back(pathconf->getParameter<std::string>("pathname"));  
00107     }
00108 
00109   pathsSummaryFolder_ = parameters_.getUntrackedParameter ("pathsSummaryFolder",std::string("HLT/FourVector/PathsSummary/"));
00110   pathsSummaryHLTCorrelationsFolder_ = parameters_.getUntrackedParameter ("hltCorrelationsFolder",std::string("HLT/FourVector/PathsSummary/HLT Correlations/"));
00111   pathsSummaryFilterCountsFolder_ = parameters_.getUntrackedParameter ("filterCountsFolder",std::string("HLT/FourVector/PathsSummary/Filters Counts/"));
00112   pathsSummaryFilterEfficiencyFolder_ = parameters_.getUntrackedParameter ("filterEfficiencyFolder",std::string("HLT/FourVector/PathsSummary/Filters Efficiencies/"));
00113 
00114 }
00115 
00116 //--------------------------------------------------------
00117 void FourVectorHLTClient::beginJob(){
00118 
00119   LogDebug("FourVectorHLTClient")<<"[FourVectorHLTClient]: beginJob" << endl;
00120   // get backendinterface  
00121   dbe_ = Service<DQMStore>().operator->();
00122 
00123 }
00124 
00125 //--------------------------------------------------------
00126 void FourVectorHLTClient::beginRun(const Run& r, const EventSetup& context) {
00127 
00128   LogDebug("FourVectorHLTClient")<<"[FourVectorHLTClient]: beginRun" << endl;
00129   // HLT config does not change within runs!
00130   bool changed=false;
00131  
00132   if (!hltConfig_.init(r, context, processname_, changed)) {
00133 
00134     processname_ = "FU";
00135 
00136     if (!hltConfig_.init(r, context, processname_, changed)){
00137 
00138       LogDebug("FourVectorHLTOffline") << "HLTConfigProvider failed to initialize.";
00139 
00140     }
00141 
00142     // check if trigger name in (new) config
00143     //  cout << "Available TriggerNames are: " << endl;
00144     //  hltConfig_.dump("Triggers");
00145   }
00146 
00147 }
00148 
00149 //--------------------------------------------------------
00150 void FourVectorHLTClient::beginLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
00151    // optionally reset histograms here
00152 }
00153 
00154 void FourVectorHLTClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& c){   
00155 } 
00156 
00157 
00158 
00159 //--------------------------------------------------------
00160 void FourVectorHLTClient::analyze(const Event& e, const EventSetup& context){
00161    
00162   counterEvt_++;
00163   if (prescaleEvt_<1) return;
00164   if (prescaleEvt_>0 && counterEvt_%prescaleEvt_ != 0) return;
00165   
00166   LogDebug("FourVectorHLTClient")<<"analyze..." << endl;
00167 
00168 }
00169 
00170 //--------------------------------------------------------
00171 void FourVectorHLTClient::endRun(const Run& r, const EventSetup& context){
00172 
00173   LogDebug("FourVectorHLTClient")<<"FourVectorHLTClient:: endLuminosityBlock "  << endl;
00174 
00175 
00176   // Work with PathsSummary ME's
00178   dbe_->setCurrentFolder(pathsSummaryFolder_.c_str());
00179  
00180   std::vector<MonitorElement*> summaryME;
00181   summaryME = dbe_->getContents(pathsSummaryFilterCountsFolder_.c_str());
00182 
00183   vector<float> hltPassCount;
00184 
00185   for(unsigned int i=0; i< summaryME.size(); i++) {
00186 
00187     TString nameME = (summaryME[i])->getName();
00188     LogDebug("FourVectorHLTClient") << "ME = " << nameME << endl;
00189 
00190     TString fullPathToME    = pathsSummaryFilterCountsFolder_ + nameME;
00191     LogDebug("FourVectorHLTClient") << "fullPathME = " << fullPathToME << endl;
00192 
00193     if(nameME.Contains("Filters_")) {
00194 
00195 
00196       TH1F* MEHist = summaryME[i]->getTH1F() ;
00197       LogDebug("FourVectorHLTClient") << "this is TH1 first bin label = " << MEHist->GetXaxis()->GetBinLabel(1) << endl;
00198       LogDebug("FourVectorHLTClient") << "is this is TH1 = " << fullPathToME << endl;
00199 
00200       TString nameMEeff           = nameME+"_Eff";
00201       TString titleMEeff           = nameME+" Efficiency wrt input to L1";
00202 
00203       TH1F* effHist = (TH1F*) MEHist->Clone(nameMEeff.Data());
00204       effHist->SetTitle(titleMEeff.Data());
00205 
00206       float firstBinContent = MEHist->GetBinContent(1);
00207 
00208       if(firstBinContent !=0 ) {
00209 
00210         effHist->Scale(1./firstBinContent);
00211 
00212       }
00213       else {
00214 
00215         unsigned int nBins = effHist->GetNbinsX();
00216         for(unsigned int bin = 0; bin < nBins+1; bin++)  effHist->SetBinContent(bin, 0);
00217 
00218       }
00219 
00220       dbe_->setCurrentFolder(pathsSummaryFilterEfficiencyFolder_.c_str());
00221 
00222       dbe_->book1D(nameMEeff.Data(), effHist);
00223 
00224 
00225      } // end if "Filters_" ME
00226 
00227   } // end for MEs
00228 
00229   // Normalize PassPass and PassFail Matrices
00231   vector<string> name;
00232   name.push_back("All");
00233   name.push_back("Muon");
00234   name.push_back("Egamma");
00235   name.push_back("Tau");
00236   name.push_back("JetMET");
00237   name.push_back("Rest");
00238   name.push_back("Special");
00239 
00241   vector<string> datasetNames =  hltConfig_.datasetNames() ;
00242 
00243   for (unsigned int i=0;i<datasetNames.size();i++) {
00244 
00245     name.push_back(datasetNames[i]);
00246 
00247   }
00248 
00249   string fullPathToME; 
00250 
00251   for (unsigned int i=0;i<name.size();i++) {
00252 
00253     fullPathToME = pathsSummaryFolder_ +"HLT_"+name[i]+"_PassPass";
00254     v_ME_HLTPassPass_.push_back( dbe_->get(fullPathToME));
00255 
00256     fullPathToME = pathsSummaryHLTCorrelationsFolder_+"HLT_"+name[i]+"_PassPass_Normalized";
00257     v_ME_HLTPassPass_Normalized_.push_back( dbe_->get(fullPathToME));
00258 
00259     fullPathToME = pathsSummaryHLTCorrelationsFolder_+"HLT_"+name[i]+"_Pass_Normalized_Any";
00260     v_ME_HLTPass_Normalized_Any_.push_back( dbe_->get(fullPathToME));
00261 
00262   }
00263   normalizeHLTMatrix();
00264   
00265 
00266 
00267   // HLT paths
00268   TObjArray *hltPathNameColl = new TObjArray(100);
00269   hltPathNameColl->SetOwner();
00270   std::vector<std::string> fullPathHLTFolders;
00271  
00272   // get subdir of the sourceDir_ to get HLT path names
00274   dbe_->setCurrentFolder(sourceDir_.Data());
00275  
00276   fullPathHLTFolders = dbe_->getSubdirs();
00277  
00278 
00279   LogDebug("FourVectorHLTClient")<<"endRun: sourceDir_(" << sourceDir_.Data() << ") has " << fullPathHLTFolders.size() << " folders. " << endl;
00280  
00281  
00282   for(unsigned int i=0;i<fullPathHLTFolders.size();i++) {
00283  
00284     LogDebug("FourVectorHLTClient")<<"endRun: sourceDir_(" << sourceDir_.Data() << ") folder["<< i << "] = " << fullPathHLTFolders[i] << endl;
00285     TString hltPath = fullPathHLTFolders[i].substr(fullPathHLTFolders[i].rfind('/')+1, fullPathHLTFolders[i].size());
00286  
00287     //*****
00288     hltPath = removeVersions(hltPath);
00289     //*****
00290 
00292     // Efficiencies
00294 
00295     TString currEffFolder = clientDir_ + "/" + hltPath + "/" + customEffDir_ + "/";
00296 
00297     //*****
00298     currEffFolder = removeVersions(currEffFolder);
00299     //*****
00300 
00301 
00302     LogDebug("FourVectorHLTClient")<< "Custom Efficiencies dir path = " << currEffFolder << endl;
00303   
00304     dbe_->setCurrentFolder(currEffFolder.Data());
00305  
00306 
00307     hltMEs = dbe_->getContents(fullPathHLTFolders[i]);
00308     LogDebug("FourVectorHLTClient")<< "Number of MEs for this HLT path = " << hltMEs.size() << endl;
00309   
00310     // custom efficiencies
00311   
00312     for (std::vector<std::pair<std::string, std::string> >::iterator custompathnamepair = custompathnamepairs_.begin(); custompathnamepair != custompathnamepairs_.end(); ++custompathnamepair)
00313     {
00314   
00315       //TString numPathName=TString(custompathnamepair->first);
00316       //if(!hltPath.Contains(numPathName,TString::kExact)) continue;
00317       //TString numPathName=hltPath;
00318       //if(!hltPath.Contains(numPathName,TString::kExact)) continue;
00319       //LogDebug("FourVectorHLTClient")<< "hltPath = " << hltPath <<  "   matchString = " << custompathnamepair->first << endl;
00320       //if(!hltPath.Contains(TString(custompathnamepair->first),TString::kExact)) continue;
00321       if(!hltPath.Contains(TString(custompathnamepair->first))) continue;
00322   
00323       TString numPathName=hltPath;
00324       TString denPathName=TString(custompathnamepair->second);
00325 
00326       numPathName = removeVersions(numPathName);
00327 
00328 
00329 
00330       vector<TString> vStage;
00331       vStage.push_back(TString("L1"));
00332       vStage.push_back(TString("On"));
00333       vStage.push_back(TString("Off"));
00334       vStage.push_back(TString("Mc"));
00335       vStage.push_back(TString("L1UM"));
00336       vStage.push_back(TString("OnUM"));
00337       vStage.push_back(TString("OffUM"));
00338       vStage.push_back(TString("McUM"));
00339   
00340       vector<TString> vObj;
00341       vObj.push_back(TString("l1Et"));
00342       vObj.push_back(TString("onEt"));
00343       vObj.push_back(TString("offEt"));
00344       vObj.push_back(TString("mcEt"));
00345   
00346   
00347       // TH1Fs
00348       for (unsigned int k=0; k<vObj.size();k++) {
00349        for (unsigned int l=0; l<vStage.size();l++) {
00350         for (unsigned int m=0; m<vStage.size();m++) {
00351   
00352           TString oldHistPathNum;
00353           TString oldHistPathNumBck;  
00354           TString oldHistPathDen;
00355    
00356           // not the differeence b/w  Num and NumBck, as in OnOff vs OffOn
00357           oldHistPathNum    = sourceDir_+"/"+hltPath+"/"+numPathName+"_wrt_"+denPathName+"_"+vObj[k]+vStage[l]+vStage[m]; 
00358           oldHistPathNumBck = sourceDir_+"/"+hltPath+"/"+numPathName+"_wrt_"+denPathName+"_"+vObj[k]+vStage[m]+vStage[l]; 
00359   
00360           // In the deominator hist name, we don't have any "UM" substrings, so remove them
00361           TString tempDenString = vStage[l];
00362           tempDenString.ReplaceAll("UM","") ;
00363           oldHistPathDen    = sourceDir_+"/"+hltPath+"/"+numPathName+"_wrt_"+denPathName+"_"+vObj[k]+tempDenString;
00364      
00365           MonitorElement *numME    = dbe_->get(oldHistPathNum.Data());
00366           MonitorElement *numMEBck = dbe_->get(oldHistPathNumBck.Data());
00367           MonitorElement *denME    = dbe_->get(oldHistPathDen.Data());
00368    
00369           LogDebug("FourVectorHLTClient")<< " oldHistPathNum    = " << oldHistPathNum    << endl;
00370           LogDebug("FourVectorHLTClient")<< " oldHistPathNumBck = " << oldHistPathNumBck << endl;
00371           LogDebug("FourVectorHLTClient")<< " oldHistPathDen    = " << oldHistPathDen    << endl;
00372      
00373           //check if HLTOffline histogram exist
00374           if ( numME &&  denME ) { 
00375    
00376             LogDebug("FourVectorHLTClient")<< "DID find NUM and DEN histograms to derive eff " << vStage[m]<<"To"<<vStage[l]<<" using:" <<endl 
00377             << " NUM = " << oldHistPathNum  << endl
00378             << " DEN = " << oldHistPathDen  << endl;
00379    
00380           }
00381           else { 
00382    
00383            LogDebug("FourVectorHLTClient")<< "Cannot find NUM and DEN histograms to derive eff " << vStage[m]<<"To"<<vStage[l]<<" using:" <<endl 
00384            << " NUM = " << oldHistPathNum  << endl
00385            << " DEN = " << oldHistPathDen  << endl;
00386    
00387            if ( numMEBck &&  denME) { 
00388    
00389              LogDebug("FourVectorHLTClient")<< "DID find NUM and DEN histograms to derive eff " << vStage[m]<<"To"<<vStage[l]<<" using:" <<endl 
00390              << " NUM = " << oldHistPathNumBck  << endl
00391              << " DEN = " << oldHistPathDen  << endl;
00392    
00393              numME = numMEBck;
00394    
00395            }
00396            else {
00397    
00398              LogDebug("FourVectorHLTClient")<< "Cannot find NUM and DEN histograms to derive eff " << vStage[m]<<"To"<<vStage[l]<<" using:" <<endl 
00399              << " NUM = " << oldHistPathNumBck  << endl
00400              << " DEN = " << oldHistPathDen  << endl;
00401    
00402              continue;
00403            }
00404    
00405           }
00406    
00407           // EtaPhi histos are TH2s, the rest are TH1s
00408           TH1F * numHist = numME->getTH1F();
00409           TH1F * denHist = denME->getTH1F();
00410   
00411           // build names and title for efficiency histogram
00412           TString newHistName   = hltPath +"_wrt_" + denPathName +"_"+vObj[k]+"_Eff_"+vStage[m]+"To"+vStage[l];
00413 
00414           // if there is "UM", remove it first,then append it to the end of the name
00415           if(newHistName.Contains("UM")) {
00416   
00417             newHistName.ReplaceAll("UM","");
00418             newHistName.Append("_UM");
00419   
00420           }
00421   
00422           TString newHistTitle  = numPathName+" given " + denPathName +"  "+vObj[k]+" Eff  "+vStage[m]+"To"+vStage[l];
00423 
00424           // if there is "UM", remove it first,then append it to the end of the name
00425           if(newHistTitle.Contains("UM")) {
00426   
00427             newHistTitle.ReplaceAll("UM","");
00428             newHistTitle.Append("_UM");
00429   
00430           }
00431   
00432           TString newHistPath   = currEffFolder+newHistName;
00433           
00434           LogDebug("FourVectorHLTClient")<< "Will make efficiency histogram " << newHistPath << endl;
00435      
00436           TH1F* effHist = (TH1F*) numHist->Clone(newHistName.Data());
00437   
00438           effHist->SetTitle(newHistTitle.Data());
00439   
00440           //effHist->Sumw2(); 
00441           //denHist->Sumw2();
00442           //effHist->Divide(numHist,denHist);
00443   
00444           //effHist->Divide(numHist,denHist,1.,1.,"B");
00445   
00446           calculateRatio(effHist, denHist);
00447   
00448           /*
00449           effHist->Divide(numHist,denHist,1.,1.);
00450   
00451           for (int i=0;i<=effHist->GetNbinsX();i++) {
00452   
00453             float err = 0;
00454             if(numHist->GetBinContent(i)>0) err = 1./sqrt(numHist->GetBinContent(i));   // 1/sqrt(number of total)
00455             effHist->SetBinError(i,err);
00456   
00457           }
00458           */
00459          
00460           LogDebug("FourVectorHLTClient")<< "Numerator   hist " << numHist->GetName() << endl;
00461           LogDebug("FourVectorHLTClient")<< "Denominator hist " << denHist->GetName() << endl;
00462          
00463           LogDebug("FourVectorHLTClient")<< "Booking efficiency histogram path " << newHistPath << endl;
00464           LogDebug("FourVectorHLTClient")<< "Booking efficiency histogram name " << newHistName << endl;
00465   
00466           // book eff histos
00467           dbe_->book1D(newHistName.Data(), effHist);
00468         
00469   
00470         } // end for Stage m
00471        } // end for Stage l
00472       } //end for obj k
00473   
00474       vObj.clear();
00475       vObj.push_back(TString("l1Etal1Phi"));
00476       vObj.push_back(TString("onEtaonPhi"));
00477       vObj.push_back(TString("offEtaoffPhi"));
00478       vObj.push_back(TString("mcEtamcPhi"));
00479  
00480       for (unsigned int k=0; k<vObj.size();k++) {
00481        for (unsigned int l=0; l<vStage.size();l++) {
00482         for (unsigned int m=0; m<vStage.size();m++) {
00483   
00484   
00485          TString oldHistPathNum;
00486          TString oldHistPathNumBck;  
00487          TString oldHistPathDen;
00488   
00489          // not the differeence b/w  Num and NumBck, as in OnOff vs OffOn
00490          oldHistPathNum    = sourceDir_+"/"+hltPath+"/"+numPathName+"_wrt_"+denPathName+"_"+vObj[k]+vStage[l]+vStage[m]; 
00491          oldHistPathNumBck = sourceDir_+"/"+hltPath+"/"+numPathName+"_wrt_"+denPathName+"_"+vObj[k]+vStage[m]+vStage[l]; 
00492 
00493          // In the deominator hist name, we don't have any "UM" substrings, so remove them
00494          TString tempDenString = vStage[l];
00495          tempDenString.ReplaceAll("UM","") ;
00496          oldHistPathDen    = sourceDir_+"/"+hltPath+"/"+numPathName+"_wrt_"+denPathName+"_"+vObj[k]+tempDenString;
00497     
00498          MonitorElement *numME    = dbe_->get(oldHistPathNum.Data());
00499          MonitorElement *numMEBck = dbe_->get(oldHistPathNumBck.Data());
00500          MonitorElement *denME    = dbe_->get(oldHistPathDen.Data());
00501   
00502          LogDebug("FourVectorHLTClient")<< " oldHistPathNum    = " << oldHistPathNum    << endl;
00503          LogDebug("FourVectorHLTClient")<< " oldHistPathNumBck = " << oldHistPathNumBck << endl;
00504          LogDebug("FourVectorHLTClient")<< " oldHistPathDen    = " << oldHistPathDen    << endl;
00505     
00506          //check if HLTOffline histogram exist
00507          if ( numME &&  denME ) { 
00508   
00509            LogDebug("FourVectorHLTClient")<< "DID find NUM and DEN histograms to derive eff " << vStage[m]<<"To"<<vStage[l]<<" using:" <<endl 
00510            << " NUM = " << oldHistPathNum  << endl
00511            << " DEN = " << oldHistPathDen  << endl;
00512   
00513          }
00514          else { 
00515   
00516            LogDebug("FourVectorHLTClient")<< "Cannot find NUM and DEN histograms to derive eff " << vStage[m]<<"To"<<vStage[l]<<" using:" <<endl 
00517            << " NUM = " << oldHistPathNum  << endl
00518            << " DEN = " << oldHistPathDen  << endl;
00519   
00520            if ( numMEBck &&  denME) { 
00521   
00522              LogDebug("FourVectorHLTClient")<< "DID find NUM and DEN histograms to derive eff " << vStage[m]<<"To"<<vStage[l]<<" using:" <<endl 
00523              << " NUM = " << oldHistPathNumBck  << endl
00524              << " DEN = " << oldHistPathDen  << endl;
00525              numME = numMEBck;
00526   
00527            }
00528            else {
00529   
00530              LogDebug("FourVectorHLTClient")<< "Cannot find NUM and DEN histograms to derive eff " << vStage[m]<<"To"<<vStage[l]<<" using:" <<endl 
00531              << " NUM = " << oldHistPathNumBck  << endl
00532              << " DEN = " << oldHistPathDen  << endl;
00533   
00534              continue;
00535  
00536            }
00537   
00538          }
00539   
00540          TH2F* numHist = numME->getTH2F();
00541          TH2F* denHist = denME->getTH2F();
00542  
00543          // build names and title for efficiency histogram
00544  
00545          TString newHistName   = hltPath +"_wrt_" + denPathName +"_"+vObj[k]+"_Eff_"+vStage[m]+"To"+vStage[l];
00546  
00547          // if there is "UM", remove it first,then append it to the end of the name
00548          if(newHistName.Contains("UM")) {
00549  
00550            newHistName.ReplaceAll("UM","");
00551            newHistName.Append("_UM");
00552  
00553          }
00554  
00555          TString newHistTitle  = numPathName+" given " + denPathName +"  "+vObj[k]+" Eff  "+vStage[m]+"To"+vStage[l];
00556          // if there is "UM", remove it first,then append it to the end of the name
00557          if(newHistTitle.Contains("UM")) {
00558            
00559            newHistTitle.ReplaceAll("UM","");
00560            newHistTitle.Append("_UM");
00561  
00562          }
00563  
00564          TString newHistPath   = currEffFolder+newHistName;
00565          newHistPath = removeVersions(newHistPath);
00566 
00567          LogDebug("FourVectorHLTClient")<< "Will make efficiency histogram " << newHistPath << endl;
00568     
00569          TH2F* effHist = (TH2F*) numHist->Clone(newHistName.Data());
00570  
00571          effHist->SetTitle(newHistTitle.Data());
00572          effHist->Sumw2(); 
00573          //denHist->Sumw2();
00574          //effHist->Divide(numHist,denHist,1.,1.,"B");
00575          effHist->Divide(numHist,denHist,1.,1.);
00576         
00577          //reportSummaryMap_ = dbe_->book2D(numHist->Divide(denHist));
00578         
00579          LogDebug("FourVectorHLTClient")<< "Booking efficiency histogram path " << newHistPath << endl;
00580          LogDebug("FourVectorHLTClient")<< "Booking efficiency histogram name " << newHistName << endl;
00581  
00582          // book eff histos
00583          dbe_->book2D(newHistName.Data(), effHist);
00584         
00585         } // end for Stage m
00586        } // end for Stage l
00587       } //end for obj k
00588  
00589     } // end for custompathpair
00590  
00591   } // end loop over folders for i
00592  
00593  
00594   hltPathNameColl->Delete();
00595 
00596 }
00597 
00598 //--------------------------------------------------------
00599 void FourVectorHLTClient::endJob(){
00600 }
00601 
00602 
00603 TH1F * FourVectorHLTClient::get1DHisto(string meName, DQMStore * dbi)
00604 {
00605 
00606   MonitorElement * me_ = dbi->get(meName);
00607 
00608   if (!me_) { 
00609     LogDebug("FourVectorHLTClient")<< "ME NOT FOUND." << endl;
00610     return NULL;
00611   }
00612 
00613   return me_->getTH1F();
00614 
00615 }
00616 
00617 
00618 TH2F * FourVectorHLTClient::get2DHisto(string meName, DQMStore * dbi)
00619 {
00620 
00621 
00622   MonitorElement * me_ = dbi->get(meName);
00623 
00624   if (!me_) { 
00625     LogDebug("FourVectorHLTClient")<< "ME NOT FOUND." << endl;
00626     return NULL;
00627   }
00628 
00629   return me_->getTH2F();
00630 }
00631 
00632 
00633 TProfile2D *  FourVectorHLTClient::get2DProfile(string meName, DQMStore * dbi)
00634 {
00635 
00636   MonitorElement * me_ = dbi->get(meName);
00637 
00638   if (!me_) { 
00639     LogDebug("FourVectorHLTClient")<< "ME NOT FOUND." << endl;
00640    return NULL;
00641   }
00642 
00643   return me_->getTProfile2D();
00644 }
00645 
00646 
00647 TProfile *  FourVectorHLTClient::get1DProfile(string meName, DQMStore * dbi)
00648 {
00649 
00650   MonitorElement * me_ = dbi->get(meName);
00651 
00652   if (!me_) { 
00653     LogDebug("FourVectorHLTClient")<< "ME NOT FOUND." << endl;
00654     return NULL;
00655   }
00656 
00657   return me_->getTProfile();
00658 }
00659 
00660 TString FourVectorHLTClient::removeVersions(TString histVersion) {
00661   for (int ii = 100; ii >= 0; ii--) {
00662     string ver = "_v";
00663     string version ="";
00664     stringstream ss;
00665     ss << ver << ii;
00666     ss >> version;
00667     
00668     if (histVersion.Contains(version)){
00669       histVersion.ReplaceAll(version,"");
00670     }
00671   }
00672   return histVersion;
00673 }
00674 
00675 void FourVectorHLTClient::calculateRatio(TH1F* effHist, TH1F* denHist) {
00676 
00677   //cout << " NUMERATOR histogram name = " << effHist->GetName() << endl;
00678   int nBins= effHist->GetNbinsX();
00679   for (int i=0;i<=nBins;i++) {
00680 
00681     float k = effHist->GetBinContent(i);   // number of pass
00682     float N = denHist->GetBinContent(i);   // number of total
00683 
00684     float ratio;
00685     float err;
00686 
00687     //ratio = N ? k / N : 0; 
00688     if(N>0) ratio = k / N;
00689     else ratio = 0;
00690 
00691     if(N > 0) {
00692 
00693       if(ratio <= 1) {
00694         err = sqrt(ratio*(1-ratio)/N);
00695       }
00696       //else if(ratio == 1) {
00697         //err = 1./sqrt(2*N);
00698       //}
00699       else {
00700         err = 0;
00701       }
00702 
00703       effHist->SetBinContent(i,ratio);
00704       effHist->SetBinError(i,err);
00705 
00706     }
00707 
00708   }
00709 
00710 }
00711 
00712 
00713 void FourVectorHLTClient::normalizeHLTMatrix() {
00714 
00715     
00716   for (unsigned int i =0;i<v_ME_HLTPassPass_.size();i++) {
00717 
00718     MonitorElement* ME_HLTPassPass_ = v_ME_HLTPassPass_[i]; 
00719     MonitorElement* ME_HLTPassPass_Normalized_ = v_ME_HLTPassPass_Normalized_[i]; 
00720     MonitorElement* ME_HLTPass_Normalized_Any_ = v_ME_HLTPass_Normalized_Any_[i]; 
00721 
00722     if(!ME_HLTPassPass_ || !ME_HLTPassPass_Normalized_ || !ME_HLTPass_Normalized_Any_) return;
00723 
00724     float passCount = 0;
00725     unsigned int nBinsX = ME_HLTPassPass_->getTH2F()->GetNbinsX();
00726     unsigned int nBinsY = ME_HLTPassPass_->getTH2F()->GetNbinsY();
00727 
00728     for(unsigned int binX = 0; binX < nBinsX+1; binX++) {
00729        
00730       passCount = ME_HLTPassPass_->getTH2F()->GetBinContent(binX,binX);
00731 
00732 
00733       for(unsigned int binY = 0; binY < nBinsY+1; binY++) {
00734 
00735         if(passCount != 0) {
00736 
00737           // normalize each bin to number of passCount
00738           float normalizedBinContentPassPass = (ME_HLTPassPass_->getTH2F()->GetBinContent(binX,binY))/passCount;
00739           //float normalizedBinContentPassFail = (ME_HLTPassFail_->getTH2F()->GetBinContent(binX,binY))/passCount;
00740 
00741           ME_HLTPassPass_Normalized_->getTH2F()->SetBinContent(binX,binY,normalizedBinContentPassPass);
00742           //ME_HLTPassFail_Normalized_->getTH2F()->SetBinContent(binX,binY,normalizedBinContentPassFail);
00743 
00744           if(binX == nBinsX) {
00745 
00746             ME_HLTPass_Normalized_Any_->getTH1F()->SetBinContent(binY,normalizedBinContentPassPass);
00747 
00748           }
00749 
00750         }
00751         else {
00752 
00753           ME_HLTPassPass_Normalized_->getTH2F()->SetBinContent(binX,binY,0);
00754           //ME_HLTPassFail_Normalized_->getTH2F()->SetBinContent(binX,binY,0);
00755 
00756         } // end if else
00757      
00758       } // end for binY
00759 
00760     } // end for binX
00761   
00762   } // end for i
00763 
00764 }