Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011
00012 #include <TH1D.h>
00013 #include <TH2D.h>
00014 #include <TCanvas.h>
00015 #include <TGraphAsymmErrors.h>
00016 #include <TLatex.h>
00017
00018 #include "BCMTFComparisonTool.h"
00019
00020
00021 BCMTFComparisonTool::BCMTFComparisonTool(const char * name)
00022 {
00023 fName = name;
00024 }
00025
00026
00027 BCMTFComparisonTool::~BCMTFComparisonTool()
00028 {
00029 for (int i = 0; i < GetNContributions(); ++i) {
00030 if (fHistogramContainer.at(i))
00031 delete fHistogramContainer.at(i);
00032 }
00033 }
00034
00035
00036 void BCMTFComparisonTool::AddContribution(const char * name, TH1D hist)
00037 {
00038
00039 fNameContainer.push_back(name);
00040
00041
00042 fHistogramContainer.push_back(new TH1D(hist));
00043
00044
00045 fCentralValueContainer.push_back(hist.GetMean());
00046
00047
00048 fUncertaintyContainer.push_back(hist.GetRMS());
00049 }
00050
00051
00052 void BCMTFComparisonTool::AddContribution(const char * name, double centralvalue, double uncertainty)
00053 {
00054
00055 fNameContainer.push_back(name);
00056
00057
00058 fHistogramContainer.push_back(0);
00059
00060
00061 fCentralValueContainer.push_back(centralvalue);
00062
00063
00064 fUncertaintyContainer.push_back(uncertainty);
00065 }
00066
00067
00068 void BCMTFComparisonTool::PrintHistograms(const char * filename)
00069 {
00070
00071 int nhistograms = (int) fHistogramContainer.size();
00072
00073
00074 TCanvas * c1 = new TCanvas();
00075 c1->cd();
00076
00077
00078 for (int i = 0; i < nhistograms; ++i) {
00079
00080 TH1D * hist = fHistogramContainer.at(i);
00081
00082
00083 hist->SetLineColor(2+i);
00084
00085
00086 if (i == 0) {
00087 hist->Draw("HIST");
00088 std::cout << " here as well." << std::endl;
00089 }
00090 else {
00091 hist->Draw("SAMEHIST");
00092 std::cout << " here as well 2." << std::endl;
00093 }
00094 }
00095
00096
00097 c1->Print(filename);
00098
00099
00100 delete c1;
00101 }
00102
00103
00104 void BCMTFComparisonTool::DrawOverview()
00105 {
00106
00107 int ncontributions = GetNContributions();
00108
00109
00110 TGraphAsymmErrors * graph_contributions = new TGraphAsymmErrors(ncontributions);
00111 graph_contributions->SetMarkerStyle(20);
00112 graph_contributions->SetMarkerSize(1);
00113
00114
00115 double xmin = 0.0;
00116 double xmax = 0.0;
00117 double xwidth = 0.0;
00118 double ymin = -0.5;
00119 double ymax = double(ncontributions)-0.5;
00120
00121
00122
00123
00124 for (int i = 0; i < ncontributions; ++i) {
00125
00126
00127 double centralvalue = fCentralValueContainer.at(i);
00128 double uncertainty = fUncertaintyContainer.at(i);
00129
00130
00131 if ((centralvalue-uncertainty) < xmin || i == 0)
00132 xmin = centralvalue-uncertainty;
00133 if ((centralvalue+uncertainty) > xmax || i == 0)
00134 xmax = centralvalue+uncertainty;
00135 xwidth = xmax - xmin;
00136
00137
00138 graph_contributions->SetPoint(i, centralvalue, double(ncontributions-i-1));
00139 graph_contributions->SetPointError(i, uncertainty, uncertainty, 0, 0);
00140 }
00141
00142
00143
00144
00145 TH2D * hist_axes = new TH2D("", Form(";%s;", GetName().c_str()), 1, xmin - 0.25 *xwidth, xmax + 1.75 * xwidth, ncontributions, ymin, ymax);
00146 hist_axes->SetStats(kFALSE);
00147 hist_axes->GetYaxis()->SetNdivisions(0);
00148 hist_axes->GetYaxis()->SetTitleOffset(1.0);
00149
00150
00151 TLatex * latex = new TLatex();
00152 latex->SetTextSize(0.04);
00153 if (ncontributions>=10)
00154 latex->SetTextSize(0.02);
00155 latex->SetTextAlign(12);
00156
00157
00158 hist_axes->Draw();
00159 graph_contributions->Draw("SAMEPZ");
00160
00161
00162 for (int i = 0; i < ncontributions; ++i) {
00163 latex->DrawLatex(xmax + 0.25 *xwidth, double(ncontributions-i-1), fNameContainer.at(i).c_str());
00164 }
00165 hist_axes->Draw("SAMEAXIS");
00166
00167
00168
00169 }
00170
00171
00172 void BCMTFComparisonTool::PrintOverview(const char * filename)
00173 {
00174
00175 TCanvas * c1 = new TCanvas();
00176 c1->cd();
00177
00178
00179 DrawOverview();
00180
00181
00182 c1->Print(filename);
00183 }
00184
00185