Hello everyone,
I need some help for reading a root file with branches having different basket sizes. I have 4 branches for 4 variables: njet (Int_t), jet_pt (Double_t), jet_eta (Double_t), and jet_phi(Double_t). The njet branch has 1 basket and the others have two baskets.
When I try to read the root file, for example the first row,
////Code///
tree->Gentries(0);
for(Int_t = 0; i < njet; i++){
cout << njet << " " << jet_pt << " " << jet_eta << " " << jet_phi << endl;
}
///////////////
I find I can only read the data for the 0th instance, but the for loop does not iterate the remaining instances, I get:
3 196.61381 -1.626381 -1.071998
3 196.61381 -1.626381 -1.071998
3 196.61381 -1.626381 -1.071998
But what I really expect is to have:
3 196.61381 -1.626381 -1.071998
3 76.989097 -2.951812 1.4268599
3 28.976756 -2.460338 0.0617163
The variables are not of the type array, I have tried something like e.g. jet_pt[i] but it does not work. However, in each entry, it is spanned by the value of njet, so with instance 0,1,2 as shown in the picture.
Do the different basket sizes matter, and how can I read the values properly ?
Regards,
Bengy
Please provide the following information:
ROOT Version (e.g.5.34/36):
Platform, compiler (e.g. CentOS 7.3, gcc6.2):
well, the jet_pt, jet_eta and jet_phi variables really should be either C arrays (e.g.: Double_t jet_pt[NMAX]; where NMAX is a compile-time constant) or pointers to C dynamic arrays (e.g.: Double_t *jet_pt;)
could you show us (more of) the code that does the reading?
could you post somewhere accessible an example ROOT data file?
void Hinv_Signal_MC(){
TFile *f1 = new TFile("tree.root");
TTree *tree; f1.GetObject("tree", tree);
tree->Print(); //This shows the branch in the figure in my original post
tree->Scan("njet : jet_pt : jet_eta : jet_phi"); //This shows the data in the figure in my original post
tree->GetEntry(0);
for(Int_t i=0; i< njet; i++){
cout << njet << "\t" << jet_pt << "\t" << jet_eta << "\t" << jet_phi << endl;
}
}
And this gives
3 196.61381 -1.626381 -1.071998
3 196.61381 -1.626381 -1.071998
3 196.61381 -1.626381 -1.071998
From the tree->Print() results it shows that the jet_pt, jet_eta, jet_phi variables are Double_t but not Double_t array[njet], not sure how it can give 0,1,2 instances.
How are the variable ‘njet’ (etc.) connected to the TTree? [In the code snippet they are not and thus can not possibly be updated with values coming from the TTree]