Losing a TH1 when I open a new file

I am having this problem:

[anlevin@lxplus0023 ~]$ root originalfile.root
root [1] tree->Draw("Jet.Eta>>my_hist")
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [2] my_hist->SetDirectory(0)
root [3] TFile *_file0 = TFile::Open("anewfile.root")
root [4] my_hist->Draw()
Error: Symbol my_hist is not defined in current scope  (tmpfile):1:
Error: Failed to evaluate my_hist->Draw()
*** Interpreter error recovered ***

I am very confused because I thought using my_hist->SetDirectory(0) would prevent me from losing the histogram. Why is it not defined after opening the new file?

I found that this problem does not happen when I use root -b. Not that this solves the problem, because I want to have the graphical interface.

[anlevin@lxplus0023 ~]$ root -b originalfile.root
root [1] tree->Draw("Jet.Eta>>my_hist")
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [2] my_hist->SetDirectory(0)
root [3] TFile *_file0 = TFile::Open("anewfile.root")
root [4] my_hist->Print()
TH1.Print Name  = phase1_hist, Entries= 255477, Total sum= 255477

Try:
tree->Draw(“Jet.Eta>>my_hist”);
TH1F *my_hist = ((TH1F *)(gROOT->FindObject(“my_hist”))); // gROOT or _file0
my_hist->SetDirectory(0); // 0 or gROOT

yes, that works!

thanks

do you understand why

TH1F *my_hist = ((TH1F *)(gROOT->FindObject(“my_hist”))); // gROOT or _file0

is needed?