FindBin and automatic binning

Dear root,

The use of the function FindBin seems not to be well defined when the automatic binning is on. This is illustrated in the following:

root [0] TH1D *h = new TH1D(“h”,“h”,100,0,0)
root [1] for(int i=0;i<100;++i)h->Fill(gRandom->Gaus(0,1));
root [2] h->FindBin(0.5)
(Int_t)(101)
root [3] h->Draw()
TCanvas::MakeDefCanvas: created default TCanvas with name c1
root [4] h->FindBin(0.5)
(Int_t)(64)
root [5]

I would like to be able to use the FindBin function once I’m done filling the histogram. It seems that if I draw it, then I’d manage to. But is there another way? Is there a function that forces the binning to be calculated?

I’m using:


  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 5.16/00 27 June 2007 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      [root.cern.ch](http://root.cern.ch)            *
    
  •                                     *
    

Compiled on 1 July 2008 for linuxx8664gcc with thread support.

CINT/ROOT C/C++ Interpreter version 5.16.21, June 22, 2007
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.

Thanks,
Nicolas

You can stop the automatic rebinning by setting

h->ResetBit(TH1::kCanRebin);
Rene

Hi Rene,

it doesn’t seem to work:

root [0] TH1D *h = new TH1D(“h”,“h”,100,0,0)
root [1] for(int i=0;i<100;++i)h->Fill(gRandom->Gaus(0,1));
root [2] h->FindBin(0.5)
(Int_t)(101)
root [3] h->ResetBit(TH1::kCanRebin);
root [4] h->FindBin(0.5)
(Int_t)(101)
root [5]

Hi,

Call h->GetEntries();(or see it’s implementation for an alternative.

Cheers,
Philippe.