TGraphErrors read data from .txt file


I have a .txt file like this. The format is X Y Ey.
3.txt (510 字节)
And I want to make a TGraphErrors picture. So I reference the example from the ROOTPrimer(page24)

int macro2(){
auto c=new TCanvas();c->SetGrid();
TGraphErrors graph_expected("3.txt",
                            "%lg %lg %lg");
   "Measurement XYZ and Expectation;"
   "lenght [cm];"
TLegend leg(.1,.7,.3,.9,"Lab. Lesson 2");
leg.AddEntry(&graph_expected,"Expected Points");
return 0; }

But it doesn’t work at all.:cry: I am not familiar with CPP ,ROOT even the English. I’ve been obsessed with this problem for a long time. Thank you very very much for your kind help.:smile:

The problem is that your “3.txt” file is encoded in UTF-16 ("-dos").
You must make sure that it is encoded in iso-8859-1 / iso-latin-1, i.e. standard ASCII (and better “-unix” than “-dos”).

1 Like

Thank you very much for your efficient help. I used “iconv” to solve it. It was pretty sad to find Google can not service here.

:smile:Would you please explain more about my confusions?
(1)I tried to write if (energy > 0.5),Canvas_1.pdf (14.1 KB) But the counts of zero is still very (6.1 KB) AnaEx02.root (475.9 KB)

(2)when I set more bins numbers, the hight of the graph becomes lower and lowerCanvas_2.pdf (14.9 KB)
Maybe the core of the problem is that I don’t understand the meaning of the bin?

Best regards :grin: Thanks for helping me.

I am really appreciated for your kind and patient rely.

But I can not understand it very much. Maybe I think I need some time and learn some knowledge from Google. Then try it again.

Thank you for your rely again!:smile::smile::smile:

I am sorry “reply”:laughing:


Try something like: if (energy > 10.)

1 Like

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