# How to use TF1 with variables?

**URL:** <https://root-forum.cern.ch/t/how-to-use-tf1-with-variables/50306>\
**Category:** Newbie\
**Tags:** root\
**Created:** [June 7, 2022, 6:34pm UTC](https://root-forum.cern.ch/t/how-to-use-tf1-with-variables/50306 "2022-06-07T18:34:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scheng5134](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/scheng5134/32/30208_2.png) [@scheng5134](https://root-forum.cern.ch/u/scheng5134)\
**Post date:** [June 7, 2022, 6:34pm UTC](https://root-forum.cern.ch/t/how-to-use-tf1-with-variables/50306/1 "2022-06-07T18:34:23Z")

</div>

Hello

I’m having trouble learning how to use the TF1 function properly, due to my unfamiliarity with coding. I want to add some modifiers to a Poisson function.  
So a standard function would be

```auto
void fplot()
{
	TF1 *Poisson0 = new TF1("Poisson0","TMath::Poisson(0,x)",0,10);
	Poisson0 -> Draw();
}

```

But I need to modify the Poisson curve by giving it a amplitude multiplier which would be Var0 in this case. And to explode the x-axis by another variable “Var1”  
So I tried doing this

```auto
void fplot()
{
	double Var0 = 5000;
	double Var1 = 1e12;
	TF1 *Poisson0 = new TF1("Poisson0","Var0*TMath::Poisson(0,x/Var1)",0,Var1*10);
	Poisson0 -> Draw();
}

```

But an error where Var0 and Var1 is considered unknown is spat out. If anyone can educate me on how to solve this, your help would be greatly appreciated.

Thanks  
Soren

\_\_\_ROOT Version: 6.24  
\_Platform: Windows  
_Compiler:_ Not Provided

* * *

---

<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:** [June 7, 2022, 7:40pm UTC](https://root-forum.cern.ch/t/how-to-use-tf1-with-variables/50306/2 "2022-06-07T19:40:36Z")

</div>

One possibility:

```cpp
{
  TF1 *Poisson0 = new TF1("Poisson0", "[Var0]*TMath::Poisson(0.,x/[Var1])", 0., 10.);
  // Poisson0->Print();
  double Var0 = 5000., Var1 = 1.e12;
  Poisson0->SetParameters(Var0, Var1); Poisson0->SetRange(0., Var1 * 10.);
  Poisson0->Draw();
}

```

---

<div class="post-metadata">

**Author:** ![scheng5134](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/scheng5134/32/30208_2.png) [@scheng5134](https://root-forum.cern.ch/u/scheng5134)\
**Post date:** [June 7, 2022, 8:02pm UTC](https://root-forum.cern.ch/t/how-to-use-tf1-with-variables/50306/3 "2022-06-07T20:02:58Z")

</div>

Whoa that worked, thanks!!  
Just wondering what does the period after the parameters mean?  
like 0., 10., etc etc.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 8, 2022, 6:08am UTC](https://root-forum.cern.ch/t/how-to-use-tf1-with-variables/50306/4 "2022-06-08T06:08:52Z")

</div>

> [@scheng5134](#):
>
> Just wondering what does the period after the parameters mean?

It means these numbers are floating point numbers. Without a period it would mean they are integers.
