CbmRoot
Loading...
Searching...
No Matches
PairAnalysisStyler.cxx
Go to the documentation of this file.
1/* Copyright (C) 2015-2020 Justus-Liebig-Universitaet Giessen, Giessen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Julian Book [committer] */
4
5/*
6
7 This class provides a common TStyle for all PAPa plots including
8 usefull functions to automatically set (predefined) styles:
9 SetStyle(), SetForceLineStyle(), SetPalette(), SetLegendAttributes()
10 place legends SetLegendAlign().
11
12 The PAPa style can be replaced by the method call SetStyle(TStyle *userStyle).
13
14*/
15// //
17
18#include "PairAnalysisStyler.h"
19
20#include <TAttFill.h>
21#include <TAttLine.h>
22#include <TAttMarker.h>
23#include <TCollection.h>
24#include <TColor.h>
25#include <TError.h>
26#include <TGaxis.h>
27#include <TGraph.h>
28#include <TH1.h>
29#include <THStack.h>
30#include <TLatex.h>
31#include <TLegend.h>
32#include <TLegendEntry.h>
33#include <TPad.h>
34#include <TROOT.h>
35#include <TStyle.h>
36
38
39//_____________________________________________________________________________
40void PairAnalysisStyler::SetStyle(TStyle* userStyle)
41{
42 //
43 // set and load user defined style
44 //
45 fUserDielStyle = userStyle;
46 LoadStyle();
47}
48
49//_____________________________________________________________________________
51{
52 //
53 // load style
54 //
55
56 // define nice colors
57 // new TColor(2001, (66./255.), (98./255.), (255. /255.) );
58 // new TColor(2002, (255./255.), (89./255.), (74. /255.));
59 // new TColor(2003, (51./255.), (204./255.), (51. /255.));
60 // new TColor(2004, (255./255.), (204./255.), (0. /255.));
61 // new TColor(2005, (0./255.), (204./255.), (255. /255.) );
62
63 // return;
64 // load style defined by the user
65 if (fUserDielStyle) {
66 fUserDielStyle->cd();
67 gROOT->ForceStyle();
68 }
69 else {
70
71 Int_t font = 42;
72 Int_t bgrdcolor = 0; // set to -1 for transparaent, will causes warnings
73
74 TStyle* defaultSty = new TStyle("default", "default");
75 defaultSty->SetPaperSize(TStyle::kA4);
76 defaultSty->SetTextFont(font);
77
78 // For the canvas:
79 defaultSty->SetCanvasBorderMode(0);
80 defaultSty->SetCanvasColor(bgrdcolor); //transparent
81 defaultSty->SetCanvasDefH(600); //Height of canvas
82 defaultSty->SetCanvasDefW(600); //Width of canvas
83 defaultSty->SetCanvasDefX(0); //POsition on screen
84 defaultSty->SetCanvasDefY(0);
85
86 // For the Pad:
87 defaultSty->SetPadBorderMode(0);
88 // defaultSty->SetPadBorderSize(Width_t size = 1);
89 defaultSty->SetPadColor(bgrdcolor); //transparent
90 defaultSty->SetPadGridX(false);
91 defaultSty->SetPadGridY(false);
92 defaultSty->SetGridColor(0);
93 defaultSty->SetGridStyle(3);
94 defaultSty->SetGridWidth(1);
95
96 // For the frame:
97 defaultSty->SetFrameBorderMode(0);
98 defaultSty->SetFrameBorderSize(1);
99 defaultSty->SetFrameFillColor(bgrdcolor); //transparent
100 defaultSty->SetFrameFillStyle(0);
101 defaultSty->SetFrameLineColor(1);
102 defaultSty->SetFrameLineStyle(1);
103 defaultSty->SetFrameLineWidth(1);
104
105 // Margins:
106 defaultSty->SetPadTopMargin(0.075);
107 defaultSty->SetPadBottomMargin(0.18);
108 defaultSty->SetPadLeftMargin(0.18); //0.13
109 defaultSty->SetPadRightMargin(0.075);
110
111 // For the histo:
112 defaultSty->SetHistFillColor(bgrdcolor); //transparent
113 // defaultSty->SetHistFillStyle(0);
114 defaultSty->SetHatchesSpacing(2.); // spacing between hatches, def.=1.
115 defaultSty->SetHatchesLineWidth(2); // hatches line width.
116 defaultSty->SetHistLineColor(1);
117 defaultSty->SetHistLineStyle(0);
118 defaultSty->SetHistLineWidth(2);
119 // defaultSty->SetLegoInnerR(Float_t rad = 0.5);
120 defaultSty->SetHistMinimumZero();
121 // defaultSty->SetEndErrorSize(2);
122 defaultSty->SetErrorX(0.0);
123 defaultSty->SetLineColor(1);
124 defaultSty->SetMarkerColor(1);
125 defaultSty->SetMarkerStyle(kFullCircle); // Kind of dot used for points
126 defaultSty->SetMarkerSize(1.5);
127
128
129 //For the fit/function:
130 defaultSty->SetOptFit(1);
131 defaultSty->SetFitFormat("5.4g");
132 defaultSty->SetFuncColor(2);
133 defaultSty->SetFuncStyle(1);
134 defaultSty->SetFuncWidth(1);
135
136 //For the date:
137 defaultSty->SetOptDate(22); // bottom right only date
138 // defaultSty->SetDateX(Float_t x = 0.01);
139 // defaultSty->SetDateY(Float_t y = 0.01);
140 defaultSty->GetAttDate()->SetTextColor(kGray);
141 defaultSty->GetAttDate()->SetTextFont(font);
142 defaultSty->GetAttDate()->SetTextSize(0.02);
143
144 // For the statistics box:
145 defaultSty->SetOptFile(0);
146 defaultSty->SetOptStat(0); // To display the mean and RMS: SetOptStat("mr");
147 // defaultSty->SetOptStat("n"); // only name
148 defaultSty->SetStatColor(kWhite);
149 defaultSty->SetStatFont(font);
150 defaultSty->SetStatFontSize(0.02);
151 defaultSty->SetStatTextColor(kGray);
152 defaultSty->SetStatFormat("6.4g");
153 defaultSty->SetStatBorderSize(1);
154 defaultSty->SetStatH(0.1);
155 defaultSty->SetStatW(0.5);
156 defaultSty->SetStatStyle(kFEmpty);
157 defaultSty->SetStatX(0.01);
158 defaultSty->SetStatY(0.01);
159
160 // For the Global title:
161 defaultSty->SetOptTitle(0);
162 defaultSty->SetTitleFont(font, "T");
163 defaultSty->SetTitleSize(0.05, "T");
164 defaultSty->SetTitleColor(bgrdcolor, "T");
165 defaultSty->SetTitleTextColor(1);
166 defaultSty->SetTitleFillColor(bgrdcolor); //transparent
167 defaultSty->SetTitleFontSize(0.06);
168 // defaultSty->SetTitleH(0); // Set the height of the title box
169 defaultSty->SetTitleW(0.5); // Set the width of the title box
170 defaultSty->SetTitleX(0.25); // Set the position of the title box
171 // defaultSty->SetTitleY(0.985); // Set the position of the title box
172 defaultSty->SetTitleStyle(kFEmpty);
173 // defaultSty->SetTitleBorderSize(2);
174 defaultSty->SetPaintTextFormat(".3f"); // format if you plot with TEXT option
175
176 // for Paves and boxes
177 // defaultSty->SetFillColor(bgrdcolor); // this makes palettes unicolored
178 defaultSty->SetFillStyle(kFEmpty);
179 defaultSty->SetLineColor(0);
180 defaultSty->SetLineWidth(0);
181 defaultSty->SetLineStyle(1);
182
183 // For the axis titles:
184 defaultSty->SetTitleColor(1, "XYZ");
185 defaultSty->SetTitleFont(font, "XYZ");
186 defaultSty->SetTitleSize(0.06, "XYZ"); //
187 // defaultSty->SetTitleXSize(Float_t size = 0.02); // Another way to set the size?
188 // defaultSty->SetTitleYSize(Float_t size = 0.02);
189 defaultSty->SetTitleXOffset(1.0); // defaultSty->SetTitleXOffset(1.08);
190 defaultSty->SetTitleYOffset(1.25); // defaultSty->SetTitleYOffset(1.5);
191 //defaultSty->SetTitleOffset(1.0, "XYZ"); // Another way to set the Offset
192
193 // For the axis labels:
194 defaultSty->SetLabelColor(1, "XYZ");
195 defaultSty->SetLabelFont(font, "XYZ");
196 defaultSty->SetLabelOffset(0.007, "XYZ");
197 defaultSty->SetLabelSize(0.04,
198 "XYZ"); // defaultSty->SetLabelSize(0.06, "XYZ");
199 defaultSty->SetLabelSize(0.03,
200 "Z"); // defaultSty->SetLabelSize(0.06, "XYZ");
201
202 // For the axis:
203 defaultSty->SetHistMinimumZero();
204 defaultSty->SetAxisColor(1, "XYZ");
205 // defaultSty->SetStripDecimals(kTRUE);
206 // defaultSty->SetTickLength(0.03, "XYZ");
207 defaultSty->SetNdivisions(810, "XYZ"); // defaultSty->SetNdivisions(505, "XYZ");
208 defaultSty->SetPadTickX(1); // To get tick marks on the opposite side of the frame
209 defaultSty->SetPadTickY(1);
210
211 // Change for log plots:
212 defaultSty->SetOptLogx(0);
213 defaultSty->SetOptLogy(0);
214 defaultSty->SetOptLogz(0);
215
216 // For the colored palette
217 // defaultSty->SetPalette(1,0);
218 const Int_t NRGBs = 5;
219 const Int_t NCont = 255;
220 // beautiful colors blue to red
221 Double_t red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.51};
222 Double_t green[NRGBs] = {0.00, 0.81, 1.00, 0.20, 0.00};
223 // Double_t green[NRGBs] = { 0.20, 0.81, 1.00, 0.20, 0.00};
224 //Double_t blue[NRGBs] = { 0.0, 0.00, 0.0, 0.00, 0.00};
225 Double_t blue[NRGBs] = {0.51, 1.00, 0.12, 0.00, 0.00};
226 Double_t stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
227 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
228 defaultSty->SetNumberContours(NCont);
229
230
231 // For the legends:
232 defaultSty->SetLegendFillColor(bgrdcolor);
233 //defaultSty->SetLegendFillColor(kWhite);
234 defaultSty->SetLegendFont(font);
235 // defaultSty->SetLegendTextSize(0.02); //for root>v6??
236
237 // Additions -- transparent style
238 defaultSty->SetFillStyle(4000);
239 defaultSty->SetStatStyle(0);
240 defaultSty->SetTitleStyle(0);
241 defaultSty->SetCanvasBorderSize(0);
242 defaultSty->SetFrameBorderSize(0);
243 defaultSty->SetLegendBorderSize(0);
244 defaultSty->SetStatBorderSize(0);
245 defaultSty->SetTitleBorderSize(0);
246
247 // set current style to default
248 // gROOT->SetStyle(sty);
249 defaultSty->cd();
250 gROOT->ForceStyle();
251 fUserDielStyle = defaultSty;
252
253 // axis
254 // TGaxis::SetMaxDigits(4);
255 TGaxis::SetMaxDigits(3);
256 TGaxis::SetExponentOffset(-1. * 0.06, 0., "y");
257 }
258}
259
260//_____________________________________________________________________________
261void PairAnalysisStyler::Style(TObject* obj, Int_t idx)
262{
263 //
264 // style object according to index
265 //
266 // Int_t id=0;
267 if (!obj) return;
268
269 // axis attributes
270 if (obj->InheritsFrom(TH1::Class()) && gPad) {
271 // reset axis names in order to allow repositioning of exponents
272 dynamic_cast<TH1*>(obj)->GetXaxis()->SetName("xaxis");
273 dynamic_cast<TH1*>(obj)->GetYaxis()->SetName("yaxis");
274 // logarithmic labels
275 if (gPad->GetLogx()) {
276 dynamic_cast<TH1*>(obj)->GetXaxis()->SetMoreLogLabels(kTRUE);
277 dynamic_cast<TH1*>(obj)->GetXaxis()->SetNoExponent(kTRUE);
278 }
279 if (gPad->GetLogy()) {
280 dynamic_cast<TH1*>(obj)->GetYaxis()->SetMoreLogLabels(kTRUE);
281 dynamic_cast<TH1*>(obj)->GetYaxis()->SetNoExponent(kTRUE);
282 }
283 if (gPad->GetLogz()) {
284 dynamic_cast<TH1*>(obj)->GetZaxis()->SetMoreLogLabels(kTRUE);
285 dynamic_cast<TH1*>(obj)->GetZaxis()->SetNoExponent(kTRUE);
286 }
287 }
288
289 // marker attributes
290 if (obj->InheritsFrom(TAttMarker::Class())) {
291 if (idx >= 100) { // predefined styles
292 dynamic_cast<TAttMarker*>(obj)->SetMarkerSize(fSze[idx - static_cast<Int_t>(Eidx::kRaw)]);
293 dynamic_cast<TAttMarker*>(obj)->SetMarkerStyle(fMrk[idx - static_cast<Int_t>(Eidx::kRaw)]);
294 dynamic_cast<TAttMarker*>(obj)->SetMarkerColor(fCol[idx - static_cast<Int_t>(Eidx::kRaw)]);
295 }
296 else {
297 dynamic_cast<TAttMarker*>(obj)->SetMarkerSize(1.5);
298 dynamic_cast<TAttMarker*>(obj)->SetMarkerStyle(Marker[idx % static_cast<Int_t>(Estyle::kNMaxMarker)]);
299 dynamic_cast<TAttMarker*>(obj)->SetMarkerColor(Color[idx % static_cast<Int_t>(Estyle::kNMaxColor)]);
300 if (idx >= static_cast<Int_t>(Estyle::kNMaxColor) && idx < static_cast<Int_t>(Estyle::kNMaxColor) * 2) {
301 idx = idx % static_cast<Int_t>(Estyle::kNMaxColor);
302 dynamic_cast<TAttMarker*>(obj)->SetMarkerColor(TColor::GetColorDark(Color[idx]));
303 }
304 else if (idx >= static_cast<Int_t>(Estyle::kNMaxColor) * 2) {
305 idx = idx % (2 * static_cast<Int_t>(Estyle::kNMaxColor));
306 dynamic_cast<TAttMarker*>(obj)->SetMarkerColor(TColor::GetColorBright(Color[idx]));
307 }
308 }
309 }
310
311 // line attributes
312 if (obj->InheritsFrom(TAttLine::Class())) {
313 // printf("index %d for %s \n",idx,obj->GetName());
314 if (idx >= 100) { // predefined styles
315 dynamic_cast<TAttLine*>(obj)->SetLineWidth(fWdt[idx - static_cast<Int_t>(Eidx::kRaw)]);
316 dynamic_cast<TAttLine*>(obj)->SetLineStyle(fLne[idx - static_cast<Int_t>(Eidx::kRaw)]);
317 dynamic_cast<TAttLine*>(obj)->SetLineColor(fCol[idx - static_cast<Int_t>(Eidx::kRaw)]);
318 }
319 else {
320 dynamic_cast<TAttLine*>(obj)->SetLineWidth(2);
321 dynamic_cast<TAttLine*>(obj)->SetLineStyle(Line[idx % static_cast<Int_t>(Estyle::kNMaxLine)]);
322 dynamic_cast<TAttLine*>(obj)->SetLineColor(Color[idx % static_cast<Int_t>(Estyle::kNMaxColor)]);
323 if (idx >= static_cast<Int_t>(Estyle::kNMaxColor) && idx < static_cast<Int_t>(Estyle::kNMaxColor) * 2) {
324 idx = idx % static_cast<Int_t>(Estyle::kNMaxColor);
325 dynamic_cast<TAttLine*>(obj)->SetLineColor(TColor::GetColorDark(Color[idx]));
326 }
327 else if (idx >= static_cast<Int_t>(Estyle::kNMaxColor) * 2) {
328 idx = idx % (2 * static_cast<Int_t>(Estyle::kNMaxColor));
329 dynamic_cast<TAttLine*>(obj)->SetLineColor(TColor::GetColorBright(Color[idx]));
330 }
331 }
332 }
333
334 // fill attributes, only used if fill style is set (default: not)
335 if (obj->InheritsFrom(TAttFill::Class())) {
336 // printf("fill style %d for index: %d \n",Fill[0],idx);
337 if (idx >= 100 && fFll[idx - static_cast<Int_t>(Eidx::kRaw)] >= 0) { // predefined styles
338 dynamic_cast<TAttFill*>(obj)->SetFillColor(fCol[idx - static_cast<Int_t>(Eidx::kRaw)]);
339 dynamic_cast<TAttFill*>(obj)->SetFillStyle(fFll[idx - static_cast<Int_t>(Eidx::kRaw)]);
340 }
341 else if (Fill[0] >= 0) {
342 dynamic_cast<TAttFill*>(obj)->SetFillColor(Color[idx % static_cast<Int_t>(Estyle::kNMaxColor)]);
343 if (idx >= static_cast<Int_t>(Estyle::kNMaxColor) && idx < static_cast<Int_t>(Estyle::kNMaxColor) * 2) {
344 idx = idx % static_cast<Int_t>(Estyle::kNMaxColor);
345 dynamic_cast<TAttFill*>(obj)->SetFillColor(TColor::GetColorDark(Color[idx]));
346 }
347 else if (idx >= static_cast<Int_t>(Estyle::kNMaxColor) * 2) {
348 idx = idx % (2 * static_cast<Int_t>(Estyle::kNMaxColor));
349 dynamic_cast<TAttFill*>(obj)->SetFillColor(TColor::GetColorBright(Color[idx]));
350 }
351 dynamic_cast<TAttFill*>(obj)->SetFillStyle(Fill[0]);
352 }
353 }
354}
355
356//_____________________________________________________________________________
358{
359 //
360 // force a certain line style
361 //
362 for (Int_t i = 0; i < static_cast<Int_t>(Estyle::kNMaxLine); i++) {
363 Line[i] = line;
364 }
365}
366
367//_____________________________________________________________________________
369{
370 //
371 // force a certain color
372 //
373 for (Int_t i = 0; i < static_cast<Int_t>(Estyle::kNMaxColor); i++) {
374 Color[i] = color;
375 }
376}
377
378//_____________________________________________________________________________
380{
381 //
382 // force a certain color
383 //
384 for (Int_t i = 0; i < (static_cast<Int_t>(Eidx::kNidx) - static_cast<Int_t>(Eidx::kRaw)); i++) {
385 fFll[i] = fill;
386 }
387 Fill[0] = fill;
388}
389
390//_____________________________________________________________________________
392{
393 //
394 // force a certain marker fill style
395 //
396 for (Int_t i = 0; i < static_cast<Int_t>(Estyle::kNMaxMarker); i++) {
397
398 switch (Marker[i]) {
399 case kOpenCircle:
400 if (fill == EfillMark::kFullMarker) Marker[i] = kFullCircle;
401 break;
402 case kOpenSquare:
403 if (fill == EfillMark::kFullMarker) Marker[i] = kFullSquare;
404 break;
405 case kOpenTriangleUp:
406 if (fill == EfillMark::kFullMarker) Marker[i] = kFullTriangleUp;
407 break;
408 case kOpenTriangleDown:
409 if (fill == EfillMark::kFullMarker) Marker[i] = kFullTriangleDown;
410 break;
411 case kOpenStar:
412 if (fill == EfillMark::kFullMarker) Marker[i] = kFullStar;
413 break;
414 case kOpenDiamond:
415 if (fill == EfillMark::kFullMarker) Marker[i] = kFullDiamond;
416 break;
417 case kOpenCross:
418 if (fill == EfillMark::kFullMarker) Marker[i] = kFullCross;
419 break;
420 case kFullCircle:
421 if (fill == EfillMark::kOpenMarker) Marker[i] = kOpenCircle;
422 break;
423 case kFullSquare:
424 if (fill == EfillMark::kOpenMarker) Marker[i] = kOpenSquare;
425 break;
426 case kFullTriangleUp:
427 if (fill == EfillMark::kOpenMarker) Marker[i] = kOpenTriangleUp;
428 break;
429 case kFullTriangleDown:
430 if (fill == EfillMark::kOpenMarker) Marker[i] = kOpenTriangleDown;
431 break;
432 case kFullStar:
433 if (fill == EfillMark::kOpenMarker) Marker[i] = kOpenStar;
434 break;
435 case kFullDiamond:
436 if (fill == EfillMark::kOpenMarker) Marker[i] = kOpenDiamond;
437 break;
438 case kFullCross:
439 if (fill == EfillMark::kOpenMarker) Marker[i] = kOpenCross;
440 break;
441 }
442 }
443}
444
445
446//_____________________________________________________________________________
447void PairAnalysisStyler::SetStyle(Eidx idx, Int_t col, Int_t marker, Double_t size, Int_t line, Double_t width,
448 Int_t fill)
449{
450 //
451 // change predefined style "idx" according to arguments
452 //
453 fCol[static_cast<Int_t>(idx) - static_cast<Int_t>(Eidx::kRaw)] = col;
454 fMrk[static_cast<Int_t>(idx) - static_cast<Int_t>(Eidx::kRaw)] = marker;
455 fSze[static_cast<Int_t>(idx) - static_cast<Int_t>(Eidx::kRaw)] = size;
456 fLne[static_cast<Int_t>(idx) - static_cast<Int_t>(Eidx::kRaw)] = line;
457 fWdt[static_cast<Int_t>(idx) - static_cast<Int_t>(Eidx::kRaw)] = width;
458 fFll[static_cast<Int_t>(idx) - static_cast<Int_t>(Eidx::kRaw)] = fill;
459}
460
461
462//_____________________________________________________________________________
463void PairAnalysisStyler::SetLegendAlign(UInt_t align) { fLegAlign = align; }
464
465//_____________________________________________________________________________
466void PairAnalysisStyler::SetLegendAttributes(TLegend* leg, Bool_t fill)
467{
468 //
469 // set/update legend cooordinates according to alignement (stored in uniqueID)
470 // and "fill" a legend with white background color
471 //
472
473 // if(leg->GetUniqueID()==0) leg->SetUniqueID(fLegAlign);
474 // UInt_t fLegAlign = leg->GetUniqueID();
475
476 // printf("CURRENT leg coordinates: x1 %f x2 %f \t",leg->GetX1(),leg->GetX2());
477 // printf(" y1 %f y2 %f \n",leg->GetY1(),leg->GetY2());
478
479 Double_t maxhgth = 0.0;
480 Double_t symblwdth = 0.065; //ndc
481 Double_t txtsze = 0.04; //0.025; //gStyle->GetLegendTextSize());
482 // Double_t charwdth = 0.01;//0.01; // own defintion
483 Double_t entrysep = 1.25; //1.25; //entry seperation
484
485 // calculate get legend width
486 Double_t maxwdth = 0.0;
487 TList* llist = leg->GetListOfPrimitives();
488 Int_t nent = llist->GetEntries();
489
490 if (nent > 5) txtsze = 0.03; //0.025
491 leg->SetTextSize(txtsze); // this should switch off the autosize
492 // leg->SetTextAlign(11);
493
494
495 for (Int_t il = 0; il < nent; il++) {
496 TLegendEntry* lent = static_cast<TLegendEntry*>(llist->At(il));
497 TString lst(lent->GetLabel());
498 // lent->SetTextSize(20);
499 // /* lst.ReplaceAll("#it","");
500 lst.ReplaceAll("{", "");
501 lst.ReplaceAll("}", "");
502 lst.ReplaceAll("^", "");
503 lst.ReplaceAll("_", "");
504 lst.ReplaceAll("#LT", "#");
505 lst.ReplaceAll("#GT", "#");
506 lst.ReplaceAll("#phi", "#");
507 lst.ReplaceAll("#rho", "#");
508 lst.ReplaceAll("#omega", "#");
509 lst.ReplaceAll("#eta", "#");
510 lst.ReplaceAll("#epsilon", "#");
511 lst.ReplaceAll("#psi", "#");
512 lst.ReplaceAll("#pi", "#");
513 lst.ReplaceAll("#alpha", "#");
514 lst.ReplaceAll("#gamma", "#");
515 lst.ReplaceAll("#rightarrow", "#");
516 // */
517 // lst.ReplaceAll(" ","");
518 TLatex entrytex(0., 0., lst.Data());
519 entrytex.SetNDC(kTRUE);
520 entrytex.SetTextSize(txtsze);
521 entrytex.SetTextFont(gStyle->GetLegendFont());
522 //entrytex.SetTextFont(lent->GetTextFont());
523 Double_t wdth = entrytex.GetXsize();
524 Double_t hgth = entrytex.GetYsize();
525 //wdth = lst.Length()*charwdth;
526 if (maxwdth < wdth) maxwdth = wdth;
527 // Printf("wdth %f and height %f for '%s' \t max width: %f by textsize %f for nchars %d --> own wdth %f \n",
528 // wdth,entrytex.GetYsize(),entrytex.GetTitle(),maxwdth, entrytex.GetTextSize(),lst.Length(),lst.Length()*charwdth);
529 maxhgth += hgth;
530 }
531
532 maxhgth = nent * txtsze * entrysep;
533 // Bool_t addhdr = !(((TString)leg->GetHeader()).IsNull());
534 // maxhgth = (maxhgth/nent)*entrysep*(nent+1); // add legend header height
535
536 // set legend coordinates
537 if (fLegAlign == 12 || fLegAlign == 22) { //top
538 leg->SetY2(1. - gPad->GetTopMargin() - gStyle->GetTickLength("X"));
539 leg->SetY1(leg->GetY2() - maxhgth);
540 }
541 else { // bottom
542 leg->SetY1(0. + gPad->GetBottomMargin() + gStyle->GetTickLength("X"));
543 leg->SetY2(leg->GetY1() + maxhgth);
544 }
545 if (fLegAlign == 22 || fLegAlign == 21) { //right
546 leg->SetX2(1. - gPad->GetRightMargin() - gStyle->GetTickLength("Y") * 1.0); //x2.0 ticklength
547 leg->SetX1(leg->GetX2() - maxwdth * 1.0 - symblwdth);
548 }
549 else if (fLegAlign == 12 || fLegAlign == 11) { //left
550 leg->SetX1(0. + gPad->GetLeftMargin() + gStyle->GetTickLength("Y"));
551 leg->SetX2(leg->GetX1() + maxwdth * 1.0 + symblwdth);
552 }
553
554 // fix margin such that lines allways have the same length
555 leg->SetMargin(symblwdth / (leg->GetX2() - leg->GetX1()));
556 leg->SetEntrySeparation(entrysep - 1.);
557
558 // styling
559 if (fill) leg->SetFillStyle(1001); // solid
560 else
561 leg->SetFillStyle(kFEmpty); // empty
562 // leg->SetFillColorAlpha(gStyle->GetLegendFillColor(), 0.8);
563 // leg->SetFillColorAlpha(gStyle->GetLegendFillColor(), 0.8);
564
565 // printf("FINAL leg coordinates: x1 %f x2 %f \t",leg->GetX1(),leg->GetX2());
566 // printf(" y1 %f y2 %f \n",leg->GetY1(),leg->GetY2());
567}
568
569void PairAnalysisStyler::SetPalette(Epalette colors, Bool_t reverse)
570{
571 //
572 // use own definition of color palettes for zaxis
573 //
574
575 const Int_t NRGBs = 5;
576 const Int_t NCont = 255;
577 Double_t stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
578
579 switch (colors) {
580 case Epalette::kDefault: {
581 Double_t red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.51};
582 Double_t green[NRGBs] = {0.00, 0.81, 1.00, 0.20, 0.00};
583 Double_t blue[NRGBs] = {0.51, 1.00, 0.12, 0.00, 0.00};
584 if (reverse) TColor::CreateGradientColorTable(NRGBs, stops, blue, green, red, NCont);
585 else
586 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
587 break;
588 }
589 case Epalette::kGoodBad: {
590 Double_t red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.36};
591 Double_t green[NRGBs] = {0.20, 0.81, 1.00, 0.20, 0.00};
592 Double_t blue[NRGBs] = {0.00, 0.00, 0.00, 0.00, 0.00};
593 if (reverse) TColor::CreateGradientColorTable(NRGBs, stops, green, red, blue, NCont);
594 else
595 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
596 break;
597 }
598 }
599
600
601 gStyle->SetNumberContours(NCont);
602}
603
604//_____________________________________________________________________________
606{
607 //
608 // get the first histogram drawn on the pad
609 // this can be modified in the usual way
610 //
611 if (!gPad) {
612 Error("GetFirstHistogram", "No pad found, return NULL pointer!!");
613 return 0x0;
614 }
615
616 TIter nextObj(gPad->GetListOfPrimitives());
617 TObject* obj;
618 while ((obj = nextObj())) {
619 if (obj->InheritsFrom(TH1::Class())) { return (static_cast<TH1*>(obj)); }
620 if (obj->InheritsFrom(TGraph::Class())) { return (static_cast<TH1*>(static_cast<TGraph*>(obj)->GetHistogram())); }
621 if (obj->InheritsFrom(THStack::Class())) { return (static_cast<TH1*>(static_cast<THStack*>(obj)->GetHistogram())); }
622 }
623 return 0x0;
624}
625
626//_____________________________________________________________________________
628{
629 //
630 // TODO
631 //
632 //
633 if (!gPad) {
634 Error("GetLegendEntry", "No pad found, return NULL pointer!!");
635 return 0x0;
636 }
637
638 TList* prim = gPad->GetListOfPrimitives();
639 if (!prim) return NULL;
640 TLegend* leg = dynamic_cast<TLegend*>(prim->FindObject("TPave"));
641 if (!leg) return NULL;
642 TList* entries = leg->GetListOfPrimitives();
643 if (!entries) return NULL;
644 return (dynamic_cast<TLegendEntry*>(entries->At(idx)));
645}
static constexpr size_t size()
Definition KfSimdPseudo.h:2
TLegendEntry * GetLegendEntry(Int_t idx)
void SetForceMarkerFillStyle(EfillMark fill)
void SetForceLineStyle(Int_t line=kSolid)
void SetStyle(TStyle *userStyle)
void SetLegendAlign(UInt_t align)
void SetPalette(Epalette colors=Epalette::kDefault, Bool_t reverse=kFALSE)
void SetForceColor(Int_t color=kBlack)
void Style(TObject *obj, Int_t idx=0)
void SetLegendAttributes(TLegend *leg, Bool_t fill=kFALSE)
void SetForceFillStyle(Int_t fill=kFSolid)