File indexing completed on 2025-08-09 08:12:11
0001 #include <iostream>
0002 #include <fstream>
0003 #include <filesystem>
0004 #include <cstdlib>
0005 #include <numeric>
0006 using namespace std;
0007
0008 #include "sPhenixStyle.C"
0009
0010 vector<string> read_list(string folder_direction, string MC_list_name)
0011 {
0012 vector<string> file_list;
0013 string list_buffer;
0014 ifstream data_list;
0015 data_list.open((folder_direction + "/" + MC_list_name).c_str());
0016
0017 file_list.clear();
0018
0019 while (1)
0020 {
0021 data_list >> list_buffer;
0022 if (!data_list.good())
0023 {
0024 break;
0025 }
0026 file_list.push_back(list_buffer);
0027 }
0028 cout<<"size in the" <<MC_list_name<<": "<<file_list.size()<<endl;
0029
0030 return file_list;
0031 }
0032
0033
0034 int FromTracklet()
0035 {
0036
0037 std::string input_directory = "/sphenix/user/ChengWei/sPH_dNdeta/Run24AuAuMC/Sim_HIJING_MDC2_ana472_20250307/GeoOffset/completed";
0038 std::string input_foldername_NoIndex = "Run_00";
0039 std::string filename_NoIndex = "MC_TrackHist_VtxZQA_ClusQAAdc35PhiSize40_ColMulMask_GeoOffset_test1";
0040
0041 std::string ideal_directory = "/sphenix/user/ChengWei/sPH_dNdeta/Run24AuAuMC/Sim_HIJING_MDC2_ana472_20250307/GeoOffset/completed/Run_NoGeoOffset_00000/MC_TrackHist_VtxZQA_ClusQAAdc35PhiSize40_ColMulMask_test1_00000.root";
0042
0043 std::string label_text = "Simulation";
0044
0045
0046
0047 input_foldername_NoIndex = (input_foldername_NoIndex.back() == '_') ? input_foldername_NoIndex.substr(0, input_foldername_NoIndex.size() - 1) : input_foldername_NoIndex;
0048 filename_NoIndex = (filename_NoIndex.back() == '_') ? filename_NoIndex.substr(0, filename_NoIndex.size() - 1) : filename_NoIndex;
0049
0050 std::string file_list_name = "file_list_Tracklet.txt";
0051 std::string output_directory = input_directory + "/" + "merged_result";
0052
0053
0054
0055
0056 if(std::filesystem::exists(Form("%s",output_directory.c_str())) == false){
0057 system(Form("mkdir -p %s", output_directory.c_str()));
0058 cout<<"----------- check folder exists -----------"<<endl;
0059 system(Form("ls %s", output_directory.c_str()));
0060 }
0061 else
0062 {
0063 cout<<"----------- folder exists already -----------"<<endl;
0064 system(Form("ls %s", output_directory.c_str()));
0065 }
0066
0067
0068
0069 if(true){
0070 system(Form("ls %s/%s*/%s_*.root > %s/%s", input_directory.c_str(), input_foldername_NoIndex.c_str(), filename_NoIndex.c_str(), input_directory.c_str(), file_list_name.c_str()));
0071 cout<<"----------- file list generated -----------"<<endl;
0072 system(Form("cat %s/%s", input_directory.c_str(), file_list_name.c_str()));
0073 cout<<"----------- file list generated -----------"<<endl;
0074 }
0075 else
0076 {
0077 cout<<"----------- found the file list -----------"<<endl;
0078 system(Form("cat %s/%s", input_directory.c_str(), file_list_name.c_str()));
0079 cout<<"----------- found the file list -----------"<<endl;
0080 }
0081
0082 vector<string> file_list = read_list(input_directory, file_list_name);
0083
0084
0085
0086 SetsPhenixStyle();
0087 TCanvas * c1 = new TCanvas("c1","c1", 950, 800);
0088
0089 TLatex * ltx = new TLatex();
0090 ltx->SetNDC();
0091 ltx->SetTextSize(0.045);
0092 ltx->SetTextAlign(31);
0093
0094 TFile * file_in_ideal = TFile::Open(Form("%s", ideal_directory.c_str()));
0095 TH1D * h1D_INTTvtxZ_ideal = (TH1D*) file_in_ideal -> Get("h1D_INTTvtxZ");
0096 h1D_INTTvtxZ_ideal -> SetLineColor(2);
0097 h1D_INTTvtxZ_ideal -> SetLineWidth(1);
0098 h1D_INTTvtxZ_ideal -> Scale(1./h1D_INTTvtxZ_ideal->Integral());
0099
0100 TH1D * h1D_DeltaPhi_ideal = (TH1D*) file_in_ideal -> Get("h1D_PairDeltaPhi_inclusive");
0101 h1D_DeltaPhi_ideal -> SetLineColor(2);
0102 h1D_DeltaPhi_ideal -> SetLineWidth(1);
0103 h1D_DeltaPhi_ideal -> Scale(1./h1D_DeltaPhi_ideal->Integral());
0104
0105 TH1D * h1D_DeltaEta_ideal = (TH1D*) file_in_ideal -> Get("h1D_PairDeltaEta_inclusive");
0106 h1D_DeltaEta_ideal -> SetLineColor(2);
0107 h1D_DeltaEta_ideal -> SetLineWidth(1);
0108 h1D_DeltaEta_ideal -> Scale(1./h1D_DeltaEta_ideal->Integral());
0109
0110 TH1D * h1D_Inner_ClusEtaInttZ_ideal = (TH1D*) file_in_ideal -> Get("h1D_Inner_ClusEta_INTTz");
0111 h1D_Inner_ClusEtaInttZ_ideal -> SetLineColor(2);
0112 h1D_Inner_ClusEtaInttZ_ideal -> SetLineWidth(1);
0113 h1D_Inner_ClusEtaInttZ_ideal -> Scale(1./h1D_Inner_ClusEtaInttZ_ideal->Integral());
0114
0115 TH1D * h1D_Outer_ClusEtaInttZ_ideal = (TH1D*) file_in_ideal -> Get("h1D_Outer_ClusEta_INTTz");
0116 h1D_Outer_ClusEtaInttZ_ideal -> SetLineColor(2);
0117 h1D_Outer_ClusEtaInttZ_ideal -> SetLineWidth(1);
0118 h1D_Outer_ClusEtaInttZ_ideal -> Scale(1./h1D_Outer_ClusEtaInttZ_ideal->Integral());
0119
0120
0121
0122 TH2D * h2D_INTTvtxZ;
0123
0124 TH2D * h2D_DeltaPhi;
0125 TH2D * h2D_DeltaEta;
0126
0127 TH2D * h2D_Inner_ClusEtaInttZ;
0128 TH2D * h2D_Outer_ClusEtaInttZ;
0129
0130
0131
0132
0133 TFile * file_in;
0134
0135 TH1D * h1D_INTTvtxZ_each;
0136
0137 TH1D * h1D_DeltaPhi_each;
0138 TH1D * h1D_DeltaEta_each;
0139
0140 TH1D * h1D_Inner_ClusEtaInttZ_each;
0141 TH1D * h1D_Outer_ClusEtaInttZ_each;
0142
0143 for (int i = 0; i < file_list.size(); i++)
0144 {
0145 file_in = TFile::Open(Form("%s", file_list[i].c_str()));
0146
0147 h1D_INTTvtxZ_each = (TH1D*) file_in -> Get("h1D_INTTvtxZ");
0148
0149 h1D_DeltaPhi_each = (TH1D*) file_in -> Get("h1D_PairDeltaPhi_inclusive");
0150 h1D_DeltaEta_each = (TH1D*) file_in -> Get("h1D_PairDeltaEta_inclusive");
0151
0152 h1D_Inner_ClusEtaInttZ_each = (TH1D*) file_in -> Get("h1D_Inner_ClusEta_INTTz");
0153 h1D_Outer_ClusEtaInttZ_each = (TH1D*) file_in -> Get("h1D_Outer_ClusEta_INTTz");
0154
0155 h1D_INTTvtxZ_each->Scale( 1. / h1D_INTTvtxZ_each -> Integral() );
0156 h1D_DeltaPhi_each->Scale( 1. / h1D_DeltaPhi_each -> Integral() );
0157 h1D_DeltaEta_each->Scale( 1. / h1D_DeltaEta_each -> Integral() );
0158 h1D_Inner_ClusEtaInttZ_each->Scale( 1. / h1D_Inner_ClusEtaInttZ_each -> Integral() );
0159 h1D_Outer_ClusEtaInttZ_each->Scale( 1. / h1D_Outer_ClusEtaInttZ_each -> Integral() );
0160
0161 if (i == 0)
0162 {
0163
0164
0165 h2D_INTTvtxZ = new TH2D(
0166 "h2D_INTTvtxZ",
0167 "h2D_INTTvtxZ;INTT vtx Z [cm];Entries",
0168 h1D_INTTvtxZ_each -> GetNbinsX(), h1D_INTTvtxZ_each -> GetXaxis() -> GetXmin(), h1D_INTTvtxZ_each -> GetXaxis() -> GetXmax(),
0169 200, h1D_INTTvtxZ_each -> GetMinimum(), h1D_INTTvtxZ_each -> GetBinContent(h1D_INTTvtxZ_each -> GetMaximumBin()) * 1.2
0170 );
0171
0172 h2D_DeltaPhi = new TH2D(
0173 "h2D_DeltaPhi",
0174 "h2D_DeltaPhi;Pair #Delta#phi;Entries",
0175 h1D_DeltaPhi_each -> GetNbinsX(), h1D_DeltaPhi_each -> GetXaxis() -> GetXmin(), h1D_DeltaPhi_each -> GetXaxis() -> GetXmax(),
0176 200, h1D_DeltaPhi_each -> GetMinimum(), h1D_DeltaPhi_each -> GetBinContent(h1D_DeltaPhi_each -> GetMaximumBin()) * 1.8
0177 );
0178
0179 h2D_DeltaEta = new TH2D(
0180 "h2D_DeltaEta",
0181 "h2D_DeltaEta;Pair #Delta#eta;Entries",
0182 h1D_DeltaEta_each -> GetNbinsX(), h1D_DeltaEta_each -> GetXaxis() -> GetXmin(), h1D_DeltaEta_each -> GetXaxis() -> GetXmax(),
0183 200, h1D_DeltaEta_each -> GetMinimum(), h1D_DeltaEta_each -> GetBinContent(h1D_DeltaEta_each -> GetMaximumBin()) * 1.2
0184 );
0185
0186 h2D_Inner_ClusEtaInttZ = new TH2D(
0187 "h2D_Inner_ClusEtaInttZ",
0188 "h2D_Inner_ClusEtaInttZ;Cluster #eta (Inner, INTTz);Entries",
0189 h1D_Inner_ClusEtaInttZ_each -> GetNbinsX(), h1D_Inner_ClusEtaInttZ_each -> GetXaxis() -> GetXmin(), h1D_Inner_ClusEtaInttZ_each -> GetXaxis() -> GetXmax(),
0190 200, h1D_Inner_ClusEtaInttZ_each -> GetMinimum(), h1D_Inner_ClusEtaInttZ_each -> GetBinContent(h1D_Inner_ClusEtaInttZ_each -> GetMaximumBin()) * 1.2
0191 );
0192
0193 h2D_Outer_ClusEtaInttZ = new TH2D(
0194 "h2D_Outer_ClusEtaInttZ",
0195 "h2D_Outer_ClusEtaInttZ;Cluster #eta (Outer, INTTz);Entries",
0196 h1D_Outer_ClusEtaInttZ_each -> GetNbinsX(), h1D_Outer_ClusEtaInttZ_each -> GetXaxis() -> GetXmin(), h1D_Outer_ClusEtaInttZ_each -> GetXaxis() -> GetXmax(),
0197 200, h1D_Outer_ClusEtaInttZ_each -> GetMinimum(), h1D_Outer_ClusEtaInttZ_each -> GetBinContent(h1D_Outer_ClusEtaInttZ_each -> GetMaximumBin()) * 1.2
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 for (int bin_i = 1; bin_i <= h1D_INTTvtxZ_each->GetNbinsX(); bin_i++)
0238 {
0239 h2D_INTTvtxZ -> Fill(h1D_INTTvtxZ_each->GetBinCenter(bin_i), h1D_INTTvtxZ_each->GetBinContent(bin_i));
0240 }
0241
0242 for (int bin_i = 1; bin_i <= h1D_DeltaPhi_each->GetNbinsX(); bin_i++)
0243 {
0244 h2D_DeltaPhi -> Fill(h1D_DeltaPhi_each->GetBinCenter(bin_i), h1D_DeltaPhi_each->GetBinContent(bin_i));
0245 }
0246
0247 for (int bin_i = 1; bin_i <= h1D_DeltaEta_each->GetNbinsX(); bin_i++)
0248 {
0249 h2D_DeltaEta -> Fill(h1D_DeltaEta_each->GetBinCenter(bin_i), h1D_DeltaEta_each->GetBinContent(bin_i));
0250 }
0251
0252 for (int bin_i = 1; bin_i <= h1D_Inner_ClusEtaInttZ_each->GetNbinsX(); bin_i++)
0253 {
0254 h2D_Inner_ClusEtaInttZ -> Fill(h1D_Inner_ClusEtaInttZ_each->GetBinCenter(bin_i), h1D_Inner_ClusEtaInttZ_each->GetBinContent(bin_i));
0255 }
0256
0257 for (int bin_i = 1; bin_i <= h1D_Outer_ClusEtaInttZ_each->GetNbinsX(); bin_i++)
0258 {
0259 h2D_Outer_ClusEtaInttZ -> Fill(h1D_Outer_ClusEtaInttZ_each->GetBinCenter(bin_i), h1D_Outer_ClusEtaInttZ_each->GetBinContent(bin_i));
0260 }
0261
0262
0263 }
0264
0265 TFile * file_out = new TFile(Form("%s/FromTrack.root", output_directory.c_str()), "RECREATE");
0266 h2D_INTTvtxZ -> Write();
0267 h2D_DeltaPhi -> Write();
0268 h2D_DeltaEta -> Write();
0269 h2D_Inner_ClusEtaInttZ -> Write();
0270 h2D_Outer_ClusEtaInttZ -> Write();
0271
0272
0273 c1 -> cd();
0274 h2D_INTTvtxZ -> Draw("colz0");
0275 h1D_INTTvtxZ_ideal -> Draw("hist same");
0276 c1 -> Write("c1_h2D_INTTvtxZ");
0277 c1 -> Clear();
0278
0279 c1 -> cd();
0280 h2D_DeltaPhi -> Draw("colz0");
0281 h1D_DeltaPhi_ideal -> Draw("hist same");
0282 c1 -> Write("c1_h2D_DeltaPhi");
0283 c1 -> Clear();
0284
0285 c1 -> cd();
0286 h2D_DeltaEta -> Draw("colz0");
0287 h1D_DeltaEta_ideal -> Draw("hist same");
0288 c1 -> Write("c1_h2D_DeltaEta");
0289 c1 -> Clear();
0290
0291 c1 -> cd();
0292 h2D_Inner_ClusEtaInttZ -> Draw("colz0");
0293 h1D_Inner_ClusEtaInttZ_ideal -> Draw("hist same");
0294 c1 -> Write("c1_h2D_Inner_ClusEtaInttZ");
0295 c1 -> Clear();
0296
0297 c1 -> cd();
0298 h2D_Outer_ClusEtaInttZ -> Draw("colz0");
0299 h1D_Outer_ClusEtaInttZ_ideal -> Draw("hist same");
0300 c1 -> Write("c1_h2D_Outer_ClusEtaInttZ");
0301 c1 -> Clear();
0302
0303 file_out -> Close();
0304
0305
0306 c1 -> cd();
0307 h2D_INTTvtxZ -> Draw("colz0");
0308 h1D_INTTvtxZ_ideal -> Draw("hist same");
0309 ltx->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{#bf{sPHENIX}} %s", label_text.c_str()));
0310 c1 -> Print(Form("%s/c1_h2D_INTTvtxZ.pdf", output_directory.c_str()));
0311 c1 -> Clear();
0312
0313 c1 -> cd();
0314 h2D_DeltaPhi -> Draw("colz0");
0315 h1D_DeltaPhi_ideal -> Draw("hist same");
0316 ltx->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{#bf{sPHENIX}} %s", label_text.c_str()));
0317 c1 -> Print(Form("%s/c1_h2D_DeltaPhi.pdf", output_directory.c_str()));
0318 c1 -> Clear();
0319
0320 c1 -> cd();
0321 h2D_DeltaEta -> Draw("colz0");
0322 h1D_DeltaEta_ideal -> Draw("hist same");
0323 ltx->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{#bf{sPHENIX}} %s", label_text.c_str()));
0324 c1 -> Print(Form("%s/c1_h2D_DeltaEta.pdf", output_directory.c_str()));
0325 c1 -> Clear();
0326
0327 c1 -> cd();
0328 h2D_Inner_ClusEtaInttZ -> Draw("colz0");
0329 h1D_Inner_ClusEtaInttZ_ideal -> Draw("hist same");
0330 ltx->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{#bf{sPHENIX}} %s", label_text.c_str()));
0331 c1 -> Print(Form("%s/c1_h2D_Inner_ClusEtaInttZ.pdf", output_directory.c_str()));
0332 c1 -> Clear();
0333
0334 c1 -> cd();
0335 h2D_Outer_ClusEtaInttZ -> Draw("colz0");
0336 h1D_Outer_ClusEtaInttZ_ideal -> Draw("hist same");
0337 ltx->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{#bf{sPHENIX}} %s", label_text.c_str()));
0338 c1 -> Print(Form("%s/c1_h2D_Outer_ClusEtaInttZ.pdf", output_directory.c_str()));
0339 c1 -> Clear();
0340
0341 return 0;
0342 }