TH2D h("h","",10,0,10,10,0,10);
h.Draw();
TLine aline(0,5,10,5);
aline.Draw();
// looks ok, but if we zoom in...
h.GetXaxis()->SetRangeUser(2,8);
After zooming in, the line stands out the histogram. I would like to have something like the grid lines, so when you zoom in, the grid lines don’t stand out the histogram axis.
TExec is an object placed in the TCanvas display list. It executes the script passed in argument each time the canvas is painted. When you zoom the canvas it is automatically repainted with different values along the X axis therefore if you paint a line with fixed values, they do not take into account the new axis limits defined by the zoom. Putting the line painting into a TExec allows to recompute correctly the line position each time the canvas is painted. TExec encapsulates the line painting with some code allowing to recompute the line position each time the canvas is painted.