Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plot_g1_projection.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file plot_g1_projection.C
1 #include "calculate_g1.C"
2 
3 int
4 plot_g1_projection(TString fin_name)
5 {
6  TFile *fin = new TFile(fin_name,"OPEN");
7 
8  TH2F *hxQ2 = (TH2F*)fin->Get("hxQ2");
9  TTree *tin = (TTree*)fin->Get("tcount");
10 
11  /* beam energies */
12  float ebeam_e = 18;
13  float ebeam_p = 275;
14 
15  /* Retrieve Pythia generated events luminosity information */
16  TObjString* gen_lumi_ifb_s = (TObjString*)fin->Get("luminosity");
17  float gen_lumi_ifb = (TString((gen_lumi_ifb_s)->GetName())).Atof();
18 
19  cout << "Pythia luminosity: " << gen_lumi_ifb << " fb^-1" << endl;
20 
21  /* collect all x-bins */
22  //set<float> s_binc_x;
23 
24  /* Prepare TPaveText for plots */
25  TString str_ebeam = TString::Format("%.0f GeV x %.0f GeV", ebeam_e, ebeam_p );
26  TString str_lumin = TString::Format("L = %.4f fb^{-1}", gen_lumi_ifb );
27 
28  TPaveText *pt_ebeam_lumi_ul = new TPaveText(1e-5,1e3,1e-3,1e4,"none");
29  pt_ebeam_lumi_ul->SetFillStyle(0);
30  pt_ebeam_lumi_ul->SetLineColor(0);
31  pt_ebeam_lumi_ul->AddText(str_ebeam);
32  pt_ebeam_lumi_ul->AddText(str_lumin);
33 
34  TPaveText *pt_ebeam_lumi_ll = new TPaveText(1e2,45,1e3,50,"none");
35  pt_ebeam_lumi_ll->SetFillStyle(0);
36  pt_ebeam_lumi_ll->SetLineColor(0);
37  pt_ebeam_lumi_ll->AddText(str_ebeam);
38  pt_ebeam_lumi_ll->AddText(str_lumin);
39 
40  /* Prepare inelasticity (y) cut lines for plots */
41  TF1 *f_y095 = new TF1("f_y095", "4*x*[0]*[1]*[2]", 1e-5, 1);
42  f_y095->SetParameter( 0, ebeam_e);
43  f_y095->SetParameter( 1, ebeam_p);
44  f_y095->SetParameter( 2, 0.95);
45  TF1 *f_y001 = (TF1*)f_y095->Clone("f_y01");
46  f_y001->SetParameter(2 , 0.01);
47 
48  /* make x-Q2 plot */
49  TCanvas *c1 = new TCanvas();
50  c1->SetRightMargin(0.12);
51  hxQ2->Draw("colz");
52  c1->SetLogx(1);
53  c1->SetLogy(1);
54  c1->SetLogz(1);
55 
56  f_y095->Draw("same");
57  f_y001->Draw("same");
58 
59  TPaveText *pt_N = new TPaveText(1e-5,1e2,1e-3,3e2,"none");
60  pt_N->SetFillStyle(0);
61  pt_N->SetLineColor(0);
62  pt_N->AddText("z = # events");
63 
64  pt_N->Draw();
65  pt_ebeam_lumi_ul->Draw();
66  gPad->RedrawAxis();
67 
68 
69  /* plot g1 statistical uncertainty for different x-Q2 bins */
70  TH2F* hxQ2_g1_sigma = hxQ2->Clone("x_Q2_g1_sigma");
71  hxQ2_g1_sigma->GetZaxis()->SetNdivisions(505);
72  hxQ2_g1_sigma->Reset();
73 
74  hxQ2_g1_sigma->GetXaxis()->SetTitle("x");
75  hxQ2_g1_sigma->GetYaxis()->SetTitle("Q^{2} (GeV^{2})");
76 
77  /* Filling happens in the step below- draw afterwards */
78 
79  // tcount->Draw("Q2:x >> x_Q2_g1_sigma","stdev_g1 * (N > 0 && x >= 5e-5 && stdev_g1<1)");
80 
81  /* normalize to number of entries in each bin */
82  // hxQ2_g1_sigma->Divide(hxQ2);
83 
84 
85  /* plot g1 vs Q2 for various x */
86  TCanvas *c2 = new TCanvas("g1","",700,800);
87  c2->SetLogx();
88 
89  TH1F* hframe_g1 = (TH1F*)hxQ2->ProjectionY()->Clone("h1_g1");
90  hframe_g1->Reset();
91  hframe_g1->GetXaxis()->CenterTitle();
92  hframe_g1->GetYaxis()->CenterTitle();
93  hframe_g1->GetXaxis()->SetTitle("Q^{2} (GeV^{2})");
94  //hframe_g1->GetYaxis()->SetTitle("g_{1}(x,Q^{2}) + const(x)");
95  hframe_g1->GetYaxis()->SetTitle("const(x)");
96  hframe_g1->GetXaxis()->SetRangeUser(0.99,1500);
97  hframe_g1->GetYaxis()->SetRangeUser(2,50);
98  hframe_g1->GetYaxis()->SetNdivisions(505);
99 
100  hframe_g1->Draw("");
101 
102  /* collect all x-bins */
103  set<float> s_binc_x;
104  for ( int bin_x = 1; bin_x <= hxQ2->GetNbinsX(); bin_x++ )
105  {
106  t_x = TMath::Power(10, 0.5 * ( ( TMath::Log10( hxQ2->GetXaxis()->GetBinLowEdge(bin_x) ) )
107  + ( TMath::Log10( hxQ2->GetXaxis()->GetBinLowEdge(bin_x) + hxQ2->GetXaxis()->GetBinWidth(bin_x) ) ) ) );
108  s_binc_x.insert(t_x);
109  }
110 
111  /* Prepare legend to record offsets */
112  TPaveText *leg_offset_x = new TPaveText(0,0,1,1,"none");
113  leg_offset_x->SetFillStyle(0);
114  leg_offset_x->SetLineColor(0);
115  // leg_offset_x->SetMargin(0);
116  leg_offset_x->SetTextSize(0.1);
117 
118 
119 
120  /* draw graphs */
121  TCanvas *ctmp = new TCanvas();
122  float offset = 48;
123 
124  cout << "+++++++++++++++++++++++++++++++++++++++++++" << endl;
125  cout << "Plot offsets: " << endl;
126 
127  for ( set<float>::iterator itx = s_binc_x.begin();
128  itx != s_binc_x.end(); itx++ )
129  {
130  /* Skip x < 5e-5 */
131  if ( *itx < 5e-5 )
132  continue;
133 
134  /* print values */
135  cout << "offset = " << (int)offset << " for x = " << *itx << endl;
136 
137  /* Add to legend */
138  TString str_offset = TString::Format("const(x = %.2g) = %d", *itx, (int)offset );
139  leg_offset_x->AddText(str_offset);
140 
141  /* Create graph */
142  ctmp->cd();
143 
144  unsigned npoints = tcount->GetEntries( TString::Format("x > 0.99*%f && x < 1.01*%f", *itx, *itx ) );
145  tcount->Draw( TString::Format("%f:Q2:stdev_g1", offset),
146  TString::Format("x > 0.99*%f && x < 1.01*%f", *itx, *itx ) );
147 
148  TGraphErrors* gnew = new TGraphErrors( npoints, tcount->GetV2(), tcount->GetV1(), 0, tcount->GetV3() );
149  gnew->SetMarkerColor(kRed);
150 
151  c2->cd();
152  gnew->Draw("PLsame");
153 
154  offset -= 2;
155 
156  /* Fill TH2 histogram */
157  double x_j = 0;
158  double Q2_j = 0;
159  double g1sig_j = 0;
160  double dummy_j = 0;
161  for ( unsigned j = 0; j < gnew->GetN(); j++ )
162  {
163  gnew->GetPoint(j, Q2_j, dummy_j);
164  g1sig_j = gnew->GetErrorY(j);
165  x_j = *itx;
166  hxQ2_g1_sigma->Fill(x_j, Q2_j, g1sig_j);
167  }
168  }
169 
170  pt_ebeam_lumi_ll->Draw();
171  gPad->RedrawAxis();
172 
173  c2->Print("plots/g1_projection_eic_sphenix.eps");
174 
175  TCanvas *c2_legend = new TCanvas("g1_legend","",200,800);
176  leg_offset_x->Draw();
177  c2_legend->Print("plots/g1_projection_eic_sphenix_legend.eps");
178 
179  delete ctmp;
180 
181 
182  /* Draw TH2 with g1 uncertainty defined above */
183  TCanvas *c5 = new TCanvas();
184  c5->SetRightMargin(0.12);
185 
186  hxQ2_g1_sigma->Draw("colz");
187  hxQ2_g1_sigma->GetZaxis()->SetRangeUser(1e-3,2e1);
188  c5->SetLogx(1);
189  c5->SetLogy(1);
190  c5->SetLogz(1);
191 
192  f_y095->Draw("same");
193  f_y001->Draw("same");
194 
195  TPaveText *pt_g1_stdev = new TPaveText(1e-5,1e2,1e-3,3e2,"none");
196  pt_g1_stdev->SetFillStyle(0);
197  pt_g1_stdev->SetLineColor(0);
198  pt_g1_stdev->AddText("z = #sigma_{g_{1}}");
199 
200  pt_g1_stdev->Draw();
201  pt_ebeam_lumi_ul->Draw();
202  gPad->RedrawAxis();
203 
204  c5->Print("plots/g1_projection_eic_sphenix_2D.eps");
205 
206  return 0;
207 }