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-2018, 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 
103  gStyle->SetCanvasBorderMode(0);
104  gStyle->SetCanvasColor(kWhite);
105  gStyle->SetCanvasDefX(0);
106  gStyle->SetCanvasDefY(0);
107 
108  // For the Pad:
109  gStyle->SetPadBorderMode(0);
110  gStyle->SetPadColor(kWhite);
111  gStyle->SetGridColor(0);
112  gStyle->SetGridStyle(3);
113  gStyle->SetGridWidth(1);
114 
115  // For the frame:
116  gStyle->SetFrameBorderMode(0);
117  gStyle->SetFrameBorderSize(1);
118  gStyle->SetFrameFillColor(0);
119  gStyle->SetFrameFillStyle(0);
120  gStyle->SetFrameLineColor(1);
121  gStyle->SetFrameLineStyle(1);
122  gStyle->SetFrameLineWidth(1);
123 
124  // set the paper & margin sizes
125  gStyle->SetPaperSize(20,26);
126  gStyle->SetPadTopMargin(0.09);
127  gStyle->SetPadRightMargin(0.25);
128  gStyle->SetPadBottomMargin(0.18);
129  gStyle->SetPadLeftMargin(0.15);
130 
131  // use large Times-Roman fonts
132  gStyle->SetTitleFont(132,"xyz"); // set the all 3 axes title font
133  gStyle->SetTitleFont(132," "); // set the pad title font
134  gStyle->SetTitleSize(0.06,"xyz"); // set the 3 axes title size
135  gStyle->SetTitleSize(0.06," "); // set the pad title size
136  gStyle->SetLabelFont(132,"xyz");
137  gStyle->SetLabelSize(0.05,"xyz");
138  gStyle->SetLabelColor(1,"xyz");
139  gStyle->SetTextFont(132);
140  gStyle->SetTextSize(0.08);
141  gStyle->SetStatFont(132);
142 
143  // use bold lines and markers
144  gStyle->SetMarkerStyle(8);
145  gStyle->SetHistLineWidth(2);
146  gStyle->SetLineStyleString(2,"[12 12]"); // postscript dashes
147 
148  //..Get rid of X error bars
149  gStyle->SetErrorX(0.001);
150 
151  // do not display any of the standard histogram decorations
152  gStyle->SetOptTitle(0);
153  gStyle->SetOptStat(0);
154  gStyle->SetOptFit(11111111);
155 
156  // put tick marks on top and RHS of plots
157  gStyle->SetPadTickX(1);
158  gStyle->SetPadTickY(1);
159 
160 
161  double zcolor_s[5] = { 0.00, 0.50, 0.70, 0.82, 1.00 };
162  double zcolor_r[5] = { 0.00, 0.00, 0.74, 1.00, 1.00 };
163  double zcolor_g[5] = { 0.00, 0.61, 0.82, 0.70, 1.00 };
164  double zcolor_b[5] = { 0.31, 0.73, 0.08, 0.00, 1.00 };
165  double zcolor_is[5] = { 0.00, 0.15, 0.35, 0.60, 1.00 };
166  double zcolor_ir[5] = { 1.00, 1.00, 0.74, 0.00, 0.00 };
167  double zcolor_ig[5] = { 0.90, 0.70, 0.82, 0.61, 0.00 };
168  double zcolor_ib[5] = { 0.70, 0.00, 0.08, 0.73, 0.31 };
169  for(int i = 0; i < 5; i++){
170  zcolor_s[i] = RFPlot::rf_zcolor_s[i];
171  zcolor_r[i] = RFPlot::rf_zcolor_r[i];
172  zcolor_g[i] = RFPlot::rf_zcolor_g[i];
173  zcolor_b[i] = RFPlot::rf_zcolor_b[i];
174  zcolor_is[i] = RFPlot::rf_zcolor_is[i];
175  zcolor_ir[i] = RFPlot::rf_zcolor_ir[i];
176  zcolor_ig[i] = RFPlot::rf_zcolor_ig[i];
177  zcolor_ib[i] = RFPlot::rf_zcolor_ib[i];
178  }
179 
180  RFPlot::rf_iZPalette = TColor::CreateGradientColorTable(5, zcolor_is, zcolor_ir,
181  zcolor_ig, zcolor_ib,
182  RFPlot::rf_NZPalette);
183  RFPlot::rf_ZPalette = TColor::CreateGradientColorTable(5, zcolor_s, zcolor_r,
184  zcolor_g, zcolor_b,
185  RFPlot::rf_NZPalette);
186  gStyle->cd();
187  }
188 
189  void SetZPalette(bool invert_colors){
190  if(RFPlot::rf_ZPalette <= 0)
191  SetStyle();
192 
193  int palette[RFPlot::rf_NZPalette];
194  if(invert_colors){
195  for(int i = 0; i < RFPlot::rf_NZPalette; i++)
196  palette[i] = RFPlot::rf_iZPalette + i;
197  } else {
198  for(int i = 0; i < RFPlot::rf_NZPalette; i++)
199  palette[i] = RFPlot::rf_ZPalette + i;
200  }
201  gStyle->SetPalette(RFPlot::rf_NZPalette, palette);
202  }
203 
204  const int RFPlot::rf_NZPalette = 28;
205  int RFPlot::rf_ZPalette = 0;
206  int RFPlot::rf_iZPalette = 0;
207  const double RFPlot::rf_zcolor_s[5] = { 0.00, 0.50, 0.70, 0.82, 1.00 };
208  const double RFPlot::rf_zcolor_r[5] = { 0.00, 0.00, 0.74, 1.00, 1.00 };
209  const double RFPlot::rf_zcolor_g[5] = { 0.00, 0.61, 0.82, 0.70, 1.00 };
210  const double RFPlot::rf_zcolor_b[5] = { 0.31, 0.73, 0.08, 0.00, 1.00 };
211  const double RFPlot::rf_zcolor_is[5] = { 0.00, 0.15, 0.35, 0.60, 1.00 };
212  const double RFPlot::rf_zcolor_ir[5] = { 1.00, 1.00, 0.74, 0.00, 0.00 };
213  const double RFPlot::rf_zcolor_ig[5] = { 0.90, 0.70, 0.82, 0.61, 0.00 };
214  const double RFPlot::rf_zcolor_ib[5] = { 0.70, 0.00, 0.08, 0.73, 0.31 };
215 
216  const TColor RFPlot::rf_blue0(7000,0.749,0.78,0.933);
217  const TColor RFPlot::rf_blue1(7001,0.424,0.467,0.651);
218  const TColor RFPlot::rf_blue2(7002,0.255,0.302,0.522);
219  const TColor RFPlot::rf_blue3(7003,0.114,0.165,0.396);
220  const TColor RFPlot::rf_blue4(7004,0.024,0.063,0.251);
221  const TColor RFPlot::rf_green0(7010,0.737,0.949,0.784);
222  const TColor RFPlot::rf_green1(7011,0.435,0.722,0.498);
223  const TColor RFPlot::rf_green2(7012,0.239,0.576,0.314);
224  const TColor RFPlot::rf_green3(7013,0.082,0.439,0.161);
225  const TColor RFPlot::rf_green4(7014,0,0.275,0.063);
226  const TColor RFPlot::rf_red0(7020,1,0.796,0.776);
227  const TColor RFPlot::rf_red1(7021,0.957,0.612,0.576);
228  const TColor RFPlot::rf_red2(7022,0.765,0.361,0.318);
229  const TColor RFPlot::rf_red3(7023,0.58,0.157,0.11);
230  const TColor RFPlot::rf_red4(7024,0.365,0.035,0);
231  const TColor RFPlot::rf_yellow0(7030,1,0.933,0.776);
232  const TColor RFPlot::rf_yellow1(7031,0.957,0.843,0.576);
233  const TColor RFPlot::rf_yellow2(7032,0.765,0.631,0.318);
234  const TColor RFPlot::rf_yellow3(7033,0.58,0.443,0.11);
235  const TColor RFPlot::rf_yellow4(7034,0.365,0.259,0);
236  const TColor RFPlot::rf_purple0(7040,0.937,0.729,0.898);
237  const TColor RFPlot::rf_purple1(7041,0.753,0.478,0.702);
238  const TColor RFPlot::rf_purple2(7042,0.6,0.286,0.541);
239  const TColor RFPlot::rf_purple3(7043,0.42,0.075,0.353);
240  const TColor RFPlot::rf_purple4(7044,0.196,0,0.161);
241  const TColor RFPlot::rf_cyan0(7050,0.714,0.898,0.918);
242  const TColor RFPlot::rf_cyan1(7051,0.424,0.639,0.659);
243  const TColor RFPlot::rf_cyan2(7052,0.247,0.49,0.51);
244  const TColor RFPlot::rf_cyan3(7053,0.067,0.329,0.357);
245  const TColor RFPlot::rf_cyan4(7054,0,0.153,0.169);
246  const TColor RFPlot::rf_orange0(7060,1,0.882,0.776);
247  const TColor RFPlot::rf_orange1(7061,1,0.808,0.639);
248  const TColor RFPlot::rf_orange2(7062,0.839,0.608,0.4);
249  const TColor RFPlot::rf_orange3(7063,0.584,0.329,0.106);
250  const TColor RFPlot::rf_orange4(7064,0.275,0.129,0);
251  const TColor RFPlot::rf_lime0(7070,0.941,0.992,0.769);
252  const TColor RFPlot::rf_lime1(7071,0.882,0.961,0.612);
253  const TColor RFPlot::rf_lime2(7072,0.706,0.8,0.38);
254  const TColor RFPlot::rf_lime3(7073,0.455,0.557,0.098);
255  const TColor RFPlot::rf_lime4(7074,0.204,0.263,0);
256 
257 }
RestFrames::RFPlot::Clear
virtual void Clear()
Clears RFPlot from all connections to other objects.
Definition: RFPlot.cc:48
RFPlot.hh
RestFrames::RFBase
Base class for all RestFrame package objects.
Definition: RFBase.hh:53
RestFrames::RFPlot::WriteOutput
void WriteOutput(const std::string &filename)
Stores all plots in root file.
Definition: RFPlot.cc:59
RestFrames::RFBase::GetName
std::string GetName() const
Returns object name.
Definition: RFBase.cc:104
RestFrames::RFLog::SetSource
void SetSource(const std::string &source)
Sets name of instance that is associated with.
Definition: RFLog.cc:182
RestFrames::RFPlot::RFPlot
RFPlot(const std::string &sname, const std::string &stitle)
Standard constructor.
Definition: RFPlot.cc:38
RestFrames::SetZPalette
void SetZPalette(bool invert_colors=false)
Definition: RFPlot.cc:189