ATLAS Offline Software
InnerDetector/InDetCalibAlgs/PixelCalibAlgs/PixelCalibAlgs/AtlasStyle.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <vector>
6 #include <string>
7 #include <cmath>
8 
9 #include <TStyle.h>
10 #include <TLatex.h>
11 #include <TMarker.h>
12 #include <TROOT.h>
13 
14 #define def_Preliminary false
15 #define def_Official false
16 
17 inline void SetAtlasStyle(){
18  TStyle *atlasStyle= new TStyle("ATLAS","Atlas style");
19 
20  // use plain black on white colors
21  Int_t icol=0;
22  atlasStyle->SetFrameBorderMode(icol);
23  atlasStyle->SetCanvasBorderMode(icol);
24  atlasStyle->SetFrameFillColor(icol);
25  atlasStyle->SetPadBorderMode(icol);
26  atlasStyle->SetPadColor(icol);
27  atlasStyle->SetCanvasColor(icol);
28  atlasStyle->SetStatColor(icol);
29  //atlasStyle->SetFillColor(icol);
30 
31  // set the paper & margin sizes
32  atlasStyle->SetPaperSize(20,26);
33  atlasStyle->SetPadTopMargin(0.05);
34  atlasStyle->SetPadRightMargin(0.05);
35  atlasStyle->SetPadBottomMargin(0.16);
36  atlasStyle->SetPadLeftMargin(0.12);
37 
38  // use large fonts
39  //Int_t font=72;
40  Int_t font=42;
41  Double_t tsize=0.05;
42  atlasStyle->SetTextFont(font);
43 
44 
45  atlasStyle->SetTextSize(tsize);
46  atlasStyle->SetLabelFont(font,"x");
47  atlasStyle->SetTitleFont(font,"x");
48  atlasStyle->SetLabelFont(font,"y");
49  atlasStyle->SetTitleFont(font,"y");
50  atlasStyle->SetLabelFont(font,"z");
51  atlasStyle->SetTitleFont(font,"z");
52 
53  atlasStyle->SetLabelSize(tsize,"x");
54  atlasStyle->SetTitleSize(tsize,"x");
55  atlasStyle->SetLabelSize(tsize,"y");
56  atlasStyle->SetTitleSize(tsize,"y");
57  atlasStyle->SetLabelSize(tsize,"z");
58  atlasStyle->SetTitleSize(tsize,"z");
59 
60 
61  //use bold lines and markers
62  atlasStyle->SetMarkerStyle(20);
63  atlasStyle->SetMarkerSize(1.2);
64  atlasStyle->SetHistLineWidth(2);
65  atlasStyle->SetLineStyleString(2,"[12 12]"); // postscript dashes
66 
67  //get rid of X error bars and y error bar caps
68  //atlasStyle->SetErrorX(0.001);
69 
70  //do not display any of the standard histogram decorations
71  atlasStyle->SetOptTitle(0);
72  //atlasStyle->SetOptStat(1111);
73  atlasStyle->SetOptStat(0);
74  //atlasStyle->SetOptFit(1111);
75  atlasStyle->SetOptFit(0);
76 
77  // put tick marks on top and RHS of plots
78  atlasStyle->SetPadTickX(1);
79  atlasStyle->SetPadTickY(1);
80 
81  gROOT->SetStyle("ATLAS");
82 
83 }
84 
85 inline void DrawATLASLabel(float x,float y, float textsize = 0.05,bool Preliminary = true){
86  TLatex l; //l.SetTextAlign(12);
87  l.SetTextSize(textsize);
88  l.SetNDC();
89  l.SetTextFont(72);
90  l.SetTextColor(1);
91 
92  double delx = 0.115*696*gPad->GetWh()/(472*gPad->GetWw());
93 
94  l.DrawLatex(x,y,"ATLAS");
95  if (Preliminary) {
96  TLatex p;
97  p.SetNDC();
98  p.SetTextFont(42);
99  p.SetTextColor(1);
100  p.DrawLatex(x+delx,y,"Preliminary");
101  // p.DrawLatex(x,y,"#sqrt{s}=900GeV");
102  }
103 }
104 
105 
106 
107 inline void DrawTitleLatex(const char* chartitle,
108  float x, float y,
109  int color = 1,
110  float textsize = 0.04){
111  std::string left = std::string(chartitle);
112  std::vector<std::string> cuts;
113  std::string::size_type found = 0;
114  while(1){ // loop over the title, will exit with break
115  left = left.substr(found);
116  found = left.find(" - ");
117  if(found == std::string::npos){
118  cuts.push_back(left);
119  break;
120  }
121  cuts.push_back(left.substr(0,found));
122  found += 3; // take into account the delimiter " - "
123  }
124  TLatex TitleLabel;
125  TitleLabel.SetNDC();
126  TitleLabel.SetTextSize(textsize);
127  TitleLabel.SetTextColor(color);
128  for(unsigned int i = 0 ; i < cuts.size(); i++)
129  TitleLabel.DrawLatex(x,y-i*(1.25)*textsize,(cuts[i]).c_str());
130 
131 }
132 
133 inline void DrawLegendLatex(const char* chartitle,
134  int markertype,
135  float x, float y,
136  int color = 1,
137  float textsize = 0.03){
138 
139  TMarker *markerdot = new TMarker(x - 0.4 * textsize, y + 0.2 * textsize, markertype);
140  markerdot->SetNDC();
141  markerdot->SetMarkerColor(color);
142  markerdot->SetMarkerSize(25 * textsize);
143  markerdot->Draw(); // cannot use DrawMarker because it does not SetNDC()
144  //delete markerdot;
145 
146  DrawTitleLatex(chartitle, x, y, color, textsize);
147 }
148 
149 
150 inline void GetCoreParameters(const TH1 *hist, double &mean, double &mean_error,
151  double &rms, double &rms_error, double &nentries){
152 
153  nentries = 0.;
154  mean = 0.;
155  mean_error = 0.;
156  rms = 0.;
157  rms_error = 0.;
158 
159  double axmin = hist->GetMean() - 3 * hist->GetRMS();
160  double axmax = hist->GetMean() + 3 * hist->GetRMS();
161  int nbins = hist->GetNbinsX();
162  int imean = 0;
163  hist->GetBinWithContent(hist->GetMean(), imean);
164  float binwidth = hist->GetBinWidth(imean);
165  if( fabs(axmax-axmin) < binwidth){
166  nentries = hist->GetEntries();
167  mean = hist->GetMean();
168  rms = binwidth/sqrt(12);
169  }else{
170  for (int i = 0 ; i < nbins; i++){
171  double value = hist->GetBinCenter(i+1);
172  double ientries = hist->GetBinContent(i+1);
173  if (value < axmin) continue;
174  if (value > axmax) break;
175  mean += value*ientries;
176  rms += value*value*ientries;
177  nentries += ientries;
178  }
179  if (nentries > 0) {
180  mean = mean/nentries;
181  rms = sqrt(rms/nentries-mean*mean);
182  }
183  }
184 
185  if (nentries > 0) {
186  mean_error = rms / sqrt(nentries);
187  if(nentries > 1) rms_error = rms / sqrt(2*(nentries-1));
188  }
189 
190  return;
191 }
DrawLegendLatex
void DrawLegendLatex(const char *chartitle, int markertype, float x, float y, int color=1, float textsize=0.03)
Definition: InnerDetector/InDetCalibAlgs/PixelCalibAlgs/PixelCalibAlgs/AtlasStyle.h:133
color
Definition: jFexInputByteStreamTool.cxx:25
mean
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
Definition: dependence.cxx:254
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
SetAtlasStyle
void SetAtlasStyle()
Definition: InnerDetector/InDetCalibAlgs/PixelCalibAlgs/PixelCalibAlgs/AtlasStyle.h:17
plotmaker.hist
hist
Definition: plotmaker.py:148
binwidth
bool binwidth
Definition: listroot.cxx:58
atlasStyleMacro.atlasStyle
atlasStyle
Definition: atlasStyleMacro.py:8
athena.value
value
Definition: athena.py:122
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
x
#define x
atlasStyleMacro.icol
int icol
Definition: atlasStyleMacro.py:13
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
PlotCalibFromCool.nentries
nentries
Definition: PlotCalibFromCool.py:798
lumiFormat.i
int i
Definition: lumiFormat.py:92
plotBeamSpotVert.cuts
string cuts
Definition: plotBeamSpotVert.py:93
DrawTitleLatex
void DrawTitleLatex(const char *chartitle, float x, float y, int color=1, float textsize=0.04)
Definition: InnerDetector/InDetCalibAlgs/PixelCalibAlgs/PixelCalibAlgs/AtlasStyle.h:107
GetCoreParameters
void GetCoreParameters(const TH1 *hist, double &mean, double &mean_error, double &rms, double &rms_error, double &nentries)
Definition: InnerDetector/InDetCalibAlgs/PixelCalibAlgs/PixelCalibAlgs/AtlasStyle.h:150
y
#define y
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
TH1
Definition: rootspy.cxx:268
beamspotnt.rms
rms
Definition: bin/beamspotnt.py:1266
plotBeamSpotMon.font
font
Definition: plotBeamSpotMon.py:80
atlasStyleMacro.tsize
float tsize
Definition: atlasStyleMacro.py:37
PlotCalibFromCool.delx
delx
Definition: PlotCalibFromCool.py:865
DrawATLASLabel
void DrawATLASLabel(float x, float y, float textsize=0.05, bool Preliminary=true)
Definition: InnerDetector/InDetCalibAlgs/PixelCalibAlgs/PixelCalibAlgs/AtlasStyle.h:85