Re: [ROOT] How to set binning of an existing hist correctly?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Feb 13 2002 - 17:30:44 MET


Hi Thomas,

The straight forward way is to call the TH1D constructor accepting
an array of bin edges.
Yes, I could implement one function TH1::SetBins(n,edges), but this would imply
too many new functions to support all the combinations for 2-d and 3-D case
(TH1, TH2, TH3, TProfile, TProfile2D, TH1K), making heavier an interface already
too heavy.

Rene Brun

 - Thomas Bretz wrote:
> 
> Hi,
> 
> I have an already existing instance of TH1D and want to set the binning
> of it. Because there is no interface I descided to use TAxis directly,
> but this fails. To workaround I can do the follwoing:
> 
> TH1D *h = new TH1D;
> 
> // some other code....
> 
> h->SetBins(100, 0, 1); // 100 bins (this number is the important one, so
> that TH1D knows the correct number, 0 and one are dummy values.
> h->GetXaxis()->Set(100, edges); //edges is an array of 101 entreis
> containing the edges of my bins....
> 
> Some idea? Can you implement a more straight forward function for this?
> 
> Thanks,
> Thomas.



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