LOGO

RestFrames  v1.0.1
RestFrames HEP Event Analysis Software Library
RFPlot.cc
Go to the documentation of this file.
1 // RestFrames: particle physics event analysis library
3 // --------------------------------------------------------------------
4 // Copyright (c) 2014-2015, Christopher Rogan
14 // This file is part of RestFrames.
15 //
16 // RestFrames is free software; you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation; either version 2 of the License, or
19 // (at your option) any later version.
20 //
21 // RestFrames is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with RestFrames. If not, see <http://www.gnu.org/licenses/>.
29 
30 #include <TStyle.h>
31 #include <TROOT.h>
32 
33 #include "RestFrames/RFPlot.hh"
34 
35 namespace RestFrames {
36 
37 
38  RFPlot::RFPlot(const std::string& sname,
39  const std::string& stitle)
40  : RFBase(sname, stitle, -1){
41  m_Log.SetSource("RFPlot "+GetName());
42  }
43 
44  RFPlot::~RFPlot(){
45  Clear();
46  }
47 
48  void RFPlot::Clear(){
49  int Ncan = m_Canvases.size();
50  for(int i = 0; i < Ncan; i++)
51  delete m_Canvases[i];
52  m_Canvases.clear();
53  int Nobj = m_TObjects.size();
54  for(int i = 0; i < Nobj; i++)
55  delete m_TObjects[i];
56  m_TObjects.clear();
57  }
58 
59  void RFPlot::WriteOutput(const std::string& filename){
60  int N = m_Canvases.size();
61  if(N <= 0) return;
62 
63  TFile* file = new TFile(filename.c_str(),"UPDATE");
64  file->mkdir(GetName().c_str());
65  file->cd(GetName().c_str());
66  for(int i = 0; i < N; i++)
67  m_Canvases[i]->Write("",TObject::kOverwrite);
68  file->Close();
69  delete file;
70  }
71 
72  void RFPlot::AddCanvas(TCanvas* can){
73  m_Canvases.push_back(can);
74  }
75 
76  void RFPlot::AddTObject(TObject* obj){
77  m_TObjects.push_back(obj);
78  }
79 
80  int RFPlot::GetNCanvases(){
81  return m_Canvases.size();
82  }
83 
84  std::string RFPlot::GetUniqueName(const std::string& name){
85  int count = 0;
86  std::string uniq_name = name;
87  while(gROOT->FindObject(uniq_name.c_str())){
88  std::stringstream i;
89  i << count;
90  uniq_name = name+"_"+i.str();
91  count++;
92  }
93  return uniq_name;
94  }
95 
96  void SetStyle(){
97  SetStyle(false);
98  }
99 
100  void SetStyle(bool invert_colors){
101  // For the canvas:
102  gStyle->SetCanvasBorderMode(0);
103  gStyle->SetCanvasColor(kWhite);
104  gStyle->SetCanvasDefX(0);
105  gStyle->SetCanvasDefY(0);
106 
107  // For the Pad:
108  gStyle->SetPadBorderMode(0);
109  gStyle->SetPadColor(kWhite);
110  gStyle->SetGridColor(0);
111  gStyle->SetGridStyle(3);
112  gStyle->SetGridWidth(1);
113 
114  // For the frame:
115  gStyle->SetFrameBorderMode(0);
116  gStyle->SetFrameBorderSize(1);
117  gStyle->SetFrameFillColor(0);
118  gStyle->SetFrameFillStyle(0);
119  gStyle->SetFrameLineColor(1);
120  gStyle->SetFrameLineStyle(1);
121  gStyle->SetFrameLineWidth(1);
122 
123  // set the paper & margin sizes
124  gStyle->SetPaperSize(20,26);
125  gStyle->SetPadTopMargin(0.09);
126  gStyle->SetPadRightMargin(0.25);
127  gStyle->SetPadBottomMargin(0.18);
128  gStyle->SetPadLeftMargin(0.15);
129 
130  // use large Times-Roman fonts
131  gStyle->SetTitleFont(132,"xyz"); // set the all 3 axes title font
132  gStyle->SetTitleFont(132," "); // set the pad title font
133  gStyle->SetTitleSize(0.06,"xyz"); // set the 3 axes title size
134  gStyle->SetTitleSize(0.06," "); // set the pad title size
135  gStyle->SetLabelFont(132,"xyz");
136  gStyle->SetLabelSize(0.05,"xyz");
137  gStyle->SetLabelColor(1,"xyz");
138  gStyle->SetTextFont(132);
139  gStyle->SetTextSize(0.08);
140  gStyle->SetStatFont(132);
141 
142  // use bold lines and markers
143  gStyle->SetMarkerStyle(8);
144  gStyle->SetHistLineWidth(2);
145  gStyle->SetLineStyleString(2,"[12 12]"); // postscript dashes
146 
147  //..Get rid of X error bars
148  gStyle->SetErrorX(0.001);
149 
150  // do not display any of the standard histogram decorations
151  gStyle->SetOptTitle(0);
152  gStyle->SetOptStat(0);
153  gStyle->SetOptFit(11111111);
154 
155  // put tick marks on top and RHS of plots
156  gStyle->SetPadTickX(1);
157  gStyle->SetPadTickY(1);
158 
159  double zcolor_s[5] = { 0.00, 0.50, 0.70, 0.82, 1.00 };
160  double zcolor_r[5] = { 0.00, 0.00, 0.74, 1.00, 1.00 };
161  double zcolor_g[5] = { 0.00, 0.61, 0.82, 0.70, 1.00 };
162  double zcolor_b[5] = { 0.31, 0.73, 0.08, 0.00, 1.00 };
163  double zcolor_is[5] = { 0.00, 0.15, 0.35, 0.60, 1.00 };
164  double zcolor_ir[5] = { 1.00, 1.00, 0.74, 0.00, 0.00 };
165  double zcolor_ig[5] = { 0.90, 0.70, 0.82, 0.61, 0.00 };
166  double zcolor_ib[5] = { 0.70, 0.00, 0.08, 0.73, 0.31 };
167  for(int i = 0; i < 5; i++){
168  zcolor_s[i] = RFPlot::rf_zcolor_s[i];
169  zcolor_r[i] = RFPlot::rf_zcolor_r[i];
170  zcolor_g[i] = RFPlot::rf_zcolor_g[i];
171  zcolor_b[i] = RFPlot::rf_zcolor_b[i];
172  zcolor_is[i] = RFPlot::rf_zcolor_is[i];
173  zcolor_ir[i] = RFPlot::rf_zcolor_ir[i];
174  zcolor_ig[i] = RFPlot::rf_zcolor_ig[i];
175  zcolor_ib[i] = RFPlot::rf_zcolor_ib[i];
176  }
177 
178  RFPlot::rf_iZPalette = TColor::CreateGradientColorTable(5, zcolor_is, zcolor_ir,
179  zcolor_ig, zcolor_ib,
180  RFPlot::rf_NZPalette);
181  RFPlot::rf_ZPalette = TColor::CreateGradientColorTable(5, zcolor_s, zcolor_r,
182  zcolor_g, zcolor_b,
183  RFPlot::rf_NZPalette);
184  gStyle->cd();
185  }
186 
187  void SetZPalette(bool invert_colors){
188  if(RFPlot::rf_ZPalette <= 0)
189  SetStyle();
190 
191  int palette[RFPlot::rf_NZPalette];
192  if(invert_colors){
193  for(int i = 0; i < RFPlot::rf_NZPalette; i++)
194  palette[i] = RFPlot::rf_iZPalette + i;
195  } else {
196  for(int i = 0; i < RFPlot::rf_NZPalette; i++)
197  palette[i] = RFPlot::rf_ZPalette + i;
198  }
199  gStyle->SetPalette(RFPlot::rf_NZPalette, palette);
200  }
201 
202  const int RFPlot::rf_NZPalette = 28;
203  int RFPlot::rf_ZPalette = 0;
204  int RFPlot::rf_iZPalette = 0;
205  const double RFPlot::rf_zcolor_s[5] = { 0.00, 0.50, 0.70, 0.82, 1.00 };
206  const double RFPlot::rf_zcolor_r[5] = { 0.00, 0.00, 0.74, 1.00, 1.00 };
207  const double RFPlot::rf_zcolor_g[5] = { 0.00, 0.61, 0.82, 0.70, 1.00 };
208  const double RFPlot::rf_zcolor_b[5] = { 0.31, 0.73, 0.08, 0.00, 1.00 };
209  const double RFPlot::rf_zcolor_is[5] = { 0.00, 0.15, 0.35, 0.60, 1.00 };
210  const double RFPlot::rf_zcolor_ir[5] = { 1.00, 1.00, 0.74, 0.00, 0.00 };
211  const double RFPlot::rf_zcolor_ig[5] = { 0.90, 0.70, 0.82, 0.61, 0.00 };
212  const double RFPlot::rf_zcolor_ib[5] = { 0.70, 0.00, 0.08, 0.73, 0.31 };
213 
214  const TColor RFPlot::rf_blue0(7000,0.749,0.78,0.933);
215  const TColor RFPlot::rf_blue1(7001,0.424,0.467,0.651);
216  const TColor RFPlot::rf_blue2(7002,0.255,0.302,0.522);
217  const TColor RFPlot::rf_blue3(7003,0.114,0.165,0.396);
218  const TColor RFPlot::rf_blue4(7004,0.024,0.063,0.251);
219  const TColor RFPlot::rf_green0(7010,0.737,0.949,0.784);
220  const TColor RFPlot::rf_green1(7011,0.435,0.722,0.498);
221  const TColor RFPlot::rf_green2(7012,0.239,0.576,0.314);
222  const TColor RFPlot::rf_green3(7013,0.082,0.439,0.161);
223  const TColor RFPlot::rf_green4(7014,0,0.275,0.063);
224  const TColor RFPlot::rf_red0(7020,1,0.796,0.776);
225  const TColor RFPlot::rf_red1(7021,0.957,0.612,0.576);
226  const TColor RFPlot::rf_red2(7022,0.765,0.361,0.318);
227  const TColor RFPlot::rf_red3(7023,0.58,0.157,0.11);
228  const TColor RFPlot::rf_red4(7024,0.365,0.035,0);
229  const TColor RFPlot::rf_yellow0(7030,1,0.933,0.776);
230  const TColor RFPlot::rf_yellow1(7031,0.957,0.843,0.576);
231  const TColor RFPlot::rf_yellow2(7032,0.765,0.631,0.318);
232  const TColor RFPlot::rf_yellow3(7033,0.58,0.443,0.11);
233  const TColor RFPlot::rf_yellow4(7034,0.365,0.259,0);
234  const TColor RFPlot::rf_purple0(7040,0.937,0.729,0.898);
235  const TColor RFPlot::rf_purple1(7041,0.753,0.478,0.702);
236  const TColor RFPlot::rf_purple2(7042,0.6,0.286,0.541);
237  const TColor RFPlot::rf_purple3(7043,0.42,0.075,0.353);
238  const TColor RFPlot::rf_purple4(7044,0.196,0,0.161);
239  const TColor RFPlot::rf_cyan0(7050,0.714,0.898,0.918);
240  const TColor RFPlot::rf_cyan1(7051,0.424,0.639,0.659);
241  const TColor RFPlot::rf_cyan2(7052,0.247,0.49,0.51);
242  const TColor RFPlot::rf_cyan3(7053,0.067,0.329,0.357);
243  const TColor RFPlot::rf_cyan4(7054,0,0.153,0.169);
244  const TColor RFPlot::rf_orange0(7060,1,0.882,0.776);
245  const TColor RFPlot::rf_orange1(7061,1,0.808,0.639);
246  const TColor RFPlot::rf_orange2(7062,0.839,0.608,0.4);
247  const TColor RFPlot::rf_orange3(7063,0.584,0.329,0.106);
248  const TColor RFPlot::rf_orange4(7064,0.275,0.129,0);
249  const TColor RFPlot::rf_lime0(7070,0.941,0.992,0.769);
250  const TColor RFPlot::rf_lime1(7071,0.882,0.961,0.612);
251  const TColor RFPlot::rf_lime2(7072,0.706,0.8,0.38);
252  const TColor RFPlot::rf_lime3(7073,0.455,0.557,0.098);
253  const TColor RFPlot::rf_lime4(7074,0.204,0.263,0);
254 
255 }
std::string GetName() const
Returns object name.
Definition: RFBase.cc:104
virtual void Clear()
Clears RFBase of all connections to other objects.
Definition: RFPlot.cc:48