Automatic histogram bins and fit

Dear Rooters,

there was a discussion going on in the PyRoot section about the behaviour of histograms that use automatic binning. It turned out, that the reported behaviour is not a python problem in particular.

The concern is the fit function that is created when a histogram is fitted. The histogram allows via e.g. FindObject() to access the fit function. However, when automatic binning is used, the fit function cannot be accessed and it is also not drawn into the canvas.

The problem is reproduced with this small script:

{ TH1D* h1 = new TH1D("h1","",10,0,0); //TH1D* h1 = new TH1D("h1","",10,0,1); //same fit result, different behaviour in drawing TRandom2* rg = new TRandom2(); for (int i=0;i<1000;i++){ h1->Fill(rg->Uniform(0,1)); } h1->Draw(); h1->Fit("pol0","0+"); TF1* f = (TF1*)h1->FindObject("pol0"); for (int i=0;i<100;i++){ cout<<"What is f? :"<<f->GetParameter(0)<<endl; } f->Draw("same"); }
The outcome of the script differs when the one or the other constructor of the TH1D is used (although it should probably not…)

Here you’ll find the full discussion up to now:




Indeed this is a deficiency. Can you please submit this as a bug report on savannah?


This problem is now fixed in the SVN trunk