convert root file to txt file

Hi,
How can I convert root file to txt file, please?
That what I did.

ofstream file;
file.open(“here.txt”);

file<<energy<<endl;

but it stored only the value of the last event.

Thanks

Try searching the forum.

it depends on what you want to extract from the ROOT file (ie: histograms or tree).

but the root-dump command (from the Go-HEP/groot project), may be of interest.

$> root-dump ./testdata/small-flat-tree.root
>>> file[./testdata/small-flat-tree.root]
key[000]: tree;1 "my tree title" (TTree)
[000][Int32]: 0
[000][Int64]: 0
[000][UInt32]: 0
[000][UInt64]: 0
[000][Float32]: 0
[000][Float64]: 0
[000][Str]: evt-000
[000][ArrayInt32]: [0 0 0 0 0 0 0 0 0 0]
[000][ArrayInt64]: [0 0 0 0 0 0 0 0 0 0]
[000][ArrayInt32]: [0 0 0 0 0 0 0 0 0 0]
[000][ArrayInt64]: [0 0 0 0 0 0 0 0 0 0]
[000][ArrayFloat32]: [0 0 0 0 0 0 0 0 0 0]
[000][ArrayFloat64]: [0 0 0 0 0 0 0 0 0 0]
[000][N]: 0
[000][SliceInt32]: []
[000][SliceInt64]: []
[...]
$> root-dump ./testdata/hh2d.root 
>>> file[./testdata/hh2d.root]
key[000]: h2;1 "h2" (TH2D)
BEGIN YODA_HISTO2D_V2 /h2
Path: /h2
Title: h2
Type: Histo2D
---
# Mean: (2.250000e+00, 1.250000e+00)
# Volume: 4.000000e+00
# ID	ID	sumw	sumw2	sumwx	sumwx2	sumwy	sumwy2	sumwxy	numEntries
Total   	Total   	4.000000e+00	4.000000e+00	9.000000e+00	2.300000e+01	5.000000e+00	1.300000e+01	9.000000e+00	8.000000e+00
# 2D outflow persistency not currently supported until API is stable
# xlow	xhigh	ylow	yhigh	sumw	sumw2	sumwx	sumwx2	sumwy	sumwy2	sumwxy	numEntries
-4.000000e+00	-3.200000e+00	-5.000000e+00	-4.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00
-4.000000e+00	-3.200000e+00	-4.000000e+00	-3.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00
-4.000000e+00	-3.200000e+00	-3.000000e+00	-2.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00
[...]

hth,
-s

Thanks

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