As described in the title, I’m getting the line at 0 thing which I definitely did not order (and I don’t know who did!).
I’m aware of the thread ROOT 5.14 draws an horizontal line at y=0 but I’m getting the line anyway. Except, it’s only when I’m doing “something complicated”; in trying to provide a simple macro to reproduce the issue, even with the same ROOT build, the line did not appear.
If I’m reading https://root.cern.ch/root/Version515.news.html correctly, then I can only guess that somewhere down the line my “complicated” stuff somehow set the internal variable back to the erroneous state.
Ugh, it doesn’t work. I used the same methods in a dummy code but somehow no line comes up. Yet the framework-generated plots persistently have the line.
This is losing me way too much time now, may I just know which internal variable was problematic and a way to hack it to the correct state directly?
Gah I thought so. How about something more “pragmatic”; check if the line is there regardless of however it came to be, and make it invisible if so?
Or I’d also be happy with a list of things to try / watch out for for various of those sources. Might at least give a hint, hunting for something without knowing what it is is what too hard.
Certainly, here you go. Would be interesting if you can also tell why the canvas in the file doesn’t look as in pdf, when there’s absolutely no extra styling applied between saving to pdf and writing to file.
I am trying to see where it comes from editing the ROOT file… Would it be possible to have the .C macro corresponding to the Canvas ? (save the canvas as a .C file).
Well with the information you sent me before it was clear this flat parabola was in your macro. It could not appear without being explicitly ordered. I will now look at you new files.
I did more investigations using the canvas stored in one of your root file. It seems this line appears because the graph has only one point. I will make a reproduce to understand whyr. But with your code I can make the line disappeared if I do:
root cQq11_ctq1_dChi2.root
-------------------------------------------------------------------
| Welcome to ROOT 6.15/01 http://root.cern.ch |
| (c) 1995-2018, The ROOT Team |
| Built for macosx64 |
| From heads/master@v6-13-04-886-gcea240d1e8, Aug 09 2018, 11:10:02 |
| Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
-------------------------------------------------------------------
root [0]
Attaching file cQq11_ctq1_dChi2.root as _file0...
(TFile *) 0x7fd4a4da24d0
root [1] TGraph *g = (TGraph*)can->GetListOfPrimitives()->FindObject("cQq11_ctq1_sigma0_eAll");
root [2] g->SetPoint(1,0.5,-1)
root [3] g->SetPoint(2,1.5,1)
root [4] can->Draw()
Not that easy … the following macro does not show the line:
void graphwithonepoint()
{
auto g = new TGraph();
g->SetPoint(0,0.,0.);
auto h = new TH1F("h","h",10,-1,1);
h->SetMaximum(1);
h->SetMinimum(-1);
g->SetHistogram(h);
g->Draw("A*");
}
The smallest reproducer I found with your canvas is:
void lineat0()
{
auto f = new TFile("cQq11_ctq1_dChi2.root");
auto can = (TCanvas*) f->Get("can");
TGraph *g = (TGraph*)can->GetListOfPrimitives()->FindObject("cQq11_ctq1_sigma0_eAll");
auto C = new TCanvas();
g->Draw("A*");
}
Just to rule out some issue with my private build, I’ve also tried recompiling and rerunning the code with the cvmfs build, same version as above and also 6.14/02. In either case I get exactly the same result and the line stayed.
I also have tested with drawing everything except the first graph with “a” in option with " same" but still a line. Changing the order of graph that got the “a”, still a line. And annoyingly, test of reproducing with simple macro also didn’t work, that still has no line.
At least it seems not from the build. If there are ideas on what test/info I can provide, let me know.
The original graph was created and drawn when TH1::SetDefaultSumw2(kTRUE); was in action.
{
TFile *f = new TFile("lineat0.root");
TGraph *g; f->GetObject("cQq11_ctq1_sigma0_eAll", g);
TH1F *h = ((TH1F*)(g->GetHistogram())->Clone("h"));
h->SetDirectory(0); // (0) or (gROOT)
delete g;
delete f;
// h->Sumw2(kFALSE); // uncomment this line to see the black magic in action
g = new TGraph();
g->SetPoint(0, 0., 0.);
g->SetHistogram(h);
g->Draw("A*");
}
Yes the underlying histogram for the graph cQq11_ctq1_sigma0_eAll has errors. That does not really make sense as it is used to draw the frame. I can add some protection against that I guess.
Adding one point forces to recreate the histogram. In my case, as I do not have TH1::SetDefaultSumw2(kTRUE), the new histogram is “clean”.