I have a root file (attached) with my histograms contained within folders, but I seem completely unable to access the histograms using FindObjectAny:
FreeType Engine v2.1.9 used to render TrueType fonts.
Compiled on 1 July 2006 for macosx with thread support.
CINT/ROOT C/C++ Interpreter version 5.16.12, May 16, 2006
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] TFile* f = new TFile(“/Users/alan/Documents/data/LEM_SCFM_June06/lem06_his_0744.root”,“READ”);
root [1] TObject hDecay00object = f->FindObjectAny(“hDecay00”);
root [2] TH1F hDecayHisto = static_cast(hDecay00object);
root [3] hDecayHisto ->Draw();
Error: illegal pointer to class object hDecayHisto 0x0 149 (tmpfile):1:
*** Interpreter error recovered ***
root [4]
However, if I do something which is completely incorrect, I can access the histograms:
FreeType Engine v2.1.9 used to render TrueType fonts.
Compiled on 1 July 2006 for macosx with thread support.
CINT/ROOT C/C++ Interpreter version 5.16.12, May 16, 2006
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] TFile* f = new TFile(“/Users/alan/Documents/data/LEM_SCFM_June06/lem06_his_0744.root”,“READ”);
root [1] hDecay00 ->Draw();
Error: Symbol hDecay00 is not defined in current scope (tmpfile):1:
Error: Failed to evaluate hDecay00->Draw()
*** Interpreter error recovered ***
root [2] f->cd(“histos/LEMAnaModule”) ;
Error in : Object histos is not a directory
root [3] hDecay00 ->Draw();
: created default TCanvas with name c1
root [4]
So what am I doing wrong? Apologies from a Root newby - and thanks in advance.
A.
lem06_his_0744.root (190 KB)
brun
July 4, 2006, 8:27am
2
Do:
TFile* f = new TFile("/Users/alan/Documents/data/LEM_SCFM_June06/lem06_his_0744.root","READ");
TH1F *hDecayHisto = (TH1F*)f->Get("LEMAnaModule/hDecay00");
hDecayHisto ->Draw();
Rene
Thanks for the quick response. Unfortunately, this was one of the many variants I have tried to do over the last few days - and here is the result:
[quote]
root [1] TFile* f = new TFile("/Users/alan/Documents/data/LEM_SCFM_June06/lem06_his_0744.root",“READ”);
root [2] TH1F hDecayHisto = (TH1F )f->Get(“LEMAnaModule/hDecay00”);
root [3] hDecayHisto ->Draw();
Error: illegal pointer to class object hDecayHisto 0x0 149 (tmpfile):1:
*** Interpreter error recovered ***
root [4] [/quote]
Am I doing something wrong, or is there something fishy with the root files (see original post for attached root file)?
brun
July 4, 2006, 9:45am
4
Sorry, I did not realize that you had an attachment and that you had saved a TFolder in the ROOT file. The solution is:
TFile f("lem.root")
TFolder *histos = (TFolder*)f.Get("histos")
TH1F *hDecay = (TH1F*)histos->FindObjectAny("hDecay00");
hDecay->Draw()
Rene
Piet
December 1, 2008, 10:29am
5
Unfortunately, the solution posted above does not seem to work anymore.
13:32:39 | piet@lxplus206:~/scratch0/TriggerAnalysis> root -l
root [0] TFile f("/tmp/piet/TriggerAnalysis/SingleMuon/noise0_g3/results_merge_TriggerAnalysis_SingleMuon_noise0_g3.root");
root [1] TFolder* deff1 = (TFolder*) f.Get("Eta1-5");
root [2] TH1F* heff1 = (TH1F*) deff1->FindObjectAny("Eff.pt5 Eta 1_5");
root [3] heff1->Draw();
Error: illegal pointer to class object heff1 0x0 402 (tmpfile):1:
*** Interpreter error recovered ***
root [4]
I tried to follow the instructions above, but this didn’t work for me. Are there any comments or maybe a solution. All help would be appreciated. Thanks in advance.
Piet Verwilligen
results_merge_TriggerAnalysis_SingleMuon_noise0_g3.root (37.5 KB)
pcanal
December 1, 2008, 7:49pm
6
Hi,
The is a missing white space in your spelling of the histogram name (in general it is not a good idea to have white spaces in names …).
Try:root [0] TFile f("/tmp/piet/TriggerAnalysis/SingleMuon/noise0_g3/results_merge_TriggerAnalysis_SingleMuon_noise0_g3.root");
root [1] TFolder* deff1 = (TFolder*) f.Get("Eta1-5");
root [2] TH1F* heff1 = (TH1F*) deff1->FindObjectAny("Eff. pt5 Eta 1_5");
root [3] heff1->Draw();
(i.e. white space after the period ‘.’ after Eff)
Cheers,
Philippe.
Piet
December 2, 2008, 5:30pm
7
Thanks a lot. I never stop making silly mistakes… It’s not my idea, I better change those thinks.
Thanks
Piet