I have gone through this discussion : Get histogram and close file
The code I have is slightly different from what’s given, its just that I initialized the TFile as a pointer i.e. TFile *f, but when I do a SetDirectory(0), the code crashes.
TFile *file = new TFile(“somefile.root”);
TH1D h = (TH1D) file->Get(“h1”);
h->SetDirectory(0)l; // Code crashes
file->Close()