You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Floating point precision should be preserved when saving plots as ROOT macros with TCanvas::SaveAs(). This can probably be achieved with not too much effort using std::setprecision: https://en.cppreference.com/w/cpp/io/manip/setprecision
Reproducer
Run this code, which works fine:
TCanvas *c = new TCanvas("c", "c");
TH1D *histo = new TH1D("histo", "histo", 1, 595780500.110732, 595780531.878908);
histo->Draw();
c->SaveAs("plot.C");
The resulting macro will not preserve the precision on the floating point numbers:
TH1D *histo__1 = new TH1D("histo__1","histo",1,5.957805e+08,5.957805e+08);
And you'll get an error when running it:
Processing plot.C...
Error in <TCanvas::Range>: illegal world coordinates range: x1=595780500.000000, y1=-0.131250, x2=595780500.000000, y2=1.181250
Error in <TCanvas::RangeAxis>: illegal axis coordinates range: xmin=595780500.000000, ymin=0.000000, xmax=595780500.000000, ymax=1.050000
root [1] Error in <TCanvas::Range>: illegal world coordinates range: x1=595780500.000000, y1=-0.131250, x2=595780500.000000, y2=1.181250
Error in <TCanvas::RangeAxis>: illegal axis coordinates range: xmin=595780500.000000, ymin=0.000000, xmax=595780500.000000, ymax=1.050000
ROOT version
------------------------------------------------------------------
| Welcome to ROOT 6.32.06 https://root.cern |
| (c) 1995-2024, The ROOT Team; conception: R. Brun, F. Rademakers |
| Built for linuxx8664gcc on Sep 21 2024, 18:21:53 |
| From tags/6-32-06@6-32-06 |
| With g++ (GCC) 13.3.0 |
| Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------------
Installation method
Nix
Operating system
NixOS (Linux)
Additional context
Can easily happen in the analysis of timeseries, where one often has large axis values because they represent time with respect to some reference point far back in time (e.g. astrophysics, finance, ...).
The text was updated successfully, but these errors were encountered:
guitargeek
changed the title
Don't lose floating point precision when saving TCanvas as ROOT macro
Loss of floating point precision when saving TCanvas as ROOT macro
Oct 15, 2024
Check duplicate issues.
Description
Floating point precision should be preserved when saving plots as ROOT macros with
TCanvas::SaveAs()
. This can probably be achieved with not too much effort usingstd::setprecision
:https://en.cppreference.com/w/cpp/io/manip/setprecision
Reproducer
Run this code, which works fine:
The resulting macro will not preserve the precision on the floating point numbers:
And you'll get an error when running it:
ROOT version
Installation method
Nix
Operating system
NixOS (Linux)
Additional context
Can easily happen in the analysis of timeseries, where one often has large axis values because they represent time with respect to some reference point far back in time (e.g. astrophysics, finance, ...).
The text was updated successfully, but these errors were encountered: