Re: Keeping Histograms

Pasha Murat (murat@cdfsga.fnal.gov)
Tue, 3 Nov 1998 21:43:35 -0600 (CST)


Jeff Patterson writes:
> Hey Rooters,
>
> My problem is that my histrograms keep disappearing from memory.
> Here is what I am doing. I have an row-wise Ntuple from HBook that I have
> converted with h2root. The ntuple is called h666. So I open the file,
> make the histogram, then I want to clode the Ntuple and open another one
> and add to it. But as soon as I close the file, I lose the histogram.
> How can I get around this. Sample code
>
> f1 = new TFile("ntup1");
> MOM = new TH1F(bins);
> h666->Draw("mom>>+MOM", "cuts");
> delete f1 //This is were I lose my histogram
> f1 = new TFile("ntup2");
> MOM = new TH1F(bins);
> h666->Draw("mom>>+MOM", "cuts");
> etc.....
>
> What am I doing wrong.
>
> Jeff Patterson
>

Jeff: when you create a histogram after haaving opened a file, ROOT associates
it with this file, so when you delete the file, your histogram also gets deleted.
If you don't want to save `h666' into a file, simple inversion

MOM = new TH1F(bins);
f1 = new TFile("ntup1");

will do the job and your histogram will remain in memory after you close `f1'.

- regards, pasha.