Custom PDF in RooWorkspace

Hi,

I am trying to get a custom PDF of mine written to a file within a RooWorkspace.

//==============================================

using namespace RooFit;

RooRealVar x("x","ZZ inv. mass",100,1000);
RooRealVar cutOff("cutOff","fermi cutOff",180);
cutOff.setConstant(kTRUE);
RooRealVar g("g","fermi width",30);
g.setConstant(kTRUE);
RooFermi fermi("fermi","fermi function",x,cutOff,g);

RooWorkspace *w = new RooWorkspace("w","w");
w->importClassCode("RooFermi",kTRUE);
w->import(fermi);

w->writeToFile("simple-shapes-BinnedParam.root");

//============================================
I have the above lines in a root script which, when I run it interactively, writes the rooworkspace to a file. When I restart root I have no problem loading the workspace and I have no problem manipulating the roorealvars but when I try to do something like:

w->(pdf(“fermi”))->getVal();

I get a segmentation violation. Am I doing this correctly? I should say that I have loaded the .so file for my pdf via my rootlogon.C file with the following:

gROOT->ProcessLine(".L /afs/cern.ch/user/w/whitbeck/scratch0/HEP/PDFs/RooFermi_cc.so");

thanks in advance,
Andrew

Hi Andrew,

I’ve had luck using the overloaded version of importClassCode() that takes a TClass instead of a class name.

Replacing the line you currently have with:

myWorkspace->importClassCode(RooFermi::Class(),kTRUE);

Should do the trick for you!
Just make sure you have the include directories that the RooWorkspace will read from configured properly using RooWorkspace::addClassDeclImportDir(const char*).

Once you have the class imported you should no longer need to load the library with the ProcessLine() interface.

Cheers,
Lindsey

Hi,

After doing that, there is another warning message

[#0] WARNING:ObjectHandling – RooWorkspace::autoImportClass(w) WARNING Cannot access code of class RooAbsPdf because implementation file /build/bellenot/SPI/x86_64-slc5-gcc43-dbg/root/roofit/roofitcore/src/RooAbsPdf.cxx is not found in current directory nor in $ROOTSYS, nor in the search path . To fix this problem add the required directory to the search path using RooWorkspace::addClassImplDir(const char* dir)

Any idea to fix that ?

Best,
Mingshui

Hi,

The easiest is to install ROOT from the source.

Cheers,
Philippe.

Hi Philippe,

Many thanks.

But what are the alternative ways without installing root from source?

Best,
Mingshui

Hi Mingshui,

If you have a path to the directory of ROOT that you’re using you should be able to only add the path:

/<path/to/root>/roofit/roofitcore/src/

to the workspace using myWorkspace->importClassImplDir(“thedir”).

-Lindsey

Hi Lindsey,

I did the following :

RooWorkspace *w = new RooWorkspace("w","w"); w->addClassDeclImportDir("/afs/cern.ch/sw/lcg/app/releases/ROOT/5.28.00b/x86_64-slc5-gcc43-dbg/root"); w->addClassImplImportDir("/afs/cern.ch/sw/lcg/app/releases/ROOT/5.28.00b/src/root/roofit/roofitcore/src/"); w->addClassImplImportDir("/afs/cern.ch/sw/lcg/app/releases/ROOT/5.28.00b/src/root/roofit/roofitcore/"); w->import(fermi); w->importClassCode(RooFermi::Class(),kTRUE);
and it still gives

[color=#FF0000][#0] WARNING:ObjectHandling – RooWorkspace::autoImportClass(w) WARNING Cannot access code of class RooAbsPdf because implementation file /build/bellenot/SPI/x86_64-slc5-gcc43-dbg/root/roofit/roofitcore/src/RooAbsPdf.cxx is not found in current directory nor in $ROOTSYS, nor in the search path /afs/cern.ch/sw/lcg/app/releases/ROOT/5.28.00b/src/root/roofit/roofitcore/src/,/afs/cern.ch/sw/lcg/app/releases/ROOT/5.28.00b/src/root/roofit/roofitcore/. To fix this problem add the required directory to the search path using RooWorkspace::addClassImplDir(const char* dir)

[/color]

Any hints ?

Best,
Mingshui

Hi,

This feature requires a build of ROOT that contains ROOT’s own source code. You will need to download and build your own copy.

Cheers,
Philippe.

Hi,

I like to resurrect this topic. I am attempting to implement the samething as the OP. I am trying to use the suggestion of w->importClassCode(Fermi::Class(),kTRUE); for my own PDF class.

The follow codes compiles and loads RooSignalPDF just fine, but it is unable to import the ClassCode.
PLRun3.cxx:66:22: error: ‘RooSignalPDF’ has not been declared
w->importClassCode(RooSignalPDF::Class(),kTRUE)

Normally I would just
w->importClassCode(“RooSignalPDF”,kTRUE). But I am having trouble getting the class to run with PROOF. I was hoping importing the actual class itself might help.

Thanks,

=======================

gROOT->ProcessLine(".L …/Models/RooSignalPDF.cxx++");
gROOT->ProcessLine(".L …/Models/RooSignalPDF_cxx.so");
w->factory(“SignalPDF::SigPDF(mWimp,r,S1,log10S2)”);
w->addClassImplImportDir("…/Models/");
w->addClassDeclImportDir("…/Models/");
w->importClassCode(RooSignalPDF::Class(),kTRUE);