• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

BCMTFComparisonTool.cxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008-2012, Daniel Kollar and Kevin Kroeninger.
00003  * All rights reserved.
00004  *
00005  * For the licensing terms see doc/COPYING.
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    // add name to container
00039    fNameContainer.push_back(name);
00040 
00041    // add histogram to container
00042    fHistogramContainer.push_back(new TH1D(hist));
00043 
00044    // add central value to container
00045    fCentralValueContainer.push_back(hist.GetMean());
00046 
00047    // add uncertainty to container
00048    fUncertaintyContainer.push_back(hist.GetRMS());
00049 }
00050 
00051 // ---------------------------------------------------------
00052 void BCMTFComparisonTool::AddContribution(const char * name, double centralvalue, double uncertainty)
00053 {
00054    // add name to container
00055    fNameContainer.push_back(name);
00056 
00057    // add 0 to container
00058    fHistogramContainer.push_back(0);
00059 
00060    // add central value to container
00061    fCentralValueContainer.push_back(centralvalue);
00062 
00063    // add uncertainty to container
00064    fUncertaintyContainer.push_back(uncertainty);
00065 }
00066 
00067 // ---------------------------------------------------------
00068 void BCMTFComparisonTool::PrintHistograms(const char * filename)
00069 {
00070    // get number of histograms
00071    int nhistograms = (int) fHistogramContainer.size();
00072 
00073    // create canvas
00074    TCanvas * c1 = new TCanvas();
00075    c1->cd();
00076 
00077    // loop over all histograms
00078    for (int i = 0; i < nhistograms; ++i) {
00079       // get histogram
00080       TH1D * hist = fHistogramContainer.at(i);
00081 
00082       // set color
00083       hist->SetLineColor(2+i);
00084 
00085       // draw histogram
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    // print canvas
00097    c1->Print(filename);
00098 
00099    // free memory
00100    delete c1;
00101 }
00102 
00103 // ---------------------------------------------------------
00104 void BCMTFComparisonTool::DrawOverview()
00105 {
00106    // get number of contributions
00107    int ncontributions = GetNContributions();
00108 
00109    // create graph
00110    TGraphAsymmErrors * graph_contributions = new TGraphAsymmErrors(ncontributions);
00111    graph_contributions->SetMarkerStyle(20);
00112    graph_contributions->SetMarkerSize(1);
00113 
00114    // coordinate system
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    // ---- fill the graph ---- //
00122 
00123    // loop over all contributions
00124    for (int i = 0; i < ncontributions; ++i) {
00125 
00126       // get summary information
00127       double centralvalue = fCentralValueContainer.at(i);
00128       double uncertainty  = fUncertaintyContainer.at(i);
00129 
00130       // update coordinate system
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       // set point and error
00138       graph_contributions->SetPoint(i, centralvalue, double(ncontributions-i-1));
00139       graph_contributions->SetPointError(i, uncertainty, uncertainty, 0, 0);
00140    }
00141 
00142    // ---- do the plotting ---- //
00143 
00144    // create histogram for axes
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    // create latex
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    // draw
00158    hist_axes->Draw();
00159    graph_contributions->Draw("SAMEPZ");
00160 
00161    // loop over all contributions and draw labels
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    // debugKK
00168    // stuff doesn't get deleted
00169 }
00170 
00171 // ---------------------------------------------------------
00172 void BCMTFComparisonTool::PrintOverview(const char * filename)
00173 {
00174    // create canvas
00175    TCanvas * c1 = new TCanvas();
00176    c1->cd();
00177 
00178    // draw the overview
00179    DrawOverview();
00180 
00181    // print to file
00182    c1->Print(filename);
00183 }
00184 
00185 // ---------------------------------------------------------

Generated by  doxygen 1.7.1