File indexing completed on 2025-08-06 08:12:56
0001 #include <iostream>
0002 #include <cstdlib>
0003 #include <memory>
0004 #include <string>
0005 #include <cstring>
0006 #include <vector>
0007 #include <set>
0008 #include <cmath>
0009 #include <utility>
0010 #include <cassert>
0011
0012 #include "TFile.h"
0013 #include "TTree.h"
0014 #include "TCanvas.h"
0015 #include "TLegend.h"
0016 #include "TROOT.h"
0017 #include "TH1F.h"
0018 #include "TColor.h"
0019 #include "TImage.h"
0020 #include "TApplication.h"
0021 #include "TGraphErrors.h"
0022 #include "/sphenix/user/gregtom3/SBU/research/macros/macros/sPHENIXStyle/sPhenixStyle.C"
0023
0024 #define STR(X) #X
0025 #define XSTR(X) STR(X)
0026 #define NELEMS(a) (sizeof(a)/sizeof(a[0]))
0027
0028
0029 TTree *load_tree(const char *const file_name, const char *const tree_name);
0030 const char *const hitcount_file_path
0031 {"/sphenix/user/gregtom3/data/Summer2018/SVTX_studies/hits-per-eta/hitcount.root"};
0032
0033 const char *const hit_containers[] {"G4HIT_EGEM_0", "G4HIT_EGEM_1", "G4HIT_EGEM_3",
0034 "G4HIT_FGEM_0", "G4HIT_FGEM_1", "G4HIT_FGEM_2", "G4HIT_FGEM_3","G4HIT_FGEM_4", "G4HIT_MAPS",
0035 "G4HIT_SVTX"};
0036 const static Color_t plot_colors[] = { kBlue, kSpring, kBlack, kYellow, kCyan, kGray, kMagenta, kOrange,
0037 kRed, kGreen + 3, kPink};
0038
0039
0040 void Plot_Hit_Count() {
0041 assert(NELEMS(plot_colors) >= NELEMS(hit_containers));
0042 SetsPhenixStyle();
0043 gROOT->SetBatch(true);
0044
0045 TCanvas *const c {new TCanvas {"hits", "Hits", gStyle->GetCanvasDefW(), gStyle->GetCanvasDefH()}};
0046 TLegend *const l {new TLegend {0.7, 0.9, 0.95, 0.61, "Detector"}};
0047 l->SetTextSize(0.03);
0048 Double_t max {0};
0049 std::vector<TH1F*> hists {};
0050 for (size_t i {0}; i < NELEMS(hit_containers); ++i) {
0051 const std::string tree_name {std::string(hit_containers[i]) + "_normalized"};
0052 TTree *const hits {load_tree(hitcount_file_path, tree_name.c_str())};
0053
0054
0055 Double_t eta, hit_count;
0056 hits->SetBranchAddress("eta", &eta);
0057 hits->SetBranchAddress("hit_count", &hit_count);
0058
0059 Long64_t nentries {hits->GetEntries()};
0060 TH1F *const h {new TH1F {hit_containers[i], "Hit Count", 100, -4.5, 4.5}};
0061 h->SetXTitle("#eta");
0062 h->SetYTitle("Normalized Hit Count");
0063 h->SetLineColor(plot_colors[i]);
0064 for (Long64_t j {0}; j < nentries; ++j) {
0065 if (hits->LoadTree(j) < 0)
0066 break;
0067 hits->GetEntry(j);
0068 if (strcmp("G4HIT_SVTX", hit_containers[i]) == 0)
0069 hit_count /= 10;
0070
0071 h->Fill(eta, hit_count);
0072 }
0073
0074 const Long64_t nbins {h->GetSize() - 2};
0075 for (Long64_t j {0}; j < nbins; ++j) {
0076 const Double_t hit_count {h->GetBinContent(j + 1)};
0077 max = (hit_count > max) ? hit_count : max;
0078 }
0079
0080
0081 hists.push_back(h);
0082 if (strcmp("G4HIT_SVTX", hit_containers[i]) == 0)
0083 l->AddEntry(h, "G4HIT_SVTX / 10", "l");
0084 else
0085 l->AddEntry(h, hit_containers[i], "l");
0086 }
0087
0088 c->cd();
0089 for (const auto& h: hists) {
0090 h->GetYaxis()->SetRangeUser(0.000001, max * 1.1);
0091 h->Draw("SAME");
0092
0093 }
0094
0095 l->Draw();
0096 gPad->RedrawAxis();
0097
0098
0099 TImage *const img {TImage::Create()};
0100 img->FromPad(c);
0101 img->WriteImage("Hits_vs_Eta.png");
0102
0103 gApplication->Terminate(0);
0104 }
0105
0106 TTree *load_tree(const char *const file_name, const char *const tree_name)
0107 {
0108 return (TTree *) (new TFile(file_name, "READ"))->Get(tree_name);
0109 }
0110
0111 int main(int argc, char *argv[]) {
0112 TApplication app("Hit Plots", &argc, argv);
0113 Plot_Hit_Count();
0114 app.Run();
0115 return 0;
0116 }
0117