Add step function in the final pdf

I want to build a roofit pdf which contains a step function. For example, g(x,a)*step(x,b) where a and b are the parameters of g and step functions, which need to be obtained by fitting. I have got the g(x,a) but I don’t know how to build step function in the roofit.

Hi @zebing_wang!

Have a look at the RooStepFunction, which takes a list of boundaries and coefficients to describe a general step function. You can turn such a step function into a PDF by using the RooWrapperPdf class. Then, you can multiply your PDFs with a RooProdPdf.

In case it is simpler to just write your PDF in a formula string, you can also consider to use the RooGenericPdf.

I hope this helps you to get started!


Hi, thanks for your method. I tried to use RooGenericPdf to build this function, it worked. But I need to convolute it with a gaussian function, which always failed. Do you know how I can convolute with a gaussian? There is my codes. Thanks!

void test(){
RooRealVar *obs_var = new RooRealVar(“obs_var”, “obs_var”,120,110,180) ;

RooRealVar *tau = new RooRealVar(“tau”,“tau”,-0.02,-10,-0.) ;
RooExponential *exp = new RooExponential(“model”,“model”,*obs_var,*tau) ;
RooRealVar *mean = new RooRealVar(“mean”,“mean”,10,0,180) ;
RooRealVar *sigma = new RooRealVar(“sigma”,“sigma”,20,-10, 20) ;
RooGaussian *gaus = new RooGaussian(“gaus”,“gaus”,*obs_var,*mean,*sigma) ;

RooRealVar *step_value = new RooRealVar(“step_value”, “step value”,120.,110.,130.) ;
//RooGenericPdf *step_func = new RooGenericPdf(“step_func”,“step_func”,“(abs(step_value-obs_var)/(step_value-obs_var)+1.0)/2.0”,RooArgSet(*obs_var,*step_value));
RooGenericPdf *step_func = new RooGenericPdf(“step_func”,“step_func”,"((abs( @ 0- @ 1)/(@ 0-@ 1)+1.0)/2.0)*@ 2",RooArgSet(*obs_var,*step_value,*exp));
//RooProdPdf *step_gen = new RooProdPdf(“model”, “model”, RooArgSet(*step_func,*exp));
RooFFTConvPdf *exp_gaus = new RooFFTConvPdf(“exp_gaus”,“exp_gaus”, *obs_var, *gaus, <em>step_func);
RooPlot</em> frame = obs_var->frame() ;
frame->Draw() ;


Just for reference, this separate question was followed up on in a separate thread:

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