Nb of signal and bkg event after a fit in a specific range

Hello,

I have a stupid question. I want to get the number of signal and background event after my fit. I use :

RooAddPdf sum(“sum”,“Signal+Bkg”,RooArgList(gauss,px),gaussFrac);

and after the fit I do :

RooAbsReal* Sig = gauss.createIntegral(x, x, “signal”) ;
Double_t nsig = Sig->getVal();

RooAbsReal* fracBkg = px.createIntegral(x, x, “signal”) ;
Double_t nbkg = Bkg->getVal();

but I am probably doing the wrong thing because the results is not what I expect.

I saw that it is possible to fit Nsig and Nbkg but with :
RooAddPdf sum(“sum”,“Signal+Bkg”,RooArgList(Sig,Bkg),RooArgList(Nsig,Nbkg),gausFrac); and the extended fit it seems that I cannot use the additional argument gauFrac that is needed to fit my data.

I guess there is something obvious that I am not doing.
Thanks for any idea
Cheers
Fabien

Dear Fabian,

You can either perform an extended fit (fit for Ns and Nb with a Poisson constain to the number of entries Ntot in your dataset) or a non-extended fit where the number of entries in the dataset is kept as total normalisation.

double Ntot = data.numEntries();
double frac = gaussFrac.getVal();

In the second case the signal yield is Ntotfrac and background Ntot(1-frac).

In the first case you don’t fit for gaussFrac but Nsig and Nbkg only :
RooAddPdf sum(“sum”,“Signal+Bkg”,RooArgList(Sig,Bkg),RooArgList(Nsig,Nbkg));

You can check the RooFit documentation on Extended fits to see what’s the difference on the formula of the likelihood function.

Then: double frac = Nsig.getVal()/(Nsig.getVal()+Nbkg.getVal());

in case of need, you can also create a FooFormulaVar frac(“frac”,"@0/(@0+@1)",RooArgList(RooArgList(Nsig,Nbkg)));

Regards,

– Gregory

Dear Gregory,
Thanks a lot for your answer. I tried one of your solution :

double Ntot = data.numEntries();
double frac = gaussFrac.getVal();

In the second case the signal yield is Ntotfrac and background Ntot(1-frac).

but I am surprised by the result :

RooRealVar mgg(“mgg”,“Uncorrected m_{#gamma#gamma}”,0.,1000.,“MeV”);
RooDataHist dh(“dh”,“dh”,mgg,hRoot);

hRoot->GetEntries() = 2.41455e+06

Nfrac = 0.00945642
Signal : NtotNfrac = 0.945642
Bkg : Ntot
(1-Nfrac) = 99.0544

number of bins in dh : dh.numEntries() : 100
sum of weights in dh : dh.sum(kFALSE) : 907244
integral over histogram : dh.sum(kTRUE) : 9.07244e+06

It seems that dh.numEntries() give the number of bin and dh.sum(kTRUE) the number of entries. What surprised my is that the number of entries given by “ROOT” :
hRoot->GetEntries() = 2.41455e+06

is different from the one given by “ROOFIT”
dh.sum(kTRUE) = 9.07244e+06

I am using ROOT 5.22.00d/slc4_amd64_gcc34.
Any idea ?

Thanks
Cheers
Fabien

Hello,

Let me conclude on this thread :

with ROOT :
hRoot->GetEntries() = 51635
hRoot->Integral() = 19051
hRoot->GetNbinsX() = 100

The mistake that I did previously was to use GetEntries that take into account the underflow/overflow bins

with ROOFIT

number of bins in dh : dh.numEntries() : 100
sum of weights in dh : dh.sum(kFALSE) : 19051
integral over histogram : dh.sum(kTRUE) : 190510

It seems that the equivalent of Integral in ROOT fit is .sum(kFalse) and dh.numEntries() give the number of bins

Cheers
Fabien