Saving a histogram from a tree

I am having troubles saving a Histrogram from a loaded tree. I have a file input.root which is loaded and has a tree as a key. I call the tree and create a histogram with:

Then I create another file using TFile and write the histogram to the new file, but when I closes the new file and loaded later on I got an empty histogram. My total code follows:

TMBTree->Draw("L2GblJet.Eta():L2GblJet.Phi() >> EtaPhi")
TFile L2GblJet("/shift/shd01/kmurphy/L2Gbl/L2GblJet.root","recreate")
EtaPhi->Write()
L2GblJet.Close()

Any help is much appreciated

Kyle

Hi Kyle,

Do:

TMBTree->Draw("L2GblJet.Eta():L2GblJet.Phi() >> EtaPhi"); TH1 *EtaPhi = (TH1*)gDirectory->Get("EtaPhi"); TFile L2GblJet("/shift/shd01/kmurphy/L2Gbl/L2GblJet.root","recreate") EtaPhi->Write() L2GblJet.Close()

Rene

All right, thanks so much Rene, thats been bugging me for a while. :smiley:
Agiain Thanks…

Kyle