Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:12:39

0001 #include "sPhenixStyle.C"
0002 #include "../Constants.cpp"
0003 
0004 int MakePlot_THStack1D()
0005 {
0006 
0007     int Mbin = 0;
0008     bool isPhiRotated = true;
0009 
0010     std::string input_file_directory = Form("/sphenix/tg/tg01/commissioning/INTT/work/cwshih/seflgendata/run_54280_HR_Feb102025/Run6_EvtZFitWidthChange/EvtVtxZ/FinalResult_10cm_Pol2BkgFit/completed/vtxZ_-10_10cm_MBin%d/Folder_BaseLine/Run_0/completed", Mbin); 
0011     std::string input_file_name = Form("Data_PreparedNdEtaEach_AlphaCorr_AllSensor_VtxZ10_Mbin%d_00054280_00000_DeltaPhi.root", Mbin);
0012     std::string output_directory = input_file_directory;
0013     
0014     std::string target_plot_name = (isPhiRotated) ? "hstack1D_DeltaPhi_Eta13_rotated" : "hstack1D_DeltaPhi_Eta13";
0015 
0016     double y_max = 2 * pow(10,6);
0017 
0018     std::string sPH_label = "Internal";
0019     
0020     std::pair<std::string, std::string> axes_label = {"", "Entries (/0.001)"};
0021     string rotate_string = (isPhiRotated) ? "Inner clusters rotated by #pi in #phi angle" : "";
0022     std::vector<std::tuple<double,double,std::string>> additional_text = {
0023         // {0.2, 0.9, "The cluster pairs post the VtxZ linking requirement are filled"},
0024 
0025         // {0.22, 0.9, "Au+Au 200 GeV"},
0026         // {0.22, 0.86, "HIJING"},
0027         // {0.22, 0.82, "Centrality 0-70%"},
0028         // {0.22, 0.78, "|INTT vtxZ| #leq 10 cm"}
0029 
0030         {0.22, 0.90, Form("%s", rotate_string.c_str())},
0031         {0.22, 0.86, "#eta: [-0.1 - 0.1]"},
0032         {0.22, 0.82, Form("Centrality interval: [%s]%%", Constants::centrality_text[Mbin].c_str())},
0033         {0.22, 0.78, "|INTT vtxZ| #leq 10 cm"}
0034 
0035     };
0036 
0037     bool isSetLogY = false;
0038     bool isSetLogZ = false;
0039     double y_min = 0;
0040     bool set_X_505 = true;
0041 
0042     system(Form("mkdir -p %s", output_directory.c_str()));
0043     
0044     SetsPhenixStyle();
0045 
0046     TCanvas * c1 = new TCanvas("c1", "c1", 950, 800);
0047 
0048     TLatex * ltx = new TLatex();
0049     ltx->SetNDC();
0050     ltx->SetTextSize(0.045);
0051     ltx->SetTextAlign(31);
0052 
0053     TLatex * draw_text = new TLatex();
0054     draw_text -> SetNDC();
0055     draw_text -> SetTextSize(0.03);
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     THStack * hstack1D_in = nullptr;
0064     hstack1D_in = (THStack*)file_in->Get(Form("%s",target_plot_name.c_str()));
0065     if (!hstack1D_in){
0066         std::cout<<"Error: cannot find histogram: "<<target_plot_name<<std::endl;
0067         return 1;
0068     }
0069 
0070     TList* histList = hstack1D_in->GetHists(); // Retrieve the list of histograms in the stack
0071     if (histList) {
0072         for (auto* obj : *histList) {
0073             TH1D* hist = dynamic_cast<TH1D*>(obj); // Cast to TH1D
0074             if (hist) {
0075                 hist->SetLineWidth(1); // Set line width to 0
0076             }
0077         }
0078     }
0079 
0080     auto temp_h1D = (TH1D*)((TH1D*)hstack1D_in -> GetStack()->Last())->Clone("temp_h1D");
0081     temp_h1D -> Reset("ICESM");
0082 
0083     if (isSetLogY){ // note : logy
0084         temp_h1D -> SetMaximum(y_max);
0085         c1 -> SetLogy(true);
0086     }
0087     else if (!isSetLogY) // note : linear y
0088     {
0089         temp_h1D -> SetMinimum(y_min);
0090         temp_h1D -> SetMaximum(y_max);
0091     }
0092 
0093     if (axes_label.first.size() > 0){
0094         temp_h1D -> GetXaxis() -> SetTitle(axes_label.first.c_str());
0095     }
0096     if (axes_label.second.size() > 0){
0097         temp_h1D -> GetYaxis() -> SetTitle(axes_label.second.c_str());
0098     }
0099 
0100     if (set_X_505) {temp_h1D -> GetXaxis() -> SetNdivisions(505);}
0101 
0102 
0103     // todo : the drawing 
0104     c1 -> cd();
0105 
0106     gStyle->SetPaintTextFormat("1.3f");
0107 
0108     // hist_in -> SetMarkerSize(0.5);
0109     // hist_in -> Draw("hist TEXT90");
0110 
0111     // hstack1D_in -> SetMarkerSize(0.8);
0112     // hstack1D_in -> Draw("hist TEXT90 E");
0113     temp_h1D -> Draw("hist");
0114     hstack1D_in -> Draw("same");
0115 
0116     ltx->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{#bf{sPHENIX}} %s", sPH_label.c_str())); 
0117 
0118     for (auto text : additional_text){
0119         double x = std::get<0>(text);
0120         double y = std::get<1>(text);
0121         std::string text_str = std::get<2>(text);
0122 
0123         draw_text -> DrawLatex(x, y, text_str.c_str());
0124     }
0125 
0126     c1 -> Print(Form("%s/%s.pdf", output_directory.c_str(), target_plot_name.c_str()));
0127     c1 -> Clear();
0128 
0129     return 0;
0130 }