Back to home page

sPhenix code displayed by LXR

 
 

    


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("EnergyPosition2.root");
0026 
0027 //Set Tower Horizontal Lines//
0028 double y1 = -90;
0029 double y2 = -113;
0030 double y3 = -141;
0031 double y4 = -166;
0032 double y5 = -190;
0033 
0034 //Set Tower Vertical Lines//
0035 
0036 double x1 = -204;
0037 double x2 = -228;
0038 double x3 = -248;
0039 double x4 = -265;
0040 double x5 = -283;
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 double Xmax = -170;
0062 double Xmin = -340.0;
0063 
0064 double Ymax = -60;
0065 double Ymin = -245.0;
0066 */
0067 
0068 double Xmax = -170;
0069 double Xmin = -310.0;
0070 
0071 double Ymax = -60;
0072 double Ymin = -245.0;
0073 
0074 
0075 
0076 cout << Ymax << endl;
0077 
0078 int NumX = (Xmax - Xmin)/step;
0079 int NumY = (Ymax - Ymin)/step;
0080 
0081 const int XBins = NumX;
0082 
0083 const int YBins = NumY;
0084 double x;
0085 double y;
0086 
0087 cout << "XBins = " << XBins << endl;
0088 cout << "YBins = " << YBins << endl;
0089 
0090 
0091 double value[XBins][YBins];
0092 
0093 double finalvalue[XBins][YBins];
0094 
0095 TH2D *Inter = new TH2D("Inter","",XBins,Xmin,Xmax,YBins,Ymin,Ymax);
0096 
0097 /*
0098 double ylower = 35;
0099 double yhigher = 188;
0100 double xlower = 178;
0101 double xhigher = 301; 
0102 */
0103 int k;
0104 
0105 int NumberofValue;
0106 double Sum;
0107 
0108 TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
0109 
0110 c1->cd();
0111 
0112 EnPo->GetXaxis()->SetTitle("Horizontal Axis (mm)");
0113 EnPo->GetYaxis()->SetTitle("Vertical Axis (mm)");
0114 
0115 EnPo->SetTitle("Energy vs Horizontal and Vertical Positions Before Interpolation - 0 Degree");
0116 EnPo->SetMaximum(9);
0117 EnPo->Draw("colz");
0118 c1->Update();
0119 
0120 
0121 double XVP;
0122 double YVP;
0123 
0124 
0125 int Xnow;
0126 int Ynow;
0127 c1->SaveAs("Before0Degree.png");
0128 
0129 for(int i = 0; i < XBins; i++)
0130 {
0131 
0132 //x = Xmin + step*i;
0133 
0134 
0135 for(int j = 0; j < YBins; j++)
0136 {
0137 
0138 //  TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
0139 //  y = Ymin + step*j;
0140 
0141 
0142 
0143 
0144 value[i][j] = EnPo->GetBinContent(i,j);
0145 
0146 
0147 }
0148 }
0149 
0150 //Horizontal Interpolation Begins//
0151 
0152 for(int i = backward; i < XBins - backward; i++)
0153 {
0154 
0155     for(int j = backward; j < YBins - backward; j++)
0156 {
0157 
0158 //cout << "OK" << endl;
0159 
0160 NumberofValue = 0;
0161 Sum = 0;
0162 
0163 Xnow = XBins - i;
0164 Ynow = YBins - j;
0165 
0166 
0167 for(int k = i - backward; k < i + forward +1; k++)
0168 {
0169 
0170     for(int m = j - backward; m < j+backward+1; m++)
0171     {
0172     
0173         if(value[k][m] > 0) NumberofValue = NumberofValue + 1;
0174         
0175         Sum = Sum + value[k][m];
0176     
0177             }
0178 
0179 }
0180 
0181 cout << "Number of Value = " << NumberofValue << endl;
0182 
0183 cout << "Sum = " << Sum << endl;
0184 
0185 if(NumberofValue > 0) finalvalue[i][j] = Sum/NumberofValue;
0186 
0187 cout << " i = " << i <<  "  j = " << j << endl;
0188 cout << " Xnow = " << Xnow <<  "  YNow = " << Ynow << endl;
0189 
0190 cout << "Final Value is " << finalvalue[i][j]  << endl;
0191 
0192 
0193 //Inter->SetBinContent(i,j,finalvalue[i][j]);
0194 
0195 Inter->SetBinContent(Xnow,Ynow,finalvalue[i][j]);
0196 
0197 }
0198 
0199 
0200 }
0201 
0202 /*
0203 cout << "Horizontal Done" << endl;
0204 
0205 
0206 //Vertical Interpolation Begins//
0207 
0208 cout << "DONE Value" << endl;
0209 
0210 for(int i = 1; i < XBins; i++)
0211 {
0212 
0213     for(int j = 1; j < YBins; j++)
0214 {
0215 
0216     cout << "Before Updating: Binx =  " << i << "   " << "Bin y = " << j << " Value =  " << value[i][j] << endl;
0217 
0218 
0219 if (value[i][j] < 6.8 && value[i][j-1] >0 && i < XBins && j < YBins)
0220 {
0221 
0222 
0223 k = j;
0224 do {
0225     k = k + 1;
0226     
0227 //  cout << "k value is = " << k << endl;
0228 }
0229 while(value[i][k] == 0 && k < YBins); 
0230 
0231 //cout << "neW k " << k  << endl;
0232         
0233 value[i][j] =value[i][j-1] + (value[i][k] - value[i][j-1])/(k+1-j);
0234 
0235     cout << "After Updating: Binx =  " << i << "   " << "  Bin y = " << j << "  Value =  " <<value[i][j] << endl;
0236 
0237 }
0238 
0239 
0240 }
0241 
0242 
0243 }
0244 
0245 cout << "Vk =" << k << endl;
0246 
0247 //Vertical Interpolation Ends//
0248 
0249 cout << "VERTICAL DONE" << endl;
0250 
0251 */
0252 /*
0253 for(int i =0; i < XBins; i++)
0254 {
0255 
0256 
0257 
0258     for(int j = 1; j < YBins; j++)
0259 {
0260 
0261 
0262 }
0263 
0264 
0265 }
0266 */
0267 Inter->GetXaxis()->SetTitle("Horizontal Axis (mm)");
0268 Inter->GetYaxis()->SetTitle("Vertical Axis (mm)");
0269 Inter->SetTitle("Energy vs Horizontal and Vertical Positions After Interpolation - 0 Degree");
0270 
0271   TFile *fout = new TFile("Interpolated2.root","RECREATE");
0272 Inter->Write();
0273 
0274 
0275 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
0276 
0277 c22->cd();
0278 
0279 Inter->SetMinimum(4.5);
0280 
0281 Inter->SetMaximum(9);
0282 
0283 
0284 
0285 
0286 
0287 Inter->Draw("colz");
0288 
0289 // Horizontal line Tower 6 //
0290    TLine *l1 = new TLine(Xmin,y1,Xmax,y1);
0291    l1->SetLineWidth(1);
0292    l1->Draw("same");
0293 
0294 
0295  TLatex* texCol;
0296 texCol= new TLatex(Xmin,y1,"Row 6");
0297   texCol->SetTextAlign(11);
0298   texCol->SetTextSize(0.03);
0299  texCol->SetTextFont(42);
0300   texCol->Draw();
0301 
0302 
0303 // Horizontal line Tower 5 //
0304 
0305 
0306    TLine *l2 = new TLine(Xmin,y2,Xmax,y2);
0307    l2->SetLineWidth(1);
0308    l2->Draw("same");
0309 
0310 
0311 
0312 texCol= new TLatex(Xmin,y2,"Row 5");
0313   texCol->SetTextAlign(11);
0314   texCol->SetTextSize(0.03);
0315  texCol->SetTextFont(42);
0316   texCol->Draw();
0317 
0318 // Horizontal line Tower 4//
0319 
0320 
0321    TLine *l3 = new TLine(Xmin,y3,Xmax,y3);
0322    l3->SetLineWidth(1);
0323    l3->Draw("same");
0324 
0325 
0326 
0327 texCol= new TLatex(Xmin,y3,"Row 4");
0328   texCol->SetTextAlign(11);
0329   texCol->SetTextSize(0.03);
0330  texCol->SetTextFont(42);
0331   texCol->Draw();
0332 
0333 
0334 
0335 // Horizontal line Tower 3 //
0336 
0337 
0338    TLine *l4 = new TLine(Xmin,y4,Xmax,y4);
0339    l4->SetLineWidth(1);
0340    l4->Draw("same");
0341 
0342 
0343 
0344 texCol= new TLatex(Xmin,y4,"Row 3");
0345   texCol->SetTextAlign(11);
0346   texCol->SetTextSize(0.03);
0347  texCol->SetTextFont(42);
0348   texCol->Draw();
0349 
0350   // Horizontal line Tower 2 //
0351 
0352 
0353    TLine *l4 = new TLine(Xmin,y5,Xmax,y5);
0354    l4->SetLineWidth(1);
0355    l4->Draw("same");
0356 
0357 
0358 
0359 
0360 texCol= new TLatex(Xmin,y5,"Row 2");
0361   texCol->SetTextAlign(11);
0362   texCol->SetTextSize(0.03);
0363  texCol->SetTextFont(42);
0364   texCol->Draw();
0365 
0366 
0367   // Horizontal line Tower 1 //
0368 
0369      TLine *l12 = new TLine(Xmax,Ymax,Xmax,Ymax);
0370    l12->SetLineWidth(1);
0371    l12->Draw("same");
0372 
0373 
0374  TLatex* texCol;
0375 texCol= new TLatex(Xmin,-215,"Row 1");
0376   texCol->SetTextAlign(11);
0377   texCol->SetTextSize(0.03);
0378  texCol->SetTextFont(42);
0379   texCol->Draw();
0380 
0381 
0382 
0383 // Vertical line Tower 6 //
0384    TLine *l6 = new TLine(x1,Ymin,x1,Ymax);
0385    l6->SetLineWidth(1);
0386    l6->Draw("same");
0387 
0388 
0389  TLatex* texCol;
0390 texCol= new TLatex(x1,Ymin,"Column 6");
0391   texCol->SetTextAlign(11);
0392   texCol->SetTextSize(0.03);
0393  texCol->SetTextFont(42);
0394   texCol->Draw();
0395 
0396 
0397 // Horizontal line Tower 5 //
0398 
0399 
0400    TLine *l7 = new TLine(x2,Ymin,x2,Ymax);
0401    l7->SetLineWidth(1);
0402    l7->Draw("same");
0403 
0404 
0405  TLatex* texCol;
0406 texCol= new TLatex(x2,Ymin,"Column 5");
0407   texCol->SetTextAlign(11);
0408   texCol->SetTextSize(0.03);
0409  texCol->SetTextFont(42);
0410   texCol->Draw();
0411 
0412 // Horizontal line Tower 4//
0413 
0414 
0415    TLine *l8 = new TLine(x3,Ymin,x3,Ymax);
0416    l8->SetLineWidth(1);
0417    l8->Draw("same");
0418 
0419 
0420  TLatex* texCol;
0421 texCol= new TLatex(x3,Ymin,"Column 4");
0422   texCol->SetTextAlign(11);
0423   texCol->SetTextSize(0.03);
0424  texCol->SetTextFont(42);
0425   texCol->Draw();
0426 
0427 
0428 // Horizontal line Tower 3 //
0429 
0430    TLine *l9 = new TLine(x4,Ymin,x4,Ymax);
0431    l9->SetLineWidth(1);
0432    l9->Draw("same");
0433 
0434 
0435  TLatex* texCol;
0436 texCol= new TLatex(x4,Ymin,"Column 3");
0437   texCol->SetTextAlign(11);
0438   texCol->SetTextSize(0.03);
0439  texCol->SetTextFont(42);
0440   texCol->Draw();
0441 
0442 
0443   // Horizontal line Tower 2 //
0444 
0445 
0446    TLine *l10 = new TLine(x5,Ymin,x5,Ymax);
0447    l10->SetLineWidth(1);
0448    l10->Draw("same");
0449 
0450 
0451  TLatex* texCol;
0452 texCol= new TLatex(x5,Ymin,"Column 2");
0453   texCol->SetTextAlign(11);
0454   texCol->SetTextSize(0.03);
0455  texCol->SetTextFont(42);
0456   texCol->Draw();
0457 
0458   // Horizontal line Tower 1 //
0459 
0460      TLine *l11 = new TLine(Xmax,Ymin,Xmax,Ymax);
0461    l11->SetLineWidth(1);
0462    l11->Draw("same");
0463 
0464 
0465  TLatex* texCol;
0466 texCol= new TLatex(x5-8,Ymin,"Column 1");
0467   texCol->SetTextAlign(31);
0468   texCol->SetTextSize(0.03);
0469  texCol->SetTextFont(42);
0470   texCol->Draw();
0471 
0472 
0473 
0474 c22->Update();
0475 
0476 c22->SaveAs("Interpolation 0 Degree Reversed.png");
0477 
0478 }