RooDataSet* GetData(RooRealVar &x) { TFile *rootFile = new TFile("test.root","READ"); TTree *tree = (TTree*)rootFile->Get("tree"); RooDataSet *data = new RooDataSet("data","data",tree,RooArgSet(x)); delete rootFile; rootFile = 0; return data; } void DeleteData(RooDataSet *data) { delete data; data = 0; } RooAbsPdf* GetPdf(RooRealVar &x) { RooRealVar a("a","a",450.,250.,650.); RooRealVar b("b","b",125.,50.,200.); RooAbsPdf *pdf = new RooGaussian("pdf","pdf",x,a,b); return pdf; } void DeletePdf(RooAbsPdf *pdf) { delete pdf; pdf = 0; } void test() { RooRealVar x("numDegDaysBranch","numDegDaysBranch",190.,785.); RooAbsPdf *pdf = GetPdf(x); ////////// If I move the following block of code into GetPdf(), above, it works ////////// RooDataSet *data = GetData(x); pdf->fitTo(*data); // Crashes at this line, when in test() RooPlot *xframe = x.frame(); data->plotOn(xframe); pdf->plotOn(xframe); xframe->Draw(); ////////////////////////////////////////////////////////////////////////////////////////// DeletePdf(pdf); DeleteData(data); }