CMS 3D CMS Logo

ExclusionBandPlot.cc
Go to the documentation of this file.
1 // Author: Danilo.Piparo@cern.ch 01/06/2008
2 
3 #include <cassert>
4 #include <cmath>
5 
6 #if (defined(STANDALONE) or defined(__CINT__))
7 #include "ExclusionBandPlot.h"
8 #else
10 #endif
11 #include "TGraphAsymmErrors.h"
12 #include "TStyle.h"
13 #include "TAxis.h"
14 
15 //For Cint
16 #if (defined(STANDALONE) or defined(__CINT__))
18 #endif
19 /*----------------------------------------------------------------------------*/
21  const char* title,
22  const int n_points,
23  double* x_vals,
24  double* y_vals,
25  double* y_up_points1,
26  double* y_down_points1,
27  double* y_up_points2,
28  double* y_down_points2)
29  : StatisticalPlot(name, title, false) {
30  // Prepare errorbars
31  double* y_down_bars2 = new double[n_points];
32  double* y_down_bars1 = new double[n_points];
33  double* y_up_bars1 = new double[n_points];
34  double* y_up_bars2 = new double[n_points];
35 
36  for (int i = 0; i < n_points; ++i) {
37  y_down_bars2[i] = y_vals[i] - y_down_points2[i];
38  y_down_bars1[i] = y_vals[i] - y_down_points1[i];
39  y_up_bars2[i] = y_up_points2[i] - y_vals[i];
40  y_up_bars1[i] = y_up_points1[i] - y_vals[i];
41  }
42 
43  // bline
44  m_y_line_graph = new TGraph(n_points, x_vals, y_vals);
45  m_y_line_graph->SetLineWidth(2);
46  m_y_line_graph->SetLineStyle(2);
47  m_y_line_graph->SetFillColor(kWhite);
48 
49  // y band 1 sigma
50  m_y_band_graph_1sigma = new TGraphAsymmErrors(n_points, x_vals, y_vals, nullptr, nullptr, y_down_bars1, y_up_bars1);
51  m_y_band_graph_1sigma->SetFillColor(kGreen);
52  m_y_band_graph_1sigma->SetLineColor(kGreen);
53  m_y_band_graph_1sigma->SetMarkerColor(kGreen);
54 
55  // y band 2 sigma
56  m_y_band_graph_2sigma = new TGraphAsymmErrors(n_points, x_vals, y_vals, nullptr, nullptr, y_down_bars2, y_up_bars2);
57  m_y_band_graph_2sigma->SetFillColor(kYellow);
58  m_y_band_graph_2sigma->SetFillColor(kYellow);
59  m_y_band_graph_2sigma->SetLineColor(kYellow);
60  m_y_band_graph_2sigma->SetMarkerColor(kYellow);
61  m_y_band_graph_2sigma->GetYaxis()->SetTitle("#sigma/#sigma_{SM}");
62 
63  // Line for 1
64  m_one_line = new TLine(m_y_line_graph->GetXaxis()->GetXmin(), 1, m_y_line_graph->GetXaxis()->GetXmax(), 1);
65 
66  // The legend
67 
68  m_legend = new TLegend(0.60, 0.78, 0.98, 0.98);
69  m_legend->SetName("SM exclusion");
70  m_legend->AddEntry(m_y_band_graph_1sigma, "#pm 1#sigma");
71  m_legend->AddEntry(m_y_band_graph_2sigma, "#pm 2#sigma");
72  m_legend->AddEntry(m_y_line_graph, title);
73 
74  m_legend->SetFillColor(0);
75 
76  delete[] y_down_bars2;
77  delete[] y_down_bars1;
78  delete[] y_up_bars2;
79  delete[] y_up_bars1;
80 }
81 
82 /*----------------------------------------------------------------------------*/
83 
85  delete m_y_line_graph;
86 
87  delete m_y_band_graph_1sigma;
88  delete m_y_band_graph_2sigma;
89 
90  delete m_one_line;
91 
92  delete m_legend;
93 }
94 
95 /*----------------------------------------------------------------------------*/
96 
101 void ExclusionBandPlot::setXaxisTitle(const char* title) { m_y_band_graph_2sigma->GetXaxis()->SetTitle(title); }
102 
103 /*----------------------------------------------------------------------------*/
104 
109 void ExclusionBandPlot::setYaxisTitle(const char* title) { m_y_band_graph_2sigma->GetYaxis()->SetTitle(title); }
110 
111 /*----------------------------------------------------------------------------*/
112 
117 void ExclusionBandPlot::setTitle(const char* title) { m_y_band_graph_2sigma->SetTitle(title); }
118 
119 /*----------------------------------------------------------------------------*/
120 
121 void ExclusionBandPlot::draw(const char* options) {
122  setCanvas(new TCanvas(GetName(), GetTitle()));
123  getCanvas()->cd();
124 
125  getCanvas()->SetGridx();
126  getCanvas()->SetGridy();
127 
128  TString opt(options);
129  // Bands
130  if (opt.Contains("4") == 0) {
131  m_y_band_graph_2sigma->Draw("A3");
132  m_y_band_graph_1sigma->Draw("3");
133  } else {
134  m_y_band_graph_2sigma->Draw("A4");
135  m_y_band_graph_1sigma->Draw("4");
136  }
137 
138  // Lines
139  if (opt.Contains("4") == 0) {
140  m_y_line_graph->Draw("L");
141  } else {
142  m_y_line_graph->Draw("C");
143  }
144 
145  m_one_line->Draw("Same");
146 
147  // Legend
148  m_legend->Draw("Same");
149 }
150 
151 /*----------------------------------------------------------------------------*/
152 
153 void ExclusionBandPlot::dumpToFile(const char* RootFileName, const char* options) {
154  TFile ofile(RootFileName, options);
155  ofile.cd();
156 
157  // Bands
158  m_y_band_graph_2sigma->Write("band_2sigma");
159  m_y_band_graph_1sigma->Draw("band_1sigma");
160 
161  // Lines
162  m_y_line_graph->Draw("line");
163 
164  // Legend
165  m_legend->Draw("IamTheLegend");
166 
167  ofile.Close();
168 }
169 
170 /*----------------------------------------------------------------------------*/
171 
172 void ExclusionBandPlot::print(const char* options) { std::cout << "\nExclusionBandPlot object " << GetName() << ":\n"; }
173 
174 /*----------------------------------------------------------------------------*/
175 // Automatically converted from the standalone version Wed Apr 15 11:36:34 2009
ClassImp(ExclusionBandPlot)
TGraph * m_y_band_graph_1sigma
The band 1 sigma.
TGraph * m_y_band_graph_2sigma
The band 2 sigma.
TGraph * m_y_line_graph
The line.
void setCanvas(TCanvas *new_canvas)
Set the canvas.
~ExclusionBandPlot() override
Destructor.
void setTitle(const char *title)
Set the title of the plot.
ExclusionBandPlot(const char *name, const char *title, const int n_points, double *x_vals, double *y_vals, double *y_up_bars1, double *y_down_bars1, double *y_up_bars2, double *y_down_bars2)
Constructor.
void setXaxisTitle(const char *title)
Set the title of the x axis.
StatisticalPlot: the base class for the statistical plots.
TLegend * m_legend
The legend.
void setYaxisTitle(const char *title)
Set the title of the x axis.
ExclusionBandPlot: plot a la tevatron for SM eclusion in function of mass.
TLine * m_one_line
The line at 1.
TCanvas * getCanvas()
Get the canvas.
void draw(const char *options="") override
Draw on canvas.
void print(const char *options="") override
Print the relevant information.
void dumpToFile(const char *RootFileName, const char *options) override
All the objects are written to rootfile.