Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:32:37

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);
0045 
0046 inline void CMS_lumi(TPad* pad, int iPeriod, int iPosX) {
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   latex.DrawLatex(1 - r, 1 - t + lumiTextOffset * t, lumiText);
0143 
0144   if (outOfFrame) {
0145     latex.SetTextFont(cmsTextFont);
0146     latex.SetTextAlign(11);
0147     latex.SetTextSize(cmsTextSize * t);
0148     latex.DrawLatex(l, 1 - t + lumiTextOffset * t, cmsText);
0149   }
0150 
0151   pad->cd();
0152 
0153   float posX_ = 0;
0154   if (iPosX % 10 <= 1) {
0155     posX_ = l + relPosX * (1 - l - r);
0156   } else if (iPosX % 10 == 2) {
0157     posX_ = l + 0.5 * (1 - l - r);
0158   } else if (iPosX % 10 == 3) {
0159     posX_ = 1 - r - relPosX * (1 - l - r);
0160   }
0161   float posY_ = 1 - t - relPosY * (1 - t - b);
0162   if (!outOfFrame) {
0163     if (drawLogo) {
0164       posX_ = l + 0.045 * (1 - l - r) * W / H;
0165       posY_ = 1 - t - 0.045 * (1 - t - b);
0166       float xl_0 = posX_;
0167       float yl_0 = posY_ - 0.15;
0168       float xl_1 = posX_ + 0.15 * H / W;
0169       float yl_1 = posY_;
0170       TPad* pad_logo = new TPad("logo", "logo", xl_0, yl_0, xl_1, yl_1);
0171       pad_logo->Draw();
0172       pad_logo->cd();
0173       pad_logo->Modified();
0174       pad->cd();
0175     } else {
0176       latex.SetTextFont(cmsTextFont);
0177       latex.SetTextSize(cmsTextSize * t);
0178       latex.SetTextAlign(align_);
0179       latex.DrawLatex(posX_, posY_, cmsText);
0180       if (writeExtraText) {
0181         latex.SetTextFont(extraTextFont);
0182         latex.SetTextAlign(align_);
0183         latex.SetTextSize(extraTextSize * t);
0184         latex.DrawLatex(posX_, posY_ - relExtraDY * cmsTextSize * t, extraText);
0185       }
0186     }
0187   } else if (writeExtraText) {
0188     if (iPosX == 0) {
0189       posX_ = l + relPosX * (1 - l - r);
0190       posY_ = 1 - t + lumiTextOffset * t;
0191     }
0192     latex.SetTextFont(extraTextFont);
0193     latex.SetTextSize(extraTextSize * t);
0194     latex.SetTextAlign(align_);
0195     latex.DrawLatex(posX_, posY_, extraText);
0196   }
0197   return;
0198 }
0199 
0200 #endif