Drawing TArrow on top of TF1

Dear root authors,

I’m trying to do something that I think should be very simple: Draw an arrow on top of a function. Below is my code

> TCanvas *c1 = new TCanvas("c1","c1", 1980, 1200);
> TF1* fa1 = new TF1("fa1", "0.01874568066 / (x^2 + 28086.4801637)", -837.951075, 837.951075);
> TArrow *ar1 = new TArrow(0.3, 0.3, 0.5, 0.5, 0.05, "|>");
> fa1->Draw();
> ar1->Draw();
> c1->Print("Breit-Wigner_plot.pdf", "pdf");

Looking around the web, this seems like it should be the way to do it. The arrow appears to disappear behind the TF1, since it will show up when I don’t draw the TF1. No amount of updating the canvas, changing the order of drawing or adding the “same” keyword appears to make a difference.

Thanks,
Rob


ROOT Version: 6.16
Platform: MacOS
Compiler: clang 10.0.1


Looks like TArrow still only has “user” coordinate options, but you want “NDC” coordinates in fractions of pad size. You will need to convert your 0.3, 0.5, etc coordinates into “user” coordinates manually: https://root.cern.ch/root/html534/guides/users-guide/Graphics.html#converting-between-coordinate-systems

If you change the arrow coordinates in your example to something that will fit on-screen with your TF1, you can see the arrow: ar1->DrawArrow(0,200,0,0.4e-6,0.05,"|>")

Hi Rob,

your arrow is outside of your histogram. Your histogram spans -800 < x < 800 and 0 < y < 0.7e-6. And you try to draw the arrow at around x=0.4, y=0.4. Try changing the arrow ctor to something like

TArrow *ar1 = new TArrow(100, 0.1e-6, 200, 0.3e-6, 0.05, "|>");

and you’ll see the arrow.

Hi Guys,

Thank you very much. I was not expecting the coordinate system to change as a consequence of drawing the function. Good to know!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.