Go to the documentation of this file.00001
00002 #ifndef HLTriggerOffline_HLTEffCalculator_H
00003 #define HLTriggerOffline_HLTEffCalculator_H
00004
00005
00006
00007 #include <memory>
00008 #include <string>
00009
00010
00011 #include "FWCore/Framework/interface/Frameworkfwd.h"
00012 #include "FWCore/Framework/interface/EDAnalyzer.h"
00013 #include "FWCore/Framework/interface/Event.h"
00014 #include "FWCore/Framework/interface/MakerMacros.h"
00015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00016
00017 #include "DataFormats/Common/interface/Ref.h"
00018 #include "DataFormats/Common/interface/DetSetVector.h"
00019 #include "DataFormats/Candidate/interface/Candidate.h"
00020 #include "DataFormats/JetReco/interface/Jet.h"
00021 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00022 #include "DataFormats/TrackReco/interface/Track.h"
00023 #include "DataFormats/TrackReco/interface/TrackExtra.h"
00024
00025 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00026 #include "DataFormats/MuonReco/interface/Muon.h"
00027
00028 #include "DataFormats/Candidate/interface/Candidate.h"
00029 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00030 #include "DataFormats/Common/interface/Handle.h"
00031 #include "DataFormats/Common/interface/TriggerResults.h"
00032 #include "DataFormats/Common/interface/RefToBase.h"
00033 #include "HLTrigger/HLTfilters/interface/HLTHighLevel.h"
00034 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00035 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00036
00037 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00038 #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
00039 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00040 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00041 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00042
00043 #include "FWCore/ServiceRegistry/interface/Service.h"
00044
00045 #include "HLTriggerOffline/Top/interface/TopHLTDQMHelper.h"
00046
00047
00048 #include "TDirectory.h"
00049 #include "TH1F.h"
00050 #include "TVector3.h"
00051 #include "TLorentzVector.h"
00052 #include <string>
00053 #include <vector>
00054 #include <sstream>
00055 #include <iostream>
00056 #include <TMath.h>
00057 #include "TFile.h"
00058 #include "TH1.h"
00059
00060 class EfficiencyHandler{
00061 public:
00062 EfficiencyHandler(std::string Name, std::vector<std::string> pathnames, int verb = 0):name(Name),verbosity(verb){
00063 int nPaths = (int)pathnames.size();
00064 efficiencies= new TH1D(name.c_str(),"efficiencies per path",nPaths,-0.5,(double)nPaths-0.5);
00065 std::stringstream s;
00066 for(int i = 0; i < nPaths; i++){
00067 pathNames.push_back(pathnames.at(i));
00068 efficiencies->GetXaxis()->SetBinLabel(i+1,pathnames.at(i).c_str());
00069 s.str("");
00070 s<<"path_"<<i+1;
00071 numerator.push_back(new TH1D((s.str()+"_num").c_str(),(s.str()+"_num").c_str(),1,-0.5,0.5));
00072 denominator.push_back(new TH1D((s.str()+"_den").c_str(),(s.str()+"_den").c_str(),1,-0.5,0.5));
00073 }
00074 }
00075 ~EfficiencyHandler(){}
00076 void Fill(const edm::Event& event, const edm::TriggerResults& triggerTable){
00077 for(unsigned int i = 0; i< pathNames.size(); i++){
00078 denominator.at(i)->Fill(0);
00079 if(verbosity > 0)
00080 std::cout<<pathNames.at(i)<<std::endl;
00081 if(acceptHLT(event, triggerTable,pathNames.at(i)))
00082 numerator.at(i)->Fill(0);
00083 }
00084 }
00085 void WriteAll(TDirectory * d){
00086 if(d == NULL){
00087 std::cout<<"NULL directory! Cannot write!"<<std::endl;
00088 return;
00089 }
00090 if((int)efficiencies->GetXaxis()->GetNbins() != (int)denominator.size()){
00091 std::cout<<"HLT path numbers mismatch!"<<std::endl;
00092 return;
00093 }
00094 for(unsigned int s = 0; s < pathNames.size(); s++){
00095 double eff = (double)numerator.at(s)->GetEntries();
00096 eff= eff/(double)denominator.at(s)->GetEntries();
00097 efficiencies->SetBinContent(s+1, eff);
00098 }
00099 (d->mkdir(std::string(name+"_BareNumberHists").c_str()))->cd();
00100 for(unsigned int s = 0; s < pathNames.size(); s++){
00101 numerator.at(s)->Write();
00102 denominator.at(s)->Write();
00103 }
00104 d->cd();
00105 efficiencies->Write();
00106 d->cd();
00107 }
00108 private:
00109 TH1* efficiencies;
00110 std::vector<TH1*> numerator;
00111 std::vector<TH1*> denominator;
00112 std::string name;
00113 std::vector<std::string> pathNames;
00114 int verbosity;
00115 };
00116
00117
00118
00119
00120
00121 class HLTEffCalculator : public edm::EDAnalyzer {
00122 public:
00123 explicit HLTEffCalculator(const edm::ParameterSet&);
00124 ~HLTEffCalculator();
00125
00126
00127 private:
00128 virtual void beginJob() ;
00129 virtual void analyze(const edm::Event&, const edm::EventSetup&);
00130 virtual void endJob() ;
00131
00132
00133
00134
00135
00136
00137 std::string outputFileName ;
00138 EfficiencyHandler * myEffHandler;
00139 edm::InputTag HLTresCollection;
00140 int verbosity ;
00141
00142 };
00143
00144
00145 #endif