TGraphErrors Bug in log scale?

Hello,

I am plotting a TMultigraph which contains 4 objects
1)Tick Blue Line with Marker --> TGraph
2)Tick Red Line with Marker --> TGraph
3)Thin Blue Line without Marker --> TGraph
4)Green band shows the error of 3) --> TGraphErrors

Then I compute using the Eval method, the intersection between the Thick Blue line and the lower edge of the green band (It is the Thin blue line - 15% Error). If I do this, I find an intersection point of 382GeV/c².
Note, that Eval is used as a linear interpolator (no spline used here)

Then I’ve plotted the TMultigraph both in log and in linear scale.
As you can see it, the displayed intersection point in the log scale (left of the attachement) is obviously incompatible with the previous computation. In the linear scale plot, everything seem to be Ok.
However, I absolutely need the log scale version of this plot (since I need to add more line on it that have different y scale).

Can you please advice me on how to solve this problem…
I am using ROOT5.22/00d and can hardly use an other version, since I’d like to tick to the CMSSW root version.


see an example below

Rene

void gerrors2() {
   //Draw two graphs with error bars
   // To see the output of this macro, click begin_html <a href="gif/gerrors2.gif">here</a>. end_html
   //Author: Rene Brun
   
   TCanvas *c1 = new TCanvas("c1","gerrors2",200,10,700,500);
   c1->SetFillColor(42);
   c1->SetGrid();
   TMultiGraph *mg = new TMultiGraph();
      // create first graph
   const Int_t n1 = 10;
   Double_t x1[]  = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
   Double_t y1[]  = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};
   Double_t ex1[] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05};
   Double_t ey1[] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8};
   TGraphErrors *gr1 = new TGraphErrors(n1,x1,y1,ex1,ey1);
   gr1->SetMarkerColor(kBlue);
   gr1->SetMarkerStyle(21);
   mg->Add(gr1);
   //gr1->Draw("LP");

      // create second graph
   const Int_t n2 = 10;
   Float_t x2[]  = {-0.28, 0.005, 0.19, 0.29, 0.45, 0.56,0.65,0.80,0.90,1.01};
   Float_t y2[]  = {0.82,3.86,7,9,10,10.55,9.64,7.26,5.42,2};
   Float_t ex2[] = {.04,.12,.08,.06,.05,.04,.07,.06,.08,.04};
   Float_t ey2[] = {.6,.8,.7,.4,.3,.3,.4,.5,.6,.7};
   TGraphErrors *gr2 = new TGraphErrors(n2,x2,y2,ex2,ey2);
   gr2->SetMarkerColor(kRed);
   gr2->SetMarkerStyle(20);
   mg->Add(gr2);
   mg->SetMinimum(0.1);
   mg->Draw("alp");
   
   TCutG *cutg = new TCutG("CUTG",8);
   cutg->SetFillColor(3);
   cutg->SetFillStyle(3001);
   cutg->SetPoint(0,-0.2072271,10.66425);
   cutg->SetPoint(1,-0.307333,9.796366);
   cutg->SetPoint(2,-0.2883941,8.270086);
   cutg->SetPoint(3,1.007572,0.2197083);
   cutg->SetPoint(4,1.099561,1.147447);
   cutg->SetPoint(5,1.075211,3.182487);
   cutg->SetPoint(6,-0.1801715,10.48469);
   cutg->SetPoint(7,-0.2072271,10.66425);
   cutg->Draw("f");
}

Hi René,

First, thanks a lot for your answer… but, can you be a bit more explicit?
Is this a known bug of TGraphError? or is it me that is badly using it?

Then about the TCutG, it is indeed a nice quick work around, but computing the primitive vertices is not so convenient… is there any better way ? or there is maybe some function that can return me the vertices starting from a TGraphError?

Thanks again,
Loic

To find out what is wrong, I would need the shortest piece of code reproducing your problem.

Rene

Ok… I will send you a reduced .C in few minutes…
I tried to use a TCutG, but looks like the problem is not actually the Error band, but whell the line themselve.

Please, look at the Intersection point between the Thin and the Thick blue line…
It is once around 370GeV (LogScale) and once around 390GeV(Linear Scale)

I can not understand something of that kind…

Loic,


Here is a .C reproducing the bug

{
//=========Macro generated from canvas: c1/c1
//=========  (Tue Aug 24 15:37:06 2010) by ROOT version5.22/00d
   TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
   gStyle->SetOptFit(1);
   c1->Range(290,5,410,60);
   c1->SetFillColor(0);
   c1->SetBorderMode(0);
   c1->SetBorderSize(2);
   c1->SetGridx();
   c1->SetGridy();
   c1->SetTickx(1);
   c1->SetTicky(1);
   c1->SetLeftMargin(0.12);
   c1->SetRightMargin(0.18); 
   c1->SetTopMargin(0.06);
   c1->SetFrameFillStyle(0);
   c1->SetFrameBorderMode(0);
   c1->SetFrameFillStyle(0);
   c1->SetFrameBorderMode(0);
   
   TMultiGraph *multigraph = new TMultiGraph();
   multigraph->SetName("");
   multigraph->SetTitle("");
   
   TGraph *graph = new TGraph(6);
   graph->SetName("Graph");
   graph->SetTitle("");
   graph->SetFillColor(1);
   graph->SetLineColor(4);
   graph->SetMarkerColor(4);
   graph->SetMarkerStyle(20);
   graph->SetPoint(0,200,606);
   graph->SetPoint(1,300,57.2);
   graph->SetPoint(2,400,8.98);
   graph->SetPoint(3,500,1.87);
   graph->SetPoint(4,600,0.465);
   graph->SetPoint(5,900,0.0128);
   
   TH1 *Graph14 = new TH1F("Graph14","",100,130,970);
   Graph14->SetMinimum(0.01152);
   Graph14->SetMaximum(666.5987);
   Graph14->SetDirectory(0);
   Graph14->SetStats(0);
   Graph14->SetLineStyle(0);
   Graph14->SetMarkerStyle(20);
   Graph14->GetXaxis()->SetNdivisions(509);
   Graph14->GetXaxis()->SetLabelFont(42);
   Graph14->GetXaxis()->SetLabelOffset(0.007);
   Graph14->GetXaxis()->SetLabelSize(0.05);
   Graph14->GetXaxis()->SetTitleOffset(1.1);
   Graph14->GetXaxis()->SetTitleFont(42);
   Graph14->GetYaxis()->SetLabelFont(42);
   Graph14->GetYaxis()->SetLabelOffset(0.007);
   Graph14->GetYaxis()->SetLabelSize(0.05);
   Graph14->GetYaxis()->SetTitleOffset(1.35);
   Graph14->GetYaxis()->SetTitleFont(42);
   Graph14->GetZaxis()->SetLabelFont(42);
   Graph14->GetZaxis()->SetLabelOffset(0.007);
   Graph14->GetZaxis()->SetLabelSize(0.05);
   Graph14->GetZaxis()->SetTitleFont(42);
   graph->SetHistogram(Graph14);

   multigraph->Add(graph,"L");

   graph = new TGraph(6);
   graph->SetName("Graph");
   graph->SetTitle("");
   graph->SetFillColor(4);
   graph->SetLineColor(4);
   graph->SetLineWidth(2);
   graph->SetMarkerColor(4);
   graph->SetMarkerStyle(20);
   graph->SetPoint(0,200,23.70605);
   graph->SetPoint(1,300,18.35938);
   graph->SetPoint(2,400,14.23828);
   graph->SetPoint(3,500,11.99707);
   graph->SetPoint(4,600,11.51855);
   graph->SetPoint(5,900,16.25977);

   TH1 *Graph815 = new TH1F("Graph815","",100,130,970);
   Graph815->SetMinimum(10.2998);
   Graph815->SetMaximum(24.9248);
   Graph815->SetDirectory(0);
   Graph815->SetStats(0);
   Graph815->SetLineStyle(0);
   Graph815->SetMarkerStyle(20);
   Graph815->GetXaxis()->SetTitle("A");
   Graph815->GetXaxis()->SetNdivisions(509);
   Graph815->GetXaxis()->SetLabelFont(42);
   Graph815->GetXaxis()->SetLabelOffset(0.007);
   Graph815->GetXaxis()->SetLabelSize(0.05);
   Graph815->GetXaxis()->SetTitleOffset(1.1);
   Graph815->GetXaxis()->SetTitleFont(42);
   Graph815->GetYaxis()->SetTitle("CrossSection [ Pb ]");
   Graph815->GetYaxis()->SetLabelFont(42);
   Graph815->GetYaxis()->SetLabelOffset(0.007);
   Graph815->GetYaxis()->SetLabelSize(0.05);
   Graph815->GetYaxis()->SetTitleOffset(1.7);
   Graph815->GetYaxis()->SetTitleFont(42);
   Graph815->GetZaxis()->SetLabelFont(42);
   Graph815->GetZaxis()->SetLabelOffset(0.007);
   Graph815->GetZaxis()->SetLabelSize(0.05);
   Graph815->GetZaxis()->SetTitleFont(42);
   graph->SetHistogram(Graph815);

   multigraph->Add(graph,"LP");
   multigraph->Draw("A");
   multigraph->GetXaxis()->SetTitle("m (GeV/c^{2})");
//   multigraph->GetXaxis()->SetRange(17,32);
   multigraph->GetXaxis()->SetNdivisions(509);
   multigraph->GetXaxis()->SetLabelFont(42);
   multigraph->GetXaxis()->SetLabelOffset(0.007);
   multigraph->GetXaxis()->SetLabelSize(0.05);
   multigraph->GetXaxis()->SetTitleOffset(1.1);
   multigraph->GetXaxis()->SetTitleFont(42);
   multigraph->GetYaxis()->SetTitle("#sigma (pb)");
   multigraph->GetYaxis()->SetLabelFont(42);
   multigraph->GetYaxis()->SetLabelOffset(0.007);
   multigraph->GetYaxis()->SetLabelSize(0.05);
   multigraph->GetYaxis()->SetTitleOffset(1.7);
   multigraph->GetYaxis()->SetTitleFont(42);
   multigraph->GetYaxis()->SetRangeUser(5,60);
   multigraph->GetXaxis()->SetRangeUser(290,410);
   c1->Modified();
   c1->cd();

   c1->SetSelected(c1);

   c1->SaveAs("TMP_LIN.png");
   c1->SetLogy(true);
   c1->SaveAs("TMP_LOG.png");


}

Thanks for any help…
This is relatively urgent,

Loic,

Any idea?

Hello,

Can you please tell me the status of the investigations?
Are you able to reproduce the problem using the code snippet I send?

Thanks in advance,
Loic,

It is likely that you sent a wrong file. I do not see any place where you draw the green band.
Olivier will follow.

Rene

I have simplified the problem as much as possible…
So the green band have been removed… only two line from TGraph are present
But the problem is still there…

The intersection of the lines occurs at different X value when being in Y log scale or in Y linear scale.
This is completely impossible, the intersection of two lines in a plane can not depend on the way we are representing these lines…

This is a dramatic problem

In attachement, is what you are suppose to reproduce…

Loic,


I am investigating…

I understand the problem. Your two graphs have only 6 points. You draw them using the option line. When a graph is drawn in log scale only the points belonging to the graph are converted in log scale (in your case 6 points for each graph). The intermediate points belonging to the connecting line are simply linear. Because of the small number of points you have, the linear connection between the points is not meaningful, and therefore the intersection point is not the same in linear and log scale.
In the attached images I have drawn the points as markers. On the blue plots you can see that these points do not move when you go to log scale. On the red plot I have added a 7th point close to the intersection point in both graphs. You can see it does not move either.








Ok,
I still think it is a bug in the display,
It would be more meaningful to use a linear interpolation between the points in linear scale and to use a log linear interpolation when using a log scale. That would avoid such problems…

So, I a understand correctly, a simple fix to my problem would be to add more points on my Graph (for instance using the Eval method to populate it with additional points…)

Is that correct?

Anyhow, thanks a lot for the investigations
Loic,

Yes … or do not use the LINE option …