[ROOTTALK] More efficient "FillRandom"

From: Gerco Onderwater (onderwat@nialas.npl.uiuc.edu)
Date: Sat May 15 1999 - 18:46:01 MEST


Hi All,

Recently I have been using the TH1::FillRandom method extensively, and
although very straightforward, it is also time consuming for generating
large numbers of random events. My solution to this was the following:

1) create a (normalized) function: TH1F* F
2) create an "experiment": TRandom2* EXP
3) for each bin in the histogram to be filled, evaluate the average
   number of events expected in that bin: MU = f->Eval(XBIN)*BINWIDTH (or
   area or volume). More sophisticated: calculate the integral of f within
   the bin.
4) multiply this number with the required number of events for the total
   histogram: MU *= TOTAL
5) calculate COUNTS = EXP->Poisson(MU) and store this in the histogram

In this way, you will get TOTAL+-sqrt(TOTAL) events in your histogram
(i.e. not exactly TOTAL!). The time needed to generate the histogram is
proportional to the number of bins of the histogram, not the number of
events. The statistics of the data is correct for all those cases where
the Poisson distribution is applicable. 

Perhaps this could be used to make Root even more powerful (and fast)? For
completeness, a Binomial random generator would be handy.

Anyhow, it saved me a lot of time,

-- Gerco

Dr. C.J.G. Onderwater
Nuclear Physics Laboratory
312 Loomis Laboratory of Physics
University of Illinois at Urbana-Champaign
1110 West Green Street
Urbana, IL 61801-3080     
Phone : (217) 244-7363
Fax   : (217) 333-1215  
E-mail: onderwat@uiuc.edu



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:33 MET