Title of TF1

Hello,
I am unable to get the title of my TF1 graph to show up. It comes up as “myfunction.” Here is my source code…

#include <iostream>
using namespace std;

void main()
{
  TCanvas *c1 = new TCanvas("c1", "br");
    TF1 *f1 = new TF1("Differential Cross Section of Compton Scattering for 5MeV Photons",myfunction,0,10,3);
    f1->SetParameters(0.0794, 9.769, 5.0);
    f1->SetParNames("electron radius squared","Incident Photon Energy/Rest Mass Energy of Electron", "Incident Photon Energy");
    gPad -> SetLogy();
    f1->Draw();
    f1->GetHistogram()->GetYaxis()->SetTitle("d#sigma/dE_{k}(barns/MeV)");
    f1->GetHistogram()->GetXaxis()->SetTitle("Kinetic Energy of Ejected Electron = E_{k}(MeV)");
    c1->Modified();

}
Double_t myfunction(Double_t *x, Double_t *par)
{
    const Double_t pi = TMath::Pi(); 
    Float_t y = x[0];
    Double_t f = (pi*par[0])/(par[1]*par[2])*(2-(2*y)/(par[1]*(par[2]-y))+(y*y)/((par[1]*par[1])*(par[2]-y)*(par[2]-y))+(y*y/(par[2]*(par[2]-y))));
  
    return f;
}

The string that you put as the first argument in the TF1 constructor is the function “name”, not the function “title”.

The title can be set using TF1::SetTitle: http://root.cern.ch/root/html/TF1.html#TF1:SetTitle and will show up on the canvas when you draw the function (provided the correct styles are set).

The name is a different string which ROOT uses internally to identify the function object and provide persistence, it’s what you see as a key if you save an object in a TFile, and what you use when you do gROOT->FindObject(“foo”).

I couldn’t easily find any document pages which explain this distinction.

Jfcaron thank you so much! That fixed it : )

TF1 *f1 = new TF1(“f1”,myfunction,0,10,3);
f1->SetTitle(“Differential Cross Section of Compton Scattering for 5MeV Photons”);