Dear Rooters,
I read in the reference manual about the binning of 2D historgrams,
"In case of 2-D or 3-D histograms, a "global bin" number is defined. For example, assuming a 3-D histogram with binx,biny,binz, the function Int_t <ListOfTypes.html#Int_t> gbin = h->GetBin <#TH1:GetBin>(binx,biny,binz); returns a global/linearized gbin number. This global gbin is useful to access the bin content/error information independently of the dimension. "
but I've a problem to understand what's happening with TProfile2D..
I want to fill the TProfile2D, plot it and then print out what is contained in each bin.
Please find attached a simple script intending to do that.
Why "i", the bin number, does not go from 1 to 4 (=nbinsx*nbinsy) ? Why only one bin results with a content > 0 while 2 are plotted?
Maybe I'm giving wrong arguments to:
h2->GetBin(x,y);
Is it possible to:
-retrieve the total number of bins
-scan with some index over all the bins and get bincenter (in 2D), bins
contents, bin entries etc...
Thanks a lot,
Federico
{
gROOT->Reset();
gStyle->SetOptStat(0);
Double_t nbinsx=2; Double_t xmin=-4; Double_t xmax=4; Double_t nbinsy=2; Double_t ymin=-4; Double_t ymax=4; Double_t bwidthx=(xmax-xmin)/nbinsx; Double_t bwidthy=(ymax-ymin)/nbinsy; TCanvas *c1 = new TCanvas("c1","Profile histogram example",200,10,700,500); h2 = new TProfile2D("h2","h2",nbinsx,xmin,xmax,nbinsy,ymin,ymax,0,20); Int_t i=0; for (i=0; i<5; i++) h2->Fill((Double_t)i-2,(Double_t)i-1,(Double_t)i); h2->Draw("colz"); Double_t x,y,z; x=xmin+bwidthx/2; while(x<xmax) { y=ymin+bwidthy/2; while(y<ymax) { i=h2->GetBin(x,y); z=h2->GetBinContent(i); cout << i << "\t" << x << "\t" << y << "\t" << z << endl; y+=bwidthy; } x+=bwidthx; }
} Received on Tue Feb 15 2005 - 19:40:56 MET
This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:05 MET