Histogram parameter inside fit function

Dear all,
I’m interested in getting the bin width of the histogram I’m currently fitting in my fit function. The way I usually do this is:

// Find Bin Width 
  TVirtualFitter *fitter = TVirtualFitter::GetFitter();  //the current fitter 
  TH1 *hist = (TH1*)fitter->GetObjectFit(); //the histogram being fitted 
  Double_t  bin_width = hist->GetBinWidth(1); 

However, this does not always work, unfortunately. I’ve found a similar topic already discussed in this forum. Please see the attachment for the example macro which can be used to test. This macro works for ROOT version 5.17.00, but it fails in ROOT version 5.26.00, because the pointer to the TVirtualFitter is NULL.

Did I miss something in the latest ROOT developments?
Can you tell me which is the correct way to get the bin width of the histogram being fitted, in the fitting function?

Thank you in advance for your help,
Angela
Fits.C (1.42 KB)

Lorenzo will investigate this backward incompatibility problem. Meanwhile I suggest to change your code slightly as shown in the attachment.

Rene
Fits.C (1.51 KB)

Hi,

to be able to retrieve the histogram using the static instance of the TVirtualFitter you need just do add this simple line before fitting :

TVirtualFitter::Fitter(h); 

However, I would recommend you to build the fitting function passing directly the bin width, using an object instead of a free function, as it is done with the second TF1 in the attached example.

Best Regards

Lorenzo
Fits.C (2.18 KB)