Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InterlopationV4.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file InterlopationV4.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 EnPo->SetMaximum(9);
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 Inter->SetBinContent(i,j,finalvalue[i][j]);
169 
170 }
171 
172 
173 }
174 
175 /*
176 cout << "Horizontal Done" << endl;
177 
178 
179 //Vertical Interpolation Begins//
180 
181 cout << "DONE Value" << endl;
182 
183 for(int i = 1; i < XBins; i++)
184 {
185 
186  for(int j = 1; j < YBins; j++)
187 {
188 
189  cout << "Before Updating: Binx = " << i << " " << "Bin y = " << j << " Value = " << value[i][j] << endl;
190 
191 
192 if (value[i][j] < 6.8 && value[i][j-1] >0 && i < XBins && j < YBins)
193 {
194 
195 
196 k = j;
197 do {
198  k = k + 1;
199 
200 // cout << "k value is = " << k << endl;
201 }
202 while(value[i][k] == 0 && k < YBins);
203 
204 //cout << "neW k " << k << endl;
205 
206 value[i][j] =value[i][j-1] + (value[i][k] - value[i][j-1])/(k+1-j);
207 
208  cout << "After Updating: Binx = " << i << " " << " Bin y = " << j << " Value = " <<value[i][j] << endl;
209 
210 }
211 
212 
213 }
214 
215 
216 }
217 
218 cout << "Vk =" << k << endl;
219 
220 //Vertical Interpolation Ends//
221 
222 cout << "VERTICAL DONE" << endl;
223 
224 */
225 /*
226 for(int i =0; i < XBins; i++)
227 {
228 
229 
230 
231  for(int j = 1; j < YBins; j++)
232 {
233 
234 
235 }
236 
237 
238 }
239 */
240 Inter->GetXaxis()->SetTitle("Horizontal Axis (mm)");
241 Inter->GetYaxis()->SetTitle("Vertical Axis (mm)");
242 Inter->SetTitle("Energy vs Horizontal and Vertical Positions After Interpolation - 0 Degree");
243 
244  TFile *fout = new TFile("Interpolated2.root","RECREATE");
245 Inter->Write();
246 
247 
248 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
249 
250 c22->cd();
251 
252 Inter->SetMinimum(3.5);
253 
254 Inter->SetMaximum(9);
255 
256 
257 
258 
259 
260 Inter->Draw("colz");
261 
262 // Horizontal line Tower 6 //
263  TLine *l1 = new TLine(Xmin,y1,Xmax,y1);
264  l1->SetLineWidth(1);
265  l1->Draw("same");
266 
267 
268  TLatex* texCol;
269 texCol= new TLatex(Xmin,y1,"Tower 6");
270  texCol->SetTextAlign(13);
271  texCol->SetTextSize(0.03);
272  texCol->SetTextFont(42);
273  texCol->Draw();
274 
275 
276 // Horizontal line Tower 5 //
277 
278 
279  TLine *l2 = new TLine(Xmin,y2,Xmax,y2);
280  l2->SetLineWidth(1);
281  l2->Draw("same");
282 
283 
284 
285 texCol= new TLatex(Xmin,y2,"Tower 5");
286  texCol->SetTextAlign(13);
287  texCol->SetTextSize(0.03);
288  texCol->SetTextFont(42);
289  texCol->Draw();
290 
291 // Horizontal line Tower 4//
292 
293 
294  TLine *l3 = new TLine(Xmin,y3,Xmax,y3);
295  l3->SetLineWidth(1);
296  l3->Draw("same");
297 
298 
299 
300 texCol= new TLatex(Xmin,y3,"Tower 4");
301  texCol->SetTextAlign(13);
302  texCol->SetTextSize(0.03);
303  texCol->SetTextFont(42);
304  texCol->Draw();
305 
306 
307 
308 // Horizontal line Tower 3 //
309 
310 
311  TLine *l4 = new TLine(Xmin,y4,Xmax,y4);
312  l4->SetLineWidth(1);
313  l4->Draw("same");
314 
315 
316 
317 texCol= new TLatex(Xmin,y4,"Tower 3");
318  texCol->SetTextAlign(13);
319  texCol->SetTextSize(0.03);
320  texCol->SetTextFont(42);
321  texCol->Draw();
322 
323  // Horizontal line Tower 2 //
324 
325 
326  TLine *l4 = new TLine(Xmin,y5,Xmax,y5);
327  l4->SetLineWidth(1);
328  l4->Draw("same");
329 
330 
331 
332 
333 texCol= new TLatex(Xmin,y5,"Tower 2");
334  texCol->SetTextAlign(13);
335  texCol->SetTextSize(0.03);
336  texCol->SetTextFont(42);
337  texCol->Draw();
338 
339 
340  // Horizontal line Tower 1 //
341 
342  TLine *l12 = new TLine(Xmax,Ymax,Xmax,Ymax);
343  l12->SetLineWidth(1);
344  l12->Draw("same");
345 
346 
347  TLatex* texCol;
348 texCol= new TLatex(Xmin,215,"Tower 1");
349  texCol->SetTextAlign(13);
350  texCol->SetTextSize(0.03);
351  texCol->SetTextFont(42);
352  texCol->Draw();
353 
354 
355 
356 // Vertical line Tower 6 //
357  TLine *l6 = new TLine(x1,Ymin,x1,Ymax);
358  l6->SetLineWidth(1);
359  l6->Draw("same");
360 
361 
362  TLatex* texCol;
363 texCol= new TLatex(x1,Ymax,"Tower 6");
364  texCol->SetTextAlign(33);
365  texCol->SetTextSize(0.03);
366  texCol->SetTextFont(42);
367  texCol->Draw();
368 
369 
370 // Horizontal line Tower 5 //
371 
372 
373  TLine *l7 = new TLine(x2,Ymin,x2,Ymax);
374  l7->SetLineWidth(1);
375  l7->Draw("same");
376 
377 
378  TLatex* texCol;
379 texCol= new TLatex(x2,Ymax,"Tower 5");
380  texCol->SetTextAlign(33);
381  texCol->SetTextSize(0.03);
382  texCol->SetTextFont(42);
383  texCol->Draw();
384 
385 // Horizontal line Tower 4//
386 
387 
388  TLine *l8 = new TLine(x3,Ymin,x3,Ymax);
389  l8->SetLineWidth(1);
390  l8->Draw("same");
391 
392 
393  TLatex* texCol;
394 texCol= new TLatex(x3,Ymax,"Tower 4");
395  texCol->SetTextAlign(33);
396  texCol->SetTextSize(0.03);
397  texCol->SetTextFont(42);
398  texCol->Draw();
399 
400 
401 // Horizontal line Tower 3 //
402 
403  TLine *l9 = new TLine(x4,Ymin,x4,Ymax);
404  l9->SetLineWidth(1);
405  l9->Draw("same");
406 
407 
408  TLatex* texCol;
409 texCol= new TLatex(x4,Ymax,"Tower 3");
410  texCol->SetTextAlign(33);
411  texCol->SetTextSize(0.03);
412  texCol->SetTextFont(42);
413  texCol->Draw();
414 
415 
416  // Horizontal line Tower 2 //
417 
418 
419  TLine *l10 = new TLine(x5,Ymin,x5,Ymax);
420  l10->SetLineWidth(1);
421  l10->Draw("same");
422 
423 
424  TLatex* texCol;
425 texCol= new TLatex(x5,Ymax,"Tower 2");
426  texCol->SetTextAlign(33);
427  texCol->SetTextSize(0.03);
428  texCol->SetTextFont(42);
429  texCol->Draw();
430 
431  // Horizontal line Tower 1 //
432 
433  TLine *l11 = new TLine(Xmax,Ymin,Xmax,Ymax);
434  l11->SetLineWidth(1);
435  l11->Draw("same");
436 
437 
438  TLatex* texCol;
439 texCol= new TLatex(Xmax,Ymax,"Tower 1");
440  texCol->SetTextAlign(33);
441  texCol->SetTextSize(0.03);
442  texCol->SetTextFont(42);
443  texCol->Draw();
444 
445 
446 
447 c22->Update();
448 
449 c22->SaveAs("Interpolation 0 Degree.png");
450 
451 }