1

I am working to solve a problem in which I would like to plot a number of ellipses on a TCanvas. I have constructed the program outside of ROOT by linking in the appropriate ROOT libraries. I can successfully draw a single ellipse to the canvas by hardcoding it into the main, but when I try to adapt it to draw a series of ellipses, the program outputs an empty canvas.

extern void InitGui();
VoidFuncPtr_t initfuncs[] = { InitGui, 0 };
int Error;
TROOT root("plot", "Plot", initfuncs);

int main(int argc, char **argv) {
  TApplication *app = new TApplication("App", &argc, argv);
  TCanvas *c = new TCanvas();
  c->Range(0,0,100,100);
  TEllipse *e;

  while(getline(myFile1, coordinate)) {
    split(myVector, coordinate, is_any_of(" "));
    arr[0] = myVector.at(0);
    arr[1] = myVector.at(1);
    getline(myFile2, arr[2]);
    e = plotZone(stod(arr[0]), stod(arr[1]), stod(arr[2]));
    e->Draw();
    c->Update();
  }

  c->Show();
  app->Run();
  delete app;
  return 0;
}

TEllipse * plotZone(double x, double y, double r) {
  TEllipse *e = new TEllipse(x, y, r, r);
  e->SetFillColor(38);
  e->SetFillStyle(3003);

  return e;
}

I really just want to know why the act of passing a TEllipse back to main prevents it from being rendered, or is it perhaps that I am doing the Draw/Update wrong? All help is greatly appreciated :)

1 Answer 1

1

It seems likely you've figured out/given up on this by now, but here goes:

By default, the Draw() method overwrites whatever is on the current TPad. You want to give it the "same" option:

e->Draw("same");

1
  • Praise ye! It seems ROOT support is hard to come by Commented Feb 9, 2016 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.