Read two textfiles and make two branches

Hallo routers!
I want to open two textfiles which contain measured data and are formated like:
0.1 // line 1
0.2 // line 2
0.3 // line 3
[…]

For every file I want to create a new branch in my Tree T.
I am using TTree::ReadFile(, , ,)

My code looks like:

void openfile(){
gROOT->Reset();
TFile *f = new TFile("online.root","RECREATE");
TTree *T = new TTree("PD","data from txt file");

Double_t time; 
Float_t teData;
T->Branch("Time", &time, "Time/D");
time = T->ReadFile("C:\\Users\\q349344\\Desktop\\time.txt", "F");
T->Branch("PD_Data", &teData, "PD_Data/F");
teData = T->ReadFile("C:\\Users\\q349344\\Desktop\\qiec.txt", "F");
T->Write();
}

To test the code, I wrote the text files manually. txt-file1 contains 2 points with the same value (1.0)
txt-file2 contains 3 points with the same value (2.0).
In this case my tree contains two branches. Both are filles with 4 entries and a RMS I can’t connect to the values I entered.

Thanks! :slight_smile:

TTree::ReadFile

Thank you! If I understand it correctly, root will make a branch for every variable I defined in the branch descriptor. So it should be like:

TFile *f = new TFile("online.root","RECREATE");
TTree *T = new TTree("PD","data from txt file");
T->ReadFile("C:\\time.txt", "time/F");
T->ReadFile("C:\\qiec.txt", "teData/F");
T->Write();

But this code doesn’t work. Root doesn’t create a second branch called teData…