Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:19

0001 #include "Alignment/OfflineValidation/interface/TkAlStyle.h"
0002 
0003 TString TkAlStyle::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 TString TkAlStyle::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 TString TkAlStyle::toTString(const AlignObj obj) {
0038   TString str = "";
0039   if (obj == IDEALAlign)
0040     str = "MC (no mis-alignment)";
0041   else if (obj == RUN1Align)
0042     str = "No Run-2 alignment (Run-1 geometry)";
0043   else if (obj == CRUZETAlign)
0044     str = "Aligned (0T cosmic rays)";
0045   else if (obj == CRAFTAlign)
0046     str = "Aligned (cosmic rays)";
0047   else if (obj == Coll0TAlign)
0048     str = "Aligned (0T collisions + cosmic rays)";
0049 
0050   return str;
0051 }
0052 
0053 // Line and fill styles depending on alignment object
0054 int TkAlStyle::color(const AlignObj obj) {
0055   int col = 1;
0056   if (obj == IDEALAlign)
0057     col = kGray + 1;
0058   else if (obj == RUN1Align)
0059     col = kBlack;
0060   else if (obj == CRUZETAlign)
0061     col = kGreen + 2;
0062   else if (obj == CRAFTAlign)
0063     col = kBlue;
0064   else if (obj == Coll0TAlign)
0065     col = kRed;
0066 
0067   return col;
0068 }
0069 
0070 int TkAlStyle::style(const AlignObj obj) { return obj == RUN1Align ? kDashed : kSolid; }
0071 
0072 PublicationStatus TkAlStyle::publicationStatus_ = NO_STATUS;
0073 Era TkAlStyle::era_ = NONE;
0074 TString TkAlStyle::legendheader = "";
0075 TString TkAlStyle::legendoptions = "all";
0076 TString TkAlStyle::customTitle_ = "";
0077 TString TkAlStyle::customRightTitle_ = "";
0078 double TkAlStyle::lineHeight_ = 0.042;
0079 double TkAlStyle::margin_ = 0.04;
0080 double TkAlStyle::textSize = 0.035;
0081 
0082 // --------------------------------------------------------------
0083 PublicationStatus TkAlStyle::toStatus(std::string status) {
0084   PublicationStatus st;
0085   std::for_each(status.begin(), status.end(), [](char& c) { c = ::toupper(c); });
0086   if (status == "NO_STATUS")
0087     st = NO_STATUS;
0088   else if (status == "INTERNAL")
0089     st = INTERNAL;
0090   else if (status == "SIMULATION (INTERNAL)")
0091     st = INTERNAL_SIMULATION;
0092   else if (status == "PRELIMINARY")
0093     st = PRELIMINARY;
0094   else if (status == "PUBLIC")
0095     st = PUBLIC;
0096   else if (status == "SIMULATION")
0097     st = SIMULATION;
0098   else if (status == "UNPUBLISHED")
0099     st = UNPUBLISHED;
0100   else
0101     st = CUSTOM;
0102 
0103   return st;
0104 }
0105 
0106 // --------------------------------------------------------------
0107 void TkAlStyle::setXCoordinatesL(const double relWidth, double& x0, double& x1) {
0108   x0 = gStyle->GetPadLeftMargin() + margin_;
0109   x1 = x0 + relWidth * (1. - gStyle->GetPadLeftMargin() - gStyle->GetPadRightMargin() - 2. * margin_);
0110 }
0111 
0112 // --------------------------------------------------------------
0113 void TkAlStyle::setXCoordinatesR(const double relWidth, double& x0, double& x1) {
0114   x0 = 1. - gStyle->GetPadRightMargin() - margin_ -
0115        relWidth * (1. - gStyle->GetPadLeftMargin() - gStyle->GetPadRightMargin() - 2. * margin_);
0116   x1 = 1. - gStyle->GetPadRightMargin() - margin_;
0117 }
0118 
0119 // --------------------------------------------------------------
0120 void TkAlStyle::setYCoordinatesT(const int nEntries, double& y0, double& y1) {
0121   y1 = 1. - gStyle->GetPadTopMargin() - margin_;
0122   y0 = y1 - nEntries * lineHeight_;
0123 }
0124 
0125 // --------------------------------------------------------------
0126 void TkAlStyle::setYCoordinatesB(const int nEntries, double& y0, double& y1) {
0127   y1 = gStyle->GetPadBottomMargin() + margin_;
0128   y0 = y1 + nEntries * lineHeight_;
0129 }
0130 
0131 // --------------------------------------------------------------
0132 TLegend* TkAlStyle::legend(const int nEntries, const double relWidth, const bool left, const bool top) {
0133   double x0 = 0.;
0134   double x1 = 0.;
0135   double y0 = 0.;
0136   double y1 = 0.;
0137   bool hasheader = (TkAlStyle::legendheader != "");
0138   if (left)
0139     setXCoordinatesL(relWidth, x0, x1);
0140   else
0141     setXCoordinatesR(relWidth, x0, x1);
0142   if (top)
0143     setYCoordinatesT(nEntries + hasheader, y0, y1);
0144   else
0145     setYCoordinatesB(nEntries + hasheader, y0, y1);
0146 
0147   TLegend* leg = new TLegend(x0, y0, x1, y1);
0148   leg->SetBorderSize(0);
0149   leg->SetFillColor(0);
0150   leg->SetFillStyle(0);
0151   leg->SetTextFont(42);
0152   leg->SetTextSize(textSize);
0153   if (hasheader)
0154     leg->SetHeader(TkAlStyle::legendheader);
0155 
0156   return leg;
0157 }
0158 
0159 // --------------------------------------------------------------
0160 TPaveText* TkAlStyle::label(const int nEntries, const double relWidth, const bool left, const bool top) {
0161   double x0 = 0.;
0162   double x1 = 0.;
0163   double y0 = 0.;
0164   double y1 = 0.;
0165   if (left)
0166     setXCoordinatesL(relWidth, x0, x1);
0167   else
0168     setXCoordinatesR(relWidth, x0, x1);
0169   if (top)
0170     setYCoordinatesT(nEntries, y0, y1);
0171   else
0172     setYCoordinatesB(nEntries, y0, y1);
0173 
0174   TPaveText* label = new TPaveText(x0, y0, x1, y1, "NDC");
0175   label->SetBorderSize(0);
0176   label->SetFillColor(0);
0177   label->SetFillStyle(0);
0178   label->SetTextFont(42);
0179   label->SetTextAlign(12);  // left adjusted and vertically centered
0180   label->SetTextSize(textSize);
0181   label->SetMargin(0.);
0182 
0183   return label;
0184 }
0185 
0186 // --------------------------------------------------------------
0187 //unfortunately no #definecommand in TLatex...
0188 //#CMS{text} gives CMS in big bold, text in italics
0189 //#CMS with no "argument" just gives CMS in big bold
0190 //#noCMS{text} gives text in italics
0191 TString TkAlStyle::applyCMS(const TString& txt) {
0192   TString newtxt = txt;
0193   newtxt.ReplaceAll("#CMS{", "#scale[1.4]{#font[61]{CMS}} #font[52]{");
0194   newtxt.ReplaceAll("#noCMS{", "#font[52]{");
0195   newtxt.ReplaceAll("#CMS", "#scale[1.4]{#font[61]{CMS}}");
0196   return newtxt;
0197 }
0198 
0199 // --------------------------------------------------------------
0200 TPaveText* TkAlStyle::title(const TString& txt) {
0201   double x0 = gStyle->GetPadLeftMargin();
0202   double x1 = 1. - gStyle->GetPadRightMargin();
0203   double y0 = 1. - gStyle->GetPadTopMargin();
0204   double y1 = 1.;
0205   if (txt.Contains("#CMS"))
0206     y0 += .02;
0207   TPaveText* theTitle = new TPaveText(x0, y0, x1, y1, "NDC");
0208   theTitle->SetBorderSize(0);
0209   theTitle->SetFillColor(10);
0210   theTitle->SetFillStyle(0);
0211   theTitle->SetTextFont(42);
0212   theTitle->SetTextAlign(13);  // left bottom adjusted
0213   theTitle->SetTextSize(0.038);
0214   theTitle->SetMargin(0.);
0215   theTitle->AddText(applyCMS(txt));
0216 
0217   return theTitle;
0218 }
0219 
0220 // --------------------------------------------------------------
0221 TPaveText* TkAlStyle::righttitle(const TString& txt) {
0222   TString newtxt = applyCMS(txt);
0223   double x0 = gStyle->GetPadLeftMargin();
0224   double x1 = 1. - gStyle->GetPadRightMargin();
0225   double y0 = 1. - gStyle->GetPadTopMargin();
0226   double y1 = 1.;
0227   TPaveText* theTitle = new TPaveText(x0, y0, x1, y1, "NDC");
0228   theTitle->SetBorderSize(0);
0229   theTitle->SetFillColor(10);
0230   theTitle->SetFillStyle(0);
0231   theTitle->SetTextFont(42);
0232   theTitle->SetTextAlign(33);  // right bottom adjusted
0233   theTitle->SetTextSize(0.038);
0234   theTitle->SetMargin(0.);
0235   theTitle->AddText(newtxt);
0236 
0237   return theTitle;
0238 }
0239 
0240 // --------------------------------------------------------------
0241 TString TkAlStyle::header(const PublicationStatus status) {
0242   TString txt;
0243   if (status == NO_STATUS) {
0244     std::cout << "Status not set yet!  Can't draw the title!" << std::endl;
0245   } else if (status == INTERNAL_SIMULATION) {
0246     txt = "#noCMS{Simulation}";
0247   } else if (status == INTERNAL) {
0248     txt = "#CMS{Internal}";
0249   } else if (status == PRELIMINARY) {
0250     txt = "#CMS{Preliminary}";
0251   } else if (status == PUBLIC) {
0252     txt = "#CMS";
0253   } else if (status == SIMULATION) {
0254     txt = "#CMS{Simulation}";
0255   } else if (status == UNPUBLISHED) {
0256     txt = "#CMS{(unpublished)}";
0257   } else if (status == CUSTOM) {
0258     txt = customTitle_;
0259   }
0260 
0261   return txt;
0262 }
0263 
0264 TString TkAlStyle::rightheader(const Era era) {
0265   TString txt = "";
0266   if (era != NONE) {
0267     txt = toTString(era);
0268   } else {
0269     txt = customRightTitle_;
0270   }
0271   return txt;
0272 }
0273 
0274 // --------------------------------------------------------------
0275 void TkAlStyle::set(const PublicationStatus status,
0276                     const Era era,
0277                     const TString customTitle,
0278                     const TString customRightTitle) {
0279   // Store the PublicationStatus for later usage, e.g. in the title
0280   publicationStatus_ = status;
0281   customTitle_ = customTitle;
0282   customRightTitle_ = customRightTitle;
0283   era_ = era;
0284   if (publicationStatus_ == CUSTOM && customTitle_ == "")
0285     std::cout << "Error: you are trying to use a custom title, but you don't provide it" << std::endl;
0286   if (publicationStatus_ != CUSTOM && customTitle_ != "")
0287     std::cout
0288         << "Error: you provide a custom title, but you don't indicate CUSTOM status.  Your title will not be used."
0289         << std::endl;
0290 
0291   // Suppress message when canvas has been saved
0292   gErrorIgnoreLevel = 1001;
0293 
0294   // Zero horizontal error bars
0295   gStyle->SetErrorX(0);
0296 
0297   //  For the canvas
0298   gStyle->SetCanvasBorderMode(0);
0299   gStyle->SetCanvasColor(kWhite);
0300   gStyle->SetCanvasDefH(800);  //Height of canvas
0301   gStyle->SetCanvasDefW(800);  //Width of canvas
0302   gStyle->SetCanvasDefX(0);    //Position on screen
0303   gStyle->SetCanvasDefY(0);
0304 
0305   //  For the frame
0306   gStyle->SetFrameBorderMode(0);
0307   gStyle->SetFrameBorderSize(10);
0308   gStyle->SetFrameFillColor(kBlack);
0309   gStyle->SetFrameFillStyle(0);
0310   gStyle->SetFrameLineColor(kBlack);
0311   gStyle->SetFrameLineStyle(0);
0312   gStyle->SetFrameLineWidth(2);
0313   gStyle->SetLineWidth(3);
0314 
0315   //  For the Pad
0316   gStyle->SetPadBorderMode(0);
0317   gStyle->SetPadColor(kWhite);
0318   gStyle->SetPadGridX(false);
0319   gStyle->SetPadGridY(false);
0320   gStyle->SetGridColor(0);
0321   gStyle->SetGridStyle(3);
0322   gStyle->SetGridWidth(1);
0323 
0324   //  Margins
0325   gStyle->SetPadTopMargin(0.08);
0326   gStyle->SetPadBottomMargin(0.13);
0327   gStyle->SetPadLeftMargin(0.16);
0328   gStyle->SetPadRightMargin(0.05);
0329 
0330   //  For the histo:
0331   gStyle->SetHistLineColor(kBlack);
0332   gStyle->SetHistLineStyle(0);
0333   gStyle->SetHistLineWidth(3);
0334   gStyle->SetMarkerSize(0.8);
0335   gStyle->SetEndErrorSize(4);
0336   gStyle->SetHatchesLineWidth(1);
0337 
0338   //  For the statistics box:
0339   gStyle->SetOptStat(0);
0340 
0341   //  For the axis
0342   gStyle->SetAxisColor(1, "XYZ");
0343   gStyle->SetTickLength(0.03, "XYZ");
0344   gStyle->SetNdivisions(510, "XYZ");
0345   gStyle->SetPadTickX(1);
0346   gStyle->SetPadTickY(1);
0347   gStyle->SetStripDecimals(kFALSE);
0348 
0349   //  For the axis labels and titles
0350   gStyle->SetTitleColor(1, "XYZ");
0351   gStyle->SetLabelColor(1, "XYZ");
0352   gStyle->SetLabelFont(42, "XYZ");
0353   gStyle->SetLabelOffset(0.007, "XYZ");
0354   gStyle->SetLabelSize(0.04, "XYZ");
0355   gStyle->SetTitleFont(42, "XYZ");
0356   gStyle->SetTitleSize(0.047, "XYZ");
0357   gStyle->SetTitleXOffset(1.2);
0358   gStyle->SetTitleYOffset(1.5);
0359 
0360   //  For the legend
0361   gStyle->SetLegendBorderSize(0);
0362 }
0363 
0364 void TkAlStyle::set(const TString customTitle) { set(CUSTOM, NONE, customTitle); }