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