CMS 3D CMS Logo

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