1 |
|
#include "Layout.h" |
2 |
< |
|
3 |
< |
|
2 |
> |
#include <sstream> |
3 |
> |
#include <TPaveText.h> |
4 |
> |
#include <TLatex.h> |
5 |
|
|
6 |
|
void Layout::DrawInit() |
7 |
|
{ |
74 |
|
|
75 |
|
} |
76 |
|
|
76 |
– |
struct HistoDescription |
77 |
– |
{ |
78 |
– |
unsigned int linecolor; |
79 |
– |
std::string algoName; |
80 |
– |
}; |
81 |
– |
|
82 |
– |
|
77 |
|
|
78 |
< |
void Layout::Draw(const std::vector<HistoBlock>& histos, |
79 |
< |
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 |
|
|
109 |
|
float xmax = mystack->GetXaxis()->GetXmin(); |
110 |
|
|
111 |
|
// Draw legend |
112 |
< |
TLegend* mylegend = new TLegend(0.17,0.72,0.43,0.85); |
112 |
> |
TLegend* mylegend = new TLegend(0.55,0.90-(0.04*histos.size()),0.90,0.90); |
113 |
|
mylegend->SetFillColor(0); |
114 |
|
for (unsigned int i=0;i<histos.size();i++) |
115 |
|
{ |
118 |
|
} |
119 |
|
mylegend->Draw(); |
120 |
|
|
121 |
< |
// To Fit |
122 |
< |
for (unsigned int i=0;i<histos.size();i++) |
121 |
> |
|
122 |
> |
if (fit) |
123 |
|
{ |
124 |
< |
TF1* fitter = new TF1(dummy().c_str(),dummy().c_str(),xmin,xmax); |
125 |
< |
fitter->SetParameter(0,K); |
126 |
< |
fitter->SetParameter(1,MU); |
127 |
< |
fitter->SetParameter(2,SIG); |
128 |
< |
histos[i].histo->Fit(fitter,"R+"); |
124 |
> |
// To Fit |
125 |
> |
std::vector<double> sigmas; |
126 |
> |
std::vector<double> errors; |
127 |
> |
for (unsigned int i=0;i<histos.size();i++) |
128 |
> |
{ |
129 |
> |
TF1* fitter = new TF1(dummy().c_str(),"gaus",xmin,xmax); |
130 |
> |
fitter->SetParameter(0,K); |
131 |
> |
fitter->SetParameter(1,MU); |
132 |
> |
fitter->SetParameter(2,SIG); |
133 |
> |
histos[i].histo->Fit(fitter,"0"); |
134 |
> |
sigmas.push_back(fitter->GetParameter(2)); |
135 |
> |
errors.push_back(fitter->GetParError(2)); |
136 |
> |
} |
137 |
> |
|
138 |
> |
// Display sigmas |
139 |
> |
TPaveText* myblock = new TPaveText(0.65,0.65-(0.04*histos.size()),0.90,0.65,"NDC"); |
140 |
> |
myblock->SetBorderSize(0); |
141 |
> |
myblock->SetFillColor(0); |
142 |
> |
for (unsigned int i=0;i<sigmas.size();i++) |
143 |
> |
{ |
144 |
> |
std::stringstream str; |
145 |
> |
str << "#sigma_{" << histos[i].shortName <<"} = "; |
146 |
> |
str.precision(3); str << sigmas[i]; |
147 |
> |
str << " #pm "; |
148 |
> |
str.precision(3); str << errors[i]; |
149 |
> |
TText* mytext = myblock->AddText(str.str().c_str()); |
150 |
> |
mytext->SetTextColor(histos[i].linecolor); |
151 |
> |
mytext->SetTextAlign(11); |
152 |
> |
} |
153 |
> |
myblock->Draw(); |
154 |
|
} |
155 |
|
|
156 |
|
// Save |
157 |
< |
std::string filename = GetFileName(histos[0].histo->GetTitle()); |
157 |
> |
std::string filename = GetFileName(title); |
158 |
|
mycanvas->SaveAs((filename+".gif").c_str()); |
159 |
+ |
mycanvas->SaveAs((filename+".root").c_str()); |
160 |
+ |
|
161 |
|
} |
162 |
|
|