Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loss of floating point precision when saving TCanvas as ROOT macro #16687

Open
1 task
guitargeek opened this issue Oct 15, 2024 · 0 comments
Open
1 task

Loss of floating point precision when saving TCanvas as ROOT macro #16687

guitargeek opened this issue Oct 15, 2024 · 0 comments

Comments

@guitargeek
Copy link
Contributor

guitargeek commented Oct 15, 2024

Check duplicate issues.

  • Checked for duplicates

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 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, ...).

@guitargeek 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant