Im writing a small simulation which requires me to generate a random number from a TF1. The problem is each time I call the function I need to update a parameter. This seems to be very slow. Is there a quicker way around this?
TF1 *f = ("f",func,0, 1.5, 1);
for(int i=0; i<count, ++i)
output = f->GetRandom();
this can be very inefficient (the integral is each time recalculated) and it’s hard to understand the context in which you are calling the code you pasted.
Could you elaborate a bit?
Essentially I’m modelling compton scattering of electrons. So for each incoming photon, each with a different energy, I need to update the function that gives me the outgoing electron angle. With millions of photons in each run this takes a long time to generate the electron angles.
thanks for the additional info.
Recalculating the integral for every change of parameter is expensive.
I see two solutions: either precalculate all of the integrals, one per value of the parameter or express the integral analytically and draw numbers directly from it.