I wrote the attached script to draw a line on a 2D histogram by dragging mouse.
But drawing becomes extremely slow when number of bins of the histogram is increased.
I wonder why and if there is any faster way…
Using option “col” did not make much difference, although it’s much faster when the number of bins of the histogram is reduced to 1/100.
I wonder why the response depends on the number of bins…
Okay, I figured out that c1->Modified() and/or c1->Update() takes more time with increasing number of bins of the histogram.
If only there was a way to update only the line, not redrawing all the objects on the canvas…
When you draw a line by mouse drag via “tool bar” of a canvas, the response does not seem to be depending on the objects drawn on the canvas. I would like to know how this is realized.
What I want to do is to write a script to draw a profile histogram along a line drawn by dragging mouse on a 2D histogram.
[quote=“kame”]…
What I want to do is to write a script to draw a profile histogram along a line drawn by dragging mouse on a 2D histogram.[/quote]Can you remove your
l = new TLine;
. . .
l->Draw();
and replace it the
[quote=“kame”]…What I want to do is to draw an arbitrary straight line by a mouse drag, not a crosshair…[/quote] Are you satisfied with the performance of drawing TWO lines to represent that crosshair over your plot?
Yes, drawing the crosshair is fast enough.
I wrote the attached script based on the code called when “Line button” of the canvas toolbar is clicked (TCreatePrimitives.cxx). This is much faster than the previous one. I guess it’s due to the use of faster lower-level functions, although I still couldn’t find how to prevent the line once disappearing after the mouse button is released. dndline2.C (1.7 KB)