Rid unwanted spaces in piecewise fit

I would like to rid unwanted gaps inbetween my end points of fits such that I am able to use the parameters I have for a fully piecewise continuous function.

In the end I want to use the parameters in a function defined on my own as

``((xv<0.002)*([0]+x*[1]+x*x*[2]+x*x*x*[3])+(xv>=0.002 && xv<=0.09)*([4]+x*[5]+x*x*[6]+x*x*x*[7])+(xv>0.09)*([8]+x*[9]+x*x*[10]+x*x*x*[11]))``

So I can’t use a TF1 to interpolate.

A working example of my code is:

``````{
double parprime[12] = {
-0.00173391,
2.29074,
-681.27,
54078.6,
-2.45396,
163.542,
-1590.19,
6052.45,
1.60338,
21.4827,
80.8714,
-546.914};

double sec1end = 0.02;
double sec2end = 0.09;
double sec3end= 0.18;
TF1 *sec1 = new TF1("sec1","pol3",0,sec1end);
TF1 *sec2 = new TF1("sec2","pol3",sec1end,sec2end);
TF1 *sec3 = new TF1("sec3","pol3",sec2end,0.18);
sec1->SetParameters(&parprime[0]);
sec2->SetParameters(&parprime[4]);
sec3->SetParameters(&parprime[8]);
// ME TRYING TO MEND THE GAPS::
double sec2current = sec2->GetParameter(0);
double sec2sec2 = sec2(sec1end);
double sec2sec1 = sec1(sec1end);
double sec2NEW = sec2current + (sec2sec1 - sec2sec2);
sec2->SetParameter(0,sec2NEW);

// ME TRYING TO MEND THE GAPS::
double sec3current = sec3->GetParameter(0);
double sec3sec3 = sec3(sec2end);
double sec3sec2 = sec2(sec2end);
double sec3NEW = sec3current + (sec3sec2 - sec3sec2);
sec3->SetParameter(0,sec3NEW);
// FILLING NEW FUNCTION WITH PARAMETERS TO TEST IT OUT
double par[12];
for (int i=0;i<4;i++){
par[i]=sec1->GetParameter(i);
par[i+4]=sec2->GetParameter(i);
par[i+8]=sec3->GetParameter(i);
}
TF1 *hsec1 = new TF1("hsec1","pol3",0,sec1end);
TF1 *hsec2 = new TF1("hsec2","pol3",sec1end,sec2end);
TF1 *hsec3 = new TF1("hsec3","pol3",sec2end,0.18);
hsec1->SetParameters(&par[0]);
hsec2->SetParameters(&par[4]);
hsec3->SetParameters(&par[8]);

// PLOTTING
Double_t w=900;
Double_t h=544;
TCanvas * c1=new TCanvas("c1","Orthcoord vs drifttime",w,h);
c1->SetWindowSize(w + (w - c1->GetWw()), h + (h - c1->GetWh()));
c1->DrawFrame(0,0,0.19,5,"");
sec1->Draw("same");
sec2->Draw("same");
sec3->Draw("same");

}``````

Thankful for help!

HI,

I am not sure I have udersttod completely your problem. Your piece of code does not work, so it cannot be tried.

If I have understood, if you want a continuous function, you should find a common parametrization working for all regions instead of building 3 separate functions

Lorenzo