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++){
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));
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 ==
nullptr)
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){
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");
231 varNames.push_back(
"etaphi");
239 filterName2= total->GetXaxis()->GetBinLabel(1);
241 for(std::vector<std::string>::iterator
var = varNames.begin();
var != varNames.end() ;
var++){
243 numName = ibooker.
pwd() +
"/" + filterName2 + *
var + *
postfix;
246 genName = ibooker.
pwd() +
"/reco_" + *
var ;
248 genName = ibooker.
pwd() +
"/gen_" + *
var ;
250 if((*var).find(
"etaphi") != std::string::npos)
252 if(!
dividehistos2D(ibooker,igetter,numName,genName,
"efficiency_"+filterName2+
"_vs_"+*
var +*postfix,*
var,
"eff. of"+filterName2+
" vs "+*
var +*postfix))
break;
253 }
else if(!
dividehistos(ibooker,igetter,numName,genName,
"efficiency_"+filterName2+
"_vs_"+*
var +*postfix,*
var,
"eff. of"+filterName2+
" vs "+*
var +*postfix))
259 filterName = total->GetXaxis()->GetBinLabel(
filter);
260 filterName2= total->GetXaxis()->GetBinLabel(
filter+1);
263 for(std::vector<std::string>::iterator
var = varNames.begin();
var != varNames.end() ;
var++){
264 numName = ibooker.
pwd() +
"/" + filterName2 + *
var + *
postfix;
265 denomName = ibooker.
pwd() +
"/" + filterName + *
var + *
postfix;
269 if (
filter==total->GetNbinsX()-3 && temp.find(
"matched")!=std::string::npos) {
271 genName = ibooker.
pwd() +
"/reco_" + *
var;
273 genName = ibooker.
pwd() +
"/gen_" + *
var;
275 if((*var).find(
"etaphi") != std::string::npos)
277 if(!
dividehistos2D(ibooker,igetter,numName,genName,
"final_eff_vs_"+*
var,*
var,
"Efficiency Compared to " + shortReferenceName +
" vs "+*
var))
break;
278 }
else if(!
dividehistos(ibooker,igetter,numName,genName,
"final_eff_vs_"+*
var,*
var,
"Efficiency Compared to " + shortReferenceName +
" vs "+*
var))
282 if((*var).find(
"etaphi") != std::string::npos)
284 if(!
dividehistos2D(ibooker,igetter,numName,denomName,
"efficiency_"+filterName2+
"_vs_"+*
var +*postfix,*
var,
"efficiency_"+filterName2+
"_vs_"+*
var + *postfix))
break;
285 }
else if(!
dividehistos(ibooker,igetter,numName,denomName,
"efficiency_"+filterName2+
"_vs_"+*
var +*postfix,*
var,
"efficiency_"+filterName2+
"_vs_"+*
var + *postfix))
294 double totCont = total->GetBinContent(total->GetNbinsX());
295 double totErr = total->GetBinError(total->GetNbinsX());
296 if (trigName.find(
"Ele") != std::string::npos || trigName.find(
"_SC") != std::string::npos) {
297 allElePaths.back()->SetBinContent(elePos, totCont);
298 allElePaths.back()->SetBinEntries(elePos, 1);
299 allElePaths.back()->SetBinError(elePos,
sqrt(totCont * totCont + totErr * totErr));
300 allElePaths.back()->GetXaxis()->SetBinLabel(elePos, trigName.c_str());
303 else if (trigName.find(
"Photon") != std::string::npos) {
304 allPhotonPaths.back()->SetBinContent(photonPos, totCont);
305 allPhotonPaths.back()->SetBinEntries(photonPos, 1);
306 allPhotonPaths.back()->SetBinError(photonPos,
sqrt(totCont * totCont + totErr * totErr));
307 allPhotonPaths.back()->GetXaxis()->SetBinLabel(photonPos, trigName.c_str());
313 allElePaths.pop_back();
314 allPhotonPaths.pop_back();
317 allElePaths.back()->GetXaxis()->SetLabelSize(0.03);
318 allPhotonPaths.back()->GetXaxis()->SetLabelSize(0.03);
319 ibooker.
bookProfile(allEleHistoName, allElePaths.back())->setEfficiencyFlag();
320 ibooker.
bookProfile(allPhotonHistoName, allPhotonPaths.back())->setEfficiencyFlag();
337 edm::LogWarning(
"EmDQMPostProcessor") <<
"numerator histogram " << numName <<
" does not exist";
339 if (denom ==
nullptr)
340 edm::LogWarning(
"EmDQMPostProcessor") <<
"denominator histogram " << denomName <<
" does not exist";
344 if(num ==
nullptr || denom ==
nullptr)
return nullptr;
346 MonitorElement* meOut = ibooker.
bookProfile(outName,titel,num->GetXaxis()->GetNbins(),num->GetXaxis()->GetXmin(),num->GetXaxis()->GetXmax(),0.,1.2);
349 out->GetXaxis()->SetTitle(label.c_str());
350 out->SetYTitle(
"Efficiency");
351 out->SetOption(
"PE");
352 out->SetLineColor(2);
353 out->SetLineWidth(2);
354 out->SetMarkerStyle(20);
355 out->SetMarkerSize(0.8);
356 out->SetStats(kFALSE);
357 for(
int i=1;
i<=num->GetNbinsX();
i++){
359 Efficiency( (
int)num->GetBinContent(
i), (
int)denom->GetBinContent(
i), 0.683,
e, low, high );
360 double err = e-low>high-e ? e-low : high-
e;
362 out->SetBinContent(
i, e );
363 out->SetBinEntries(
i, 1 );
364 out->SetBinError(
i,
sqrt(e*e+err*err) );
376 edm::LogWarning(
"EmDQMPostProcessor") <<
"2D numerator histogram " << numName <<
" does not exist";
378 if (denom ==
nullptr)
379 edm::LogWarning(
"EmDQMPostProcessor") <<
"2D denominator histogram " << denomName <<
" does not exist";
382 if(num ==
nullptr || denom ==
nullptr)
return nullptr;
384 MonitorElement* meOut = ibooker.
book2D(outName,titel,num->GetXaxis()->GetNbins(),num->GetXaxis()->GetXmin(),num->GetXaxis()->GetXmax(),num->GetYaxis()->GetNbins(),num->GetYaxis()->GetXmin(),num->GetYaxis()->GetXmax());
388 out->GetXaxis()->SetTitle(label.c_str());
389 out->SetYTitle(
"#phi");
390 out->SetXTitle(
"#eta");
391 out->SetOption(
"COLZ");
392 out->SetStats(kFALSE);
399 if (monElement !=
nullptr)
407 if (monElement !=
nullptr)
427 mode = passing / ((double) total);
435 lowerBound = TEfficiency::Wilson(total, passing, level,
false);
436 upperBound = TEfficiency::Wilson(total, passing, level,
true);
T getUntrackedParameter(std::string const &, T const &) 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)
MonitorElement * bookProfile(Args &&...args)
MonitorElement * get(const std::string &path)
#define DEFINE_FWK_MODULE(type)
const std::string & pwd(void)
static void pop(std::vector< T > &vec, unsigned int index)
constexpr char const * varNames[]
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="")
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)
bin
set the eta bin as selection string.
bool dirExists(const std::string &path)
MonitorElement * book2D(Args &&...args)
TH1F * getTH1F(void) const
std::vector< std::string > getSubdirs(void)
TProfile * getTProfile(void) const
void setEfficiencyFlag(void)
TH2F * getTH2F(void) const
static void Efficiency(int passing, int total, double level, double &mode, double &lowerBound, double &upperBound)