Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataAna2.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DataAna2.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 DataAna2(){
25  gStyle->SetOptFit(0);
26  gStyle->SetOptStat(0);
27 
28 TFile *fin = new TFile("Interpolated.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 = -300;
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 if(0){
97 
98 for(int j = 0; j < All; j++)
99 {
100 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
101 
102 c22->cd();
103 
104  TFile *fin = new TFile("Interpolated2.root");
105  x = xinitial - inteval * j;
106 
107 
108 //cout << "x = " << x << endl;
109 //cout << "j = " << j << endl;
110 
111 Center = Inter->GetXaxis()->FindBin(x);
112 
113 
114 
115 //double x[NBins];
116 //int xbin[NBins];
117 
118 cout << "OK 0" << endl;
119 
120  xlow = x - bins * step;
121  xhigh = x + bins * step;
122 
123  binlow = Inter->GetXaxis()->FindBin(xlow);
124 
125  binhigh = Inter->GetXaxis()->FindBin(xhigh);
126 
127  YBins = (Ymax - Ymin)/step;
128 
129 cout << "binlow = " << binlow << endl;
130 cout << "binhigh = " << binhigh << endl;
131 
132 
133 TH1D *h1 = new TH1D("h1","",YBins,Ymin,Ymax);
134 
135 
136 Inter->ProjectionY("h1",binlow,binhigh);
137 
138 //cout << "mean = " << Inter->GetMean() << endl;
139 
140 
141 
142 //h1->Draw();
143 
144 
145  Ybinmin = h1->GetXaxis()->FindBin(Ymin);
146 
147 
148  Ybinmax = h1->GetXaxis()->FindBin(Ymax);
149 cout << " OK 1" << endl;
150 
151  N = (Ybinmax - Ybinmin)/NBins;
152 /*
153 for(int i = 0; i < N; i++)
154 {
155 
156  y = Ymin + (i+0.5) * NBins;
157 
158 cout << "y = " << y << endl;
159 ylow = Ymin + i * NBins;
160 
161 yhigh = Ymin + (i+1)*NBins;
162 
163 ybinlow = h1->GetXaxis()->FindBin(ylow);
164 ybinhigh = h1->GetXaxis()->FindBin(yhigh);
165 
166 ycent = h2->GetXaxis()->FindBin(y);
167 
168 
169 mean = h1->Integral(ybinlow,ybinhigh)/NBins/(ybinhigh - ybinlow);
170 
171 cout << "Difference = " << ybinhigh - ybinlow << endl;
172 cout << "y Bin = " << ycent << endl;
173 cout << "Average is = " << mean << endl;
174 
175 h2->SetBinContent(ycent,mean);
176 
177 }
178 */
179 
180 
181 h1->Scale(0.1);
182 //h1->Draw();
183 //h2 = h1;
184 //h2->Draw();
185 
186 sprintf(HistoName,"Result%d.root",j);
187 
188  TFile *fout = new TFile(HistoName,"RECREATE");
189  h1->GetXaxis()->SetTitle("y (mm)");
190  h1->GetYaxis()->SetTitle("Average Energy (GeV)");
191 int k = 7- (j+1)/2;
192 int l = 6- (j+1)/2;
193 int m = 7 - (j+2)/2;
194 
195 
196 if(j == 1 || j == 3 || j == 5) sprintf(Title,"10 X Bin Average Energy vs Vertical Position Tower Between %d and %d",k,l);
197 
198 if(j == 0 || j == 2 || j == 4 || j == 6 ) sprintf(Title,"10 X Bin Average Energy vs Vertical Position Tower %d",m);
199 
200  h1->SetTitle(Title);
201 
202  h1->Write();
203 
204 
205 
206 //return;
207 
208 h1->Draw("same");
209 
210 sprintf(outname,"Result/Energy vs 10-Bin Average Y %d.png",j);
211 
212 
213 
214 c22->Update();
215 
216 c22->SaveAs(outname);
217 
218 //cout << " OK 2" << endl;
219 }
220 
221 }
222 int HAll = All + 4;
223 
224 for(int j = 0; j < HAll; j++)
225 {
226 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
227 
228 c22->cd();
229 
230  TFile *fin = new TFile("Interpolated2.root");
231  y = yinitial - inteval * j;
232 
233 
234 //cout << "x = " << x << endl;
235 //cout << "j = " << j << endl;
236 
237 Center = Inter->GetXaxis()->FindBin(x);
238 
239 
240 
241 //double x[NBins];
242 //int xbin[NBins];
243 
244 //cout << "OK 0" << endl;
245 
246  ylow = y - bins * step;
247  yhigh = y + bins * step;
248 
249 ybinlow = Inter->GetYaxis()->FindBin(ylow);
250 
251  ybinhigh = Inter->GetYaxis()->FindBin(yhigh);
252 
253 
254 
255  YBins = (Ymax - Ymin)/step;
256 
257 cout << "ybinlow = " <<ybinlow << endl;
258 cout << "ybinhigh = " << ybinhigh << endl;
259 
260 
261 TH1D *h1 = new TH1D("h1","",YBins,Ymin,Ymax);
262 
263 
264 Inter->ProjectionX("h1",ybinlow,ybinhigh);
265 
266 //cout << "mean = " << Inter->GetMean() << endl;
267 
268 
269 
270 //h1->Draw();
271 
272 
273  Ybinmin = h1->GetXaxis()->FindBin(Ymin);
274 
275 
276  Ybinmax = h1->GetXaxis()->FindBin(Ymax);
277 cout << " OK 1" << endl;
278 
279  N = (Ybinmax - Ybinmin)/NBins;
280 /*
281 for(int i = 0; i < N; i++)
282 {
283 
284  y = Ymin + (i+0.5) * NBins;
285 
286 cout << "y = " << y << endl;
287 ylow = Ymin + i * NBins;
288 
289 yhigh = Ymin + (i+1)*NBins;
290 
291 ybinlow = h1->GetXaxis()->FindBin(ylow);
292 ybinhigh = h1->GetXaxis()->FindBin(yhigh);
293 
294 ycent = h2->GetXaxis()->FindBin(y);
295 
296 
297 mean = h1->Integral(ybinlow,ybinhigh)/NBins/(ybinhigh - ybinlow);
298 
299 cout << "Difference = " << ybinhigh - ybinlow << endl;
300 cout << "y Bin = " << ycent << endl;
301 cout << "Average is = " << mean << endl;
302 
303 h2->SetBinContent(ycent,mean);
304 
305 }
306 */
307 
308 
309 h1->Scale(0.1);
310 //h1->Draw();
311 //h2 = h1;
312 //h2->Draw();
313 
314 sprintf(HistoName,"Result%d.root",j);
315 
316  TFile *fout = new TFile(HistoName,"RECREATE");
317  h1->GetXaxis()->SetTitle("x (mm)");
318  h1->GetYaxis()->SetTitle("Average Energy (GeV)");
319 int k = 7- (j+1)/2;
320 int l = 6- (j+1)/2;
321 int m = 7 - (j+2)/2;
322 
323 
324 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);
325 
326 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);
327 
328  h1->SetTitle(Title);
329 
330  h1->Write();
331 
332 
333 
334 //return;
335 
336 h1->Draw("same");
337 
338 sprintf(outname,"Result2/Energy vs 10-Bin Average X %d.png",j);
339 
340 
341 
342 c22->Update();
343 
344 c22->SaveAs(outname);
345 
346 cout << " OK 2" << endl;
347 }
348 
349 
350 
351 }