ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/IPHCalignment2/analysis/Layout.cpp
(Generate patch)

Comparing UserCode/IPHCalignment2/analysis/Layout.cpp (file contents):
Revision 1.1 by econte, Sun Nov 27 09:57:20 2011 UTC vs.
Revision 1.9 by cgoetzma, Thu Dec 1 13:46:25 2011 UTC

# Line 1 | Line 1
1   #include "Layout.h"
2 <
3 <
2 > #include <sstream>
3 > #include <TPaveText.h>
4 > #include <TLatex.h>
5  
6   void Layout::DrawInit()
7   {
# Line 16 | Line 17 | void Layout::DrawInit()
17    gStyle->SetFrameBorderMode(0);
18    gStyle->SetFrameBorderSize(0);
19    gStyle->SetFrameFillColor(0);
20 <  gStyle->SetOptStat(0);
20 >  //  gStyle->SetOptStat(0);
21  
22    gStyle->SetLabelOffset(0.005,"X");
23    gStyle->SetLabelSize(0.03,"X");
# Line 73 | Line 74 | void Layout::DrawInit()
74  
75   }
76  
76 struct HistoDescription
77 {
78  unsigned int linecolor;
79  std::string algoName;
80 };
81
82
77  
78 < void Layout::Draw(const std::vector<HistoBlock>& histos,
79 <                  std::string& xlabel, float K, float MU, float SIG)
78 > void Layout::Draw(const std::string title, const std::vector<HistoBlock>& histos,
79 >                  const std::string& xlabel, bool fit, 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  
# Line 91 | Line 87 | void Layout::Draw(const std::vector<Hist
87    TCanvas* mycanvas = new TCanvas((std::string(histos[0].histo->GetName())+
88                                    "_canvas").c_str(),
89                                    histos[0].histo->GetTitle());
94
90    // SetLineColor
91    for (unsigned int i=0;i<histos.size();i++)
92    {
# Line 113 | Line 108 | void Layout::Draw(const std::vector<Hist
108    float xmax = mystack->GetXaxis()->GetXmin();
109  
110    // Draw legend
111 <  TLegend* mylegend = new TLegend(0.17,0.72,0.43,0.85);
111 >  TLegend* mylegend = new TLegend(0.55,0.90-(0.04*histos.size()),0.90,0.90);
112    mylegend->SetFillColor(0);
113    for (unsigned int i=0;i<histos.size();i++)
114    {
# Line 122 | Line 117 | void Layout::Draw(const std::vector<Hist
117    }
118    mylegend->Draw();
119  
120 <  // To Fit
121 <  for (unsigned int i=0;i<histos.size();i++)
120 >
121 >  if (fit)
122    {
123 <    TF1* fitter = new TF1(dummy().c_str(),dummy().c_str(),xmin,xmax);
124 <    fitter->SetParameter(0,K);
125 <    fitter->SetParameter(1,MU);
126 <    fitter->SetParameter(2,SIG);
127 <    histos[i].histo->Fit(fitter,"R+");
123 >    // 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    }
154  
155    // Save
156 <  std::string filename = GetFileName(histos[0].histo->GetTitle());
156 >  std::string filename = GetFileName(title);
157    mycanvas->SaveAs((filename+".gif").c_str());
158 +  mycanvas->SaveAs((filename+".root").c_str());
159 +
160   }
161  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines