Filling a Histogram from a text file with 2 Columns

Hello,

I have a text file that contains two columns with my data, the value in the X axis, and the weight.

How can I plot this as a 1D histogram?

So far I’ve only found this [url]Histogram from a text file
but when I try it, I get a scatter plot, and because it is a 2D histogram I haven’t been able to pass a smooth line through those points.

I’m trying to do something like

1)Read data from file “Data.txt” (three columns: row number, x, weight…I’m interested only in the last 2)
2) Fill a 1D histogram with (x,weight)
3) Plot the 1D histogram with the smooth line

Any help is appreciated…

Thank you

Try:

root [0] TTree *MyTree = new TTree("MyTree", "MyTree");
root [1] MyTree->ReadFile("Data.txt", "row/I:x/D:weight/D");
root [2] MyTree->SetEstimate(-1);
root [3] MyTree->Draw("x", "weight", "C");

Hello,
I am very new to Root and struggling to find a solution to my question.
I want to plot a histogram (Time vs data) from a .dat file( containing 2 columns).
My .dat file contains
14:01:06 163.52
14:01:07 164.34
14:01:08 162.04
14:01:09 163.50
14:01:10 164.38
14:01:11 161.22
14:01:12 160.70
14:01:15 135.54
14:01:16 158.43
14:01:17 160.78
The 1st column is time (X-axis) and the 2nd column is value (Y-axis).
I am getting following error:
Warning in TTree::ReadStream: Ignoring trailing “:01:06” while reading data for branch x on line 1
Warning in TTree::ReadStream: Ignoring trailing “:01:07” while reading data for branch x on line 2
Warning in TTree::ReadStream: Ignoring trailing "
14:01:08" while reading data for branch y on line 2
Warning in TTree::ReadStream: Ignoring trailing " 162.04" while reading line 2
Warning in TTree::ReadStream: Ignoring trailing “:01:09” while reading data for branch x on line 3
Warning in TTree::ReadStream: Ignoring trailing “:01:10” while reading data for branch x on line 4
Warning in TTree::ReadStream: Ignoring trailing “:01:11” while reading data for branch x on line 5 … and so on
Any help on this would be very much appreciated.
Time is in HH:MM:SS but it ignores the MM:SS and plots only for Hour on X-Axis.
Thanking you!

Nawang.

Try:

{
  TTree *MyTree = new TTree("MyTree", "MyTree");
  MyTree->ReadFile("Data.txt", "time/C:value/D");
  MyTree->SetEstimate(-1);
  MyTree->SetMarkerStyle(kFullStar);
  MyTree->Draw("value:time");
}

It worked… Thank you a lot!

But, it pops up a message
Warning in TTree::ReadStream: Ignoring trailing “14:01:08” while reading data for branch value on line 2
Warning in TTree::ReadStream: Ignoring trailing " 162.04" while reading line 2

Value “162.04” is unable to plot.
May I know why is it so?

Open your data file with any editor and see what is “different” in this line as compared to another ones.

Yes, you are right!
Thank you again.
I really appreciate your help.

warm wishes,