ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/IPHCalignment2/analysis/Layout.cpp
Revision: 1.2
Committed: Sun Nov 27 11:11:48 2011 UTC (13 years, 5 months ago) by econte
Branch: MAIN
Changes since 1.1: +6 -10 lines
Log Message:
eric changes for Layout

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
77 void Layout::Draw(const std::vector<HistoBlock>& histos,
78 const std::string& xlabel, float K, float MU, float SIG)
79 {
80 // safety
81 if (histos.empty()) return;
82
83 // Create a new canvas
84 TCanvas* mycanvas = new TCanvas((std::string(histos[0].histo->GetName())+
85 "_canvas").c_str(),
86 histos[0].histo->GetTitle());
87
88 // SetLineColor
89 for (unsigned int i=0;i<histos.size();i++)
90 {
91 std::cout << "TEST : " << histos[i].linecolor << std::endl;
92 histos[i].histo->SetLineColor( histos[i].linecolor );
93 }
94
95 // Stack
96 THStack *mystack = new THStack;
97 for (unsigned int i=0;i<histos.size();i++)
98 {
99 mystack->Add( histos[i].histo );
100 }
101 mystack->Draw("nostack");
102
103 // Axis
104 mystack->GetYaxis()->SetTitle("# events");
105 mystack->GetXaxis()->SetTitle(xlabel.c_str());
106 float xmin = mystack->GetXaxis()->GetXmin();
107 float xmax = mystack->GetXaxis()->GetXmin();
108
109 // Draw legend
110 TLegend* mylegend = new TLegend(0.17,0.72,0.43,0.85);
111 mylegend->SetFillColor(0);
112 for (unsigned int i=0;i<histos.size();i++)
113 {
114 mylegend->AddEntry(histos[i].histo,
115 histos[i].algoName.c_str(),"l");
116 }
117 mylegend->Draw();
118
119 // To Fit
120 for (unsigned int i=0;i<histos.size();i++)
121 {
122 TF1* fitter = new TF1(dummy().c_str(),"gaus",xmin,xmax);
123 fitter->SetParameter(0,K);
124 fitter->SetParameter(1,MU);
125 fitter->SetParameter(2,SIG);
126 histos[i].histo->Fit(fitter,"0");
127 }
128
129 // Save
130 std::string filename = GetFileName(histos[0].histo->GetTitle());
131 mycanvas->SaveAs((filename+".gif").c_str());
132 mycanvas->SaveAs((filename+".root").c_str());
133
134 }
135