Drag and Drop

Dear all,

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…

Many thanks,
Satoru
dndline.C (949 Bytes)

Replace your line

h0->Draw(); by, eg

h0->Draw("col");
Rene

Hi, thank you for your reply.

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…

Is the answer not obvious ?

Rene

Thank you for your reply.

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

c1->SetCrosshair(1);Does it make sense for you ?

HI,
thank you for your advice.

What I want to do is to draw an arbitrary straight line by a mouse drag, not a crosshair…

[quote=“kame”]…What I want to do is to draw an arbitrary straight line by a mouse drag, not a crosshair…[/quote] :blush: Are you satisfied with the performance of drawing TWO lines to represent that crosshair :unamused: over your plot?

Thank you for your reply.

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)