Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
noi_fmt.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file noi_fmt.h
1 // David Stewart, Dec 1 2022
2 // A way to format plots
3 
4 #ifndef noi_fmt__h
5 #define noi_fmt__h
6 #include "noiDict.h"
7 
9  return {{
10  "MarkerStyle", kFullCircle,
11  "MarkerColor", kBlack,
12  "MarkerAlpha", 1.,
13  "MarkerSize", 1.,
14 
15  "LineWidth", 1 ,
16  "LineStyle", 1 ,
17 
18  /* "FillStyle", 4000, */
19  /* {"LineColor", kBlack }, */
20  /* {"LineAlpha", 1. }, */
21 
22  "xAxisTitleFont", 43,
23  "xAxisTitleSize", 22,
24  "xAxisTitleOffset", 1.6 ,
25 
26  "xAxisLabelFont", 43,
27  "xAxisLabelSize", 18,
28  "xAxisLabelOffset", 0.02,
29 
30  "yAxisTitleFont", 43,
31  "yAxisTitleSize", 22,
32  "yAxisTitleOffset", 1.85,
33 
34  "yAxisLabelFont", 43,
35  "yAxisLabelSize", 18,
36  "yAxisLabelOffset", 0.02,
37 
38  "zAxisTitleFont", 43,
39  "zAxisTitleSize", 22,
40  "zAxisTitleOffset", 2.4 ,
41 
42  "zAxisLabelFont", 43,
43  "zAxisLabelSize", 18,
44  "zAxisLabelOffset", 0.02 ,
45 
46  "SetStats", 0
47  }};
48 };
49 
50 TH1* noi_fmt (TH1* hg, noiDict _override={{}}, noiDict dict=_tu_fmt__hg_dict()) {
51  // if don't want defaults, add {} to override value
52  dict += _override;
53 
54  /* if (dict["noTitle"]) hg->SetTitle(""); */
55  if (dict["Name"]) hg->SetName(dict("Name"));
56 
57  if (dict["SetStats"]) hg->SetStats((int)dict("SetStats"));
58 
59  if (dict["no_errors"]) for (int i=1; i<=hg->GetNbinsX(); ++i) hg->SetBinError(i,0.);
60 
61 
62  if (dict["MarkerStyle"]) hg->SetMarkerStyle(dict("MarkerStyle"));
63 
64  if (dict["MarkerColor"]) hg->SetMarkerColor(dict("MarkerColor"));
65  if (dict["MarkerColorAlpha"]) hg->SetMarkerColorAlpha(dict("MarkerColorAlpha",1),dict("MarkerColorAlpha",2));
66 
67 
68  if (dict["MarkerSize"]) hg->SetMarkerSize(dict("MarkerSize"));
69 
70  if (dict["LineWidth"]) hg->SetLineWidth(dict("LineWidth"));
71  if (dict["LineStyle"]) hg->SetLineStyle(dict("LineStyle"));
72 
73  if (dict["LineColor"]) hg->SetLineColor(dict("LineColor"));
74  if (dict["LineColorAlpha"]) hg->SetLineColorAlpha(dict("LineColorAlpha",1),dict("LineColorAlpha",2));
75 
76  if (!dict["LineColor"] && !dict["LineColorAlpha"] && (dict["MarkerColor"] || dict["MarkerColorAlpha"])) {
77  if (dict["MarkerColor"]) hg->SetLineColor(dict("MarkerColor"));
78  if (dict["MarkerColorAlpha"]) hg->SetLineColorAlpha(dict("MarkerColorAlpha",1),dict("MarkerColorAlpha",2));
79  }
80  /* else if (dict["MarkerColor"]) */
81  /* hg->SetLineColorAlpha(dict("MarkerColor"), dict("LineAlpha",dict("MarkerAlpha",1.))); */
82  if (dict["FillColor"]) hg->SetFillColor(dict("FillColor"));
83  if (dict["FillColorAlpha"]) hg->SetFillColorAlpha(dict("FillColorAlpha",1),dict("FillColorAlpha",2));
84 
85  if (dict["FillStyle"]) hg->SetFillStyle(dict("FillStyle"));
86 
87  // Set titles
88  if (dict["Title"]) hg->SetTitle(dict("Title"));
89  if (dict["xAxisTitle"]) hg->GetXaxis()->SetTitle(dict("xAxisTitle"));
90  if (dict["yAxisTitle"]) hg->GetYaxis()->SetTitle(dict("yAxisTitle"));
91 
92  // Set axes styles
93 
94  if (dict["TitleSize"]) hg->SetTitleSize(dict("TitleSize"));
95  if (dict["TitleFont"]) hg->SetTitleFont(dict("TitleFont"));
96  // x Axis
97  if (dict["xAxisTitleFont"])
98  hg->GetXaxis()->SetTitleFont(dict("xAxisTitleFont"));
99  if (dict["xAxisTitleSize"])
100  hg->GetXaxis()->SetTitleSize(dict("xAxisTitleSize"));
101  /* cout << " beta " << endl; */
102  /* if (dict["xAxisTitleOffset"]) cout << " Setting xaxistitleoffset " << dict("xAxisTitleOffset") << endl; */
103  if (dict["xAxisTitleOffset"])
104  hg->GetXaxis()->SetTitleOffset(dict("xAxisTitleOffset"));
105  if (dict["xAxisLabelFont"])
106  hg->GetXaxis()->SetLabelFont(dict("xAxisLabelFont"));
107  if (dict["xAxisLabelSize"])
108  hg->GetXaxis()->SetLabelSize(dict("xAxisLabelSize"));
109  if (dict["xAxisLabelOffset"])
110  hg->GetXaxis()->SetLabelOffset(dict("xAxisLabelOffset"));
111 
112  // y Axis
113  if (dict["yAxisTitleFont"])
114  hg->GetYaxis()->SetTitleFont(dict("yAxisTitleFont"));
115  if (dict["yAxisTitleSize"])
116  hg->GetYaxis()->SetTitleSize(dict("yAxisTitleSize"));
117  if (dict["yAxisTitleOffset"])
118  hg->GetYaxis()->SetTitleOffset(dict("yAxisTitleOffset"));
119  if (dict["yAxisLabelFont"])
120  hg->GetYaxis()->SetLabelFont(dict("yAxisLabelFont"));
121  if (dict["yAxisLabelSize"])
122  hg->GetYaxis()->SetLabelSize(dict("yAxisLabelSize"));
123  if (dict["yAxisLabelOffset"])
124  hg->GetYaxis()->SetLabelOffset(dict("yAxisLabelOffset"));
125 
126 
127  // z Axis
128  if (dict["zAxisTitleFont"])
129  hg->GetZaxis()->SetTitleFont(dict("zAxisTitleFont"));
130  if (dict["zAxisTitleSize"])
131  hg->GetZaxis()->SetTitleSize(dict("zAxisTitleSize"));
132  if (dict["zAxisTitleOffset"])
133  hg->GetZaxis()->SetTitleOffset(dict("zAxisTitleOffset"));
134  if (dict["zAxisLabelFont"])
135  hg->GetZaxis()->SetLabelFont(dict("zAxisLabelFont"));
136  if (dict["zAxisLabelSize"])
137  hg->GetZaxis()->SetLabelSize(dict("zAxisLabelSize"));
138  if (dict["zAxisLabelOffset"])
139  hg->GetZaxis()->SetLabelOffset(dict("zAxisLabelOffset"));
140 
141  if (dict["xAxisRange"]) hg->GetXaxis()->SetRangeUser(dict("xAxisRange",1),dict("xAxisRange",2));
142  // Set Axis ranges with {x||y||z}AxisRange{Lo||Hi}
143  if (dict["xAxisRangeLo"] || dict["xAxisRangeHi"]) {
144  if (!dict["xAxisRangeLo"] || !dict["xAxisRangeHi"]) {
145  cout << " Warning in noi_fmt: has xAxisRange{lo||hi} but not both. Needs both."<<endl;
146  cout << " -> Not setting xAxisRange." << endl;
147  } else {
148  hg->GetXaxis()->SetRangeUser(dict("xAxisRangeLo"), dict("xAxisRangeHi"));
149  }
150  }
151 
152  if (dict["yAxisRange"]) hg->GetYaxis()->SetRangeUser(dict("yAxisRange",1),dict("yAxisRange",2));
153  if (dict["yAxisRangeLo"] || dict["yAxisRangeHi"]) {
154  if (!dict["yAxisRangeLo"] || !dict["yAxisRangeHi"]) {
155  cout << " Warning in noi_fmt: has yAxisRange{Lo||Hi} but not both. Needs both."<<endl;
156  cout << " -> Not setting yAxisRange." << endl;
157  } else {
158  hg->GetYaxis()->SetRangeUser(dict("yAxisRangeLo"), dict("yAxisRangeHi"));
159  }
160  }
161  if (dict["zAxisRangeLo"] || dict["zAxisRangeHi"]) {
162  if (!dict["zAxisRangeLo"] || !dict["zAxisRangeHi"]) {
163  cout << " Warning in noi_fmt: has zAxisRange{lo||hi} but not both. Needs both."<<endl;
164  cout << " -> Not setting zAxisRange." << endl;
165  } else {
166  hg->GetZaxis()->SetRangeUser(dict("zAxisRangeLo"), dict("zAxisRangeHi"));
167  }
168  }
169  // Set Ndivisions
170  if (dict["xAxisNdivisions"]) hg->GetXaxis()->SetNdivisions(dict("xAxisNdivisions"));
171  if (dict["yAxisNdivisions"]) hg->GetYaxis()->SetNdivisions(dict("yAxisNdivisions"));
172  if (dict["zAxisNdivisions"]) hg->GetZaxis()->SetNdivisions(dict("zAxisNdivisions"));
173  return hg;
174 };
175 
176 TLine* noi_fmt(TLine* line, noiDict options={{}}, noiDict dict={{
177  "LineColor",kBlack, "LineColorAlpha",kBlack, 1., "LineStyle",1,
178  "LineWidth",1 }})
179 {
180  dict += options;
181  line->SetLineColorAlpha(dict("LineColorAlpha",1),dict("LineColorAlpha",2));
182  line->SetLineStyle(dict("LineStyle"));
183  line->SetLineWidth(dict("LineWidth"));
184  return line;
185 }
186 
187 TLegend* noi_fmt (TLegend* leg, noiDict _override={{}},
188  // default values:
189  noiDict dict={{ "LineColor", kWhite, "LineColorAlpha",0., "FillColorAlpha",kWhite, 0. }}
190 ) {
191  dict += _override;
192  if (dict["LineColor"])
193  leg->SetLineColorAlpha(dict("LineColor"),dict("LineColorAlpha",0.));
194  if (dict["FillColor"])
195  leg->SetLineColorAlpha(dict("FillColor"),dict("FillColorAlpha",0.));
196  if (dict["FillStyle"])
197  leg->SetFillStyle(dict("FillStyle"));
198  if (dict["TextSize"]) leg->SetTextSize(dict("TextSize"));
199  return leg;
200 };
201 
202 TGraph* noi_fmt (TGraph* hg, noiDict _override={{}}, noiDict dict=_tu_fmt__hg_dict()) {
203  // if don't want defaults, add {} to override value
204  dict += _override;
205 
206  if (dict["MarkerStyle"]) hg->SetMarkerStyle(dict("MarkerStyle"));
207  if (dict["MarkerColor"]) hg->SetMarkerColor(dict("MarkerColor"));
208  if (dict["MarkerColorAlpha"]) hg->SetMarkerColorAlpha(dict("MarkerColorAlpha",1),dict("MarkerColorAlpha",2));
209 
210  if (dict["MarkerSize"]) hg->SetMarkerSize(dict("MarkerSize"));
211  if (dict["LineWidth"]) hg->SetLineWidth(dict("LineWidth"));
212  if (dict["LineStyle"]) hg->SetLineStyle(dict("LineStyle"));
213 
214  if (dict["LineColor"]) hg->SetLineColor(dict("LineColor"));
215  if (dict["LineColorAlpha"]) hg->SetLineColorAlpha(dict("LineColorAlpha",1),dict("LineColorAlpha",2));
216 
217  if (!dict["LineColor"] && !dict["LineColorAlpha"] && (dict["MarkerColor"] || dict["MarkerColorAlpha"])) {
218  if (dict["MarkerColor"]) hg->SetLineColor(dict("MarkerColor"));
219  if (dict["MarkerColorAlpha"]) hg->SetLineColorAlpha(dict("MarkerColorAlpha",1),dict("MarkerColorAlpha",2));
220  }
221  /* else if (dict["MarkerColor"]) */
222  /* hg->SetLineColorAlpha(dict("MarkerColor"), dict("LineAlpha",dict("MarkerAlpha",1.))); */
223  if (dict["FillColor"]) hg->SetFillColor(dict("FillColor"));
224  if (dict["FillColorAlpha"]) hg->SetFillColorAlpha(dict("FillColorAlpha",1),dict("FillColorAlpha",2));
225 
226  if (dict["FillStyle"]) hg->SetFillStyle(dict("FillStyle"));
227 
228  // Set titles
229  if (dict["Title"]) hg->SetTitle(dict("Title"));
230  if (dict["xAxisTitle"]) hg->GetXaxis()->SetTitle(dict("xAxisTitle"));
231  if (dict["yAxisTitle"]) hg->GetYaxis()->SetTitle(dict("yAxisTitle"));
232 
233  // Set axes styles
234 
235  // x Axis
236  if (dict["xAxisTitleFont"])
237  hg->GetXaxis()->SetTitleFont(dict("xAxisTitleFont"));
238  if (dict["xAxisTitleSize"])
239  hg->GetXaxis()->SetTitleSize(dict("xAxisTitleSize"));
240  /* cout << " beta " << endl; */
241  /* if (dict["xAxisTitleOffset"]) cout << " Setting xaxistitleoffset " << dict("xAxisTitleOffset") << endl; */
242  if (dict["xAxisTitleOffset"])
243  hg->GetXaxis()->SetTitleOffset(dict("xAxisTitleOffset"));
244  if (dict["xAxisLabelFont"])
245  hg->GetXaxis()->SetLabelFont(dict("xAxisLabelFont"));
246  if (dict["xAxisLabelSize"])
247  hg->GetXaxis()->SetLabelSize(dict("xAxisLabelSize"));
248  if (dict["xAxisLabelOffset"])
249  hg->GetXaxis()->SetLabelOffset(dict("xAxisLabelOffset"));
250 
251  // y Axis
252  if (dict["yAxisTitleFont"])
253  hg->GetYaxis()->SetTitleFont(dict("yAxisTitleFont"));
254  if (dict["yAxisTitleSize"])
255  hg->GetYaxis()->SetTitleSize(dict("yAxisTitleSize"));
256  if (dict["yAxisTitleOffset"])
257  hg->GetYaxis()->SetTitleOffset(dict("yAxisTitleOffset"));
258  if (dict["yAxisLabelFont"])
259  hg->GetYaxis()->SetLabelFont(dict("yAxisLabelFont"));
260  if (dict["yAxisLabelSize"])
261  hg->GetYaxis()->SetLabelSize(dict("yAxisLabelSize"));
262  if (dict["yAxisLabelOffset"])
263  hg->GetYaxis()->SetLabelOffset(dict("yAxisLabelOffset"));
264 
265  if (dict["xAxisRange"]) hg->GetXaxis()->SetRangeUser(dict("xAxisRange",1),dict("xAxisRange",2));
266  // Set Axis ranges with {x||y||z}AxisRange{Lo||Hi}
267  if (dict["xAxisRangeLo"] || dict["xAxisRangeHi"]) {
268  if (!dict["xAxisRangeLo"] || !dict["xAxisRangeHi"]) {
269  cout << " Warning in noi_fmt: has xAxisRange{lo||hi} but not both. Needs both."<<endl;
270  cout << " -> Not setting xAxisRange." << endl;
271  } else {
272  hg->GetXaxis()->SetRangeUser(dict("xAxisRangeLo"), dict("xAxisRangeHi"));
273  }
274  }
275 
276  if (dict["yAxisRange"]) hg->GetYaxis()->SetRangeUser(dict("yAxisRange",1),dict("yAxisRange",2));
277  if (dict["yAxisRangeLo"] || dict["yAxisRangeHi"]) {
278  if (!dict["yAxisRangeLo"] || !dict["yAxisRangeHi"]) {
279  cout << " Warning in noi_fmt: has yAxisRange{Lo||Hi} but not both. Needs both."<<endl;
280  cout << " -> Not setting yAxisRange." << endl;
281  } else {
282  hg->GetYaxis()->SetRangeUser(dict("yAxisRangeLo"), dict("yAxisRangeHi"));
283  }
284  }
285  // Set Ndivisions
286  if (dict["xAxisNdivisions"]) hg->GetXaxis()->SetNdivisions(dict("xAxisNdivisions"));
287  if (dict["yAxisNdivisions"]) hg->GetYaxis()->SetNdivisions(dict("yAxisNdivisions"));
288  return hg;
289 };
290 
291 #endif