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
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:
Generate a theta from its th1 histogram with GetRandom()
With this theta, go to the th2 (theta, phi) and get a phi (somehow…)
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.
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 ?
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 ?
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.