void extraConstantParamsSpeedTest() { int nToys = 1000; RooWorkspace* wksp = new RooWorkspace("wksp"); //Create a bkg + mu*sig model with zero signal component wksp->factory("SUM::bkgPlusSigModel(Exponential::bkgModel(x[-1,1],k[-15,-100,0]), mu[0]*BreitWigner::sigModel(x,m[0.5],w[0.01]))"); //These will store the time distributions TH1D* hist1 = new TH1D("hist1","hist1",nToys,0.,0.02); TH1D* hist2 = new TH1D("hist2","hist2",nToys,0.,0.02); TStopwatch watch; for(int i=0; ipdf("bkgPlusSigModel")->generateBinned(*((RooRealVar*)wksp->var("x")),1000.); //Time how long it takes to fit the data with bkgModel alone watch.Start(); wksp->pdf("bkgModel")->fitTo(*toyData); watch.Stop(); hist1->Fill(watch.RealTime()); watch.Reset(); //Time how long it takes to fit the data with bkgPlusSigModel with sigN set constant at zero watch.Start(); wksp->pdf("bkgPlusSigModel")->fitTo(*toyData); watch.Stop(); hist2->Fill(watch.RealTime()); watch.Reset(); delete(toyData); } //Plot the histograms TCanvas* histCan = new TCanvas("histCan","histCan",800,600); hist1->Draw(); hist2->SetLineColor(kRed); hist2->Draw("same"); //Save the results TFile* histFile = new TFile("histFile.root","recreate"); hist1->Write(); hist2->Write(); histCan->Write(); histFile->Close(); //Summary cout << "\n\n\nIt takes " << hist1->GetMean() << "s on average to fit using bkgModel alone" << endl; cout << "It takes " << hist2->GetMean() << "s on average to fit using bkgPlusSigModel" << endl; }