Switch between 2 functions for a fit

Dear all

I want to fit some data with 1 function for the signal and 2 functions for the background and for switch from the first to the second background function there is a condition on the mass like that:

if x < M -->use bkg function 1 else use bkg function 2 (it will be 2 exponentials with different slopes)

How can I do that with roofit ?

Thanks

Hi,

Can you explain a bit more precisely what you want to do. Does your problem have one or two observable, e.g.
is it

F(x) = S(x) + B1(x) if y<A
F(x) = S(x) + B2(x) if y>A

or
F(x) = S(x) + B(x)

where B(x) = B1(x) if x<A and B(x) = B2(x) if x>A

Wouter

Hi

It’s the second case.

Hi,

OK, that’s actually the more difficult case. The simplest shot at this would use a RooGenericPdf

RooGenericPdf B("B","(x>5)*B1+(x<=5)*B2)",RooArgSet(x,B1,B2)) ;

But this has two issues: 1) Numeric integrals is always used for normalization and 2) you might have a discontuity in your pdf if B1(5) != B2(5). You might be able to improve if you would write a custom class,.e.g

RooClassFactory::makePdf(“RooGluePdf”,“f1,f2,x,xcut”) ;

which will write code for a dummy pdf class RooGluePdf that takes four RooAbsReal input arguments named f1,f2,x,cut. Here you can then put some smarter code in evaluate(), e.g.

RooGluePdf::evaluate() {
if (x<xcut) return f1 ;
if (x>=xcut) {
Double_t xsave = x ; // save present value of x
x = xcut ; // set x to xcut
Double_t ratio = f1/f2 ; // calculate f1(xcut)/f2(xcut)
x = xsave ; // restore x to original value
return f2*ratio ; // return f2(x)*f1(xcut)/f2(xcut)
}
}

You can then use this code by doing
root> .L RooGluePdf.cxx+
and then instantiate it as follows

RooGluePdf B("B","B",x,RooConst(5),B1,B2)) ;

Please be aware that the general problem is quite difficult. The above example does e.g. not handle the case where f1(xcut)=0 in a graceful way.

Wouter

Ok thanks a lot.

There are 2 errors when I try to compile the class

x = xcut ;

RooGluePdf.cxx:: erreur: passing «const RooRealProxy» as «this» argument of «RooRealProxy& RooRealProxy::operator=(const RooRealProxy&)» discards qualifiers

x = xsave ; // restore x to original value

/RooGluePdf.cxx:: erreur: passing «const RooRealProxy» as «this» argument of «RooRealProxy& RooRealProxy::operator=(const Double_t&)» discards qualifiers