void Test_RooNDKeysPdf() { // Simple macro to test the writeability of RooNDKeysPdf using namespace RooFit ; // Define two variables RooRealVar x("x","x",0,20) ; RooRealVar y("y","y",0,20) ; // Define two model for 1D RooPolynomial px("px","px",x,RooArgList(RooConst(0.03),RooConst(-0.01),RooConst(0.00032))) ; RooPolynomial py("py","py",y,RooArgList(RooConst(0.01),RooConst(0.01),RooConst(-0.0004))) ; // Combine them into a 2D model RooProdPdf pxy("pxy","pxy",RooArgSet(px,py)) ; // Create a dataset from this model RooDataSet* data = pxy.generate(RooArgSet(x,y),1000) ; // Create a histogram of the data TH1* hh_data = data->createHistogram("hh_data",x,Binning(10),YVar(y,Binning(10))) ; // Create 2D adaptive kernel estimation pdf with mirroring RooNDKeysPdf kest("kest","kest",RooArgSet(x,y),*data,"am") ; // Create histogram of the 2d kernel estimation pdfs TH1* hh_pdf = kest.createHistogram("hh_pdf",x,Binning(50),YVar(y,Binning(50))) ; hh_pdf->SetLineColor(kBlue) ; TCanvas* c = new TCanvas("Test_RooNDKeysPdf","Test_RooNDKeysPdf",800,800) ; gPad->SetLeftMargin(0.15) ; hh_data->GetZaxis()->SetTitleOffset(1.2) ; hh_data->Draw("lego") ; hh_pdf->Draw("surfsame") ; c->Draw(); // So far, so good // This won't work TFile* fout= TFile::Open("fout.root","RECREATE"); kest.Write(); fout->Close(); // This won't work either // Create a new empty workspace RooWorkspace *w = new RooWorkspace("w","workspace") ; // Import model and all its components into the workspace w->import(pxy) ; // Import data into the workspace w->import(*data) ; // Import RooNDKeysPdf //w->import(kest); // Print workspace contents w->Print() ; // S a v e w o r k s p a c e i n f i l e // ------------------------------------------- // Save the workspace into a ROOT file w->writeToFile("rf502_workspace.root") ; // Workspace will remain in memory after macro finishes gDirectory->Add(w) ; }