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