Plotting custom function within TF1

Hi, I’m trying to plot a function (Compton scattering) and I am trying to use TF1.
My function is defined in a header file

double E_1(double theta);

And in my main file I am trying to recall it like this:

    TApplication app("App",0,0);
    TF1 *g = new TF1("E(theta)","E_1(x)",0.,2*M_PI);
    TCanvas * c1 = new TCanvas("E_gamma","Energia Fotone uscente",600,600);

		c1->cd();

			g->SetTitle("E_gamma;Theta [rad];Energy [KeV]");

			g->Draw();

    app.Run();

Since my custom formula (for another case I have to implement) can be very long I would like to keep its definition outside of the TF1 declaration and the recall it there. Is there any way I can do it?

SOLVED:
The function needs the proper definition to be accepted by TF1:

double E_1(double *x,double *params){

    double theta = x[0];
    
    return 511/(2-cos(theta));
}

And then the recall within TF1:

TF1 *g = new TF1("E(x)",E_2,0.,M_PI,0);
//where there are 0 additional parameters in my formula

ROOT Version: 6.30/04
Platform: Linux Mint
Compiler: g++


I think you are looking for something like that.

I understand the example shown but here is what I struggle with:
My function E_1 accepts 1 parameter theta so from what I understand I need to adjust

TF1 *g = new TF1("E(theta)",E_1,0.,2*M_PI,1);
//where 1 is the number of parameters

What I don’t understand is why should I fix the parameters with g->SetParameters(..) ? (as shown in the example)
My intention is to let ROOT plot the function from theta=0 to theta=2*M_PI

SOLVED:
The function needs the proper definition to be accepted by TF1:

double E_1(double *x,double *params){

    double theta = x[0];
    
    return 511/(2-cos(theta));
}

And then the recall within TF1:

TF1 *g = new TF1("E(x)",E_2,0.,M_PI,0);
//where there are 0 additional parameters in my formula
1 Like