I would like to convert from the text data file to the root data file (binary file).
The text data file includes numbers,
for instance,
x y errorx errory
0.5 2.5 0.01 0.01
1.5 3.0 0.01 0.02
2.5 3.1 0.02 0.01
…
…
and root data file means “filename.root” (binary code).
How can I convert from the text data file to the root data file?
How about from the root data file to the text data file??
With ReadFile, you will need to either remove the first line or change it to: x/F:y/F:errorx/F:errory/F and then do:f = new TFile("filename.root");
t = new TTree("thedata","");
t->ReadFile("file.dat");
It works and thank you very much. But I want to make 2 dimensional graph rather than TTree or histograms. The data includes just x, y, and x error, y error. How do you create these data from ascii files to root files?
I want to create these root files (such as filename.root) for root fitting macros. And the original data is written by text files. That’s why I want to convert ascii files to root files.
Note that you can fit the data in a TTree directly (see TTree::UnbinnedFit and TTree::Fit). You can also generate a TGraph out of TTree (see TTree::Draw).