using namespace RooFit ; void RooFitRotate_testsig() { RooRealVar x("x","x",5.25,5.31) ; RooRealVar y("y","y",-0.3,0.3) ; RooRealVar theta_rot("theta_rot","theta_rot",3.1415926/5); RooFormulaVar x1("x1","x1","cos(theta_rot)*(x-5.28)+sin(theta_rot)*y+5.28",RooArgList(theta_rot,x,y)); RooFormulaVar y1("y1","y1","-sin(theta_rot)*(x-5.28)+cos(theta_rot)*y",RooArgList(theta_rot,x,y)); RooRealVar meanx("mean1","mean of gaussian x1",5.28) ; RooRealVar meany("mean2","mean of gaussian y1",0) ; RooRealVar sigmax("sigmax","width of gaussian x1",0.0025) ; RooRealVar sigmay("sigmay","width of gaussian y1",0.01) ; RooGaussian gaussx("gaussx","gaussian PDF",x1,meanx,sigmax) ; RooGaussian gaussy("gaussy","gaussian PDF",y1,meany,sigmay) ; RooProdPdf sigpdf("sigpdf","gaussx*gaussy",RooArgList(gaussx,gaussy)) ; double toynumsig = 100000; RooDataSet *toysig = sigpdf.generate(RooArgSet(x,y),toynumsig) ; RooFitResult* ToyfitRes = sigpdf.fitTo(*toysig,Extended(),RooFit::Minos(kTRUE),RooFit::Save(kTRUE), PrintLevel(-1)); // Plot x distribution of data and projection of gaussxy on x = Int(dy) gaussxy(x,y) RooPlot* xframe = x.frame(Title("X projection of gauss(x)*gauss(y)")) ; toysig->plotOn(xframe) ; sigpdf.plotOn(xframe, LineColor(kRed), LineWidth(3)) ; // Plot y distribution of data and projection of gaussxy on y = Int(dx) gaussxy(x,y) RooPlot* yframe = y.frame(Title("Y projection of gauss(x)*gauss(y)")) ; toysig->plotOn(yframe) ; sigpdf.plotOn(yframe, LineColor(kRed), LineWidth(3)) ; // Make canvas and draw RooPlots TCanvas *c = new TCanvas("canvas","canvas",1000, 400); c->Divide(2); c->cd(1) ; gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.4) ; xframe->Draw() ; c->cd(2) ; gPad->SetLeftMargin(0.15) ; yframe->GetYaxis()->SetTitleOffset(1.4) ; yframe->Draw() ; c->Print("~/Desktop/testfit.png"); TH2* mc_2d = (TH2*) toysig->createHistogram("x,y",100,100) ; mc_2d->SetMarkerStyle(21); mc_2d->SetMarkerSize(0.5); mc_2d->SetContour(50); TH2* pdf_2d = (TH2*) sigpdf.createHistogram("x,y",200,200) ; pdf_2d->SetMarkerStyle(21); pdf_2d->SetMarkerSize(0.5); pdf_2d->SetContour(50); c->cd(1) ; gPad->SetLeftMargin(0.15) ; mc_2d->Draw("COLZ"); c->cd(2) ; gPad->SetLeftMargin(0.15) ; pdf_2d->Draw("COLZ"); c->Print("~/Desktop/test.png"); }