# Evaluation value from a function

**URL:** <https://root-forum.cern.ch/t/evaluation-value-from-a-function/48693>\
**Category:** Newbie\
**Created:** [February 7, 2022, 2:25pm UTC](https://root-forum.cern.ch/t/evaluation-value-from-a-function/48693 "2022-02-07T14:25:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saradindu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/saradindu/32/26687_2.png) [@Saradindu](https://root-forum.cern.ch/u/Saradindu)\
**Post date:** [February 7, 2022, 2:25pm UTC](https://root-forum.cern.ch/t/evaluation-value-from-a-function/48693/1 "2022-02-07T14:25:30Z")

</div>

I have a function eff = exp[c0+c1_log(x)+c2_(log(x))\*\*2]

The input is like this :

x y ey

450 16770 515  
1600 10924 634  
2453 8538 1043  
2904 6438 604  
4083 4719 828  
5691 2676 456  
6124 2275 318  
6575 2115 353

Now I fit this data using abobe function and get value of c0 , c1 , c2 .

Now I want to fix value of c0, c1 , c2 and want to get value of eff for a given x ?

Please tell me how to do it ?

regards  
saradindu

---

<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 7, 2022, 3:51pm UTC](https://root-forum.cern.ch/t/evaluation-value-from-a-function/48693/2 "2022-02-07T15:51:56Z")

</div>

```cpp
{
  TF1 *eff = new TF1("eff",
    "TMath::Exp([c0]) + [c1] / TMath::Log(x) + [c2] * TMath::Sq(TMath::Log(x))",
    100., 10000.);
  // eff->Print();
  eff->SetNpx(1000);
  eff->SetParameters(1., 1., 1.);
  // eff->Draw();
  Double_t x[] = { 450., 1600., 2453., 2904., 4083., 5691., 6124., 6575.};
  Double_t y[] = {16770., 10924., 8538., 6438., 4719., 2676., 2275., 2115.};
  Double_t ey[] = { 515., 634., 1043., 604., 828., 456., 318., 353.};
  UInt_t n = sizeof(x) / sizeof(Double_t);
  TGraphErrors *g = new TGraphErrors(n, x, y, 0, ey);
  g->SetTitle("Efficiency;x;eff");
  g->Draw("A*");
  eff->SetParameters(10., -1300., -380.); // set "reasonable" initial values
  g->Fit(eff, "R"); // use the range specified in the function range
  std::cout << "c0 = " << eff->GetParameter(0) << " +- " << eff->GetParError(0) << std::endl;
  std::cout << "c1 = " << eff->GetParameter(1) << " +- " << eff->GetParError(1) << std::endl;
  std::cout << "c2 = " << eff->GetParameter(2) << " +- " << eff->GetParError(2) << std::endl;
  std::cout << "eff(1000.) = " << eff->Eval(1000.) << std::endl;
  std::cout << "eff(5000.) = " << eff->Eval(5000.) << std::endl;
}

```

---

<div class="post-metadata">

**Author:** ![Saradindu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/saradindu/32/26687_2.png) [@Saradindu](https://root-forum.cern.ch/u/Saradindu)\
**Post date:** [February 7, 2022, 6:43pm UTC](https://root-forum.cern.ch/t/evaluation-value-from-a-function/48693/3 "2022-02-07T18:43:03Z")

</div>

Thank you very much .

Could you please tell me how do I can get errors of efficiency ? Here there is no way to evaluate errors ?

regards  
saradindu

---

<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 7, 2022, 7:38pm UTC](https://root-forum.cern.ch/t/evaluation-value-from-a-function/48693/4 "2022-02-07T19:38:26Z")

</div>

I don’t have any simple solution. Maybe @moneta knows some trick.

---

<div class="post-metadata">

**Author:** ![Saradindu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/saradindu/32/26687_2.png) [@Saradindu](https://root-forum.cern.ch/u/Saradindu)\
**Post date:** [February 7, 2022, 8:00pm UTC](https://root-forum.cern.ch/t/evaluation-value-from-a-function/48693/5 "2022-02-07T20:00:55Z")

</div>

I have another problem . I fit the data points using the above functions . Now I want to fix c1 , c2 and keep c0 as free variable.

How do I can fit another set of data points using this function where c1 , c2 are fixed ?

Thanks  
saradindu

---

<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 7, 2022, 8:03pm UTC](https://root-forum.cern.ch/t/evaluation-value-from-a-function/48693/6 "2022-02-07T20:03:43Z")

</div>

`eff->FixParameter(1, some_c1_value); eff->FixParameter(2, some_c2_value); g->Fit(eff, "R");`

---

<div class="post-metadata">

**Author:** ![Saradindu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/saradindu/32/26687_2.png) [@Saradindu](https://root-forum.cern.ch/u/Saradindu)\
**Post date:** [February 7, 2022, 8:52pm UTC](https://root-forum.cern.ch/t/evaluation-value-from-a-function/48693/7 "2022-02-07T20:52:22Z")

</div>

Thanks !

regards  
saradindu
