I’d like to draw the TGraph in the attached files into pdf files.
It appears the last TGraph (named “PtEtaBins_sub0_mR_0_4”) does not appear in the output pdf file when doing :
All,
Thanks, this was indeed the issue !
I didn’t notice the nan in the visual, since the last value simply appeared to be out of the frame and that could be expected in this case.
It’s surprising the pdf output behaves differently than other outputs though… May I humbly suggest this is harmonized or that a clear warning is displayed in this case ? (I’m happy to submit a ticket if it helps)
In the case of pdf I do see the graph. In my case the final point is clipped. It is very difficult to predict what will be the behavior of a computation involving NaN. What you are asking would imply to test all the graph values against NaN which might be a big penalty for all the graphs containing only good values. We think it is the responsibility of the user to check the validity of numbers put in graphs histograms etc … Note also that, in your case, the fact the two outputs behaved differently pointed something was wrong. You may have never noticed it otherwise.
Ok, fair enough !
But just by curiosity, the ROOT graphic stacks decides to set the nan point at +infinity (and draw the line to there), so it must be somehow aware of the nan ? Maybe issuing a warning there would help ?
No, nothing is “decided” … The graphics backend for screen and pdf are different that’s why you might see different things on screen and pdf output (or not). Also that sort of thing is very machine dependant… So the only thing we can say for sure, is that the result is unpredictable.
Well, this example was actually extracted from a set of pyroot scripts producing hundreds of plots : in these conditions it’s difficult to understand if your “GO” is due to “GI” or a bug in the (huge) set of code producing the output
Now it seems to me the graphic backend “decides” where to draw the nan in TPad::YtoPixel … is it possible to check for a nan there ? a warning there could be a useful indication, but from the previous answers, I understand it might be too costly or not appropriate ?
The method YtoPixel simply does a simple computation to transform the Y value into Pixel value. That’s simple arithmetic . If you give it a NaN or an Inf it will return some unpredictable value as would any computing in any program.
Basically you are asking we call TMath::IsNaN() for you… It is not possible. That’s to costly. As I said it is up to you (or the program filling the TGraph) to make sure it is not filling the TGraph with garbage values.
ROOT provides all the tools to make that sort of test.
Moreover … why should it be done on the Graphics side ? … you can also imagine to do it earlier at the SetPoint() time ? … But there also it far more to costly ! this will penalise users who are carefully testing the validity of there data … And that’s not only that: if we test for NaN why not testing for Inf ? … Etc … Etc …
indeed, that’s why I wrote decides into quotes. But I get your arguments. I was trying to find an ideal place where those nan could be detected, and I realize there’s probably none…
That is weird…
At some point this graph must be filled … That’s the place to call IsNaN …
I understand you do not have access to the place the graph is filled ?
No, no I meant : no ideal place within ROOT.
There’s always the case where you receive the data from a code you can’t /don’t want to touch, but I now understand it’s probably not possible for ROOT to do the garbage sorting job…
Cheers,
P-A
If you are not confident into the data (graphs) you are receiving from the 3rd party program, you can always make a small utility scanning the graphs (basically a loop over all the points) to detect NaN Inf etc …
void IsGraphValid(TGraph *g) {
int n = g->GetN();
double x,y;
for (int i=0; i<n; i++) {
g->GetPoint(i,x,y);
if (TMath::IsNaN(x)) printf("x[%d] is a NaN\n",i);
if (TMath::IsNaN(y)) printf("y[%d] is a NaN\n",i);
}
}
Example:
$ root test.root
------------------------------------------------------------------
| Welcome to ROOT 6.19/01 https://root.cern |
| (c) 1995-2019, The ROOT Team; conception: R. Brun, F. Rademakers |
| Built for macosx64 on Aug 23 2019, 12:28:37 |
| From heads/master@v6-19-01-984-g389f0c87c6 |
| Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------------
root [0]
Attaching file test-4.root as _file0...
(TFile *) 0x7fd4e5ced300
root [1] auto g = (TGraphErrors*)_file0->Get("PtEtaBins_sub0_mR_0_4")
(TGraphErrors *) @0x7ffeef0ab638
root [2] .x IsGraphValid.C(g)
y[10] is a NaN
root [3]