Large numbers on x-axis and problems loosing precision

Dear ROOT-forumers

I have a problem trying to use the TTimeStamp for the x-axis of my histogram. It seems to me that the problem is that the precision is lost. I typically make the x-axis from a 9-digit number that I get from the GetSec() method of TTimeStamp, making this into a float, and defining a histogram using these floats as the x-axis bin-values (I need to use floats, so that the values of the histogram and the values on the x-axis both are floats, I have understood must be required). A test-code is pasted below as an example showing the problem

>>> from ROOT import *
>>> from numpy import asarray
>>> x_list = [float(1343670783),float(1343670784),float(1343670785),float(1343670786)]
>>> x_array = asarray(x_list)
>>> h = TH1F("h","h",len(x_array)-1,x_array)
>>> h.SetBinContent(1,2)
>>> h.SetBinContent(2,4)
>>> h.Draw()
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
TCanvas::ResizePad:0: RuntimeWarning: c1 width changed from 0 to 10

TCanvas::ResizePad:0: RuntimeWarning: c1 width changed from 0 to 10

Error in <TGaxis::PaintAxis>: length of axis is 0
Error in <TGaxis::PaintAxis>: length of axis is 0
>>> TCanvas::ResizePad:0: RuntimeWarning: c1 width changed from 0 to 10

The histogram looks like the following if I make a .C file and look into it. You can see that I have not managed correctly setting the x-axis (the precision is gone).

//========= Macro generated from object: h/h
//========= by ROOT version5.30/02
   Double_t xAxis1[4] = {1.34367e+09, 1.34367e+09, 1.34367e+09, 1.34367e+09}; 
   TH1F *h = new TH1F("h","h",3, xAxis1);

How do I correctly deal with this?

Thanks a lot,

I think you need to convince ROOT to output 16 digits instead of 7 for the “double”: TCanvas::SaveSource


Yes I did try using Double instead of float but the result I get is identical. The x-axis bin-values are still represented with numbers like 1.343405e+09 and so on, so only with 6 decimal digits.

What am I not getting?




and put there:

Canvas.SavePrecision 16

or edit your:

`root-config --etcdir`/system.rootrc

and modify the line:

Canvas.SavePrecision 16

Actually, you can also get and set this variable in a C++ macro:
gEnv->GetValue(“Canvas.SavePrecision”, -1)
gEnv->SetValue(“Canvas.SavePrecision”, 16)
and/or in a python macro:
gEnv.GetValue(“Canvas.SavePrecision”, -1)
gEnv.SetValue(‘Canvas.SavePrecision’, “16”)
So, no need to modify “global” settings.

Great, thank you so much for your help. Now the numbers are represented correctly.

Have a good evening,

You can test how floating point numbers are implemented in your python (i.e. whether your python’s “float” is actually a C/C++ “double”):

>>> import sys
>>> print sys.float_info
sys.floatinfo(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.2204460492503131e-16, radix=2, rounds=1)

The above seems to suggest I should use “15”, not “16” decimal digits precision when setting “Canvas.SavePrecision”.

Anyhow, the numbers you use are 10 digits, so 10 or 11 should be sufficient for you.