I am using a fit function that requires knowing the bin width. I find the bin width by using a procedure I found in the root doucmentaion:
// 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);
This works fine… except I am fitting many histograms with the same function, some with different bin widths, and displaying the results on the same canvas. After I fit a histogram with a new bin width, the functions on the previous histograms are updated, assuming the now wrong bin width. Is there any simple way to get around the problem other than passing the bin width as an additonal parameter to the fit?
If you fit via TH1::Fit, your problem should not happen.
TH1::Fit takes care of storing a copy of the original function in teh histogram list of functions and it draws this copy.
In case you draw the function yourself, you should call TF1::DrawCopy instead of Draw
Thanks for your reply. I am just using the TH1::Fit() member function. If I add a TH1::DrawCopy() after the fit, then all is well. But I still am not sure why that is necessary in this case. Perhaps I am doing something else wrong? Here is a simplified version of what I am trying to do (comment out the DrawCopy to see the problem).