File indexing completed on 2025-08-06 08:15:41
0001 #include <cmath>
0002 #include <TFile.h>
0003 #include <TString.h>
0004 #include <TLine.h>
0005 #include <TTree.h>
0006 #include <TLatex.h>
0007 #include <TGraphErrors.h>
0008 #include <cassert>
0009 #include <iostream>
0010 #include <fstream>
0011 using namespace std;
0012
0013
0014
0015 using std::cout;
0016 using std::endl;
0017 #endif
0018
0019 void Interlopation0Degree()
0020 {
0021
0022 gStyle->SetOptFit(0);
0023 gStyle->SetOptStat(0);
0024
0025 TFile *fin = new TFile("EnergyPosition3.root");
0026
0027
0028 double y1 = 90;
0029 double y2 = 117;
0030 double y3 = 143;
0031 double y4 = 167;
0032 double y5 = 192;
0033
0034
0035
0036 double x1 = 205;
0037 double x2 = 228;
0038 double x3 = 253;
0039 double x4 = 277;
0040 double x5 = 301;
0041
0042
0043
0044 int binx;
0045
0046 int forward = 2;
0047 int backward = 2;
0048
0049
0050 int biny;
0051 double step = 1;
0052
0053 double Xmin = 170;
0054 double Xmax = 340.0;
0055
0056 double Ymin = 60;
0057 double Ymax = 245.0;
0058
0059
0060
0061
0062 cout << Ymax << endl;
0063
0064 int NumX = (Xmax - Xmin)/step;
0065 int NumY = (Ymax - Ymin)/step;
0066
0067 const int XBins = NumX;
0068
0069 const int YBins = NumY;
0070 double x;
0071 double y;
0072
0073 cout << "XBins = " << XBins << endl;
0074 cout << "YBins = " << YBins << endl;
0075
0076
0077 double value[XBins][YBins];
0078
0079 double finalvalue[XBins][YBins];
0080
0081 TH2D *Inter = new TH2D("Inter","",XBins,Xmin,Xmax,YBins,Ymin,Ymax);
0082
0083
0084
0085
0086
0087
0088
0089 int k;
0090
0091 int NumberofValue;
0092 double Sum;
0093
0094 TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
0095
0096 c1->cd();
0097
0098 EnPo->GetXaxis()->SetTitle("Horizontal Axis (mm)");
0099 EnPo->GetYaxis()->SetTitle("Vertical Axis (mm)");
0100
0101 EnPo->SetTitle("Energy vs Horizontal and Vertical Positions Before Interpolation - 0 Degree");
0102
0103 EnPo->Draw("colz");
0104 c1->Update();
0105
0106 c1->SaveAs("Before0Degree.png");
0107
0108 for(int i = 0; i < XBins; i++)
0109 {
0110
0111
0112
0113
0114 for(int j = 0; j < YBins; j++)
0115 {
0116
0117
0118
0119
0120
0121
0122
0123 value[i][j] = EnPo->GetBinContent(i,j);
0124
0125
0126 }
0127 }
0128
0129
0130
0131 for(int i = backward; i < XBins - backward; i++)
0132 {
0133
0134 for(int j = backward; j < YBins - backward; j++)
0135 {
0136
0137
0138
0139 NumberofValue = 0;
0140 Sum = 0;
0141 for(int k = i - backward; k < i + forward +1; k++)
0142 {
0143
0144 for(int m = j - backward; m < j+backward+1; m++)
0145 {
0146
0147 if(value[k][m] > 0) NumberofValue = NumberofValue + 1;
0148
0149 Sum = Sum + value[k][m];
0150
0151 }
0152
0153 }
0154
0155 cout << "Number of Value = " << NumberofValue << endl;
0156
0157 cout << "Sum = " << Sum << endl;
0158
0159 if(NumberofValue > 0) finalvalue[i][j] = Sum/NumberofValue;
0160
0161 cout << " i = " << i << " j = " << j << endl;
0162
0163 cout << "Final Value is " << finalvalue[i][j] << endl;
0164
0165
0166 Inter->SetBinContent(i,j,finalvalue[i][j]);
0167
0168
0169 }
0170
0171
0172 }
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239 Inter->GetXaxis()->SetTitle("Horizontal Axis (mm)");
0240 Inter->GetYaxis()->SetTitle("Vertical Axis (mm)");
0241 Inter->SetTitle("Energy vs Horizontal and Vertical Positions After Interpolation - 0 Degree");
0242
0243 TFile *fout = new TFile("Interpolated2.root","RECREATE");
0244 Inter->Write();
0245
0246
0247 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
0248
0249 c22->cd();
0250
0251
0252
0253
0254
0255 Inter->Draw("colz");
0256
0257
0258 TLine *l1 = new TLine(Xmin,y1,Xmax,y1);
0259 l1->SetLineWidth(1);
0260 l1->Draw("same");
0261
0262
0263 TLatex* texCol;
0264 texCol= new TLatex(Xmin,y1,"Tower 1");
0265 texCol->SetTextAlign(13);
0266 texCol->SetTextSize(0.03);
0267 texCol->SetTextFont(42);
0268 texCol->Draw();
0269
0270
0271
0272
0273
0274 TLine *l2 = new TLine(Xmin,y2,Xmax,y2);
0275 l2->SetLineWidth(1);
0276 l2->Draw("same");
0277
0278
0279
0280 texCol= new TLatex(Xmin,y2,"Tower 2");
0281 texCol->SetTextAlign(13);
0282 texCol->SetTextSize(0.03);
0283 texCol->SetTextFont(42);
0284 texCol->Draw();
0285
0286
0287
0288
0289 TLine *l3 = new TLine(Xmin,y3,Xmax,y3);
0290 l3->SetLineWidth(1);
0291 l3->Draw("same");
0292
0293
0294
0295 texCol= new TLatex(Xmin,y3,"Tower 3");
0296 texCol->SetTextAlign(13);
0297 texCol->SetTextSize(0.03);
0298 texCol->SetTextFont(42);
0299 texCol->Draw();
0300
0301
0302
0303
0304
0305
0306 TLine *l4 = new TLine(Xmin,y4,Xmax,y4);
0307 l4->SetLineWidth(1);
0308 l4->Draw("same");
0309
0310
0311
0312 texCol= new TLatex(Xmin,y4,"Tower 4");
0313 texCol->SetTextAlign(13);
0314 texCol->SetTextSize(0.03);
0315 texCol->SetTextFont(42);
0316 texCol->Draw();
0317
0318
0319
0320
0321 TLine *l4 = new TLine(Xmin,y5,Xmax,y5);
0322 l4->SetLineWidth(1);
0323 l4->Draw("same");
0324
0325
0326
0327
0328 texCol= new TLatex(Xmin,y5,"Tower 5");
0329 texCol->SetTextAlign(13);
0330 texCol->SetTextSize(0.03);
0331 texCol->SetTextFont(42);
0332 texCol->Draw();
0333
0334
0335
0336
0337
0338 TLine *l6 = new TLine(x1,Ymin,x1,Ymax);
0339 l6->SetLineWidth(1);
0340 l6->Draw("same");
0341
0342
0343 TLatex* texCol;
0344 texCol= new TLatex(x1,Ymax,"Tower 1");
0345 texCol->SetTextAlign(33);
0346 texCol->SetTextSize(0.03);
0347 texCol->SetTextFont(42);
0348 texCol->Draw();
0349
0350
0351
0352
0353
0354 TLine *l7 = new TLine(x2,Ymin,x2,Ymax);
0355 l7->SetLineWidth(1);
0356 l7->Draw("same");
0357
0358
0359 TLatex* texCol;
0360 texCol= new TLatex(x2,Ymax,"Tower 2");
0361 texCol->SetTextAlign(33);
0362 texCol->SetTextSize(0.03);
0363 texCol->SetTextFont(42);
0364 texCol->Draw();
0365
0366
0367
0368
0369 TLine *l8 = new TLine(x3,Ymin,x3,Ymax);
0370 l8->SetLineWidth(1);
0371 l8->Draw("same");
0372
0373
0374 TLatex* texCol;
0375 texCol= new TLatex(x3,Ymax,"Tower 3");
0376 texCol->SetTextAlign(33);
0377 texCol->SetTextSize(0.03);
0378 texCol->SetTextFont(42);
0379 texCol->Draw();
0380
0381
0382
0383
0384 TLine *l9 = new TLine(x4,Ymin,x4,Ymax);
0385 l9->SetLineWidth(1);
0386 l9->Draw("same");
0387
0388
0389 TLatex* texCol;
0390 texCol= new TLatex(x4,Ymax,"Tower 4");
0391 texCol->SetTextAlign(33);
0392 texCol->SetTextSize(0.03);
0393 texCol->SetTextFont(42);
0394 texCol->Draw();
0395
0396
0397
0398
0399
0400 TLine *l10 = new TLine(x5,Ymin,x5,Ymax);
0401 l10->SetLineWidth(1);
0402 l10->Draw("same");
0403
0404
0405 TLatex* texCol;
0406 texCol= new TLatex(x5,Ymax,"Tower 5");
0407 texCol->SetTextAlign(33);
0408 texCol->SetTextSize(0.03);
0409 texCol->SetTextFont(42);
0410 texCol->Draw();
0411
0412
0413
0414 c22->Update();
0415
0416 c22->SaveAs("Interpolation 0 Degree.png");
0417
0418 }