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 writeExraLumi = false;
42 bool drawLogo = false;
43 
44 void CMS_lumi(TPad* pad, int iPeriod = 3, int iPosX = 10, TString RLabel = "");
45 
46 inline void CMS_lumi(TPad* pad, int iPeriod, int iPosX, TString RLabel) {
47  bool outOfFrame = false;
48  if (iPosX / 10 == 0) {
49  outOfFrame = true;
50  }
51  int alignY_ = 3;
52  int alignX_ = 2;
53  if (iPosX / 10 == 0)
54  alignX_ = 1;
55  if (iPosX == 0)
56  alignX_ = 1;
57  if (iPosX == 0)
58  alignY_ = 1;
59  if (iPosX / 10 == 1)
60  alignX_ = 1;
61  if (iPosX / 10 == 2)
62  alignX_ = 2;
63  if (iPosX / 10 == 3)
64  alignX_ = 3;
65  //if( iPosX == 0 ) relPosX = 0.12;
66  int align_ = 10 * alignX_ + alignY_;
67 
68  float H = pad->GetWh();
69  float W = pad->GetWw();
70  float l = pad->GetLeftMargin();
71  float t = pad->GetTopMargin();
72  float r = pad->GetRightMargin();
73  float b = pad->GetBottomMargin();
74  // float e = 0.025;
75 
76  pad->cd();
77 
78  TString lumiText;
79  if (iPeriod == 1) {
80  lumiText += lumi_7TeV;
81  if (writeExraLumi)
82  lumiText += " (7 TeV)";
83  } else if (iPeriod == 2) {
84  lumiText += lumi_8TeV;
85  if (writeExraLumi)
86  lumiText += " (8 TeV)";
87  } else if (iPeriod == 3) {
88  lumiText = lumi_8TeV;
89  if (writeExraLumi) {
90  lumiText += " (8 TeV)";
91  lumiText += " + ";
92  lumiText += lumi_7TeV;
93  lumiText += " (7 TeV)";
94  }
95  } else if (iPeriod == 4) {
96  lumiText += lumi_13TeV;
97  if (writeExraLumi)
98  lumiText += " (#sqrt{s} = 13 TeV)";
99  } else if (iPeriod == 5) {
100  lumiText += lumi_0p9TeV;
101  if (writeExraLumi)
102  lumiText += " (#sqrt{s} = 0.9 TeV)";
103  } else if (iPeriod == 6) {
104  lumiText += lumi_13p6TeV;
105  if (writeExraLumi)
106  lumiText += " (#sqrt{s} = 13.6 TeV)";
107  } else if (iPeriod == 7) {
108  if (outOfFrame)
109  lumiText += "#scale[0.85]{";
110  lumiText += lumi_13TeV;
111  if (writeExraLumi) {
112  lumiText += " (13 TeV)";
113  lumiText += " + ";
114  lumiText += lumi_8TeV;
115  lumiText += " (8 TeV)";
116  lumiText += " + ";
117  lumiText += lumi_7TeV;
118  lumiText += " (7 TeV)";
119  }
120  if (outOfFrame)
121  lumiText += "}";
122  } else if (iPeriod == 12) {
123  if (writeExraLumi)
124  lumiText += "8 TeV";
125  } else if (iPeriod == 0) {
126  if (writeExraLumi)
127  lumiText += lumi_sqrtS;
128  }
129 
130  std::cout << lumiText << std::endl;
131 
132  TLatex latex;
133  latex.SetNDC();
134  latex.SetTextAngle(0);
135  latex.SetTextColor(kBlack);
136 
137  float extraTextSize = extraOverCmsTextSize * cmsTextSize;
138 
139  latex.SetTextFont(42);
140  latex.SetTextAlign(31);
141  latex.SetTextSize(lumiTextSize * t);
142  if (RLabel != "") {
143  latex.DrawLatex(1 - r, 1 - t + lumiTextOffset * t, RLabel);
144  } else {
145  latex.DrawLatex(1 - r, 1 - t + lumiTextOffset * t, lumiText);
146  }
147 
148  if (outOfFrame) {
149  latex.SetTextFont(cmsTextFont);
150  latex.SetTextAlign(11);
151  latex.SetTextSize(cmsTextSize * t);
152  latex.DrawLatex(l, 1 - t + lumiTextOffset * t, cmsText);
153  }
154 
155  pad->cd();
156 
157  float posX_ = 0;
158  if (iPosX % 10 <= 1) {
159  posX_ = l + relPosX * (1 - l - r);
160  } else if (iPosX % 10 == 2) {
161  posX_ = l + 0.5 * (1 - l - r);
162  } else if (iPosX % 10 == 3) {
163  posX_ = 1 - r - relPosX * (1 - l - r);
164  }
165  float posY_ = 1 - t - relPosY * (1 - t - b);
166  if (!outOfFrame) {
167  if (drawLogo) {
168  posX_ = l + 0.045 * (1 - l - r) * W / H;
169  posY_ = 1 - t - 0.045 * (1 - t - b);
170  float xl_0 = posX_;
171  float yl_0 = posY_ - 0.15;
172  float xl_1 = posX_ + 0.15 * H / W;
173  float yl_1 = posY_;
174  TPad* pad_logo = new TPad("logo", "logo", xl_0, yl_0, xl_1, yl_1);
175  pad_logo->Draw();
176  pad_logo->cd();
177  pad_logo->Modified();
178  pad->cd();
179  } else {
180  latex.SetTextFont(cmsTextFont);
181  latex.SetTextSize(cmsTextSize * t);
182  latex.SetTextAlign(align_);
183  latex.DrawLatex(posX_, posY_, cmsText);
184  if (writeExtraText) {
185  latex.SetTextFont(extraTextFont);
186  latex.SetTextAlign(align_);
187  latex.SetTextSize(extraTextSize * t);
188  latex.DrawLatex(posX_, posY_ - relExtraDY * cmsTextSize * t, extraText);
189  }
190  }
191  } else if (writeExtraText) {
192  if (iPosX == 0) {
193  posX_ = l + relPosX * (1 - l - r);
194  posY_ = 1 - t + lumiTextOffset * t;
195  }
196  latex.SetTextFont(extraTextFont);
197  latex.SetTextSize(extraTextSize * t);
198  latex.SetTextAlign(align_);
199  latex.DrawLatex(posX_, posY_, extraText);
200  }
201  return;
202 }
203 
204 #endif
float relPosY
Definition: CMS_lumi.h:29
TString lumi_8TeV
Definition: CMS_lumi.h:36
float cmsTextFont
Definition: CMS_lumi.h:15
bool writeExraLumi
Definition: CMS_lumi.h:41
float relExtraDY
Definition: CMS_lumi.h:30
bool drawLogo
Definition: CMS_lumi.h:42
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:120
TString lumi_sqrtS
Definition: CMS_lumi.h:40
void CMS_lumi(TPad *pad, int iPeriod=3, int iPosX=10, TString RLabel="")
Definition: CMS_lumi.h:46
float extraTextFont
Definition: CMS_lumi.h:19
float lumiTextOffset
Definition: CMS_lumi.h:24