13 #include <TEfficiency.h>
45 shortReferenceName =
"RECO";
47 shortReferenceName =
"gen";
68 std::vector<std::string> subdirectories = igetter.
getSubdirs();
74 std::vector<std::string> postfixes;
75 postfixes.push_back(
"");
76 postfixes.push_back(
"_RECO_matched");
81 postfixes.push_back(
"_MC_matched");
83 std::vector<TProfile *> allElePaths;
88 for(std::vector<std::string>::iterator
dir = subdirectories.begin() ;
dir!= subdirectories.end(); ++
dir) {
89 if (
dir->find(
"Ele") != std::string::npos ||
dir->find(
"_SC") != std::string::npos) ++nEle;
90 else if (
dir->find(
"Photon") != std::string::npos) ++nPhoton;
93 std::vector<TProfile *> allPhotonPaths;
94 for(std::vector<std::string>::iterator postfix=postfixes.begin(); postfix!=postfixes.end();postfix++){
103 std::string histoName =
"efficiency_by_step" + *postfix;
106 std::string allEleHistoName =
"EfficiencyByPath_Ele" + *postfix;
107 std::string allEleHistoLabel =
"Efficiency_for_each_validated_electron_path" + *postfix;
108 allElePaths.push_back(
new TProfile(allEleHistoName.c_str(), allEleHistoLabel.c_str(), nEle, 0., (double)nEle, 0., 1.2));
109 std::string allPhotonHistoName =
"EfficiencyByPath_Photon" + *postfix;
110 std::string allPhotonHistoLabel =
"Efficiency_for_each_validated_photon_path" + *postfix;
111 allPhotonPaths.push_back(
new TProfile(allPhotonHistoName.c_str(), allPhotonHistoLabel.c_str(), nPhoton, 0., (double)nPhoton, 0., 1.2));
113 for(std::vector<std::string>::iterator
dir = subdirectories.begin();
dir!= subdirectories.end();
dir++) {
118 trigName = trigName.replace(trigName.rfind(
"_DQM"),4,
"");
127 else genName = ibooker.
pwd() +
"/gen_et";
128 TH1F* genHist =
getHistogram(ibooker, igetter, genName);
129 if (genHist->GetEntries() == 0) {
130 edm::LogInfo(
"EmDQMPostProcessor") <<
"Zero events were selected for path '" << trigName <<
"'. No efficiency plots will be generated.";
131 if (trigName.find(
"Ele") != std::string::npos || trigName.find(
"_SC") != std::string::npos) {
132 allElePaths.back()->GetXaxis()->SetBinLabel(elePos, trigName.c_str());
134 }
else if (trigName.find(
"Photon") != std::string::npos) {
135 allPhotonPaths.back()->GetXaxis()->SetBinLabel(photonPos, trigName.c_str());
143 TH1F* basehist =
getHistogram(ibooker, igetter, ibooker.
pwd() +
"/" + baseName);
144 if (basehist ==
NULL)
155 MonitorElement* meTotal = ibooker.
bookProfile(trigName +
"__" + histoName,trigName +
"__" + histoName,basehist->GetXaxis()->GetNbins(),basehist->GetXaxis()->GetXmin(),basehist->GetXaxis()->GetXmax(),0.,1.2);
159 total->GetXaxis()->SetBinLabel(1,basehist->GetXaxis()->GetBinLabel(1));
167 double errorh=0,errorl=0,
error=0;
169 for(
int bin= total->GetNbinsX()-2 ;
bin > 1 ;
bin--){
174 if(basehist->GetBinContent(
bin-1) != 0){
175 Efficiency( (
int)basehist->GetBinContent(
bin), (int)basehist->GetBinContent(
bin-1), 0.683,
value, errorl, errorh );
176 error = value-errorl>errorh-value ? value-errorl : errorh-
value;
178 total->SetBinContent(
bin, value );
179 total->SetBinEntries(
bin, 1 );
181 total->GetXaxis()->SetBinLabel(
bin,basehist->GetXaxis()->GetBinLabel(
bin));
185 if(basehist->GetBinContent(basehist->GetNbinsX()) !=0 ){
186 Efficiency( (
int)basehist->GetBinContent(1), (int)basehist->GetBinContent(basehist->GetNbinsX()), 0.683, value, errorl, errorh );
187 error= value-errorl>errorh-value ? value-errorl : errorh-
value;
191 total->SetBinContent(1,value);
192 total->SetBinEntries(1, 1 );
196 if(basehist->GetBinContent(basehist->GetNbinsX()) !=0 ){
197 Efficiency( (
int)basehist->GetBinContent(basehist->GetNbinsX()-2), (
int)basehist->GetBinContent(basehist->GetNbinsX()), 0.683, value, errorl, errorh );
198 error= value-errorl>errorh-value ? value-errorl : errorh-
value;
202 total->SetBinContent(total->GetNbinsX(),
value);
203 total->SetBinEntries(total->GetNbinsX(),1);
204 total->SetBinError(total->GetNbinsX(),
sqrt(value*value+error*error));
205 total->GetXaxis()->SetBinLabel(total->GetNbinsX(),(
"total efficiency rel. " + shortReferenceName).c_str());
208 if(basehist->GetBinContent(1) !=0 ){
209 Efficiency( (
int)basehist->GetBinContent(basehist->GetNbinsX()-2), (
int)basehist->GetBinContent(1), 0.683,
value, errorl, errorh );
210 error= value-errorl > errorh-value ? value-errorl : errorh-
value;
214 total->SetBinContent(total->GetNbinsX()-1,
value);
215 total->SetBinError(total->GetNbinsX()-1,
sqrt(value*value+error*error));
216 total->SetBinEntries(total->GetNbinsX()-1,1);
217 total->GetXaxis()->SetBinLabel(total->GetNbinsX()-1,
"total efficiency rel. L1");
226 varNames.push_back(
"et");
227 varNames.push_back(
"eta");
236 filterName2= total->GetXaxis()->GetBinLabel(1);
239 for(std::vector<std::string>::iterator var = varNames.begin(); var != varNames.end() ; var++){
241 numName = ibooker.
pwd() +
"/" + filterName2 + *var + *postfix;
244 genName = ibooker.
pwd() +
"/reco_" + *var ;
246 genName = ibooker.
pwd() +
"/gen_" + *var ;
249 if(!
dividehistos(ibooker,igetter,numName,genName,
"efficiency_"+filterName2+
"_vs_"+*var +*postfix,*var,
"eff. of"+filterName2+
" vs "+*var +*postfix))
255 filterName = total->GetXaxis()->GetBinLabel(
filter);
256 filterName2= total->GetXaxis()->GetBinLabel(
filter+1);
259 for(std::vector<std::string>::iterator var = varNames.begin(); var != varNames.end() ; var++){
260 numName = ibooker.
pwd() +
"/" + filterName2 + *var + *postfix;
261 denomName = ibooker.
pwd() +
"/" + filterName + *var + *postfix;
265 if (
filter==total->GetNbinsX()-3 && temp.find(
"matched")!=std::string::npos) {
267 genName = ibooker.
pwd() +
"/reco_" + *var;
269 genName = ibooker.
pwd() +
"/gen_" + *var;
271 if(!
dividehistos(ibooker,igetter,numName,genName,
"final_eff_vs_"+*var,*var,
"Efficiency Compared to " + shortReferenceName +
" vs "+*var))
275 if(!
dividehistos(ibooker,igetter,numName,denomName,
"efficiency_"+filterName2+
"_vs_"+*var +*postfix,*var,
"efficiency_"+filterName2+
"_vs_"+*var + *postfix))
284 double totCont = total->GetBinContent(total->GetNbinsX());
285 double totErr = total->GetBinError(total->GetNbinsX());
286 if (trigName.find(
"Ele") != std::string::npos || trigName.find(
"_SC") != std::string::npos) {
287 allElePaths.back()->SetBinContent(elePos, totCont);
288 allElePaths.back()->SetBinEntries(elePos, 1);
289 allElePaths.back()->SetBinError(elePos,
sqrt(totCont * totCont + totErr * totErr));
290 allElePaths.back()->GetXaxis()->SetBinLabel(elePos, trigName.c_str());
293 else if (trigName.find(
"Photon") != std::string::npos) {
294 allPhotonPaths.back()->SetBinContent(photonPos, totCont);
295 allPhotonPaths.back()->SetBinEntries(photonPos, 1);
296 allPhotonPaths.back()->SetBinError(photonPos,
sqrt(totCont * totCont + totErr * totErr));
297 allPhotonPaths.back()->GetXaxis()->SetBinLabel(photonPos, trigName.c_str());
303 allElePaths.pop_back();
304 allPhotonPaths.pop_back();
307 allElePaths.back()->GetXaxis()->SetLabelSize(0.03);
308 allPhotonPaths.back()->GetXaxis()->SetLabelSize(0.03);
309 ibooker.
bookProfile(allEleHistoName, allElePaths.back())->setEfficiencyFlag();
310 ibooker.
bookProfile(allPhotonHistoName, allPhotonPaths.back())->setEfficiencyFlag();
327 edm::LogWarning(
"EmDQMPostProcessor") <<
"numerator histogram " << numName <<
" does not exist";
330 edm::LogWarning(
"EmDQMPostProcessor") <<
"denominator histogram " << denomName <<
" does not exist";
334 if(!num || !denom)
return 0;
336 MonitorElement* meOut = ibooker.
bookProfile(outName,titel,num->GetXaxis()->GetNbins(),num->GetXaxis()->GetXmin(),num->GetXaxis()->GetXmax(),0.,1.2);
339 out->GetXaxis()->SetTitle(label.c_str());
340 out->SetYTitle(
"Efficiency");
341 out->SetOption(
"PE");
342 out->SetLineColor(2);
343 out->SetLineWidth(2);
344 out->SetMarkerStyle(20);
345 out->SetMarkerSize(0.8);
346 out->SetStats(kFALSE);
347 for(
int i=1;
i<=num->GetNbinsX();
i++){
349 Efficiency( (
int)num->GetBinContent(
i), (int)denom->GetBinContent(
i), 0.683,
e, low, high );
350 double err = e-low>high-e ? e-low : high-
e;
352 out->SetBinContent(
i, e );
353 out->SetBinEntries(
i, 1 );
354 out->SetBinError(
i,
sqrt(e*e+err*err) );
366 if (monElement !=
NULL)
386 mode = passing / ((double) total);
394 lowerBound = TEfficiency::Wilson(total, passing, level,
false);
395 upperBound = TEfficiency::Wilson(total, passing, level,
true);
T getUntrackedParameter(std::string const &, T const &) const
TH1F * getHistogram(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const std::string &histoPath)
MonitorElement * bookProfile(Args &&...args)
MonitorElement * get(const std::string &path)
#define DEFINE_FWK_MODULE(type)
const std::string & pwd(void)
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
MonitorElement * book1D(Args &&...args)
TProfile * dividehistos(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const std::string &num, const std::string &denom, const std::string &out, const std::string &label, const std::string &titel="")
EmDQMPostProcessor(const edm::ParameterSet &pset)
bool dirExists(const std::string &path)
TH1F * getTH1F(void) const
std::vector< std::string > getSubdirs(void)
TProfile * getTProfile(void) const
void setEfficiencyFlag(void)
static void Efficiency(int passing, int total, double level, double &mode, double &lowerBound, double &upperBound)