ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/IPHCalignment2/analysis/Layout.cpp
Revision: 1.1
Committed: Sun Nov 27 09:57:20 2011 UTC (13 years, 5 months ago) by econte
Branch: MAIN
Log Message:
Layout add

File Contents

# Content
1 #include "Layout.h"
2
3
4
5 void Layout::DrawInit()
6 {
7 gStyle->SetCanvasColor(0);
8 gStyle->SetCanvasBorderMode(0);
9 gStyle->SetCanvasBorderSize(3);
10
11 gStyle->SetPadLeftMargin(0.125);
12 gStyle->SetPadBottomMargin(0.12);
13 gStyle->SetPadColor(0);
14 gStyle->SetPadBorderMode(0);
15
16 gStyle->SetFrameBorderMode(0);
17 gStyle->SetFrameBorderSize(0);
18 gStyle->SetFrameFillColor(0);
19 gStyle->SetOptStat(0);
20
21 gStyle->SetLabelOffset(0.005,"X");
22 gStyle->SetLabelSize(0.03,"X");
23 gStyle->SetLabelFont(22,"X");
24
25 gStyle->SetTitleOffset(1.1,"X");
26 gStyle->SetTitleSize(0.04,"X");
27 gStyle->SetTitleFont(22,"X");
28
29 gStyle->SetLabelOffset(0.005,"Y");
30 gStyle->SetLabelSize(0.03,"Y");
31 gStyle->SetLabelFont(22,"Y");
32
33 gStyle->SetTitleOffset(1.1,"Y");
34 gStyle->SetTitleSize(0.04,"Y");
35 gStyle->SetTitleFont(22,"Y");
36
37 gStyle->SetStatColor(0);
38 gStyle->SetStatBorderSize(0);
39
40 gStyle->SetTextFont(2);
41 gStyle->SetTextSize(.05);
42
43 gStyle->SetLegendBorderSize(1);
44
45 gStyle->SetHistLineWidth(2);
46
47 gStyle->SetTitleFillColor(0);
48 gStyle->SetTitleFontSize(0.05);
49 gStyle->SetTitleBorderSize(0);
50 gStyle->SetTitleAlign(13);
51 gStyle->SetTextAlign(22);
52
53 //Canvas declaration and configuration
54 // TCanvas *c1 = new TCanvas("c1", "plots",200,10,800,600);
55
56 //General ROOT style setup
57 gStyle->SetOptDate(0);
58 gStyle->SetStatColor(0);
59 gStyle->SetTitleColor(1);
60 gStyle->SetOptStat(0);
61 gStyle->SetPalette(1);
62
63 const Int_t NRGBs = 5;
64 const Int_t NCont = 255;
65
66 Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
67 Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
68 Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
69 Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
70 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
71 gStyle->SetNumberContours(NCont);
72
73
74 }
75
76 struct HistoDescription
77 {
78 unsigned int linecolor;
79 std::string algoName;
80 };
81
82
83
84 void Layout::Draw(const std::vector<HistoBlock>& histos,
85 std::string& xlabel, float K, float MU, float SIG)
86 {
87 // safety
88 if (histos.empty()) return;
89
90 // Create a new canvas
91 TCanvas* mycanvas = new TCanvas((std::string(histos[0].histo->GetName())+
92 "_canvas").c_str(),
93 histos[0].histo->GetTitle());
94
95 // SetLineColor
96 for (unsigned int i=0;i<histos.size();i++)
97 {
98 histos[i].histo->SetLineColor( histos[i].linecolor );
99 }
100
101 // Stack
102 THStack *mystack = new THStack;
103 for (unsigned int i=0;i<histos.size();i++)
104 {
105 mystack->Add( histos[i].histo );
106 }
107 mystack->Draw("nostack");
108
109 // Axis
110 mystack->GetYaxis()->SetTitle("# events");
111 mystack->GetXaxis()->SetTitle(xlabel.c_str());
112 float xmin = mystack->GetXaxis()->GetXmin();
113 float xmax = mystack->GetXaxis()->GetXmin();
114
115 // Draw legend
116 TLegend* mylegend = new TLegend(0.17,0.72,0.43,0.85);
117 mylegend->SetFillColor(0);
118 for (unsigned int i=0;i<histos.size();i++)
119 {
120 mylegend->AddEntry(histos[i].histo,
121 histos[i].algoName.c_str(),"l");
122 }
123 mylegend->Draw();
124
125 // To Fit
126 for (unsigned int i=0;i<histos.size();i++)
127 {
128 TF1* fitter = new TF1(dummy().c_str(),dummy().c_str(),xmin,xmax);
129 fitter->SetParameter(0,K);
130 fitter->SetParameter(1,MU);
131 fitter->SetParameter(2,SIG);
132 histos[i].histo->Fit(fitter,"R+");
133 }
134
135 // Save
136 std::string filename = GetFileName(histos[0].histo->GetTitle());
137 mycanvas->SaveAs((filename+".gif").c_str());
138 }
139