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 InterlopationV4()
0020 {
0021 
0022      gStyle->SetOptFit(0);
0023    gStyle->SetOptStat(0);
0024     
0025     TFile *fin = new TFile("EnergyPosition3.root");
0026 
0027 //Set Tower Horizontal Lines//
0028 double y1 = 90;
0029 double y2 = 117;
0030 double y3 = 143;
0031 double y4 = 167;
0032 double y5 = 192;
0033 
0034 //Set Tower Vertical Lines//
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 double ylower = 35;
0085 double yhigher = 188;
0086 double xlower = 178;
0087 double xhigher = 301; 
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 EnPo->SetMaximum(9);
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 //x = Xmin + step*i;
0112 
0113 
0114 for(int j = 0; j < YBins; j++)
0115 {
0116 
0117 //  TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
0118 //  y = Ymin + step*j;
0119 
0120 
0121 
0122 
0123 value[i][j] = EnPo->GetBinContent(i,j);
0124 
0125 
0126 }
0127 }
0128 
0129 //Horizontal Interpolation Begins//
0130 
0131 for(int i = backward; i < XBins - backward; i++)
0132 {
0133 
0134     for(int j = backward; j < YBins - backward; j++)
0135 {
0136 
0137 //cout << "OK" << endl;
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 Inter->SetBinContent(i,j,finalvalue[i][j]);
0169 
0170 }
0171 
0172 
0173 }
0174 
0175 /*
0176 cout << "Horizontal Done" << endl;
0177 
0178 
0179 //Vertical Interpolation Begins//
0180 
0181 cout << "DONE Value" << endl;
0182 
0183 for(int i = 1; i < XBins; i++)
0184 {
0185 
0186     for(int j = 1; j < YBins; j++)
0187 {
0188 
0189     cout << "Before Updating: Binx =  " << i << "   " << "Bin y = " << j << " Value =  " << value[i][j] << endl;
0190 
0191 
0192 if (value[i][j] < 6.8 && value[i][j-1] >0 && i < XBins && j < YBins)
0193 {
0194 
0195 
0196 k = j;
0197 do {
0198     k = k + 1;
0199     
0200 //  cout << "k value is = " << k << endl;
0201 }
0202 while(value[i][k] == 0 && k < YBins); 
0203 
0204 //cout << "neW k " << k  << endl;
0205         
0206 value[i][j] =value[i][j-1] + (value[i][k] - value[i][j-1])/(k+1-j);
0207 
0208     cout << "After Updating: Binx =  " << i << "   " << "  Bin y = " << j << "  Value =  " <<value[i][j] << endl;
0209 
0210 }
0211 
0212 
0213 }
0214 
0215 
0216 }
0217 
0218 cout << "Vk =" << k << endl;
0219 
0220 //Vertical Interpolation Ends//
0221 
0222 cout << "VERTICAL DONE" << endl;
0223 
0224 */
0225 /*
0226 for(int i =0; i < XBins; i++)
0227 {
0228 
0229 
0230 
0231     for(int j = 1; j < YBins; j++)
0232 {
0233 
0234 
0235 }
0236 
0237 
0238 }
0239 */
0240 Inter->GetXaxis()->SetTitle("Horizontal Axis (mm)");
0241 Inter->GetYaxis()->SetTitle("Vertical Axis (mm)");
0242 Inter->SetTitle("Energy vs Horizontal and Vertical Positions After Interpolation - 0 Degree");
0243 
0244   TFile *fout = new TFile("Interpolated2.root","RECREATE");
0245 Inter->Write();
0246 
0247 
0248 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
0249 
0250 c22->cd();
0251 
0252 Inter->SetMinimum(3.5);
0253 
0254 Inter->SetMaximum(9);
0255 
0256 
0257 
0258 
0259 
0260 Inter->Draw("colz");
0261 
0262 // Horizontal line Tower 6 //
0263    TLine *l1 = new TLine(Xmin,y1,Xmax,y1);
0264    l1->SetLineWidth(1);
0265    l1->Draw("same");
0266 
0267 
0268  TLatex* texCol;
0269 texCol= new TLatex(Xmin,y1,"Tower 6");
0270   texCol->SetTextAlign(13);
0271   texCol->SetTextSize(0.03);
0272  texCol->SetTextFont(42);
0273   texCol->Draw();
0274 
0275 
0276 // Horizontal line Tower 5 //
0277 
0278 
0279    TLine *l2 = new TLine(Xmin,y2,Xmax,y2);
0280    l2->SetLineWidth(1);
0281    l2->Draw("same");
0282 
0283 
0284 
0285 texCol= new TLatex(Xmin,y2,"Tower 5");
0286   texCol->SetTextAlign(13);
0287   texCol->SetTextSize(0.03);
0288  texCol->SetTextFont(42);
0289   texCol->Draw();
0290 
0291 // Horizontal line Tower 4//
0292 
0293 
0294    TLine *l3 = new TLine(Xmin,y3,Xmax,y3);
0295    l3->SetLineWidth(1);
0296    l3->Draw("same");
0297 
0298 
0299 
0300 texCol= new TLatex(Xmin,y3,"Tower 4");
0301   texCol->SetTextAlign(13);
0302   texCol->SetTextSize(0.03);
0303  texCol->SetTextFont(42);
0304   texCol->Draw();
0305 
0306 
0307 
0308 // Horizontal line Tower 3 //
0309 
0310 
0311    TLine *l4 = new TLine(Xmin,y4,Xmax,y4);
0312    l4->SetLineWidth(1);
0313    l4->Draw("same");
0314 
0315 
0316 
0317 texCol= new TLatex(Xmin,y4,"Tower 3");
0318   texCol->SetTextAlign(13);
0319   texCol->SetTextSize(0.03);
0320  texCol->SetTextFont(42);
0321   texCol->Draw();
0322 
0323   // Horizontal line Tower 2 //
0324 
0325 
0326    TLine *l4 = new TLine(Xmin,y5,Xmax,y5);
0327    l4->SetLineWidth(1);
0328    l4->Draw("same");
0329 
0330 
0331 
0332 
0333 texCol= new TLatex(Xmin,y5,"Tower 2");
0334   texCol->SetTextAlign(13);
0335   texCol->SetTextSize(0.03);
0336  texCol->SetTextFont(42);
0337   texCol->Draw();
0338 
0339 
0340   // Horizontal line Tower 1 //
0341 
0342      TLine *l12 = new TLine(Xmax,Ymax,Xmax,Ymax);
0343    l12->SetLineWidth(1);
0344    l12->Draw("same");
0345 
0346 
0347  TLatex* texCol;
0348 texCol= new TLatex(Xmin,215,"Tower 1");
0349   texCol->SetTextAlign(13);
0350   texCol->SetTextSize(0.03);
0351  texCol->SetTextFont(42);
0352   texCol->Draw();
0353 
0354 
0355 
0356 // Vertical line Tower 6 //
0357    TLine *l6 = new TLine(x1,Ymin,x1,Ymax);
0358    l6->SetLineWidth(1);
0359    l6->Draw("same");
0360 
0361 
0362  TLatex* texCol;
0363 texCol= new TLatex(x1,Ymax,"Tower 6");
0364   texCol->SetTextAlign(33);
0365   texCol->SetTextSize(0.03);
0366  texCol->SetTextFont(42);
0367   texCol->Draw();
0368 
0369 
0370 // Horizontal line Tower 5 //
0371 
0372 
0373    TLine *l7 = new TLine(x2,Ymin,x2,Ymax);
0374    l7->SetLineWidth(1);
0375    l7->Draw("same");
0376 
0377 
0378  TLatex* texCol;
0379 texCol= new TLatex(x2,Ymax,"Tower 5");
0380   texCol->SetTextAlign(33);
0381   texCol->SetTextSize(0.03);
0382  texCol->SetTextFont(42);
0383   texCol->Draw();
0384 
0385 // Horizontal line Tower 4//
0386 
0387 
0388    TLine *l8 = new TLine(x3,Ymin,x3,Ymax);
0389    l8->SetLineWidth(1);
0390    l8->Draw("same");
0391 
0392 
0393  TLatex* texCol;
0394 texCol= new TLatex(x3,Ymax,"Tower 4");
0395   texCol->SetTextAlign(33);
0396   texCol->SetTextSize(0.03);
0397  texCol->SetTextFont(42);
0398   texCol->Draw();
0399 
0400 
0401 // Horizontal line Tower 3 //
0402 
0403    TLine *l9 = new TLine(x4,Ymin,x4,Ymax);
0404    l9->SetLineWidth(1);
0405    l9->Draw("same");
0406 
0407 
0408  TLatex* texCol;
0409 texCol= new TLatex(x4,Ymax,"Tower 3");
0410   texCol->SetTextAlign(33);
0411   texCol->SetTextSize(0.03);
0412  texCol->SetTextFont(42);
0413   texCol->Draw();
0414 
0415 
0416   // Horizontal line Tower 2 //
0417 
0418 
0419    TLine *l10 = new TLine(x5,Ymin,x5,Ymax);
0420    l10->SetLineWidth(1);
0421    l10->Draw("same");
0422 
0423 
0424  TLatex* texCol;
0425 texCol= new TLatex(x5,Ymax,"Tower 2");
0426   texCol->SetTextAlign(33);
0427   texCol->SetTextSize(0.03);
0428  texCol->SetTextFont(42);
0429   texCol->Draw();
0430 
0431   // Horizontal line Tower 1 //
0432 
0433      TLine *l11 = new TLine(Xmax,Ymin,Xmax,Ymax);
0434    l11->SetLineWidth(1);
0435    l11->Draw("same");
0436 
0437 
0438  TLatex* texCol;
0439 texCol= new TLatex(Xmax,Ymax,"Tower 1");
0440   texCol->SetTextAlign(33);
0441   texCol->SetTextSize(0.03);
0442  texCol->SetTextFont(42);
0443   texCol->Draw();
0444 
0445 
0446 
0447 c22->Update();
0448 
0449 c22->SaveAs("Interpolation 0 Degree.png");
0450 
0451 }