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);
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 Sun May 24 2009 - 19:12:59 CEST
This archive was generated by hypermail 2.2.0 : Tue May 26 2009 - 17:50:04 CEST