How to integrate function in roofit

Dear ROOTers,

Hi.

I’m trying to integrate component functions to compare background and signal in short range.

Actually I found how to integrate a function with given range.
But it looks not work at workspace.

How can I get a component function from workspace and integrate it?

Followings are some part of my code.

Blockquote
RooCBShape* CB1S_1 = new RooCBShape(“CB1S_1”, “1S Crystal ball function1”, (ws->var(“mass”)), mean1S, sigma1S_1, alpha, n);
RooCBShape
CB2S_1 = new RooCBShape(“CB2S_1”, “2S Crystal ball function1”, (ws->var(“mass”)), mean2S, sigma2S_1, alpha, n);
RooAddPdf
twoCB1S = new RooAddPdf(“twoCB1S”, “Sum of 1S Crystal ball”, RooArgList(*CB1S_1, *CB1S_2), RooArgList(*frac));

omit************

Blockquote
RooGenericPdf* bkgErf = new RooGenericPdf(“bkgErr”, “Error background”, "TMath::Exp(-@0/@1)(TMath::Erf((@0-@2)/(TMath::Sqrt(2)@3))+1)0.5", RooArgList((ws->var(“mass”)), Erfp0, Erfmean, Erfsigma));
RooGenericPdf* Signal1S = (RooGenericPdf*) twoCB1S;
RooGenericPdf* Background;
Background = (RooGenericPdf*) bkgErf;
RooAddPdf* model = new RooAddPdf(“model”, “1S+2S+3S+Bkg”, RooArgList(*Signal1S, *Signal2S, *Signal3S, *Background), RooArgList(*nSig1S, *nSig2S, *nSig3S, *nBkg));
ws->import(*model);

Thank you

@moneta maybe you can help here? Thank you!

HI,

To get a function from a workspace, just do

auto function = ws->function(“functionName”);

This will return a RooABsReal function object.
You can integrate either using the function RooAbsReal::createIntegral, but I would prefer
converting the RooAbsReal to a TF1 object using RooAbsReal::asTF and then using TF1::Integral.

Lorenzo

1 Like

Thank you,

I see how it works.
But there is one more question to get the TF.
The command RooAbsReal::asTF need argument list.
However the function I want to call is sum of two function.
So I think the argument list should have different form.

RooCBShape* CB1S_1 = new RooCBShape("CB1S_1", "1S Crystal ball function1", *(ws->var("mass")), mean1S, sigma1S_1, alpha, n);
RooCBShape* CB1S_2 = new RooCBShape("CB1S_2", "1S Crystal ball function2", *(ws->var("mass")), mean1S, sigma1S_2, alpha, n);
RooAddPdf* twoCB1S = new RooAddPdf("twoCB1S", "Sum of 1S Crystal ball", RooArgList(*CB1S_1, *CB1S_2), RooArgList(*frac));
TF1* Sgnfc = ws->function("twoCB1S")->asTF();

How can I set the argument list to make TF1?

Thank you,
Kisoo

Hi,

The argument for making a TF1 are:

 TF1* RooAbsReal::asTF(const RooArgList& obs, const RooArgList& pars, const RooArgSet& nset) const

The Tf1 will be a function of x (observables) and p (parameters)

  • obs is the RooFit list defining the observables (x)
  • pars is the list defining the parameters §
  • nset are the variables (observables) you want to use for returning a normalised function. If you are not interest to get a normalised function, this list should be empty

I hope this answer the question

Best Regards

Lorenzo

Hi,

What I want to know is about pars.
I call the added function.
So the parameters are defined in each function and more parameters are applied when it added.
mean1S, sigma1S_1, alpha, n for CB1S_1.
mean1S, sigma1S_2, alpha, n for CB1S_2.
*CB1S_1, *CB1S_2, *frac for twoCB1S.

It make me confuse.
How can I arrange these parameters to obtain TF from the twoCB1S function?

Thank you,
Kisoo

Hi,

Following is what I have tried to get a function.
But I got segmentation break.
Could you please let me know what is my mistake?

RooRealVar Erfmean(“Erfmean”, “Mean of Errfunction”, 5, 0, 10);
RooRealVar Erfsigma(“Erfsigma”, “Sigma of Errfunction”, 1, 0, 100);
RooRealVar Erfp0(“Erfp0”, “1st parameter of Errfunction”, 1, 0, 30);
RooGenericPdf* bkgErf = new RooGenericPdf(“bkgErr”, “Error background”, "TMath::Exp(-@0/@1)(TMath::Erf((@0-@2)/(TMath::Sqrt(2)@3))+1)0.5", RooArgList((ws->var(“mass”)), Erfp0, Erfmean, Erfsigma));
TF1* Bkgfc = ws->function(“bkgErf”)->asTF(*(ws->var(“mass”)), RooArgList(Erfp0, Erfmean, Erfsigma), *(ws->var(“mass”)));

Thank you,
Kisoo

Hi,

The RooFit function is not imported in the workspace and it is called bkgErr and not bkgErf.
You should do

TF1* Bkgfc = bkgErf->asTF(*(ws->var(“mass”)), RooArgList(Erfp0, Erfmean, Erfsigma), *(ws->var(“mass”)));type or paste code here

Thank you,

The segmentation is disappeared.
But to be sure let me explain my situation more detailed.

Actually the function bkgErf is included in a workspace and fitted to mass distribution.

RooGenericPdf* Background;
Background = (RooGenericPdf*) bkgErf;
RooAddPdf* model = new RooAddPdf(“model”, “1S+2S+3S+Bkg”, RooArgList(*Signal1S, *Signal2S, *Signal3S, *Background), RooArgList(*nSig1S, *nSig2S, *nSig3S, *nBkg));
ws->import(model);
RooFitResult
Result = ws->pdf(“model”)->fitTo(*reducedDS, Save(), Hesse(kTRUE), Range(8, 14), Minos(0), SumW2Error(kTRUE), Extended(kTRUE));

That is why I called the function using “ws->function(“bkgErf”)”.
Then if I call this function directly, the called function reflect the fitting result?

Thank you,
Kisoo

now I found what you mean “bkgErr and not bkgErf”
It was my mistake.
I understand how to get function now.

Thank you

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