13 #include <TEfficiency.h>
44 shortReferenceName =
"RECO";
46 shortReferenceName =
"gen";
72 std::vector<std::string> postfixes;
73 postfixes.push_back(
"");
74 postfixes.push_back(
"_RECO_matched");
79 postfixes.push_back(
"_MC_matched");
81 std::vector<TProfile *> allElePaths;
86 for (std::vector<std::string>::iterator
dir = subdirectories.begin();
dir != subdirectories.end(); ++
dir) {
87 if (
dir->find(
"Ele") != std::string::npos ||
dir->find(
"_SC") != std::string::npos)
89 else if (
dir->find(
"Photon") != std::string::npos)
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(
109 new TProfile(allEleHistoName.c_str(), allEleHistoLabel.c_str(), nEle, 0., (double)nEle, 0., 1.2));
110 std::string allPhotonHistoName =
"EfficiencyByPath_Photon" + *postfix;
111 std::string allPhotonHistoLabel =
"Efficiency_for_each_validated_photon_path" + *postfix;
112 allPhotonPaths.push_back(
113 new TProfile(allPhotonHistoName.c_str(), allPhotonHistoLabel.c_str(), nPhoton, 0., (double)nPhoton, 0., 1.2));
115 for (std::vector<std::string>::iterator
dir = subdirectories.begin();
dir != subdirectories.end();
dir++) {
120 trigName = trigName.replace(trigName.rfind(
"_DQM"), 4,
"");
130 genName = ibooker.
pwd() +
"/reco_et";
132 genName = ibooker.
pwd() +
"/gen_et";
133 TH1F *genHist =
getHistogram(ibooker, igetter, genName);
134 if (genHist->GetEntries() == 0) {
136 <<
"Zero events were selected for path '" << trigName <<
"'. No efficiency plots will be generated.";
137 if (trigName.find(
"Ele") != std::string::npos || trigName.find(
"_SC") != std::string::npos) {
138 allElePaths.back()->GetXaxis()->SetBinLabel(elePos, trigName.c_str());
140 }
else if (trigName.find(
"Photon") != std::string::npos) {
141 allPhotonPaths.back()->GetXaxis()->SetBinLabel(photonPos, trigName.c_str());
149 TH1F *basehist =
getHistogram(ibooker, igetter, ibooker.
pwd() +
"/" + baseName);
150 if (basehist ==
nullptr) {
164 trigName +
"__" + histoName,
165 basehist->GetXaxis()->GetNbins(),
166 basehist->GetXaxis()->GetXmin(),
167 basehist->GetXaxis()->GetXmax(),
173 total->GetXaxis()->SetBinLabel(1, basehist->GetXaxis()->GetBinLabel(1));
182 double errorh = 0, errorl = 0,
error = 0;
184 for (
int bin = total->GetNbinsX() - 2;
bin > 1;
bin--) {
189 if (basehist->GetBinContent(
bin - 1) != 0) {
191 (
int)basehist->GetBinContent(
bin), (int)basehist->GetBinContent(
bin - 1), 0.683,
value, errorl, errorh);
192 error = value - errorl > errorh - value ? value - errorl : errorh -
value;
194 total->SetBinContent(
bin, value);
195 total->SetBinEntries(
bin, 1);
197 total->GetXaxis()->SetBinLabel(
bin, basehist->GetXaxis()->GetBinLabel(
bin));
201 if (basehist->GetBinContent(basehist->GetNbinsX()) != 0) {
203 (int)basehist->GetBinContent(basehist->GetNbinsX()),
208 error = value - errorl > errorh - value ? value - errorl : errorh -
value;
213 total->SetBinContent(1, value);
214 total->SetBinEntries(1, 1);
218 if (basehist->GetBinContent(basehist->GetNbinsX()) != 0) {
219 Efficiency((
int)basehist->GetBinContent(basehist->GetNbinsX() - 2),
220 (
int)basehist->GetBinContent(basehist->GetNbinsX()),
225 error = value - errorl > errorh - value ? value - errorl : errorh -
value;
230 total->SetBinContent(total->GetNbinsX(),
value);
231 total->SetBinEntries(total->GetNbinsX(), 1);
232 total->SetBinError(total->GetNbinsX(),
sqrt(value * value + error * error));
233 total->GetXaxis()->SetBinLabel(total->GetNbinsX(), (
"total efficiency rel. " + shortReferenceName).c_str());
236 if (basehist->GetBinContent(1) != 0) {
237 Efficiency((
int)basehist->GetBinContent(basehist->GetNbinsX() - 2),
238 (
int)basehist->GetBinContent(1),
243 error = value - errorl > errorh - value ? value - errorl : errorh -
value;
248 total->SetBinContent(total->GetNbinsX() - 1,
value);
249 total->SetBinError(total->GetNbinsX() - 1,
sqrt(value * value + error * error));
250 total->SetBinEntries(total->GetNbinsX() - 1, 1);
251 total->GetXaxis()->SetBinLabel(total->GetNbinsX() - 1,
"total efficiency rel. L1");
260 varNames.push_back(
"et");
261 varNames.push_back(
"eta");
264 varNames.push_back(
"phi");
266 varNames.push_back(
"etaphi");
274 filterName2 = total->GetXaxis()->GetBinLabel(1);
276 for (std::vector<std::string>::iterator
var = varNames.begin();
var != varNames.end();
var++) {
277 numName = ibooker.
pwd() +
"/" + filterName2 + *
var + *postfix;
280 genName = ibooker.
pwd() +
"/reco_" + *
var;
282 genName = ibooker.
pwd() +
"/gen_" + *
var;
284 if ((*var).find(
"etaphi") != std::string::npos) {
289 "efficiency_" + filterName2 +
"_vs_" + *
var + *postfix,
291 "eff. of" + filterName2 +
" vs " + *
var + *postfix))
297 "efficiency_" + filterName2 +
"_vs_" + *
var + *postfix,
299 "eff. of" + filterName2 +
" vs " + *
var + *postfix))
305 filterName = total->GetXaxis()->GetBinLabel(
filter);
306 filterName2 = total->GetXaxis()->GetBinLabel(
filter + 1);
309 for (std::vector<std::string>::iterator
var = varNames.begin();
var != varNames.end();
var++) {
310 numName = ibooker.
pwd() +
"/" + filterName2 + *
var + *postfix;
311 denomName = ibooker.
pwd() +
"/" + filterName + *
var + *postfix;
316 if (
filter == total->GetNbinsX() - 3 && temp.find(
"matched") != std::string::npos) {
318 genName = ibooker.
pwd() +
"/reco_" + *
var;
320 genName = ibooker.
pwd() +
"/gen_" + *
var;
322 if ((*var).find(
"etaphi") != std::string::npos) {
327 "final_eff_vs_" + *
var,
329 "Efficiency Compared to " + shortReferenceName +
" vs " + *
var))
335 "final_eff_vs_" + *
var,
337 "Efficiency Compared to " + shortReferenceName +
" vs " + *
var))
341 if ((*var).find(
"etaphi") != std::string::npos) {
346 "efficiency_" + filterName2 +
"_vs_" + *
var + *postfix,
348 "efficiency_" + filterName2 +
"_vs_" + *
var + *postfix))
354 "efficiency_" + filterName2 +
"_vs_" + *
var + *postfix,
356 "efficiency_" + filterName2 +
"_vs_" + *
var + *postfix))
365 double totCont = total->GetBinContent(total->GetNbinsX());
366 double totErr = total->GetBinError(total->GetNbinsX());
367 if (trigName.find(
"Ele") != std::string::npos || trigName.find(
"_SC") != std::string::npos) {
368 allElePaths.back()->SetBinContent(elePos, totCont);
369 allElePaths.back()->SetBinEntries(elePos, 1);
370 allElePaths.back()->SetBinError(elePos,
sqrt(totCont * totCont + totErr * totErr));
371 allElePaths.back()->GetXaxis()->SetBinLabel(elePos, trigName.c_str());
373 }
else if (trigName.find(
"Photon") != std::string::npos) {
374 allPhotonPaths.back()->SetBinContent(photonPos, totCont);
375 allPhotonPaths.back()->SetBinEntries(photonPos, 1);
376 allPhotonPaths.back()->SetBinError(photonPos,
sqrt(totCont * totCont + totErr * totErr));
377 allPhotonPaths.back()->GetXaxis()->SetBinLabel(photonPos, trigName.c_str());
383 allElePaths.pop_back();
384 allPhotonPaths.pop_back();
386 allElePaths.back()->GetXaxis()->SetLabelSize(0.03);
387 allPhotonPaths.back()->GetXaxis()->SetLabelSize(0.03);
388 ibooker.
bookProfile(allEleHistoName, allElePaths.back())->setEfficiencyFlag();
389 ibooker.
bookProfile(allPhotonHistoName, allPhotonPaths.back())->setEfficiencyFlag();
411 edm::LogWarning(
"EmDQMPostProcessor") <<
"numerator histogram " << numName <<
" does not exist";
413 if (denom ==
nullptr)
414 edm::LogWarning(
"EmDQMPostProcessor") <<
"denominator histogram " << denomName <<
" does not exist";
418 if (num ==
nullptr || denom ==
nullptr)
422 outName, titel, num->GetXaxis()->GetNbins(), num->GetXaxis()->GetXmin(), num->GetXaxis()->GetXmax(), 0., 1.2);
425 out->GetXaxis()->SetTitle(label.c_str());
426 out->SetYTitle(
"Efficiency");
427 out->SetOption(
"PE");
428 out->SetLineColor(2);
429 out->SetLineWidth(2);
430 out->SetMarkerStyle(20);
431 out->SetMarkerSize(0.8);
432 out->SetStats(kFALSE);
433 for (
int i = 1;
i <= num->GetNbinsX();
i++) {
435 Efficiency((
int)num->GetBinContent(
i), (int)denom->GetBinContent(
i), 0.683,
e, low, high);
436 double err = e - low > high - e ? e - low : high -
e;
438 out->SetBinContent(
i, e);
439 out->SetBinEntries(
i, 1);
440 out->SetBinError(
i,
sqrt(e * e + err * err));
458 edm::LogWarning(
"EmDQMPostProcessor") <<
"2D numerator histogram " << numName <<
" does not exist";
460 if (denom ==
nullptr)
461 edm::LogWarning(
"EmDQMPostProcessor") <<
"2D denominator histogram " << denomName <<
" does not exist";
464 if (num ==
nullptr || denom ==
nullptr)
469 num->GetXaxis()->GetNbins(),
470 num->GetXaxis()->GetXmin(),
471 num->GetXaxis()->GetXmax(),
472 num->GetYaxis()->GetNbins(),
473 num->GetYaxis()->GetXmin(),
474 num->GetYaxis()->GetXmax());
478 out->GetXaxis()->SetTitle(label.c_str());
479 out->SetYTitle(
"#phi");
480 out->SetXTitle(
"#eta");
481 out->SetOption(
"COLZ");
482 out->SetStats(kFALSE);
491 if (monElement !=
nullptr)
501 if (monElement !=
nullptr)
520 mode = passing / ((double)total);
530 lowerBound = TEfficiency::Wilson(total, passing, level,
false);
531 upperBound = TEfficiency::Wilson(total, passing, level,
true);
T getUntrackedParameter(std::string const &, T const &) const
virtual TH2F * getTH2F() const
TH2F * get2DHistogram(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const std::string &histoPath)
TH1F * getHistogram(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const std::string &histoPath)
virtual DQM_DEPRECATED std::vector< std::string > getSubdirs() const
#define DEFINE_FWK_MODULE(type)
virtual TH1F * getTH1F() const
virtual std::string pwd()
virtual bool dirExists(std::string const &path) const
constexpr char const * varNames[]
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
virtual MonitorElement * get(std::string const &fullpath) const
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="")
TH2F * dividehistos2D(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)
Log< level::Info, false > LogInfo
virtual TProfile * getTProfile() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
static void Efficiency(int passing, int total, double level, double &mode, double &lowerBound, double &upperBound)