# Adding ploynomial to TEfficiency

**URL:** <https://root-forum.cern.ch/t/adding-ploynomial-to-tefficiency/40700>\
**Category:** Newbie\
**Created:** [July 28, 2020, 5:33pm UTC](https://root-forum.cern.ch/t/adding-ploynomial-to-tefficiency/40700 "2020-07-28T17:33:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [July 28, 2020, 5:33pm UTC](https://root-forum.cern.ch/t/adding-ploynomial-to-tefficiency/40700/1 "2020-07-28T17:33:13Z")

</div>

Dear All,  
I have a series of plot where I fitted erf= 0.5\*[0]\*( 1 - TMath::Erf( ([1] - x)/[2] ) ) using TEfficiency class. I want to add zero degree poly(pol0), use add function to 1-D but got error “Can’t call add in TEfficiency”  
Can help me adding this new pol0 to the erf fit?

Best  
P

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [July 29, 2020, 8:58am UTC](https://root-forum.cern.ch/t/adding-ploynomial-to-tefficiency/40700/2 "2020-07-29T08:58:16Z")

</div>

Hi @Prya13,  
Could you provide a snippet of your code and the full error you get?  
Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [July 29, 2020, 2:55pm UTC](https://root-forum.cern.ch/t/adding-ploynomial-to-tefficiency/40700/3 "2020-07-29T14:55:26Z")

</div>

Thank you vpadulan for your response. Here is a snippet portion of the code:

histeff[isect] = new TEfficiency( \*h\_e\_ert2\_sect[isect], \*h\_e\_mb\_sect[isect] );

```
// set up turn-on curve fit function
name = "effit"; name += isect;
effit[isect] = new TF1(name,"0.5*[0]*( 1 - TMath::Erf( ([1] - x)/[2] ) ) ", 0.5 , 6);
effit[isect]->SetParameters(1,1.2,1.5)
effit[isect]->SetParLimits(0,0.86,1.1);.
effit[isect]->SetLineColor(2);

```

histeff[isect]-\>Fit( effit[isect], “R”);

```
// polynomial fit
name = "line"; name += isect;
line[isect] = new TF1( name, "pol0", FIT_RANGE_MIN, FIT_RANGE_MAX );
line[isect]->SetLineColor(4);
histeff[isect]->Fit(line[isect],"same");
histeff[isect]->Add(line[isect]);

```

This is the error:  
Error: Can’t call TEfficiency::Add(line[isect])

void TEfficiency::Add(const TEfficiency& rEff);  
\*\*\* Interpreter error recovered \*\*\*

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [July 29, 2020, 3:03pm UTC](https://root-forum.cern.ch/t/adding-ploynomial-to-tefficiency/40700/4 "2020-07-29T15:03:01Z")

</div>

Indeed the error shows you that `TEfficiency::Add` expects a `TEfficiency` object as an argument, whereas you are calling it with a `TF1` object as an argument.  
But probably you do not want to add two efficiencies in your case, maybe you are trying to add a function to the list of functions of the `TEfficiency` object. To that end, take a look at this example taken from the [docs](https://root.cern.ch/doc/master/classTEfficiency.html)

```auto
   //canvas only needed for this documentation
   TCanvas* c1 = new TCanvas("example","",600,400);
   c1->SetFillStyle(1001);
   c1->SetFillColor(kWhite);
 
   //create one-dimensional TEfficiency object with fixed bin size
   TEfficiency* pEff = new TEfficiency("eff","my efficiency;x;#epsilon",20,0,10);
   TRandom3 rand3;
 
   bool bPassed;
   double x;
   for(int i=0; i<10000; ++i)
   {
      //simulate events with variable under investigation
      x = rand3.Uniform(10);
      //check selection: bPassed = DoesEventPassSelection(x)
      bPassed = rand3.Rndm() < TMath::Gaus(x,5,4);
      pEff->Fill(bPassed,x);
   }
 
   //create a function for fitting and do the fit
   TF1* f1 = new TF1("f1","gaus",0,10);
   f1->SetParameters(1,5,2);
   pEff->Fit(f1);
 
   //create a threshold function
   TF1* f2 = new TF1("thres","0.8",0,10);
   f2->SetLineColor(kRed);
   //add it to the list of functions
   //use add first because the parameters of the last function will be displayed
   pEff->GetListOfFunctions()->AddFirst(f2);
 
   pEff->Draw("AP");

```

Note especially the line `pEff->GetListOfFunctions()->AddFirst(f2);`

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [July 29, 2020, 3:22pm UTC](https://root-forum.cern.ch/t/adding-ploynomial-to-tefficiency/40700/5 "2020-07-29T15:22:37Z")

</div>

Thank you @vpadulan for your response, so the last section becomes:

```auto
line[isect] = new TF1( name, "pol0", FIT_RANGE_MIN, FIT_RANGE_MAX );
line[isect]->SetLineColor(4);
histeff[isect]->GetListOfFunctions()->AddFirst(line[isect]);
histeff[isect]->Draw();

```

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [July 29, 2020, 5:17pm UTC](https://root-forum.cern.ch/t/adding-ploynomial-to-tefficiency/40700/6 "2020-07-29T17:17:02Z")

</div>

Thank you vpadulan, it worked but its lying along the x-axis.  
I made FIT\_RANGE\_MIN = 0; FIT\_RANGE\_MAX = 5; Can the p0 fit be placed say above 5 of values on x-axis?

 ![fit](https://root-forum.cern.ch/uploads/default/original/3X/6/f/6f0714658c8fe348333aecb21b86a980b93ea6d6.png)

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [July 30, 2020, 7:51am UTC](https://root-forum.cern.ch/t/adding-ploynomial-to-tefficiency/40700/7 "2020-07-30T07:51:09Z")

</div>

Try setting the parameter of the pol(0) function to whatever y coordinate you like.  
Cheers,  
Vincenzo
