376 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
377 <<
"Cannot find sub-directory " << startDir << endl;
389 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
390 <<
"No sim-ME '" << simMEName <<
"' found\n";
397 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
398 <<
"No reco-ME '" << recoMEName <<
"' found\n";
405 TH1* hSim = simME ->getTH1();
406 TH1* hReco = recoME->getTH1();
408 if ( !hSim || !hReco ) {
410 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
411 <<
"Cannot create TH1 from ME\n";
416 string efficDir = startDir;
417 string newEfficMEName = efficMEName;
419 if ( string::npos != (shiftPos = efficMEName.rfind(
'/')) ) {
420 efficDir +=
"/"+efficMEName.substr(0, shiftPos);
421 newEfficMEName.erase(0, shiftPos+1);
426 TProfile * efficHist = (hReco->GetXaxis()->GetXbins()->GetSize()==0) ?
427 new TProfile(newEfficMEName.c_str(), efficMETitle.c_str(),
428 hReco->GetXaxis()->GetNbins(),
429 hReco->GetXaxis()->GetXmin(),
430 hReco->GetXaxis()->GetXmax()) :
431 new TProfile(newEfficMEName.c_str(), efficMETitle.c_str(),
432 hReco->GetXaxis()->GetNbins(),
433 hReco->GetXaxis()->GetXbins()->GetArray());
434 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,27,0)
435 for (
int i=1;
i <= hReco->GetNbinsX();
i++) {
437 const double nReco = hReco->GetBinContent(
i);
438 const double nSim = hSim->GetBinContent(
i);
439 if(nSim > INT_MAX || nSim < INT_MIN || nReco > INT_MAX || nReco < INT_MIN)
441 LogError(
"DQMGenericClient") <<
"computeEfficiency() : "
442 <<
"Overflow: bin content either too large or too small to be casted to int";
446 if ( nSim == 0 || nReco > nSim )
continue;
447 const double effVal = nReco/nSim;
449 const double errLo = TEfficiency::ClopperPearson((
int)nSim,
452 const double errUp = TEfficiency::ClopperPearson((
int)nSim,
455 const double errVal = (effVal - errLo > errUp - effVal) ? effVal - errLo : errUp - effVal;
456 efficHist->SetBinContent(
i, effVal);
457 efficHist->SetBinEntries(
i, 1);
458 efficHist->SetBinError(
i,
sqrt(effVal * effVal + errVal * errVal));
461 for (
int i=1;
i <= hReco->GetNbinsX();
i++) {
463 const double nReco = hReco->GetBinContent(
i);
464 const double nSim = hSim->GetBinContent(
i);
465 if(nSim > INT_MAX || nSim < INT_MIN || nReco > INT_MAX || nReco < INT_MIN)
467 LogError(
"DQMGenericClient") <<
"computeEfficiency() : "
468 <<
"Overflow: bin content either too large or too small to be casted to int";
472 TGraphAsymmErrorsWrapper asymm;
473 std::pair<double, double> efficiencyWithError;
474 efficiencyWithError = asymm.efficiency((
int)nReco,
476 double effVal = efficiencyWithError.first;
477 double errVal = efficiencyWithError.second;
479 efficHist->SetBinContent(
i, effVal);
480 efficHist->SetBinEntries(
i, 1);
481 efficHist->SetBinError(
i,
sqrt(effVal * effVal + errVal * errVal));
491 TH1* efficHist = (TH1*)hSim->Clone(newEfficMEName.c_str());
492 efficHist->SetTitle(efficMETitle.c_str());
501 TClass * myHistClass = efficHist->IsA();
502 TString histClassName = myHistClass->GetName();
504 if (histClassName ==
"TH1F"){
505 efficME =
theDQM->
book1D(newEfficMEName, (TH1F*)efficHist);
506 }
else if (histClassName ==
"TH2F"){
507 efficME =
theDQM->
book2D(newEfficMEName, (TH2F*)efficHist);
508 }
else if (histClassName ==
"TH3F"){
509 efficME =
theDQM->
book3D(newEfficMEName, (TH3F*)efficHist);
514 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
515 <<
"Cannot book effic-ME from the DQM\n";
536 efficME->setEntries(simME->getEntries());
541 ME* globalEfficME =
theDQM->
get(efficDir+
"/globalEfficiencies");
542 if ( !globalEfficME ) globalEfficME =
theDQM->
book1D(
"globalEfficiencies",
"Global efficiencies", 1, 0, 1);
543 if ( !globalEfficME ) {
544 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
545 <<
"Cannot book globalEffic-ME from the DQM\n";
548 TH1F* hGlobalEffic = globalEfficME->getTH1F();
549 if ( !hGlobalEffic ) {
550 LogInfo(
"DQMGenericClient") <<
"computeEfficiency() : "
551 <<
"Cannot create TH1F from ME, globalEfficME\n";
555 const float nSimAll = hSim->GetEntries();
556 const float nRecoAll = hReco->GetEntries();
558 if (
type == 1 ) efficAll = nSimAll ? nRecoAll/nSimAll : 0;
559 else if (
type == 2 ) efficAll = nSimAll ? 1-nRecoAll/nSimAll : 0;
560 const float errorAll = nSimAll && efficAll < 1 ?
sqrt(efficAll*(1-efficAll)/nSimAll) : 0;
562 const int iBin = hGlobalEffic->Fill(newEfficMEName.c_str(), 0);
563 hGlobalEffic->SetBinContent(iBin, efficAll);
564 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)