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 ProjectionReverse2()
0020 {
0021
0022 gStyle->SetOptFit(0);
0023 gStyle->SetOptStat(0);
0024
0025 TFile *fin = new TFile("EnergyPosition2.root");
0026
0027 double y1 = -90;
0028 double y2 = -117;
0029 double y3 = -143;
0030 double y4 = -167;
0031 double y5 = -192;
0032
0033
0034
0035 double x1 = -205;
0036 double x2 = -228;
0037 double x3 = -253;
0038 double x4 = -277;
0039 double x5 = -301;
0040
0041
0042
0043 int binx;
0044
0045 int forward = 2;
0046 int backward = 2;
0047
0048
0049 int biny;
0050 double step = 1;
0051
0052
0053
0054
0055
0056
0057
0058 double Xmax = -170;
0059 double Xmin = -310.0;
0060
0061 double Ymax = -60;
0062 double Ymin = -205.0;
0063 cout << Ymax << endl;
0064
0065 int NumX = (Xmax - Xmin)/step;
0066 int NumY = (Ymax - Ymin)/step;
0067
0068 const int XBins = NumX;
0069
0070 const int YBins = NumY;
0071 double x;
0072 double y;
0073
0074 cout << "XBins = " << XBins << endl;
0075 cout << "YBins = " << YBins << endl;
0076
0077
0078 double value[XBins][YBins];
0079
0080 double finalvalue[XBins][YBins];
0081
0082 TH2D *Inter = new TH2D("Inter","",XBins,Xmin,Xmax,YBins,Ymin,Ymax);
0083
0084
0085
0086
0087
0088
0089
0090 int k;
0091
0092 int NumberofValue;
0093 double Sum;
0094 int Xnow;
0095
0096 int Ynow;
0097 TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
0098
0099 c1->cd();
0100
0101 EnPo->GetXaxis()->SetTitle("Horizontal Axis (mm)");
0102 EnPo->GetYaxis()->SetTitle("Vertical Axis (mm)");
0103
0104 EnPo->SetTitle("Energy vs Horizontal and Vertical Positions Before Interpolation - 0 Degree");
0105
0106 EnPo->Draw("colz");
0107 c1->Update();
0108
0109 c1->SaveAs("Before0Degree.png");
0110
0111 for(int i = 0; i < XBins; i++)
0112 {
0113
0114
0115
0116
0117 for(int j = 0; j < YBins; j++)
0118 {
0119
0120
0121
0122
0123
0124
0125
0126 value[i][j] = EnPo->GetBinContent(i,j);
0127
0128
0129 }
0130 }
0131
0132
0133 for(int i = backward; i < XBins - backward; i++)
0134 {
0135
0136 for(int j = backward; j < YBins - backward; j++)
0137 {
0138
0139
0140
0141 NumberofValue = 0;
0142 Sum = 0;
0143
0144 Xnow = XBins - i;
0145 Ynow = YBins - j;
0146
0147
0148 for(int k = i - backward; k < i + forward +1; k++)
0149 {
0150
0151 for(int m = j - backward; m < j+backward+1; m++)
0152 {
0153
0154 if(value[k][m] > 0) NumberofValue = NumberofValue + 1;
0155
0156 Sum = Sum + value[k][m];
0157
0158 }
0159
0160 }
0161
0162 cout << "Number of Value = " << NumberofValue << endl;
0163
0164 cout << "Sum = " << Sum << endl;
0165
0166 if(NumberofValue > 0) finalvalue[i][j] = Sum/NumberofValue;
0167
0168 cout << " i = " << i << " j = " << j << endl;
0169 cout << " Xnow = " << Xnow << " YNow = " << Ynow << endl;
0170
0171 cout << "Final Value is " << finalvalue[i][j] << endl;
0172
0173
0174
0175
0176 Inter->SetBinContent(Xnow,Ynow,finalvalue[i][j]);
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
0240
0241
0242
0243
0244
0245
0246
0247
0248 Inter->GetXaxis()->SetTitle("Horizontal Axis (mm)");
0249 Inter->GetYaxis()->SetTitle("Vertical Axis (mm)");
0250 Inter->SetTitle("Energy vs Horizontal and Vertical Positions After Interpolation - 10 Degree");
0251
0252 TFile *fout = new TFile("Interpolated2.root","RECREATE");
0253 Inter->Write();
0254
0255
0256
0257
0258
0259
0260
0261 Inter->Draw("colz");
0262
0263
0264 char Outname[512];
0265
0266 const int All = 7;
0267 double inteval = -12.5;
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302 double initial = -77;
0303 int HAll = All + 5;
0304 for(int i=0; i < HAll; i++)
0305 {
0306 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
0307
0308 Inter->SetMinimum(3.5);
0309 Inter->SetMaximum(9.0);
0310 c22->cd();
0311 Inter->Draw("colz");
0312
0313 left = initial + inteval * i - 5;
0314 right = initial + inteval * i + 5;
0315
0316 TLine *l1 = new TLine(Xmin,left,Xmax,left);
0317
0318 l1->SetLineWidth(2);
0319 l1->Draw("same");
0320
0321 TLine *l2 = new TLine(Xmin,right,Xmax,right);
0322 l2->SetLineWidth(2);
0323 l2->Draw("same");
0324 sprintf(Outname,"Result2/HorizontalPlot%d.png",i);
0325
0326 c22->Update();
0327
0328 c22->SaveAs(Outname);
0329
0330 }
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497 }