File indexing completed on 2025-08-06 08:12:15
0001 #include "GeoScanV2.C"
0002
0003 map<int,int> hist_location(string folder_direction, vector<string> file_list)
0004 {
0005 int random_seed;
0006 map<int,int> hist_location_map;
0007
0008 for (int i = 0; i < file_list.size(); i++)
0009 {
0010 cout<<file_list[i]<<endl;
0011 TFile * _file0 = TFile::Open(Form("%s/%s",folder_direction.c_str(),file_list[i].c_str()));
0012 TTree * _tree0 = (TTree *) _file0 -> Get("tree_geo_scan");
0013 _tree0 -> SetBranchStatus("*",0);
0014 _tree0 -> SetBranchStatus("random_seed",1);
0015 _tree0 -> SetBranchAddress("random_seed",&random_seed);
0016
0017 for (int j = 0; j < _tree0 -> GetEntries(); j++)
0018 {
0019 _tree0 -> GetEntry(j);
0020 hist_location_map[random_seed] = i;
0021 }
0022
0023 _file0 -> Close();
0024 }
0025
0026 return hist_location_map;
0027 }
0028
0029 vector<double> SumTH2FColumnContent(TH2F * hist_in)
0030 {
0031 vector<double> sum_vec; sum_vec.clear();
0032 for (int i = 0; i < hist_in -> GetNbinsX(); i++){
0033 double sum = 0;
0034 for (int j = 0; j < hist_in -> GetNbinsY(); j++){
0035 sum += hist_in -> GetBinContent(i+1, j+1);
0036 }
0037 sum_vec.push_back(sum);
0038 }
0039 return sum_vec;
0040 }
0041
0042 void Characterize_Pad(TPad *pad, float left = 0.15, float right = 0.1, float top = 0.1, float bottom = 0.12, bool set_logY = false, int setgrid_bool = 0)
0043 {
0044 if (setgrid_bool == true) {pad -> SetGrid (1, 1);}
0045 pad -> SetLeftMargin (left);
0046 pad -> SetRightMargin (right);
0047 pad -> SetTopMargin (top);
0048 pad -> SetBottomMargin (bottom);
0049 pad -> SetTicks(1,1);
0050 if (set_logY == true)
0051 {
0052 pad -> SetLogy (1);
0053 }
0054
0055 }
0056
0057 vector<double> Get_coveriance_TH2 (TH2F * hist_in)
0058 {
0059 double X_mean = hist_in -> GetMean(1);
0060 double Y_mean = hist_in -> GetMean(2);
0061
0062 double denominator = 0;
0063 double variance_x = 0;
0064 double variance_y = 0;
0065 double covariance = 0;
0066
0067 for (int xi = 0; xi < hist_in -> GetNbinsX(); xi++){
0068 for (int yi = 0; y1 < hist_in -> GetNbinsY(); yi++)
0069 {
0070 double cell_weight = hist_in -> GetBinContent(xi+1, yi+1);
0071 double cell_x = hist_in -> GetXaxis() -> GetBinCenter(xi+1);
0072 double cell_y = hist_in -> GetYaxis() -> GetBinCenter(yi+1);
0073
0074 denominator += pow(cell_weight, 2);
0075 variance_x += pow(cell_x - X_mean, 2) * pow(cell_weight,2);
0076 variance_y += pow(cell_y - Y_mean, 2) * pow(cell_weight,2);
0077 covariance += (cell_x - X_mean) * (cell_y - Y_mean) * pow(cell_weight,2);
0078 }
0079 }
0080
0081 return {variance_x/denominator, variance_y/denominator, covariance/denominator};
0082 }
0083
0084 void Geo1Scan_Ana()
0085 {
0086
0087
0088 string folder_direction = "/sphenix/user/ChengWei/sPH_dNdeta/dNdEta_INTT_MC_388_000/Geo_scan1_MC_ZF_xyvtx/complete_file";
0089 string MC_list_name = "file_list.txt";
0090 int Nfile = -1;
0091 pair<double,double> origin_fitE = {0.0956607, 0.0101596};
0092 pair<double,double> origin_posY = {0.189019, 0.0424588};
0093
0094 TChain * chain_in = new TChain("tree_geo_scan");
0095 GeoScanV2 * data_in = new GeoScanV2(chain_in, folder_direction, MC_list_name, Nfile);
0096 cout<<"Total event : "<<chain_in -> GetEntries()<<endl;
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 int small_random_seed;
0109 int small_eID;
0110 double small_check_number;
0111
0112 TCanvas * c1 = new TCanvas("c1","c1",1800,1200);
0113 c1 -> Divide(3,2);
0114 c1 -> Print(Form("%s/good_correct_set.pdf(",folder_direction.c_str()));
0115
0116 TGraph * gx_all = new TGraph();
0117 gx_all -> SetMarkerStyle(20);
0118 gx_all -> SetMarkerColor(2);
0119 gx_all -> SetTitle("gx_all;Ladder ID; #DeltaX [mm]");
0120 TGraph * gy_all = new TGraph();
0121 gy_all -> SetMarkerStyle(20);
0122 gy_all -> SetMarkerColor(2);
0123 gy_all -> SetTitle("gy_all;Ladder ID; #DeltaY [mm]");
0124
0125 TGraph * gx_each = new TGraph();
0126 gx_each -> SetMarkerStyle(20);
0127 gx_each -> SetMarkerColor(2);
0128 gx_each -> SetTitle("gx_each;Ladder ID; #DeltaX [mm]");
0129 TGraph * gy_each = new TGraph();
0130 gy_each -> SetMarkerStyle(20);
0131 gy_each -> SetMarkerColor(2);
0132 gy_each -> SetTitle("gy_each;Ladder ID; #DeltaY [mm]");
0133
0134 TH2F * correct_vtx = new TH2F("","vertex;X axis[mm];Y axis[mm]",100,-2,2,100,0,4);
0135 TH2F * x_correction = new TH2F("","Correction in X axis;Ladder index;Offset [mm]",14,1,15,100,-0.4,0.4); x_correction -> SetStats(0);
0136 TH2F * y_correction = new TH2F("","Correction in Y axis;Ladder index;Offset [mm]",14,1,15,100,-0.4,0.4); y_correction -> SetStats(0);
0137
0138 TLine * coord_line = new TLine();
0139 coord_line -> SetLineWidth(1);
0140 coord_line -> SetLineColor(16);
0141 coord_line -> SetLineStyle(2);
0142
0143 TLatex * draw_text = new TLatex();
0144 draw_text -> SetNDC();
0145 draw_text -> SetTextSize(0.03);
0146
0147 map<int,int> hist_location_map = hist_location(folder_direction, data_in -> file_list);
0148
0149 TF1 * f2 = new TF1("f2","pol0",-360,360);
0150 TF1 * f3 = new TF1("f3","pol0",-360,360);
0151 TF1 * f4 = new TF1("f4","pol0",-360,360);
0152 TF1 * f5 = new TF1("f5","pol0",-360,360);
0153
0154 TGraph * h2_profile_graph = new TGraph(); h2_profile_graph -> SetMarkerStyle(20); h2_profile_graph -> SetMarkerSize(0.4);
0155 TGraph * h3_profile_graph = new TGraph(); h3_profile_graph -> SetMarkerStyle(20); h3_profile_graph -> SetMarkerSize(0.4);
0156 TGraph * h4_profile_graph = new TGraph(); h4_profile_graph -> SetMarkerStyle(20); h4_profile_graph -> SetMarkerSize(0.4);
0157 TGraph * h5_profile_graph = new TGraph(); h5_profile_graph -> SetMarkerStyle(20); h5_profile_graph -> SetMarkerSize(0.4);
0158
0159 vector<double> hist_column_content;
0160
0161
0162 for (int i = 0; i <chain_in -> GetEntries(); i++ )
0163 {
0164 data_in->LoadTree(i);
0165 data_in->GetEntry(i);
0166
0167
0168
0169
0170 if (data_in -> DCA_inner_fitE < 0.1/2. && data_in -> angle_diff_inner_fitE < 0.01/2. && fabs(data_in -> DCA_inner_fitYpos) < 0.1/2. && fabs(data_in -> angle_diff_inner_fitYpos) < 0.025)
0171 {
0172 double correct_center_x = accumulate( data_in -> offset_x_vec -> begin(), data_in -> offset_x_vec -> end(), 0.0 ) / double(data_in -> offset_x_vec -> size());
0173 double correct_center_y = accumulate( data_in -> offset_y_vec -> begin(), data_in -> offset_y_vec -> end(), 0.0 ) / double(data_in -> offset_y_vec -> size());
0174
0175 correct_vtx -> Fill( (data_in -> vtxX + data_in -> trial_originX)/2. - correct_center_x, (data_in -> vtxY + data_in -> trial_originY)/2. - correct_center_y);
0176
0177
0178 cout<<" "<<endl;
0179
0180 for (int ladder_i = 0; ladder_i < data_in -> offset_x_vec -> size(); ladder_i++)
0181 {
0182 gx_each -> SetPoint(gx_each -> GetN(), ladder_i + 1, data_in -> offset_x_vec -> at(ladder_i) - correct_center_x);
0183 gy_each -> SetPoint(gy_each -> GetN(), ladder_i + 1, data_in -> offset_y_vec -> at(ladder_i) - correct_center_y);
0184
0185 x_correction -> Fill(ladder_i + 1, data_in -> offset_x_vec -> at(ladder_i) - correct_center_x);
0186 y_correction -> Fill(ladder_i + 1, data_in -> offset_y_vec -> at(ladder_i) - correct_center_y);
0187
0188 gx_all -> SetPoint(gx_all -> GetN(), ladder_i + 1, data_in -> offset_x_vec -> at(ladder_i) - correct_center_x);
0189 gy_all -> SetPoint(gy_all -> GetN(), ladder_i + 1, data_in -> offset_y_vec -> at(ladder_i) - correct_center_y);
0190
0191
0192 cout<<"{"<<data_in -> offset_x_vec -> at(ladder_i)<<", "<<data_in -> offset_y_vec -> at(ladder_i)<<"}, "<<endl;
0193 }
0194
0195 cout<<" random_seed: "<<data_in -> random_seed<<" vtxX: "<<data_in -> vtxX<<" vtxY: "<<data_in -> vtxY<<" trial_originX: "<<data_in -> trial_originX<<" trial_originY: "<<data_in -> trial_originY<<endl;
0196 cout<<"corrected center "<<correct_center_x<<" "<<correct_center_y<<endl;
0197
0198 c1 -> cd(1);
0199 gx_each -> GetYaxis() -> SetRangeUser(-0.4,0.4);
0200 gx_each -> SetTitle(Form("Random seed: %i",data_in -> random_seed));
0201 gx_each -> Draw("ap");
0202 coord_line -> DrawLine(gx_each->GetXaxis()->GetXmin(),0,gx_each->GetXaxis()->GetXmax(),0);
0203 draw_text -> DrawLatex(0.2,0.8,Form("corrected center: %.3f, %.3f mm",correct_center_x, correct_center_y));
0204
0205 c1 -> cd(2);
0206 gy_each -> GetYaxis() -> SetRangeUser(-0.4,0.4);
0207 gy_each -> Draw("ap");
0208 coord_line -> DrawLine(gy_each->GetXaxis()->GetXmin(),0,gy_each->GetXaxis()->GetXmax(),0);
0209 draw_text -> DrawLatex(0.2,0.8,Form("Vertex: %.3f, %.3f mm", (data_in -> vtxX + data_in -> trial_originX)/2. - correct_center_x, (data_in -> vtxY + data_in -> trial_originY)/2. - correct_center_y));
0210
0211 c1 -> cd(3);
0212 TFile * _file0 = TFile::Open(Form("%s/%s",folder_direction.c_str(),data_in -> file_list[hist_location_map[data_in -> random_seed]].c_str()));
0213 TH2F * h2 = (TH2F *) _file0->Get(Form("DCA_distance_inner_phi_peak_final_%i",data_in -> random_seed));
0214 hist_column_content = SumTH2FColumnContent(h2);
0215 TProfile * h2_profile = h2 -> ProfileX("h2");
0216 for (int i = 0; i < h2_profile->GetNbinsX(); i++){
0217 if (hist_column_content[i] < 5){continue;}
0218 h2_profile_graph -> SetPoint(h2_profile_graph->GetN(), h2_profile->GetBinCenter(i+1), h2_profile->GetBinContent(i+1));
0219 }
0220 f2 -> SetParameter(0,0);
0221 h2_profile_graph -> Fit(f2,"NQ");
0222 h2 -> Draw("colz");
0223 f2 -> Draw("lsame");
0224 h2_profile_graph -> Draw("p same");
0225 draw_text -> DrawLatex(0.2,0.8,Form("mean: %.6f",f2->GetParameter(0)));
0226 draw_text -> DrawLatex(0.2,0.75,Form("fitE: %.6f",f2->GetParError(0)));
0227 draw_text -> DrawLatex(0.2,0.7,Form("Reduced #chi^{2}: %.6f",f2->GetChisquare()/double(f2->GetNDF())));
0228
0229
0230
0231
0232 c1 -> cd(4);
0233 TH2F * h3 = (TH2F *) _file0->Get(Form("angle_diff_inner_phi_peak_final_%i",data_in -> random_seed));
0234 hist_column_content = SumTH2FColumnContent(h3);
0235 TProfile * h3_profile = h3 -> ProfileX("h3");
0236 for (int i = 0; i < h3_profile->GetNbinsX(); i++){
0237 if (hist_column_content[i] < 5){continue;}
0238 h3_profile_graph -> SetPoint(h3_profile_graph->GetN(), h3_profile->GetBinCenter(i+1), h3_profile->GetBinContent(i+1));
0239 }
0240 f3 -> SetParameter(0,0);
0241 h3_profile_graph -> Fit(f3,"NQ");
0242 h3 -> Draw("colz");
0243 f3 -> Draw("lsame");
0244 h3_profile_graph -> Draw("p same");
0245 draw_text -> DrawLatex(0.2,0.8,Form("mean: %.6f",f3->GetParameter(0)));
0246 draw_text -> DrawLatex(0.2,0.75,Form("fitE: %.6f",f3->GetParError(0)));
0247 draw_text -> DrawLatex(0.2,0.7,Form("Reduced #chi^{2}: %.6f",f3->GetChisquare()/double(f3->GetNDF())));
0248
0249
0250
0251
0252 c1 -> cd(5);
0253 TH2F * h4 = (TH2F *) _file0->Get(Form("DCA_distance_outer_phi_peak_final_%i",data_in -> random_seed));
0254 hist_column_content = SumTH2FColumnContent(h4);
0255 TProfile * h4_profile = h4 -> ProfileX("h4");
0256 for (int i = 0; i < h4_profile->GetNbinsX(); i++){
0257 if (hist_column_content[i] < 5){continue;}
0258 h4_profile_graph -> SetPoint(h4_profile_graph->GetN(), h4_profile->GetBinCenter(i+1), h4_profile->GetBinContent(i+1));
0259 }
0260 f4 -> SetParameter(0,0);
0261 h4_profile_graph -> Fit(f4,"NQ");
0262 h4 -> Draw("colz");
0263 f4 -> Draw("lsame");
0264 h4_profile_graph -> Draw("p same");
0265 draw_text -> DrawLatex(0.2,0.8,Form("mean: %.6f",f4->GetParameter(0)));
0266 draw_text -> DrawLatex(0.2,0.75,Form("fitE: %.6f",f4->GetParError(0)));
0267 draw_text -> DrawLatex(0.2,0.7,Form("Reduced #chi^{2}: %.6f",f4->GetChisquare()/double(f4->GetNDF())));
0268
0269
0270
0271
0272 c1 -> cd(6);
0273 TH2F * h5 = (TH2F *) _file0->Get(Form("angle_diff_outer_phi_peak_final_%i",data_in -> random_seed));
0274 hist_column_content = SumTH2FColumnContent(h5);
0275 TProfile * h5_profile = h5 -> ProfileX("h5");
0276 for (int i = 0; i < h5_profile->GetNbinsX(); i++){
0277 if (hist_column_content[i] < 5){continue;}
0278 h5_profile_graph -> SetPoint(h5_profile_graph->GetN(), h5_profile->GetBinCenter(i+1), h5_profile->GetBinContent(i+1));
0279 }
0280 f5 -> SetParameter(0,0);
0281 h5_profile_graph -> Fit(f5,"NQ");
0282 h5 -> Draw("colz");
0283 f5 -> Draw("lsame");
0284 h5_profile_graph -> Draw("p same");
0285 draw_text -> DrawLatex(0.2,0.8,Form("mean: %.6f",f5->GetParameter(0)));
0286 draw_text -> DrawLatex(0.2,0.75,Form("fitE: %.6f",f5->GetParError(0)));
0287 draw_text -> DrawLatex(0.2,0.7,Form("Reduced #chi^{2}: %.6f",f5->GetChisquare()/double(f5->GetNDF())));
0288
0289 c1 -> Print(Form("%s/good_correct_set.pdf",folder_direction.c_str()));
0290
0291 h2_profile_graph -> Set(0);
0292 h3_profile_graph -> Set(0);
0293 h4_profile_graph -> Set(0);
0294 h5_profile_graph -> Set(0);
0295
0296 c1 -> Clear();
0297 c1 -> Divide(3,2);
0298 }
0299
0300
0301
0302
0303
0304
0305
0306 if (i == 0)
0307 {
0308 small_eID = i;
0309 small_random_seed = data_in -> random_seed;
0310 small_check_number = data_in -> DCA_inner_fitE + data_in -> angle_diff_inner_fitE * 10.;
0311 }
0312 else
0313 {
0314 if (data_in -> DCA_inner_fitE + data_in -> angle_diff_inner_fitE * 10. < small_check_number)
0315 {
0316 small_eID = i;
0317 small_random_seed = data_in -> random_seed;
0318 small_check_number = data_in -> DCA_inner_fitE + data_in -> angle_diff_inner_fitE * 10.;
0319 }
0320 }
0321
0322
0323 gx_each -> Set(0);
0324 gy_each -> Set(0);
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347 }
0348
0349 c1 -> Print(Form("%s/good_correct_set.pdf)",folder_direction.c_str()));
0350
0351 TCanvas * c2 = new TCanvas("c2","c2",650,600);
0352 c2 -> cd();
0353 TPad * pad_plot = new TPad(Form("pad_plot"), "", 0.0, 0.0, 1.0, 1.0);
0354 Characterize_Pad(pad_plot, 0.15, 0.1, 0.1, 0.2, 0, 0);
0355 pad_plot -> Draw();
0356
0357 pad_plot -> cd();
0358 correct_vtx -> Draw("colz");
0359 c2 -> Print(Form("%s/correct_vtx.pdf",folder_direction.c_str()));
0360
0361 pad_plot -> Clear();
0362
0363 pad_plot -> cd();
0364 x_correction -> Draw("colz");
0365 c2 -> Print(Form("%s/x_correction.pdf",folder_direction.c_str()));
0366
0367 pad_plot -> Clear();
0368
0369 pad_plot -> cd();
0370 y_correction -> Draw("colz");
0371 c2 -> Print(Form("%s/y_correction.pdf",folder_direction.c_str()));
0372
0373 pad_plot -> Clear();
0374
0375
0376
0377
0378 cout<<" "<<endl;
0379 cout<<"!!!! the best one: "<<small_check_number<<" with the random seed: "<<small_random_seed<<endl;
0380 data_in->LoadTree(small_eID);
0381 data_in->GetEntry(small_eID);
0382
0383 cout<<" random_seed: "<<data_in -> random_seed<<" vtxX: "<< data_in -> vtxX<<" vtxY: "<< data_in -> vtxY<<" trial_originX: "<< data_in -> trial_originX<<" trial_originY: "<< data_in -> trial_originY<<endl;
0384 cout<<" DCA_inner_fitYpos: "<<data_in -> DCA_inner_fitYpos <<" DCA_inner_fitE: "<<data_in -> DCA_inner_fitE <<" angle_diff_inner_fitYpos: "<< data_in -> angle_diff_inner_fitYpos <<" angle_diff_inner_fitE: "<< data_in -> angle_diff_inner_fitE <<endl;
0385 cout<<" DCA_outer_fitYpos: "<< data_in -> DCA_outer_fitYpos <<" DCA_outer_fitE: "<< data_in -> DCA_outer_fitE <<" angle_diff_outer_fitYpos: "<< data_in -> angle_diff_outer_fitYpos <<" angle_diff_outer_fitE: "<< data_in -> angle_diff_outer_fitE<<endl;
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403 }