Drawing a histogram from a text file

Hi I’m new in Root, and want to write and draw a histogram from a two (log base) column text file. I really appreciate your help.

VanDyke
Mytext…txt (465 Bytes)

Hi,

I propose you tackle the parsing of the ASCII following something along this lines: cplusplus.com/doc/tutorial/files/
And find inspiration about the usage of ROOT histograms having a look to these tutorials: root.cern/doc/master/group__tutorial__hist.html

Let us know if you encounter blockers with the ROOT part.

Cheers,
Danilo

I reformatted a bit your text file (remove tabs and aligned columns). Your file becomes:

1         6.12504e+14
1.25893   3.61421e+14
1.58489   2.17905e+14
1.99526   1.39038e+14
2.51189   9.13678e+13
3.16228   5.77759e+13
3.98107   3.26895e+13
5.01187   2.30892e+13
6.30957   1.25978e+13
7.94328   1.17648e+13
10        5.93986e+12
12.5893   3.40322e+12
15.8489   2.54676e+12
19.9526   1.29766e+12
25.1189   7.67923e+11
31.6228   3.89503e+11
39.8107   1.25781e+11
50.1187   4.13651e+10
63.0957   1.01185e+10
79.4328   1.52105e+09
100       1.44305e+08
125.893   9.3292e+06
158.489   142960
199.526   108.063
251.189   0

Then it is enough to do:

root [0] TGraph *g = new TGraph("Mytext.txt");
root [1] g->Draw();

That’s a graph, not an histogram, but given the layout of your data I thought it might be appropriate. From the graph you can retrieve the underlying histogram using g->GetHistogram().

I want to draw histogram with my txt file .what is command.file Name is events_MCH600.txt

Did you try the recipe given in this post ?

yes tried but error my file name is events_MCH600. txt and this file is in downloads I copies this file in my Analysis code. I want to draw histogram from this txt file so what’s command

Can you post this file ?

that file can not be shared heavy fie

Even a subset of it ?

this is file

I cannot do anything with a screen shot …
But the file you show looks like a xml file generated CompHEP.
Is it the case ?
Is there data inside you can read in a TGraph as this post suggests ?

Doing some google search pointed me to some links which might be of some help for you: https://theory.sinp.msu.ru/doku.php/comphep/extra/main

yes file generated from comphep actually file very heavy anyhows try to share but will be time taking

May be have a look at the link I posted. I think that’s what you need.

ok thanx