CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/PhysicsTools/RooStatsCms/src/ExclusionBandPlot.cc

Go to the documentation of this file.
00001 // @(#)root/hist:$Id: ExclusionBandPlot.cc,v 1.4 2009/05/15 09:55:59 dpiparo Exp $
00002 // Author: Danilo.Piparo@cern.ch   01/06/2008
00003 
00004 #include "assert.h"
00005 #include "math.h"
00006 
00007 #if (defined (STANDALONE) or defined (__CINT__) )
00008    #include "ExclusionBandPlot.h"
00009 #else
00010    #include "PhysicsTools/RooStatsCms/interface/ExclusionBandPlot.h"
00011 #endif
00012 #include "TGraphAsymmErrors.h"
00013 #include "TStyle.h"
00014 #include "TAxis.h"
00015 
00016 
00017 //For Cint
00018 #if (defined (STANDALONE) or defined (__CINT__) )
00019 ClassImp(ExclusionBandPlot)
00020 #endif
00021 /*----------------------------------------------------------------------------*/
00022 ExclusionBandPlot::ExclusionBandPlot(const char* name,
00023                                      const char* title,
00024                                      const int n_points,
00025                                      double* x_vals,
00026                                      double* y_vals,
00027                                      double* y_up_points1,
00028                                      double* y_down_points1,
00029                                      double* y_up_points2,
00030                                      double* y_down_points2):
00031                     StatisticalPlot(name,title,false){
00032 
00033     // Prepare errorbars
00034     double* y_down_bars2 = new double[n_points];
00035     double* y_down_bars1 = new double[n_points];
00036     double* y_up_bars1 = new double[n_points];
00037     double* y_up_bars2 = new double[n_points];
00038 
00039     for (int i=0;i<n_points;++i){
00040         y_down_bars2[i]=y_vals[i]-y_down_points2[i];
00041         y_down_bars1[i]=y_vals[i]-y_down_points1[i];
00042         y_up_bars2[i]=y_up_points2[i]-y_vals[i];
00043         y_up_bars1[i]=y_up_points1[i]-y_vals[i];
00044         }
00045 
00046     // bline
00047     m_y_line_graph = new TGraph(n_points, x_vals, y_vals);
00048     m_y_line_graph->SetLineWidth(2);
00049     m_y_line_graph->SetLineStyle(2);
00050     m_y_line_graph->SetFillColor(kWhite);
00051 
00052 
00053 
00054     // y band 1 sigma
00055     m_y_band_graph_1sigma = new TGraphAsymmErrors(n_points,
00056                                                   x_vals,
00057                                                   y_vals,
00058                                                   0,
00059                                                   0,
00060                                                   y_down_bars1,
00061                                                   y_up_bars1);
00062     m_y_band_graph_1sigma->SetFillColor(kGreen);
00063     m_y_band_graph_1sigma->SetLineColor(kGreen);
00064     m_y_band_graph_1sigma->SetMarkerColor(kGreen);
00065 
00066     // y band 2 sigma
00067     m_y_band_graph_2sigma = new TGraphAsymmErrors(n_points,
00068                                                   x_vals,
00069                                                   y_vals,
00070                                                   0,
00071                                                   0,
00072                                                   y_down_bars2,
00073                                                   y_up_bars2);
00074     m_y_band_graph_2sigma->SetFillColor(kYellow);
00075     m_y_band_graph_2sigma->SetFillColor(kYellow);
00076     m_y_band_graph_2sigma->SetLineColor(kYellow);
00077     m_y_band_graph_2sigma->SetMarkerColor(kYellow);
00078     m_y_band_graph_2sigma->GetYaxis()->SetTitle("#sigma/#sigma_{SM}");
00079 
00080     // Line for 1
00081     m_one_line = new TLine(m_y_line_graph->GetXaxis()->GetXmin(),1,
00082                            m_y_line_graph->GetXaxis()->GetXmax(),1);
00083 
00084     // The legend 
00085 
00086     m_legend = new TLegend(0.60,0.78,0.98,0.98);
00087     m_legend->SetName("SM exclusion");
00088     m_legend->AddEntry(m_y_band_graph_1sigma,"#pm 1#sigma");
00089     m_legend->AddEntry(m_y_band_graph_2sigma,"#pm 2#sigma");
00090     m_legend->AddEntry(m_y_line_graph,title);
00091 
00092     m_legend->SetFillColor(0);
00093 
00094     delete[] y_down_bars2;
00095     delete[] y_down_bars1;
00096     delete[] y_up_bars2;
00097     delete[] y_up_bars1;
00098 
00099     }
00100 
00101 /*----------------------------------------------------------------------------*/
00102 
00103 ExclusionBandPlot::~ExclusionBandPlot(){
00104 
00105     delete m_y_line_graph;
00106 
00107     delete m_y_band_graph_1sigma;
00108     delete m_y_band_graph_2sigma;
00109 
00110     delete m_one_line;
00111 
00112     delete m_legend;
00113 
00114     }
00115 
00116 /*----------------------------------------------------------------------------*/
00117 
00122 void ExclusionBandPlot::setXaxisTitle(const char* title){
00123         m_y_band_graph_2sigma->GetXaxis()->SetTitle(title);
00124         }
00125 
00126 /*----------------------------------------------------------------------------*/
00127 
00132 void ExclusionBandPlot::setYaxisTitle(const char* title){
00133         m_y_band_graph_2sigma->GetYaxis()->SetTitle(title);
00134         }
00135 
00136 /*----------------------------------------------------------------------------*/
00137 
00142 void ExclusionBandPlot::setTitle(const char* title){
00143     m_y_band_graph_2sigma->SetTitle(title);
00144     }
00145 
00146 /*----------------------------------------------------------------------------*/
00147 
00148 void ExclusionBandPlot::draw (const char* options){
00149 
00150     setCanvas(new TCanvas(GetName(),GetTitle()));
00151     getCanvas()->cd();
00152 
00153     getCanvas()->SetGridx();
00154     getCanvas()->SetGridy();
00155 
00156     TString opt(options);
00157     // Bands
00158     if (opt.Contains("4")==0){
00159         m_y_band_graph_2sigma->Draw("A3");
00160         m_y_band_graph_1sigma->Draw("3");
00161         }
00162     else{
00163         m_y_band_graph_2sigma->Draw("A4");
00164         m_y_band_graph_1sigma->Draw("4");
00165         }
00166 
00167     // Lines
00168     if (opt.Contains("4")==0){
00169         m_y_line_graph->Draw("L");
00170     }
00171     else{
00172         m_y_line_graph->Draw("C");
00173     }
00174 
00175     m_one_line->Draw("Same");
00176 
00177     // Legend
00178     m_legend->Draw("Same");
00179 
00180     }
00181 
00182 /*----------------------------------------------------------------------------*/
00183 
00184 void ExclusionBandPlot::dumpToFile (const char* RootFileName, const char* options){
00185 
00186     TFile ofile(RootFileName,options);
00187     ofile.cd();
00188 
00189     // Bands
00190     m_y_band_graph_2sigma->Write("band_2sigma");
00191     m_y_band_graph_1sigma->Draw("band_1sigma");
00192 
00193     // Lines
00194     m_y_line_graph->Draw("line");
00195 
00196     // Legend
00197     m_legend->Draw("IamTheLegend");
00198 
00199     ofile.Close();
00200 
00201     }
00202 
00203 /*----------------------------------------------------------------------------*/
00204 
00205 void ExclusionBandPlot::print (const char* options){
00206     std::cout << "\nExclusionBandPlot object " << GetName() << ":\n";
00207     }
00208 
00209 /*----------------------------------------------------------------------------*/
00210 // Automatically converted from the standalone version Wed Apr 15 11:36:34 2009