Access data from a Tree

Dear rooters,

I would like to print a datum from a root file to the screen. I have tried to imitate examples from tutorials, however, that did not work!.

The correct value should be 16, but it always shows 0.

Please give me a favor. Thank you.

My root file is big, so you can download it here: run01.root - Google Drive

nanh.C (298 Bytes)


Please read tips for efficient and successful posting and posting code

ROOT Version: 5.34
Platform: Win 7
Compiler: Not Provided


with ROOT 6.23 on Mac it is 16:

% root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.23/01                        https://root.cern |
  | (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosx64 on Feb 12 2021, 06:10:13                      |
  | From heads/master@v6-23-01-RF-binSampling-737-g3d545273d7        |
  | With Apple clang version 12.0.0 (clang-1200.0.32.29)             |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0]    TFile *f = new TFile("run01.root");
Warning in <TClass::Init>: no dictionary for class TNeEvent is available
Warning in <TClass::Init>: no dictionary for class TGo4EventElement is available
root [1]    TTree *t1 = (TTree*)f->Get("AnalysisxTree");
root [2]    UShort_t abc[16];
root [3]    t1->SetBranchAddress("NeEvent.PPAC[16]",abc);
root [4]    t1->GetEntry(1);
root [5]    cout<<abc[0]<<endl;
16
root [6] 

It is weird that it does not work on root 5.34 window 7.

5.34 is very old. Can you try with a more recent version ?

My computer is ten years old. I also have many other software. Move to Linux to use Root 6 is an option that I don’t really want.

Anyway, thank you for your support. I’ll find my best solution.

Note also you get warnings. That’s not a good sign.
May be @pcanal can tell more about them.

Note also that ROOT 6 is available on windows now:

1 Like

Before the “SetBranchAddress” line, add: t1->SetMakeClass(1);

1 Like

The
no dictionary for class ROOT::TIOFeatures
can be ignored (it indicates the file was written with ROOT v6 but it should still work.

The fact that you set the address of the inners of an object to a standalone array means that indeed you need to put the TTree in SetMakeClass mode.

1 Like

Hello Everybody,
I am Nhat, I am a new member.
I start learning root recently, I had some problems with trees. i could not solve it.
i hope everybody can help me solve it.
My problem is
my purpose: I want to draw 2 PPAC,tPPAC histograms, and fit “gaus” for each.
but my code had a problem.
Below are the link code and file root I want to analyze.

image

My code : nhat6.C (1.2 KB) .

My root file is big, so you can download it here: [run01.root - Google Drive]

(run01.root - Google Drive)

sorry i sent a new photo.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.