Errors plotting with TGraph2D and setting axis titles

Hi
In a macro, I have:

TGraph2D *tg = new TGraph2D(); ... for-loop tg->SetPoint(n++,t->getX(),t->getY(),t->getZ()); end for-loop ... tg->SetTitle(title); tg->Draw("PCOL"); tg->GetXaxis()->SetTitle("X in meters"); tg->GetYaxis()->SetTitle("Y in meters"); tg->GetZaxis()->SetTitle("Z in meters");
When I run this macro, I get spewing errors of
Warning in TGraphDelaunay::Interpolate: Two of these three points are coincident 26 13 3
Error in TGraphDelaunay::Interpolate: Point outside hull when expected inside: this point could be dodgy 0.4885 0.4635 3276

And the plot does look skewed.

But when I comment out the following code from the above code:

tg->GetXaxis()->SetTitle("X in meters"); tg->GetYaxis()->SetTitle("Y in meters"); tg->GetZaxis()->SetTitle("Z in meters");
then the spewing stops, and the plot no longer looks skewed. Only now I’ve got no lables on the axis. And it’s not just the setting of the titles of the axis that produces spewing of those errors and producing skewed plots, it whenever I try to set any attributes to any of the axis (e.g. SetLabelSize, SetTitleSize, etc).

Any advice to what am I doing wrong here? Thanks!

that’s weird. can you sent a macro reproducing the problem ?

Here’s the macro:

#include "TFile.h"
#include "TTree.h"
#include "TBrowser.h"
#include "TH2.h"
#include "TRandom.h"
#include "TClassTable.h"
#include "TSystem.h"
#include "TROOT.h"
#include <iomanip>
#if defined(__CINT__) && !defined(__MAKECINT__) 
#include "../../../src/root-cern/libMyEvent.so"
#else 
#include "MyEvent.h"
#endif

using namespace std;

void PlotFusedNode(const Double_t &time, const Int_t &fusedNodeID);


// fusedNodeID corresponds to PathID in the data
void PlotFusedNode(const Double_t &time, const Int_t &fusedNodeID) {

  // don't bother resetting since it sometimes causes crashes.
  // gROOT->Reset();

  // check to see if the event class is in the dictionary
  // if it is not load the definition in libMyEvent.so
  if (!TClassTable::GetDict("MyEvent")) {
    gSystem->Load("libMyEvent");
  } 

  TFile *f = new TFile("mytree.root");
  TTree *tr = (TTree*)f->Get("tr"); 
  // create a pointer to an event object. This will be used
  // to read the branch values.
  REvent *event = new REvent(); 

  // get branch and set the buffer address
  TBranch *branch = tr->GetBranch("EventBranch");
  branch->SetAddress(&event);

  // first locate event
  Long64_t nevent = tr->GetEntries();
  bool foundEvt=false;
  for (Long64_t i=0;i<nevent;i++) { 
    // read complete given event in memory
    branch->GetEntry(i);

    if (event->getTime()==time) {
      foundEvt=true;
      break;
    }
  }

  if (!foundEvt) {
    cout << "Error: Failed to find event with time=" << setprecision(20)
	   << time << endl;
    return;
  }

  // get list of nodes in this event
  TClonesArray *path=event->getPaths();
  // now find the desired path (or fusedNode) by nodeID
  TObject *myp=new RPath();
  RPath *tmp=dynamic_cast<RPath*>(myp);
  // set pathID to find
  tmp->setPathID(fusedNodeID);
  RPath *pptr=path->FindObject(myp);

  if (pptr) {
    TGraph2D *tg = new TGraph2D();
    cout << "Found pathID=" << pptr->getPathID() << endl;
    Int_t n=0;
    size_t nNodes=pptr->getNumOfNodes();
    cout << "There are " << nNodes << " nodes in path/fused id="
	   << fusedNodeID << endl;
    TRefArray *node=pptr->getNodes(); 
    for (size_t j=0; j<nNodes; ++j) {
      RNode *nd=dynamic_cast<RNode *>(node->At(j));
      size_t ntrks=nd->getNtrks();
      cout << "NodeID=" << nd->getNodeID() << " has " 
	     << ntrks << " tracks" << endl;
      TClonesArray *trk=nd->getTrks();

      for (size_t k=0; k<ntrks; ++k) {
	RTrk *t=dynamic_cast<RTrk *>(trk->At(k));
	cout << "DataPt " << k << setprecision(10) << ") x=" << t->getX()
	       << " y=" << t->getY() << " time=" << t->getTime() 
	       << " sec" << endl;
	// use the nodeID as the z point
	tg->SetPoint(n++,t->getX(),t->getY(),nd->getNodeID());
	tg->SetLineStyle(2); // lines between trks in node
      } // for close k
    } // for close j

    tg->SetMarkerStyle(8);
    TCanvas *c1 = new TCanvas("c1","c1");
    char title[200];
    snprintf(title,sizeof(title),
	     "SrcTrkNodes(w/DataPts) assoc w/Fused NodeID=%u at frame time=%.2f sec",
	     fusedNodeID,time);
    tg->SetTitle(title);
    tg->Draw("PCOL LINE");
    tg->GetXaxis()->SetLabelSize(0.02);
    tg->GetYaxis()->SetLabelSize(0.02);
    tg->GetZaxis()->SetLabelSize(0.02);

    tg->GetXaxis()->SetTitleSize(0.02);
    tg->GetXaxis()->SetTitle("X in meters");
    tg->GetXaxis()->SetTitleOffset(3);
    tg->GetYaxis()->SetTitle("Y in meters");
    tg->GetYaxis()->SetTitleSize(0.02);
    tg->GetZaxis()->SetTitle("Source trk NodeID")
  }
  else {
    cout << "Error: Failed to find fused node="<< fusedNodeID 
	 << setprecision(20) << " at time="
	 << time << endl;
    return;
  }

  return;
}

One is NOT able to use your macro to “reproduce” the problem -> “…/…/…/src/root-cern/libMyEvent.so” and “MyEvent.h” are missing.

Wile is right. Post something as simple as possible, we can run, and reproducing the problem.

[quote=“couet”][quote]
One is NOT able to use your macro to “reproduce” the problem
[/quote]

Wile is right. Post something as simple as possible, we can run, and reproducing the problem.[/quote]

I’m going to have to write something else that reproduces this problem, because the data structure is large and I wouldn’t be able to just attached the root file to this forum. So do I therefore also attach a code that generates the root file so you can reproduce the problem?

We only need a macro reproducing the problem. You can use fake data.

Hi,
I attached the macro in this post that reproduces this problem. For this simplified version, it doesn’t seem to produce the spewing but clearly the plot is corrupted. Just execute the macro in root. The current macro has commented out the lines that causes problems so you can see how the plot looks like when not corrupted:

#if 0  // comment out below and the plot won't be corrupted.
 tg->GetXaxis()->SetLabelSize(0.02);
 tg->GetYaxis()->SetLabelSize(0.02);
 tg->GetZaxis()->SetLabelSize(0.02);
   
 tg->GetXaxis()->SetTitleSize(0.02);
 tg->GetXaxis()->SetTitle("X in meters");
 tg->GetXaxis()->SetTitleOffset(3);
 tg->GetYaxis()->SetTitle("Y in meters");
 tg->GetYaxis()->SetTitleSize(0.02);
 tg->GetZaxis()->SetTitle("Source trk NodeID");
#endif

Removing the “#if 0 && #endif” and re-executing the macro should reproduce the problem.
plot3DScatter.C (1.99 KB)

I see the problem. I am investigating.

now fixed in the SVN trunk and in v.5-34.
Thanks for reporting.

[quote=“couet”]now fixed in the SVN trunk and in v.5-34.
Thanks for reporting.[/quote]

I checked out the svn repository:
svn co root.cern.ch/svn/root/trunk root

and cd to ‘root’, but all I see there in that directory are cmake files and scripts. There’s no source code. How can I build without the code? Is there a svn repository to get the most recent changes but not have to build with cmake? I prefer just to run configure/make…

I do see this printout when I svn co above:
svn: REPORT of ‘/svn/root/!svn/vcc/default’: 200 OK (root.cern.ch)

Is that an error and probably an indication why I didn’t get the source code?

thanks!

Hi Couet,
So I figured out how to download the code. I verified that I picked up your changes in the svn log but I still see the plot corrupted when I comment out the #if 0 /#endif in the script.

I attached is the plot (NotCorrupted.pdf) of how it looks like when I keep the following code (with #if 0) kept:

#if 0  // comment out below and the plot won't be corrupted.
 tg->GetXaxis()->SetLabelSize(0.02);
 tg->GetYaxis()->SetLabelSize(0.02);
 tg->GetZaxis()->SetLabelSize(0.02);
   
 tg->GetXaxis()->SetTitleSize(0.02);
 tg->GetXaxis()->SetTitle("X in meters");
 tg->GetXaxis()->SetTitleOffset(3);
 tg->GetYaxis()->SetTitle("Y in meters");
 tg->GetYaxis()->SetTitleOffset(3);
 tg->GetYaxis()->SetTitleSize(0.02);
 tg->GetZaxis()->SetTitle("Source trk NodeID");
 #endif

Then when I remove the #if 0 and #endif, the plot looks like attached Corrupted.pdf.
Corrupted.pdf (33.5 KB)
NotCorrupted.pdf (15.4 KB)

Have you reinstalled root ?
which root are you running ?

check what the command “which root” gives you …

[quote=“couet”][quote]
but I still see the plot corrupted
[/quote]

Have you reinstalled root ?
which root are you running ?

check what the command “which root” gives you …[/quote]

Yes, I installed root to /usr/local/bin:
$ which root
/usr/local/bin/root
And it’s definitely just built late last night:
$ ls -l /usr/local/bin/root
-rwxrwxr-x 1 jade jade 27995 Oct 16 01:00 /usr/local/bin/root

When I startup root, I see the graphcial logo that appears at startup noting at the lower lefthand corner:
Version 5.99/01

I know I’m definitely running the newest one because the old root sits at /usr/bin/root and when I start that one up, it notes Version 5.30/06 on the startup logo.

For BOTH your “ROOT installations”, try (inspect absolute paths of all libraries reported by “ldd”):
root-config --bindir
ldd root-config --bindir/root.exe
root-config --libdir
ldd root-config --libdir/libTree.so
root-config --etcdir
BTW. You MUST have different “etcdir” for different “ROOT installations”.

[quote=“Wile E. Coyote”]For BOTH your “ROOT installations”, try (inspect absolute paths of all libraries reported by “ldd”):
root-config --bindir
ldd root-config --bindir/root.exe
root-config --libdir
ldd root-config --libdir/libTree.so
root-config --etcdir
BTW. You MUST have different “etcdir” for different “ROOT installations”.[/quote]

OK, so this is what I have:
$ ldd root-config --bindir/root.exe
linux-vdso.so.1 => (0x00007fffea7ff000)
libCore.so => /usr/lib64/root/libCore.so (0x0000003bd3600000)
libRint.so => /usr/lib64/root/libRint.so (0x0000003bd6000000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00000032ec400000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00000032ea800000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00000032ea400000)
libc.so.6 => /lib64/libc.so.6 (0x00000032e9800000)
libz.so.1 => /lib64/libz.so.1 (0x0000003bd2200000)
liblzma.so.5 => /usr/lib64/liblzma.so.5 (0x0000003bfe400000)
libpcre.so.0 => /lib64/libpcre.so.0 (0x000000330be00000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00000032f6000000)
libCint.so.5.30 => /usr/lib64/root/libCint.so.5.30 (0x00000032ed000000)
libdl.so.2 => /lib64/libdl.so.2 (0x00000032ea000000)
libm.so.6 => /lib64/libm.so.6 (0x00000032e9c00000)
/lib64/ld-linux-x86-64.so.2 (0x00000032e9400000)
librt.so.1 => /lib64/librt.so.1 (0x00000037d2200000)
libfreebl3.so => /lib64/libfreebl3.so (0x00000032f6400000)

$ ldd root-config --libdir/libTree.so
linux-vdso.so.1 => (0x00007fff0cbff000)
libNet.so => /usr/lib64/root/libNet.so (0x00007f7c5be2c000)
libRIO.so => /usr/lib64/root/libRIO.so (0x00007f7c5ba3b000)
libThread.so => /usr/lib64/root/libThread.so (0x00007f7c5b7e7000)
libCore.so => /usr/lib64/root/libCore.so (0x00007f7c5ae66000)
libCint.so => /usr/lib64/root/libCint.so (0x00007f7c5a4e1000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f7c5a1d9000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f7c59fc4000)
libc.so.6 => /lib64/libc.so.6 (0x00007f7c59c0c000)
libMathCore.so.5.30 => /usr/lib64/root/libMathCore.so.5.30 (0x00007f7c599f8000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f7c597f4000)
libm.so.6 => /lib64/libm.so.6 (0x00007f7c59570000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f7c59353000)
libz.so.1 => /lib64/libz.so.1 (0x00007f7c5913c000)
liblzma.so.5 => /usr/lib64/liblzma.so.5 (0x00007f7c58f17000)
libpcre.so.0 => /lib64/libpcre.so.0 (0x00007f7c58cd9000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f7c58aa2000)
/lib64/ld-linux-x86-64.so.2 (0x00000032e9400000)
librt.so.1 => /lib64/librt.so.1 (0x00007f7c58899000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007f7c58636000)

$ root-config --etcdir
/etc/root

So clearly I’m picking up the older *.so. But if I used configure/make to build the source directory — that is I did this in the root directory:
./configure --prefix="/usr/local"
make
sudo make install

Shouldn’t that have built in the executable the correct path in during the build since I did set the --prefix to /usr/local??? So you say I have to have different /etc/root for different installation. How then do I do that? Do I just “sudo mv /etc/root /etc/oldroot” and would the “sudo make install” then put a the new and consistent /etc/root in place?

[url]ROOTSYS and linux distribution installation
[url]Problems installing root with --prefix=$HOME/.local
[url]Release 5.32.03 on Ubuntu 12.04

[quote=“Wile E. Coyote”][url]ROOTSYS and linux distribution installation
[url]Problems installing root with --prefix=$HOME/.local
[url]Release 5.32.03 on Ubuntu 12.04

Thank you, that did it! :smiley: