Finding coordinates on a TPad with the mouse

Hello ROOTers,

I’ve been trying to build an interactive fitting routine.

I want to take in three user mouse clicks and use the coordinates to preform calculations.

Most examples (such as Triangles.C or Exec2.C) have a number problems:

  1. They read an infinite number of mouse events, I want to limit them to three.

  2. They output the coordinates in a separate routine, whereas I want to output them in the main program routine.

Basically, I want a routine that will wait for a mouse click and return the click position (only once). Is there any way I could do this?

see a possible solution below


void ginput() { TCanvas *c = new TCanvas; c->DrawFrame(0,0,10,100); TGraph *gr = (TGraph*)c->WaitPrimitive("Graph","PolyLine"); gr->Fit("pol2"); }