ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/IPHCalignment2/analysis/Layout.cpp
Revision: 1.5
Committed: Mon Nov 28 16:14:23 2011 UTC (13 years, 5 months ago) by econte
Branch: MAIN
Changes since 1.4: +33 -29 lines
Log Message:
Chris bug fix

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