Retrieving a non parametric function

I have interpolated an experimental distribution
with a non parametric function using RooNDKeysPdf :

RooNDKeysPdf *kest4 ;
kest4 = new RooNDKeysPdf(“kest4”,“kest4”,RooArgSet(Mnu2),data,“am”) ;

I wish to save this function for later use, possibly in the form of C++ code. The following lines :

ofstream outfile ;“T.cxx”,ios::out) ;
kest4->SavePrimitive( outfile,"" ) ;
outfile.close() ;

kest4->SaveAs(“test.C”) ;
kest4->SaveAs(“test.root”) ;

don’t work :

[pbsimo:~/PDF-Analyzer/RootNewFiles/MakeNonParametricPdf] simo% more T.cxx
//Primitive: kest4/kest4. You must implement RooNDKeysPdf::SavePrimitive
[pbsimo:~/PDF-Analyzer/RootNewFiles/MakeNonParametricPdf] simo%

while the file test.root contains in fact the Object key4 but I cannot then use it:

root [0] TFile f(“test.root”)
root [1]
TFile** test.root
TFile* test.root
KEY: RooNDKeysPdf kest4;1 kest4
root [2] RooNDKeysPdf *k = (RooNDKeysPdf) f.Get(kest4)->Clone(“k”)
Error in TClass::New: cannot create object of class RooNDKeysPdf
Error in TKey::ReadObj: Cannot create new object of class RooNDKeysPdf
Error: Symbol kest4 is not defined in current scope (tmpfile):1:
Error: non class,struct,union object Get(kest4) used with . or -> (tmpfile):1:
Error: illegal type cast (2) (tmpfile):1:
*** Interpreter error recovered ***

(other attemps similarly failed). Any suggestion ? Cheers


I think the I/O for this class is not yet supported. You should store the data used for making this class


How should I do ?
I tried to generate events from the non parametric pdf, but I had crazy results :

RooRealVar Mnu2(“Mnu2”,“Squared Missing Mass”,-12.5,2.5,“GeV/c^{2}”) ;
RooRealVar dZ(“dZ”,“delta Z”,-0.25,0.25 ) ;

RooNDKeysPdf kest4(“kest4”,“kest4”,RooArgSet(Mnu2,dZ),*data,“am”) ;

RooRealVar M2gen(“M2gen”,“Generated Squared Missing Mass”,-12.5,2.5,“GeV/c^{2}”) ;
RooRealVar dZgen(“dZgen”,“Generated Delta Z”,-0.25,0.25,“cm”) ;
const RooArgSet toy( M2gen, dZgen ) ;
for( int i=0; i<1000 ; i++ )
kest4.generate( toy, 1 ) ;
cout << i << " " << M2gen.getValV() << " " << dZgen.getValV() << endl ;
hToy->Fill( M2gen.getValV(), dZgen.getValV() ) ;

Results are displayed in . In both cases the top plot is the orginal distribution, the central plot is the NP PDF, the last plot is the result of the generation : a FLAT distribution in both projections.
So: what did I do wrong ? Is there any other way to access the value of the NP PDF for a given value of the input variables ?