CMS 3D CMS Logo

CMS_lumi.h
Go to the documentation of this file.
1 #ifndef _ALIGNMENT_OFFLINEVALIDATION_CMS_LUMI_H_
2 #define _ALIGNMENT_OFFLINEVALIDATION_CMS_LUMI_H_
3 
4 #include "TPad.h"
5 #include "TLatex.h"
6 #include "TLine.h"
7 #include "TBox.h"
8 #include <iostream>
9 
10 //
11 // Global variables
12 //
13 
14 TString cmsText = "CMS";
15 float cmsTextFont = 61; // default is helvetic-bold
16 
17 bool writeExtraText = false;
18 TString extraText = "Preliminary";
19 float extraTextFont = 52; // default is helvetica-italics
20 
21 // text sizes and text offsets with respect to the top frame
22 // in unit of the top margin size
23 float lumiTextSize = 0.6;
24 float lumiTextOffset = 0.2;
25 float cmsTextSize = 0.75;
26 float cmsTextOffset = 0.1; // only used in outOfFrame version
27 
28 float relPosX = 0.045;
29 float relPosY = 0.035;
30 float relExtraDY = 1.2;
31 
32 // ratio of "CMS" and extra text size
33 float extraOverCmsTextSize = 0.76;
34 
35 TString lumi_13TeV = "20.1 fb^{-1}";
36 TString lumi_8TeV = "19.7 fb^{-1}";
37 TString lumi_7TeV = "5.1 fb^{-1}";
38 TString lumi_0p9TeV = "";
39 TString lumi_13p6TeV = "";
40 TString lumi_sqrtS = "";
41 bool drawLogo = false;
42 
43 void CMS_lumi(TPad* pad, int iPeriod = 3, int iPosX = 10);
44 
45 void CMS_lumi(TPad* pad, int iPeriod, int iPosX) {
46  bool outOfFrame = false;
47  if (iPosX / 10 == 0) {
48  outOfFrame = true;
49  }
50  int alignY_ = 3;
51  int alignX_ = 2;
52  if (iPosX / 10 == 0)
53  alignX_ = 1;
54  if (iPosX == 0)
55  alignX_ = 1;
56  if (iPosX == 0)
57  alignY_ = 1;
58  if (iPosX / 10 == 1)
59  alignX_ = 1;
60  if (iPosX / 10 == 2)
61  alignX_ = 2;
62  if (iPosX / 10 == 3)
63  alignX_ = 3;
64  //if( iPosX == 0 ) relPosX = 0.12;
65  int align_ = 10 * alignX_ + alignY_;
66 
67  float H = pad->GetWh();
68  float W = pad->GetWw();
69  float l = pad->GetLeftMargin();
70  float t = pad->GetTopMargin();
71  float r = pad->GetRightMargin();
72  float b = pad->GetBottomMargin();
73  // float e = 0.025;
74 
75  pad->cd();
76 
77  TString lumiText;
78  if (iPeriod == 1) {
79  lumiText += lumi_7TeV;
80  lumiText += " (7 TeV)";
81  } else if (iPeriod == 2) {
82  lumiText += lumi_8TeV;
83  lumiText += " (8 TeV)";
84  } else if (iPeriod == 3) {
85  lumiText = lumi_8TeV;
86  lumiText += " (8 TeV)";
87  lumiText += " + ";
88  lumiText += lumi_7TeV;
89  lumiText += " (7 TeV)";
90  } else if (iPeriod == 4) {
91  lumiText += lumi_13TeV;
92  lumiText += " (#sqrt{s} = 13 TeV)";
93  } else if (iPeriod == 5) {
94  lumiText += lumi_0p9TeV;
95  lumiText += " (#sqrt{s} = 0.9 TeV)";
96  } else if (iPeriod == 6) {
97  lumiText += lumi_13p6TeV;
98  lumiText += " (#sqrt{s} = 13.6 TeV)";
99  } else if (iPeriod == 7) {
100  if (outOfFrame)
101  lumiText += "#scale[0.85]{";
102  lumiText += lumi_13TeV;
103  lumiText += " (13 TeV)";
104  lumiText += " + ";
105  lumiText += lumi_8TeV;
106  lumiText += " (8 TeV)";
107  lumiText += " + ";
108  lumiText += lumi_7TeV;
109  lumiText += " (7 TeV)";
110  if (outOfFrame)
111  lumiText += "}";
112  } else if (iPeriod == 12) {
113  lumiText += "8 TeV";
114  } else if (iPeriod == 0) {
115  lumiText += lumi_sqrtS;
116  }
117 
118  std::cout << lumiText << std::endl;
119 
120  TLatex latex;
121  latex.SetNDC();
122  latex.SetTextAngle(0);
123  latex.SetTextColor(kBlack);
124 
125  float extraTextSize = extraOverCmsTextSize * cmsTextSize;
126 
127  latex.SetTextFont(42);
128  latex.SetTextAlign(31);
129  latex.SetTextSize(lumiTextSize * t);
130  latex.DrawLatex(1 - r, 1 - t + lumiTextOffset * t, lumiText);
131 
132  if (outOfFrame) {
133  latex.SetTextFont(cmsTextFont);
134  latex.SetTextAlign(11);
135  latex.SetTextSize(cmsTextSize * t);
136  latex.DrawLatex(l, 1 - t + lumiTextOffset * t, cmsText);
137  }
138 
139  pad->cd();
140 
141  float posX_ = 0;
142  if (iPosX % 10 <= 1) {
143  posX_ = l + relPosX * (1 - l - r);
144  } else if (iPosX % 10 == 2) {
145  posX_ = l + 0.5 * (1 - l - r);
146  } else if (iPosX % 10 == 3) {
147  posX_ = 1 - r - relPosX * (1 - l - r);
148  }
149  float posY_ = 1 - t - relPosY * (1 - t - b);
150  if (!outOfFrame) {
151  if (drawLogo) {
152  posX_ = l + 0.045 * (1 - l - r) * W / H;
153  posY_ = 1 - t - 0.045 * (1 - t - b);
154  float xl_0 = posX_;
155  float yl_0 = posY_ - 0.15;
156  float xl_1 = posX_ + 0.15 * H / W;
157  float yl_1 = posY_;
158  TPad* pad_logo = new TPad("logo", "logo", xl_0, yl_0, xl_1, yl_1);
159  pad_logo->Draw();
160  pad_logo->cd();
161  pad_logo->Modified();
162  pad->cd();
163  } else {
164  latex.SetTextFont(cmsTextFont);
165  latex.SetTextSize(cmsTextSize * t);
166  latex.SetTextAlign(align_);
167  latex.DrawLatex(posX_, posY_, cmsText);
168  if (writeExtraText) {
169  latex.SetTextFont(extraTextFont);
170  latex.SetTextAlign(align_);
171  latex.SetTextSize(extraTextSize * t);
172  latex.DrawLatex(posX_, posY_ - relExtraDY * cmsTextSize * t, extraText);
173  }
174  }
175  } else if (writeExtraText) {
176  if (iPosX == 0) {
177  posX_ = l + relPosX * (1 - l - r);
178  posY_ = 1 - t + lumiTextOffset * t;
179  }
180  latex.SetTextFont(extraTextFont);
181  latex.SetTextSize(extraTextSize * t);
182  latex.SetTextAlign(align_);
183  latex.DrawLatex(posX_, posY_, extraText);
184  }
185  return;
186 }
187 
188 #endif
float relPosY
Definition: CMS_lumi.h:29
TString lumi_8TeV
Definition: CMS_lumi.h:36
float cmsTextFont
Definition: CMS_lumi.h:15
float relExtraDY
Definition: CMS_lumi.h:30
bool drawLogo
Definition: CMS_lumi.h:41
float relPosX
Definition: CMS_lumi.h:28
bool writeExtraText
Definition: CMS_lumi.h:17
TString lumi_7TeV
Definition: CMS_lumi.h:37
float cmsTextSize
Definition: CMS_lumi.h:25
TString extraText
Definition: CMS_lumi.h:18
float cmsTextOffset
Definition: CMS_lumi.h:26
float lumiTextSize
Definition: CMS_lumi.h:23
TString cmsText
Definition: CMS_lumi.h:14
TString lumi_13p6TeV
Definition: CMS_lumi.h:39
TString lumi_13TeV
Definition: CMS_lumi.h:35
float extraOverCmsTextSize
Definition: CMS_lumi.h:33
TString lumi_0p9TeV
Definition: CMS_lumi.h:38
double b
Definition: hdecay.h:118
void CMS_lumi(TPad *pad, int iPeriod=3, int iPosX=10)
Definition: CMS_lumi.h:45
TString lumi_sqrtS
Definition: CMS_lumi.h:40
float extraTextFont
Definition: CMS_lumi.h:19
float lumiTextOffset
Definition: CMS_lumi.h:24