Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:13:19

0001 #include "sPhenixStyle.h"
0002 #include "sPhenixStyle.C"
0003 #include "utilities.h"
0004 
0005 void JetSpectra()
0006 {
0007   SetsPhenixStyle();
0008   TH1::SetDefaultSumw2();
0009   TH2::SetDefaultSumw2();
0010 
0011   TChain *ct = new TChain("T");
0012   ct->Add("../macro/output_sim1cutSUB.root");
0013 
0014   vector<float> *pt = nullptr; // Declare a pointer to a vector of floats
0015 
0016   ct->SetBranchAddress("pt", &pt); // Assign the branch to the vector<float>*
0017 
0018   // Define the binning for the histogram (Replace these values with your desired bins)
0019   int pt_N = 8;
0020   float pt_min = 10.0;
0021   float pt_max = 50.0;
0022 
0023   TH1F *pt_hist = new TH1F("h_MC_Reso", "", pt_N, pt_min, pt_max);
0024 
0025   Long64_t nEntries = ct->GetEntries();
0026 
0027   for (Long64_t iEntry = 0; iEntry < nEntries; ++iEntry) {
0028     ct->GetEntry(iEntry);
0029 
0030     // Loop over the vector<float> and fill the histogram
0031     for (size_t i = 0; i < pt->size(); ++i) {
0032       pt_hist->Fill((*pt)[i]); // Fill the histogram with each element of the vector
0033     }
0034   }
0035 
0036   // TCanvas *canvas = new TCanvas("canvas", "Histogram Canvas", 800, 600);
0037   TCanvas *canvas = new TCanvas("canvas", "canvas",10,54,700,500);
0038   canvas->Range(41,-4.051882,51,0.1891844);
0039   canvas->SetFillColor(0);
0040   canvas->SetBorderMode(0);
0041   canvas->SetBorderSize(2);
0042   canvas->SetLogy();
0043   canvas->SetFrameBorderMode(0);
0044   canvas->SetFrameBorderMode(0);
0045   /*
0046   TPaveStats *ptstats = new TPaveStats(0.78,0.775,0.98,0.935,"brNDC");
0047   ptstats->SetName("stats");
0048   ptstats->SetBorderSize(1);
0049   ptstats->SetFillColor(0);
0050   ptstats->SetTextAlign(12);
0051   ptstats->SetTextFont(42);
0052   ptstats->SetOptStat(1111);
0053   ptstats->SetOptFit(0);
0054   ptstats->Draw();
0055   pt_hist->GetListOfFunctions()->Add(ptstats);
0056   ptstats->SetParent(pt_hist);
0057   */
0058   
0059   for (int bin = 0; bin <= pt_hist->GetNbinsX(); ++bin) {
0060     double binContent = pt_hist->GetBinContent(bin);
0061     double binWidth = pt_hist->GetBinWidth(bin);
0062     double binErrorLow = pt_hist->GetBinErrorLow(bin);
0063     double binErrorUp = pt_hist->GetBinErrorUp(bin);
0064     pt_hist->SetBinContent(bin, binContent / binWidth);
0065     cout << "Bin " << bin << ": Content = " << binContent << ", Width = " << binWidth << ", Low Bin Error:" << binErrorLow << ", Upper Bin Error" << binErrorUp << endl;
0066 
0067     for (int i = 1; i <= pt_hist->GetNbinsX(); ++i) {
0068       if (pt_hist->GetBinContent(i) == 0) {
0069         pt_hist->SetBinContent(i, 0.0); // Set a small non-zero value
0070       }
0071     }
0072 
0073     //    cout << "Bin " << bin << ": Content = " << binContent << ", Width = " << binWidth << endl;
0074   }
0075   for (int binj = 0; binj <= pt_hist->GetNbinsY(); ++binj) {
0076     double binContentj = pt_hist->GetBinContent(binj);
0077     double binWidthj = pt_hist->GetBinWidth(binj);
0078     double binErrorLowj = pt_hist->GetBinErrorLow(binj);
0079     double binErrorUpj = pt_hist->GetBinErrorUp(binj);
0080 
0081     // pt_hist->SetBinContent(bin, binContent / binWidth);
0082     cout << "Bin " << binj << ": Content = " << binContentj << ", Width = " << binWidthj << ", Low Bin Error:" << binErrorLowj << ", Upper Bin Error" << binErrorUpj << endl;
0083   }
0084 
0085   Int_t ci;      // for color index setting                                                                                                                                  
0086   TColor *color; // for color definition with alpha                                                                                                                          
0087   ci = TColor::GetColor("#000099");
0088   pt_hist->SetLineColor(ci);
0089   pt_hist->GetXaxis()->SetTitle("p_{T}");
0090   pt_hist->GetXaxis()->SetLabelFont(42);
0091   pt_hist->GetXaxis()->SetTitleOffset(1);
0092   pt_hist->GetXaxis()->SetTitleFont(42);
0093   pt_hist->GetYaxis()->SetTitle("N Jets (arbitrary units)");
0094   pt_hist->GetYaxis()->SetLabelFont(42);
0095   pt_hist->GetYaxis()->SetTitleFont(42);
0096   pt_hist->GetZaxis()->SetLabelFont(42);
0097   pt_hist->GetZaxis()->SetTitleOffset(1);
0098   pt_hist->GetZaxis()->SetTitleFont(42);
0099   //  pt_hist->SetMinimum(-0.01);
0100   pt_hist->SetAxisRange(-0.5, 0.1, "Y");
0101   pt_hist->Scale(1.0/pt_hist->Integral("width"));
0102   pt_hist->Draw("E0");
0103 
0104   TPaveLabel *label = new TPaveLabel(0.2, 0.5, 0.5, 0.6, "s_{NN}=200GeV");
0105   label->SetTextSize(0.04); // Adjust the label's text size                                                                                                                  
0106   label->SetTextFont(42);   // Set the font for the label text                                                                                                               
0107   label->SetFillColor(0);
0108   label->Draw();
0109 
0110   TPaveText *pt_textt = new TPaveText(0.4742407,0.9366491,0.5257593,0.995,"blNDC");
0111   pt_textt->SetName("title");
0112   pt_textt->SetBorderSize(0);
0113   pt_textt->SetFillColor(0);
0114   pt_textt->SetFillStyle(0);
0115 
0116   pt_textt->SetTextFont(42);
0117   TText *pt_LaTex = pt_textt->AddText("Jet Spectra R=0.4 [Simulation]");
0118   pt_LaTex->SetTextSize(0.04); // Adjust the size of the title text                                                                                                          
0119   pt_LaTex->SetTextFont(42); // Set the font for the title                                                                                                                   
0120   pt_textt->Draw();
0121 
0122   drawText("Au+Au #sqrt{s} = 200 GeV Pythia+HIJING", 0.6, 0.87, 14);
0123   drawText("anti-k_{T} R_{jet}=0.4, |#eta_{jet}| < 0.6", 0.6, 0.84, 14);
0124   // drawText("R_{sj}=0.1", 0.25, 0.81, 14);
0125   // drawText("10 < p_{T} < 20 [GeV/c]", 0.25, 0.775, 14);
0126   drawText("#it{#bf{sPHENIX}} Internal", 0.6, 0.805, 14);
0127 
0128   canvas->Modified();
0129   canvas->cd();
0130   canvas->SetSelected(canvas);
0131   canvas->SaveAs("JetSpectra_sim1SUB.pdf");
0132   canvas->Draw();
0133 }
0134