Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProjectionReverse.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ProjectionReverse.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 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 = -340.0;
60 
61 double Ymax = -60;
62 double Ymin = -245.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 - 0 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 
268 double left;
269 double right;
270 double initial = -191;
271 double inteval = -12.5;
272 
273 for(int i=0; i < All; i++)
274 {
275 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
276 
277 Inter->SetMinimum(3.5);
278 Inter->SetMaximum(9.0);
279 c22->cd();
280  Inter->Draw("colz");
281 
282  left = initial + inteval * i - 5;
283  right = initial + inteval * i + 5;
284 
285  TLine *l1 = new TLine(left,Ymin,left,Ymax);
286 
287  l1->SetLineWidth(2);
288  l1->Draw("same");
289 
290  TLine *l2 = new TLine(right,Ymin,right,Ymax);
291  l2->SetLineWidth(2);
292  l2->Draw("same");
293 sprintf(Outname,"Result/VerticalPlot%d.png",i);
294 
295 c22->Update();
296 
297 c22->SaveAs(Outname);
298 
299 }
300 
301 initial = -77;
302 int HAll = All + 5;
303 for(int i=0; i < HAll; i++)
304 {
305 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
306 
307 Inter->SetMinimum(3.5);
308 Inter->SetMaximum(9.0);
309 c22->cd();
310  Inter->Draw("colz");
311 
312  left = initial + inteval * i - 5;
313  right = initial + inteval * i + 5;
314 
315  TLine *l1 = new TLine(Xmin,left,Xmax,left);
316 
317  l1->SetLineWidth(2);
318  l1->Draw("same");
319 
320  TLine *l2 = new TLine(Xmin,right,Xmax,right);
321  l2->SetLineWidth(2);
322  l2->Draw("same");
323 sprintf(Outname,"Result/HorizontalPlot%d.png",i);
324 
325 c22->Update();
326 
327 c22->SaveAs(Outname);
328 
329 }
330 
331 
332 /*
333 // Horizontal line Tower 1 //
334  TLine *l1 = new TLine(Xmin,y1,Xmax,y1);
335  l1->SetLineWidth(1);
336  l1->Draw("same");
337 
338 
339  TLatex* texCol;
340 texCol= new TLatex(Xmin,y1,"Tower 1");
341  texCol->SetTextAlign(13);
342  texCol->SetTextSize(0.03);
343  texCol->SetTextFont(42);
344  texCol->Draw();
345 
346 
347 // Horizontal line Tower 2 //
348 
349 
350  TLine *l2 = new TLine(Xmin,y2,Xmax,y2);
351  l2->SetLineWidth(1);
352  l2->Draw("same");
353 
354 
355 
356 texCol= new TLatex(Xmin,y2,"Tower 2");
357  texCol->SetTextAlign(13);
358  texCol->SetTextSize(0.03);
359  texCol->SetTextFont(42);
360  texCol->Draw();
361 
362 // Horizontal line Tower 3//
363 
364 
365  TLine *l3 = new TLine(Xmin,y3,Xmax,y3);
366  l3->SetLineWidth(1);
367  l3->Draw("same");
368 
369 
370 
371 texCol= new TLatex(Xmin,y3,"Tower 3");
372  texCol->SetTextAlign(13);
373  texCol->SetTextSize(0.03);
374  texCol->SetTextFont(42);
375  texCol->Draw();
376 
377 
378 
379 // Horizontal line Tower 4 //
380 
381 
382  TLine *l4 = new TLine(Xmin,y4,Xmax,y4);
383  l4->SetLineWidth(1);
384  l4->Draw("same");
385 
386 
387 
388 texCol= new TLatex(Xmin,y4,"Tower 4");
389  texCol->SetTextAlign(13);
390  texCol->SetTextSize(0.03);
391  texCol->SetTextFont(42);
392  texCol->Draw();
393 
394  // Horizontal line Tower 5 //
395 
396 
397  TLine *l4 = new TLine(Xmin,y5,Xmax,y5);
398  l4->SetLineWidth(1);
399  l4->Draw("same");
400 
401 
402 
403 
404 texCol= new TLatex(Xmin,y5,"Tower 5");
405  texCol->SetTextAlign(13);
406  texCol->SetTextSize(0.03);
407  texCol->SetTextFont(42);
408  texCol->Draw();
409 
410 
411 
412 
413 // Vertical line Tower 1 //
414  TLine *l6 = new TLine(x1,Ymin,x1,Ymax);
415  l6->SetLineWidth(1);
416  l6->Draw("same");
417 
418 
419  TLatex* texCol;
420 texCol= new TLatex(x1,Ymax,"Tower 1");
421  texCol->SetTextAlign(33);
422  texCol->SetTextSize(0.03);
423  texCol->SetTextFont(42);
424  texCol->Draw();
425 
426 
427 // Horizontal line Tower 2 //
428 
429 
430  TLine *l7 = new TLine(x2,Ymin,x2,Ymax);
431  l7->SetLineWidth(1);
432  l7->Draw("same");
433 
434 
435  TLatex* texCol;
436 texCol= new TLatex(x2,Ymax,"Tower 2");
437  texCol->SetTextAlign(33);
438  texCol->SetTextSize(0.03);
439  texCol->SetTextFont(42);
440  texCol->Draw();
441 
442 // Horizontal line Tower 3//
443 
444 
445  TLine *l8 = new TLine(x3,Ymin,x3,Ymax);
446  l8->SetLineWidth(1);
447  l8->Draw("same");
448 
449 
450  TLatex* texCol;
451 texCol= new TLatex(x3,Ymax,"Tower 3");
452  texCol->SetTextAlign(33);
453  texCol->SetTextSize(0.03);
454  texCol->SetTextFont(42);
455  texCol->Draw();
456 
457 
458 // Horizontal line Tower 4 //
459 
460  TLine *l9 = new TLine(x4,Ymin,x4,Ymax);
461  l9->SetLineWidth(1);
462  l9->Draw("same");
463 
464 
465  TLatex* texCol;
466 texCol= new TLatex(x4,Ymax,"Tower 4");
467  texCol->SetTextAlign(33);
468  texCol->SetTextSize(0.03);
469  texCol->SetTextFont(42);
470  texCol->Draw();
471 
472 
473  // Horizontal line Tower 5 //
474 
475 
476  TLine *l10 = new TLine(x5,Ymin,x5,Ymax);
477  l10->SetLineWidth(1);
478  l10->Draw("same");
479 
480 
481  TLatex* texCol;
482 texCol= new TLatex(x5,Ymax,"Tower 5");
483  texCol->SetTextAlign(33);
484  texCol->SetTextSize(0.03);
485  texCol->SetTextFont(42);
486  texCol->Draw();
487 */
488 
489 
490 
491 
492 
493 
494 
495 
496 }