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.10 by cgoetzma, Wed Dec 7 18:31:52 2011 UTC

# Line 1 | Line 1
1   #include "Layout.h"
2 <
3 <
2 > #include <sstream>
3 > #include <TPaveText.h>
4 > #include <TLatex.h>
5 > #include <iostream>
6 > using namespace std;
7  
8   void Layout::DrawInit()
9   {
# Line 16 | Line 19 | void Layout::DrawInit()
19    gStyle->SetFrameBorderMode(0);
20    gStyle->SetFrameBorderSize(0);
21    gStyle->SetFrameFillColor(0);
22 <  gStyle->SetOptStat(0);
22 >  //  gStyle->SetOptStat(0);
23  
24    gStyle->SetLabelOffset(0.005,"X");
25    gStyle->SetLabelSize(0.03,"X");
# Line 73 | Line 76 | void Layout::DrawInit()
76  
77   }
78  
76 struct HistoDescription
77 {
78  unsigned int linecolor;
79  std::string algoName;
80 };
81
82
79  
80 < void Layout::Draw(const std::vector<HistoBlock>& histos,
81 <                  std::string& xlabel, float K, float MU, float SIG)
80 > void Layout::Draw(const std::string title, const std::vector<HistoBlock>& histos,
81 >                  const std::string& xlabel, bool fit, float K, float MU, float SIG)
82   {
83 +  std::cout << "----------------- Draw : " << histos[0].histo->GetName() << std::endl;
84 +
85    // safety
86    if (histos.empty()) return;
87  
# Line 91 | Line 89 | void Layout::Draw(const std::vector<Hist
89    TCanvas* mycanvas = new TCanvas((std::string(histos[0].histo->GetName())+
90                                    "_canvas").c_str(),
91                                    histos[0].histo->GetTitle());
94
92    // SetLineColor
93    for (unsigned int i=0;i<histos.size();i++)
94    {
# Line 113 | Line 110 | void Layout::Draw(const std::vector<Hist
110    float xmax = mystack->GetXaxis()->GetXmin();
111  
112    // Draw legend
113 <  TLegend* mylegend = new TLegend(0.17,0.72,0.43,0.85);
113 >  TLegend* mylegend = new TLegend(0.55,0.90-(0.04*histos.size()),0.90,0.90);
114    mylegend->SetFillColor(0);
115    for (unsigned int i=0;i<histos.size();i++)
116    {
# Line 122 | Line 119 | void Layout::Draw(const std::vector<Hist
119    }
120    mylegend->Draw();
121  
122 <  // To Fit
123 <  for (unsigned int i=0;i<histos.size();i++)
122 >
123 >  if (fit)
124    {
125 <    TF1* fitter = new TF1(dummy().c_str(),dummy().c_str(),xmin,xmax);
126 <    fitter->SetParameter(0,K);
127 <    fitter->SetParameter(1,MU);
128 <    fitter->SetParameter(2,SIG);
129 <    histos[i].histo->Fit(fitter,"R+");
125 >    // To Fit
126 >    std::vector<double> sigmas;
127 >    std::vector<double> errors;
128 >    for (unsigned int i=0;i<histos.size();i++)
129 >    {
130 >      TF1* fitter = new TF1(dummy().c_str(),"gaus",-900,900); //or xmin, xmax...
131 >      fitter->SetParameter(0,K);
132 >      fitter->SetParameter(1,MU);
133 >      fitter->SetParameter(2,SIG);
134 >      histos[i].histo->Fit(fitter,"0");
135 >      sigmas.push_back(fitter->GetParameter(2));
136 >      errors.push_back(fitter->GetParError(2));
137 >    }
138 >
139 >    // Display sigmas
140 >    TPaveText* myblock = new TPaveText(0.65,0.65-(0.04*histos.size()),0.90,0.65,"NDC");
141 >    myblock->SetBorderSize(0);
142 >    myblock->SetFillColor(0);
143 >    for (unsigned int i=0;i<sigmas.size();i++)
144 >    {
145 >      std::stringstream str;
146 >      str << "#sigma_{" << histos[i].shortName <<"} = ";
147 >      str.precision(2); str.setf(ios_base::scientific); str << sigmas[i];
148 >      str << " #pm ";
149 >      str.precision(1); str.setf(ios_base::scientific); str << errors[i];
150 >      TText* mytext = myblock->AddText(str.str().c_str());
151 >      mytext->SetTextColor(histos[i].linecolor);
152 >      mytext->SetTextAlign(11);
153 >    }
154 >    myblock->Draw();
155    }
156  
157    // Save
158 <  std::string filename = GetFileName(histos[0].histo->GetTitle());
158 >  std::string filename = GetFileName(title);
159    mycanvas->SaveAs((filename+".gif").c_str());
160 +  mycanvas->SaveAs((filename+".root").c_str());
161 +
162   }
163  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines