Create an histogram with a txt file

ROOT Version: 6.26/02
Platform: macOs
_Compiler: Xcode

Hi everyone.
i am sorry for my bad English, I hope you will forgive me.

i have some little issues with creating a histogram: I already tried to look for something useful in the previous questions and answers, but I was a little confused.

I need to do a histogram which contains the x-values (first column of the txt file I will share here) and how many times a software has seen the y-values (second column).
how can I make a decent histogram with these data…
is it possibile with TH1F? I need then to do some fit on this histogram…

here I paste the txt file
spettrofotometro_nuovo.txt (46.4 KB)

second ps: I already succeeded in doing a graph considering the first column as a x-value and the second one as a y- value (I used them as points, but I’d like to have an histogram, since in the graph I needed to introduce the errors of the measures…)

I hope you can help me…
thanks for spending your time on answering for this question

You can create a TGraphErrors, e.g.:
TGraphErrors *g = new TGraphErrors("spettrofotometro_nuovo.txt", "%lg %lg"); // read only 2 first columns into X,Y

Afterward, you can simply “add” any errors you need, using the TGraphErrors::SetPointError method.

hi! thank you for the answer!
i am sorry, but I will bother you just a bit more

I already did this (and this does give me no issues), but this treats the x and y data as points, doesn’t it?

To be honest, I am pretty satisfied with this type of graph, since I can finish my data analysis, but I may need to do a histogram with (the y values are supposed to represent how many times the x-value appeared to the software which was used for the measure) just to satisfy my teacher’s desire…

is it possibile? if it is, could you tell me?

ps: I can, eventually, split the columns of the txt file and make two different txt files, but I don’t know how to make root generate a histogram with the frequency of events;

thank you for your time spent here!

In the posts given below, you can find examples of how to create a histogram from a graph.

Thank you so much!

i will make you one more question, which is the most stupid, but it’s making my brain implode (I don’t know why: how do I fill the histogram? (if it is h->FillN(…) it’s not working)


I am sorry for the question, this one was too stupid
i owe you a debt of gratitude, thank you! have a nice day!