BayesianAnalysisToolkit  0.9.3
Private Attributes | List of all members
BCMTFComparisonTool Class Reference

A helper class for BCMTFAnalysisFacility storing information. More...

#include <BCMTFComparisonTool.h>

Public Member Functions

Constructors and destructors
 BCMTFComparisonTool (const char *name)
 
 ~BCMTFComparisonTool ()
 
Member functions (get)
std::string GetName ()
 
int GetNContributions ()
 
Member functions (miscellaneous methods)
void AddContribution (const char *name, TH1D hist)
 
void AddContribution (const char *name, double centralvalue, double uncertainty)
 
void DrawOverview ()
 
Member functions (output methods)
void PrintHistograms (const char *filename)
 
void PrintOverview (const char *filename)
 

Private Attributes

std::string fName
 
std::vector< std::string > fNameContainer
 
std::vector< TH1D * > fHistogramContainer
 
std::vector< double > fCentralValueContainer
 
std::vector< double > fUncertaintyContainer
 

Detailed Description

A helper class for BCMTFAnalysisFacility storing information.

Author
Daniel Kollar
Kevin Kröninger
Version
1.1
Date
06.2012 This is a helper class for BCMTFAnalysisFacility storing information.

Definition at line 29 of file BCMTFComparisonTool.h.

Constructor & Destructor Documentation

BCMTFComparisonTool::BCMTFComparisonTool ( const char *  name)

The default constructor.

Parameters
nameThe name of the class.

Definition at line 22 of file BCMTFComparisonTool.cxx.

23 {
24  fName = name;
25 }
BCMTFComparisonTool::~BCMTFComparisonTool ( )

The defaul destructor.

Definition at line 28 of file BCMTFComparisonTool.cxx.

29 {
30  for (int i = 0; i < GetNContributions(); ++i) {
31  if (fHistogramContainer.at(i))
32  delete fHistogramContainer.at(i);
33  }
34 }

Member Function Documentation

void BCMTFComparisonTool::AddContribution ( const char *  name,
TH1D  hist 
)

Add a constribution.

Parameters
nameThe name of the contribution.
histThe histogram.

Definition at line 37 of file BCMTFComparisonTool.cxx.

38 {
39  // add name to container
40  fNameContainer.push_back(name);
41 
42  // add histogram to container
43  fHistogramContainer.push_back(new TH1D(hist));
44 
45  // add central value to container
46  fCentralValueContainer.push_back(hist.GetMean());
47 
48  // add uncertainty to container
49  fUncertaintyContainer.push_back(hist.GetRMS());
50 }
void BCMTFComparisonTool::AddContribution ( const char *  name,
double  centralvalue,
double  uncertainty 
)

Add a constribution.

Parameters
nameThe name of the contribution.
centralvalueThe central value.
uncertaintyThe uncertainty.

Definition at line 53 of file BCMTFComparisonTool.cxx.

54 {
55  // add name to container
56  fNameContainer.push_back(name);
57 
58  // add 0 to container
59  fHistogramContainer.push_back(0);
60 
61  // add central value to container
62  fCentralValueContainer.push_back(centralvalue);
63 
64  // add uncertainty to container
65  fUncertaintyContainer.push_back(uncertainty);
66 }
void BCMTFComparisonTool::DrawOverview ( )

Draw an overview.

Definition at line 105 of file BCMTFComparisonTool.cxx.

106 {
107  // get number of contributions
108  int ncontributions = GetNContributions();
109 
110  // create graph
111  TGraphAsymmErrors * graph_contributions = new TGraphAsymmErrors(ncontributions);
112  graph_contributions->SetMarkerStyle(20);
113  graph_contributions->SetMarkerSize(1);
114 
115  // coordinate system
116  double xmin = 0.0;
117  double xmax = 0.0;
118  double xwidth = 0.0;
119  double ymin = -0.5;
120  double ymax = double(ncontributions)-0.5;
121 
122  // ---- fill the graph ---- //
123 
124  // loop over all contributions
125  for (int i = 0; i < ncontributions; ++i) {
126 
127  // get summary information
128  double centralvalue = fCentralValueContainer.at(i);
129  double uncertainty = fUncertaintyContainer.at(i);
130 
131  // update coordinate system
132  if ((centralvalue-uncertainty) < xmin || i == 0)
133  xmin = centralvalue-uncertainty;
134  if ((centralvalue+uncertainty) > xmax || i == 0)
135  xmax = centralvalue+uncertainty;
136  xwidth = xmax - xmin;
137 
138  // set point and error
139  graph_contributions->SetPoint(i, centralvalue, double(ncontributions-i-1));
140  graph_contributions->SetPointError(i, uncertainty, uncertainty, 0, 0);
141  }
142 
143  // ---- do the plotting ---- //
144 
145  // create histogram for axes
146  TH2D * hist_axes = new TH2D("", Form(";%s;", GetName().c_str()), 1, xmin - 0.25 *xwidth, xmax + 1.75 * xwidth, ncontributions, ymin, ymax);
147  hist_axes->SetStats(kFALSE);
148  hist_axes->GetYaxis()->SetNdivisions(0);
149  hist_axes->GetYaxis()->SetTitleOffset(1.0);
150 
151  // create latex
152  TLatex * latex = new TLatex();
153  latex->SetTextSize(0.04);
154  if (ncontributions>=10)
155  latex->SetTextSize(0.02);
156  latex->SetTextAlign(12);
157 
158  // draw
159  hist_axes->Draw();
160  graph_contributions->Draw("SAMEPZ");
161 
162  // loop over all contributions and draw labels
163  for (int i = 0; i < ncontributions; ++i) {
164  latex->DrawLatex(xmax + 0.25 *xwidth, double(ncontributions-i-1), fNameContainer.at(i).c_str());
165  }
166  hist_axes->Draw("SAMEAXIS");
167 
168  // todo: delete objects properly
169 }
std::string BCMTFComparisonTool::GetName ( )
inline
Returns
The name of the class.

Definition at line 52 of file BCMTFComparisonTool.h.

53  { return fName; };
int BCMTFComparisonTool::GetNContributions ( )
inline
Returns
The number of contributions.

Definition at line 57 of file BCMTFComparisonTool.h.

58  { return (int) fHistogramContainer.size(); };
void BCMTFComparisonTool::PrintHistograms ( const char *  filename)

Print all histograms to a file.

Parameters
filenameThe name of the file.

Definition at line 69 of file BCMTFComparisonTool.cxx.

70 {
71  // get number of histograms
72  int nhistograms = (int) fHistogramContainer.size();
73 
74  // create canvas
75  TCanvas * c1 = new TCanvas();
76  c1->cd();
77 
78  // loop over all histograms
79  for (int i = 0; i < nhistograms; ++i) {
80  // get histogram
81  TH1D * hist = fHistogramContainer.at(i);
82 
83  // set color
84  hist->SetLineColor(2+i);
85 
86  // draw histogram
87  if (i == 0) {
88  hist->Draw("HIST");
89  std::cout << " here as well." << std::endl;
90  }
91  else {
92  hist->Draw("SAMEHIST");
93  std::cout << " here as well 2." << std::endl;
94  }
95  }
96 
97  // print canvas
98  c1->Print(filename);
99 
100  // free memory
101  delete c1;
102 }
void BCMTFComparisonTool::PrintOverview ( const char *  filename)

Print an overview to a file.

Parameters
filenameThe name of the file.

Definition at line 172 of file BCMTFComparisonTool.cxx.

173 {
174  // create canvas
175  TCanvas * c1 = new TCanvas();
176  c1->cd();
177 
178  // draw the overview
179  DrawOverview();
180 
181  // print to file
182  c1->Print(filename);
183 }

Member Data Documentation

std::vector<double> BCMTFComparisonTool::fCentralValueContainer
private

A container of central values.

Definition at line 113 of file BCMTFComparisonTool.h.

std::vector<TH1D *> BCMTFComparisonTool::fHistogramContainer
private

A container of TH1D histograms.

Definition at line 109 of file BCMTFComparisonTool.h.

std::string BCMTFComparisonTool::fName
private

The name of the class.

Definition at line 101 of file BCMTFComparisonTool.h.

std::vector<std::string> BCMTFComparisonTool::fNameContainer
private

The names of the contributions.

Definition at line 105 of file BCMTFComparisonTool.h.

std::vector<double> BCMTFComparisonTool::fUncertaintyContainer
private

A container of uncertainties.

Definition at line 117 of file BCMTFComparisonTool.h.


The documentation for this class was generated from the following files: