# Cannot get TF1 with Sqrt() to plot

**URL:** <https://root-forum.cern.ch/t/cannot-get-tf1-with-sqrt-to-plot/53559>\
**Category:** Newbie\
**Tags:** root\
**Created:** [February 9, 2023, 6:55pm UTC](https://root-forum.cern.ch/t/cannot-get-tf1-with-sqrt-to-plot/53559 "2023-02-09T18:55:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![izzy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/izzy/32/27392_2.png) [@izzy](https://root-forum.cern.ch/u/izzy)\
**Post date:** [February 9, 2023, 6:55pm UTC](https://root-forum.cern.ch/t/cannot-get-tf1-with-sqrt-to-plot/53559/1 "2023-02-09T18:55:45Z")

</div>

* * *

_ROOT Version:_ JupyROOT 6.22/06  
_Platform:_ macOS Ventura 13.2  
_Compiler:_ Jupyter Lab

* * *

I am making TF1 objects from functions in python 3.11.0. I have been unable to get a sqrt to work, either via Sqrt() or Pow(x,1/2). I can get Power to work for when it is not raised to 1/2. My code looks like the following:

```auto
def background(X, P):
    return ROOT.TMath.Power( P[1]*(P[0]-X[0]), 2 )
can = ROOT.TCanvas("can", "can")

show_background = ROOT.TF1("show_background", background, 0.15, 0.45, 2)
show_background.SetParameters( 0.37, 2)
show_background.DrawClone()

can.Draw()

```

However, when I try `ROOT.TMath.Sqrt( P[1]*(P[0]-X[0]) )` or `ROOT.TMath.Power( P[1]*(P[0]-X[0]), 1/2 )` in the function `background` I get an empty canvas. My end goal is to use the Sqrt() in fits, but I can’t even get it to plot properly. Is there something obvious that I am missing for getting Sqrt() to work? Even when I did get it to sometimes “plot” it was a straight line. I can provide the outputs that I see on my end as well, if this is an issue specific to my environment.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [February 9, 2023, 7:06pm UTC](https://root-forum.cern.ch/t/cannot-get-tf1-with-sqrt-to-plot/53559/2 "2023-02-09T19:06:50Z")

</div>

Try with the power “`1`” (see how your function becomes negative).

BTW. [I think you cannot “clone” this type of function](https://root.cern/doc/master/classTF1.html#aa8905d28455ed7be02019f20b9cc5827).

---

<div class="post-metadata">

**Author:** ![izzy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/izzy/32/27392_2.png) [@izzy](https://root-forum.cern.ch/u/izzy)\
**Post date:** [February 9, 2023, 8:49pm UTC](https://root-forum.cern.ch/t/cannot-get-tf1-with-sqrt-to-plot/53559/3 "2023-02-09T20:49:02Z")

</div>

Hello Wile,

1.) Thank you for pointing that out re Clone

2.) Yes, I see that with a power of 1 it is just a line that goes negative y for positive x.

I have been trying to think of why this will not plot in root. Is this an issue because of the (P[0]-X[0]) term? I am trying to use that to get the model to terminate at some maximal x value P[0], hence P[0]-X[0]. I tried plotting `ROOT.TMath.Power( P[0]*X[0], 1/2)` and that does indeed seem to return a reasonable result. But now I am stuck with the issue of being unable to use (P[0]-X[0]).

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [February 9, 2023, 8:54pm UTC](https://root-forum.cern.ch/t/cannot-get-tf1-with-sqrt-to-plot/53559/4 "2023-02-09T20:54:30Z")

</div>

[Uncle Google → sqrt(-1)](https://www.google.com/search?q=sqrt%28-1%29)

---

<div class="post-metadata">

**Author:** ![izzy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/izzy/32/27392_2.png) [@izzy](https://root-forum.cern.ch/u/izzy)\
**Post date:** [February 10, 2023, 3:16pm UTC](https://root-forum.cern.ch/t/cannot-get-tf1-with-sqrt-to-plot/53559/5 "2023-02-10T15:16:23Z")

</div>

Ah. I do feel silly now. I was able to plot it with some random values in Mathematica but I do forget that Mathematica != root…
