Dear Experts,
If I have a leaf named Interaction that looks like Interaction[hit][4] in the header file with [hit] of dimension 100 ,and [4] refers 0 as x, 1 as y, 2 as z and 3 as t coordinates. In my c++ macro I am trying to loop over time (Interaction[hit][3]) but I don’t understand how to write the for loop condition with the the index variable [3]
from Interaction[hit][3]
, Please help me write this condition.
- Also how do I look at all the numbers in Interaction[hit][3] leaf using a terminal command.
Thank you,
Saurav
Hi,
- Do you mean looping over a 2D array in C++?
for (int hit_i = 0;hit_i <100;hit_i++) {
for (int coord_i = 0;coord_i <3;coord_i++) {
std::cout << Interaction[hit_i][coord_i] << std::endl;
}
}
- Have you had a look to TTree::Scan ? ROOT: TTree Class Reference
In any case, I would advise to consider RDataFrame for all your analysis and manipulation of columnar data.
Best,
Danilo
1 Like
HI Danilo,
Thanks for your response.
Yes, I am trying to loop over a 2D array. I already looped over the [hit], now I am trying to loop over only the time coordinate, I don’t want to loop the spatial coordinates. So while doing the second for loop, how do I assign the time coordinate inside the array and only loop over all the values assigned to t.
Also if you could explain this:
for (int coord_i = 0;coord_i <3;coord_i++) {}
it will be really helpful. As, what I understand from this is that you are also looping through x,y,z.
I did look at the scan feature ,I am not sure what to put inside the bracket to only view the time coordinate.
And, sure I will look into RDataFrame, thanks for pointing this out.
Regards,
Saurav