Convert root file to txt file with accuracy

ROOT Version: 6.18/04
Platform: Centos 7
Compiler: C++, C


Dear ROOT developers and users

I am post-processing the Root list-mode data generated from the GATE simulation and reconstructing it using the CASToR. I convert the ROOT to txt, after the post-processing, I convert the txt back to ROOT for the reconstruction. Most of the things went well, and the image can be successfully reconstructed by CASToR.

However, recently I am trying to add TOF in the recon, but soon realize that the txt file converted from ROOT has a lower TOF accuracy. I have output the .dat file from GATE directly for a comparison: For example, In the txt file converted from ROOT, I got a TTree time1 = 4.83994e-06 for the first event (first row in ROOT). In .dat, I got time1 = 4.83994034373751110439431e-06 for the same event.

The loss of accuracy basically ruined the image since every event got the same time difference. Although I can bypass the loss of precision during the root to txt by using the .dat files, I am worrying that the same thing will happen again when I convert txt back to ROOT.

I attached two converting codes I generated for root convert to txt and txt back to root. TreeTotxt.cxx (7.3 KB) txttoroot.C (5.6 KB) May someone help me point out where is the problem? Could we convert this accuracy (23 decimal points) from Root to txt or from txt back to Root?

Thank you for your help.

The most simple fix … in the “TreeTotxt.cxx” add something like this (of course, instead of “std::cout”, use “myfile”):

std::cout << std::scientific; // scientific notation
std::cout << std::setprecision(16); // std::scientific 17 decimal digits

or that:

std::cout << std::defaultfloat; // defaultfloat notation
std::cout << std::setprecision(17); // std::defaultfloat 17 decimal digits

Thank you for your reply!

I tried to add the two commands in my file, but I got some errors.

When I use

myfile << std::scientific;;
myfile << std::setprecision(22);

The root output is:

root [2] .x TreeTotxt.cxx
IncrementalExecutor::executeFunction: symbol ‘ZStanSt13_Ios_FmtflagsS’ unresolved while linking [cling interface function]!
You are probably missing the definition of std::operator&(std::_Ios_Fmtflags, std::_Ios_Fmtflags)
Maybe you need to load the corresponding shared library?
IncrementalExecutor::executeFunction: symbol ‘_ZSt12setprecisioni’ unresolved while linking [cling interface function]!
You are probably missing the definition of std::setprecision(int)
Maybe you need to load the corresponding shared library?

And when I use:

myfile << std::scientific;;
myfile << std::setprecision(23);

The root output is:

root [1] .x TreeTotxt.cxx
In file included from input_line_10:1:
/home/goldan/Desktop/share/RDecagon/Decagon1mm/Result_debug2/TreeTotxt.cxx:132:15: error: use of undeclared identifier ‘defaultfloat’

Do you have any idea for these errors?

Thank you!

#include <iostream> // std::cout, std::defaultfloat, std::scientific
#include <iomanip> // std::setprecision

This works great! Thank you very much for your help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.