Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataAna.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DataAna.C
1 #include <cmath>
2 #include <TFile.h>
3 #include <TString.h>
4 #include <TLine.h>
5 #include <TTree.h>
6 #include <TLatex.h>
7 #include <TGraphErrors.h>
8 #include <cassert>
9 #include <iostream>
10 #include <fstream>
11 #include "TROOT.h"
12 #include "TH1.h"
13 #include "TTree.h"
14 using namespace std;
15 
16 
17 
18 using std::cout;
19 using std::endl;
20 #endif
21 
22 
23 
24 void DataAna(){
25  gStyle->SetOptFit(0);
26  gStyle->SetOptStat(0);
27 
28 TFile *fin = new TFile("Interpolated2.root");
29 
30 const int NBins = 10;
31 int bins = 5;
32 double step = 1;
33 
34 const int All = 7;
35 double inteval = 12.5;
36 double xinitial = -188;
37 //double x[All];
38 double yinitial = -77;
39 double x;
40 char HistoName[512];
41 //Set Tower Vertical Lines//
42 
43 double x1 = 205;
44 double x2 = 228;
45 double x3 = 253;
46 double x4 = 277;
47 double x5 = 301;
48 char outname[512];
49 /*
50 for(int i = 0; i < All; i ++)
51 {
52 
53 
54 
55 
56 
57 }
58 
59 */
60 
61 double Xmin = -340;
62 double Xmax = -170;
63 
64 double Ymax = -60;
65 double Ymin = -245.0;
66 
67 int binlow;
68 
69 int binhigh;
70 
71 double Center;
72 
73 double xlow;
74 double xhigh;
75 
76 double ylow;
77 double yhigh;
78 int ybinlow;
79 int ybinhigh;
80 double y;
81 
82 int ycent;
83 
84 double mean;
85 
86 int YBins;
87 
88 int N;
89 
90 int Ybinmax;
91 
92 int Ybinmin;
93 
94 char Title[512];
95 
96 for(int j = 0; j < All; j++)
97 {
98 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
99 
100 c22->cd();
101 
102  TFile *fin = new TFile("Interpolated2.root");
103  x = xinitial - inteval * j;
104 
105 
106 //cout << "x = " << x << endl;
107 //cout << "j = " << j << endl;
108 
109 Center = Inter->GetXaxis()->FindBin(x);
110 
111 
112 
113 //double x[NBins];
114 //int xbin[NBins];
115 
116 cout << "OK 0" << endl;
117 
118  xlow = x - bins * step;
119  xhigh = x + bins * step;
120 
121  binlow = Inter->GetXaxis()->FindBin(xlow);
122 
123  binhigh = Inter->GetXaxis()->FindBin(xhigh);
124 
125  YBins = (Ymax - Ymin)/step;
126 
127 cout << "binlow = " << binlow << endl;
128 cout << "binhigh = " << binhigh << endl;
129 
130 
131 TH1D *h1 = new TH1D("h1","",YBins,Ymin,Ymax);
132 
133 
134 Inter->ProjectionY("h1",binlow,binhigh);
135 
136 //cout << "mean = " << Inter->GetMean() << endl;
137 
138 
139 
140 //h1->Draw();
141 
142 
143  Ybinmin = h1->GetXaxis()->FindBin(Ymin);
144 
145 
146  Ybinmax = h1->GetXaxis()->FindBin(Ymax);
147 cout << " OK 1" << endl;
148 
149  N = (Ybinmax - Ybinmin)/NBins;
150 /*
151 for(int i = 0; i < N; i++)
152 {
153 
154  y = Ymin + (i+0.5) * NBins;
155 
156 cout << "y = " << y << endl;
157 ylow = Ymin + i * NBins;
158 
159 yhigh = Ymin + (i+1)*NBins;
160 
161 ybinlow = h1->GetXaxis()->FindBin(ylow);
162 ybinhigh = h1->GetXaxis()->FindBin(yhigh);
163 
164 ycent = h2->GetXaxis()->FindBin(y);
165 
166 
167 mean = h1->Integral(ybinlow,ybinhigh)/NBins/(ybinhigh - ybinlow);
168 
169 cout << "Difference = " << ybinhigh - ybinlow << endl;
170 cout << "y Bin = " << ycent << endl;
171 cout << "Average is = " << mean << endl;
172 
173 h2->SetBinContent(ycent,mean);
174 
175 }
176 */
177 
178 
179 h1->Scale(0.1);
180 //h1->Draw();
181 //h2 = h1;
182 //h2->Draw();
183 
184 sprintf(HistoName,"Result%d.root",j);
185 
186  TFile *fout = new TFile(HistoName,"RECREATE");
187  h1->GetXaxis()->SetTitle("y (mm)");
188  h1->GetYaxis()->SetTitle("Average Energy (GeV)");
189 int k = 7- (j+1)/2;
190 int l = 6- (j+1)/2;
191 int m = 7 - (j+2)/2;
192 
193 
194 if(j == 1 || j == 3 || j == 5) sprintf(Title,"10 X Bin Average Energy vs Vertical Position Tower Between %d and %d",k,l);
195 
196 if(j == 0 || j == 2 || j == 4 || j == 6 ) sprintf(Title,"10 X Bin Average Energy vs Vertical Position Tower %d",m);
197 
198  h1->SetTitle(Title);
199 
200  h1->Write();
201 
202 
203 
204 //return;
205 
206 h1->Draw("same");
207 
208 sprintf(outname,"Result/Energy vs 10-Bin Average Y %d.png",j);
209 
210 
211 
212 c22->Update();
213 
214 c22->SaveAs(outname);
215 
216 //cout << " OK 2" << endl;
217 }
218 
219 for(int j = 0; j < All; j++)
220 {
221 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
222 
223 c22->cd();
224 
225  TFile *fin = new TFile("Interpolated2.root");
226  y = yinitial - inteval * j;
227 
228 
229 //cout << "x = " << x << endl;
230 //cout << "j = " << j << endl;
231 
232 Center = Inter->GetXaxis()->FindBin(x);
233 
234 
235 
236 //double x[NBins];
237 //int xbin[NBins];
238 
239 //cout << "OK 0" << endl;
240 
241  ylow = y - bins * step;
242  yhigh = y + bins * step;
243 
244 ybinlow = Inter->GetYaxis()->FindBin(ylow);
245 
246  ybinhigh = Inter->GetYaxis()->FindBin(yhigh);
247 
248 
249 
250  YBins = (Ymax - Ymin)/step;
251 
252 cout << "ybinlow = " <<ybinlow << endl;
253 cout << "ybinhigh = " << ybinhigh << endl;
254 
255 
256 TH1D *h1 = new TH1D("h1","",YBins,Ymin,Ymax);
257 
258 
259 Inter->ProjectionX("h1",ybinlow,ybinhigh);
260 
261 //cout << "mean = " << Inter->GetMean() << endl;
262 
263 
264 
265 //h1->Draw();
266 
267 
268  Ybinmin = h1->GetXaxis()->FindBin(Ymin);
269 
270 
271  Ybinmax = h1->GetXaxis()->FindBin(Ymax);
272 cout << " OK 1" << endl;
273 
274  N = (Ybinmax - Ybinmin)/NBins;
275 /*
276 for(int i = 0; i < N; i++)
277 {
278 
279  y = Ymin + (i+0.5) * NBins;
280 
281 cout << "y = " << y << endl;
282 ylow = Ymin + i * NBins;
283 
284 yhigh = Ymin + (i+1)*NBins;
285 
286 ybinlow = h1->GetXaxis()->FindBin(ylow);
287 ybinhigh = h1->GetXaxis()->FindBin(yhigh);
288 
289 ycent = h2->GetXaxis()->FindBin(y);
290 
291 
292 mean = h1->Integral(ybinlow,ybinhigh)/NBins/(ybinhigh - ybinlow);
293 
294 cout << "Difference = " << ybinhigh - ybinlow << endl;
295 cout << "y Bin = " << ycent << endl;
296 cout << "Average is = " << mean << endl;
297 
298 h2->SetBinContent(ycent,mean);
299 
300 }
301 */
302 
303 
304 h1->Scale(0.1);
305 //h1->Draw();
306 //h2 = h1;
307 //h2->Draw();
308 
309 sprintf(HistoName,"Result%d.root",j);
310 
311  TFile *fout = new TFile(HistoName,"RECREATE");
312  h1->GetXaxis()->SetTitle("x (mm)");
313  h1->GetYaxis()->SetTitle("Average Energy (GeV)");
314 int k = 7- (j+1)/2;
315 int l = 6- (j+1)/2;
316 int m = 7 - (j+2)/2;
317 
318 
319 if(j == 1 || j == 3 || j == 5) sprintf(Title,"10 X Bin Average Energy vs Horizontal Position Tower Between %d and %d",k,l);
320 
321 if(j == 0 || j == 2 || j == 4 || j == 6 ) sprintf(Title,"10 X Bin Average Energy vs Horizontal Position Tower %d",m);
322 
323  h1->SetTitle(Title);
324 
325  h1->Write();
326 
327 
328 
329 //return;
330 
331 h1->Draw("same");
332 
333 sprintf(outname,"Result/Energy vs 10-Bin Average X %d.png",j);
334 
335 
336 
337 c22->Update();
338 
339 c22->SaveAs(outname);
340 
341 cout << " OK 2" << endl;
342 }
343 
344 
345 
346 }