Fwd: Making histogram from a ascii data file

From: Ivan Pulido <mefistofeles87_at_gmail.com>
Date: Fri, 8 May 2009 03:20:52 -0500


Oh sorry, this message was intented for the mailing list but I accidentally sent it only to Rene Brun. Sorry for this.

On Fri, May 8, 2009 at 1:55 AM, Rene Brun <Rene.Brun_at_cern.ch> wrote:

> Did you check that the array ydata2 is correctly filled before filling the
> histogram?

Ok I did check this and it's getting filled correctly, just one correction from the original code in the line:

while(fscanf(f,"%lf",&ydata2[i]) == 1) i++;

the format specifier should be %f and NOT %lf, after this the array ydata2 gets filled correctly. But apparently the histogram ydata is not, Im not getting anything on the canvas.

>
> Did you check that the values are in the range [0.64,1.63]?

Well I have a doubt here, in the line:
TH1F* ydata = new TH1F("ydata","times measured; Energy (q^2)",100,0.64,1.63);

0.64 and 1.63 are suppoused to be the limits for the x axis, right? so if this is the case then it's right.
On the other hand my ydata (y axis) values are different, they go approx from 4.5 to 10000. Im not sure if the parameters/values needed for the TH1F are the x limits or y limits. Please clarify this to me. Thanks for the response and attention.

NOTE: If it helps I'm attaching two text files with the data so that you can see how is my data formatted. The file Im using in the code above ("tau_ydata.dat") is there and is the one with a single column having the y axis values. The other file attached ("tau2.dat") is the one having x values in the first column and y values on the second column, just so that you see which are my limits.

>
>
> Rene Brun
>
>
> Ivan Pulido wrote:
>
>> Hi, Im trying to make a histogram from a plain text data file. I tried
>> following instructions from
>> http://root.cern.ch/drupal/content/binned-data
>>
>> The histrogram I want to make is in 1D, I try to make an array from a
>> plain text data file before filling the histogram as suggested in the site.
>> Here are the steps/instructions Im following to make this happen, please let
>> me know what is wrong. The result is just the canvas with no data in it,
>> just the axis, axis tittles and no data.
>>
>> TH1F* ydata = new TH1F("ydata","times measured; Energy
>> (q^2)",100,0.64,1.63);
>> float ydata2[100];
>> FILE * f = fopen ("tau_ydata.dat","r");
>> int i=0;
>> while(fscanf(f,"%lf",&ydata2[i]) == 1) i++;
>> for (i=0; i<100; ++i) ydata->Fill(ydata2[i]);
>> ydata->Draw();
>>
>> I must tell that the tau_ydata.dat file is read correctly and the array
>> ydata2 has the correct values, so I think the problem is filling the
>> histogram, since when I draw it Im getting nothing. Please help me on this,
>> Im new with ROOT so maybe you can point where to find the solution to this
>> or anything, maybe this is not the correct way to do it. Thanks for the
>> attention.
>>
>
>

-- 
Ivan Pulido
Estudiante de Física
Universidad Industrial de Santander



-- 
Ivan Pulido
Estudiante de Física
Universidad Industrial de Santander


  • application/octet-stream attachment: tau2.dat
Received on Fri May 08 2009 - 10:20:56 CEST

This archive was generated by hypermail 2.2.0 : Fri May 08 2009 - 11:50:01 CEST