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 using namespace std;
00061 class EfficiencyHandler{
00062 public:
00063 EfficiencyHandler(std::string Name, std::vector<std::string> pathnames, int verb = 0):name(Name),verbosity(verb){
00064 int nPaths = (int)pathnames.size();
00065 efficiencies= new TH1D(name.c_str(),"efficiencies per path",nPaths,-0.5,(double)nPaths-0.5);
00066 stringstream s;
00067 for(int i = 0; i < nPaths; i++){
00068 pathNames.push_back(pathnames.at(i));
00069 efficiencies->GetXaxis()->SetBinLabel(i+1,pathnames.at(i).c_str());
00070 s.str("");
00071 s<<"path_"<<i+1;
00072 numerator.push_back(new TH1D((s.str()+"_num").c_str(),(s.str()+"_num").c_str(),1,-0.5,0.5));
00073 denominator.push_back(new TH1D((s.str()+"_den").c_str(),(s.str()+"_den").c_str(),1,-0.5,0.5));
00074 }
00075 }
00076 ~EfficiencyHandler(){}
00077 void Fill(const edm::Event& event, const edm::TriggerResults& triggerTable){
00078 for(unsigned int i = 0; i< pathNames.size(); i++){
00079 denominator.at(i)->Fill(0);
00080 if(verbosity > 0)
00081 cout<<pathNames.at(i)<<endl;
00082 if(acceptHLT(event, triggerTable,pathNames.at(i)))
00083 numerator.at(i)->Fill(0);
00084 }
00085 }
00086 void WriteAll(TDirectory * d){
00087 if(d == NULL){
00088 std::cout<<"NULL directory! Cannot write!"<<std::endl;
00089 return;
00090 }
00091 if((int)efficiencies->GetXaxis()->GetNbins() != (int)denominator.size()){
00092 std::cout<<"HLT path numbers mismatch!"<<std::endl;
00093 return;
00094 }
00095 for(unsigned int s = 0; s < pathNames.size(); s++){
00096 double eff = (double)numerator.at(s)->GetEntries();
00097 eff= eff/(double)denominator.at(s)->GetEntries();
00098 efficiencies->SetBinContent(s+1, eff);
00099 }
00100 (d->mkdir(string(name+"_BareNumberHists").c_str()))->cd();
00101 for(unsigned int s = 0; s < pathNames.size(); s++){
00102 numerator.at(s)->Write();
00103 denominator.at(s)->Write();
00104 }
00105 d->cd();
00106 efficiencies->Write();
00107 d->cd();
00108 }
00109 private:
00110 TH1* efficiencies;
00111 std::vector<TH1*> numerator;
00112 std::vector<TH1*> denominator;
00113 std::string name;
00114 std::vector<std::string> pathNames;
00115 int verbosity;
00116 };
00117
00118
00119
00120
00121
00122 class HLTEffCalculator : public edm::EDAnalyzer {
00123 public:
00124 explicit HLTEffCalculator(const edm::ParameterSet&);
00125 ~HLTEffCalculator();
00126
00127
00128 private:
00129 virtual void beginJob() ;
00130 virtual void analyze(const edm::Event&, const edm::EventSetup&);
00131 virtual void endJob() ;
00132
00133
00134
00135
00136
00137
00138 std::string outputFileName ;
00139 EfficiencyHandler * myEffHandler;
00140 edm::InputTag HLTresCollection;
00141 int verbosity ;
00142
00143 };
00144
00145
00146 #endif