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