377 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
378 <<
"Cannot find sub-directory " << startDir << endl;
390 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
391 <<
"No sim-ME '" << simMEName <<
"' found\n";
398 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
399 <<
"No reco-ME '" << recoMEName <<
"' found\n";
406 TH1* hSim = simME ->getTH1();
407 TH1* hReco = recoME->getTH1();
409 if ( !hSim || !hReco ) {
411 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
412 <<
"Cannot create TH1 from ME\n";
417 string efficDir = startDir;
418 string newEfficMEName = efficMEName;
420 if ( string::npos != (shiftPos = efficMEName.rfind(
'/')) ) {
421 efficDir +=
"/"+efficMEName.substr(0, shiftPos);
422 newEfficMEName.erase(0, shiftPos+1);
427 TProfile * efficHist = (hReco->GetXaxis()->GetXbins()->GetSize()==0) ?
428 new TProfile(newEfficMEName.c_str(), efficMETitle.c_str(),
429 hReco->GetXaxis()->GetNbins(),
430 hReco->GetXaxis()->GetXmin(),
431 hReco->GetXaxis()->GetXmax()) :
432 new TProfile(newEfficMEName.c_str(), efficMETitle.c_str(),
433 hReco->GetXaxis()->GetNbins(),
434 hReco->GetXaxis()->GetXbins()->GetArray());
435 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,27,0)
436 for (
int i=1;
i <= hReco->GetNbinsX();
i++) {
437 const double nReco = hReco->GetBinContent(
i);
438 const double nSim = hSim->GetBinContent(
i);
440 if ( nSim == 0 || nReco > nSim )
continue;
441 const double effVal = nReco/nSim;
443 const double errLo = TEfficiency::ClopperPearson((
int)hSim->GetBinContent(
i),
444 (int)hReco->GetBinContent(
i),
446 const double errUp = TEfficiency::ClopperPearson((
int)hSim->GetBinContent(
i),
447 (int)hReco->GetBinContent(
i),
449 const double errVal = (effVal - errLo > errUp - effVal) ? effVal - errLo : errUp - effVal;
450 efficHist->SetBinContent(
i, effVal);
451 efficHist->SetBinEntries(
i, 1);
452 efficHist->SetBinError(
i,
sqrt(effVal * effVal + errVal * errVal));
455 for (
int i=1;
i <= hReco->GetNbinsX();
i++) {
456 TGraphAsymmErrorsWrapper asymm;
457 std::pair<double, double> efficiencyWithError;
458 efficiencyWithError = asymm.efficiency((
int)hReco->GetBinContent(
i),
459 (int)hSim->GetBinContent(
i));
460 double effVal = efficiencyWithError.first;
461 double errVal = efficiencyWithError.second;
462 if ((
int)hSim->GetBinContent(
i) > 0) {
463 efficHist->SetBinContent(
i, effVal);
464 efficHist->SetBinEntries(
i, 1);
465 efficHist->SetBinError(
i,
sqrt(effVal * effVal + errVal * errVal));
475 TH1* efficHist = (TH1*)hSim->Clone(newEfficMEName.c_str());
476 efficHist->SetTitle(efficMETitle.c_str());
485 TClass * myHistClass = efficHist->IsA();
486 TString histClassName = myHistClass->GetName();
488 if (histClassName ==
"TH1F"){
489 efficME =
theDQM->
book1D(newEfficMEName, (TH1F*)efficHist);
490 }
else if (histClassName ==
"TH2F"){
491 efficME =
theDQM->
book2D(newEfficMEName, (TH2F*)efficHist);
492 }
else if (histClassName ==
"TH3F"){
493 efficME =
theDQM->
book3D(newEfficMEName, (TH3F*)efficHist);
498 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
499 <<
"Cannot book effic-ME from the DQM\n";
520 efficME->setEntries(simME->getEntries());
525 ME* globalEfficME =
theDQM->
get(efficDir+
"/globalEfficiencies");
526 if ( !globalEfficME ) globalEfficME =
theDQM->
book1D(
"globalEfficiencies",
"Global efficiencies", 1, 0, 1);
527 if ( !globalEfficME ) {
528 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
529 <<
"Cannot book globalEffic-ME from the DQM\n";
532 TH1F* hGlobalEffic = globalEfficME->getTH1F();
533 if ( !hGlobalEffic ) {
534 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
535 <<
"Cannot create TH1F from ME, globalEfficME\n";
539 const float nSimAll = hSim->GetEntries();
540 const float nRecoAll = hReco->GetEntries();
542 if (
type == 1 ) efficAll = nSimAll ? nRecoAll/nSimAll : 0;
543 else if (
type == 2 ) efficAll = nSimAll ? 1-nRecoAll/nSimAll : 0;
544 const float errorAll = nSimAll && efficAll < 1 ?
sqrt(efficAll*(1-efficAll)/nSimAll) : 0;
546 const int iBin = hGlobalEffic->Fill(newEfficMEName.c_str(), 0);
547 hGlobalEffic->SetBinContent(iBin, efficAll);
548 hGlobalEffic->SetBinError(iBin, errorAll);
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
MonitorElement * book3D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ)
Book 3D histogram.
void cd(void)
go to top directory (ie. root)
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
bool dirExists(const std::string &path) const
true if directory exists
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
void setCurrentFolder(const std::string &fullpath)
void generic_eff(TH1 *denom, TH1 *numer, MonitorElement *efficiencyHist, const int type=1)