Problem with integral over subrange of RooKeysPdf

Hello,

I have the following problem. I tried to store my pdfs to a TFile in order to read them out later. My problem is that I need an integral over a subrange of the pdf. But when performing the integral I always get the integral of the full range (1). I do the following:

[code] TFile f(“FitTuple/pdf.root”)
root [1] f.ls()
TFile** FitTuple/pdf.root
TFile* FitTuple/pdf.root
KEY: RooKeysPdf D0Pi_mm2_D1lnu_pdf;1 D0Pi_mm2_D1lnu_pdf
KEY: RooKeysPdf D0Pi_mm2_D2lnu_DPi_pdf;1 D0Pi_mm2_D2lnu_DPi_pdf

root [2] RooRealVar mm2(“mm2”,“mm2”, 1, -2, 2)

//I plotted the pdf to check if it looks right (it does)
root [3] RooPlot * p = mm2.frame()
root [4] D0Pi_mm2_D1lnu_pdf->plotOn§
[#1] INFO:NumericIntegration – RooRealIntegral::init(D0Pi_mm2_D1lnu_pdf_Int[mm2]) using numeric integrator RooIntegrator1D to calculate Int(mm2)
(const class RooPlot*)0x284cdd0
root [5] p->Draw()
Info in TCanvas::MakeDefCanvas: created default TCanvas with name c1

root [6] mm2.setRange(“test”, 0, 0.2)
[#1] INFO:Eval – RooRealVar::setRange(mm2) new range named ‘test’ created with bounds [0,0.2]
root [7]
root [7] RooRealVar * i = D0Pi_mm2_D1lnu_pdf->createIntegral(mm2, mm2, “test”)
[#1] INFO:NumericIntegration – RooRealIntegral::init(D0Pi_mm2_D1lnu_pdf_Int[mm2]) using numeric integrator RooIntegrator1D to calculate Int(mm2)
root [8] i->getVal()
[#1] INFO:NumericIntegration – RooRealIntegral::init(D0Pi_mm2_D1lnu_pdf_Int[mm2|test]_Norm[mm2]) using numeric integrator RooIntegrator1D to calculate Int(mm2)
(const Double_t)9.99999999999999889e-01
root [9]
root [10] D0Pi_mm2_D1lnu_pdf->Print(“v”)
— RooAbsArg —
Value State: DIRTY
Shape State: clean
Attributes:
Address: 0x2928480
Clients:
(0x2f224c0,–) RooRealIntegral::D0Pi_mm2_D1lnu_pdf_Int[mm2|test]_Norm[mm2] “Integral of D0Pi_mm2_D1lnu_pdf”
(0x2f493d0,–) RooRealIntegral::D0Pi_mm2_D1lnu_pdf_Int[mm2] "Integral of D0Pi_mm2_D1lnu_pdf"
Servers:
(0x2a31e20,V-) RooRealVar::mm2 "mm2"
Proxies:
x -> mm2
— RooAbsReal —

Plot label is “D0Pi_mm2_D1lnu_pdf”
— RooAbsPdf —
Cached value = 0.061351
Normalization integral:
0x2f493d0 D0Pi_mm2_D1lnu_pdf_Int[mm2][ Int D0Pi_mm2_D1lnu_pdf dNum ] = 0.333332 “Integral of D0Pi_mm2_D1lnu_pdf”

[/code]

The used pdf is defined between -2 and 2. The code to do the integral shown above worked in the case I do not load the pdf from a file but create it from a RooDataset. My root version is ROOT 5.28/00h (branches/v5-28-00-patches@42209), with RooFit v3.14.

Best regards,
Thomas

Hello,

here a tiny update. I experience the same problem with the RooVoigtianPdf.

Could someone confirm that this problem is reproducible?

Cheers,
Thomas

Hi,

I had the same problem and given that no one has answered Tomas’ question in 2 years I had to spend an hour of my time trying to fix it myself. The reason why this does not work is because the PDF stores the set of RooRealVar in a RooAbsSet and you have to use the observable there to get the integral. The very simple code below illustrates this.

[code]#include

#include “TFile.h”
#include “RooGenericPdf.h”
#include “RooRealVar.h”
#include “RooPlot.h”

void test(int min_x, int max_x)
{
RooRealVar *var = new RooRealVar(“x”,"",40,120);
RooGenericPdf *pdf = new RooGenericPdf(“pdf”,"",“TMath::Exp(-x/100)”,RooArgSet(*var) );

TFile ofile("integral_test.root","recreate");
pdf->Write();
ofile.Close();
///////////////////////////////////////////////////////
TFile *ifile = new TFile("integral_test.root");
RooGenericPdf *pdf_f = (RooGenericPdf*)ifile->Get("pdf");

RooArgSet *vset = pdf_f->getVariables();
RooRealVar *var_pdf = (RooRealVar*)vset->find("x");
var_pdf->setRange("range_f",min_x,max_x);

RooAbsReal *integral_f = pdf_f->createIntegral(*var_pdf, *var_pdf, "range_f");
cout<<"INTEGRAL FROM FILE ::"<<integral_f->getVal()<<endl;

}[/code]