Dear Rooters,
I have a TH2D histo, filled with random numbers in range (0,1)
distributed flat in either of axes. The integral is ofcourse equal to
the number of entries filled. But if I divide this x-y plane into four
boxes (by cutting simultaneously on X and Y axis). Now I calculate
the integral for each box, and add those values. Contrary to my
expectations, the value does not turn out to be same as that
obtained by integrating full histo.
//==================
Full Integral: 10000
Box1: 2551 Box2: 2546 Box3: 5053 Box4: 2546
I am also appending my code below.
Anil Singh
//===========================================================
float BoxIntegral(TH2D* h1, float xmin, float xmax, float ymin, float ymax)
{
h1->GetXaxis()->SetRangeUser(xmin,xmax);
h1->GetYaxis()->SetRangeUser(ymin,ymax);
return h1->Integral();
}
void experiment(){
TH2D* h2=new TH2D("h2","test",100,0,1,100,0,1); TRandom3 r(0);
for (int i=0;i<10000;i++) {
float r1 = r.Rndm();
float r2 = r.Rndm();
h2->Fill(r1,r2);
}
float all=h2->Integral();
float x_cut=0.5;
float y_cut=0.5;
// Box1
float box1=BoxIntegral(h2,0,x_cut,0,y_cut);
//Box2
float box2=BoxIntegral(h2,0,x_cut,y_cut,1);
//Box3
float box3=BoxIntegral(h2,x_cut,1,0,y_cut);
//Box4
float box4=BoxIntegral(h2,x_cut,1,0,y_cut);
std::cout<<"Full Integral: "<<all<<endl; std::cout<<"Box1: "<<box1<<endl; std::cout<<"Box2: "<<box2<<endl; std::cout<<"Box3: "<<box3<<endl; std::cout<<"Box4: "<<box4<<endl; std::cout<<"Sum of all Boxes: "<<box4+box3+box2+box1<<endl;}
//========================================================
Received on Tue Jun 02 2009 - 15:22:51 CEST
This archive was generated by hypermail 2.2.0 : Tue Jun 02 2009 - 17:50:02 CEST