00001 #include "DQMOffline/Trigger/interface/HLTTauPostProcessor.h"
00002 #include <math.h>
00003 HLTTauPostProcessor::HLTTauPostProcessor(const edm::ParameterSet& iConfig):
00004 L1Folder_(iConfig.getParameter<std::vector<std::string> >("L1Folder")),
00005 L2Folder_(iConfig.getParameter<std::vector<std::string> >("L2Folder")),
00006 L25Folder_(iConfig.getParameter<std::vector<std::string> >("L25Folder")),
00007 L3Folder_(iConfig.getParameter<std::vector< std::string> >("L3Folder")),
00008 pathValFolder_(iConfig.getParameter<std::vector< std::string> >("HLTPathValidationFolder")),
00009 pathDQMFolder_(iConfig.getParameter<std::vector<std::string> >("HLTPathDQMFolder"))
00010 {
00011
00012 }
00013
00014 HLTTauPostProcessor::~HLTTauPostProcessor() {}
00015
00016 void HLTTauPostProcessor::beginJob(const edm::EventSetup& iSetup)
00017 {
00018 return;
00019 }
00020
00021 void HLTTauPostProcessor::endJob()
00022 {
00023
00024 dbe = 0;
00025 dbe = edm::Service<DQMStore>().operator->();
00026
00027 if (dbe) {
00028
00029
00030 for(size_t i=0;i<pathValFolder_.size();++i)
00031 if(pathValFolder_[i].size()>0)
00032 {
00033 calculatePathEfficiencies(pathValFolder_[i],"MatchedTriggers",dbe);
00034 }
00035
00036
00037 for(size_t i=0;i<L1Folder_.size();++i)
00038 if(L1Folder_[i].size()>0)
00039 {
00040 createEfficiencyHisto(L1Folder_[i],"L1TauEtEff","L1RefMatchedTauEt","RefTauHadEt",dbe);
00041 createEfficiencyHisto(L1Folder_[i],"L1TauPhiEff","L1RefMatchedTauPhi","RefTauHadPhi",dbe);
00042 createEfficiencyHisto(L1Folder_[i],"L1TauEtaEff","L1RefMatchedTauEta","RefTauHadEta",dbe);
00043
00044 createEfficiencyHisto(L1Folder_[i],"L1MuonEtEff","L1RefMatchedTauMuonEt","RefTauMuonEt",dbe);
00045 createEfficiencyHisto(L1Folder_[i],"L1MuonPhiEff","L1RefMatchedTauMuonPhi","RefTauMuonPhi",dbe);
00046 createEfficiencyHisto(L1Folder_[i],"L1MuonEtaEff","L1RefMatchedTauMuonEta","RefTauMuonEta",dbe);
00047
00048 createEfficiencyHisto(L1Folder_[i],"L1ElecEtEff","L1RefMatchedTauElecEt","RefTauElecEt",dbe);
00049 createEfficiencyHisto(L1Folder_[i],"L1ElecPhiEff","L1RefMatchedTauElecPhi","RefTauElecPhi",dbe);
00050 createEfficiencyHisto(L1Folder_[i],"L1ElecEtaEff","L1RefMatchedTauElecEta","RefTauElecEta",dbe);
00051
00052 createIntegratedHisto(L1Folder_[i],"L1SingleTauEffEt","nfidCounter",1,dbe);
00053 createIntegratedHisto(L1Folder_[i],"L1SingleTauEffRefMatchEt","nfidCounter",2,dbe);
00054
00055 createIntegratedHisto(L1Folder_[i],"L1TauMETfixEffEt","nfidCounter",1,dbe);
00056 createIntegratedHisto(L1Folder_[i],"L1TauMETfixEffRefMatchEt","nfidCounter",2,dbe);
00057
00058 createIntegratedHisto(L1Folder_[i],"L1DoubleTauEffEt","nfidCounter",1,dbe);
00059 createIntegratedHisto(L1Folder_[i],"L1DoubleTauEffRefMatchEt","nfidCounter",3,dbe);
00060
00061 createIntegratedHisto(L1Folder_[i],"L1TauIsoEgfixEffEt","nfidCounter",1,dbe);
00062 createIntegratedHisto(L1Folder_[i],"L1TauIsoEgfixEffRefMatchEt","nfidCounter",5,dbe);
00063
00064 createIntegratedHisto(L1Folder_[i],"L1TauMuonfixEffEt","nfidCounter",1,dbe);
00065 createIntegratedHisto(L1Folder_[i],"L1TauMuonfixEffRefMatchEt","nfidCounter",4,dbe);
00066
00067
00068 }
00069
00070
00071 for(size_t i=0;i<L2Folder_.size();++i)
00072 if(L2Folder_[i].size()>0)
00073 {
00074 createEfficiencyHisto(L2Folder_[i],"L2EtEff","L2EtEffNum","L2EtEffDenom",dbe);
00075
00076 }
00077
00078
00079 for(size_t i=0;i<L25Folder_.size();++i)
00080 if(L25Folder_[i].size()>0)
00081 {
00082 createEfficiencyHisto(L25Folder_[i],"L25EtEff","L25IsoJetEt","L25jetEt",dbe);
00083 createEfficiencyHisto(L25Folder_[i],"L25EtaEff","L25IsoJetEta","L25jetEta",dbe);
00084 }
00085
00086
00087 for(size_t i=0;i<L3Folder_.size();++i)
00088 if(L3Folder_[i].size()>0)
00089 {
00090 createEfficiencyHisto(L3Folder_[i],"L3EtEff","L3IsoJetEt","L3jetEt",dbe);
00091 createEfficiencyHisto(L3Folder_[i],"L3EtaEff","L3IsoJetEta","L3jetEta",dbe);
00092 }
00093
00094 }
00095
00096
00097 }
00098
00099
00100 void HLTTauPostProcessor::beginRun(const edm::Run& iRun,
00101 const edm::EventSetup& iSetup)
00102 {
00103 return;
00104 }
00105
00106 void HLTTauPostProcessor::endRun(const edm::Run& iRun,
00107 const edm::EventSetup& iSetup)
00108 {
00109 return;
00110 }
00111
00112 void HLTTauPostProcessor::analyze(const edm::Event& iEvent,
00113 const edm::EventSetup& iSetup)
00114 {
00115 return;
00116 }
00117
00118 void
00119 HLTTauPostProcessor::createEfficiencyHisto(std::string folder,std::string name,std::string hist1,std::string hist2,DQMStore* dbe)
00120 {
00121 if(dbe->dirExists(folder))
00122 {
00123 MonitorElement * effnum = dbe->get(folder+"/"+hist1);
00124 MonitorElement * effdenom = dbe->get(folder+"/"+hist2);
00125
00126 if(effnum && effdenom)
00127 {
00128 dbe->setCurrentFolder(folder);
00129 MonitorElement* Eff = dbe->book1D(name,name,effnum->getTH1F()->GetNbinsX(),effnum->getTH1F()->GetXaxis()->GetXmin(),effnum->getTH1F()->GetXaxis()->GetXmax());
00130 Eff->getTH1F()->Divide(effnum->getTH1F(),effdenom->getTH1F(),1.,1.,"B");
00131 }
00132 }
00133 }
00134
00135
00136
00137
00138 void
00139 HLTTauPostProcessor::createIntegratedHisto(std::string folder,std::string histo,std::string nfidh,int bin,DQMStore* dbe)
00140 {
00141 if(dbe->dirExists(folder))
00142 {
00143
00144 MonitorElement* eff = dbe->get(folder+"/"+histo);
00145 MonitorElement* nfid = dbe->get(folder+"/"+nfidh);
00146
00147 if(eff && nfid)
00148 {
00149 double nGenerated = nfid->getBinContent(bin);
00150
00151 int nbins = eff->getTH1F()->GetNbinsX();
00152 double integral = eff->getTH1F()->GetBinContent(nbins+1);
00153 if (nGenerated<=0) {
00154 return;
00155 }
00156 for(int i = nbins; i >= 1; i--)
00157 {
00158 double thisBin = eff->getBinContent(i);
00159 integral += thisBin;
00160 double integralEff;
00161 double integralError;
00162 integralEff = (integral / nGenerated);
00163 eff->setBinContent(i, integralEff);
00164 integralError = (sqrt(integral) / nGenerated);
00165 eff->setBinError(i, integralError);
00166 }
00167 }
00168 }
00169 }
00170
00171 void
00172 HLTTauPostProcessor::calculatePathEfficiencies(std::string folder,std::string histo,DQMStore* dbe)
00173 {
00174 if(dbe->dirExists(folder))
00175 {
00176 dbe->setCurrentFolder(folder);
00177 MonitorElement* eff = dbe->get(folder+"/"+histo);
00178
00179 if(eff)
00180 {
00181
00182 MonitorElement * effRefTruth = dbe->book1D("PathEffMatchedRef","Efficiency with Matching",eff->getNbinsX()-1,0,eff->getNbinsX()-1);
00183 for(int i =2;i<=eff->getNbinsX();++i)
00184 {
00185 effRefTruth->setBinContent(i-1,calcEfficiency(eff->getBinContent(i),eff->getBinContent(1))[0]);
00186 effRefTruth->setBinError(i-1,calcEfficiency(eff->getBinContent(i),eff->getBinContent(1))[1]);
00187 effRefTruth->setBinLabel(i-1,eff->getTH1F()->GetXaxis()->GetBinLabel(i));
00188
00189 }
00190
00191
00192
00193 MonitorElement * effRefL1 = dbe->book1D("PathEffMatchedRefL1","Efficiency with Matching Ref to L1",eff->getNbinsX()-2,0,eff->getNbinsX()-2);
00194 for(int i =3;i<=eff->getNbinsX();++i)
00195 {
00196 effRefL1->setBinContent(i-2,calcEfficiency(eff->getBinContent(i),eff->getBinContent(2))[0]);
00197 effRefL1->setBinError(i-2,calcEfficiency(eff->getBinContent(i),eff->getBinContent(2))[1]);
00198 effRefL1->setBinLabel(i-2,eff->getTH1F()->GetXaxis()->GetBinLabel(i));
00199 }
00200
00201
00202 MonitorElement * effRefPrevious = dbe->book1D("PathEffMatchedRefPrevious","Efficiency with Matching Ref To previous",eff->getNbinsX()-1,0,eff->getNbinsX()-1);
00203 for(int i = 2;i<=eff->getNbinsX();++i)
00204 {
00205 effRefPrevious->setBinContent(i-1,calcEfficiency(eff->getBinContent(i),eff->getBinContent(i-1))[0]);
00206 effRefPrevious->setBinError(i-1,calcEfficiency(eff->getBinContent(i),eff->getBinContent(i-1))[1]);
00207 effRefPrevious->setBinLabel(i-1,eff->getTH1F()->GetXaxis()->GetBinLabel(i));
00208 }
00209 }
00210 }
00211 }
00212
00213
00214 std::vector<double>
00215 HLTTauPostProcessor::calcEfficiency(float num,float denom)
00216 {
00217 std::vector<double> a;
00218 if(denom==0)
00219 {
00220 a.push_back(0.);
00221 a.push_back(0.);
00222 }
00223 else
00224 {
00225 a.push_back(num/denom);
00226 a.push_back(sqrt(a[0]*(1-a[0])/(denom)));
00227 }
00228 return a;
00229 }