Construct a TF1 object with a TGraph->Eval() + TMath function with parameters

Dear rooters,

I’m trying to create a TF1 with a TGraph->Eval() and a TMath::voigt() to fit two peaks in my spectra. Yet, I’ve not been very successful doing it. I can fit the peaks individually but I can’t build a TF1 with this two different objects.

I have something like this:

	sprintf(fit_antip_name,"fit_antip%d",i+fits_counter);
	
	fit_antip[i+fits_counter]= new TF1(fit_antip_name,[&](double*x, double *par){ return par[1]+(par[0]*(gr_simulations_antiparallel[i]->Eval(x[0]-par[2]))/par[4])+par[3]*x[0];}, 35.00, 35.3, 5);
	
  fit_antip[i+fits_counter]->SetParameter(0,y_maximum_value_exp[nr_file]);
  fit_antip[i+fits_counter]->SetParameter(1,0.5);
  fit_antip[i+fits_counter]->SetParameter(2,x_maximum_value_exp[nr_file]-x_maximum_value[i]);
  fit_antip[i+fits_counter]->SetParameter(3,0.1);
  fit_antip[i+fits_counter]->FixParameter(4,y_maximum_value[i]);
  fit_antip[i+fits_counter]->SetParName(0,"amplitude");
  fit_antip[i+fits_counter]->SetParName(1,"baseline");
  fit_antip[i+fits_counter]->SetParName(2,"energy offset");
  fit_antip[i+fits_counter]->SetParName(3,"slope");

	fit_antip[i+fits_counter]->SetNpx(10000);
	fit_antip[i+fits_counter]->SetLineWidth(2);
	gr_exp_antiparallel[nr_file]->Fit(fit_antip_name,"NMR+");
	
	
	
	TF1 *voigt = new TF1("voigt","[0]*(TMath::Voigt(x[0]-[1],[2],[3], 4))+[4]+[5]*x",35.03, 35.065); 
  voigt->SetParameter(0,2.0);
  voigt->SetParameter(1,35.05);
  voigt->SetParameter(2,0.1);
  voigt->SetParameter(3,0.00001);
  voigt->SetParameter(4,0.5);
  voigt->SetParameter(5,0.1);
	gr_exp_antiparallel[nr_file]->Fit("voigt","NMR+");
	voigt->Draw("same");	

I would like to implement the voigt in the fit_antip[i+fits_counter].

Thank you very much.

Jorge


_ROOT Version:v6-11-02
_Platform: mac osx 10.12.6
_Compiler: Apple LLVM version 9.0.0 (clang-900.0.39.2)


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.