Recalling fit parameters

Hi

I am trying to recall the fitted parameters from a previously fitted histogram saved to a rootfile.

The original histogram is fitted using myfunc so it looks like this

                       //...
                        hist->Fit("myfunc","R+");
                       TFile myfile("myrootfile.root","RECREATE");
                       hist->Write();
                       //...

So now in my new script I am trying to do a ratio of two fitted histograms and have the ratio of their functions, but right now I am having to put in the parameters by hand and I am wondering if I can call the parameters from the rootfile like

                  TFile *Z = new TFile("myrootfile.root");

                  TH1F *Pseudhist = Z->Get("hist");

                  TF1 *Pseudfunc = Pseudhist->GetFunction("myfunc");

                  double_t a1 =  Pseudfunc->GetParameter(0)
                  //... and so on

I’ve tried this along with other combinations and I can’t seem to get this to work. Is it possible? Thanks as always

-Matt

Hi,

what you are describing in your post, it should work to recall the fit parameters

TFile *Z = new TFile("myrootfile.root"); 
TH1F *Pseudhist = Z->Get("hist"); 
if (!Pseudhist) return -1;
TF1 *Pseudfunc = Pseudhist->GetFunction("myfunc"); 
if (!Pseudfunc) return -2; 
double_t a1 = Pseudfunc->GetParameter(0) 

if it does not please send me a running script showing the problem,
Regards

Lorenzo

Hi Lorenzo,

Here is a running script, I get an illegal pointer error when I try to recall the function.
If you just put all files in same directory, should run.

Thanks

-Matt
NewFit4lepMassNCStackzz.root (10.6 KB)
4lepMassNCzz.root (5.96 KB)
4lepMassNCNoPhzz.root (5.86 KB)
4lepMassPseudozz.root (5.74 KB)
4lepMassPseudoNoPhzz.root (5.6 KB)
RatioEx.C (3.02 KB)

You forgot to add some of the file referenced in your script :

root [0] .x RatioEx.C 
Error in <TFile::TFile>: file NewFit4lepMassNCzz.root does not exist
Error in <TFile::TFile>: file NewFit4lepMassPseudozz.root does not exist

Lorenzo

Sorry about that, here ya go…
NewFit4lepMassPseudozz.root (10.4 KB)
NewFit4lepMassNCzz.root (10.6 KB)

Your script had lots of error.
You are also retrieving the histogram and the functions from the file with the wrong names. Here attached is the script working, but please send the next time a RUNNING script

Regards

Lorenzo
RatioEx.C (3.03 KB)

Sorry Lorenzo, I double checked the script I sent and it wasn’t the final version. Very sorry about that. Thanks for all the help!