Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef _ALIGNMENT_OFFLINEVALIDATION_CMS_LUMI_H_
0002 #define _ALIGNMENT_OFFLINEVALIDATION_CMS_LUMI_H_
0003 
0004 #include "TPad.h"
0005 #include "TLatex.h"
0006 #include "TLine.h"
0007 #include "TBox.h"
0008 #include <iostream>
0009 
0010 //
0011 // Global variables
0012 //
0013 
0014 TString cmsText = "CMS";
0015 float cmsTextFont = 61;  // default is helvetic-bold
0016 
0017 bool writeExtraText = false;
0018 TString extraText = "Preliminary";
0019 float extraTextFont = 52;  // default is helvetica-italics
0020 
0021 // text sizes and text offsets with respect to the top frame
0022 // in unit of the top margin size
0023 float lumiTextSize = 0.6;
0024 float lumiTextOffset = 0.2;
0025 float cmsTextSize = 0.75;
0026 float cmsTextOffset = 0.1;  // only used in outOfFrame version
0027 
0028 float relPosX = 0.045;
0029 float relPosY = 0.035;
0030 float relExtraDY = 1.2;
0031 
0032 // ratio of "CMS" and extra text size
0033 float extraOverCmsTextSize = 0.76;
0034 
0035 TString lumi_13TeV = "20.1 fb^{-1}";
0036 TString lumi_8TeV = "19.7 fb^{-1}";
0037 TString lumi_7TeV = "5.1 fb^{-1}";
0038 TString lumi_0p9TeV = "";
0039 TString lumi_13p6TeV = "";
0040 TString lumi_sqrtS = "";
0041 bool writeExraLumi = false;
0042 bool drawLogo = false;
0043 
0044 void CMS_lumi(TPad* pad, int iPeriod = 3, int iPosX = 10, TString RLabel = "");
0045 
0046 inline void CMS_lumi(TPad* pad, int iPeriod, int iPosX, TString RLabel) {
0047   bool outOfFrame = false;
0048   if (iPosX / 10 == 0) {
0049     outOfFrame = true;
0050   }
0051   int alignY_ = 3;
0052   int alignX_ = 2;
0053   if (iPosX / 10 == 0)
0054     alignX_ = 1;
0055   if (iPosX == 0)
0056     alignX_ = 1;
0057   if (iPosX == 0)
0058     alignY_ = 1;
0059   if (iPosX / 10 == 1)
0060     alignX_ = 1;
0061   if (iPosX / 10 == 2)
0062     alignX_ = 2;
0063   if (iPosX / 10 == 3)
0064     alignX_ = 3;
0065   //if( iPosX == 0  ) relPosX = 0.12;
0066   int align_ = 10 * alignX_ + alignY_;
0067 
0068   float H = pad->GetWh();
0069   float W = pad->GetWw();
0070   float l = pad->GetLeftMargin();
0071   float t = pad->GetTopMargin();
0072   float r = pad->GetRightMargin();
0073   float b = pad->GetBottomMargin();
0074   //  float e = 0.025;
0075 
0076   pad->cd();
0077 
0078   TString lumiText;
0079   if (iPeriod == 1) {
0080     lumiText += lumi_7TeV;
0081     if (writeExraLumi)
0082       lumiText += " (7 TeV)";
0083   } else if (iPeriod == 2) {
0084     lumiText += lumi_8TeV;
0085     if (writeExraLumi)
0086       lumiText += " (8 TeV)";
0087   } else if (iPeriod == 3) {
0088     lumiText = lumi_8TeV;
0089     if (writeExraLumi) {
0090       lumiText += " (8 TeV)";
0091       lumiText += " + ";
0092       lumiText += lumi_7TeV;
0093       lumiText += " (7 TeV)";
0094     }
0095   } else if (iPeriod == 4) {
0096     lumiText += lumi_13TeV;
0097     if (writeExraLumi)
0098       lumiText += " (#sqrt{s} = 13 TeV)";
0099   } else if (iPeriod == 5) {
0100     lumiText += lumi_0p9TeV;
0101     if (writeExraLumi)
0102       lumiText += " (#sqrt{s} = 0.9 TeV)";
0103   } else if (iPeriod == 6) {
0104     lumiText += lumi_13p6TeV;
0105     if (writeExraLumi)
0106       lumiText += " (#sqrt{s} = 13.6 TeV)";
0107   } else if (iPeriod == 7) {
0108     if (outOfFrame)
0109       lumiText += "#scale[0.85]{";
0110     lumiText += lumi_13TeV;
0111     if (writeExraLumi) {
0112       lumiText += " (13 TeV)";
0113       lumiText += " + ";
0114       lumiText += lumi_8TeV;
0115       lumiText += " (8 TeV)";
0116       lumiText += " + ";
0117       lumiText += lumi_7TeV;
0118       lumiText += " (7 TeV)";
0119     }
0120     if (outOfFrame)
0121       lumiText += "}";
0122   } else if (iPeriod == 12) {
0123     if (writeExraLumi)
0124       lumiText += "8 TeV";
0125   } else if (iPeriod == 0) {
0126     if (writeExraLumi)
0127       lumiText += lumi_sqrtS;
0128   }
0129 
0130   std::cout << lumiText << std::endl;
0131 
0132   TLatex latex;
0133   latex.SetNDC();
0134   latex.SetTextAngle(0);
0135   latex.SetTextColor(kBlack);
0136 
0137   float extraTextSize = extraOverCmsTextSize * cmsTextSize;
0138 
0139   latex.SetTextFont(42);
0140   latex.SetTextAlign(31);
0141   latex.SetTextSize(lumiTextSize * t);
0142   if (RLabel != "") {
0143     latex.DrawLatex(1 - r, 1 - t + lumiTextOffset * t, RLabel);
0144   } else {
0145     latex.DrawLatex(1 - r, 1 - t + lumiTextOffset * t, lumiText);
0146   }
0147 
0148   if (outOfFrame) {
0149     latex.SetTextFont(cmsTextFont);
0150     latex.SetTextAlign(11);
0151     latex.SetTextSize(cmsTextSize * t);
0152     latex.DrawLatex(l, 1 - t + lumiTextOffset * t, cmsText);
0153   }
0154 
0155   pad->cd();
0156 
0157   float posX_ = 0;
0158   if (iPosX % 10 <= 1) {
0159     posX_ = l + relPosX * (1 - l - r);
0160   } else if (iPosX % 10 == 2) {
0161     posX_ = l + 0.5 * (1 - l - r);
0162   } else if (iPosX % 10 == 3) {
0163     posX_ = 1 - r - relPosX * (1 - l - r);
0164   }
0165   float posY_ = 1 - t - relPosY * (1 - t - b);
0166   if (!outOfFrame) {
0167     if (drawLogo) {
0168       posX_ = l + 0.045 * (1 - l - r) * W / H;
0169       posY_ = 1 - t - 0.045 * (1 - t - b);
0170       float xl_0 = posX_;
0171       float yl_0 = posY_ - 0.15;
0172       float xl_1 = posX_ + 0.15 * H / W;
0173       float yl_1 = posY_;
0174       TPad* pad_logo = new TPad("logo", "logo", xl_0, yl_0, xl_1, yl_1);
0175       pad_logo->Draw();
0176       pad_logo->cd();
0177       pad_logo->Modified();
0178       pad->cd();
0179     } else {
0180       latex.SetTextFont(cmsTextFont);
0181       latex.SetTextSize(cmsTextSize * t);
0182       latex.SetTextAlign(align_);
0183       latex.DrawLatex(posX_, posY_, cmsText);
0184       if (writeExtraText) {
0185         latex.SetTextFont(extraTextFont);
0186         latex.SetTextAlign(align_);
0187         latex.SetTextSize(extraTextSize * t);
0188         latex.DrawLatex(posX_, posY_ - relExtraDY * cmsTextSize * t, extraText);
0189       }
0190     }
0191   } else if (writeExtraText) {
0192     if (iPosX == 0) {
0193       posX_ = l + relPosX * (1 - l - r);
0194       posY_ = 1 - t + lumiTextOffset * t;
0195     }
0196     latex.SetTextFont(extraTextFont);
0197     latex.SetTextSize(extraTextSize * t);
0198     latex.SetTextAlign(align_);
0199     latex.DrawLatex(posX_, posY_, extraText);
0200   }
0201   return;
0202 }
0203 
0204 #endif