1 |
econte |
1.1 |
#include "Layout.h"
|
2 |
econte |
1.3 |
#include <sstream>
|
3 |
|
|
#include <TPaveText.h>
|
4 |
|
|
#include <TLatex.h>
|
5 |
cgoetzma |
1.10 |
#include <iostream>
|
6 |
|
|
using namespace std;
|
7 |
econte |
1.1 |
|
8 |
|
|
void Layout::DrawInit()
|
9 |
|
|
{
|
10 |
econte |
1.4 |
gStyle->SetCanvasColor(0);
|
11 |
econte |
1.1 |
gStyle->SetCanvasBorderMode(0);
|
12 |
|
|
gStyle->SetCanvasBorderSize(3);
|
13 |
|
|
|
14 |
|
|
gStyle->SetPadLeftMargin(0.125);
|
15 |
|
|
gStyle->SetPadBottomMargin(0.12);
|
16 |
|
|
gStyle->SetPadColor(0);
|
17 |
|
|
gStyle->SetPadBorderMode(0);
|
18 |
|
|
|
19 |
|
|
gStyle->SetFrameBorderMode(0);
|
20 |
|
|
gStyle->SetFrameBorderSize(0);
|
21 |
|
|
gStyle->SetFrameFillColor(0);
|
22 |
cgoetzma |
1.9 |
// gStyle->SetOptStat(0);
|
23 |
econte |
1.1 |
|
24 |
|
|
gStyle->SetLabelOffset(0.005,"X");
|
25 |
|
|
gStyle->SetLabelSize(0.03,"X");
|
26 |
|
|
gStyle->SetLabelFont(22,"X");
|
27 |
|
|
|
28 |
|
|
gStyle->SetTitleOffset(1.1,"X");
|
29 |
|
|
gStyle->SetTitleSize(0.04,"X");
|
30 |
|
|
gStyle->SetTitleFont(22,"X");
|
31 |
|
|
|
32 |
|
|
gStyle->SetLabelOffset(0.005,"Y");
|
33 |
|
|
gStyle->SetLabelSize(0.03,"Y");
|
34 |
|
|
gStyle->SetLabelFont(22,"Y");
|
35 |
|
|
|
36 |
|
|
gStyle->SetTitleOffset(1.1,"Y");
|
37 |
|
|
gStyle->SetTitleSize(0.04,"Y");
|
38 |
|
|
gStyle->SetTitleFont(22,"Y");
|
39 |
|
|
|
40 |
|
|
gStyle->SetStatColor(0);
|
41 |
|
|
gStyle->SetStatBorderSize(0);
|
42 |
|
|
|
43 |
|
|
gStyle->SetTextFont(2);
|
44 |
|
|
gStyle->SetTextSize(.05);
|
45 |
|
|
|
46 |
|
|
gStyle->SetLegendBorderSize(1);
|
47 |
|
|
|
48 |
|
|
gStyle->SetHistLineWidth(2);
|
49 |
|
|
|
50 |
|
|
gStyle->SetTitleFillColor(0);
|
51 |
|
|
gStyle->SetTitleFontSize(0.05);
|
52 |
|
|
gStyle->SetTitleBorderSize(0);
|
53 |
|
|
gStyle->SetTitleAlign(13);
|
54 |
|
|
gStyle->SetTextAlign(22);
|
55 |
|
|
|
56 |
|
|
//Canvas declaration and configuration
|
57 |
|
|
// TCanvas *c1 = new TCanvas("c1", "plots",200,10,800,600);
|
58 |
|
|
|
59 |
|
|
//General ROOT style setup
|
60 |
|
|
gStyle->SetOptDate(0);
|
61 |
|
|
gStyle->SetStatColor(0);
|
62 |
|
|
gStyle->SetTitleColor(1);
|
63 |
|
|
gStyle->SetOptStat(0);
|
64 |
|
|
gStyle->SetPalette(1);
|
65 |
|
|
|
66 |
|
|
const Int_t NRGBs = 5;
|
67 |
|
|
const Int_t NCont = 255;
|
68 |
|
|
|
69 |
|
|
Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
|
70 |
|
|
Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
|
71 |
|
|
Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
|
72 |
|
|
Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
|
73 |
|
|
TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
|
74 |
|
|
gStyle->SetNumberContours(NCont);
|
75 |
econte |
1.4 |
|
76 |
econte |
1.1 |
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
|
80 |
econte |
1.7 |
void Layout::Draw(const std::string title, const std::vector<HistoBlock>& histos,
|
81 |
econte |
1.5 |
const std::string& xlabel, bool fit, float K, float MU, float SIG)
|
82 |
econte |
1.1 |
{
|
83 |
econte |
1.3 |
std::cout << "----------------- Draw : " << histos[0].histo->GetName() << std::endl;
|
84 |
|
|
|
85 |
econte |
1.1 |
// safety
|
86 |
|
|
if (histos.empty()) return;
|
87 |
|
|
|
88 |
|
|
// Create a new canvas
|
89 |
|
|
TCanvas* mycanvas = new TCanvas((std::string(histos[0].histo->GetName())+
|
90 |
|
|
"_canvas").c_str(),
|
91 |
|
|
histos[0].histo->GetTitle());
|
92 |
|
|
// SetLineColor
|
93 |
|
|
for (unsigned int i=0;i<histos.size();i++)
|
94 |
|
|
{
|
95 |
|
|
histos[i].histo->SetLineColor( histos[i].linecolor );
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
// Stack
|
99 |
|
|
THStack *mystack = new THStack;
|
100 |
|
|
for (unsigned int i=0;i<histos.size();i++)
|
101 |
|
|
{
|
102 |
|
|
mystack->Add( histos[i].histo );
|
103 |
|
|
}
|
104 |
|
|
mystack->Draw("nostack");
|
105 |
|
|
|
106 |
|
|
// Axis
|
107 |
|
|
mystack->GetYaxis()->SetTitle("# events");
|
108 |
|
|
mystack->GetXaxis()->SetTitle(xlabel.c_str());
|
109 |
|
|
float xmin = mystack->GetXaxis()->GetXmin();
|
110 |
|
|
float xmax = mystack->GetXaxis()->GetXmin();
|
111 |
|
|
|
112 |
|
|
// Draw legend
|
113 |
cgoetzma |
1.8 |
TLegend* mylegend = new TLegend(0.55,0.90-(0.04*histos.size()),0.90,0.90);
|
114 |
econte |
1.1 |
mylegend->SetFillColor(0);
|
115 |
|
|
for (unsigned int i=0;i<histos.size();i++)
|
116 |
|
|
{
|
117 |
|
|
mylegend->AddEntry(histos[i].histo,
|
118 |
|
|
histos[i].algoName.c_str(),"l");
|
119 |
|
|
}
|
120 |
|
|
mylegend->Draw();
|
121 |
|
|
|
122 |
econte |
1.3 |
|
123 |
econte |
1.5 |
if (fit)
|
124 |
econte |
1.3 |
{
|
125 |
econte |
1.5 |
// To Fit
|
126 |
|
|
std::vector<double> sigmas;
|
127 |
|
|
std::vector<double> errors;
|
128 |
|
|
for (unsigned int i=0;i<histos.size();i++)
|
129 |
|
|
{
|
130 |
cgoetzma |
1.10 |
TF1* fitter = new TF1(dummy().c_str(),"gaus",-900,900); //or xmin, xmax...
|
131 |
econte |
1.5 |
fitter->SetParameter(0,K);
|
132 |
|
|
fitter->SetParameter(1,MU);
|
133 |
|
|
fitter->SetParameter(2,SIG);
|
134 |
|
|
histos[i].histo->Fit(fitter,"0");
|
135 |
|
|
sigmas.push_back(fitter->GetParameter(2));
|
136 |
|
|
errors.push_back(fitter->GetParError(2));
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
// Display sigmas
|
140 |
|
|
TPaveText* myblock = new TPaveText(0.65,0.65-(0.04*histos.size()),0.90,0.65,"NDC");
|
141 |
|
|
myblock->SetBorderSize(0);
|
142 |
|
|
myblock->SetFillColor(0);
|
143 |
|
|
for (unsigned int i=0;i<sigmas.size();i++)
|
144 |
|
|
{
|
145 |
|
|
std::stringstream str;
|
146 |
|
|
str << "#sigma_{" << histos[i].shortName <<"} = ";
|
147 |
cgoetzma |
1.10 |
str.precision(2); str.setf(ios_base::scientific); str << sigmas[i];
|
148 |
econte |
1.5 |
str << " #pm ";
|
149 |
cgoetzma |
1.10 |
str.precision(1); str.setf(ios_base::scientific); str << errors[i];
|
150 |
econte |
1.5 |
TText* mytext = myblock->AddText(str.str().c_str());
|
151 |
|
|
mytext->SetTextColor(histos[i].linecolor);
|
152 |
|
|
mytext->SetTextAlign(11);
|
153 |
|
|
}
|
154 |
|
|
myblock->Draw();
|
155 |
econte |
1.1 |
}
|
156 |
|
|
|
157 |
|
|
// Save
|
158 |
econte |
1.7 |
std::string filename = GetFileName(title);
|
159 |
econte |
1.1 |
mycanvas->SaveAs((filename+".gif").c_str());
|
160 |
econte |
1.2 |
mycanvas->SaveAs((filename+".root").c_str());
|
161 |
|
|
|
162 |
econte |
1.1 |
}
|
163 |
|
|
|