Reading Tree data error


I am pretty new to trees and I am experiencing a problem of extracting vector data from branch of tree and storing it in variables. I have a branch that is vector which I have scanned for variables. I have attached an image below showing the scan of variables.

My code below is (modified from documentation):

TFile *input = new TFile("mc16_DrellYan_SpinHalf_HECOs_100_1000GeV.root","read");
TTree *MonAnaTree = (TTree*)input->Get("MonAnaTree");
std::vector<Float_t> *monPx = 0;
MonAnaTree->SetBranchAddress("monPx", &monPx);
for (Int_t i = 0; i<20; i++) {MonAnaTree->GetEntry(i);}

however, when I check the value for monPx i am only provided two values shown below .

root [21] (*monPx)
(std::vector<Float_t> &) { 268166.f, -280968.f }

Maybe it is due to my rustiness in C++ and ROOT but where am I going wrong ?

monPx keeps the values (“Instances”) from the last GetEntry call (“Row”)

Hi , thank you for that. How would I extract the data , all values from the vector? Also just as curiosity what is an instance? is it something like an array index?

“Row” is the entry number of the tree, and “Instance” is the vector’s element index (always for the current tree entry).

Thank you for the information. So for storing the values will this code work for storing all the vector values in an array:

Int_t array[20] = {0};

for (Int_t i = 0; i<20; i++) {MonAnaTree->GetEntry(i); array[i]=(*monPx)[i]  }

Hello sorry , this still stores just the last two values, How do you extract the original values of the data of monPx ? I am able to draw the histogram as shown below:


(*monPx)[i] doesn’t really make sense to me.
from the screenshot in your first post, it seems to me that, for every tree entry, the size of the monPx vector is 2 (always?).

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