/** g++ $(root-config --cflags) $(root-config --libs) -o tefficiency.exe tefficiency.cc */ #include "TH1.h" #include "TGraphAsymmErrors.h" #include "TList.h" #include "TEfficiency.h" void tefficiency() { Double_t a_num=1000., a_den=2000.; Double_t b_num=100., b_den=200.; Double_t d_num=900., d_den=1000.; TEfficiency *effa = new TEfficiency("effa", "effa", 1, 0., 1.); TEfficiency *effb = new TEfficiency("effb", "effb", 1, 0., 1.); TEfficiency *effd = new TEfficiency("effd", "effd", 1, 0., 1.); effa->SetTotalEvents(1, a_den); effa->SetPassedEvents(1, a_num); effb->SetTotalEvents(1, b_den); effb->SetPassedEvents(1, b_num); effd->SetTotalEvents(1, d_den); effd->SetPassedEvents(1, d_num); TList *pList = new TList(); Double_t weights1[2] = {1., 1.} ; TGraphAsymmErrors *tg = NULL; Double_t x, y; pList->Add(effa); pList->Add(effd); tg = TEfficiency::Combine(pList, "", 2, weights1); tg->GetPoint(0,x,y); printf("effa (%f) (+) effd (%f) : %f\n", weights1[0], weights1[1], y); pList->Clear(); pList->Add(effb); pList->Add(effd); tg = TEfficiency::Combine(pList, "", 2, weights1); tg->GetPoint(0,x,y); printf("effb (%f) (+) effd (%f) : %f\n", weights1[0], weights1[1], y); pList->Clear(); // Reweight with total events weights1[0] = 1. * ((Double_t) effa->GetTotalHistogram()->GetBinContent(1)) / ((Double_t) effb->GetTotalHistogram()->GetBinContent(1)) ; pList->Add(effb); pList->Add(effd); tg = TEfficiency::Combine(pList, "", 2, weights1); tg->GetPoint(0,x,y); printf("effb (%f) (+) effd (%f) : %f (reweighted)\n", weights1[0], weights1[1], y); pList->Clear(); } int main(int argc, const char* argv[]) { tefficiency(); return 0; }