Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eicsmear_dvmp_plot.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file eicsmear_dvmp_plot.C
1 #include <vector>
3 {
4 
5  /* PRELIMINARY ROOT STUFF */
6 
7 
8  /* Loading libraries and setting sphenix style */
9  gSystem->Load("libeicsmear");
10  gROOT->LoadMacro("/sphenix/user/gregtom3/SBU/research/macros/macros/sPHENIXStyle/sPhenixStyle.C");
12 
13  /* Open TFile */
14  TFile *input = new TFile("/sphenix/user/gregtom3/data/Fall2018/LOI_smear_studies/DVMP.root","READ");
15 
16  /* Open histograms in TFile */
17  TH1F *h1_invariant_mass = (TH1F*)input->Get("h1_invariant_mass");
18  TH1F *h1_invariant_mass_comb = (TH1F*)input->Get("h1_invariant_mass_comb");
19  TH1F *h1_invariant_mass_alone = (TH1F*)input->Get("h1_invariant_mass_alone");
20 
21 
22  TCanvas *c_inv = new TCanvas("c_inv","",700,500);
23  h1_invariant_mass_comb->SetLineColor(kGray);
24  h1_invariant_mass_comb->SetFillColor(kGray);
25  h1_invariant_mass->GetXaxis()->SetTitle("e^{-}e^{+} Invariant Mass [GeV/c^{2}]");
26  h1_invariant_mass->GetYaxis()->SetTitle("Entries");
27 
28  //Scale for Luminosity
29  h1_invariant_mass->Scale(10/1.55);
30  h1_invariant_mass_comb->Scale(10/1.55);
31  h1_invariant_mass_alone->Scale(10/1.55);
32 
33 
34 
35 
36  // Legend text
37  auto legend = new TLegend(0.6,0.65,0.8,0.75);
38  legend->SetTextSize(0.03);
39  legend->AddEntry(h1_invariant_mass,"All e^{+}e^{-} pairs","l");
40  legend->AddEntry(h1_invariant_mass_comb,"Combinatorial background","l");
41 
42  //h1_invariant_mass->Draw();
43  //h1_invariant_mass_comb->Draw("same");
44  //h1_invariant_mass->Draw("same");
45  legend->Draw("same");
46  gPad->SetLogy();
47  gPad->RedrawAxis();
48  c_inv->SaveAs("inv_mass_poly.eps");
49 
50  TCanvas *c_sing = new TCanvas("c_sing","",700,500);
51  double x[100]; double y[100]; double ex[100]; double ey[100];
52  for(int entry = 0; entry<100; entry++)
53  {
54  x[entry] = h1_invariant_mass->GetXaxis()->GetBinCenter(entry);
55  if(entry==0)
56  y[entry]=h1_invariant_mass->GetBinContent(1);
57  else
58  y[entry] = h1_invariant_mass->GetBinContent(entry);
59  ey[entry] = sqrt(h1_invariant_mass->GetBinContent(entry));
60  ex[entry] = 0;
61 
62  }
63 
64  auto gr = new TGraph(100,x,y);
65  auto gr_error = new TGraphErrors(100,x,y,ex,ey);
66  gr_error->SetMarkerSize(1);
67  gr_error->SetMarkerColor(kBlack);
68  gr->SetMarkerSize(.5);
69  gr->SetMarkerColor(kBlue);
70 
71  gr->Draw("AP");
72 
73  gr->GetXaxis()->SetTitle("e^{+}e^{-} Invariant Mass [GeV/c^{2}]");
74  gr->GetYaxis()->SetTitle("Entries");
75  //gr->GetYaxis()->SetTitleOffset(1.6);
76  auto th2 = new TLatex(3.16,38000,"Luminosity 10 fb^{-1}");
77  th2->SetTextSize(0.04);
78  th2->Draw("same");
79  h1_invariant_mass_comb->Draw("same");
80  c_sing->SaveAs("inv_mass_sing.eps");
81 
82  TCanvas *c_nils = new TCanvas("c_nils","",700,500);
83  //gr_error->Draw("ap");
84  h1_invariant_mass_alone->SetMarkerColor(kWhite);
85  h1_invariant_mass_alone->SetLineColor(kWhite);
86  gr_error->GetXaxis()->SetRangeUser(2.95,3.25);
87  gr_error->GetXaxis()->SetTitle("e^{+}e^{-} Invariant Mass [GeV/c^{2}]");
88  gr_error->GetYaxis()->SetTitle("Entries");
89  gr_error->GetYaxis()->SetNdivisions(505);
90  gr_error->Draw("aP");
91  // h1_invariant_mass_alone->GetYaxis()->SetRangeUser(0,50000);
92  /*h1_invariant_mass_alone->Draw();
93  h1_invariant_mass_comb->SetLineWidth(0);
94  h1_invariant_mass_comb->Draw("same");
95  gr->Draw("p");
96  gPad->RedrawAxis();
97  */
98  //h1_invariant_mass_alone->Draw();
99  using namespace RooFit;
100  //double hmin = h1_invariant_mass_alone->GetXaxis()->GetXmin();
101  //double hmax = h1_invariant_mass_alone->GetXaxis()->GetXmax();
102 
103  double hmin = 3.075;
104  double hmax = 3.125;
105  // Declare observable x
106  RooRealVar xx("xx","e^{+}e^{-} Invariant Mass [GeV/c^{2}]",hmin,hmax);
107  RooDataHist dh("dh","Entries",xx,h1_invariant_mass);
108  RooPlot* frame = xx.frame("Z mass");
109  //h1_invariant_mass->Draw();
110  h1_invariant_mass->GetYaxis()->SetNdivisions(505);
111  //frame->Draw("same");
112  //dh.plotOn(frame,MarkerColor(4),MarkerSize(2),MarkerStyle(20)); //this will show histogram data points on canvas
113  //dh.statOn(frame); //this will display hist stat on canvas
114 
115  RooRealVar mean("mean","mean",3.096, 3, 1200.0);
116  RooRealVar width("width","width",0.0926, 0.0900, 0.1);
117  RooRealVar sigma("sigma","sigma",0.02, 0.0, 100.0);
118  RooRealVar alpha("alpha","alpha",0.02, -1000.0, 1000.0);
119  RooRealVar n("n","n",3, -5, 5);
120  RooGaussian gauss("gauss","gauss",xx,mean,sigma);
121  //RooCBShape gauss("gauss","gauss",xx,mean,sigma,alpha,n);
122  //RooBreitWigner gauss("gauss","gauss",xx,mean,sigma);
123  //RooVoigtian gauss("gauss","gauss",xx,mean,width,sigma);
124  //h1_invariant_mass->SetLineColor(kWhite);
125  //h1_invariant_mass->Draw("same");
126  RooFitResult* filters = gauss.fitTo(dh,"qr");
127  //h1_invariant_mass_alone->SetLineColor(kWhite);
128  //h1_invariant_mass_alone->Draw("same");
129  frame->GetYaxis()->SetTitle("Entries");
130  frame->GetYaxis()->SetNdivisions(505);
131 
132 
133  TF1 *gfit = new TF1("Gaussian","gaus",hmin,hmax); // Create the fit function
134  h1_invariant_mass->Fit("Gaussian","RQ0"); //
135  gfit->SetLineColor(kBlue);
136  gfit->Draw("same");
137 
138  //gauss.plotOn(frame,LineColor(4));//this will show fit overlay on canvas
139  //gauss.paramOn(frame); //this will display the fit parameters on canvas
140  dh.plotOn(frame,MarkerColor(4),MarkerSize(1),MarkerStyle(20)); //this will show histogram data points on canvas
141  //frame->Draw();
142  //h1_invariant_mass_comb->Draw("same");
143  frame->Draw("same");
144  auto legend = new TLegend(0.2,0.79,0.4,0.89);
145  legend->SetTextSize(0.04);
146  legend->AddEntry(h1_invariant_mass,"All e^{+}e^{-} pairs","l");
147  legend->AddEntry(gr,"Bin points","p");
148  legend->AddEntry(gfit,"Fitted Gaussian","l");
149  //legend->AddEntry(h1_invariant_mass_comb,"Combinatorial Background","f");
150  //legend->Draw("same");
151  // Luminosity Text
152  auto th1 = new TLatex(3.14,130000,"Luminosity 10 fb^{-1}");
153  th1->SetTextSize(0.04);
154  th1->Draw("same");
155 
156  auto th3 = new TLatex(3.14,150000,"18x275 e+p");
157  th3->SetTextSize(0.04);
158  th3->Draw("same");
159 
160 
161  auto th4 = new TLatex(3.14,140000,"DVMP Sartre");
162  th4->SetTextSize(0.04);
163  th4->Draw("same");
164 
165  auto th5 = new TLatex(3.14,160000,"#bf{#it{sPHENIX}} Simulation");
166  th5->SetTextSize(0.04);
167  th5->Draw("same");
168 
169 
170 
171  c_nils->SaveAs("dvmp_gaussian.eps");
172 
173 
174  return 0;
175 }
176 
177 Double_t mybw(Double_t* x, Double_t* par)
178 {
179  Double_t arg1 = 14.0/22.0; // 2 over pi
180  Double_t arg2 = par[1]*par[1]*par[2]*par[2]; //Gamma=par[1] M=par[2]
181  Double_t arg3 = ((x[0]*x[0]) - (par[2]*par[2]))*((x[0]*x[0]) - (par[2]*par[2]));
182  Double_t arg4 = x[0]*x[0]*x[0]*x[0]*((par[1]*par[1])/(par[2]*par[2]));
183  return par[0]*arg1*arg2/(arg3 + arg4);
184 }