Saving a fit at a root file

Dear Experts,

I have a code comprised of several classes and functions, one of which is responsible for fitting. This function will take as an argument a vector and the kind of fit and will return two values of interest with itheir uncertainties (typically sigma and mean or MPV and sigma), the goodness (Ndf/chi^2) and the corresponding TH1D. The definition of the function is as follows:

int LGADBase::IterativeFit(std::vector<double> *w, std::pair<double, double> &gmean, std::pair<double, double> &gsigma, TH1D* &FitHist, double &minchi2, std::string methode, std::pair<int, int> points)

with the first argument being a pointer tot he vector to fit, then pointers to the variables that will receive the mean and the sigma, a pointer to the fit, a pointer to the goodness variable, the methode argument and at the end a start and stop index for which elements to use from the supplied vector.

The function works and returns all the information but I only get the TH1D binned histogram without the fit info, although while fitting I do specify the ā€œSā€ option to save the fit. Is there a way to have the histogram with the traced fit passed over? Is this a result of me passing a pointer to an object that is just an empty TH1D and not one that can accept fit values?

Thanks a lot for the help!!

Vagelis


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


@moneta Can you help?

Hi,

If you are fitting your histogram by calling TH1::Fit, by default the fit function should be saved together with the histogram in a file. Note however if the fit function is created from C++ code, what is saved is only the vector of points representing a function, it can be used only to display the results but not to re-fit afterwards the histogram.

If you still having issues , I would need to see your code
Cheers

Lorenzo