RooFit Problem

I would like to fit a generated RooKeysPdf for unknown parameter(m_p0) which is introduced by using RooFormulaVar. I can do the above using the built in RooFit Pdfs e,g RooGuassian as shown in the first macro below but if I do the same with RooKeysPdf then the program crashes as shown in the second macro(fitRooKeysPdf.C).

I can avoid the crash by adding a new column of type “RooForumaVar” to my data set and then the program runs but it doesn’t perform any fitting and I get the following message “Observables (m_formVar) in dataset are either not used at all, orserving exclusively p.d.f nodes that are now cached, disabling reading of these observables for TTree”.

Does anyone knows how to fit RooKeysPdf for unknown parameter(m_p0) and make the second macro working?

Thanks for your help,

[code]////fit RooGaussian–working

void fitRooGauss(){

double x[10000];

//fill array
for(int i=0;i<1000;i++){
double rn =gRandom->Gaus(0,1);

RooRealVar *m_x = new RooRealVar(“m_x”,“x observable”,-5.0,5.0);
RooRealVar *m_p0 = new RooRealVar(“m_p0”,“param”,-0.5,0.5);
RooDataSet *m_ubdata = new RooDataSet(“ubdata”,“unbinned dataSet”,RooArgSet(*m_x ));

for(int i=0; i<1000; i++){
*m_x = x[i];

//introduce parameter p0
RooAbsReal m_formVar = new RooFormulaVar(“m_formVar”,"@0@1",RooArgSet(*m_x,*m_p0));
//set mean and sigma constant

//gauss Pdf

RooGaussian *m_g = new RooGaussian(“m_g”,“gaussian”,*m_formVar,*m_mean,*m_sigma);


///fit RooKeysPdf-- following macro doesn’t work

void fitRooKeysPdf(){
/////here goes the same lines as in the above macro

//introduce parameter p0
RooAbsReal m_formVar = new RooFormulaVar(“m_formVar”,"@0@1",RooArgSet(*m_x,*m_p0));
//adding new column to data set
RooRealVar newVar =(RooRealVar) m_ubdata->addColumn(*m_formVar);

//with the following line program crashes
//RooKeysPdf *m_keyPdf = new RooKeysPdf(“keyPdf”,“keypdfFromHist”,*m_formVar,*m_ubdata);
//with the following program runs but without fitting…
RooKeysPdf *m_keyPdf = new RooKeysPdf(“keyPdf”,“keypdfFromHist”,*newVar,*m_ubdata);




A keys p.d.f has no parameters (intentionally!) so it cannot be fit by itself as there is nothing to do. You can add it to another p.d.f or multiply it with something, or aso you transform its input with a function that introduces a parameter, so that the overall p.d.f has parameters.

Of course the code shouldn’t crash, I will fix that, so that you’ll get just an error messages.



Could you please let me know how can I transform the input with a function to introduce a parameter? You can see in the code that I introduce a parameter with RooFormulaVar which doesn’t work for RooKeysPdf though it works for parametric Pdf like RooGaussian. As I wrote before by adding a new column to the data set the crashes goes away but still I can’t fit for the unknown parameter as given in the macro in my previous posting. Should I be using something other than RooFormulaVar?

I need to introduce a parameter instead of multiplying or adding it to another Pdf.

Thanks for your help.


OK. I think there are two issues

  1. By using the addColumn technique you add a new observable
    to your dataset which will subsequently be considered an
    new fundamental observable. The fact that it was calculated through
    some parameterized function from another observable is lost
    at that point. Thus if you construct a RooKeysPdf in terms of this
    addColumned() observable the fit still has no parameters, it
    just works with another observable. If you intend parameter of
    your RooFormulaVar transformation to be floating you need to
    construct your p.d.f explicitly that way, i.e. just express the p.d.f
    directly in terms of the transformation function, in other words,
    just leave out the addColumn() call

  2. That brings me to the next issue. I think this will work for any
    p.d.f except RooKeysPdf. The current implementation assumes
    that it shape is eternally fixed and in fact calculates a lookup table
    in the ctor because the actual calculation is very expensive. I’m
    very close to committing a new version of RooKeysPdf that should
    not have this problem. It will probably appear next week (this week
    is ATLAS Software week and I have little time)


Hi Wouter,

Thanks for your help. I’ll be waiting for the new version of RooKeysPdf. BTW I have the same problem with the RooHistPdf probably because it is also a non-parametric Pdf like RooKeysPdf.

Thanks again,