File indexing completed on 2025-08-06 08:12:38
0001 #include "sPhenixStyle.C"
0002
0003 int MakePlot()
0004 {
0005 bool isTH1D = true;
0006 std::string input_file_directory = "/sphenix/tg/tg01/commissioning/INTT/work/cwshih/sPH_dNdeta/Run24AuAuMC/Sim_Ntuple_HIJING_ana443_20241102/Run3/EvtVtxZ/completed/VtxZDist/completed";
0007 std::string input_file_name = "MC_vtxZDist_VtxZQA_merged.root";
0008 std::string target_plot_name = "h1D_INTTvtxZ_resolution_HighNClus";
0009 std::string output_directory = input_file_directory;
0010 std::string output_file_name = "h1D_INTTvtxZ_resolution_HighNClus";
0011
0012 std::string Zaxis_title = "";
0013 std::pair<std::string, std::string> axes_label = {"", ""};
0014
0015 std::string sPH_label = "Simulation";
0016 std::vector<std::tuple<double,double,std::string>> additional_text = {
0017
0018
0019 {0.22, 0.9, "Au+Au 200 GeV"},
0020 {0.22, 0.86, "HIJING"},
0021 {0.22, 0.82, "NClus > 500"},
0022
0023
0024 };
0025
0026 bool isSetLogY = false;
0027 bool isSetLogZ = false;
0028 double y_min = 0;
0029 double y_max = 8000;
0030 bool set_X_505 = true;
0031 bool DoGausFit = true;
0032
0033 system(Form("mkdir -p %s", output_directory.c_str()));
0034
0035 SetsPhenixStyle();
0036
0037 TCanvas * c1 = new TCanvas("c1", "c1", 950, 800);
0038
0039 TLatex * ltx = new TLatex();
0040 ltx->SetNDC();
0041 ltx->SetTextSize(0.045);
0042 ltx->SetTextAlign(31);
0043
0044 TLatex * draw_text = new TLatex();
0045 draw_text -> SetNDC();
0046 draw_text -> SetTextSize(0.03);
0047
0048 TLegend * leg = new TLegend(0.52,0.81,0.72,0.9);
0049
0050 leg -> SetBorderSize(0);
0051 leg -> SetTextSize(0.025);
0052 leg -> SetMargin(0.2);
0053
0054 TF1 * gaus_fit = new TF1("gaus_fit", "gaus", -30, 30);
0055 gaus_fit -> SetLineColor(kRed);
0056
0057 TFile * file_in = TFile::Open(Form("%s/%s", input_file_directory.c_str(), input_file_name.c_str()));
0058 if (!file_in){
0059 std::cout<<"Error: cannot open file: "<<input_file_name<<std::endl;
0060 return 1;
0061 }
0062
0063 TH1D * h1D_in = nullptr;
0064 TH2D * h2D_in = nullptr;
0065
0066 if (isTH1D){
0067 h1D_in = (TH1D*)file_in->Get(Form("%s",target_plot_name.c_str()));
0068 if (!h1D_in){
0069 std::cout<<"Error: cannot find histogram: "<<target_plot_name<<std::endl;
0070 return 1;
0071 }
0072 }
0073 else{
0074 h2D_in = (TH2D*)file_in->Get(Form("%s",target_plot_name.c_str()));
0075 if (!h2D_in){
0076 std::cout<<"Error: cannot find histogram: "<<target_plot_name<<std::endl;
0077 return 1;
0078 }
0079 }
0080
0081
0082
0083
0084
0085
0086
0087 if (isTH1D){
0088
0089 if (isSetLogY){
0090 h1D_in -> SetMaximum(y_max);
0091 c1 -> SetLogy(true);
0092 }
0093 else if (!isSetLogY)
0094 {
0095 h1D_in -> SetMinimum(y_min);
0096 h1D_in -> SetMaximum(y_max);
0097 }
0098
0099 if (axes_label.first.size() > 0){
0100 h1D_in -> GetXaxis() -> SetTitle(axes_label.first.c_str());
0101 }
0102 if (axes_label.second.size() > 0){
0103 h1D_in -> GetYaxis() -> SetTitle(axes_label.second.c_str());
0104 }
0105
0106 if (set_X_505) {h1D_in -> GetXaxis() -> SetNdivisions(505);}
0107
0108 if (DoGausFit){
0109 leg -> AddEntry(h1D_in, "Reco. VtxZ", "f");
0110 leg -> AddEntry(gaus_fit, "Gaus. Fit", "l");
0111
0112 gaus_fit -> SetParameters(
0113 h1D_in -> GetMaximum(),
0114 h1D_in -> GetMean(),
0115 h1D_in -> GetRMS()
0116 );
0117 double fit_range_l = h1D_in -> GetMean() - 1.3 * h1D_in -> GetRMS();
0118 double fit_range_r = h1D_in -> GetMean() + 1.3 * h1D_in -> GetRMS();
0119 h1D_in -> Fit("gaus_fit", "R", "", fit_range_l, fit_range_r);
0120 gaus_fit -> SetRange(fit_range_l, fit_range_r);
0121 }
0122
0123 }
0124 else if (!isTH1D)
0125 {
0126 if (isSetLogZ){
0127 c1 -> SetLogz(true);
0128 }
0129
0130 if (axes_label.first.size() > 0){
0131 h2D_in -> GetXaxis() -> SetTitle(axes_label.first.c_str());
0132 }
0133 if (axes_label.second.size() > 0){
0134 h2D_in -> GetYaxis() -> SetTitle(axes_label.second.c_str());
0135 }
0136 if (Zaxis_title.size() > 0){
0137 h2D_in -> GetZaxis() -> SetTitle(Zaxis_title.c_str());
0138 }
0139
0140 if (set_X_505) {h2D_in -> GetXaxis() -> SetNdivisions(505);}
0141 }
0142
0143
0144 c1 -> cd();
0145
0146 gStyle->SetPaintTextFormat("1.3f");
0147
0148
0149
0150
0151
0152 if (isTH1D){
0153 h1D_in -> SetMarkerSize(0.8);
0154
0155 h1D_in -> Draw("hist");
0156
0157 if (DoGausFit){
0158 gaus_fit -> Draw("same");
0159 leg -> Draw("same");
0160 }
0161 }
0162 else {
0163
0164
0165
0166 h2D_in -> Draw("colz0");
0167 }
0168
0169
0170 ltx->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{#bf{sPHENIX}} %s", sPH_label.c_str()));
0171
0172 for (auto text : additional_text){
0173 double x = std::get<0>(text);
0174 double y = std::get<1>(text);
0175 std::string text_str = std::get<2>(text);
0176
0177 draw_text -> DrawLatex(x, y, text_str.c_str());
0178 }
0179
0180 if (DoGausFit)
0181 {
0182 draw_text -> DrawLatex(
0183 std::get<0>(additional_text[0]),
0184 std::get<1>(additional_text.back()) - 0.08,
0185 Form("Mean_{Gaus. Fit} = %.3f", gaus_fit -> GetParameter(1))
0186 );
0187
0188 draw_text -> DrawLatex(
0189 std::get<0>(additional_text[0]),
0190 std::get<1>(additional_text.back()) - 0.12,
0191 Form("#sigma_{Gaus. Fit} = %.3f", gaus_fit -> GetParameter(2))
0192 );
0193 }
0194
0195 c1 -> Print(Form("%s/%s.pdf", output_directory.c_str(), output_file_name.c_str()));
0196 c1 -> Clear();
0197
0198 return 0;
0199 }