Excluding Underflow/Overflow Bins in Projections

If I understand correctly then setting the range of an axis to 1->nbins causes the range to reset so that underflow and overflow bins are included. Calling TAxis::SetBit(TAxis::kAxisRange) after doing this is then supposed to exclude the underflow and overflow bins (as described in this post: TAxis::SetRange and TH2::Projection). When I run the following

{ TH3D *h3 = new TH3D("h3",";x;y;z", 10, 0, 10, 10, 0, 10, 10, 0, 10); h3->Fill(.1, 3, 3); h3->Fill(.1, 4.5, 3); h3->Fill(.1, 5.5, 3); h3->Fill(.1, 24, 3); h3->GetYaxis()->SetRange(1, 10); h3->GetYaxis()->SetBit(TAxis::kAxisRange); TH1 *h = h3->Project3D("x"); h->Draw(); }
the drawn histogram is empty but I would expect it to have 3 entries in the first bin. Removing the SetBit line results in 4 entries so the underflow and overflow are being included in that case. This is in ROOT 5.22/00. Do I have to do something differently to exclude the overflow and underflow bins?

PS - In the documentation for TH3::Project3D it says

and then stops. Is the example here is supposed to include another line demonstrating how to set the axis bit?

This weirdness was fixed in v5-34-04 and later. If you do not want to work around this yourself updating is the best idea.

Unfortunately, I don’t have a choice about which version I use because I rely on a large code base that won’t compile with anything newer. If anybody finds this thread in the future and is also stuck on an old version then a workaround is:

{ TH3D *h3 = new TH3D("h3",";x;y;z", 10, 0, 10, 10, 0, 10, 10, 0, 10); h3->Fill(.1, 3, 3); h3->Fill(.1, 4.5, 3); h3->Fill(.1, 5.5, 3); h3->Fill(.1, 24, 3); h3->GetYaxis()->SetRange(1, 10); TH1 *h = h3->Project3D("xnofnuf"); h->Draw(); }

You can’t select which axes you want to exclude the overflow and underflow for but it worked for my purposes.

Thanks for the response,
foobie