Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JetSpectra.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JetSpectra.C
1 #include "sPhenixStyle.h"
2 #include "sPhenixStyle.C"
3 
4 void JetSpectra()
5 {
7  TH1::SetDefaultSumw2();
8  TH2::SetDefaultSumw2();
9 
10  TChain *ct = new TChain("T");
11  ct->Add("../macro/output.root");
12 
13  vector<float> *pt = nullptr; // Declare a pointer to a vector of floats
14 
15  ct->SetBranchAddress("pt", &pt); // Assign the branch to the vector<float>*
16 
17  // Define the binning for the histogram (Replace these values with your desired bins)
18  int pt_N = 8;
19  float pt_min = 15.0;
20  float pt_max = 50.0;
21 
22  TH1F *pt_hist = new TH1F("h_MC_Reso", "", pt_N, pt_min, pt_max);
23 
24  Long64_t nEntries = ct->GetEntries();
25 
26  for (Long64_t iEntry = 0; iEntry < nEntries; ++iEntry) {
27  ct->GetEntry(iEntry);
28 
29  // Loop over the vector<float> and fill the histogram
30  for (size_t i = 0; i < pt->size(); ++i) {
31  pt_hist->Fill((*pt)[i]); // Fill the histogram with each element of the vector
32  }
33  }
34 
35  // TCanvas *canvas = new TCanvas("canvas", "Histogram Canvas", 800, 600);
36  TCanvas *canvas = new TCanvas("canvas", "canvas",10,54,700,500);
37  canvas->Range(41,-4.051882,51,0.1891844);
38  canvas->SetFillColor(0);
39  canvas->SetBorderMode(0);
40  canvas->SetBorderSize(2);
41  canvas->SetLogy();
42  canvas->SetFrameBorderMode(0);
43  canvas->SetFrameBorderMode(0);
44 
45  TPaveStats *ptstats = new TPaveStats(0.78,0.775,0.98,0.935,"brNDC");
46  ptstats->SetName("stats");
47  ptstats->SetBorderSize(1);
48  ptstats->SetFillColor(0);
49  ptstats->SetTextAlign(12);
50  ptstats->SetTextFont(42);
51  TText *ptstats_LaTex = ptstats->AddText("pt_hist");
52  ptstats_LaTex->SetTextSize(0.0368);
53  ptstats_LaTex = ptstats->AddText("Entries = 23023 ");
54  ptstats_LaTex = ptstats->AddText("Mean = 44.05");
55  ptstats_LaTex = ptstats->AddText("s_{NN}=200 GeV");
56  ptstats_LaTex = ptstats->AddText("-0.3 < #eta < 0.7");
57  ptstats->SetOptStat(1111);
58  ptstats->SetOptFit(0);
59  ptstats->Draw();
60  pt_hist->GetListOfFunctions()->Add(ptstats);
61  ptstats->SetParent(pt_hist);
62 
63  // Normalize the x-axis by dividig each bin content by its width
64  for (int biny = 1; biny <= pt_hist->GetNbinsY(); ++biny) {
65  double binContenty = pt_hist->GetBinContent(biny);
66  double binWidthy = pt_hist->GetBinWidth(biny);
67  pt_hist->SetBinContent(biny, binContenty / binWidthy);
68  }
69  // Normalize the x-axis by dividing each bin content by its width
70  for (int bin = 1; bin <= pt_hist->GetNbinsX(); ++bin) {
71  double binContent = pt_hist->GetBinContent(bin);
72  double binWidth = pt_hist->GetBinWidth(bin);
73  pt_hist->SetBinContent(bin, binContent / binWidth);
74  }
75 
76 
77  Int_t ci; // for color index setting
78  TColor *color; // for color definition with alpha
79  ci = TColor::GetColor("#000099");
80  pt_hist->SetLineColor(ci);
81  pt_hist->GetXaxis()->SetTitle("p_{T}");
82  pt_hist->GetXaxis()->SetLabelFont(42);
83  pt_hist->GetXaxis()->SetTitleOffset(1);
84  pt_hist->GetXaxis()->SetTitleFont(42);
85  pt_hist->GetYaxis()->SetTitle("N Jets (arbitrary units)");
86  pt_hist->GetYaxis()->SetLabelFont(42);
87  pt_hist->GetYaxis()->SetTitleFont(42);
88  pt_hist->GetZaxis()->SetLabelFont(42);
89  pt_hist->GetZaxis()->SetTitleOffset(1);
90  pt_hist->GetZaxis()->SetTitleFont(42);
91  pt_hist->Scale(1.0/pt_hist->Integral("width"));
92  pt_hist->Draw("");
93 
94  TPaveLabel *label = new TPaveLabel(0.2, 0.5, 0.5, 0.6, "s_{NN}=200GeV");
95  label->SetTextSize(0.04); // Adjust the label's text size
96  label->SetTextFont(42); // Set the font for the label text
97  label->SetFillColor(0);
98  label->Draw();
99 
100  TPaveText *pt_textt = new TPaveText(0.4742407,0.9366491,0.5257593,0.995,"blNDC");
101  pt_textt->SetName("title");
102  pt_textt->SetBorderSize(0);
103  pt_textt->SetFillColor(0);
104  pt_textt->SetFillStyle(0);
105 
106  pt_textt->SetTextFont(42);
107  TText *pt_LaTex = pt_textt->AddText("Jet Spectra R=0.4 [Simulation]");
108  pt_LaTex->SetTextSize(0.04); // Adjust the size of the title text
109  pt_LaTex->SetTextFont(42); // Set the font for the title
110  pt_textt->Draw();
111  canvas->Modified();
112  canvas->cd();
113  canvas->SetSelected(canvas);
114  canvas->SaveAs("JetSpectra.pdf");
115  canvas->Draw();
116 }
117