TGraph2D problem with version 6.06/08

Hi,

I tried a macro (in attachment) that used to work with root 5, but, as I moved to ROOT 6 (version 6.0.6/08), the TGraph2D are no longer displayed. I tried a number of Draw options, but none worked.

Is there any change I should implement from version 5 to version 6?

Thanks,
Luca
cond2d.C (2.32 KB)

I made some progress. Apparently, ROOT does no longer like cases where points are all aligned.
I changed x as follows, and now I see a red curve:

double x[11]={-0.50001, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.49999};

I don’t know whether this is a new feature or a problem…

Luca

… same for the vertical line. I can display it if I change:

double xx[2]={-0.50001, -0.49999};
double yy[2]={-0.98501, -0.98499};

So, the TGraph2D should have non-null width in all three dimensions, or it won’t be shown in the TCanvas.

Luca

Without any changes in your initial code I get the attached image with the ROOT master version (6.09/01)

Note I get the same image with ROOT 5.34/37


Any way you are miss-using TGraph2D … What you want really is a Line in 3D … so use the appropriate class like in the following example :


{
   TCanvas c("c", "",600, 600);
   c.SetTheta(30);
   c.SetPhi(50);
   gStyle->SetOptStat(0);
   gStyle->SetHistTopMargin(0);
   gStyle->SetOptTitle(kFALSE);
   TF2 f("f", "[0]*cos(x)*cos(y)", -1, 1, -1, 1);
   f.SetParameter(0, 1);
   double s = 1./f.Integral(-1, 1, -1, 1);
   f.SetParameter(0, s);
   f.SetNpx(50);
   f.SetNpy(50);
   double x[11]={-0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5};
   double y[11]={-0.985, -0.8, -0.6, -0.4, -0.2,  0.0,  0.2,  0.4,  0.6,  0.8,  0.985};
   double z[11]={0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3};
   for(int i = 0; i < 11; ++i) z[i] = s*cos(x[i])*cos(y[i]);
   TPolyLine3D g2(11, x, y, z);
   double xx[2]={-0.5, -0.5};
   double yy[2]={-0.985, -0.985};
   double zz[2]={0.11, s*cos(-0.5)*cos(-0.985)};
   TPolyLine3D l2(2, xx, yy, zz);
   f.SetTitle("dP/dxdy=f(x,y)");
   f.SetLineWidth(1);
   f.SetLineColor(kAzure-2);

   f.GetXaxis()->SetTitle("x");
   f.GetXaxis()->SetTitleOffset(1.4);
   f.GetXaxis()->SetTitleSize(0.04);
   f.GetXaxis()->CenterTitle();
   f.GetXaxis()->SetNdivisions(505);
   f.GetXaxis()->SetTitleOffset(1.3);
   f.GetYaxis()->SetTitle("y");
   f.GetYaxis()->CenterTitle();
   f.GetYaxis()->SetTitleOffset(1.4);
   f.GetYaxis()->SetTitleSize(0.04);
   f.GetYaxis()->SetTitleOffset(1.3);
   f.GetYaxis()->SetNdivisions(505);
   f.GetZaxis()->SetTitle("dP/dx");
   f.GetZaxis()->CenterTitle();
   f.GetZaxis()->SetTitleOffset(1.3);
   f.GetZaxis()->SetNdivisions(505);
   f.GetZaxis()->SetTitleSize(0.04);
   f.GetXaxis()->SetLabelSize(0.03);
   f.GetYaxis()->SetLabelSize(0.03);
   f.GetZaxis()->SetLabelSize(0.03);
   f.Draw("surf");
   g2.SetLineColor(kRed);
   g2.SetLineWidth(3);
   g2.Draw();
   l2.SetLineColor(kRed);
   l2.SetLineStyle(2);
   l2.SetLineWidth(1);
   l2.Draw();
   TLatex txt(0.05, 0, "f(y|x_{0})");
   txt.SetTextColor(kRed);
   txt.Draw();
   TLatex txt1(0.12, 0.52, "f(x,y)");
   txt1.SetTextColor(kBlue);
   txt1.Draw();
   TLatex txt2(0.28, -0.76, "x_{0}");
   txt2.SetTextColor(kRed);
   txt2.Draw();
}

and you will get what you are looking for. That’s a nice example by the way :slight_smile:


I have improved a little bit your macro. Would you allow to add it as one of the ROOT tutorials ?

{
   TCanvas *c = new TCanvas("c", "c", 600, 600);
   c->SetTheta(30);
   c->SetPhi(50);
   gStyle->SetOptStat(0);
   gStyle->SetHistTopMargin(0);
   gStyle->SetOptTitle(kFALSE);

   // Define and draw a surface
   TF2 *f = new TF2("f", "[0]*cos(x)*cos(y)", -1, 1, -1, 1);
   f->SetParameter(0, 1);
   double s = 1./f->Integral(-1, 1, -1, 1);
   f->SetParameter(0, s);
   f->SetNpx(50);
   f->SetNpy(50);

   f->GetXaxis()->SetTitle("x");
   f->GetXaxis()->SetTitleOffset(1.4);
   f->GetXaxis()->SetTitleSize(0.04);
   f->GetXaxis()->CenterTitle();
   f->GetXaxis()->SetNdivisions(505);
   f->GetXaxis()->SetTitleOffset(1.3);
   f->GetXaxis()->SetLabelSize(0.03);
   f->GetXaxis()->ChangeLabel(2,-1,-1,-1,kRed,-1,"X_{0}");

   f->GetYaxis()->SetTitle("y");
   f->GetYaxis()->CenterTitle();
   f->GetYaxis()->SetTitleOffset(1.4);
   f->GetYaxis()->SetTitleSize(0.04);
   f->GetYaxis()->SetTitleOffset(1.3);
   f->GetYaxis()->SetNdivisions(505);
   f->GetYaxis()->SetLabelSize(0.03);

   f->GetZaxis()->SetTitle("dP/dx");
   f->GetZaxis()->CenterTitle();
   f->GetZaxis()->SetTitleOffset(1.3);
   f->GetZaxis()->SetNdivisions(505);
   f->GetZaxis()->SetTitleSize(0.04);
   f->GetZaxis()->SetLabelSize(0.03);

   f->SetLineWidth(1);
   f->SetLineColor(kAzure-2);

   f->Draw("surf1 fb");

   // Lines for 3D annotation
   double x[11] = {-0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5};
   double y[11] = {-0.985, -0.8, -0.6, -0.4, -0.2,  0.0,  0.2,  0.4,  0.6,  0.8,  0.985};
   double z[11] = {0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3};
   for (int i = 0; i < 11; ++i) z[i] = s*cos(x[i])*cos(y[i]);
   TPolyLine3D *g2 = new TPolyLine3D(11, x, y, z);

   double xx[2]={-0.5, -0.5};
   double yy[2]={-0.985, -0.985};
   double zz[2]={0.11, s*cos(-0.5)*cos(-0.985)};
   TPolyLine3D *l2 = new TPolyLine3D(2, xx, yy, zz);

   g2->SetLineColor(kRed);
   g2->SetLineWidth(3);
   g2->Draw();

   l2->SetLineColor(kRed);
   l2->SetLineStyle(2);
   l2->SetLineWidth(1);
   l2->Draw();

   // Draw text Annotations
   TLatex *txt = new TLatex(0.05, 0, "f(y|x_{0})");
   txt->SetTextFont(42);
   txt->SetTextColor(kRed);
   txt->Draw();

   TLatex *txt1 = new TLatex(0.12, 0.52, "f(x,y)");
   txt1->SetTextColor(kBlue);
   txt1->SetTextFont(42);
   txt1->Draw();
}


I just had an exchange with my editor, and he is fine if the macro, which refers to a figure taken from my book, is used in ROOT totorial, provided that the book is cited (the 2nd edition is in preparation):

http://www.springer.com/la/book/9783319201757

By the way, the method ChangeLabel requires the latest verion of ROOT, which I have now problems to compile under Mac OS :frowning:

Luca

Thanks ! I have added the required references in the macro.
Yes ChangeLabel is a new feature.
I am using Mac my2self and I have no problem to compile (I do it many times per day).
What problem do you encounter exactly ?