EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CharmJetClassification_Plots.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CharmJetClassification_Plots.C
1 #include "TROOT.h"
2 #include "TChain.h"
3 #include "TEfficiency.h"
4 #include "TH1.h"
5 #include "TGraphErrors.h"
6 #include "TCut.h"
7 #include "TCanvas.h"
8 #include "TStyle.h"
9 #include "TLegend.h"
10 #include "TMath.h"
11 #include "TLine.h"
12 #include "TLatex.h"
13 #include "TRatioPlot.h"
14 
15 #include <glob.h>
16 #include <iostream>
17 #include <iomanip>
18 #include <vector>
19 
20 #include "PlotFunctions.h"
21 
22 
23 float target_xsec = LookupCrossSection("CC_DIS");
24 
25 float target_lumi = 100 * u_fb;
26 
27 float n_gen = -1;
28 
29 
31 {
32  // Global options
33  gStyle->SetOptStat(0);
34 
35  // Create the TCanvas
36  TCanvas *pad = new TCanvas("pad", "", 800, 600);
37  TLegend *legend = nullptr;
38  TH1F *htemplate = nullptr;
39 
40  std::vector<TString> input_folders = { "dataset_ip3dtagger", "dataset_ktagger", "dataset_etagger", "dataset_mutagger" };
41  std::vector<TString> input_vars = { "jet_t1_pt", "jet_t1_sIP3D", "jet_t2_pt", "jet_t2_sIP3D", "jet_t3_pt", "jet_t3_sIP3D", "jet_t4_pt", "jet_t4_sIP3D", "jet_k1_pt", "jet_k1_sIP3D", "jet_k2_pt", "jet_k2_sIP3D", "jet_e1_pt", "jet_e1_sIP3D", "jet_e2_pt", "jet_e2_sIP3D", "jet_mu1_pt", "jet_mu1_sIP3D", "jet_mu2_pt", "jet_mu2_sIP3D" };
42 
43  for (auto input_folder : input_folders) {
44  std::cout << input_folder.Data() << std::endl;
45 
46  for (auto input_var : input_vars) {
47  std::cout << input_var.Data() << std::endl;
48 
49  TChain testing_data(Form("%s/TestTree", input_folder.Data()));
50  TChain training_data(Form("%s/TrainTree", input_folder.Data()));
51 
52  testing_data.Add("CharmJetClassification_Results.root");
53  training_data.Add("CharmJetClassification_Results.root");
54 
55  pad->Clear();
56 
57  // pad->Divide(1,2);
58  pad->cd();
59 
60  TH1F *h_signal = nullptr;
61  TH1F *h_background = nullptr;
62 
63  if (input_var.Contains("pt") == kTRUE) {
64  h_signal = new TH1F("h_signal", "signal distribution", 100, 0, 15);
65  h_signal->Sumw2();
66  pad->SetLogy(kFALSE);
67  }
68 
69  if (input_var.Contains("sIP3D") == kTRUE) {
70  h_signal = new TH1F("h_signal", "signal distribution", 200, -100, 100);
71  h_signal->Sumw2();
72  pad->SetLogy();
73  }
74 
75  if (h_signal == nullptr) {
76  continue;
77  }
78 
79  h_background = static_cast<TH1F *>(h_signal->Clone("h_background"));
80  training_data.Project(h_signal->GetName(), input_var.Data(), "jet_flavor==4");
81  training_data.Project(h_background->GetName(), input_var.Data(), "jet_flavor<4 || jet_flavor==22");
82 
83  if ((h_signal->GetEntries() == 0) || (h_background->GetEntries() == 0)) {
84  if (h_signal) {
85  delete h_signal;
86  }
87 
88  if (h_background) {
89  delete h_background;
90  }
91  continue;
92  }
93 
94  auto h_signal_norm = h_signal->DrawNormalized("HIST");
95  auto h_background_norm = h_background->DrawNormalized("HIST SAME");
96 
97  h_signal_norm->SetLineWidth(2);
98  h_signal_norm->SetLineColor(kBlue);
99 
100  h_background_norm->SetLineWidth(2);
101  h_background_norm->SetLineColor(kRed);
102  h_background_norm->SetLineStyle(kDashed);
103 
104  Float_t max_value = TMath::Max(h_signal_norm->GetMaximum(), h_background_norm->GetMaximum());
105 
106  Float_t min_value = 0.0;
107 
108  if (input_var.Contains("sIP3D") == kTRUE) {
109  min_value = 1e-6;
110  }
111 
112  h_signal_norm->SetMaximum(max_value * 1.25);
113  h_background_norm->SetMaximum(max_value * 1.25);
114  h_signal_norm->SetMinimum(min_value);
115  h_background_norm->SetMinimum(min_value);
116 
117  // Label axes
118  h_signal_norm->SetYTitle("Probability");
119 
120  if (input_var.Contains("sIP3D") == kTRUE) {
121  h_signal_norm->SetXTitle("Track sIP_{3D}");
122  }
123 
124  if (input_var.Contains("pt") == kTRUE) {
125  h_signal_norm->SetXTitle("Track p_{T}");
126  }
127 
128  pad->SetGrid(1, 1);
129 
130  // Legend
131  TLegend *legend = smart_legend("upper right");
132  legend->SetFillStyle(0);
133  legend->SetBorderSize(0);
134  legend->AddEntry(h_signal_norm, "True Charm Jets", "lf");
135  legend->AddEntry(h_background_norm, "True Light Jets", "lp");
136  legend->Draw();
137 
138 
139  pad->SaveAs(Form("%s.pdf", input_var.Data()));
140 
141  if (h_signal) {
142  delete h_signal;
143  }
144 
145  if (h_background) {
146  delete h_background;
147  }
148 
149  if (legend)
150  delete legend;
151  }
152  }
153 }