Failed to export root file

Dear Root users

I have tried to export my root file to txt for instance

KEY: TH1D 1;1 step
KEY: TH1D 2;1 X-Pos
KEY: TH1D 3;1 Y-Pos
KEY: TH1D 4;1 Z-Pos

But it gave me strange output

10 4
20 0
30 0
40 0
50 0
60 0
70 0
80 0
90 0
100 0
110 0
120 0
130 0
140 0
150 0
160 0

tell
1000 0

this is my code for exporting root file to text file ,
{
gROOT->Reset();

TFile f(“M1.root”);

ofstream myFile(“M11.txt”);
//int nbins =step->GetNbinsX();
for (Int_t i=1; i<=X_pos->GetNbinsX();i++) {

myFile <<(double)(X_pos->GetBinCenter(i))+(double)(X_pos->GetBinWidth(i)/2.) << "\t " <<
(double)X_pos->GetBinContent(i) << endl; }
myFile.close();
}

any help is appreciated .
:bulb:

You ROOT file contains “broken” contents.
Your histograms have names “1”, “2”, “3”, “4” which is not really kosher.
You should use “names” which look like standard C/C++ identifiers (“titles” can be anything you like, including “step”, “X-Pos”, “Y-Pos”, “Z-Pos” which you use now).

thank you for replying , I post that details of previous root file

my root file contains
KEY: TH1D step;1 step
KEY: TH1D XPos;1 X-Pos
KEY: TH1D YPos;1 Y-Pos
KEY: TH1D ZPos;1 Z-Pos

and with that output !!!

In your macro you try to access “X_pos” while in your ROOT file you have “XPos”.
BTW. Do not use “gROOT->Reset();” at all.