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