Re: Copying a Histogram

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Aug 04 1999 - 18:01:40 MEST


Marco,
When you close a TFile, all histograms associated with this file are
deleted.
Remember that, by default, histograms are created in the current
directory
(in your case the TFile).
You can add the statement
   h2->SetDirectory(0);
after your statement:
   TH1F *h2 = (TH1F*) hist->Clone();

In this case h2 will not be associated with any directory and closing
the file will not delete h2.

Rene Brun

Marco van Leeuwen wrote:
> 
> 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