Accessing the same leaf for different events of TTree

Hello,

I have a TTree object with, lets say, a 100 events on it
(tree->Show(0) will show all the leaves for the first event, tree->Show(1) for the second event, and so on).

I would like to access this information through
TLeaf* leaf = tree->GetLeaf(“some_information”)
however, this only get me the first event, so I was wondering how I can do that for any event.

Thanks.

I believe you just need to use TTree::GetEntry.

When using for example:
TLeaf* leaf = tree->GetLeaf(“some_information”)
leaf -> GetEntry(1)

I receive an error
"
Error: Can’t call TLeaf::GetEntry(1) in current scope (tmpfile)(1)
Possible candidates are…
(in TLeaf)
*** Interpreter error recovered ***
"
I’m sorry for the trouble, i’m new to root

GetEntry is a member of TTree

TLeaf* leaf = tree->GetLeaf("some_information");
tree -> GetEntry(1);

Also, see this about posting code fragments:

A working example:

{
   //Create a tree and fill it with some data
   TTree *tree = new TTree("tree","Tree");
   double value;
   tree->Branch("value", &value);
   for (int i=0;i<5000;i++) {
      value = i;
      tree->Fill();
   }
   tree->ResetBranchAddresses();

   //Get the pointer to the leaf.
   TLeaf * leaf = tree->GetLeaf("value");

   //Get each entry in the tree (first 10) and print it to the screen.
   for (int i=0;i<10;i++) {
      tree->GetEntry(i);
      std::cout << leaf->GetValue() << "\n";
   }
}

Outputs:

$ root tleaf.C
root [0]
Processing tleaf.C...
0
1
2
3
4
5
6
7
8
9

It works!

Thank you!

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