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) |
79 |
> |
const std::string& xlabel, 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.17,0.85-(0.04*histos.size()),0.33,0.85); |
113 |
|
mylegend->SetFillColor(0); |
114 |
|
for (unsigned int i=0;i<histos.size();i++) |
115 |
|
{ |
119 |
|
mylegend->Draw(); |
120 |
|
|
121 |
|
// To Fit |
122 |
+ |
std::vector<double> sigmas; |
123 |
+ |
std::vector<double> errors; |
124 |
|
for (unsigned int i=0;i<histos.size();i++) |
125 |
|
{ |
126 |
< |
TF1* fitter = new TF1(dummy().c_str(),dummy().c_str(),xmin,xmax); |
126 |
> |
TF1* fitter = new TF1(dummy().c_str(),"gaus",xmin,xmax); |
127 |
|
fitter->SetParameter(0,K); |
128 |
|
fitter->SetParameter(1,MU); |
129 |
|
fitter->SetParameter(2,SIG); |
130 |
< |
histos[i].histo->Fit(fitter,"R+"); |
130 |
> |
histos[i].histo->Fit(fitter,"0"); |
131 |
> |
sigmas.push_back(fitter->GetParameter(2)); |
132 |
> |
errors.push_back(fitter->GetParError(2)); |
133 |
|
} |
134 |
|
|
135 |
+ |
// Display sigmas |
136 |
+ |
TPaveText* myblock = new TPaveText(0.6,0.65-(0.04*histos.size()),0.80,0.65,"NDC"); |
137 |
+ |
myblock->SetBorderSize(0); |
138 |
+ |
myblock->SetFillColor(0); |
139 |
+ |
for (unsigned int i=0;i<sigmas.size();i++) |
140 |
+ |
{ |
141 |
+ |
std::stringstream str; |
142 |
+ |
str << "#sigma_{RECO} = "; |
143 |
+ |
str.precision(3); str << sigmas[i]; |
144 |
+ |
str << " #pm "; |
145 |
+ |
str.precision(3); str << errors[i]; |
146 |
+ |
TText* mytext = myblock->AddText(str.str().c_str()); |
147 |
+ |
mytext->SetTextColor(histos[i].linecolor); |
148 |
+ |
mytext->SetTextAlign(11); |
149 |
+ |
} |
150 |
+ |
myblock->Draw(); |
151 |
+ |
|
152 |
|
// Save |
153 |
|
std::string filename = GetFileName(histos[0].histo->GetTitle()); |
154 |
|
mycanvas->SaveAs((filename+".gif").c_str()); |
155 |
+ |
mycanvas->SaveAs((filename+".root").c_str()); |
156 |
+ |
|
157 |
|
} |
158 |
|
|