Re: Integrating: TH2D

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Tue, 26 May 2009 14:55:09 +0200


I do not understand your mail. I was talking about the Unix function "rand", not about TRandom.
The default generator in ROOT is TRandom3. The global variable gRandom points to a TRandom3 object. You can check it with:

    root > gRandom->ClassName()
You can change it to whatever you want, eg   gRandom = new TRandom2
The fumctions like TH1::FillRandom, TF1::GetRandom use gRandom internally.

Rene Brun

Alessio Mangiarotti wrote:
> Dear Rene and Anil,
>
> I am sorry to break into this discussion, as it seems that TRandom is not
> well behaving, but then I have a question. What about Gaussian random
> numbers and random numbers drawn from an histogram? As far as I
> understand they always use TRandom, or is there a way to select TRandom3?
>
> Thank you,
> Alessio Mangiarotti
>
>
>
>> rand() is known to be a bad random number generator.
>> You are selecting 11 bins in x and y. In your example I would expect
>> 1210 entries in the selected range +- sqrt(1210), ie 35 entries.
>> If you use the TRandom3 generator and run many times you should see the
>> expected behavior
>>
>> Rene Brun
>>
>> void rand() {
>> TH2F *h2 = new TH2F("h2","test",100,0,1,100,0,1);
>> TRandom3 r(0);
>> for (Int_t i=0;i<100000;i++) {
>> r1 = r.Rndm();
>> r2 = r.Rndm();
>> h2->Fill(r1,r2);
>> }
>> float num1 = h2->Integral(10,20,10,20);
>> float num2 = h2->Integral(20,30,20,30);
>> cout<<"num1: "<<num1<<endl;
>> cout<<"num2: "<<num2<<endl;
>> }
>>
>> Anil Singh wrote:
>>
>>> Dear Rooters,
>>>
>>> I am creating a TH2D histogram and filling it using
>>> random numbers, uniformly distributed in range 0, 1
>>> (100-bins).
>>>
>>> =================================
>>> for(int i=0; i!=100000; i++){
>>> float x = rand()/(float)RAND_MAX;
>>> float y = rand()/(float)RAND_MAX;
>>> h2->Fill(x,y);
>>> }
>>> ======================================
>>>
>>> Well, now I expect that, number of entries enclosed
>>> in any "box" created on X-Y plane of this histogram
>>> should be proportional to the area of the box
>>> (Please correct me if I am wrong). So in that spirit,
>>> I did following:
>>> ===============================
>>> float num1 = h2->Integral(10,20,10,20);
>>> float num2 = h2->Integral(20,30,20,30);
>>> cout<<"num1: "<<num1<<endl;
>>> cout<<"num2: "<<num2<<endl;
>>> =================================
>>>
>>> I expected the numbers to be very similar if
>>> not exactly same. Here's what I get:
>>>
>>> num1: 1152
>>> num2: 1258
>>>
>>> We see there is a discrepency of almost 100 counts....
>>> Can this be explained out ? Or am I messing up
>>> somewhere ?
>>>
>>> Anil
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>
>
>
Received on Tue May 26 2009 - 14:55:19 CEST

This archive was generated by hypermail 2.2.0 : Tue May 26 2009 - 17:50:04 CEST