I have a TH1 h named “old_name” in a TFile f.
Can I rename h to “new_name” inside f?
I try the following code:
TFile *f = TFile::Open("file.root");
TH1 *h = (TH1*) f->Get("old_name");
h -> SetName("new_name");
f -> Save();
After opening file.root again, calling
TH1 *h = (TH1*) f->Get("new_name");
gives a nullptr, while
TH1 *h = (TH1*) f->Get("old_name");
gives a non-zero pointer
so my code does not work.