1 |
|
#include "Layout.h" |
2 |
< |
|
3 |
< |
|
2 |
> |
#include <sstream> |
3 |
> |
#include <TPaveText.h> |
4 |
> |
#include <TLatex.h> |
5 |
|
|
6 |
|
void Layout::DrawInit() |
7 |
|
{ |
17 |
|
gStyle->SetFrameBorderMode(0); |
18 |
|
gStyle->SetFrameBorderSize(0); |
19 |
|
gStyle->SetFrameFillColor(0); |
20 |
< |
gStyle->SetOptStat(0); |
20 |
> |
// gStyle->SetOptStat(0); |
21 |
|
|
22 |
|
gStyle->SetLabelOffset(0.005,"X"); |
23 |
|
gStyle->SetLabelSize(0.03,"X"); |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
< |
void Layout::Draw(const std::vector<HistoBlock>& histos, |
79 |
< |
const std::string& xlabel, float K, float MU, float SIG) |
78 |
> |
void Layout::Draw(const std::string title, const std::vector<HistoBlock>& histos, |
79 |
> |
const std::string& xlabel, bool fit, float K, float MU, float SIG) |
80 |
|
{ |
81 |
+ |
std::cout << "----------------- Draw : " << histos[0].histo->GetName() << std::endl; |
82 |
+ |
|
83 |
|
// safety |
84 |
|
if (histos.empty()) return; |
85 |
|
|
87 |
|
TCanvas* mycanvas = new TCanvas((std::string(histos[0].histo->GetName())+ |
88 |
|
"_canvas").c_str(), |
89 |
|
histos[0].histo->GetTitle()); |
87 |
– |
|
90 |
|
// SetLineColor |
91 |
|
for (unsigned int i=0;i<histos.size();i++) |
92 |
|
{ |
91 |
– |
std::cout << "TEST : " << histos[i].linecolor << std::endl; |
93 |
|
histos[i].histo->SetLineColor( histos[i].linecolor ); |
94 |
|
} |
95 |
|
|
108 |
|
float xmax = mystack->GetXaxis()->GetXmin(); |
109 |
|
|
110 |
|
// Draw legend |
111 |
< |
TLegend* mylegend = new TLegend(0.17,0.72,0.43,0.85); |
111 |
> |
TLegend* mylegend = new TLegend(0.55,0.90-(0.04*histos.size()),0.90,0.90); |
112 |
|
mylegend->SetFillColor(0); |
113 |
|
for (unsigned int i=0;i<histos.size();i++) |
114 |
|
{ |
117 |
|
} |
118 |
|
mylegend->Draw(); |
119 |
|
|
120 |
< |
// To Fit |
121 |
< |
for (unsigned int i=0;i<histos.size();i++) |
120 |
> |
|
121 |
> |
if (fit) |
122 |
|
{ |
123 |
< |
TF1* fitter = new TF1(dummy().c_str(),"gaus",xmin,xmax); |
124 |
< |
fitter->SetParameter(0,K); |
125 |
< |
fitter->SetParameter(1,MU); |
126 |
< |
fitter->SetParameter(2,SIG); |
127 |
< |
histos[i].histo->Fit(fitter,"0"); |
123 |
> |
// To Fit |
124 |
> |
std::vector<double> sigmas; |
125 |
> |
std::vector<double> errors; |
126 |
> |
for (unsigned int i=0;i<histos.size();i++) |
127 |
> |
{ |
128 |
> |
TF1* fitter = new TF1(dummy().c_str(),"gaus",xmin,xmax); |
129 |
> |
fitter->SetParameter(0,K); |
130 |
> |
fitter->SetParameter(1,MU); |
131 |
> |
fitter->SetParameter(2,SIG); |
132 |
> |
histos[i].histo->Fit(fitter,"0"); |
133 |
> |
sigmas.push_back(fitter->GetParameter(2)); |
134 |
> |
errors.push_back(fitter->GetParError(2)); |
135 |
> |
} |
136 |
> |
|
137 |
> |
// Display sigmas |
138 |
> |
TPaveText* myblock = new TPaveText(0.65,0.65-(0.04*histos.size()),0.90,0.65,"NDC"); |
139 |
> |
myblock->SetBorderSize(0); |
140 |
> |
myblock->SetFillColor(0); |
141 |
> |
for (unsigned int i=0;i<sigmas.size();i++) |
142 |
> |
{ |
143 |
> |
std::stringstream str; |
144 |
> |
str << "#sigma_{" << histos[i].shortName <<"} = "; |
145 |
> |
str.precision(3); str << sigmas[i]; |
146 |
> |
str << " #pm "; |
147 |
> |
str.precision(3); str << errors[i]; |
148 |
> |
TText* mytext = myblock->AddText(str.str().c_str()); |
149 |
> |
mytext->SetTextColor(histos[i].linecolor); |
150 |
> |
mytext->SetTextAlign(11); |
151 |
> |
} |
152 |
> |
myblock->Draw(); |
153 |
|
} |
154 |
|
|
155 |
|
// Save |
156 |
< |
std::string filename = GetFileName(histos[0].histo->GetTitle()); |
156 |
> |
std::string filename = GetFileName(title); |
157 |
|
mycanvas->SaveAs((filename+".gif").c_str()); |
158 |
|
mycanvas->SaveAs((filename+".root").c_str()); |
159 |
|
|