I have a root file named “filename.root” with the tree named “treename”. There is a histogram named “histname” in this tree. I am trying to read this histogram but nothing is showing up. Please let me know my error. Here’s my code.
void TFileRead()
{
TFile *filename = new TFile("filename.root", "READ"); //READ
TTree *treename = (TTree*)filename->Get("treename");
// TH1F* histname = (TH1F*)treename->GetHistogram("histname");
treename->Draw("histname");
treename->GetHistogram();
}
couet
July 28, 2021, 6:45am
2
Can you give more details ? Which error message do you get ? May be post the file filename.root
here ?
Hi Couet, here are the all the files. Thank you.
filename.root (6.7 KB)
TFileCreate.C (469 Bytes)
TFileRead.C (306 Bytes)
couet
July 29, 2021, 6:25am
4
histname
is not in the tree. It seats in the root file. Simply do:
% root filename.root
------------------------------------------------------------------
| Welcome to ROOT 6.25/01 https://root.cern |
| (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
| Built for macosx64 on Jul 05 2021, 04:58:33 |
| From heads/master@v6-25-01-1526-g96258cd49b |
| With Apple clang version 12.0.5 (clang-1205.0.22.11) |
| Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------------
root [0]
Attaching file filename.root as _file0...
(TFile *) 0x7fb08e33a170
root [1] _file0->ls()
TFile** filename.root
TFile* filename.root
KEY: TTree treename;1 treetitle
KEY: TH1F histname;1 histtitle
root [2] histname->Draw()
1 Like