362 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
363 <<
"Cannot find sub-directory " << startDir << endl;
370 ME* simME = igetter.
get(startDir+
"/"+simMEName);
371 ME* recoME = igetter.
get(startDir+
"/"+recoMEName);
375 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
376 <<
"No sim-ME '" << simMEName <<
"' found\n";
383 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
384 <<
"No reco-ME '" << recoMEName <<
"' found\n";
391 TH1* hSim = simME ->getTH1();
392 TH1* hReco = recoME->getTH1();
394 if ( !hSim || !hReco ) {
396 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
397 <<
"Cannot create TH1 from ME\n";
402 string efficDir = startDir;
403 string newEfficMEName = efficMEName;
405 if ( string::npos != (shiftPos = efficMEName.rfind(
'/')) ) {
406 efficDir +=
"/"+efficMEName.substr(0, shiftPos);
407 newEfficMEName.erase(0, shiftPos+1);
412 TProfile * efficHist = (hReco->GetXaxis()->GetXbins()->GetSize()==0) ?
413 new TProfile(newEfficMEName.c_str(), efficMETitle.c_str(),
414 hReco->GetXaxis()->GetNbins(),
415 hReco->GetXaxis()->GetXmin(),
416 hReco->GetXaxis()->GetXmax()) :
417 new TProfile(newEfficMEName.c_str(), efficMETitle.c_str(),
418 hReco->GetXaxis()->GetNbins(),
419 hReco->GetXaxis()->GetXbins()->GetArray());
421 efficHist->GetXaxis()->SetTitle(hSim->GetXaxis()->GetTitle());
422 efficHist->GetYaxis()->SetTitle(hSim->GetYaxis()->GetTitle());
424 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,27,0)
425 for (
int i=1;
i <= hReco->GetNbinsX();
i++) {
427 const double nReco = hReco->GetBinContent(
i);
428 const double nSim = hSim->GetBinContent(
i);
429 if(nSim > INT_MAX || nSim < INT_MIN || nReco > INT_MAX || nReco < INT_MIN)
431 LogError(
"DQMGenericClient") <<
"computeEfficiency() : "
432 <<
"Overflow: bin content either too large or too small to be casted to int";
437 efficHist->GetXaxis()->SetBinLabel(
i, hSim->GetXaxis()->GetBinLabel(
i));
439 if ( nSim == 0 || nReco > nSim )
continue;
440 const double effVal = nReco/nSim;
442 const double errLo = TEfficiency::ClopperPearson((
int)nSim,
445 const double errUp = TEfficiency::ClopperPearson((
int)nSim,
448 const double errVal = (effVal - errLo > errUp - effVal) ? effVal - errLo : errUp - effVal;
449 efficHist->SetBinContent(
i, effVal);
450 efficHist->SetBinEntries(
i, 1);
451 efficHist->SetBinError(
i,
sqrt(effVal * effVal + errVal * errVal));
454 for (
int i=1;
i <= hReco->GetNbinsX();
i++) {
456 const double nReco = hReco->GetBinContent(
i);
457 const double nSim = hSim->GetBinContent(
i);
458 if(nSim > INT_MAX || nSim < INT_MIN || nReco > INT_MAX || nReco < INT_MIN)
460 LogError(
"DQMGenericClient") <<
"computeEfficiency() : "
461 <<
"Overflow: bin content either too large or too small to be casted to int";
465 TGraphAsymmErrorsWrapper asymm;
466 std::pair<double, double> efficiencyWithError;
467 efficiencyWithError = asymm.efficiency((
int)nReco,
469 double effVal = efficiencyWithError.first;
470 double errVal = efficiencyWithError.second;
472 efficHist->SetBinContent(
i, effVal);
473 efficHist->SetBinEntries(
i, 1);
474 efficHist->SetBinError(
i,
sqrt(effVal * effVal + errVal * errVal));
477 efficHist->GetXaxis()->SetBinLabel(
i, hSim->GetXaxis()->GetBinLabel(
i));
480 ibooker.
bookProfile(newEfficMEName.c_str(),efficHist);
486 TH1* efficHist = (TH1*)hSim->Clone(newEfficMEName.c_str());
487 efficHist->SetTitle(efficMETitle.c_str());
496 TClass * myHistClass = efficHist->IsA();
497 TString histClassName = myHistClass->GetName();
499 if (histClassName ==
"TH1F"){
500 efficME = ibooker.
book1D(newEfficMEName, (TH1F*)efficHist);
501 }
else if (histClassName ==
"TH2F"){
502 efficME = ibooker.
book2D(newEfficMEName, (TH2F*)efficHist);
503 }
else if (histClassName ==
"TH3F"){
504 efficME = ibooker.
book3D(newEfficMEName, (TH3F*)efficHist);
509 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
510 <<
"Cannot book effic-ME from the DQM\n";
531 efficME->setEntries(simME->getEntries());
536 ME* globalEfficME = igetter.
get(efficDir+
"/globalEfficiencies");
537 if ( !globalEfficME ) globalEfficME = ibooker.
book1D(
"globalEfficiencies",
"Global efficiencies", 1, 0, 1);
538 if ( !globalEfficME ) {
539 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
540 <<
"Cannot book globalEffic-ME from the DQM\n";
543 TH1F* hGlobalEffic = globalEfficME->getTH1F();
544 if ( !hGlobalEffic ) {
545 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
546 <<
"Cannot create TH1F from ME, globalEfficME\n";
550 const float nSimAll = hSim->GetEntries();
551 const float nRecoAll = hReco->GetEntries();
553 if (
type == 1 ) efficAll = nSimAll ? nRecoAll/nSimAll : 0;
554 else if (
type == 2 ) efficAll = nSimAll ? 1-nRecoAll/nSimAll : 0;
555 const float errorAll = nSimAll && efficAll < 1 ?
sqrt(efficAll*(1-efficAll)/nSimAll) : 0;
557 const int iBin = hGlobalEffic->Fill(newEfficMEName.c_str(), 0);
558 hGlobalEffic->SetBinContent(iBin, efficAll);
559 hGlobalEffic->SetBinError(iBin, errorAll);
MonitorElement * bookProfile(Args &&...args)
MonitorElement * get(const std::string &path)
MonitorElement * book1D(Args &&...args)
bool dirExists(const std::string &path)
void setCurrentFolder(const std::string &fullpath)
MonitorElement * book2D(Args &&...args)
MonitorElement * book3D(Args &&...args)
void generic_eff(TH1 *denom, TH1 *numer, MonitorElement *efficiencyHist, const int type=1)