Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:15:28

0001 #include <TCanvas.h>
0002 #include <TFile.h>
0003 #include <TH1D.h>
0004 #include <TH2D.h>
0005 #include <TPad.h>
0006 #include "sPhenixStyle.C"
0007 
0008 void drawProfile_v2()
0009 {
0010   SetsPhenixStyle();
0011   TFile *file = TFile::Open("Profile.root");
0012   if (!file || file->IsZombie())
0013   {
0014     std::cerr << "Error: Cannot open file 'Profile.root'" << std::endl;
0015     return;
0016   }
0017 
0018   const char *hist_names[] = {
0019       "nxy_hits_all_south",
0020       "nxy_hits_all_south_cut",
0021       "nxy_hits_all_north",
0022       "nxy_hits_all_north_cut"};
0023 
0024   const char *hist_names_up[] = {
0025       "nxy_hits_all_south_up",
0026       "nxy_hits_all_south_cut_up",
0027       "nxy_hits_all_north_up",
0028       "nxy_hits_all_north_cut_up"};
0029   
0030   const char *hist_names_down[] = {
0031       "nxy_hits_all_south_down",
0032       "nxy_hits_all_south_cut_down",
0033       "nxy_hits_all_north_down",
0034       "nxy_hits_all_north_cut_down"};
0035 
0036 
0037 
0038   const char *cut_name =
0039       "2.0 cm < |r| < 4.0 cm";
0040   TLatex *latex = new TLatex();
0041   latex->SetNDC();
0042   latex->SetTextSize(0.045);
0043   latex->SetTextAlign(31);
0044   
0045   TCanvas *c2[2];
0046   TCanvas *c1_south = new TCanvas("SMD_2D_South","SMD 2D Profiles South",2000,800);
0047   c1_south->Divide(2);
0048   TCanvas *c1_north = new TCanvas("SMD_2D_North","SMD 2D Profiles North",2000,800);
0049   c1_north->Divide(2);
0050   c2[0] = new TCanvas("SMD_South_2", "SMD South", 1600, 1600);
0051   c2[1] = new TCanvas("SMD_North_2", "SMD North", 1600, 1600);
0052   c2[0]->Divide(2, 2);
0053   c2[1]->Divide(2, 2);
0054   for (int i = 0; i < 4; ++i)
0055   {
0056     TH2D *hist = (TH2D *) file->Get(hist_names[i]);
0057     if (i < 2)
0058       c1_south->cd(i + 1);
0059     else
0060       c1_north->cd(i - 1);
0061     hist->Draw("COLZ");
0062     hist->SetXTitle("x [cm]");
0063     hist->SetYTitle("y [cm]");
0064     if (i % 2 == 1) latex->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{p+p}, 200 GeV #it{#bf{sPHENIX}} internal"));
0065     if (i % 2 == 1)
0066     {
0067       latex->DrawLatex(0.95 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() - 0.08, Form("%s / Run 42796+42797", c2[i / 2]->GetTitle()));
0068       latex->DrawLatex(0.95 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() - 0.75, Form("%s", cut_name));
0069     }
0070     TH2D *hist_up = (TH2D *) file->Get(hist_names_up[i]);
0071     TH2D *hist_down = (TH2D *) file->Get(hist_names_down[i]);
0072     if (!hist)
0073     {
0074       std::cerr << "Error: Cannot find histogram '" << hist_names[i] << "'" << std::endl;
0075       continue;
0076     }
0077     if (!hist_up)
0078     {
0079       std::cerr << "Error: Cannot find histogram '" << hist_names_up[i] << "'" << std::endl;
0080       continue;
0081     }
0082     if (!hist_down)
0083     {
0084       std::cerr << "Error: Cannot find histogram '" << hist_names_down[i] << "'" << std::endl;
0085       continue;
0086     }
0087     TH1D *projX = hist->ProjectionX();
0088     TH1D *projX_up = hist_up->ProjectionX();
0089     TH1D *projX_down = hist_down->ProjectionX();
0090     if (i < 2)
0091     {
0092       c2[i / 2]->cd(i * 2 + 1);
0093     }
0094     else
0095       c2[i / 2]->cd((i - 2) * 2 + 1);
0096     projX->SetTitle(Form("%s ProjectionX", hist_names[i]));
0097     double maxX = projX->GetMaximum();
0098     projX->SetMaximum(1.3 * maxX);
0099     projX->Draw("P");
0100     projX_up->Draw("SAME P");
0101     projX_up->SetLineColor(kRed);
0102     projX_down->SetLineColor(kBlue);
0103     projX_up->SetMarkerColor(kRed);
0104     projX_down->SetMarkerColor(kBlue);
0105     projX_down->Draw("SAME P");
0106     TLegend *leg_blue = new TLegend(0.2, 0.75, 0.5, 0.85);
0107     leg_blue->AddEntry(projX_up, "blue spin #uparrow", "P");
0108     leg_blue->AddEntry(projX_down, "blue spin #downarrow", "P");
0109     leg_blue->AddEntry(projX, "sum", "P");
0110     leg_blue->SetTextSize(0.04);
0111     TLegend *leg_yellow = new TLegend(0.2, 0.75, 0.5, 0.85);
0112     leg_yellow->AddEntry(projX_up, "yellow spin #uparrow", "P");
0113     leg_yellow->AddEntry(projX_down, "yellow spin #downarrow", "P");
0114     leg_yellow->AddEntry(projX, "sum", "P");
0115     leg_yellow->SetTextSize(0.04);
0116     if (i<2)
0117     {
0118       leg_yellow->Draw();
0119     }
0120     else 
0121     {
0122       leg_blue->Draw();
0123     }
0124     latex->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{p+p}, 200 GeV #it{#bf{sPHENIX}} internal"));
0125     latex->DrawLatex(0.95 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() - 0.08, Form("%s / Run 42796+42797", c2[i / 2]->GetTitle()));
0126     if (i % 2 == 1)
0127       latex->DrawLatex(0.95 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() - 0.13, Form("%s", cut_name));
0128     projX_up->GetXaxis()->SetTitle("x [cm]");
0129 
0130     TH1D *projY = hist->ProjectionY();
0131     TH1D *projY_up = hist_up->ProjectionY();
0132     TH1D *projY_down = hist_down->ProjectionY();
0133     if (i < 2)
0134     {
0135       c2[i / 2]->cd(i * 2 + 2);
0136     }
0137     else
0138       c2[i / 2]->cd((i - 2) * 2 + 2);
0139     projY->SetTitle(Form("%s ProjectionY", hist_names[i]));
0140     double maxY = projY->GetMaximum();
0141     projY->SetMaximum(1.3 * maxY);
0142     projY->Draw("P");
0143     projY_up->SetLineColor(kRed);
0144     projY_down->SetLineColor(kBlue);
0145     projY_up->SetMarkerColor(kRed);
0146     projY_down->SetMarkerColor(kBlue);
0147     projY_up->Draw("SAME P");
0148     projY_down->Draw("SAME P");
0149     if (i<2)
0150     {
0151       leg_yellow->Draw();
0152     }
0153     else 
0154     {
0155       leg_blue->Draw();
0156     }
0157     latex->DrawLatex(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, Form("#it{p+p}, 200 GeV #it{#bf{sPHENIX}} internal"));
0158     latex->DrawLatex(0.95 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() - 0.08, Form("%s / Run 42796+42797", c2[i / 2]->GetTitle()));
0159     if (i % 2 == 1)
0160       latex->DrawLatex(0.95 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() - 0.13, Form("%s", cut_name));
0161     projY_up->GetXaxis()->SetTitle("x [cm]");
0162   }
0163  
0164   c1_south->SaveAs("h2_profile_xy_south.pdf");
0165   c1_north->SaveAs("h2_profile_xy_north.pdf");
0166   c2[0]->SaveAs("h1_xyprofiles_south_all.pdf");
0167   c2[1]->SaveAs("h1_xyprofiles_north_all.pdf");
0168   file->Close();
0169 }