Trying to access TGraphPolargram from TGraphPolar throws segmentation fault

Dear all,

I’ve been trying to change the axes and generally pretty up a TGraphPolar by accessing the TGraphPolargram on which it is drawn. I can get a pointer to the TGraphPolargram via

TGraphPolargram* polargram = Graph->GetPolargram();

but if I try to use it, eg


  polargram->SetToDegree();

when I run the code it throws a segmentation violation fault. I’m not sure if this is a bug or my own error. It’s happened in root 6.06/06 and root 5.34/03.

Please could you advise me on where I’ve gone wrong.

Can you post here a little example showing this problem ?

Here’s a script that gives the error:

void polarGraph()
{
  
  TRandom2 angles;
  Double_t phi[10000];
  Double_t theta[10000];

  TGraphPolar * PP = new TGraphPolar();

  for (int i = 0; i < 10000; i++)
    {
      phi[i]= angles.Gaus(0,1.6);
      theta[i] = angles.Gaus(0.8,0.3);
      PP->SetPoint(i,phi[i],theta[i]);
    }



  TGraphPolargram* polargram = PP->GetPolargram();
  polargram->SetToDegree();

  PP->SetTitle("Betterplot?");
  
  PP->SetMarkerStyle(20);
  PP->SetMarkerSize(0.1);
  PP->SetMarkerColor(4);
 
  TCanvas * c = new TCanvas("c","c",800,800); 

  PP->Draw("ALP");
  //c->Print("SamplePolar.gif");

  return ;
}

run with “root polarGraph.C” in linux.

void polarGraph()
{

   TCanvas * c = new TCanvas("c","c",800,800);

   TRandom2 angles;
   Double_t phi[10000];
   Double_t theta[10000];

   TGraphPolar * PP = new TGraphPolar();

   for (int i = 0; i < 100; i++) {
      phi[i]= angles.Gaus(0,1.6);
      theta[i] = angles.Gaus(0.8,0.3);
      PP->SetPoint(i,phi[i],theta[i]);
   }

   PP->SetTitle("Betterplot?");

   PP->SetMarkerStyle(20);
   PP->SetMarkerSize(0.1);
   PP->SetMarkerColor(4);

   PP->Draw("ALP");
   gPad->Update();

   TGraphPolargram* polargram = PP->GetPolargram();
   polargram->SetToDegree();
}

Thanks, that seems to have solved it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.