Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Plot-Hits_vs_Eta.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Plot-Hits_vs_Eta.C
1 #include <iostream>
2 #include <cstdlib>
3 #include <memory>
4 #include <string>
5 #include <cstring>
6 #include <vector>
7 #include <set>
8 #include <cmath>
9 #include <utility>
10 #include <cassert>
11 
12 #include "TFile.h"
13 #include "TTree.h"
14 #include "TCanvas.h"
15 #include "TLegend.h"
16 #include "TROOT.h"
17 #include "TH1F.h"
18 #include "TColor.h"
19 #include "TImage.h"
20 #include "TApplication.h"
21 #include "TGraphErrors.h"
22 #include "/sphenix/user/gregtom3/SBU/research/macros/macros/sPHENIXStyle/sPhenixStyle.C"
23 
24 #define STR(X) #X
25 #define XSTR(X) STR(X)
26 #define NELEMS(a) (sizeof(a)/sizeof(a[0]))
27 
28 
29 TTree *load_tree(const char *const file_name, const char *const tree_name);
30 const char *const hitcount_file_path
31  {"/sphenix/user/gregtom3/data/Summer2018/SVTX_studies/hits-per-eta/hitcount.root"};
32 
33 const char *const hit_containers[] {"G4HIT_EGEM_0", "G4HIT_EGEM_1", "G4HIT_EGEM_3",
34  "G4HIT_FGEM_0", "G4HIT_FGEM_1", "G4HIT_FGEM_2", "G4HIT_FGEM_3","G4HIT_FGEM_4", "G4HIT_MAPS",
35  "G4HIT_SVTX"};
36 const static Color_t plot_colors[] = { kBlue, kSpring, kBlack, kYellow, kCyan, kGray, kMagenta, kOrange,
37  kRed, kGreen + 3, kPink};
38 
39 
43  gROOT->SetBatch(true);
44 
45  TCanvas *const c {new TCanvas {"hits", "Hits", gStyle->GetCanvasDefW(), gStyle->GetCanvasDefH()}};
46  TLegend *const l {new TLegend {0.7, 0.9, 0.95, 0.61, "Detector"}};
47  l->SetTextSize(0.03);
48  Double_t max {0};
49  std::vector<TH1F*> hists {};
50  for (size_t i {0}; i < NELEMS(hit_containers); ++i) {
51  const std::string tree_name {std::string(hit_containers[i]) + "_normalized"};
52  TTree *const hits {load_tree(hitcount_file_path, tree_name.c_str())};
53 
54 
55  Double_t eta, hit_count;
56  hits->SetBranchAddress("eta", &eta);
57  hits->SetBranchAddress("hit_count", &hit_count);
58 
59  Long64_t nentries {hits->GetEntries()};
60  TH1F *const h {new TH1F {hit_containers[i], "Hit Count", 100, -4.5, 4.5}};
61  h->SetXTitle("#eta");
62  h->SetYTitle("Normalized Hit Count");
63  h->SetLineColor(plot_colors[i]);
64  for (Long64_t j {0}; j < nentries; ++j) {
65  if (hits->LoadTree(j) < 0)
66  break;
67  hits->GetEntry(j);
68  if (strcmp("G4HIT_SVTX", hit_containers[i]) == 0)
69  hit_count /= 10;
70 
71  h->Fill(eta, hit_count);
72  }
73 
74  const Long64_t nbins {h->GetSize() - 2}; /* -2 for underflow and overflow */
75  for (Long64_t j {0}; j < nbins; ++j) {
76  const Double_t hit_count {h->GetBinContent(j + 1)};
77  max = (hit_count > max) ? hit_count : max;
78  }
79 
80 
81  hists.push_back(h);
82  if (strcmp("G4HIT_SVTX", hit_containers[i]) == 0)
83  l->AddEntry(h, "G4HIT_SVTX / 10", "l");
84  else
85  l->AddEntry(h, hit_containers[i], "l");
86  }
87 
88  c->cd();
89  for (const auto& h: hists) {
90  h->GetYaxis()->SetRangeUser(0.000001, max * 1.1);
91  h->Draw("SAME");
92 
93  }
94 
95  l->Draw();
96  gPad->RedrawAxis();
97 
98 
99  TImage *const img {TImage::Create()};
100  img->FromPad(c);
101  img->WriteImage("Hits_vs_Eta.png");
102 
103  gApplication->Terminate(0);
104 }
105 
106 TTree *load_tree(const char *const file_name, const char *const tree_name)
107 {
108  return (TTree *) (new TFile(file_name, "READ"))->Get(tree_name);
109 }
110 
111 int main(int argc, char *argv[]) {
112  TApplication app("Hit Plots", &argc, argv);
113  Plot_Hit_Count();
114  app.Run();
115  return 0;
116 }
117