Retrieve array of values from a TTree

I have a tree populated with data that looks like this

> k:5.8
> tree->SetBranchAddress(“k”, &k)

m : [-1.5, 3.1, 9.2, 7.2, 8.5]
tree->SetBranchAddress(“m”, &m)

A single value of k is mapped to several values of m, how can I read the values. ?

When I do the following :

Loop(allEntries)

tree->GetEntry(i)
cout << m

I am getting only one value of m.

Typically you will do something like this:

    TFile file("tree.root");
    TTreeReader reader("t1", &file);
    
    TTreeReaderArray<double> m(reader, "m");
    TTreeReaderValue<int> k(reader, "k");

    while (reader.Next()) {
      cout << " k = " <<  *k << " [ "; 
      for (const double& i : m) { 
        cout << i << ", "; 
      }
      cout << " ]" << endl;
    }
1 Like

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