Retrieving histograms from a file

Hi, I am not able to retrieve all the histograms I need from a TFile
using the macro shown below : the newly created histograms
are all empty, while the originals contained in the file are not .
The same instructions, typed interactively on a root session, work plainly and smoothly.

#include <TFile.h> #include <TH1D.h> TH1D *Signal, *data, *LightQuark, *Sequential ; void Smear() { TFile f("EventMLP_Single.hist","UPDATE"); TH1D* data = (TH1D*) f.Get("hDt"); TH1D* sig = (TH1D*) f.Get("hSg"); TH1D* lq = (TH1D*) f.Get("hLq"); TH1D* seq = (TH1D*) f.Get("hSq"); data->Draw(); seq->Draw("same"); data->Add(seq,-1); data->Draw(); data->Add(lq,-1); data->Draw(); sig->Draw("same"); data->Draw(); sig->Draw("samehist"); sig->Draw("hist"); data->Draw("sameeror"); }

Try to add:
data->SetDirectory(gROOT); // (gROOT) … or … (0)
sig->SetDirectory(gROOT); // (gROOT) … or … (0)
lq->SetDirectory(gROOT); // (gROOT) … or … (0)
seq->SetDirectory(gROOT); // (gROOT) … or … (0)

It works, thank you.