Nan values when saving a plot in C macro format


ROOT Version: 5.34 (But also observed with recent versions)
Platform: Linux


Hi, when I am in a TCanvas I can save my Draw-ed object in a C-macro file. Then, if everything is ok I can recover the plot in an interactive ROOT session by doing “.x plot.C”

However, sometimes, when I save the ROOT file some “nan” values are generated which are not properly understood when I execute the macro.

Have you observed something similar? There is a way to bypass this problem?

do you have a reproducer canvas I can try to save the same way and see if I get Nan too ?

Yes, I have an idea where the problem is coming from. Actually, some of the points in my TGraph contain “nan” values. This makes no problem to draw the TGraph object, but it makes a problem when saving it to a .C macro. When writing the C-macro, the range of the histogram is nan, nan.

I have saved the TCanvas in a ROOT file. I can redraw by doing

TFile *f = new TFile(“tracks.root”);
TCanvas *c = f->Get(“Event Viewer”);
c->Draw();

Then I can generate the .C macro with the problem I describe.

There is another problem, I have to replace by hand “Event Viewer” by “Event_Viewer” for the TCanvas variable name (at the beginning of the generated .C macro).

tracks.root (382.4 KB)

I see the same. Your Canvas is corrupted with NaNs. you should clean that.
From the canvas plot one can even see that the graphics behaves in a strange way:
If you click on the graphs (the blue one for instance) you see weird lines appearing. Even without clicking you can see strange vertical lines on the side of the plot. I would not trust a such plot full of NaN values.

Yes. I was always wondering what are those strange vertical lines on the side of the plot.

But what do you mean by clicking on the blue graph? Which weird lines appear? When you Left-click?

Actually, we use a 3D (X,Y,Z) description and we use NaN to identify if a hit is projected in XY, for example, (X,Y,NaN) is a projected hit on XY. I will need to check that.

Ok, I have filtered NaN values from the graph, now I don’t get any error related with that.

But I still have a problem when I generate the .C macro. I attach the new ROOT file tracks_2.root with NaN symbols corrected.

On the multigraph, the GetXaxis() is NULL.

And it ends with an illegal pointer to class object GetXaxis() 0x0 351 tracks_2.C:24991

Could you give some hints on this too?

Thanks!tracks_2.root (176.1 KB)

I see a problem because your canvas name has a white space in its name but once I have renamed it, the C macro generated with SaveAs works fine for me.

I do as follows.

TFile *f = new TFile("tracks_2.root");
TCanvas *c = (TCanvas *)f->Get("Event Viewer");
c->SetName( "evViewer");
c->Draw();

Then, I saveAs plot.C. But when I load using

.x plot.C

I still have the multigraph->GetXaxis() null pointer issue.

Is not the same for you? I am testing using ROOT 5.34

Ok. I tested on ROOT 6.10. Problem is not appearing there.

No problem for me:

 $ root
   ------------------------------------------------------------
  | Welcome to ROOT 6.17/01                  https://root.cern |
  |                               (c) 1995-2018, The ROOT Team |
  | Built for macosx64 on Nov 28 2018, 13:26:32                |
  | From heads/master@v6-16-00-rc1-135-g9b8c396d33             |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------

root [0] TFile *f = new TFile("tracks_2.root");
root [1] TCanvas *c = (TCanvas *)f->Get("Event Viewer");
root [2] c->SetName( "evViewer");
root [3] c->Draw();
root [4] c->SaveAs("plot.C")
Info in <TCanvas::SaveSource>: C++ Macro file: plot.C has been generated
root [5] .q

$ root
   ------------------------------------------------------------
  | Welcome to ROOT 6.17/01                  https://root.cern |
  |                               (c) 1995-2018, The ROOT Team |
  | Built for macosx64 on Nov 28 2018, 13:26:32                |
  | From heads/master@v6-16-00-rc1-135-g9b8c396d33             |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------

root [0] .x plot.C
root [1] 

Yep. It seems the macro generated by ROOT 6 does not produce multigraph->GetXaxis.

Thanks for the help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.