forked from uboone/xsec_analyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotBDTVariableRankings.C
161 lines (132 loc) · 5.36 KB
/
PlotBDTVariableRankings.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <TH1D.h>
#include <TCanvas.h>
#include <TLegend.h>
#include <vector>
#include <string>
#include <memory>
void PlotBDTVariableRankings()
{
std::vector<std::pair<std::string, float>> goldenPionSeparation{
{"ln(R_{p}/MIP)", 2.240e-01},
{"Track score", 1.665e-01},
{"Truncated mean dE/dx", 1.538e-01},
{"Wiggliness", 6.130e-02},
{"# Descendents", 3.464e-02},
{"ln(R_{#pi}/MIP)", 2.393e-02}
};
std::vector<std::pair<std::string, float>> goldenPionImportance{
{"ln(R_{p}/MIP)", 2.373e-01},
{"Track score", 2.349e-01},
{"Truncated mean dE/dx", 1.651e-01},
{"ln(R_{#pi}/MIP)", 1.606e-01},
{"Wiggliness", 1.115e-01},
{"# Descendents", 9.069e-02}
};
std::vector<std::pair<std::string, float>> protonSeparation{
{"ln(R_{p}/MIP)", 6.058e-01},
{"Truncated mean dE/dx", 5.225e-01},
{"Track score", 1.701e-01},
{"ln(R_{#pi}/MIP)", 1.648e-01},
{"Wiggliness", 6.342e-02}
};
std::vector<std::pair<std::string, float>> protonImportance{
{"ln(R_{p}/MIP)", 2.699e-01},
{"Truncated mean dE/dx", 2.359e-01},
{"Track score", 2.157e-01},
{"Wiggliness", 1.483e-01},
{"ln(R_{#pi}/MIP)", 1.302e-01}
};
std::vector<std::pair<std::string, float>> muonSeparation{
{"Track score", 3.739e-01},
{"ln(R_{p}/MIP)", 3.194e-01},
{"Truncated mean dE/dx", 3.000e-01},
{"ln(R_{#pi}/MIP)", 2.122e-01},
{"Wiggliness", 3.634e-02},
{"# Descendents", 3.753e-03}
};
std::vector<std::pair<std::string, float>> muonImportance{
{"ln(R_{p}/MIP)", 3.232e-01},
{"Truncated mean dE/dx", 1.859e-01},
{"Track score", 1.800e-01},
{"ln(R_{#pi}/MIP)", 1.619e-01},
{"Wiggliness", 1.026e-01},
{"# Descendents", 4.649e-02}
};
std::map<std::string, std::map<std::string, std::vector<std::pair<std::string, float>>>> allRankings{
{"goldenPion", {
{"Separation", goldenPionSeparation},
{"Importance", goldenPionImportance}
}},
{"proton", {
{"Separation", protonSeparation},
{"Importance", protonImportance}
}},
{"muon", {
{"Separation", muonSeparation},
{"Importance", muonImportance}
}}
};
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
std::vector<std::string> bdtTypes = {"goldenPion", "muon", "proton"};
std::vector<std::string> metrics = {"Separation", "Importance"};
for (const auto& bdtType : bdtTypes) {
for (const auto& metric : metrics) {
// Get the data for this particle type and metric
const auto& data = allRankings.at(bdtType).at(metric);
std::cout<<"DEBUG data.size() = "<<data.size()<<std::endl;
// Create a histogram
TH1D h(("h "+bdtType+metric).c_str(), ("h "+bdtType+metric).c_str(), data.size(), 0, 1);
// Set the title
std::string bdtName = bdtType == "goldenPion" ? "Golden Pion" : (bdtType == "proton" ? "Proton" : "Muon");
std::string title = bdtName + " BDT Input Variable Ranking";
h.SetTitle(title.c_str());
// Set the y axis label
std::string yAxisLabel = metric == "Separation" ? "Separation score" : "Importance score";
h.SetYTitle(yAxisLabel.c_str());
// Fill the histogram in reverse order
int i = 1;
for (auto it = data.rbegin(); it != data.rend(); ++it) {
const auto& [key, value] = *it;
h.SetBinContent(i, value);
h.GetXaxis()->SetBinLabel(i, key.c_str());
++i;
}
// // Center the axis labels on the bars
// h.GetXaxis()->SetLabelOffset(-0.05);
// Disable the stats box
h.SetStats(0);
// // Remove the y-axis ticks
// h.GetYaxis()->SetNdivisions(0);
// Access the y-axis and disable ticks
h.GetXaxis()->SetTickLength(0); // Hides the ticks
// h.GetXaxis()->SetLabelOffset(999); // Hides the labels
// Create a canvas
TCanvas c("c", "", 800, 600);
// Disable the y-axis grid lines
c.SetGridx(1);
// Increase the left margin
c.SetLeftMargin(0.2);
// Draw the histogram as a horizontal bar chart
h.SetBarWidth(0.5);
h.SetBarOffset(0.1);
if (metric == "Importance") {
h.SetFillColor(kGreen);
} else {
h.SetFillColor(kBlue);
}
// Set the line color to black
h.SetLineColor(kBlack);
h.Draw("hbar");
// Update the canvas
c.Update();
// Save the plot
std::string filename = "plots/BDTVariableRankings_" + bdtType + "_" + metric;
c.SaveAs((filename + ".pdf").c_str());
c.SaveAs((filename + ".png").c_str());
c.SaveAs((filename + ".C").c_str());
}
}
}