Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:56

0001 // Common style file for TkAl public plots
0002 // --------------------------------------------------------------
0003 //
0004 // Defines a set of functions to define the plotting style and
0005 // provide commonly used style objects such as histogram title
0006 // and legends. Can be used in compiled code and uncompiled scripts.
0007 //
0008 // Always call TkAlStyle::set(PublicationStatus) in the beginning
0009 // of your plotting script to adjust the gStyle options. Also,
0010 // the behaviour of some other methods of this class depend on
0011 // this, e.g. the histogram title displays "CMS preliminary" etc.
0012 // depending on the PublicationStatus. Call TkAlStyle::set before
0013 // declaring any histograms (or call TH1::UseCurrentStyle()) to
0014 // make sure the style settings are used.
0015 // --------------------------------------------------------------
0016 
0017 #ifndef ALIGNMENT_OFFLINEVALIDATION_TKAL_STYLE_H
0018 #define ALIGNMENT_OFFLINEVALIDATION_TKAL_STYLE_H
0019 
0020 #include "TColor.h"
0021 #include "TError.h"
0022 #include "TLegend.h"
0023 #include "TPaveText.h"
0024 #include "TString.h"
0025 #include "TStyle.h"
0026 #include <iostream>
0027 #include <string>
0028 #include <algorithm>
0029 
0030 // Publication status: determines what is plotted in title
0031 enum PublicationStatus {
0032   NO_STATUS,
0033   INTERNAL,
0034   INTERNAL_SIMULATION,
0035   PRELIMINARY,
0036   PUBLIC,
0037   SIMULATION,
0038   UNPUBLISHED,
0039   CUSTOM
0040 };
0041 
0042 // Data era: determines labels of data-taking periods, e.g. CRUZET
0043 enum Era { NONE, CRUZET15, CRAFT15, COLL0T15 };
0044 
0045 // Alignment object
0046 enum AlignObj { IDEALAlign, RUN1Align, CRUZETAlign, CRAFTAlign, Coll0TAlign };
0047 
0048 class TkAlStyle {
0049 public:
0050   // Adjusts the gStyle settings and store the PublicationStatus
0051   static void set(const PublicationStatus status,
0052                   const Era era = NONE,
0053                   const TString customTitle = "",
0054                   const TString customRightTitle = "");
0055   static void set(const TString customTitle);
0056   static PublicationStatus status() { return publicationStatus_; }
0057 
0058   static TString toTString(const PublicationStatus status);
0059   static TString toTString(const Era era);
0060   static TString toTString(const AlignObj obj);
0061 
0062   static int color(const AlignObj obj);
0063   static int style(const AlignObj obj);
0064 
0065   // Draws a title "<CMS label> 2015" on the current pad
0066   // dependending on the PublicationStatus
0067   //  INTERNAL    : no extra label (intended for AN-only plots with data)
0068   //  INTERNAL    : show "Simulation" label (intended for AN-only plots, no "CMS")
0069   //  PRELIMINARY : show "CMS preliminary 2015" label
0070   //  PUBLIC      : show "CMS 2015" label
0071   //  SIMULATION  : show "CMS Simulation" label
0072   //  UNPUBLISHED : show "CMS (unpublished)" label (intended for additional material on TWiki)
0073   // Note that this method does not allow for easy memory
0074   // handling. For that, use standardTitle().
0075   static void drawStandardTitle() {
0076     standardTitle()->Draw("same");
0077     standardRightTitle()->Draw("same");
0078   }
0079   static void drawStandardTitle(const Era era) {
0080     standardTitle()->Draw("same");
0081     standardRightTitle(era)->Draw("same");
0082   }
0083   static PublicationStatus toStatus(std::string _status);
0084 
0085   // Returns a TPaveText object that fits as a histogram title
0086   // with the current pad dimensions.
0087   // It has the same text as described in drawStandardTitle().
0088   // The idea of this method is that one has control over the
0089   // TPaveText object and can do proper memory handling.
0090   static TPaveText* standardTitle(PublicationStatus status) { return title(header(status)); }
0091   static TPaveText* standardTitle() { return standardTitle(publicationStatus_); }
0092 
0093   static TPaveText* standardRightTitle(const Era era) { return righttitle(rightheader(era)); }
0094   static TPaveText* standardRightTitle() { return standardRightTitle(era_); }
0095 
0096   // Returns a TPaveText object that fits as a histogram title
0097   // with the current pad dimensions and displays the specified text txt.
0098   static TPaveText* customTitle(const TString& txt) { return title(txt); }
0099   static TPaveText* customRightTitle(const TString& txt) { return righttitle(txt); }
0100 
0101   static TString legendheader;
0102   static TString legendoptions;
0103   static double textSize;
0104   // Returns a TLegend object that fits into the top-right corner
0105   // of the current pad. Its width, relative to the pad size (without
0106   // margins), can be specified. Its height is optimized for nEntries
0107   // entries.
0108   static TLegend* legend(const int nEntries, const double relWidth = 0.5) { return legendTR(nEntries, relWidth); }
0109   static TLegend* legend(TString position, const int nEntries, const double relWidth = 0.5) {
0110     position.ToLower();
0111     if (!(position.Contains("top") || position.Contains("bottom")))
0112       position += "top";
0113     if (!(position.Contains("left") || position.Contains("right")))
0114       position += "right";
0115     TLegend* leg = nullptr;
0116     if (position.Contains("top") && position.Contains("right")) {
0117       leg = legendTR(nEntries, relWidth);
0118     } else if (position.Contains("top") && position.Contains("left")) {
0119       leg = legendTL(nEntries, relWidth);
0120     } else if (position.Contains("bottom") && position.Contains("right")) {
0121       leg = legendBR(nEntries, relWidth);
0122     } else if (position.Contains("bottom") && position.Contains("left")) {
0123       leg = legendBL(nEntries, relWidth);
0124     } else {
0125       leg = legendTR(nEntries, relWidth);
0126     }
0127 
0128     return leg;
0129   }
0130   // Same but explicitly state position on pad
0131   static TLegend* legendTL(const int nEntries, const double relWidth = 0.5) {
0132     return legend(nEntries, relWidth, true, true);
0133   }
0134   static TLegend* legendTR(const int nEntries, const double relWidth = 0.5) {
0135     return legend(nEntries, relWidth, false, true);
0136   }
0137   static TLegend* legendBL(const int nEntries, const double relWidth = 0.5) {
0138     return legend(nEntries, relWidth, true, false);
0139   }
0140   static TLegend* legendBR(const int nEntries, const double relWidth = 0.5) {
0141     return legend(nEntries, relWidth, false, false);
0142   }
0143 
0144   // Returns a TPaveText object that fits into the top-right corner
0145   // of the current pad and that can be used for additional labels.
0146   // Its width, relative to the pad size (without margins), can be
0147   // specified. Its height is optimized for nEntries entries.
0148   static TPaveText* label(const int nEntries, const double relWidth = 0.5) { return labelTR(nEntries, relWidth); }
0149 
0150   static TPaveText* label(TString position, const int nEntries, const double relWidth = 0.5) {
0151     position.ToLower();
0152     if (!(position.Contains("top") || position.Contains("bottom")))
0153       position += "top";
0154     if (!(position.Contains("left") || position.Contains("right")))
0155       position += "right";
0156     TPaveText* label = nullptr;
0157     if (position.Contains("top") && position.Contains("right")) {
0158       label = labelTR(nEntries, relWidth);
0159     } else if (position.Contains("top") && position.Contains("left")) {
0160       label = labelTL(nEntries, relWidth);
0161     } else if (position.Contains("bottom") && position.Contains("right")) {
0162       label = labelBR(nEntries, relWidth);
0163     } else if (position.Contains("bottom") && position.Contains("left")) {
0164       label = labelBL(nEntries, relWidth);
0165     } else {
0166       label = labelTR(nEntries, relWidth);
0167     }
0168 
0169     return label;
0170   }
0171 
0172   // Same but explicitly state position on pad
0173   static TPaveText* labelTL(const int nEntries, const double relWidth = 0.5) {
0174     return label(nEntries, relWidth, true, true);
0175   }
0176   static TPaveText* labelTR(const int nEntries, const double relWidth = 0.5) {
0177     return label(nEntries, relWidth, false, true);
0178   }
0179   static TPaveText* labelBL(const int nEntries, const double relWidth = 0.5) {
0180     return label(nEntries, relWidth, true, false);
0181   }
0182   static TPaveText* labelBR(const int nEntries, const double relWidth = 0.5) {
0183     return label(nEntries, relWidth, false, false);
0184   }
0185 
0186   static double lineHeight() { return lineHeight_; }
0187 
0188 private:
0189   static PublicationStatus publicationStatus_;
0190   static Era era_;
0191   static TString customTitle_;
0192   static TString customRightTitle_;
0193   static double lineHeight_;
0194   static double margin_;
0195 
0196   // creates a title
0197   static TString applyCMS(const TString& txt);
0198   static TPaveText* title(const TString& txt);
0199   static TPaveText* righttitle(const TString& txt);
0200 
0201   // returns the standard-title (CMS label 2015) depending
0202   // on the PublicationStatus
0203   static TString header(const PublicationStatus status);
0204   static TString rightheader(const Era era);
0205 
0206   // NDC coordinates for TPave, TLegend,...
0207   static void setXCoordinatesL(const double relWidth, double& x0, double& x1);
0208   static void setXCoordinatesR(const double relWidth, double& x0, double& x1);
0209   static void setYCoordinatesT(const int nEntries, double& y0, double& y1);
0210   static void setYCoordinatesB(const int nEntries, double& y0, double& y1);
0211 
0212   static TLegend* legend(const int nEntries, const double relWidth, const bool left, const bool top);
0213   static TPaveText* label(const int nEntries, const double relWidth, const bool leftt, const bool top);
0214 };
0215 
0216 #endif