Home | News | Documentation | Download

Adding ploynomial to TEfficiency

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

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

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 ***

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

   //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);

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

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();

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?

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