Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Interlopation0Degree.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Interlopation0Degree.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 using namespace std;
12 
13 
14 
15 using std::cout;
16 using std::endl;
17 #endif
18 
20 {
21 
22  gStyle->SetOptFit(0);
23  gStyle->SetOptStat(0);
24 
25  TFile *fin = new TFile("EnergyPosition3.root");
26 
27 //Set Tower Horizontal Lines//
28 double y1 = 90;
29 double y2 = 117;
30 double y3 = 143;
31 double y4 = 167;
32 double y5 = 192;
33 
34 //Set Tower Vertical Lines//
35 
36 double x1 = 205;
37 double x2 = 228;
38 double x3 = 253;
39 double x4 = 277;
40 double x5 = 301;
41 
42 
43 
44 int binx;
45 
46 int forward = 2;
47 int backward = 2;
48 
49 
50 int biny;
51 double step = 1;
52 
53 double Xmin = 170;
54 double Xmax = 340.0;
55 
56 double Ymin = 60;
57 double Ymax = 245.0;
58 
59 
60 
61 
62 cout << Ymax << endl;
63 
64 int NumX = (Xmax - Xmin)/step;
65 int NumY = (Ymax - Ymin)/step;
66 
67 const int XBins = NumX;
68 
69 const int YBins = NumY;
70 double x;
71 double y;
72 
73 cout << "XBins = " << XBins << endl;
74 cout << "YBins = " << YBins << endl;
75 
76 
77 double value[XBins][YBins];
78 
79 double finalvalue[XBins][YBins];
80 
81 TH2D *Inter = new TH2D("Inter","",XBins,Xmin,Xmax,YBins,Ymin,Ymax);
82 
83 /*
84 double ylower = 35;
85 double yhigher = 188;
86 double xlower = 178;
87 double xhigher = 301;
88 */
89 int k;
90 
91 int NumberofValue;
92 double Sum;
93 
94 TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
95 
96 c1->cd();
97 
98 EnPo->GetXaxis()->SetTitle("Horizontal Axis (mm)");
99 EnPo->GetYaxis()->SetTitle("Vertical Axis (mm)");
100 
101 EnPo->SetTitle("Energy vs Horizontal and Vertical Positions Before Interpolation - 0 Degree");
102 
103 EnPo->Draw("colz");
104 c1->Update();
105 
106 c1->SaveAs("Before0Degree.png");
107 
108 for(int i = 0; i < XBins; i++)
109 {
110 
111 //x = Xmin + step*i;
112 
113 
114 for(int j = 0; j < YBins; j++)
115 {
116 
117 // TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
118 // y = Ymin + step*j;
119 
120 
121 
122 
123 value[i][j] = EnPo->GetBinContent(i,j);
124 
125 
126 }
127 }
128 
129 //Horizontal Interpolation Begins//
130 
131 for(int i = backward; i < XBins - backward; i++)
132 {
133 
134  for(int j = backward; j < YBins - backward; j++)
135 {
136 
137 //cout << "OK" << endl;
138 
139 NumberofValue = 0;
140 Sum = 0;
141 for(int k = i - backward; k < i + forward +1; k++)
142 {
143 
144  for(int m = j - backward; m < j+backward+1; m++)
145  {
146 
147  if(value[k][m] > 0) NumberofValue = NumberofValue + 1;
148 
149  Sum = Sum + value[k][m];
150 
151  }
152 
153 }
154 
155 cout << "Number of Value = " << NumberofValue << endl;
156 
157 cout << "Sum = " << Sum << endl;
158 
159 if(NumberofValue > 0) finalvalue[i][j] = Sum/NumberofValue;
160 
161 cout << " i = " << i << " j = " << j << endl;
162 
163 cout << "Final Value is " << finalvalue[i][j] << endl;
164 
165 
166 Inter->SetBinContent(i,j,finalvalue[i][j]);
167 
168 
169 }
170 
171 
172 }
173 
174 /*
175 cout << "Horizontal Done" << endl;
176 
177 
178 //Vertical Interpolation Begins//
179 
180 cout << "DONE Value" << endl;
181 
182 for(int i = 1; i < XBins; i++)
183 {
184 
185  for(int j = 1; j < YBins; j++)
186 {
187 
188  cout << "Before Updating: Binx = " << i << " " << "Bin y = " << j << " Value = " << value[i][j] << endl;
189 
190 
191 if (value[i][j] < 6.8 && value[i][j-1] >0 && i < XBins && j < YBins)
192 {
193 
194 
195 k = j;
196 do {
197  k = k + 1;
198 
199 // cout << "k value is = " << k << endl;
200 }
201 while(value[i][k] == 0 && k < YBins);
202 
203 //cout << "neW k " << k << endl;
204 
205 value[i][j] =value[i][j-1] + (value[i][k] - value[i][j-1])/(k+1-j);
206 
207  cout << "After Updating: Binx = " << i << " " << " Bin y = " << j << " Value = " <<value[i][j] << endl;
208 
209 }
210 
211 
212 }
213 
214 
215 }
216 
217 cout << "Vk =" << k << endl;
218 
219 //Vertical Interpolation Ends//
220 
221 cout << "VERTICAL DONE" << endl;
222 
223 */
224 /*
225 for(int i =0; i < XBins; i++)
226 {
227 
228 
229 
230  for(int j = 1; j < YBins; j++)
231 {
232 
233 
234 }
235 
236 
237 }
238 */
239 Inter->GetXaxis()->SetTitle("Horizontal Axis (mm)");
240 Inter->GetYaxis()->SetTitle("Vertical Axis (mm)");
241 Inter->SetTitle("Energy vs Horizontal and Vertical Positions After Interpolation - 0 Degree");
242 
243  TFile *fout = new TFile("Interpolated2.root","RECREATE");
244 Inter->Write();
245 
246 
247 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
248 
249 c22->cd();
250 
251 
252 
253 
254 
255 Inter->Draw("colz");
256 
257 // Horizontal line Tower 1 //
258  TLine *l1 = new TLine(Xmin,y1,Xmax,y1);
259  l1->SetLineWidth(1);
260  l1->Draw("same");
261 
262 
263  TLatex* texCol;
264 texCol= new TLatex(Xmin,y1,"Tower 1");
265  texCol->SetTextAlign(13);
266  texCol->SetTextSize(0.03);
267  texCol->SetTextFont(42);
268  texCol->Draw();
269 
270 
271 // Horizontal line Tower 2 //
272 
273 
274  TLine *l2 = new TLine(Xmin,y2,Xmax,y2);
275  l2->SetLineWidth(1);
276  l2->Draw("same");
277 
278 
279 
280 texCol= new TLatex(Xmin,y2,"Tower 2");
281  texCol->SetTextAlign(13);
282  texCol->SetTextSize(0.03);
283  texCol->SetTextFont(42);
284  texCol->Draw();
285 
286 // Horizontal line Tower 3//
287 
288 
289  TLine *l3 = new TLine(Xmin,y3,Xmax,y3);
290  l3->SetLineWidth(1);
291  l3->Draw("same");
292 
293 
294 
295 texCol= new TLatex(Xmin,y3,"Tower 3");
296  texCol->SetTextAlign(13);
297  texCol->SetTextSize(0.03);
298  texCol->SetTextFont(42);
299  texCol->Draw();
300 
301 
302 
303 // Horizontal line Tower 4 //
304 
305 
306  TLine *l4 = new TLine(Xmin,y4,Xmax,y4);
307  l4->SetLineWidth(1);
308  l4->Draw("same");
309 
310 
311 
312 texCol= new TLatex(Xmin,y4,"Tower 4");
313  texCol->SetTextAlign(13);
314  texCol->SetTextSize(0.03);
315  texCol->SetTextFont(42);
316  texCol->Draw();
317 
318  // Horizontal line Tower 5 //
319 
320 
321  TLine *l4 = new TLine(Xmin,y5,Xmax,y5);
322  l4->SetLineWidth(1);
323  l4->Draw("same");
324 
325 
326 
327 
328 texCol= new TLatex(Xmin,y5,"Tower 5");
329  texCol->SetTextAlign(13);
330  texCol->SetTextSize(0.03);
331  texCol->SetTextFont(42);
332  texCol->Draw();
333 
334 
335 
336 
337 // Vertical line Tower 1 //
338  TLine *l6 = new TLine(x1,Ymin,x1,Ymax);
339  l6->SetLineWidth(1);
340  l6->Draw("same");
341 
342 
343  TLatex* texCol;
344 texCol= new TLatex(x1,Ymax,"Tower 1");
345  texCol->SetTextAlign(33);
346  texCol->SetTextSize(0.03);
347  texCol->SetTextFont(42);
348  texCol->Draw();
349 
350 
351 // Horizontal line Tower 2 //
352 
353 
354  TLine *l7 = new TLine(x2,Ymin,x2,Ymax);
355  l7->SetLineWidth(1);
356  l7->Draw("same");
357 
358 
359  TLatex* texCol;
360 texCol= new TLatex(x2,Ymax,"Tower 2");
361  texCol->SetTextAlign(33);
362  texCol->SetTextSize(0.03);
363  texCol->SetTextFont(42);
364  texCol->Draw();
365 
366 // Horizontal line Tower 3//
367 
368 
369  TLine *l8 = new TLine(x3,Ymin,x3,Ymax);
370  l8->SetLineWidth(1);
371  l8->Draw("same");
372 
373 
374  TLatex* texCol;
375 texCol= new TLatex(x3,Ymax,"Tower 3");
376  texCol->SetTextAlign(33);
377  texCol->SetTextSize(0.03);
378  texCol->SetTextFont(42);
379  texCol->Draw();
380 
381 
382 // Horizontal line Tower 4 //
383 
384  TLine *l9 = new TLine(x4,Ymin,x4,Ymax);
385  l9->SetLineWidth(1);
386  l9->Draw("same");
387 
388 
389  TLatex* texCol;
390 texCol= new TLatex(x4,Ymax,"Tower 4");
391  texCol->SetTextAlign(33);
392  texCol->SetTextSize(0.03);
393  texCol->SetTextFont(42);
394  texCol->Draw();
395 
396 
397  // Horizontal line Tower 5 //
398 
399 
400  TLine *l10 = new TLine(x5,Ymin,x5,Ymax);
401  l10->SetLineWidth(1);
402  l10->Draw("same");
403 
404 
405  TLatex* texCol;
406 texCol= new TLatex(x5,Ymax,"Tower 5");
407  texCol->SetTextAlign(33);
408  texCol->SetTextSize(0.03);
409  texCol->SetTextFont(42);
410  texCol->Draw();
411 
412 
413 
414 c22->Update();
415 
416 c22->SaveAs("Interpolation 0 Degree.png");
417 
418 }