TGraphErrors read data from .txt file

Hi

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");
graph_expected.SetTitle(
   "Measurement XYZ and Expectation;"
   "lenght [cm];"
   "Arb.Units");
graph_expected.SetFillColor(kYellow); 
graph_expected.DrawClone("E3AL"); 
TLegend leg(.1,.7,.3,.9,"Lab. Lesson 2");
leg.SetFillColor(0);
leg.AddEntry(&graph_expected,"Expected Points");
leg.DrawClone("Same");
graph.Print();
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 high.HistoManager.cc (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:

TH1::SetStats

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.