2D TEfficiency

Dear ROOTers,

I am trying to use the TEfficiency class (ROOT 5.28.00) to parametrize a trigger efficiency as a function of two variables

Unfortunately there is no TEfficiency TH2 constructor such as

TEfficiency(const TH2& passed, const TH2& total)

but I managed to use

TEfficiency(const char* name, const char* title, Int_t nbinsx, Double_t  xlow, Double_t  xup, Int_t  nbinsy, Double_t  ylow, Double_t  yup)

Suppose hNL1 is the TH2D histogram corresponding to the “passed” events and hDL1 to the “total” ones, I tried the following:

TEfficiency *tEL1 = new TEfficiency("tEL1", "", hNL1->GetNbinsX(), hNL1->GetXaxis()->GetXmin(), hNL1->GetXaxis()->GetXmax(), hNL1->GetNbinsY(), hNL1->GetYaxis()->GetXmin(), hNL1->GetYaxis()->GetXmax()); for (Int_t i = 1; i <= hNL1->GetNbinsX(); ++i) { for (Int_t j = 1; j <= hNL1->GetNbinsY(); ++j) { tEL1->GetPassedHistogram()->SetBinContent(i, j, hNL1->GetBinContent(i, j)); tEL1->GetTotalHistogram()->SetBinContent(i, j, hDL1->GetBinContent(i, j)); } }

While using CINT everything is fine, if I try to compile this lines I get the following error

which as far as I can understand is due to the fact that GetPassedHistogram() and GetTotalHistogram() return a const object that I cannot modify

My first question is how can I solve this problem? How can I easily create a 2D TEfficiency starting from two TH2D histos?

Next, why there is no 2D TEfficiency constructor?
Moreover, even if the TEfficiency class as it is now can be used to create 2D and 3D objects, why there is only a GetEfficiency(Int_t bin) method and not GetEfficiency(Int_t binx, Int_t biny) and GetEfficiency(Int_t binx, Int_t biny, Int_t binz) ones as well? I know I can use GetBin(Int_t binx, Int_t biny, Int_t binz) to retrieve the global bin number and this is working, but it would be handier

Last question, as I mentioned earlier when using CINT the lines I wrote are working but when I draw the 2D TEfficiency object as tEL1->Draw(“colz”) X and Y axis doesn’t correspond to the created ones according to hNL1 but both ranges goes from 0 to 1
How is that possible?

Thanks,
s.

Hi,

the constructor

can be used for 1D,2D and 3D histograms, since all of them are derived from TH1.

The method TH1::GetPassedHistogram returns a const pointer to TH1 and therefore you should not then call SetBinContent on the returned histogram.

The method GetEfficiency(Int_t bin) works also for 2D and 3D histograms, you need to pass the global bin number.

Concerning the TEfficiency::Draw, there is a bug in the case of the 2D histograms, I will fix it as soon as possible.
Thanks for finding this problem.

Cheers

Lorenzo

The fix for TEfficiency::Draw in the case of 2D histogram is committed in the trunk
see root.cern.ch/viewvc?view=rev&revision=37701

Lorenzo