Problem in reading data from a text file

Hi,

I am generating a root file after reading data from a text file. The data in the text file (“gs_out.txt”) in each row is organized in the order as given below:

EventNbr,dE_a1,E_a1,totE_a1,Th_a1,dE_a2,E_a2,totE_a2,Th_a2,dE_p,E_p,totE_p,Th_p

The root file (“gs_data.root”) that I am generating has branches of the same names as above. However the problem is that the following branches are showing same data although the data file contains different values for those variables!

  • dE_a2 and dE_p

  • E_a2 and E_p

  • Th_a2 and Th_p

I am attaching the data file, the root file and the macro (“gs_data.C”) that I am using to generate the root file. Any help will be much appreciated.

Thank you in advance.

gs_data.C (1.3 KB)
gs_data.root (20.0 KB)
gs_out.txt (32.4 KB)

dE_a2 and dE_p refer to the same adress &dE_a2

tree->Branch("dE_a2",&dE_a2,"dE_a2/F");
tree->Branch("dE_p",&dE_a2,"dE_p/F");

very likely copy/paste mistake :slight_smile:

2 Likes

Hi,
if you have a recent-enough ROOT version (v6.12 should work already) you could also try with:

auto df = ROOT::Experimental::TDF::MakeCsvDataFrame("gs_out.txt"); // create a DataFrame that reads a CSV file
df.Snapshot("treename", "gs_data.root"); // write contents of DataFrame to root file

Cheers,
Enrico

1 Like

Thank you so much for pointing out the silly mistake! My bad! :slight_smile:

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