File indexing completed on 2023-03-17 10:40:35
0001 #include "Alignment/OfflineValidation/interface/TkAlStyle.h"
0002
0003 TString toTString(const PublicationStatus status) {
0004 TString str = "";
0005 if (status == NO_STATUS)
0006 str = "Status not set yet!";
0007 else if (status == INTERNAL)
0008 str = "internal";
0009 else if (status == INTERNAL_SIMULATION)
0010 str = "simulation (internal)";
0011 else if (status == PRELIMINARY)
0012 str = "preliminary";
0013 else if (status == PUBLIC)
0014 str = "public";
0015 else if (status == SIMULATION)
0016 str = "simulation (public)";
0017 else if (status == UNPUBLISHED)
0018 str = "unpublished";
0019 else if (status == CUSTOM)
0020 str = "custom title set";
0021
0022 return str;
0023 }
0024
0025 static TString toTString(const Era era) {
0026 TString str = "";
0027 if (era == CRUZET15)
0028 str = "0T cosmic ray data 2015";
0029 else if (era == CRAFT15)
0030 str = "3.8T cosmic ray data 2015";
0031 else if (era == COLL0T15)
0032 str = "0T collision data 2015";
0033
0034 return str;
0035 }
0036
0037 PublicationStatus TkAlStyle::publicationStatus_ = NO_STATUS;
0038 Era TkAlStyle::era_ = NONE;
0039 TString TkAlStyle::legendheader = "";
0040 TString TkAlStyle::legendoptions = "all";
0041 TString TkAlStyle::customTitle_ = "";
0042 TString TkAlStyle::customRightTitle_ = "";
0043 double TkAlStyle::lineHeight_ = 0.042;
0044 double TkAlStyle::margin_ = 0.04;
0045 double TkAlStyle::textSize = 0.035;
0046
0047
0048 PublicationStatus TkAlStyle::toStatus(std::string status) {
0049 PublicationStatus st;
0050 std::for_each(status.begin(), status.end(), [](char& c) { c = ::toupper(c); });
0051 if (status == "NO_STATUS")
0052 st = NO_STATUS;
0053 else if (status == "INTERNAL")
0054 st = INTERNAL;
0055 else if (status == "SIMULATION (INTERNAL)")
0056 st = INTERNAL_SIMULATION;
0057 else if (status == "PRELIMINARY")
0058 st = PRELIMINARY;
0059 else if (status == "PUBLIC")
0060 st = PUBLIC;
0061 else if (status == "SIMULATION")
0062 st = SIMULATION;
0063 else if (status == "UNPUBLISHED")
0064 st = UNPUBLISHED;
0065 else
0066 st = CUSTOM;
0067
0068 return st;
0069 }
0070
0071
0072 void TkAlStyle::setXCoordinatesL(const double relWidth, double& x0, double& x1) {
0073 x0 = gStyle->GetPadLeftMargin() + margin_;
0074 x1 = x0 + relWidth * (1. - gStyle->GetPadLeftMargin() - gStyle->GetPadRightMargin() - 2. * margin_);
0075 }
0076
0077
0078 void TkAlStyle::setXCoordinatesR(const double relWidth, double& x0, double& x1) {
0079 x0 = 1. - gStyle->GetPadRightMargin() - margin_ -
0080 relWidth * (1. - gStyle->GetPadLeftMargin() - gStyle->GetPadRightMargin() - 2. * margin_);
0081 x1 = 1. - gStyle->GetPadRightMargin() - margin_;
0082 }
0083
0084
0085 void TkAlStyle::setYCoordinatesT(const int nEntries, double& y0, double& y1) {
0086 y1 = 1. - gStyle->GetPadTopMargin() - margin_;
0087 y0 = y1 - nEntries * lineHeight_;
0088 }
0089
0090
0091 void TkAlStyle::setYCoordinatesB(const int nEntries, double& y0, double& y1) {
0092 y1 = gStyle->GetPadBottomMargin() + margin_;
0093 y0 = y1 + nEntries * lineHeight_;
0094 }
0095
0096
0097 TLegend* TkAlStyle::legend(const int nEntries, const double relWidth, const bool left, const bool top) {
0098 double x0 = 0.;
0099 double x1 = 0.;
0100 double y0 = 0.;
0101 double y1 = 0.;
0102 bool hasheader = (TkAlStyle::legendheader != "");
0103 if (left)
0104 setXCoordinatesL(relWidth, x0, x1);
0105 else
0106 setXCoordinatesR(relWidth, x0, x1);
0107 if (top)
0108 setYCoordinatesT(nEntries + hasheader, y0, y1);
0109 else
0110 setYCoordinatesB(nEntries + hasheader, y0, y1);
0111
0112 TLegend* leg = new TLegend(x0, y0, x1, y1);
0113 leg->SetBorderSize(0);
0114 leg->SetFillColor(0);
0115 leg->SetFillStyle(0);
0116 leg->SetTextFont(42);
0117 leg->SetTextSize(textSize);
0118 if (hasheader)
0119 leg->SetHeader(TkAlStyle::legendheader);
0120
0121 return leg;
0122 }
0123
0124
0125 TPaveText* TkAlStyle::label(const int nEntries, const double relWidth, const bool left, const bool top) {
0126 double x0 = 0.;
0127 double x1 = 0.;
0128 double y0 = 0.;
0129 double y1 = 0.;
0130 if (left)
0131 setXCoordinatesL(relWidth, x0, x1);
0132 else
0133 setXCoordinatesR(relWidth, x0, x1);
0134 if (top)
0135 setYCoordinatesT(nEntries, y0, y1);
0136 else
0137 setYCoordinatesB(nEntries, y0, y1);
0138
0139 TPaveText* label = new TPaveText(x0, y0, x1, y1, "NDC");
0140 label->SetBorderSize(0);
0141 label->SetFillColor(0);
0142 label->SetFillStyle(0);
0143 label->SetTextFont(42);
0144 label->SetTextAlign(12);
0145 label->SetTextSize(textSize);
0146 label->SetMargin(0.);
0147
0148 return label;
0149 }
0150
0151
0152
0153
0154
0155
0156 TString TkAlStyle::applyCMS(const TString& txt) {
0157 TString newtxt = txt;
0158 newtxt.ReplaceAll("#CMS{", "#scale[1.4]{#font[61]{CMS}} #font[52]{");
0159 newtxt.ReplaceAll("#noCMS{", "#font[52]{");
0160 newtxt.ReplaceAll("#CMS", "#scale[1.4]{#font[61]{CMS}}");
0161 return newtxt;
0162 }
0163
0164
0165 TPaveText* TkAlStyle::title(const TString& txt) {
0166 double x0 = gStyle->GetPadLeftMargin();
0167 double x1 = 1. - gStyle->GetPadRightMargin();
0168 double y0 = 1. - gStyle->GetPadTopMargin();
0169 double y1 = 1.;
0170 if (txt.Contains("#CMS"))
0171 y0 += .02;
0172 TPaveText* theTitle = new TPaveText(x0, y0, x1, y1, "NDC");
0173 theTitle->SetBorderSize(0);
0174 theTitle->SetFillColor(10);
0175 theTitle->SetFillStyle(0);
0176 theTitle->SetTextFont(42);
0177 theTitle->SetTextAlign(13);
0178 theTitle->SetTextSize(0.038);
0179 theTitle->SetMargin(0.);
0180 theTitle->AddText(applyCMS(txt));
0181
0182 return theTitle;
0183 }
0184
0185
0186 TPaveText* TkAlStyle::righttitle(const TString& txt) {
0187 TString newtxt = applyCMS(txt);
0188 double x0 = gStyle->GetPadLeftMargin();
0189 double x1 = 1. - gStyle->GetPadRightMargin();
0190 double y0 = 1. - gStyle->GetPadTopMargin();
0191 double y1 = 1.;
0192 TPaveText* theTitle = new TPaveText(x0, y0, x1, y1, "NDC");
0193 theTitle->SetBorderSize(0);
0194 theTitle->SetFillColor(10);
0195 theTitle->SetFillStyle(0);
0196 theTitle->SetTextFont(42);
0197 theTitle->SetTextAlign(33);
0198 theTitle->SetTextSize(0.038);
0199 theTitle->SetMargin(0.);
0200 theTitle->AddText(newtxt);
0201
0202 return theTitle;
0203 }
0204
0205
0206 TString TkAlStyle::header(const PublicationStatus status) {
0207 TString txt;
0208 if (status == NO_STATUS) {
0209 std::cout << "Status not set yet! Can't draw the title!" << std::endl;
0210 } else if (status == INTERNAL_SIMULATION) {
0211 txt = "#noCMS{Simulation}";
0212 } else if (status == INTERNAL) {
0213 txt = "#CMS{Internal}";
0214 } else if (status == PRELIMINARY) {
0215 txt = "#CMS{Preliminary}";
0216 } else if (status == PUBLIC) {
0217 txt = "#CMS";
0218 } else if (status == SIMULATION) {
0219 txt = "#CMS{Simulation}";
0220 } else if (status == UNPUBLISHED) {
0221 txt = "#CMS{(unpublished)}";
0222 } else if (status == CUSTOM) {
0223 txt = customTitle_;
0224 }
0225
0226 return txt;
0227 }
0228
0229 TString TkAlStyle::rightheader(const Era era) {
0230 TString txt = "";
0231 if (era != NONE) {
0232 txt = toTString(era);
0233 } else {
0234 txt = customRightTitle_;
0235 }
0236 return txt;
0237 }
0238
0239
0240 void TkAlStyle::set(const PublicationStatus status,
0241 const Era era,
0242 const TString customTitle,
0243 const TString customRightTitle) {
0244
0245 publicationStatus_ = status;
0246 customTitle_ = customTitle;
0247 customRightTitle_ = customRightTitle;
0248 era_ = era;
0249 if (publicationStatus_ == CUSTOM && customTitle_ == "")
0250 std::cout << "Error: you are trying to use a custom title, but you don't provide it" << std::endl;
0251 if (publicationStatus_ != CUSTOM && customTitle_ != "")
0252 std::cout
0253 << "Error: you provide a custom title, but you don't indicate CUSTOM status. Your title will not be used."
0254 << std::endl;
0255
0256
0257 gErrorIgnoreLevel = 1001;
0258
0259
0260 gStyle->SetErrorX(0);
0261
0262
0263 gStyle->SetCanvasBorderMode(0);
0264 gStyle->SetCanvasColor(kWhite);
0265 gStyle->SetCanvasDefH(800);
0266 gStyle->SetCanvasDefW(800);
0267 gStyle->SetCanvasDefX(0);
0268 gStyle->SetCanvasDefY(0);
0269
0270
0271 gStyle->SetFrameBorderMode(0);
0272 gStyle->SetFrameBorderSize(10);
0273 gStyle->SetFrameFillColor(kBlack);
0274 gStyle->SetFrameFillStyle(0);
0275 gStyle->SetFrameLineColor(kBlack);
0276 gStyle->SetFrameLineStyle(0);
0277 gStyle->SetFrameLineWidth(2);
0278 gStyle->SetLineWidth(3);
0279
0280
0281 gStyle->SetPadBorderMode(0);
0282 gStyle->SetPadColor(kWhite);
0283 gStyle->SetPadGridX(false);
0284 gStyle->SetPadGridY(false);
0285 gStyle->SetGridColor(0);
0286 gStyle->SetGridStyle(3);
0287 gStyle->SetGridWidth(1);
0288
0289
0290 gStyle->SetPadTopMargin(0.08);
0291 gStyle->SetPadBottomMargin(0.13);
0292 gStyle->SetPadLeftMargin(0.16);
0293 gStyle->SetPadRightMargin(0.05);
0294
0295
0296 gStyle->SetHistLineColor(kBlack);
0297 gStyle->SetHistLineStyle(0);
0298 gStyle->SetHistLineWidth(3);
0299 gStyle->SetMarkerSize(0.8);
0300 gStyle->SetEndErrorSize(4);
0301 gStyle->SetHatchesLineWidth(1);
0302
0303
0304 gStyle->SetOptStat(0);
0305
0306
0307 gStyle->SetAxisColor(1, "XYZ");
0308 gStyle->SetTickLength(0.03, "XYZ");
0309 gStyle->SetNdivisions(510, "XYZ");
0310 gStyle->SetPadTickX(1);
0311 gStyle->SetPadTickY(1);
0312 gStyle->SetStripDecimals(kFALSE);
0313
0314
0315 gStyle->SetTitleColor(1, "XYZ");
0316 gStyle->SetLabelColor(1, "XYZ");
0317 gStyle->SetLabelFont(42, "XYZ");
0318 gStyle->SetLabelOffset(0.007, "XYZ");
0319 gStyle->SetLabelSize(0.04, "XYZ");
0320 gStyle->SetTitleFont(42, "XYZ");
0321 gStyle->SetTitleSize(0.047, "XYZ");
0322 gStyle->SetTitleXOffset(1.2);
0323 gStyle->SetTitleYOffset(1.5);
0324
0325
0326 gStyle->SetLegendBorderSize(0);
0327 }
0328
0329 void TkAlStyle::set(const TString customTitle) { set(CUSTOM, NONE, customTitle); }