CMS 3D CMS Logo

TkAlStyle.h
Go to the documentation of this file.
1 // Common style file for TkAl public plots
2 // --------------------------------------------------------------
3 //
4 // Defines a set of functions to define the plotting style and
5 // provide commonly used style objects such as histogram title
6 // and legends. Can be used in compiled code and uncompiled scripts.
7 //
8 // Always call TkAlStyle::set(PublicationStatus) in the beginning
9 // of your plotting script to adjust the gStyle options. Also,
10 // the behaviour of some other methods of this class depend on
11 // this, e.g. the histogram title displays "CMS preliminary" etc.
12 // depending on the PublicationStatus. Call TkAlStyle::set before
13 // declaring any histograms (or call TH1::UseCurrentStyle()) to
14 // make sure the style settings are used.
15 // --------------------------------------------------------------
16 
17 #ifndef ALIGNMENT_OFFLINEVALIDATION_TKAL_STYLE_H
18 #define ALIGNMENT_OFFLINEVALIDATION_TKAL_STYLE_H
19 
20 #include "TColor.h"
21 #include "TError.h"
22 #include "TLegend.h"
23 #include "TPaveText.h"
24 #include "TString.h"
25 #include "TStyle.h"
26 #include <iostream>
27 #include <string>
28 #include <algorithm>
29 
30 // Publication status: determines what is plotted in title
40 };
41 
42 // Data era: determines labels of data-taking periods, e.g. CRUZET
44 
45 // Alignment object
47 
48 class TkAlStyle {
49 public:
50  // Adjusts the gStyle settings and store the PublicationStatus
51  static void set(const PublicationStatus status,
52  const Era era = NONE,
53  const TString customTitle = "",
54  const TString customRightTitle = "");
55  static void set(const TString customTitle);
57 
58  static TString toTString(const PublicationStatus status);
59  static TString toTString(const Era era);
60  static TString toTString(const AlignObj obj);
61 
62  static int color(const AlignObj obj);
63  static int style(const AlignObj obj);
64 
65  // Draws a title "<CMS label> 2015" on the current pad
66  // dependending on the PublicationStatus
67  // INTERNAL : no extra label (intended for AN-only plots with data)
68  // INTERNAL : show "Simulation" label (intended for AN-only plots, no "CMS")
69  // PRELIMINARY : show "CMS preliminary 2015" label
70  // PUBLIC : show "CMS 2015" label
71  // SIMULATION : show "CMS Simulation" label
72  // UNPUBLISHED : show "CMS (unpublished)" label (intended for additional material on TWiki)
73  // Note that this method does not allow for easy memory
74  // handling. For that, use standardTitle().
75  static void drawStandardTitle() {
76  standardTitle()->Draw("same");
77  standardRightTitle()->Draw("same");
78  }
79  static void drawStandardTitle(const Era era) {
80  standardTitle()->Draw("same");
81  standardRightTitle(era)->Draw("same");
82  }
83  static PublicationStatus toStatus(std::string _status);
84 
85  // Returns a TPaveText object that fits as a histogram title
86  // with the current pad dimensions.
87  // It has the same text as described in drawStandardTitle().
88  // The idea of this method is that one has control over the
89  // TPaveText object and can do proper memory handling.
90  static TPaveText* standardTitle(PublicationStatus status) { return title(header(status)); }
91  static TPaveText* standardTitle() { return standardTitle(publicationStatus_); }
92 
93  static TPaveText* standardRightTitle(const Era era) { return righttitle(rightheader(era)); }
94  static TPaveText* standardRightTitle() { return standardRightTitle(era_); }
95 
96  // Returns a TPaveText object that fits as a histogram title
97  // with the current pad dimensions and displays the specified text txt.
98  static TPaveText* customTitle(const TString& txt) { return title(txt); }
99  static TPaveText* customRightTitle(const TString& txt) { return righttitle(txt); }
100 
101  static TString legendheader;
102  static TString legendoptions;
103  static double textSize;
104  // Returns a TLegend object that fits into the top-right corner
105  // of the current pad. Its width, relative to the pad size (without
106  // margins), can be specified. Its height is optimized for nEntries
107  // entries.
108  static TLegend* legend(const int nEntries, const double relWidth = 0.5) { return legendTR(nEntries, relWidth); }
109  static TLegend* legend(TString position, const int nEntries, const double relWidth = 0.5) {
110  position.ToLower();
111  if (!(position.Contains("top") || position.Contains("bottom")))
112  position += "top";
113  if (!(position.Contains("left") || position.Contains("right")))
114  position += "right";
115  TLegend* leg = nullptr;
116  if (position.Contains("top") && position.Contains("right")) {
117  leg = legendTR(nEntries, relWidth);
118  } else if (position.Contains("top") && position.Contains("left")) {
119  leg = legendTL(nEntries, relWidth);
120  } else if (position.Contains("bottom") && position.Contains("right")) {
121  leg = legendBR(nEntries, relWidth);
122  } else if (position.Contains("bottom") && position.Contains("left")) {
123  leg = legendBL(nEntries, relWidth);
124  } else {
125  leg = legendTR(nEntries, relWidth);
126  }
127 
128  return leg;
129  }
130  // Same but explicitly state position on pad
131  static TLegend* legendTL(const int nEntries, const double relWidth = 0.5) {
132  return legend(nEntries, relWidth, true, true);
133  }
134  static TLegend* legendTR(const int nEntries, const double relWidth = 0.5) {
135  return legend(nEntries, relWidth, false, true);
136  }
137  static TLegend* legendBL(const int nEntries, const double relWidth = 0.5) {
138  return legend(nEntries, relWidth, true, false);
139  }
140  static TLegend* legendBR(const int nEntries, const double relWidth = 0.5) {
141  return legend(nEntries, relWidth, false, false);
142  }
143 
144  // Returns a TPaveText object that fits into the top-right corner
145  // of the current pad and that can be used for additional labels.
146  // Its width, relative to the pad size (without margins), can be
147  // specified. Its height is optimized for nEntries entries.
148  static TPaveText* label(const int nEntries, const double relWidth = 0.5) { return labelTR(nEntries, relWidth); }
149 
150  static TPaveText* label(TString position, const int nEntries, const double relWidth = 0.5) {
151  position.ToLower();
152  if (!(position.Contains("top") || position.Contains("bottom")))
153  position += "top";
154  if (!(position.Contains("left") || position.Contains("right")))
155  position += "right";
156  TPaveText* label = nullptr;
157  if (position.Contains("top") && position.Contains("right")) {
158  label = labelTR(nEntries, relWidth);
159  } else if (position.Contains("top") && position.Contains("left")) {
160  label = labelTL(nEntries, relWidth);
161  } else if (position.Contains("bottom") && position.Contains("right")) {
162  label = labelBR(nEntries, relWidth);
163  } else if (position.Contains("bottom") && position.Contains("left")) {
164  label = labelBL(nEntries, relWidth);
165  } else {
166  label = labelTR(nEntries, relWidth);
167  }
168 
169  return label;
170  }
171 
172  // Same but explicitly state position on pad
173  static TPaveText* labelTL(const int nEntries, const double relWidth = 0.5) {
174  return label(nEntries, relWidth, true, true);
175  }
176  static TPaveText* labelTR(const int nEntries, const double relWidth = 0.5) {
177  return label(nEntries, relWidth, false, true);
178  }
179  static TPaveText* labelBL(const int nEntries, const double relWidth = 0.5) {
180  return label(nEntries, relWidth, true, false);
181  }
182  static TPaveText* labelBR(const int nEntries, const double relWidth = 0.5) {
183  return label(nEntries, relWidth, false, false);
184  }
185 
186  static double lineHeight() { return lineHeight_; }
187 
188 private:
190  static Era era_;
191  static TString customTitle_;
192  static TString customRightTitle_;
193  static double lineHeight_;
194  static double margin_;
195 
196  // creates a title
197  static TString applyCMS(const TString& txt);
198  static TPaveText* title(const TString& txt);
199  static TPaveText* righttitle(const TString& txt);
200 
201  // returns the standard-title (CMS label 2015) depending
202  // on the PublicationStatus
203  static TString header(const PublicationStatus status);
204  static TString rightheader(const Era era);
205 
206  // NDC coordinates for TPave, TLegend,...
207  static void setXCoordinatesL(const double relWidth, double& x0, double& x1);
208  static void setXCoordinatesR(const double relWidth, double& x0, double& x1);
209  static void setYCoordinatesT(const int nEntries, double& y0, double& y1);
210  static void setYCoordinatesB(const int nEntries, double& y0, double& y1);
211 
212  static TLegend* legend(const int nEntries, const double relWidth, const bool left, const bool top);
213  static TPaveText* label(const int nEntries, const double relWidth, const bool leftt, const bool top);
214 };
215 
216 #endif
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 TPaveText * label(TString position, const int nEntries, const double relWidth=0.5)
Definition: TkAlStyle.h:150
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 TPaveText * standardRightTitle()
Definition: TkAlStyle.h:94
static double lineHeight_
Definition: TkAlStyle.h:193
static void drawStandardTitle(const Era era)
Definition: TkAlStyle.h:79
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 void drawStandardTitle()
Definition: TkAlStyle.h:75
static int style(const AlignObj obj)
Definition: TkAlStyle.cc:70
static TPaveText * standardTitle()
Definition: TkAlStyle.h:91
static TString legendheader
Definition: TkAlStyle.h:101
static TPaveText * standardRightTitle(const Era era)
Definition: TkAlStyle.h:93
static TPaveText * customRightTitle(const TString &txt)
Definition: TkAlStyle.h:99
static void setXCoordinatesL(const double relWidth, double &x0, double &x1)
Definition: TkAlStyle.cc:107
static TPaveText * labelBR(const int nEntries, const double relWidth=0.5)
Definition: TkAlStyle.h:182
static TLegend * legendBR(const int nEntries, const double relWidth=0.5)
Definition: TkAlStyle.h:140
AlignObj
Definition: TkAlStyle.h:46
static double margin_
Definition: TkAlStyle.h:194
static double lineHeight()
Definition: TkAlStyle.h:186
static TPaveText * righttitle(const TString &txt)
Definition: TkAlStyle.cc:221
static TPaveText * labelBL(const int nEntries, const double relWidth=0.5)
Definition: TkAlStyle.h:179
static TPaveText * labelTR(const int nEntries, const double relWidth=0.5)
Definition: TkAlStyle.h:176
static TString legendoptions
Definition: TkAlStyle.h:102
static TLegend * legendBL(const int nEntries, const double relWidth=0.5)
Definition: TkAlStyle.h:137
static TString rightheader(const Era era)
Definition: TkAlStyle.cc:264
static TLegend * legendTR(const int nEntries, const double relWidth=0.5)
Definition: TkAlStyle.h:134
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
static int position[264][3]
Definition: ReadPGInfo.cc:289
static TLegend * legend(TString position, const int nEntries, const double relWidth=0.5)
Definition: TkAlStyle.h:109
static int color(const AlignObj obj)
Definition: TkAlStyle.cc:54
Definition: TkAlStyle.h:43
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 TPaveText * labelTL(const int nEntries, const double relWidth=0.5)
Definition: TkAlStyle.h:173
static TLegend * legend(const int nEntries, const double relWidth=0.5)
Definition: TkAlStyle.h:108
static TLegend * legendTL(const int nEntries, const double relWidth=0.5)
Definition: TkAlStyle.h:131
static TPaveText * standardTitle(PublicationStatus status)
Definition: TkAlStyle.h:90
static TString header(const PublicationStatus status)
Definition: TkAlStyle.cc:241