Issue drawing points on TGraph2D - code/data/images attached

Hi,

I’m having an issue plotting TPolyMarker3D points on a TGraph2D, and have provided a macro and data file which shows how to reproduce the issue.

There are two functions in the code, demo1() plots the data using TPolyMarker3D points on an existing graph – this is where I see an issue. For comparison, demo2() plots the same data directly using the TGraph2D constructor.

In demo1 I create and Draw(“p”) a TGraph2D with two initial reference points, where these points are essentially used to define the axis ranges. The axis ranges here are intentionally greater than for demo2.

In each demo I read in a text file which contains x/y/z coordinates of 10 points and plot them.

I am having three issues here, all related to the method of drawing TPolyMarker3D points.

First, there is an extra point appearing at 0,0,0 which I did not draw. It is not one of the ten points from the file, and not one of the two reference points. See attached image Issue1 – you can see the extra point I did not draw.
Second, usually the point at –1,-1,-1 does not appear – but it can sometimes appear upon rotation. See attached image Issue2 – note the black point at –1,-1,-1 which does not appear in the first image attachment.

Third, occasionally upon execution of the function, another unexpected data point appears. See attached image Issue3 – there is another data point I did not draw. The x and z coordinates of this extra point are 0, however I cannot tell the y coordinate since it disappears upon rotation of the image (see attached image Issue3a – you can see the point is just outside the axes – if I rotate any further it disappears altogether)

I am using root 5.34/05 on OS X 10.8.2 and gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

Thanks
Peter









data.dat (269 Bytes)
demo.C (2.81 KB)

when I run you macro I get:

root [0] .L demo.C
root [1] runDemos("data.dat")
Error: Symbol vector<TPolyMarker3D*>markers is not defined in current scope  demo.C:60:
*** Interpreter error recovered ***

with the following display.

Hi,
sorry I compile it first.

.L demo.C+

runDemos(“data.dat”)

ok. i see… before going further I have a question:

What is the purpose of using markers with TGraph2D as TGraph2D already draw markers ?

Are you using TGraph2D only to define the 2D space ?

Hi,

The purpose is to set the attributes (color/size/style) of individual markers in a 3D space.

In that case the following example would be better:

{
   gStyle->SetOptStat(0);

   TH3F *frame3d = new TH3F("frame3d","frame3d",10,-1,1,10,-1,1,10,-1,1);
   frame3d->Draw();

   TPolyMarker3D *pm3d1 = new TPolyMarker3D(3);
   pm3d1->SetPoint(0,1,0,0);
   pm3d1->SetPoint(1,0,1,0);
   pm3d1->SetPoint(2,0,0,1);

   pm3d1->SetMarkerSize(2);
   pm3d1->SetMarkerColor(kBlue);
   pm3d1->SetMarkerStyle(20);

   pm3d1->Draw();

   TPolyMarker3D *pm3d2 = new TPolyMarker3D(3);
   pm3d2->SetPoint(0,-1,0,0);
   pm3d2->SetPoint(1,0,-1,0);
   pm3d2->SetPoint(2,0,0,-1);

   pm3d2->SetMarkerSize(2);
   pm3d2->SetMarkerColor(kRed);
   pm3d2->SetMarkerStyle(20);

   pm3d2->Draw();
}

Hi,

OK this is interesting - I’ve been able to merge your approach with mine and it works great.

However, if I use the following code to set the markers:

[code]float* vals = new float[3];
vals[0]=x;
vals[1]=y;
vals[2]=z;

markers.push_back(new TPolyMarker3D(3,vals));[/code]

then extra points that I did not draw appear randomly on the plot.

However, if I use your approach with the SetPoint function, i.e.:

markers.push_back(new TPolyMarker3D(3)); markers.back()->SetPoint(0, x, y, z);

Then it works just fine and there are no mysterious extra points.

I’d be interested to know if you understand the difference between the two behaviours. I’ve uploaded a macro comparing the output of the functions, please try

.L demo.C+
demo(“data.data”)

I also find that repeatedly running the demo adds yet more undrawn points :confused:



data.dat (269 Bytes)
demo.C (2.29 KB)

I see you are not using TGraph2D anymore. Good.

I am not really an expert in the usage of … I started looking at your “push”“back” etc …
and then I tried to invert the way you execute your two functions Good and Bad …

If you invert the order ou get a completely different result !

The code I sent you use plain simple vectors and works…

My guess is that there is may be something wrong in your vectors manipulation as the
result depends of the order you execute the function … :frowning:

So I stopped investigating…