Multiple fits to TH1F in one routine and drawing in another

Hi

I am using root version v4-00-04 and I do multiple fits to a TH1F in one routine. Later on
I would like to draw the TH1F with the multiple fits. I think this is possible as the TH1F keeps the functions in a liist. When I do this I can only get the last function fitted.

The code below is a simple version on mine but exhibits the same behaviour - it complains about the existence of “formula” but not “fullformula”.

How can I retrieve both fits to draw them both in a later function?

Thanks,

Mark

[code]
void drawdouble()
{

    TH1F* hist = new TH1F("hist","Test hist",100,-5,5);
    hist->Sumw2();
    hist->FillRandom("gaus",1000);
    TF1* formula = new TF1("formula","[0]*exp(-0.5*((x-[1])/[2])**2)",-5,5);
    TF1* fullformula = new TF1("fullformula","[0]*exp(-[2]*((x-[1]))**2)",-5,5);
    hist->Fit("formula","R");
    hist->Fit("fullformula","R");
    Draw(hist);

}

void Draw(TH1F* hist)
{

    TCanvas* c = new TCanvas("c","C");
    ((TF1*)hist->GetFunction("formula"))->SetLineColor(kBlue);
    ((TF1*)hist->GetFunction("formulafull"))->SetLineColor(kRed);
    if (hist->GetFunction("formulafull")) ((TF1*)hist->GetFunction("formulafull"))->SetLineStyle(2);
    hist->Draw();
    if (hist->GetFunction("formula")) ((TF1*)hist->GetFunction("formula"))->Draw("same");
    if (hist->GetFunction("formulafull")) ((TF1*)hist->GetFunction("formulafull"))->Draw("same");
    c->Update();

}[/code]

Use fit option “+” to add a new function to the list of fitted functions.
In your case:
hist->Fit(“fullformula”,“R+”);
see documentation of TH1::Fit

I do not understand the second part of your message. Note that in one function you use “fullformula” and in the other "formulafull"
Send a short running script illustrating this problem.

Rene

  • did it - thanks.

I checked this page:

root.cern.ch/root/html/TH1.html#TH1:Fit

and it said

So I assumed that it was added automatically - hence no “+”. Sorry about that.

Mark