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 int HAll = All + 4;
220 
221 for(int j = 0; j < HAll; j++)
222 {
223 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
224 
225 c22->cd();
226 
227  TFile *fin = new TFile("Interpolated2.root");
228  y = yinitial - inteval * j;
229 
230 
231 //cout << "x = " << x << endl;
232 //cout << "j = " << j << endl;
233 
234 Center = Inter->GetXaxis()->FindBin(x);
235 
236 
237 
238 //double x[NBins];
239 //int xbin[NBins];
240 
241 //cout << "OK 0" << endl;
242 
243  ylow = y - bins * step;
244  yhigh = y + bins * step;
245 
246 ybinlow = Inter->GetYaxis()->FindBin(ylow);
247 
248  ybinhigh = Inter->GetYaxis()->FindBin(yhigh);
249 
250 
251 
252  YBins = (Ymax - Ymin)/step;
253 
254 cout << "ybinlow = " <<ybinlow << endl;
255 cout << "ybinhigh = " << ybinhigh << endl;
256 
257 
258 TH1D *h1 = new TH1D("h1","",YBins,Ymin,Ymax);
259 
260 
261 Inter->ProjectionX("h1",ybinlow,ybinhigh);
262 
263 //cout << "mean = " << Inter->GetMean() << endl;
264 
265 
266 
267 //h1->Draw();
268 
269 
270  Ybinmin = h1->GetXaxis()->FindBin(Ymin);
271 
272 
273  Ybinmax = h1->GetXaxis()->FindBin(Ymax);
274 cout << " OK 1" << endl;
275 
276  N = (Ybinmax - Ybinmin)/NBins;
277 /*
278 for(int i = 0; i < N; i++)
279 {
280 
281  y = Ymin + (i+0.5) * NBins;
282 
283 cout << "y = " << y << endl;
284 ylow = Ymin + i * NBins;
285 
286 yhigh = Ymin + (i+1)*NBins;
287 
288 ybinlow = h1->GetXaxis()->FindBin(ylow);
289 ybinhigh = h1->GetXaxis()->FindBin(yhigh);
290 
291 ycent = h2->GetXaxis()->FindBin(y);
292 
293 
294 mean = h1->Integral(ybinlow,ybinhigh)/NBins/(ybinhigh - ybinlow);
295 
296 cout << "Difference = " << ybinhigh - ybinlow << endl;
297 cout << "y Bin = " << ycent << endl;
298 cout << "Average is = " << mean << endl;
299 
300 h2->SetBinContent(ycent,mean);
301 
302 }
303 */
304 
305 
306 h1->Scale(0.1);
307 //h1->Draw();
308 //h2 = h1;
309 //h2->Draw();
310 
311 sprintf(HistoName,"Result%d.root",j);
312 
313  TFile *fout = new TFile(HistoName,"RECREATE");
314  h1->GetXaxis()->SetTitle("x (mm)");
315  h1->GetYaxis()->SetTitle("Average Energy (GeV)");
316 int k = 7- (j+1)/2;
317 int l = 6- (j+1)/2;
318 int m = 7 - (j+2)/2;
319 
320 
321 if(j == 1 || j == 3 || j == 5 || j == 7 || j == 9) sprintf(Title,"10 X Bin Average Energy vs Horizontal Position Tower Between %d and %d",k,l);
322 
323 if(j == 0 || j == 2 || j == 4 || j == 6 || j == 8 || j == 10 ) sprintf(Title,"10 X Bin Average Energy vs Horizontal Position Tower %d",m);
324 
325  h1->SetTitle(Title);
326 
327  h1->Write();
328 
329 
330 
331 //return;
332 
333 h1->Draw("same");
334 
335 sprintf(outname,"Result/Energy vs 10-Bin Average X %d.png",j);
336 
337 
338 
339 c22->Update();
340 
341 c22->SaveAs(outname);
342 
343 cout << " OK 2" << endl;
344 }
345 
346 
347 
348 }