Plotting the background and signal

[code]#include “TDirectory.h”
#include “TCanvas.h”
#include “TEventList.h”
#include “TFile.h”

#include “TMath.h”
#include “TString.h”
#include “TTree.h”

#include “RooFit.h”
#include “TRandom.h”
#include “RooAbsPdf.h”
#include “RooAbsReal.h”
#include “RooAddPdf.h”
#include “RooArgList.h”
#include “RooArgSet.h”

#include “RooDataSet.h”
#include “RooFitResult.h”
#include “RooGaussian.h”
#include “RooGaussModel.h”
#include “RooKeysPdf.h”
#include “RooPlot.h”
#include “RooPolynomial.h”
#include “RooProdPdf.h”
#include “RooProduct.h”

#ifndef CINT
#include “RooGlobalFunc.h”
#endif
#include “RooRealVar.h”
#include “RooDataSet.h”
#include “RooGaussian.h”
#include “RooConstVar.h”
#include “RooAddPdf.h”
#include “RooChebychev.h”
#include “RooFitResult.h”
#include “TCanvas.h”
#include “TAxis.h”
#include “RooPlot.h”
#include “TFile.h”
#include “TStyle.h”
#include “TH2.h”
#include “TMatrixDSym.h”
#include “RooFormulaVar.h”

using namespace RooFit;

int Higgs_Pt() {

const int binning=100;

//Declare variables
RooRealVar Higgs_Pt(“Higgs_Pt”, “Higgs Transverse Momentum”, 100000, 200000, “GeV”);//Higgs Transverse momentum cut to a certain range
RooRealVar DiLept_M(“DiLept_M”, “JPsi Mass”, 2000, 4500,“GeV”);//JPsi masses cut to a certain range
RooRealVar mean(“mean”, “mean”, 35000,0,300000); //Common mean with an initital, lower and upper value
RooRealVar sigma(“sigma”,“width of Gaussian”, 80000,0,100000);//Width of the narrow gaussian with an initial, lower and upper value.
RooFormulaVar sigma2(“sigma2”, “width of 2nd Gaussian”, “2sigma", sigma); //Width of the wide guassian (2nd narrow one)- Have to use RooFormulaVar as the second gaussian is formed via an equation involving the first gaussian //The formula is written in “” marks, hence "2sigma”.

//Get file from nTuple
TFile *file=new TFile("/home/atlas/amytee/Adam/Data.Merge.root",“Data.Merge.root”, “READ”);

TTree tree=(TTree)file->Get(“newTree”);

RooDataSet data(“Pt”,“Transverse Momentum of Higgs and Dilepton Masses”, RooArgSet(Higgs_Pt,DiLept_M),Import(*tree));
data.Print();

//Build Gaussian PDF in terms of DiLept_M, mean and sigma
RooGaussian gauss1(“Gauss1”, “Gauss 1 PDF”, DiLept_M, mean, sigma);
RooGaussian gauss2(“Gauss2”, “Gauss 2 PDF”, DiLept_M, mean, sigma2);

//Background Model - This is the red line
RooRealVar c(“c”, “slope”, 0,-10,10);
RooRealVar c2(“c2”,“slope”,0 ,-10,10);
RooPolynomial Pol(“Pol”, “Quadratic distribution”, DiLept_M, RooArgSet(c,c2));

//Sum the Gauss components into a composite Gaussian PDF
RooRealVar GaussFrac(“GaussFrac”, “Fraction of both Gaussians”, 0.2,0,1.0);
RooAddPdf GaussAdd(“GaussAdd”, “Double Gaussian”, RooArgList(gauss1,gauss2),RooArgList(GaussFrac));

//Sum the composite Gaussian and Background
RooRealVar bkgfrac(“bkgfrac”, “Fraction of background”,0.5,0,1.0);
RooAddPdf model(“model”,“Gaussian + background”, RooArgList(Pol,GaussAdd),bkgfrac);

//Perform fit and save result
RooFitResult* fitresult=model.fitTo(data,Save());
TCanvas* canvas=new TCanvas(“c”,“c”, 700,500);
RooPlot* frame=DiLept_M.frame();
frame->SetTitle(“JPsi Mass”);
data.plotOn(frame,Binning(binning));
model.plotOn(frame, Components(“Pol”),LineColor(kRed));
model.plotOn(frame,Components(“GaussAdd”),LineColor(kGreen));
model.plotOn(frame,Components(“model”),LineColor(kYellow));

frame->Draw();
canvas->SaveAs(“JPsi_Mass_AllFits.png”);
canvas->SaveAs(“JPsi_Mass_AllFits.eps”);
file->Close();
return 0;
}
[/code]

I am trying to plot the background, a double gaussian and the gaussian + background. I cannot seem to get it to print the three lines, and of the double gaussian and the gaussian + background that do print, they are coming out as straight lines. I am unsure as to where in my code I have gone wrong. I’m new here so I have probably formatted wrong.

To run this macro the root file is missing.

The root file is too large for me to add.