Copying a Histogram

From: Marco van Leeuwen (mvl@nikhef.nl)
Date: Wed Aug 04 1999 - 17:44:30 MEST


Hi, 

I read the following:

------------- Start Roottalk digest

Sean Kelly wrote:
> 
> Hi Rooters,
> 
> I realize this has been the subject of previous posts. My question is
> does the code frag below represent the simplest way to duplicate
> a histogram ?
> 
> TH1F *vxDHi = (TH1F*) vx->Clone();
> vxDHi->SetName("vxDHi");
> 
> thanks
> 
> Sean Kelly

Yes, This is the recommended way. TH1::Clone make sure that all the data
structure supported by a TH1 object is copied.

Rene Brun

-------------- End Roottalk digest

So, if a file named test.root contains a histogram called hist, the
following should work:

TFile f("test.root");
TH1F *h2 = (TH1F*) hist->Clone();
h2->SetName("h2");
h2->Draw();
f.Close();

BUT, the histogram disappears... Why????

(Using root 2.21/08 on Linux)

Marco van Leeuwen



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:37 MET