19 int nlabels = labels.size();
21 double left = gPad->GetLeftMargin();
22 double right = 1-gPad->GetRightMargin();
23 double top = 1-gPad->GetTopMargin();
24 double bottom = gPad->GetBottomMargin();
26 TLatex *tLabel =
new TLatex();
28 tLabel->SetTextSize(0.05);
30 tLabel->SetTextSize(0.0125);
35 int nbins = hist->GetNbinsX();
37 double hxmin = hist->GetXaxis()->GetBinLowEdge(1);
38 double hxmax = hist->GetXaxis()->GetBinLowEdge(nbins+1);
39 start = left + 0.25*(right-
left)*nbins/(nlabels*(hxmax-hxmin));
41 std::for_each(labels.begin(), labels.end(),
43 tLabel->DrawLatex(start, 0.25*bottom,
label.c_str());
44 start += (right-
left)*nbins/(nlabels*(hxmax-hxmin));
50 void set_labels_2D(std::vector<std::string> labels_x, std::vector<std::string> labels_y, TH2D*
hist)
52 int nlabels_x = labels_x.size();
53 int nlabels_y = labels_y.size();
55 double left = gPad->GetLeftMargin();
56 double right = 1-gPad->GetRightMargin();
57 double top = 1-gPad->GetTopMargin();
58 double bottom = gPad->GetBottomMargin();
60 TLatex *tLabelX =
new TLatex();
62 tLabelX->SetTextSize(0.02);
64 tLabelX->SetTextSize(0.0125);
67 TLatex *tLabelY =
new TLatex();
69 tLabelY->SetTextSize(0.0125);
71 tLabelY->SetTextSize(0.01);
74 tLabelY->SetTextAngle(90);
78 int nbins_x = hist->GetNbinsX();
79 int nbins_y = hist->GetNbinsY();
81 double hxmin = hist->GetXaxis()->GetBinLowEdge(1);
82 double hxmax = hist->GetXaxis()->GetBinLowEdge(nbins_x+1);
84 double hymin = hist->GetYaxis()->GetBinLowEdge(1);
85 double hymax = hist->GetYaxis()->GetBinLowEdge(nbins_y+1);
87 start_x = left + 0.25*(right-
left)*nbins_x/(nlabels_y*(hxmax-hxmin));
88 start_y = bottom + 0.25*(top-bottom)*nbins_y/(nlabels_y*(hymax-hymin));
90 std::for_each(labels_x.begin(), labels_x.end(),
92 tLabelX->DrawLatex(start_x, 0.25*bottom,
label.c_str());
93 start_x += (right-
left)*nbins_x/(nlabels_x*(hxmax-hxmin));
96 std::for_each(labels_y.begin(), labels_y.end(),
98 tLabelY->DrawLatex(0.25*left, start_y,
label.c_str());
99 start_y += (top-bottom)*nbins_y/(nlabels_y*(hymax-hymin));
107 TLine *
line =
new TLine();
108 line->SetLineWidth(2);
109 line->SetLineColor(
color);
111 for(
int i = 0;
i <
n;
i++) {
112 line->DrawLine(x, y0, x, y1);
131 double left = gPad->GetLeftMargin();
132 double right = 1-gPad->GetRightMargin();
133 double top = 1-gPad->GetTopMargin();
134 double bottom = gPad->GetBottomMargin();
137 double x = 0.5*(right +
left) - 0.5*dx;
138 double y = 0.5*(top + bottom) - 0.5*dy;
140 for(
int i = 0;
i < 1000;
i++){
142 double doverlap_x = 0.;
143 double doverlap_y = 0.;
145 for(
int histIdx = 0; histIdx < (
int)hists.size(); histIdx++){
146 double hxmin = hists[histIdx]->GetXaxis()->GetBinLowEdge(1);
147 double hxmax = hists[histIdx]->GetXaxis()->GetBinLowEdge(hists[histIdx]->GetNbinsX()+1);
149 for(
int binIdx = 1; binIdx < hists[histIdx]->GetNbinsX()+1; ++binIdx){
152 double bx = (hists[histIdx]->GetXaxis()->GetBinWidth(binIdx))*(right - left)/(hxmax - hxmin);
153 double hx = ((hists[histIdx]->GetXaxis()->GetBinLowEdge(binIdx) - hxmin)*(right - left)/(hxmax - hxmin)) +
left;
154 double hy = (hists[histIdx]->GetBinContent(binIdx) - hymin)*(top - bottom)/(hymax - hymin) + bottom;
155 double hy_prev = (hists[histIdx]->GetBinContent(binIdx-1))*(top - bottom)/(hymax - hymin) + bottom;
161 double overlap_y = 0.;
171 if (overlap_x < 0.) overlap_x = 0.;
172 if (overlap_y < 0.) overlap_y = 0.;
175 if(overlap_x == bx || overlap_x == dx || overlap_x == 0.)
177 else if(x+dx >= hx + bx)
178 doverlap_x += -1.*overlap_y;
180 doverlap_x += overlap_y;
182 if(overlap_y == by || overlap_y == dy || overlap_y == 0.)
184 else if(y+dy >= low_hy + by)
185 doverlap_y += -1.*overlap_x;
187 doverlap_y += overlap_x;
189 overlap += overlap_x*overlap_y;
196 x -= 0.02*doverlap_x;
197 y -= 0.02*doverlap_y;
205 x = right - x - dx - 0.1;
213 y = top - y - dy - 0.1;
217 if(overlap == 0. || (
std::abs(x - xprev) < 0.00005 &&
std::abs(y - yprev) < 0.00005))
break;
220 return new TLegend(x, y, x+dx, y+dy);
225 bool turnOnlegend =
true,
bool turnOnMaxRange =
true,
226 double leg_w = 0.2,
double leg_h = 0.3,
231 std::vector <TH1*> h_leg;
233 for(
int histIdx = 0; histIdx<(
int)hists.size(); ++histIdx){
235 hists[histIdx].hist->SetLineColor(hists[histIdx].
color);
236 double tmp = hists[histIdx].hist->GetBinContent(hists[histIdx].
hist->GetMaximumBin())
237 +
std::sqrt(hists[histIdx].
hist->GetBinContent(hists[histIdx].hist->GetMaximumBin()));
239 if(yMax < tmp) yMax =
tmp;
241 h_leg.push_back(hists[histIdx].
hist);
244 hists[0].hist->SetTitle(
title.c_str());
247 hists[0].hist->GetYaxis()->SetRangeUser(0, yMax);
250 for(
int histIdx = 0; histIdx<(
int)hists.size(); ++histIdx)
251 hists[histIdx].
hist->Draw(hists[histIdx].drawOption);
254 TLegend* legnd =
auto_legend(h_leg, leg_w, leg_h, 0., yMax);
255 for(
int histIdx = 0; histIdx<(
int)hists.size(); ++histIdx){
257 legnd->AddEntry(hists[histIdx].
hist,hists[histIdx].
legendLabel.c_str(),hists[histIdx].legendOption);
267 bool turnOnlegend =
false,
double low_y = -1,
double high_y = -1)
270 bool turnOnMaxRange =
false;
271 std::vector <plot_h> ratios;
272 if(low_y == high_y) turnOnMaxRange =
true;
273 for(
int histIdx = 0; histIdx < (
int)
hists.size(); histIdx++){
275 TH1F* hRatio = (TH1F*)
hists[histIdx].first.hist->Clone(
"");
278 hRatio->GetYaxis()->SetTitle(
"Ratio");
279 if(!turnOnMaxRange) hRatio->GetYaxis()->SetRangeUser(low_y, high_y);
281 ratios.push_back({hRatio,
hists[histIdx].first.drawOption,
hists[histIdx].first.color,
282 hists[histIdx].first.drawLegend,
hists[histIdx].first.legendLabel,
hists[histIdx].first.legendOption});
289 ret = ratios[0].hist;
295 TLatex *tLabel =
new TLatex(x, y, label.c_str());
296 tLabel->SetTextSize(0.035);
305 TLine *line1 =
new TLine(x0,y,x1, y);
306 line1->SetLineWidth(2);
307 line1->SetLineStyle(kDashed);
308 line1->SetLineColor(color);
316 TLine *line1 =
new TLine(x,y0,x, y1);
317 line1->SetLineWidth(2);
318 line1->SetLineStyle(kDashed);
319 line1->SetLineColor(color);
T max(const caf::Proxy< T > &a, T b)
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
std::map< std::string, double > xmax
Float_t y1[n_points_granero]
Float_t x1[n_points_granero]
void set_labels_2D(std::vector< std::string > labels_x, std::vector< std::string > labels_y, TH2D *hist)
void draw_v_line(double x, double y0, double y1, Color_t color)
void plot_hists(std::vector< plot_h > hists, std::string title="", bool turnOnlegend=true, bool turnOnMaxRange=true, double leg_w=0.2, double leg_h=0.3, double offset=1.5)
void draw_h_line(double x0, double x1, double y, Color_t color)
TLegend * auto_legend(std::vector< TH1 * > hists, double dx, double dy, double hymin, double hymax)
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
TH1 * plot_ratios(std::vector< std::pair< plot_h, TH1 * >> hists, std::string title="", bool turnOnlegend=false, double low_y=-1, double high_y=-1)
void set_labels_1D(std::vector< std::string > labels, TH1D *hist)
void draw_vlines(int n, double xmax, double y0, double y1, Color_t color=kBlack)
T min(const caf::Proxy< T > &a, T b)
void plot_label(double x, double y, std::string label)