How do I print the data to a text file from the output tree?

Hello, I need help.
I need to print out a txt file with the values X Y Z Plane Bar Position Time. The data is taken from the output tree. Each event’s time of flight will have a start and end point with coordinates (X Y Z Plane Bar Position Time) (I have a sample result similar to what I want).
I’ve tried and tried to follow so many similar things like that, but couldn’t get any.
Please help me to get it.


Welcome to the ROOT Community.
There are several ways in which you can achieve this.
One could be via RDataFrame::Foreach. Suppose to have a file called myfile.root containing a TTree tree containing 3 columns x, y, and z of type float:

ROOT::RDataFrame d("tree", "myfile.root");
d.Foreach([](float x, float y, float z){ cout << x << " " << y << " " << z << endl;},{"x", "y", "z"});

In PyROOT, that could be:

import ROOT
myfile = TFile("myfile.root")
for evt in myfile.tree:
    print("%s %s %s" %(evt.x, evt.y, evt.z))


Thank you so much

You can also achieve it using TTree::SetScanField(0); TTree::Scan()
See ROOT: TTreePlayer Class Reference