I’m reading a rootfile that has several histograms and I was working with root 5.34 and this was working perfectly but recently I started to work with root 6.06 and suddenly when I open my file to obtain the graph of a histogram like this:
rootfile_example->cd();
histo_tst1->Draw("histosame");
I obtain an error from root 6 that is:
error: use of undeclared identifier ‘histo_tst1’
I wiil be very happy if you help me with this error,
In ROOT 6, you must create histogram pointers and then retrieve your histograms manually. So, for each histogram, you should have something like: TH1F *h; SomeRootFile->GetObject("SomeHistoName", h);
Note also that, you should not use the “same” drawing option, if nothing has been drawn yet (in the current pad).
I’ll give some background in case anyone cares / reads this We went back and forth with this in ROOT 6; what you observe is likely the long lasting result:
It’s easy to misspell variables. I do it all the time. To make sure that we know what we’re talking about, we decided to stop doing magic variables in named macros (anything that has a function inside). We had cases - also in ROOT tutorials - where broken code was hidden because of these magic variables, giving wrong results.
We also like the fact that code that looks like code is now much closer to what the compiler would accept (except for #includes) making it less confusing for novices why “sometimes” something is okay and sometimes it’s not.
Note that these magic variables continue to work on the prompt: opening a ROOT file with a histogram called histo will still allow you to simply issue a histo->Draw().