Autorange on a histogram does not work

Hello All,

I have a plain-text histogram file with x-values and their frequency. I am trying to load that into a root histogram as follows:

[code]float location,b;
int frequency=0,loop=0;

TH1F *h = new TH1F("h","h",1000,1,1);

while (!feof(datafile)){
	fscanf(datafile,"%f %i",&location,&frequency);
	for (loop=0;loop<frequency;loop++) h->Fill(location);
}[/code]

From the root manual, I have set the lower axis value lessthan or equal to the higher axis value for auto-range. However, the histogram does not have the correct ranges. What am I doing wrong?

Root code, the histogram plain text data and a matlab generated histogram (showing the correct range) are attached.

Thanks,
Karthik.
files.zip (14.3 KB)

Hi,

You must ‘h->BufferEmpty();’ after being done filling, do flush the filling and calculated the boundaries.

Cheers,
Philippe.

Hello

Can you please explain what you mean by “do flush the filling and calculated the boundaries”. ?

I cannot see a flush method.

Thanks.

[quote=“pcanal”]Hi,

You must ‘h->BufferEmpty();’ after being done filling, do flush the filling and calculated the boundaries.

Cheers,
Philippe.[/quote]

Hi,

You must call the routine:h->BufferEmpty();to do the flushing I am talking about … See root.cern.ch/root/html/TH1.html#TH1:BufferEmpty.

Cheers,
Philippe.