Fit within region

Is it possible to perform a fit only within a specified region?
A little example to explain what I mean exactly:

Suppose I have a sine signal that reaches from lets say 5 to 10. And I have a linear background from lets say 0 to 15.
Is it possible to have a combined fit function that fits linear from 0 to 5 and 10 to 15 and fits linear plus sine-signal from 5 to 10?

Thanks for your help!

Cheers, Christian

Hi,

you can write your fit function as follows:

double MyFitFunction(const double * x, const double * p) { 
   double f = 0; 
   if (x[0] > 0 && x[0] < 15)   {
      f = par[0] + par[1] * x[0];   
      if ( x[0] > 5 && x[0] < 10 ) 
         f += par[2] * sin( x[0] );
   }
   return f; 
} 

and then create a TF1 to be used for fitting as documented in

root.cern.ch/root/htmldoc/TF1.html#F3

Best Regards

Lorenzo