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);
45 
46 inline void CMS_lumi(TPad* pad, int iPeriod, int iPosX) {
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  latex.DrawLatex(1 - r, 1 - t + lumiTextOffset * t, lumiText);
143 
144  if (outOfFrame) {
145  latex.SetTextFont(cmsTextFont);
146  latex.SetTextAlign(11);
147  latex.SetTextSize(cmsTextSize * t);
148  latex.DrawLatex(l, 1 - t + lumiTextOffset * t, cmsText);
149  }
150 
151  pad->cd();
152 
153  float posX_ = 0;
154  if (iPosX % 10 <= 1) {
155  posX_ = l + relPosX * (1 - l - r);
156  } else if (iPosX % 10 == 2) {
157  posX_ = l + 0.5 * (1 - l - r);
158  } else if (iPosX % 10 == 3) {
159  posX_ = 1 - r - relPosX * (1 - l - r);
160  }
161  float posY_ = 1 - t - relPosY * (1 - t - b);
162  if (!outOfFrame) {
163  if (drawLogo) {
164  posX_ = l + 0.045 * (1 - l - r) * W / H;
165  posY_ = 1 - t - 0.045 * (1 - t - b);
166  float xl_0 = posX_;
167  float yl_0 = posY_ - 0.15;
168  float xl_1 = posX_ + 0.15 * H / W;
169  float yl_1 = posY_;
170  TPad* pad_logo = new TPad("logo", "logo", xl_0, yl_0, xl_1, yl_1);
171  pad_logo->Draw();
172  pad_logo->cd();
173  pad_logo->Modified();
174  pad->cd();
175  } else {
176  latex.SetTextFont(cmsTextFont);
177  latex.SetTextSize(cmsTextSize * t);
178  latex.SetTextAlign(align_);
179  latex.DrawLatex(posX_, posY_, cmsText);
180  if (writeExtraText) {
181  latex.SetTextFont(extraTextFont);
182  latex.SetTextAlign(align_);
183  latex.SetTextSize(extraTextSize * t);
184  latex.DrawLatex(posX_, posY_ - relExtraDY * cmsTextSize * t, extraText);
185  }
186  }
187  } else if (writeExtraText) {
188  if (iPosX == 0) {
189  posX_ = l + relPosX * (1 - l - r);
190  posY_ = 1 - t + lumiTextOffset * t;
191  }
192  latex.SetTextFont(extraTextFont);
193  latex.SetTextSize(extraTextSize * t);
194  latex.SetTextAlign(align_);
195  latex.DrawLatex(posX_, posY_, extraText);
196  }
197  return;
198 }
199 
200 #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
void CMS_lumi(TPad *pad, int iPeriod=3, int iPosX=10)
Definition: CMS_lumi.h:46
TString lumi_sqrtS
Definition: CMS_lumi.h:40
float extraTextFont
Definition: CMS_lumi.h:19
float lumiTextOffset
Definition: CMS_lumi.h:24