Okay, got it. I didn’t realize the TGraphs are never attached to the file. I post my code in case someone has a similar question in the future.
TList *GetObjects(char *filename)
{
TH1 *histo;
TGraph *graph;
TList *myObjects = new TList();
myObjects->SetName("myObjects");
TFile *f = new TFile(filename);
TIter next(f->GetListOfKeys());
TKey *key;
while (key = (TKey*)next()) {
TClass *cl = gROOT->GetClass(key->GetClassName());
if (cl->InheritsFrom("TH1")) {
histo = (TH1*)key->ReadObj();
histo->SetDirectory(0);
myObjects->Add(histo);
}
else if (cl->InheritsFrom("TGraph")) {
graph = (TGraph*)key->ReadObj();
myObjects->Add(graph);
}
}
f->Close();
return myObjects;
}