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