CMS 3D CMS Logo

TkAlStyle.cc
Go to the documentation of this file.
2 
4  TString str = "";
5  if (status == NO_STATUS)
6  str = "Status not set yet!";
7  else if (status == INTERNAL)
8  str = "internal";
9  else if (status == INTERNAL_SIMULATION)
10  str = "simulation (internal)";
11  else if (status == PRELIMINARY)
12  str = "preliminary";
13  else if (status == PUBLIC)
14  str = "public";
15  else if (status == SIMULATION)
16  str = "simulation (public)";
17  else if (status == UNPUBLISHED)
18  str = "unpublished";
19  else if (status == CUSTOM)
20  str = "custom title set";
21 
22  return str;
23 }
24 
25 static TString toTString(const Era era) {
26  TString str = "";
27  if (era == CRUZET15)
28  str = "0T cosmic ray data 2015";
29  else if (era == CRAFT15)
30  str = "3.8T cosmic ray data 2015";
31  else if (era == COLL0T15)
32  str = "0T collision data 2015";
33 
34  return str;
35 }
36 
39 TString TkAlStyle::legendheader = "";
40 TString TkAlStyle::legendoptions = "all";
41 TString TkAlStyle::customTitle_ = "";
42 TString TkAlStyle::customRightTitle_ = "";
43 double TkAlStyle::lineHeight_ = 0.042;
44 double TkAlStyle::margin_ = 0.04;
45 double TkAlStyle::textSize = 0.035;
46 
47 // --------------------------------------------------------------
50  std::for_each(status.begin(), status.end(), [](char& c) { c = ::toupper(c); });
51  if (status == "NO_STATUS")
52  st = NO_STATUS;
53  else if (status == "INTERNAL")
54  st = INTERNAL;
55  else if (status == "SIMULATION (INTERNAL)")
57  else if (status == "PRELIMINARY")
58  st = PRELIMINARY;
59  else if (status == "PUBLIC")
60  st = PUBLIC;
61  else if (status == "SIMULATION")
62  st = SIMULATION;
63  else if (status == "UNPUBLISHED")
64  st = UNPUBLISHED;
65  else
66  st = CUSTOM;
67 
68  return st;
69 }
70 
71 // --------------------------------------------------------------
72 void TkAlStyle::setXCoordinatesL(const double relWidth, double& x0, double& x1) {
73  x0 = gStyle->GetPadLeftMargin() + margin_;
74  x1 = x0 + relWidth * (1. - gStyle->GetPadLeftMargin() - gStyle->GetPadRightMargin() - 2. * margin_);
75 }
76 
77 // --------------------------------------------------------------
78 void TkAlStyle::setXCoordinatesR(const double relWidth, double& x0, double& x1) {
79  x0 = 1. - gStyle->GetPadRightMargin() - margin_ -
80  relWidth * (1. - gStyle->GetPadLeftMargin() - gStyle->GetPadRightMargin() - 2. * margin_);
81  x1 = 1. - gStyle->GetPadRightMargin() - margin_;
82 }
83 
84 // --------------------------------------------------------------
85 void TkAlStyle::setYCoordinatesT(const int nEntries, double& y0, double& y1) {
86  y1 = 1. - gStyle->GetPadTopMargin() - margin_;
87  y0 = y1 - nEntries * lineHeight_;
88 }
89 
90 // --------------------------------------------------------------
91 void TkAlStyle::setYCoordinatesB(const int nEntries, double& y0, double& y1) {
92  y1 = gStyle->GetPadBottomMargin() + margin_;
93  y0 = y1 + nEntries * lineHeight_;
94 }
95 
96 // --------------------------------------------------------------
97 TLegend* TkAlStyle::legend(const int nEntries, const double relWidth, const bool left, const bool top) {
98  double x0 = 0.;
99  double x1 = 0.;
100  double y0 = 0.;
101  double y1 = 0.;
102  bool hasheader = (TkAlStyle::legendheader != "");
103  if (left)
104  setXCoordinatesL(relWidth, x0, x1);
105  else
106  setXCoordinatesR(relWidth, x0, x1);
107  if (top)
108  setYCoordinatesT(nEntries + hasheader, y0, y1);
109  else
110  setYCoordinatesB(nEntries + hasheader, y0, y1);
111 
112  TLegend* leg = new TLegend(x0, y0, x1, y1);
113  leg->SetBorderSize(0);
114  leg->SetFillColor(0);
115  leg->SetFillStyle(0);
116  leg->SetTextFont(42);
117  leg->SetTextSize(textSize);
118  if (hasheader)
119  leg->SetHeader(TkAlStyle::legendheader);
120 
121  return leg;
122 }
123 
124 // --------------------------------------------------------------
125 TPaveText* TkAlStyle::label(const int nEntries, const double relWidth, const bool left, const bool top) {
126  double x0 = 0.;
127  double x1 = 0.;
128  double y0 = 0.;
129  double y1 = 0.;
130  if (left)
131  setXCoordinatesL(relWidth, x0, x1);
132  else
133  setXCoordinatesR(relWidth, x0, x1);
134  if (top)
135  setYCoordinatesT(nEntries, y0, y1);
136  else
137  setYCoordinatesB(nEntries, y0, y1);
138 
139  TPaveText* label = new TPaveText(x0, y0, x1, y1, "NDC");
140  label->SetBorderSize(0);
141  label->SetFillColor(0);
142  label->SetFillStyle(0);
143  label->SetTextFont(42);
144  label->SetTextAlign(12); // left adjusted and vertically centered
145  label->SetTextSize(textSize);
146  label->SetMargin(0.);
147 
148  return label;
149 }
150 
151 // --------------------------------------------------------------
152 //unfortunately no #definecommand in TLatex...
153 //#CMS{text} gives CMS in big bold, text in italics
154 //#CMS with no "argument" just gives CMS in big bold
155 //#noCMS{text} gives text in italics
156 TString TkAlStyle::applyCMS(const TString& txt) {
157  TString newtxt = txt;
158  newtxt.ReplaceAll("#CMS{", "#scale[1.4]{#font[61]{CMS}} #font[52]{");
159  newtxt.ReplaceAll("#noCMS{", "#font[52]{");
160  newtxt.ReplaceAll("#CMS", "#scale[1.4]{#font[61]{CMS}}");
161  return newtxt;
162 }
163 
164 // --------------------------------------------------------------
165 TPaveText* TkAlStyle::title(const TString& txt) {
166  double x0 = gStyle->GetPadLeftMargin();
167  double x1 = 1. - gStyle->GetPadRightMargin();
168  double y0 = 1. - gStyle->GetPadTopMargin();
169  double y1 = 1.;
170  if (txt.Contains("#CMS"))
171  y0 += .02;
172  TPaveText* theTitle = new TPaveText(x0, y0, x1, y1, "NDC");
173  theTitle->SetBorderSize(0);
174  theTitle->SetFillColor(10);
175  theTitle->SetFillStyle(0);
176  theTitle->SetTextFont(42);
177  theTitle->SetTextAlign(13); // left bottom adjusted
178  theTitle->SetTextSize(0.038);
179  theTitle->SetMargin(0.);
180  theTitle->AddText(applyCMS(txt));
181 
182  return theTitle;
183 }
184 
185 // --------------------------------------------------------------
186 TPaveText* TkAlStyle::righttitle(const TString& txt) {
187  TString newtxt = applyCMS(txt);
188  double x0 = gStyle->GetPadLeftMargin();
189  double x1 = 1. - gStyle->GetPadRightMargin();
190  double y0 = 1. - gStyle->GetPadTopMargin();
191  double y1 = 1.;
192  TPaveText* theTitle = new TPaveText(x0, y0, x1, y1, "NDC");
193  theTitle->SetBorderSize(0);
194  theTitle->SetFillColor(10);
195  theTitle->SetFillStyle(0);
196  theTitle->SetTextFont(42);
197  theTitle->SetTextAlign(33); // right bottom adjusted
198  theTitle->SetTextSize(0.038);
199  theTitle->SetMargin(0.);
200  theTitle->AddText(newtxt);
201 
202  return theTitle;
203 }
204 
205 // --------------------------------------------------------------
207  TString txt;
208  if (status == NO_STATUS) {
209  std::cout << "Status not set yet! Can't draw the title!" << std::endl;
210  } else if (status == INTERNAL_SIMULATION) {
211  txt = "#noCMS{Simulation}";
212  } else if (status == INTERNAL) {
213  txt = "#CMS{Internal}";
214  } else if (status == PRELIMINARY) {
215  txt = "#CMS{Preliminary}";
216  } else if (status == PUBLIC) {
217  txt = "#CMS";
218  } else if (status == SIMULATION) {
219  txt = "#CMS{Simulation}";
220  } else if (status == UNPUBLISHED) {
221  txt = "#CMS{(unpublished)}";
222  } else if (status == CUSTOM) {
223  txt = customTitle_;
224  }
225 
226  return txt;
227 }
228 
229 TString TkAlStyle::rightheader(const Era era) {
230  TString txt = "";
231  if (era != NONE) {
232  txt = toTString(era);
233  } else {
234  txt = customRightTitle_;
235  }
236  return txt;
237 }
238 
239 // --------------------------------------------------------------
241  const Era era,
242  const TString customTitle,
243  const TString customRightTitle) {
244  // Store the PublicationStatus for later usage, e.g. in the title
248  era_ = era;
249  if (publicationStatus_ == CUSTOM && customTitle_ == "")
250  std::cout << "Error: you are trying to use a custom title, but you don't provide it" << std::endl;
251  if (publicationStatus_ != CUSTOM && customTitle_ != "")
252  std::cout
253  << "Error: you provide a custom title, but you don't indicate CUSTOM status. Your title will not be used."
254  << std::endl;
255 
256  // Suppress message when canvas has been saved
257  gErrorIgnoreLevel = 1001;
258 
259  // Zero horizontal error bars
260  gStyle->SetErrorX(0);
261 
262  // For the canvas
263  gStyle->SetCanvasBorderMode(0);
264  gStyle->SetCanvasColor(kWhite);
265  gStyle->SetCanvasDefH(800); //Height of canvas
266  gStyle->SetCanvasDefW(800); //Width of canvas
267  gStyle->SetCanvasDefX(0); //Position on screen
268  gStyle->SetCanvasDefY(0);
269 
270  // For the frame
271  gStyle->SetFrameBorderMode(0);
272  gStyle->SetFrameBorderSize(10);
273  gStyle->SetFrameFillColor(kBlack);
274  gStyle->SetFrameFillStyle(0);
275  gStyle->SetFrameLineColor(kBlack);
276  gStyle->SetFrameLineStyle(0);
277  gStyle->SetFrameLineWidth(2);
278  gStyle->SetLineWidth(3);
279 
280  // For the Pad
281  gStyle->SetPadBorderMode(0);
282  gStyle->SetPadColor(kWhite);
283  gStyle->SetPadGridX(false);
284  gStyle->SetPadGridY(false);
285  gStyle->SetGridColor(0);
286  gStyle->SetGridStyle(3);
287  gStyle->SetGridWidth(1);
288 
289  // Margins
290  gStyle->SetPadTopMargin(0.08);
291  gStyle->SetPadBottomMargin(0.13);
292  gStyle->SetPadLeftMargin(0.16);
293  gStyle->SetPadRightMargin(0.05);
294 
295  // For the histo:
296  gStyle->SetHistLineColor(kBlack);
297  gStyle->SetHistLineStyle(0);
298  gStyle->SetHistLineWidth(3);
299  gStyle->SetMarkerSize(0.8);
300  gStyle->SetEndErrorSize(4);
301  gStyle->SetHatchesLineWidth(1);
302 
303  // For the statistics box:
304  gStyle->SetOptStat(0);
305 
306  // For the axis
307  gStyle->SetAxisColor(1, "XYZ");
308  gStyle->SetTickLength(0.03, "XYZ");
309  gStyle->SetNdivisions(510, "XYZ");
310  gStyle->SetPadTickX(1);
311  gStyle->SetPadTickY(1);
312  gStyle->SetStripDecimals(kFALSE);
313 
314  // For the axis labels and titles
315  gStyle->SetTitleColor(1, "XYZ");
316  gStyle->SetLabelColor(1, "XYZ");
317  gStyle->SetLabelFont(42, "XYZ");
318  gStyle->SetLabelOffset(0.007, "XYZ");
319  gStyle->SetLabelSize(0.04, "XYZ");
320  gStyle->SetTitleFont(42, "XYZ");
321  gStyle->SetTitleSize(0.047, "XYZ");
322  gStyle->SetTitleXOffset(1.2);
323  gStyle->SetTitleYOffset(1.5);
324 
325  // For the legend
326  gStyle->SetLegendBorderSize(0);
327 }
328 
329 void TkAlStyle::set(const TString customTitle) { set(CUSTOM, NONE, customTitle); }
static TString customTitle_
Definition: TkAlStyle.h:181
static void setYCoordinatesB(const int nEntries, double &y0, double &y1)
Definition: TkAlStyle.cc:91
static TString applyCMS(const TString &txt)
Definition: TkAlStyle.cc:156
static TPaveText * customTitle(const TString &txt)
Definition: TkAlStyle.h:88
static PublicationStatus status()
Definition: TkAlStyle.h:53
static Era era_
Definition: TkAlStyle.h:180
Era
Definition: TkAlStyle.h:43
static double textSize
Definition: TkAlStyle.h:93
static TString customRightTitle_
Definition: TkAlStyle.h:182
static double lineHeight_
Definition: TkAlStyle.h:183
static void set(const PublicationStatus status, const Era era=NONE, const TString customTitle="", const TString customRightTitle="")
Definition: TkAlStyle.cc:240
static TPaveText * title(const TString &txt)
Definition: TkAlStyle.cc:165
static void setYCoordinatesT(const int nEntries, double &y0, double &y1)
Definition: TkAlStyle.cc:85
static PublicationStatus publicationStatus_
Definition: TkAlStyle.h:179
PublicationStatus
Definition: TkAlStyle.h:31
TString toTString(const PublicationStatus status)
Definition: TkAlStyle.cc:3
static TString legendheader
Definition: TkAlStyle.h:91
static TPaveText * customRightTitle(const TString &txt)
Definition: TkAlStyle.h:89
static void setXCoordinatesL(const double relWidth, double &x0, double &x1)
Definition: TkAlStyle.cc:72
static double margin_
Definition: TkAlStyle.h:184
static TPaveText * righttitle(const TString &txt)
Definition: TkAlStyle.cc:186
static TString legendoptions
Definition: TkAlStyle.h:92
gErrorIgnoreLevel
Definition: utils.py:27
static TString rightheader(const Era era)
Definition: TkAlStyle.cc:229
static TPaveText * label(const int nEntries, const double relWidth=0.5)
Definition: TkAlStyle.h:138
Definition: TkAlStyle.h:43
#define str(s)
static void setXCoordinatesR(const double relWidth, double &x0, double &x1)
Definition: TkAlStyle.cc:78
static PublicationStatus toStatus(std::string _status)
Definition: TkAlStyle.cc:48
static TLegend * legend(const int nEntries, const double relWidth=0.5)
Definition: TkAlStyle.h:98
static TString header(const PublicationStatus status)
Definition: TkAlStyle.cc:206