Alternative to TH3 GetRandom3

Dear ROOT users,

I would like to ask a question about the GetRandom3 method. The situation is as follows: I would like to generate particles with angles theta, phi and energy E. The direction and energy of the particles come from a text file, but I read the file and store the quantities into several histograms
Th1 theta
Th1 phi
Th2 thetaPhi
Th2 thetaEnergy
Th1 energy
If I use the method “GetRandom” in the TH1 to generate a variable according to its distribution it works fast and nice. The problem is that there are correlations between the variables, and I thought that a GetRandom3 from the 3d histogram (theta, phi, E) would provide a better generation of events…but it is quite slow and the computational time is very high. What I was thinking is that maybe this could be possible:

  1. Generate a theta from its th1 histogram with GetRandom()
  2. With this theta, go to the th2 (theta, phi) and get a phi (somehow…)
  3. With this theta go to the th2 (theta, energy) and get an Energy.

Maybe this could make the trick. The question is how could I do 2 and 3. Should I project, work with profiles…?
Thank you very much for your time.

@moneta Perhaps you can help?

Hi,

Is it really so slow TH3::GetRandom3() ? I guess the first number is a bit slow because it requires some initial calculations (integral computation). Afterwards should be faster. How many bins your historgram is having ?

Lorenzo

Hello, Lorenzo. Thank you for your reply.
The TH3 histogram has 200, 90, and 360 bins (E, theta, phi)

Jose

Hi,

I have checked TH3::GetRandom3 and for an 3D histogram with many bins as yours, I see that the generation is still fast, 1 million events in less than a second.
Why are you saying that it is slow ? Maybe you are having some memory problem with your computer ?

Lorenzo

Hello,

probably you are right and there is a problem with the memory management in our machines. I also tried in a completely different computer and the computational time was clearly shorter…not less than a second, but extremely fast in comparison.
Thank you again, I will keep on testing it.

Jose

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