RooFit, formulas in RooHistPdf

Hi,

I want to create a RooHistPdf from an observable in a dataset. The twist is that I don’t want to use the observable as it is, but apply a formula to it, but I can’t seem to do this since a RooFormulaVar isn’t of “fundamental” type. This code snippet reproduces my problem:

{
using namespace RooFitShortHand;
RooRealVar sigma(“sigma”,“sigma”,0.0,0.2);
RooLandau sigma_dist(“sigma_dist”,“sigma_dist”,sigma, C(0.05),C(0.01));
RooDataSet *datasigma = sigma_dist.generate(RooArgSet(sigma),5000);
RooFormulaVar d1(“d1”,“sqrt(@0)”,RooArgSet(sigma));
RooDataHist h1(“h1”,“h1”,d1,*datasigma);
RooHistPdf (“h1pdf”,“h1pdf”,d1,h1);
}

which gives me the error
RooAbsSet::initialize(h1): Data set cannot contain non-fundamental types, ignoring d1

Does anyone know what I am doing wrong here? Is there another way to do this?

cheers
Aras

1 Like

Hi Aras,

Sorry for the late reply. I was on vacation.

Datasets can only contain fundamentals (i.e variables), not observables.

If you want to make a plot of a distribution of a derived observable,
you can do that easily, but it requires an intermediate step: you add a column
to the dataset with the calculated values of your transformation function on
the data points already contained in the dataset. Here is a modified version
of your example:

using namespace RooFitShortHand;
RooRealVar sigma(“sigma”,“sigma”,0.0,0.2);
RooLandau sigma_dist(“sigma_dist”,“sigma_dist”,sigma, C(0.05),C(0.01));
RooDataSet *datasigma = sigma_dist.generate(RooArgSet(sigma),5000);
RooFormulaVar d1_func(“d1”,“sqrt(@0)”,RooArgSet(sigma));

RooRealVar* d1 = (RooRealVar*) datasigma->addColumn(d1_func) ; // <–

RooDataHist h1(“h1”,“h1”,*d1,*datasigma);
RooHistPdf (“h1pdf”,“h1pdf”,*d1,h1);

The magic line is the one marked with the arrow, which adds a column to your
dataset with the output of the transformation that you give it.

I’ll answer your other posting on conditional p.d.f.s tomorrow.

Wouter

Thanks, this seems to work!

cheer
Aras