Home | News | Documentation | Download

Persistifying a RooNDKeysPdf

Hi,

I am trying to save a RooNDKeysPdf object into a TFile and get this message:

PyROOT> SMPDF.Write()
TKey::TKey:0: RuntimeWarning: since RooNDKeysPdf has no public constructor
which can be called without argument, objects of this class
can not be read with the current library. You will need to
add a default constructor before attempting to read it.
TClass::TClass:0: RuntimeWarning: no dictionary for class RooNDKeysPdf::BoxInfo is available
685

When I try to read-in the object (from the TFile), it doesn’t work:

PyROOT> f.Get(“SMPDF”)
Error in TClass::New: cannot create object of class RooNDKeysPdf
Error in TKey::ReadObj: Cannot create new object of class RooNDKeysPdf
PyROOT>

Is there any other way to persistify such an object (because creating it takes a lot of time) ?

Thanks a lot
Till

1 Like

Hi Till,

Class RooNDKeysPdf is one of the few classes that I had not gotten around to be persistable yet. It is a contributed class and somewhat complex so I am not sure
I will manage to get this done before the next ROOT Release.

I note in general that if you want to persist RooFit classes you should use the RooWorkspace to ensure that all connected objects (p.d.f.s, variables) etc
are written in the same operation, otherwise it will not work. See tutorial macro
$ROOTSYS/tutorials/roofit/rf502_wspacewrite.C and rf503_wspaceread.C
for examples.

Wouter

Hi Wouter,
thanks, good to know about the RooWorkspace.
Would be nice if the RooNDKeysPdf class can be persitified one day too :slight_smile:

Cheers & thanks,
Till

Hello,

any news about persistification of RooNDKeysPdf?
Salvatore

Hi, I’m trying to persistify RooNDKeysPdf with root 6.02/10 and I still have the same problem reported above:

Warning in <TKey::TKey>: since RooNDKeysPdf has no public constructor which can be called without argument, objects of this class can not be read with the current library. You will need to add a default constructor before attempting to read it.

Any hope that RooNDKeysPdf will became writable sometime?

I attach a standalone macro to reproduce the behavior
Test_RooNDKeysPdf.C (1.94 KB)

I am going to second the request. Users will do work with the PDFs so it would be nice to generate them once and then be able to call them when needed. Thanks.

We will add this capability. We are also working on a new faster implementation of the class, hopefully will be ready in the next ROOT version

Lorenzo

Hi, Wouter:

I would like to know whether this problem have been resolved?
I am looking forward to hearing your message .

Best wishes
Volcano

Hi,

Unfortunately this problem has not been yet solved. We will let you know when will it be done

Lorenzo

1 Like

Hi,

Is this problem solved yet?
I’ve also encountered some similar problem.
I want to save the PDF since RooNDKeysPDF generates extremely slow, so I would not want to generate it every time when I want to use it…
Thanks.

Not yet, I have created a JIRA item, so it will not be forgotten

See https://sft.its.cern.ch/jira/browse/ROOT-10341

Lorenzo

1 Like

Hi, is there any update on this bug?

Hi,

the NDKeysPdf needs serious work, so persistifying it now is probably a bad idea. I can try to get it done as a temporary fix. But when this class gets overhauled, it might not be possible to read back the current version of it.

It’s done, and first tests seem to work. Could you test tomorrow with one of ROOT’s nightly versions?
https://root.cern/nightlies

1 Like

Hi, thanks for doing it so quickly. Do you know how I can test this on an lxplus machine?

Yes, source the setup script for the full LCG software stack from the nightlies page that I linked in my previous post. Use the version from Tuesday or Wednesday to get the updated NDKeysPdf.

Thanks a lot. I tested it with the code below [1], which generates a 2D data and creates a RooNDKeys pdf. Everything works find except “workspace->Print().”, which gives a segfault [2]. Could you fix this?

[1] Test code:

> #include "RooGlobalFunc.h"
> #endif
> #include "RooRealVar.h"
> #include "RooDataSet.h"
> #include "RooGaussian.h"
> #include "RooConstVar.h"
> #include "RooPolynomial.h"
> #include "RooKeysPdf.h"
> #include "RooNDKeysPdf.h"
> #include "RooProdPdf.h"
> #include "TCanvas.h"
> #include "TAxis.h"
> #include "TH1.h"
> #include "RooPlot.h"
> #include "RooWorkspace.h"
> #include "TFile.h"
> using namespace RooFit ;
> 
> 
> void writeNDKeys(){
>   // Construct a 2D toy pdf for sampleing
> 	RooRealVar x("x","x",0,20) ;
> 	RooRealVar y("y","y",0,20) ;
> 	RooPolynomial p("p","p",x,RooArgList(RooConst(0.01),RooConst(-0.01),RooConst(0.0004))) ;
> 	RooPolynomial py("py","py",y,RooArgList(RooConst(0.01),RooConst(0.01),RooConst(-0.0004))) ;
> 	RooProdPdf pxy("pxy","pxy",RooArgSet(p,py)) ;
> 	RooDataSet* data = pxy.generate(RooArgSet(x,y),1000) ;
>   // Create 2D adaptive kernel estimation pdf with mirroring 
> 	RooNDKeysPdf kdeTest("kdeTest","kdeTest",RooArgSet(x,y),*data,"am") ;
> 
> 	RooWorkspace workspace("workspace","workspace");
> 	workspace.import(kdeTest) ;
> 	workspace.import(*data) ;
> 	workspace.Print() ;
> 	workspace.writeToFile("outFile.root") ;
> 
> 	cout<<"Wrote file"<<endl;
> };
> 
> void readNDkeys(){
> 	// Open input file with workspace (generated by writeNDKeys)
> 	TFile *f = new TFile("outFile.root") ;
> 
>   	// Retrieve workspace from file
> 	RooWorkspace* workspace = (RooWorkspace*) f->Get("workspace") ;
> 
> 	workspace->Print() ;
> 
>   	// Retrieve x,model and data from workspace
> 	RooRealVar* x = workspace->var("x");
> 	RooRealVar* y = workspace->var("y");
> 	RooAbsPdf* kdeTest = workspace->pdf("kdeTest");
> 
> 	// Create histogram of the 2d kernel estimation pdf
> 	TH1* hh_pdf = kdeTest->createHistogram("hh_pdf",*x,Binning(25),YVar(*y,Binning(25))) ;
> 
> 	TCanvas* c = new TCanvas("readNDkeys","readNDkeys",800,800) ;
> 	c->Draw();
> 	c->cd();
> 	gPad->SetLeftMargin(0.15) ;
> 	hh_pdf->Draw("lego");
> 
> 	// f->Close();
> };

[2] Error:

> 
> RooWorkspace(workspace) workspace contents
> 
> variables
> ---------
> (x,y)
> 
> p.d.f.s
> -------
> 
> *** Break *** segmentation violation
> RooNDKeysPdf::kdeTest[ varList=(x,y) rhoList=() ] =
> 
> ===========================================================
> There was a crash.
> This is the entire stack trace of all threads:
> ===========================================================
> #0  0x000000344eaac89e in waitpid () from /lib64/libc.so.6
> #1  0x000000344ea3e4e9 in do_system () from /lib64/libc.so.6
> #2  0x00007fc7bde1ceda in TUnixSystem::StackTrace() () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-
> gcc8-opt/lib/libCore.so
> #3  0x00007fc7bde1f734 in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD
> /x86_64-slc6-gcc8-opt/lib/libCore.so
> #4  <signal handler called>
> #5  0x00007fc7a6e8c048 in RooNDKeysPdf::gauss(std::vector<double, std::allocator<double> >&, std::vector<std::vector<double, std::allo
> cator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&) const () from /cvmfs/sft-nightlies.cern.ch/lcg/nigh
> tlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libRooFit.so
> #6  0x00007fc7a6e8d7e6 in RooNDKeysPdf::evaluate() const () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-
> slc6-gcc8-opt/lib/libRooFit.so
> #7  0x00007fc7a9159eb4 in RooAbsPdf::getValV(RooArgSet const*) const () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/
> HEAD/x86_64-slc6-gcc8-opt/lib/libRooFitCore.so
> #8  0x00007fc7a915696e in RooAbsPdf::printValue(std::basic_ostream<char, std::char_traits<char> >&) const () from /cvmfs/sft-nightlies
> .cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libRooFitCore.so
> #9  0x00007fc7a92b39f0 in RooPrintable::printStream(std::basic_ostream<char, std::char_traits<char> >&, int, RooPrintable::StyleOption
> , TString) const () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libRooFitCore.so
> #10 0x00007fc7a911840b in RooAbsArg::Print(char const*) const () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x8
> 6_64-slc6-gcc8-opt/lib/libRooFitCore.so
> #11 0x00007fc7a933fe78 in RooWorkspace::Print(char const*) const () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD
> /x86_64-slc6-gcc8-opt/lib/libRooFitCore.so
> #12 0x00007fc7a6ac5d70 in readNDkeys() () from /home/wadud/aNTGC/antgcpreselector/macros/jet2pho/fitEstimate/batch/testKDEnumeratorDat
> a/testNDKeys_C.so
> #13 0x00007fc7b7ebe066 in ?? ()
> #14 0x0000000103442f70 in ?? ()
> #15 0x0000000001e723e0 in ?? ()
> #16 0x00007fc7b98de820 in ?? () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libCling.s
> o
> #17 0x00007ffee1d17590 in ?? ()
> #18 0x00007fc7b7ebe000 in ?? ()
> #19 0x00007fc7b98b80d9 in cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const () from /cvmfs/sft-nightlie
> s.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libCling.so
> #20 0x00007fc7b984c753 in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) () from /cvmfs/sft-nightlies.cern
> .ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libCling.so
> #21 0x00007fc7b9851d52 in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator
> <char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /cvmfs/sft-nightlies.cern.ch/l
> cg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libCling.so
> #22 0x00007fc7b9852319 in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >
> const&, cling::Value*, cling::Transaction**, bool) () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-g
> cc8-opt/lib/libCling.so
> #23 0x00007fc7b9906e3d in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool)
> () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libCling.so
> #24 0x00007fc7b97c6a6c in HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling
> ::Value*) () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libCling.so
> #25 0x00007fc7b97d9522 in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /cvmfs/sft-nightlies.cern.ch/lcg/nightli
> es/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libCling.so
> #26 0x00007fc7bdce18a2 in TApplication::ProcessLine(char const*, bool, int*) () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/F
> ri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libCore.so
> #27 0x00007fc7be256082 in TRint::ProcessLineNr(char const*, char const*, int*) () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3
> /Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libRint.so
> #28 0x00007fc7be2563f3 in TRint::HandleTermInput() () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-g
> cc8-opt/lib/libRint.so
> #29 0x00007fc7bde1ea4b in TUnixSystem::CheckDescriptors() () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64
> -slc6-gcc8-opt/lib/libCore.so
> #30 0x00007fc7bde203c8 in TUnixSystem::DispatchOneEvent(bool) () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x8
> 6_64-slc6-gcc8-opt/lib/libCore.so
> #31 0x00007fc7bdd43d81 in TSystem::Run() () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/li
> b/libCore.so
> #32 0x00007fc7bdcdea1f in TApplication::Run(bool) () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gc
> c8-opt/lib/libCore.so
> #33 0x00007fc7be2578f6 in TRint::Run(bool) () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/
> lib/libRint.so
> #34 0x00000000004009aa in main ()
> ===========================================================
> 
> The lines below might hint at the cause of the crash.
> You may get help by asking at the ROOT forum http://root.cern.ch/forum
> Only if you are really convinced it is a bug in ROOT then please submit a
> report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
> from above as an attachment in addition to anything else
> that might help us fixing this issue.
> ===========================================================
> #5  0x00007fc7a6e8c048 in RooNDKeysPdf::gauss(std::vector<double, std::allocator<double> >&, std::vector<std::vector<double, std::allo
> cator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&) const () from /cvmfs/sft-nightlies.cern.ch/lcg/nigh
> tlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libRooFit.so
> #6  0x00007fc7a6e8d7e6 in RooNDKeysPdf::evaluate() const () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-
> slc6-gcc8-opt/lib/libRooFit.so
> #7  0x00007fc7a9159eb4 in RooAbsPdf::getValV(RooArgSet const*) const () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/
> HEAD/x86_64-slc6-gcc8-opt/lib/libRooFitCore.so
> #8  0x00007fc7a915696e in RooAbsPdf::printValue(std::basic_ostream<char, std::char_traits<char> >&) const () from /cvmfs/sft-nightlies
> .cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libRooFitCore.so
> #9  0x00007fc7a92b39f0 in RooPrintable::printStream(std::basic_ostream<char, std::char_traits<char> >&, int, RooPrintable::StyleOption
> , TString) const () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libRooFitCore.so
> #10 0x00007fc7a911840b in RooAbsArg::Print(char const*) const () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x8
> 6_64-slc6-gcc8-opt/lib/libRooFitCore.so
> #11 0x00007fc7a933fe78 in RooWorkspace::Print(char const*) const () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD
> /x86_64-slc6-gcc8-opt/lib/libRooFitCore.so
> #12 0x00007fc7a6ac5d70 in readNDkeys() () from /home/wadud/aNTGC/antgcpreselector/macros/jet2pho/fitEstimate/batch/testKDEnumeratorDat
> a/testNDKeys_C.so
> #13 0x00007fc7b7ebe066 in ?? ()
> #14 0x0000000103442f70 in ?? ()
> #15 0x0000000001e723e0 in ?? ()
> #16 0x00007fc7b98de820 in ?? () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libCling.s
> o
> #17 0x00007ffee1d17590 in ?? ()
> #18 0x00007fc7b7ebe000 in ?? ()
> #19 0x00007fc7b98b80d9 in cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const () from /cvmfs/sft-nightlie
> s.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libCling.so
> #20 0x00007fc7b984c753 in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) () from /cvmfs/sft-nightlies.cern
> .ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libCling.so
> #21 0x00007fc7b9851d52 in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator
> <char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /cvmfs/sft-nightlies.cern.ch/l
> cg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libCling.so
> #22 0x00007fc7b9852319 in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >
> const&, cling::Value*, cling::Transaction**, bool) () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-g
> cc8-opt/lib/libCling.so
> #23 0x00007fc7b9906e3d in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool)
> () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libCling.so
> #24 0x00007fc7b97c6a6c in HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling
> ::Value*) () from /cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev3/Fri/ROOT/HEAD/x86_64-slc6-gcc8-opt/lib/libCling.so
> ===========================================================```

Thanks for the feedback!
I found the problem, and you can test again tomorrow.

PS:
Enclose code in “```”, so it gets formatted nicely.

It works now! Thanks a lot for this!
(Cheers for the tip - code looks better now)