Hi, I’m trying to perform a fit with a RooAddPdf where the components (which are RooKeysPdf) are read from a workspace in a rootfile. What I do is basically a loop over the pdf that I want to include in the fit and add them to a RooArgSet* Pdfs, then create another RooArgSet* Abundances to store the normalization of the various pdfs for the RooAddPdf* model.
The I would like to get the integral of each component in a given range and use that as estimate of the number of events for each component in that range. I’ve come up with the attached code
// lots of stuff before this, then...
Abundances.Print();
Pdfs.Print();
model = new RooAddPdf("model", "", Pdfs, Abundances);
model->fitTo( *TempDataset, RooFit::Minimizer("Minuit2", "Migrad"), NumCPU(8), Timer(kTRUE) );
sample_datak->SetBinContent(ibin+1, ((RooRealVar*) Abundances.at(0))->getVal());
sample_datak->SetBinContent(ibin+1, ((RooRealVar*) Abundances.at(0))->getError());
UTrChargeVar.setRange("signal", 0, 5);
integral = ((RooKeysPdf*) Pdfs.at(0))->createIntegral(UTrChargeVar, NormSet(UTrChargeVar), Range("signal"));
cout << "Integral = " << integral->getVal() << endl;
cout << "Events = " << integral->getVal() * ((RooRealVar*) Abundances.at(0))->getVal() << " +- " << integral->getVal() * ((RooRealVar*) Abundances.at(0))->getError() << endl;
the problem is that the integral is always 1 regardless of the range I set, which is obviously wrong (see the attached plot for the fit result, component 0 is the red one).
[...]
Minuit2Minimizer : Valid minimum - status = 0
FVAL = -66378.3610329045623
Edm = 2.14752650181576472e-05
Nfcn = 228
nBoron = 8118.02 +/- 91.5493 (limited)
nCarbon = 359.397 +/- 25.4574 (limited)
nNitrogen = 20.257 +/- 6.60095 (limited)
nOxygen = 19.3898 +/- 4.74707 (limited)
[#1] INFO:Minization -- Command timer: Real time 0:00:00, CP time 0.130
[#1] INFO:Minization -- Session timer: Real time 0:00:00, CP time 0.130
Info in <Minuit2>: Minuit2Minimizer::Hesse : Hesse is valid - matrix is accurate
[#1] INFO:Minization -- Command timer: Real time 0:00:00, CP time 0.010
[#1] INFO:Minization -- Session timer: Real time 0:00:00, CP time 0.140, 2 slices
[#1] INFO:Minization -- RooMinimizer::optimizeConst: deactivating const optimization
[#1] INFO:Eval -- RooRealVar::setRange(UTrCharge) new range named 'signal' created with bounds [0,5]
Integral = 1
Scaled Integral = 8118.02 +- 91.5541
What am I doing wrong?
Thanks,
Valerio