# Problem generating a distribution using TF1::GetRandom() Function

Hello, first time posting here.

I am using Geant4 and ROOT to simulate a beta - decay. I am trying to use an analytical version of the beta - spectrum for the K40 decay to draw the random energies according to the appropriate distribution for the electrons that will be propagated by Geant4. To draw these energies from the analytical formula of the distribution I am using TF1. I couldn’t manage to write the function on a separate module to just be called by Geant4 so I just hardcoded the expresion into the main.

The problem is that TF1::GetRandom() is not generating the appropriate behavior for the tail of the distribution, the distribution generated has a hard cutoff on the tail. This seems to be related with a divergence on zero of the distribution, but I am still not using the zero.

This is my script block that tries to achieve what I want:

``````  gRandom = new TRandom3(0);
gRandom->SetSeed(0);

TF1 *f1 = new TF1("f1","\
sqrt(x*x+2.*0.511*x)*(x+0.511)*(1.311-x)*(1.311-x)*\
(pow(1.-x/1.311,6)+\
7.*pow(1.-x/1.311,4)*pow(sqrt(x*x+2.*0.511*x)/1.311,2) +\
7.*pow(1.-x/1.311,2)*pow(sqrt(x*x+2.*0.511*x)/1.311,4) + pow(sqrt(x*x+2.*0.511*x)/1.311,6))*\
(2.*3.14159265359*20./137.*(x+0.511)/sqrt(x*x+2.*0.511*x))/\
(1.-exp(-2.*3.14159265359*20./137.*(x+0.511)/sqrt(x*x+2.*0.511*x)))*\
pow( (x+0.511)/0.511*(x+0.511)/0.511*(1.+4.*20./137.*20./137.)-1,\
sqrt(1.-20./137.*20./137.)-1.)", 0.001,1.311);//0.0000001, 1.311);
G4double r = f1->GetRandom();
``````

ROOT Version: 6.24
.Platform: CentOS Linux 7
Compiler: gcc 9.3.0

Welcome to the ROOT forum.

I am sure @moneta can help.

Thank you for the welcome.

I will then wait for his help.

`f1->SetNpx(1500); // f1->GetNpx() > f1->GetXmax() / f1->GetXmin()`

1 Like

That was exactly the problem there. Thanks a lot!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.