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,
Ashfaq
[code]////fit RooGaussian–working
//fitRooGauss.C
void fitRooGauss(){
double x[10000];
//fill array
for(int i=0;i<1000;i++){
double rn =gRandom->Gaus(0,1);
x[i]=rn*0.25;
}
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];
m_ubdata->add(RooArgSet(*m_x));
}
//introduce parameter p0
RooAbsReal m_formVar = new RooFormulaVar(“m_formVar”,"@0@1",RooArgSet(*m_x,*m_p0));
//set mean and sigma constant
m_sigma->setVal(0.05);
m_mean->setVal(0.0);
m_sigma->setConstant();
m_mean->setConstant();
//gauss Pdf
RooGaussian *m_g = new RooGaussian(“m_g”,“gaussian”,*m_formVar,*m_mean,*m_sigma);
//fit
m_g->fitTo(*m_ubdata,“m”);
}
///fit RooKeysPdf-- following macro doesn’t work
////fitRooKeysPdf.C
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);
//fit
m_keyPdf->fitTo(*m_ubdata,“m”);
}[/code]