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 InterlopationV4reverse()
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
0054
0055
0056
0057
0058
0059 double Xmax = -170;
0060 double Xmin = -340.0;
0061
0062 double Ymax = -60;
0063 double Ymin = -245.0;
0064 cout << Ymax << endl;
0065
0066 int NumX = (Xmax - Xmin)/step;
0067 int NumY = (Ymax - Ymin)/step;
0068
0069 const int XBins = NumX;
0070
0071 const int YBins = NumY;
0072 double x;
0073 double y;
0074
0075 cout << "XBins = " << XBins << endl;
0076 cout << "YBins = " << YBins << endl;
0077
0078
0079 double value[XBins][YBins];
0080
0081 double finalvalue[XBins][YBins];
0082
0083 TH2D *Inter = new TH2D("Inter","",XBins,Xmin,Xmax,YBins,Ymin,Ymax);
0084
0085
0086
0087
0088
0089
0090
0091 int k;
0092
0093 int NumberofValue;
0094 double Sum;
0095
0096 TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
0097
0098 c1->cd();
0099
0100 EnPo->GetXaxis()->SetTitle("Horizontal Axis (mm)");
0101 EnPo->GetYaxis()->SetTitle("Vertical Axis (mm)");
0102
0103 EnPo->SetTitle("Energy vs Horizontal and Vertical Positions Before Interpolation - 0 Degree");
0104 EnPo->SetMaximum(9);
0105 EnPo->Draw("colz");
0106 c1->Update();
0107
0108
0109 double XVP;
0110 double YVP;
0111
0112
0113 int Xnow;
0114 int Ynow;
0115 c1->SaveAs("Before0Degree.png");
0116
0117 for(int i = 0; i < XBins; i++)
0118 {
0119
0120
0121
0122
0123 for(int j = 0; j < YBins; j++)
0124 {
0125
0126
0127
0128
0129
0130
0131
0132 value[i][j] = EnPo->GetBinContent(i,j);
0133
0134
0135 }
0136 }
0137
0138
0139
0140 for(int i = backward; i < XBins - backward; i++)
0141 {
0142
0143 for(int j = backward; j < YBins - backward; j++)
0144 {
0145
0146
0147
0148 NumberofValue = 0;
0149 Sum = 0;
0150
0151 Xnow = XBins - i;
0152 Ynow = YBins - j;
0153
0154
0155 for(int k = i - backward; k < i + forward +1; k++)
0156 {
0157
0158 for(int m = j - backward; m < j+backward+1; m++)
0159 {
0160
0161 if(value[k][m] > 0) NumberofValue = NumberofValue + 1;
0162
0163 Sum = Sum + value[k][m];
0164
0165 }
0166
0167 }
0168
0169 cout << "Number of Value = " << NumberofValue << endl;
0170
0171 cout << "Sum = " << Sum << endl;
0172
0173 if(NumberofValue > 0) finalvalue[i][j] = Sum/NumberofValue;
0174
0175 cout << " i = " << i << " j = " << j << endl;
0176 cout << " Xnow = " << Xnow << " YNow = " << Ynow << endl;
0177
0178 cout << "Final Value is " << finalvalue[i][j] << endl;
0179
0180
0181
0182
0183 Inter->SetBinContent(Xnow,Ynow,finalvalue[i][j]);
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
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255 Inter->GetXaxis()->SetTitle("Horizontal Axis (mm)");
0256 Inter->GetYaxis()->SetTitle("Vertical Axis (mm)");
0257 Inter->SetTitle("Energy vs Horizontal and Vertical Positions After Interpolation - 0 Degree");
0258
0259 TFile *fout = new TFile("Interpolated2.root","RECREATE");
0260 Inter->Write();
0261
0262
0263 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
0264
0265 c22->cd();
0266
0267 Inter->SetMinimum(3.5);
0268
0269 Inter->SetMaximum(9);
0270
0271
0272
0273
0274
0275 Inter->Draw("colz");
0276
0277
0278 TLine *l1 = new TLine(Xmin,y1,Xmax,y1);
0279 l1->SetLineWidth(1);
0280 l1->Draw("same");
0281
0282
0283 TLatex* texCol;
0284 texCol= new TLatex(Xmin,y1,"Row 6");
0285 texCol->SetTextAlign(11);
0286 texCol->SetTextSize(0.03);
0287 texCol->SetTextFont(42);
0288 texCol->Draw();
0289
0290
0291
0292
0293
0294 TLine *l2 = new TLine(Xmin,y2,Xmax,y2);
0295 l2->SetLineWidth(1);
0296 l2->Draw("same");
0297
0298
0299
0300 texCol= new TLatex(Xmin,y2,"Row 5");
0301 texCol->SetTextAlign(11);
0302 texCol->SetTextSize(0.03);
0303 texCol->SetTextFont(42);
0304 texCol->Draw();
0305
0306
0307
0308
0309 TLine *l3 = new TLine(Xmin,y3,Xmax,y3);
0310 l3->SetLineWidth(1);
0311 l3->Draw("same");
0312
0313
0314
0315 texCol= new TLatex(Xmin,y3,"Row 4");
0316 texCol->SetTextAlign(11);
0317 texCol->SetTextSize(0.03);
0318 texCol->SetTextFont(42);
0319 texCol->Draw();
0320
0321
0322
0323
0324
0325
0326 TLine *l4 = new TLine(Xmin,y4,Xmax,y4);
0327 l4->SetLineWidth(1);
0328 l4->Draw("same");
0329
0330
0331
0332 texCol= new TLatex(Xmin,y4,"Row 3");
0333 texCol->SetTextAlign(11);
0334 texCol->SetTextSize(0.03);
0335 texCol->SetTextFont(42);
0336 texCol->Draw();
0337
0338
0339
0340
0341 TLine *l4 = new TLine(Xmin,y5,Xmax,y5);
0342 l4->SetLineWidth(1);
0343 l4->Draw("same");
0344
0345
0346
0347
0348 texCol= new TLatex(Xmin,y5,"Row 2");
0349 texCol->SetTextAlign(11);
0350 texCol->SetTextSize(0.03);
0351 texCol->SetTextFont(42);
0352 texCol->Draw();
0353
0354
0355
0356
0357 TLine *l12 = new TLine(Xmax,Ymax,Xmax,Ymax);
0358 l12->SetLineWidth(1);
0359 l12->Draw("same");
0360
0361
0362 TLatex* texCol;
0363 texCol= new TLatex(Xmin,-215,"Row 1");
0364 texCol->SetTextAlign(11);
0365 texCol->SetTextSize(0.03);
0366 texCol->SetTextFont(42);
0367 texCol->Draw();
0368
0369
0370
0371
0372 TLine *l6 = new TLine(x1,Ymin,x1,Ymax);
0373 l6->SetLineWidth(1);
0374 l6->Draw("same");
0375
0376
0377 TLatex* texCol;
0378 texCol= new TLatex(x1,Ymin,"Column 6");
0379 texCol->SetTextAlign(11);
0380 texCol->SetTextSize(0.03);
0381 texCol->SetTextFont(42);
0382 texCol->Draw();
0383
0384
0385
0386
0387
0388 TLine *l7 = new TLine(x2,Ymin,x2,Ymax);
0389 l7->SetLineWidth(1);
0390 l7->Draw("same");
0391
0392
0393 TLatex* texCol;
0394 texCol= new TLatex(x2,Ymin,"Column 5");
0395 texCol->SetTextAlign(11);
0396 texCol->SetTextSize(0.03);
0397 texCol->SetTextFont(42);
0398 texCol->Draw();
0399
0400
0401
0402
0403 TLine *l8 = new TLine(x3,Ymin,x3,Ymax);
0404 l8->SetLineWidth(1);
0405 l8->Draw("same");
0406
0407
0408 TLatex* texCol;
0409 texCol= new TLatex(x3,Ymin,"Column 4");
0410 texCol->SetTextAlign(11);
0411 texCol->SetTextSize(0.03);
0412 texCol->SetTextFont(42);
0413 texCol->Draw();
0414
0415
0416
0417
0418 TLine *l9 = new TLine(x4,Ymin,x4,Ymax);
0419 l9->SetLineWidth(1);
0420 l9->Draw("same");
0421
0422
0423 TLatex* texCol;
0424 texCol= new TLatex(x4,Ymin,"Column 3");
0425 texCol->SetTextAlign(11);
0426 texCol->SetTextSize(0.03);
0427 texCol->SetTextFont(42);
0428 texCol->Draw();
0429
0430
0431
0432
0433
0434 TLine *l10 = new TLine(x5,Ymin,x5,Ymax);
0435 l10->SetLineWidth(1);
0436 l10->Draw("same");
0437
0438
0439 TLatex* texCol;
0440 texCol= new TLatex(x5,Ymin,"Column 2");
0441 texCol->SetTextAlign(11);
0442 texCol->SetTextSize(0.03);
0443 texCol->SetTextFont(42);
0444 texCol->Draw();
0445
0446
0447
0448 TLine *l11 = new TLine(Xmax,Ymin,Xmax,Ymax);
0449 l11->SetLineWidth(1);
0450 l11->Draw("same");
0451
0452
0453 TLatex* texCol;
0454 texCol= new TLatex(x5-8,Ymin,"Column 1");
0455 texCol->SetTextAlign(31);
0456 texCol->SetTextSize(0.03);
0457 texCol->SetTextFont(42);
0458 texCol->Draw();
0459
0460
0461
0462 c22->Update();
0463
0464 c22->SaveAs("Interpolation 0 Degree Reversed.png");
0465
0466 }