Re: [ROOT] TH3::Projection3D and variable bin size

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Apr 12 2002 - 11:21:11 MEST


Hi Thomas,

I have removed the obsolete comment in TH3::Project3D.
I implemented support for variable bin sizes 3-d histograms when
making projections and I forgot to remove the comment decsribing
the previous restriction.

I do not see any problems in projecting 3-d histo to 2-d histograms
in the variable bin size case.
Here is a small example showing that it works.

Rene Brun


void h3d()
{
   // test 1-d, 2-d, 3-d variable bin size histograms

   const Int_t nx = 10;
   const Int_t ny = 10;
   const Int_t nz = 6;
   Float_t xbins[nx+1] = {-4,-2,-1.5,-1,-0.4,0,0.4,1,1.5,2,4};
   Float_t ybins[ny+1] = {-4,-2,-1.5,-1,-0.4,0,0.4,1,1.5,2,4};
   Float_t zbins[nz+1] = {0,0.5,2,4,8,14,20};
   TH3F *h3 = new TH3F("h3","histo with variable bins",
                        nx,xbins,ny,ybins,nz,zbins);

   Double_t x,y,z;
   for (Int_t i=0;i<25000;i++) {
      x = gRandom->Gaus(0,1);
      y = gRandom->Gaus(0,1);
      z = x*x + y*y;
      h3->Fill(x,y,z);
   }
   h3->Project3D("xy")->Draw("box");
}


Thomas Bretz wrote:
> 
> Hi all,
> 
> in TH3::Projection3D I found:
> 
> -----------------------------------------------
>           //variable bin size axis not supported yet for 2-d projections
>      case 4:
>         xbins = fXaxis.GetXbins();
>         ybins = fYaxis.GetXbins();
>         if (xbins->fN == 0 && ybins->fN == 0) {
>            h2 = new
> TH2D(name,title,ny,fYaxis.GetBinLowEdge(iymin),fYaxis.GetBinUpEdge(iymax)
> 
> ,nx,fXaxis.GetBinLowEdge(ixmin),fXaxis.GetBinUpEdge(ixmax));
>         } else if (ybins->fN == 0) {
>            h2 = new
> TH2D(name,title,ny,fYaxis.GetBinLowEdge(iymin),fYaxis.GetBinUpEdge(iymax)
>                         ,nx,&xbins->fArray[ixmin-1]);
>         } else if (xbins->fN == 0) {
>            h2 = new
> TH2D(name,title,ny,&ybins->fArray[iymin-1]
> 
> ,nx,fXaxis.GetBinLowEdge(ixmin),fXaxis.GetBinUpEdge(ixmax));
>         } else {
>            h2 = new
> TH2D(name,title,ny,&ybins->fArray[iymin-1],nx,&xbins->fArray[ixmin-1]);
>         }
>         break;
> -------------------------------------------------
> 
> >From the code I understand that projections with variable bin size
> should be supported, but the comment say that the variable bin size is
> not supported. If I try to make a 2D projection from a 3d hist with
> variable bin size I get a constant binning... why? Can this be fixed?
> 
> Best regards,
> Thomas.



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:49 MET