I want to integrate over various z values, but plot as a function of lambda. I’m not sure how best to go about this. I have a range of z values i.e 0.2, 0.4, 0.6, 0.8 and 1.0. and Lambda is between 1.0001 and 1000.1. I’m not sure how best to approach this. Any advice would be appreciated.

you can create a TF1 and then use the TF1::Integrate method. An example integrating f = a + b*x for different values of a and b:

double func(double* x, double* p) {
double xx = x[0];
double a = p[0];
double b = p[1];
return a + b * xx;
}
void root_int() {
TF1 f("func", func, 0, 1, 2);
f.SetParameters(0, 1); // Set a = 0, b = 1
auto i = f.Integral(0, 1); // integrate between 0 and 1
std::cout << i << std::endl; // i = 0.5
f.SetParameters(0, 2); // Set a = 0, b = 2
i = f.Integral(0, 1); // integrate between 0 and 1
std::cout << i << std::endl; // i = 1
// etc...
}

I don’t quite follow this. I had initially thought of using a TF1 and figured integrating over z would be easy, but I wasn’t sure then if it was possible to plot as a function of lambda. I don’t see how this is achieved via your example? Unless I’m missing something…

Edit: I realised I wasn’t that clear. I want to take my function, and integrate over a particular z value and then plot that integrated function over the whole range of lambda (between 1.001 and 1000.1)

The easiest would probably be to save the values of lambda and the corresponding integral value in two vectors, and then make a plot using TGraph. I suppose you can also create a second function that computes the value of the integral, and plot that directly, e.g.:

double func(double* x, double* p) {
double xx = x[0];
double a = p[0];
double b = p[1];
return a + b * xx;
}
double integral(double* x, double* p) {
double b = x[0];
TF1 f("func", func, 0, 1, 2);
f.SetParameters(0, b); // Set a = 0, b = b
return f.Integral(0, 1);
}
void root_int() {
TF1* g = new TF1("integral", integral, 0, 5, 0);
g->Draw();
}

Isn’t a straight line correct in this case? If you integrate f = asin(x) you get F = -acos(x), so if you integrate between x1 and x2 you will get I = -a*(cos(x2) - cos(x1)). So if x1 and x2 are the same in all cases you will get a line with slope cos(x1) - cos(x2) as a function of a.