ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/IPHCalignment2/analysis/Layout.cpp
Revision: 1.3
Committed: Mon Nov 28 13:18:09 2011 UTC (13 years, 5 months ago) by econte
Branch: MAIN
Changes since 1.2: +32 -5 lines
Log Message:
Layout bug fix

File Contents

# Content
1 #include "Layout.h"
2 #include <sstream>
3 #include <TPaveText.h>
4 #include <TLatex.h>
5
6 void Layout::DrawInit()
7 {
8 /* gStyle->SetCanvasColor(0);
9 gStyle->SetCanvasBorderMode(0);
10 gStyle->SetCanvasBorderSize(3);
11
12 gStyle->SetPadLeftMargin(0.125);
13 gStyle->SetPadBottomMargin(0.12);
14 gStyle->SetPadColor(0);
15 gStyle->SetPadBorderMode(0);
16
17 gStyle->SetFrameBorderMode(0);
18 gStyle->SetFrameBorderSize(0);
19 gStyle->SetFrameFillColor(0);
20 gStyle->SetOptStat(0);
21
22 gStyle->SetLabelOffset(0.005,"X");
23 gStyle->SetLabelSize(0.03,"X");
24 gStyle->SetLabelFont(22,"X");
25
26 gStyle->SetTitleOffset(1.1,"X");
27 gStyle->SetTitleSize(0.04,"X");
28 gStyle->SetTitleFont(22,"X");
29
30 gStyle->SetLabelOffset(0.005,"Y");
31 gStyle->SetLabelSize(0.03,"Y");
32 gStyle->SetLabelFont(22,"Y");
33
34 gStyle->SetTitleOffset(1.1,"Y");
35 gStyle->SetTitleSize(0.04,"Y");
36 gStyle->SetTitleFont(22,"Y");
37
38 gStyle->SetStatColor(0);
39 gStyle->SetStatBorderSize(0);
40
41 gStyle->SetTextFont(2);
42 gStyle->SetTextSize(.05);
43
44 gStyle->SetLegendBorderSize(1);
45
46 gStyle->SetHistLineWidth(2);
47
48 gStyle->SetTitleFillColor(0);
49 gStyle->SetTitleFontSize(0.05);
50 gStyle->SetTitleBorderSize(0);
51 gStyle->SetTitleAlign(13);
52 gStyle->SetTextAlign(22);
53
54 //Canvas declaration and configuration
55 // TCanvas *c1 = new TCanvas("c1", "plots",200,10,800,600);
56
57 //General ROOT style setup
58 gStyle->SetOptDate(0);
59 gStyle->SetStatColor(0);
60 gStyle->SetTitleColor(1);
61 gStyle->SetOptStat(0);
62 gStyle->SetPalette(1);
63
64 const Int_t NRGBs = 5;
65 const Int_t NCont = 255;
66
67 Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
68 Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
69 Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
70 Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
71 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
72 gStyle->SetNumberContours(NCont);
73 */
74
75 }
76
77
78 void Layout::Draw(const std::vector<HistoBlock>& histos,
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
86 // Create a new canvas
87 TCanvas* mycanvas = new TCanvas((std::string(histos[0].histo->GetName())+
88 "_canvas").c_str(),
89 histos[0].histo->GetTitle());
90
91 // SetLineColor
92 for (unsigned int i=0;i<histos.size();i++)
93 {
94 std::cout << "TEST : " << histos[i].linecolor << std::endl;
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 TLegend* mylegend = new TLegend(0.17,0.85-(0.04*histos.size()),0.33,0.85);
114 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 std::cout << "size = " << mylegend->GetTextSize() << std::endl;
122 std::cout << "font = " << mylegend->GetTextFont() << std::endl;
123
124 std::cout << mylegend->GetX1() << " " << mylegend->GetX2() << std::endl;
125 std::cout << mylegend->GetY1() << " " << mylegend->GetY2() << std::endl;
126
127 TPaveText* toto = new TPaveText(0.17,0.72,0.43,0.83);
128 toto->SetFillColor(2);
129 toto->SetTextFont(2);
130 toto->SetTextSize(0);
131 toto->AddText("toto");
132 toto->Draw();
133
134 // To Fit
135 std::vector<double> sigmas;
136 for (unsigned int i=0;i<histos.size();i++)
137 {
138 TF1* fitter = new TF1(dummy().c_str(),"gaus",xmin,xmax);
139 fitter->SetParameter(0,K);
140 fitter->SetParameter(1,MU);
141 fitter->SetParameter(2,SIG);
142 histos[i].histo->Fit(fitter,"0");
143 sigmas.push_back(fitter->GetParameter(2));
144 }
145
146 // Display sigmas
147 for (unsigned int i=0;i<sigmas.size();i++)
148 {
149 std::stringstream str;
150 str << "#sigma_{RECO} = ";
151 str << sigmas[i];
152 TLatex mytext(56,200,str.str().c_str());
153 std::cout << mycanvas->GetXlowNDC() << " " << mycanvas->GetWNDC() << std::endl;
154 }
155
156 // Save
157 std::string filename = GetFileName(histos[0].histo->GetTitle());
158 mycanvas->SaveAs((filename+".gif").c_str());
159 mycanvas->SaveAs((filename+".root").c_str());
160
161 }
162