-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTEfficiency_plot.cpp
More file actions
155 lines (141 loc) · 6.66 KB
/
TEfficiency_plot.cpp
File metadata and controls
155 lines (141 loc) · 6.66 KB
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
#include "TFile.h"
#include "TCanvas.h"
#include "TEfficiency.h"
#include "PlotterUtils.hpp"
TString root_file = "./projects/NP04_PDS_article/SelfTrigger/AnaST_Ch_11121.root";
TString teff_name = "Run_32099/he_efficiency_nofit;1";
TString canvas_name = "./projects/NP04_PDS_article/SelfTrigger/EffHistoeee";
// --- Histo Title --------------------------------------------------
TString h_total_title = "External trigger";
TString h_passed_title = "Self trigger";
// --- Axis title ---------------------------------------------------
TString title_x = "PE";
TString histo_title_y = "Counts";
TString eff_title_y = "Efficiency";
// --- Axis range ---------------------------------------------------
// If (low==0 and up==0) it will set it automatically
// bool use_custom_topFrame = 1;
double x_axis_low = 0.;
double x_axis_up = 0.;
double y_axis_low = 0.;
double y_axis_up = 0.;
double min_y = 1.; // If using log_y, set it > 0
// --- Log scale and grid -------------------------------------------
bool log_x = false;
bool log_y = false;
bool hgrid_h = 0;
bool hgrid_v = 1;
// --- Graph settings -----------------------------------------------
// NB: "hist" remove the fit, if any
std::string draw_option = "h"; // only marker and errors "E", simple histo and errors "hist E"
int h_line_width = 1; // Line width of the TH1(s)
float fill_alpha = 1.; // Opacity of filling color
bool show_marker = 1;
double marker_alpha = 1.;
// --- Legend settings ----------------------------------------------
int legend_ncolumns = 1;
float legend_fill_alpha = 1.0; // Fill alpha of the legend
float margin = 0.17;
const char* entry_opt = "p"; // Options for the legend entries
double legend_x1 = 0.6;
double legend_y1 = 0.65;
double legend_x2 = 0.82;
double legend_y2 = 0.85;
void TEfficiency_plot(){
SetMyStyle();
font = 43;
title_font_size = 35;
label_font_size = 35;
title_offset_x = 0.8;
label_offset_x = 0.01;
label_offset_y = 0.01;
title_offset_y = 1.7;
std::vector<Int_t> color_list = set_palette("", 2);
double x_min = 1e100;
double x_max = -1e100;
double y_min = 1.e100;
double y_max = -1.e100;
TFile* input_file = TFile::Open(root_file);
if (!input_file || input_file->IsZombie()) {
std::cout << "Error opening file: " << root_file << std::endl;
return;
}
TEfficiency* teff = nullptr;
input_file->GetObject(teff_name, teff);
if (!teff) {
std::cout << "Error: TEfficiency object " << teff_name << " not found in file " << root_file << std::endl;
input_file->Close();
return;
}
TH1D* h_total = (TH1D*)teff->GetTotalHistogram();
h_total->SetTitle(h_total_title);
make_histo_cute(h_total, h_line_width, color_list[0], fill_alpha, show_marker, marker_alpha);
TH1D* h_passed = (TH1D*)teff->GetPassedHistogram();
h_passed->SetTitle(h_passed_title);
make_histo_cute(h_passed, h_line_width, color_list[1], fill_alpha, show_marker, marker_alpha);
TCanvas* gc = new TCanvas(canvas_name, canvas_name, 0, 0, canvas_width, canvas_height);
TPad *topPad = new TPad("topPad", "", 0.005, 0.3, 0.995, 0.995);
TPad *bottomPad = new TPad("bottomPad", "", 0.005, 0.005, 0.995, 0.3);
topPad->Draw();
bottomPad->Draw();
topPad->SetBottomMargin(0.01);
bottomPad->SetTopMargin(0.01);
bottomPad->SetBottomMargin(0.3);
topPad->cd();
TH1* topFrame;
if (x_min > h_total->GetXaxis()->GetXmin()) x_min = h_total->GetXaxis()->GetXmin();
if (x_max < h_total->GetXaxis()->GetXmax()) x_max = h_total->GetXaxis()->GetXmax();
if (y_min > h_total->GetMinimum()) y_min = h_total->GetMinimum();
if (y_max < h_total->GetMaximum()) y_max = h_total->GetMaximum()*1.05;
if (x_axis_low!=0. || x_axis_up!=0.) {
x_min = x_axis_low;
x_max = x_axis_up;
}
if (y_axis_low!=0. || y_axis_up!=0.) {
y_min = y_axis_low;
y_max = y_axis_up;
}
topFrame = topPad->DrawFrame(x_min, y_min, x_max, y_max);
topFrame->GetXaxis()->CenterTitle(); topFrame->GetYaxis()->CenterTitle();
topFrame->GetXaxis()->SetTitle(""); topFrame->GetYaxis()->SetTitle(histo_title_y);
topFrame->GetXaxis()->SetTitleFont(font); topFrame->GetYaxis()->SetTitleFont(font);
topFrame->GetXaxis()->SetTitleSize(0); topFrame->GetYaxis()->SetTitleSize(title_font_size);
topFrame->GetXaxis()->SetTitleOffset(title_offset_x); topFrame->GetYaxis()->SetTitleOffset(title_offset_y);
topFrame->GetXaxis()->SetLabelFont(font); topFrame->GetYaxis()->SetLabelFont(font);
topFrame->GetXaxis()->SetLabelSize(0); topFrame->GetYaxis()->SetLabelSize(label_font_size);
topFrame->GetXaxis()->SetLabelOffset(label_offset_x); topFrame->GetYaxis()->SetLabelOffset(label_offset_y);
topFrame->GetXaxis()->SetTickLength(0.01); topFrame->GetYaxis()->SetTickLength(0.02);
topPad->SetLogy(log_y); topPad->SetLogx(log_x);
topPad->SetGrid(hgrid_v, hgrid_h);
// remove tick from the upper boarder
topPad->SetTickx(0);
h_total->Draw("hist same");
h_passed->Draw("hist same");
auto legend = build_legend(topPad, entry_opt,
legend_x1, legend_y1, legend_x2, legend_y2,
legend_ncolumns, margin, legend_fill_alpha);
legend->SetTextFont(font); legend->SetTextSize(label_font_size);
auto entries = legend->GetListOfPrimitives();
auto entry = static_cast<TLegendEntry*>(entries->At(0));
entries->Remove(entry);
legend->Draw();
topPad->RedrawAxis();
bottomPad->cd();
TH1* bottomFrame;
if (x_min > h_total->GetXaxis()->GetXmin()) x_min = h_total->GetXaxis()->GetXmin();
bottomFrame = bottomPad->DrawFrame(x_min, -0.1, x_max, 1.05);
bottomFrame->GetXaxis()->CenterTitle(); bottomFrame->GetYaxis()->CenterTitle();
bottomFrame->GetXaxis()->SetTitle(title_x); bottomFrame->GetYaxis()->SetTitle(eff_title_y);
bottomFrame->GetXaxis()->SetTitleFont(font); bottomFrame->GetYaxis()->SetTitleFont(font);
bottomFrame->GetXaxis()->SetTitleSize(title_font_size); bottomFrame->GetYaxis()->SetTitleSize(title_font_size);
bottomFrame->GetXaxis()->SetTitleOffset(title_offset_x); bottomFrame->GetYaxis()->SetTitleOffset(title_offset_y);
bottomFrame->GetXaxis()->SetLabelFont(font); bottomFrame->GetYaxis()->SetLabelFont(font);
bottomFrame->GetXaxis()->SetLabelSize(label_font_size); bottomFrame->GetYaxis()->SetLabelSize(label_font_size);
bottomFrame->GetXaxis()->SetLabelOffset(label_offset_x); bottomFrame->GetYaxis()->SetLabelOffset(label_offset_y);
bottomFrame->GetXaxis()->SetTickLength(0.02); bottomFrame->GetYaxis()->SetTickLength(0.02);
bottomPad->SetLogy(log_y); bottomPad->SetLogx(log_x);
bottomPad->SetGrid(hgrid_v, hgrid_h);
bottomFrame->SetNdivisions(505, "y");
teff->Draw("same");
return;
}