Problem exporting histogramms to an output file

Dear Rooters.

My problem with ROOT is probably a minor one, which normaly should not be here, but since non of the persons familiar with ROOT in the department was able to solve it, I have to post it here anyway.

I’m using 3.05/07 version of ROOT. My problem is: I’m trying to export histogramms created by analysing an n-tuple data file with the procedure provided by the TSelector method.

First the file is created with:

TFile *uu_out; //(pointer in the .h file)

uu_out = (TFile*)gROOT->FindObject(“uu_hist.root”); // these three lines are in the .C file

if (uu_out) uu_out->Close();

uu_out = new TFile(“uu_hist.root”,“RECREATE”,“ROOT file with uu histos”);

at the beginning of the .C file, and after the creation of the histogramms, all histogramms should be written into this file using:

uu_out->Write();

The file is created but is empty. Probably it is just a minor error somewhere and I just don’t see it.

kind regards

Erik

Hi Erik,

You have two solutions

solution 1

TDirectory *olddir = gDirectory;
uu_out = new TFile(“uu_hist.root”,“RECREATE”,“ROOT file with uu histos”);
olddir->GetList()->Write();

solution 2

uu_out = new TFile(“uu_hist.root”,“RECREATE”,“ROOT file with uu histos”);
// create your histograms
TH1F *h = new …

uu_out->Write();

The point is that histograms are created in the current directory. When you create a new file, it becomes the current directory.

Rene