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 
16 //For Cint
17 #if (defined (STANDALONE) or defined (__CINT__) )
19 #endif
20 /*----------------------------------------------------------------------------*/
22  const char* title,
23  const int n_points,
24  double* x_vals,
25  double* y_vals,
26  double* y_up_points1,
27  double* y_down_points1,
28  double* y_up_points2,
29  double* y_down_points2):
30  StatisticalPlot(name,title,false){
31 
32  // Prepare errorbars
33  double* y_down_bars2 = new double[n_points];
34  double* y_down_bars1 = new double[n_points];
35  double* y_up_bars1 = new double[n_points];
36  double* y_up_bars2 = new double[n_points];
37 
38  for (int i=0;i<n_points;++i){
39  y_down_bars2[i]=y_vals[i]-y_down_points2[i];
40  y_down_bars1[i]=y_vals[i]-y_down_points1[i];
41  y_up_bars2[i]=y_up_points2[i]-y_vals[i];
42  y_up_bars1[i]=y_up_points1[i]-y_vals[i];
43  }
44 
45  // bline
46  m_y_line_graph = new TGraph(n_points, x_vals, y_vals);
47  m_y_line_graph->SetLineWidth(2);
48  m_y_line_graph->SetLineStyle(2);
49  m_y_line_graph->SetFillColor(kWhite);
50 
51 
52 
53  // y band 1 sigma
54  m_y_band_graph_1sigma = new TGraphAsymmErrors(n_points,
55  x_vals,
56  y_vals,
57  nullptr,
58  nullptr,
59  y_down_bars1,
60  y_up_bars1);
61  m_y_band_graph_1sigma->SetFillColor(kGreen);
62  m_y_band_graph_1sigma->SetLineColor(kGreen);
63  m_y_band_graph_1sigma->SetMarkerColor(kGreen);
64 
65  // y band 2 sigma
66  m_y_band_graph_2sigma = new TGraphAsymmErrors(n_points,
67  x_vals,
68  y_vals,
69  nullptr,
70  nullptr,
71  y_down_bars2,
72  y_up_bars2);
73  m_y_band_graph_2sigma->SetFillColor(kYellow);
74  m_y_band_graph_2sigma->SetFillColor(kYellow);
75  m_y_band_graph_2sigma->SetLineColor(kYellow);
76  m_y_band_graph_2sigma->SetMarkerColor(kYellow);
77  m_y_band_graph_2sigma->GetYaxis()->SetTitle("#sigma/#sigma_{SM}");
78 
79  // Line for 1
80  m_one_line = new TLine(m_y_line_graph->GetXaxis()->GetXmin(),1,
81  m_y_line_graph->GetXaxis()->GetXmax(),1);
82 
83  // The legend
84 
85  m_legend = new TLegend(0.60,0.78,0.98,0.98);
86  m_legend->SetName("SM exclusion");
87  m_legend->AddEntry(m_y_band_graph_1sigma,"#pm 1#sigma");
88  m_legend->AddEntry(m_y_band_graph_2sigma,"#pm 2#sigma");
89  m_legend->AddEntry(m_y_line_graph,title);
90 
91  m_legend->SetFillColor(0);
92 
93  delete[] y_down_bars2;
94  delete[] y_down_bars1;
95  delete[] y_up_bars2;
96  delete[] y_up_bars1;
97 
98  }
99 
100 /*----------------------------------------------------------------------------*/
101 
103 
104  delete m_y_line_graph;
105 
106  delete m_y_band_graph_1sigma;
107  delete m_y_band_graph_2sigma;
108 
109  delete m_one_line;
110 
111  delete m_legend;
112 
113  }
114 
115 /*----------------------------------------------------------------------------*/
116 
122  m_y_band_graph_2sigma->GetXaxis()->SetTitle(title);
123  }
124 
125 /*----------------------------------------------------------------------------*/
126 
132  m_y_band_graph_2sigma->GetYaxis()->SetTitle(title);
133  }
134 
135 /*----------------------------------------------------------------------------*/
136 
142  m_y_band_graph_2sigma->SetTitle(title);
143  }
144 
145 /*----------------------------------------------------------------------------*/
146 
147 void ExclusionBandPlot::draw (const char* options){
148 
149  setCanvas(new TCanvas(GetName(),GetTitle()));
150  getCanvas()->cd();
151 
152  getCanvas()->SetGridx();
153  getCanvas()->SetGridy();
154 
155  TString opt(options);
156  // Bands
157  if (opt.Contains("4")==0){
158  m_y_band_graph_2sigma->Draw("A3");
159  m_y_band_graph_1sigma->Draw("3");
160  }
161  else{
162  m_y_band_graph_2sigma->Draw("A4");
163  m_y_band_graph_1sigma->Draw("4");
164  }
165 
166  // Lines
167  if (opt.Contains("4")==0){
168  m_y_line_graph->Draw("L");
169  }
170  else{
171  m_y_line_graph->Draw("C");
172  }
173 
174  m_one_line->Draw("Same");
175 
176  // Legend
177  m_legend->Draw("Same");
178 
179  }
180 
181 /*----------------------------------------------------------------------------*/
182 
183 void ExclusionBandPlot::dumpToFile (const char* RootFileName, const char* options){
184 
185  TFile ofile(RootFileName,options);
186  ofile.cd();
187 
188  // Bands
189  m_y_band_graph_2sigma->Write("band_2sigma");
190  m_y_band_graph_1sigma->Draw("band_1sigma");
191 
192  // Lines
193  m_y_line_graph->Draw("line");
194 
195  // Legend
196  m_legend->Draw("IamTheLegend");
197 
198  ofile.Close();
199 
200  }
201 
202 /*----------------------------------------------------------------------------*/
203 
205  std::cout << "\nExclusionBandPlot object " << GetName() << ":\n";
206  }
207 
208 /*----------------------------------------------------------------------------*/
209 // 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.