Search code examples
c++pointersroot-framework

Iteratively drawing TEllipse in ROOT


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 :)


Solution

  • 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");