Bug in TLine drawing when lines are too short

I have a very strange behavior (clearly a bug) when trying to draw TLines. The code is a the end of this mail, but the bottom line is : if the TLine length is too short (and the limit seems to be relative to the canvas size), it is not displayed properly.
The example below shows the display of 5 lines, the 4th one being too short, the resulting picture is in attachment and shows how the line seems to be rotated by 90 degrees.

Anybody understanding what is happening ?

Sebastien

#!/usr/bin/env python
import ROOT

data = (( 70285, 110890, 0),
        (162074, 353888, 0),
        (358982, 409845, 1),
        (717886, 717900, 1),
        (976961, 987766, 0))

c = ROOT.TCanvas('timeline','Timeline',1200,500)
c.coord = ROOT.TH2I('coord',';Time',100,0,1000000,2,0,2)
c.coord.SetStats(False)
c.coord.GetYaxis().SetNdivisions(2)

c.Draw()
c.coord.Draw()
c.lines = []
for start, end, ident in data:
      l = ROOT.TLine(start,ident + 0.4,end,ident + 0.4) 
      l.SetLineWidth(30)
      c.lines += [l]
      l.Draw()

ROOT.TLine()
c.Update()
c.SaveAs('test.png')


I transformed you code to:

void shortline()
{
   TCanvas *c = new TCanvas("timeline","Timeline",1200,500);
   TH2I *coord = new TH2I("coord",";Time",100,0,1000000,2,0,2);
   coord->SetStats(kFALSE);
   coord->GetYaxis()->SetNdivisions(10);
   coord->Draw();

   TLine *l1 = new TLine( 70285, 0.3, 110890, 0.3);
   TLine *l2 = new TLine(162074, 0.7, 353888, 0.7);
   TLine *l3 = new TLine(358982, 1.1, 409845, 1.1);
   TLine *l4 = new TLine(717886, 1.5, 717900, 1.5);
   TLine *l5 = new TLine(976961, 1.9, 987766, 1.9);

   l1->SetLineWidth(3);
   l2->SetLineWidth(3);
   l3->SetLineWidth(3);
   l4->SetLineWidth(3);
   l5->SetLineWidth(3);

   l1->Draw();
   l2->Draw();
   l3->Draw();
   l4->Draw();
   l5->Draw();

}

I see l4 missing because it is really small… is it the problem you are talking about ?

X length of l4 = 717900-717886 = 14
Number of pixels along X = 1200
X length of the axis = 1000000
l4 length in pixels = 14.*(1200./1000000.) = 0.0168000 pixels … that explain why nothing is drawn.

Nothing drawn would me more or less fine (arguable, it could be at minimal one pixel, but it’s not the problem I’m reporting).
The problem is the horizontal line that is drawn in place of nothing and screw the diagram. Look carefully at the plot I’ve posted.

Now talking of precision and pixels. Is there any way to have svg plots for example ?

[quote=“couet”]I transformed you code to:

I see l4 missing because it is really small… is it the problem you are talking about ?[/quote]

If this is working with C++, then it may be a bug in the python bindings.

I do not see anything wrong with the macro I sent. can you try ?
Yes you can save canvas as SVG

Yes, yours is working, but the one I sent (in python) is not, as you can see on the plot.
Which makes me think that it’s the python wrapping that does something wrong, as I already mentioned

Yes that could be. I let the python expert answer. I you translate le macro I sent (which is a bit different from your initial script) into python what do you get ?

Just retried your C++ before translating it to python and realized that I messed up the test the first time.
So conclusion is that C++ has the same behavior as python !
I attach here the picture I get with your code. In order to produce it, I’ve used the swan service from CERN. I wanted to attach my notebook to this message, but the board refuses it…


Sorry, forgot a small precision : I changes the LineWidth to 30 in your code.

yes I get that too … For me the lines are correct. Which one is not seems to you ?

just look at my post above, the 4th line out of 5 is not having the right width at all, and not the right length either (it’s very short in theory). I should more appear as a vertical bar, despite it’s an horizontal line.

What you see is not an horizontal line … but a very small vertical line …but VERY wide !!
What you think is the length is in fact the width !
look carefully … it is equal to the width of the others …

Ok, I can buy that, by I’m trying to draw an horizontal one ! Why is this one vertical while the others are properly horizontal ???

Which the following code I get not red line on the screen because of the pixel precision issue I explained you earlier and with pdf output I get a very thin horizontal 30 pixels wide line. For me it is correct.

[code]

void shortline()
{
TCanvas *c = new TCanvas(“timeline”,“Timeline”,1200,500);
TH2I *coord = new TH2I(“coord”,";Time",100,0,1000000,2,0,2);
coord->SetStats(kFALSE);
coord->GetYaxis()->SetNdivisions(10);
coord->Draw();

TLine *l1 = new TLine( 70285, 0.3, 110890, 0.3);
TLine *l2 = new TLine(162074, 0.7, 353888, 0.7);
TLine *l3 = new TLine(358982, 1.1, 409845, 1.1);
TLine *l4 = new TLine(717886, 1.5, 717900, 1.5);
TLine *l5 = new TLine(976961, 1.9, 987766, 1.9);

l1->SetLineWidth(30); l1->SetLineColor(kBlue);
l2->SetLineWidth(30); l2->SetLineColor(kBlue);
l3->SetLineWidth(30); l3->SetLineColor(kBlue);
l4->SetLineWidth(30); l4->SetLineColor(kRed);
l5->SetLineWidth(30); l5->SetLineColor(kBlue);

l1->Draw();
l2->Draw();
l3->Draw();
l4->Draw();
l5->Draw();
}[/code]
timeline.pdf (13.2 KB)


??? Just plugged your code into swan and got a red line…
One precision though, I had to add a “c->Draw();” at the end.

so now the question is : what is the difference between your environment and the swan one (or the LCG86 one which gives me the same).


I understand now. I can reproduce it on my desktop with:

void shortline()
{
   TCanvas *c = new TCanvas("timeline","Timeline",1200,500);
   TH2I *coord = new TH2I("coord",";Time",100,0,1000000,2,0,2);
   coord->SetStats(kFALSE);
   coord->GetYaxis()->SetNdivisions(10);
   coord->Draw();

   TLine *l1 = new TLine( 70285, 0.3, 110890, 0.3);
   TLine *l2 = new TLine(162074, 0.7, 353888, 0.7);
   TLine *l3 = new TLine(358982, 1.1, 409845, 1.1);
   TLine *l4 = new TLine(717886, 1.5, 717900, 1.5);
   TLine *l5 = new TLine(976961, 1.9, 987766, 1.9);

   l1->SetLineWidth(30); l1->SetLineColor(kBlue);
   l2->SetLineWidth(30); l2->SetLineColor(kBlue);
   l3->SetLineWidth(30); l3->SetLineColor(kBlue);
   l4->SetLineWidth(30); l4->SetLineColor(kRed);
   l5->SetLineWidth(30); l5->SetLineColor(kBlue);

   l1->Draw();
   l2->Draw();
   l3->Draw();
   l4->Draw();
   l5->Draw();
   c->Print("c.png");
}

then running root with:

root -b shortline.C

The red line appears “horizontal” instead of “vertical”.

Good ! was was the difference ? I do not spot it.

It is now fix edin the master.

(I just added a Print as png at the end)

Hi,
about which version of root are you talking?
I see different behaviour with 5.34.36
The following is with 6.08.01 (exact version in top of macro)
to demonstrate what happens I modified the macro:

  • increase length of the short line l4: 14->214
  • zoom into canvas to the maximum possible: wx = 10000
    Now the red line becomes visible on my screen (1920x1080)

Olivier:
Is this maximum 10000 something magic or could it be
increased given that modern WS have huge memories?

Cheers
Otto



shortline.C (1000 Bytes)