ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/IPHCalignment2/analysis/Layout.cpp
Revision: 1.9
Committed: Thu Dec 1 13:46:25 2011 UTC (13 years, 5 months ago) by cgoetzma
Branch: MAIN
Changes since 1.8: +1 -2 lines
Log Message:
chris mods

File Contents

# User Rev Content
1 econte 1.1 #include "Layout.h"
2 econte 1.3 #include <sstream>
3     #include <TPaveText.h>
4     #include <TLatex.h>
5 econte 1.1
6     void Layout::DrawInit()
7     {
8 econte 1.4 gStyle->SetCanvasColor(0);
9 econte 1.1 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 cgoetzma 1.9 // gStyle->SetOptStat(0);
21 econte 1.1
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 econte 1.4
74 econte 1.1
75     }
76    
77    
78 econte 1.7 void Layout::Draw(const std::string title, const std::vector<HistoBlock>& histos,
79 econte 1.5 const std::string& xlabel, bool fit, float K, float MU, float SIG)
80 econte 1.1 {
81 econte 1.3 std::cout << "----------------- Draw : " << histos[0].histo->GetName() << std::endl;
82    
83 econte 1.1 // 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     // SetLineColor
91     for (unsigned int i=0;i<histos.size();i++)
92     {
93     histos[i].histo->SetLineColor( histos[i].linecolor );
94     }
95    
96     // Stack
97     THStack *mystack = new THStack;
98     for (unsigned int i=0;i<histos.size();i++)
99     {
100     mystack->Add( histos[i].histo );
101     }
102     mystack->Draw("nostack");
103    
104     // Axis
105     mystack->GetYaxis()->SetTitle("# events");
106     mystack->GetXaxis()->SetTitle(xlabel.c_str());
107     float xmin = mystack->GetXaxis()->GetXmin();
108     float xmax = mystack->GetXaxis()->GetXmin();
109    
110     // Draw legend
111 cgoetzma 1.8 TLegend* mylegend = new TLegend(0.55,0.90-(0.04*histos.size()),0.90,0.90);
112 econte 1.1 mylegend->SetFillColor(0);
113     for (unsigned int i=0;i<histos.size();i++)
114     {
115     mylegend->AddEntry(histos[i].histo,
116     histos[i].algoName.c_str(),"l");
117     }
118     mylegend->Draw();
119    
120 econte 1.3
121 econte 1.5 if (fit)
122 econte 1.3 {
123 econte 1.5 // To Fit
124     std::vector<double> sigmas;
125     std::vector<double> errors;
126     for (unsigned int i=0;i<histos.size();i++)
127     {
128     TF1* fitter = new TF1(dummy().c_str(),"gaus",xmin,xmax);
129     fitter->SetParameter(0,K);
130     fitter->SetParameter(1,MU);
131     fitter->SetParameter(2,SIG);
132     histos[i].histo->Fit(fitter,"0");
133     sigmas.push_back(fitter->GetParameter(2));
134     errors.push_back(fitter->GetParError(2));
135     }
136    
137     // Display sigmas
138     TPaveText* myblock = new TPaveText(0.65,0.65-(0.04*histos.size()),0.90,0.65,"NDC");
139     myblock->SetBorderSize(0);
140     myblock->SetFillColor(0);
141     for (unsigned int i=0;i<sigmas.size();i++)
142     {
143     std::stringstream str;
144     str << "#sigma_{" << histos[i].shortName <<"} = ";
145     str.precision(3); str << sigmas[i];
146     str << " #pm ";
147     str.precision(3); str << errors[i];
148     TText* mytext = myblock->AddText(str.str().c_str());
149     mytext->SetTextColor(histos[i].linecolor);
150     mytext->SetTextAlign(11);
151     }
152     myblock->Draw();
153 econte 1.1 }
154    
155     // Save
156 econte 1.7 std::string filename = GetFileName(title);
157 econte 1.1 mycanvas->SaveAs((filename+".gif").c_str());
158 econte 1.2 mycanvas->SaveAs((filename+".root").c_str());
159    
160 econte 1.1 }
161