]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/Tools/AliFigure.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWG / Tools / AliFigure.cxx
CommitLineData
5e2810e1 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16//
17// Canvas for ALICE figures
18//
19// This class inherits from TCanvas and can be used instead of it. It
20// places the ALICE logo, and other things according to the figure status.
21//
22// The logos are expected as:
23// alice-logo-work_in_progress.eps
24// alice-logo-performance.eps
25// alice-logo-preliminary.eps
26// alice-logo-final.eps
27//
28// Author: Jochen Klein <jochen.klein@cern.ch>
29//
30
31#include "TCanvas.h"
32#include "TList.h"
33#include "TDatime.h"
34
35#include "TStyle.h"
36#include "TColor.h"
37#include "TText.h"
38#include "TASImage.h"
39#include "TLatex.h"
40#include "TLegend.h"
41#include "TGraphErrors.h"
42
43#include "AliFigure.h"
44
45TStyle *AliFigure::fgStyle;
46
47AliFigure::AliFigure(const char* name, const char* title, Int_t ww, Int_t wh) :
48 TCanvas(name, title, ww, wh),
3661cb6f 49 fDisabled(kFALSE),
5e2810e1 50 isMC(kFALSE),
51 fStatus(kWorkInProgress),
52 fDateFormat("%d/%m/%Y"),
3661cb6f 53 fTextSize(20),
5e2810e1 54 fTextColor(kBlack),
55 fLogoFilename(),
56 fLogoPosX(0.2),
57 fLogoPosY(0.5),
58 fLogoHeight(100),
59 fLogoPad(0x0),
60 fDate(0x0),
61 fStatusPad(0x0),
62 fCollSystem(0x0),
63 fDataSample(0x0),
64 fTag(0x0),
65 fLogo(0x0)
66{
67 // default ctor
68
69 fStatusString[kWorkInProgress] = "work in progress";
3661cb6f 70 fStatusString[kThisWork] = "- this work -";
5e2810e1 71 fStatusString[kPerformance] = "Performance";
72 fStatusString[kPreliminary] = "Preliminary";
73 fStatusString[kFinal] = "";
74
75 fLogoFilename[kWorkInProgress] = "$ALICE_ROOT/PWG/Tools/fig/2011-Nov-24-ALICE_logo_WithoutStrapline.eps";
3661cb6f 76 fLogoFilename[kThisWork] = "";
77 fLogoFilename[kPerformance] = "$ALICE_ROOT/PWG/Tools/fig/2011-Nov-24-ALICE_logo_WithoutStrapline.eps";
5e2810e1 78 // fLogoFilename[kPerformance] = "$ALICE_ROOT/PWG/Tools/fig/2011-Nov-24-ALICE_PERFORMANCE_logo_BLACK_small_usage_design.eps";
79 fLogoFilename[kPreliminary] = "$ALICE_ROOT/PWG/Tools/fig/2011-Nov-24-ALICE_PRELIMINARY_logo_BLACK_small_usage_design.eps";
80 fLogoFilename[kFinal] = "";
81
82 this->SetLeftMargin(0.15);
83 this->SetRightMargin(0.04);
84 this->SetRightMargin(0.04);
85 this->SetBottomMargin(0.15);
86
87 TDatime now;
88 char date[30];
89 time_t t = (time_t) now.Convert();
90 struct tm* loctis = localtime(&t);
91 strftime(date, 30, fDateFormat.Data(), loctis);
92
dfbdeb82 93 fCollSystem = new TLatex(0.96, 0.95, "pp #sqrt{s} = 7 TeV");
5e2810e1 94 fCollSystem->SetNDC();
95 fCollSystem->SetTextSize(fTextSize);
96 fCollSystem->SetTextFont(43);
97 fCollSystem->SetTextAlign(33);
98 fCollSystem->SetTextColor(fTextColor);
99
100 fDataSample = new TLatex(0.15, 0.05, "Run ######");
101 fDataSample->SetNDC();
102 fDataSample->SetTextSize(fTextSize);
103 fDataSample->SetTextFont(43);
104 fDataSample->SetTextAlign(11);
105 fDataSample->SetTextColor(fTextColor);
106
107 fDate = new TText(0.5, 0., date);
108 fDate->SetNDC();
109 fDate->SetTextSize(fTextSize);
110 fDate->SetTextFont(43);
111 fDate->SetTextAlign(22);
112 fDate->SetTextColor(fTextColor);
113
114 fStatusPad = new TText(0.5, 0.15, fStatusString[fStatus]);
115 fStatusPad->SetNDC();
116 fStatusPad->SetTextSize(fTextSize);
117 fStatusPad->SetTextFont(43);
118 fStatusPad->SetTextAlign(22);
119 fStatusPad->SetTextColor(fTextColor);
120
121 fTag = new TText(0.5, 0., "");
122 fTag->SetNDC();
123 fTag->SetTextSize(fTextSize);
124 fTag->SetTextFont(43);
125 fTag->SetTextAlign(22);
126 fTag->SetTextColor(fTextColor);
127
128// fLogoPad->ResetBit(kCanDelete);
129// fCollSystem->ResetBit(kCanDelete);
130// fStatusPad->ResetBit(kCanDelete);
131// fDate->ResetBit(kCanDelete);
132
133// GetListOfPrimitives()->SetOwner(kFALSE);
134
135 // now compose the logo with the additional text
136 fLogoPad = new TPad("aliceLogo", "Pad for ALICE Logo", .2, .2, .4, .4);
137 this->UpdateLogo();
138
139 fLogoPad->GetListOfPrimitives()->Add(fLogo);
140
141 UpdateLogoPos();
142}
143
144AliFigure::~AliFigure()
145{
146 // dtor
147
148};
149
150void AliFigure::Draw(Option_t *option)
151{
152 // so far just passing on to the TCanvas method
153
154 TCanvas::Draw(option);
155}
156
157void AliFigure::Paint(Option_t *option)
158{
159 // anything to be done here?
160
161 TCanvas::Paint(option);
162}
163
164void AliFigure::Clear(Option_t *option)
165{
166 // clean up
167
168 // now walk through all the children
169 TList *listOfPrimitives = this->GetListOfPrimitives();
170 TIter iter(listOfPrimitives);
171
172 TObject *obj = 0x0;
173 while ((obj = iter())) {
174 if ((obj == fCollSystem) || (obj == fStatusPad) || (obj == fLogoPad) || (obj == fDate) || (obj == fTag) || (obj == fDataSample)) {
175 listOfPrimitives->Remove(obj);
176 }
177 }
178
179 TCanvas::Clear(option);
180}
181
182void AliFigure::Update()
183{
184 // while updating make sure that the additional logo and text
185 // get drawn last
186
3661cb6f 187 if (fDisabled)
188 return;
189
5e2810e1 190 this->UpdateLogoPos();
191 this->UpdatePad(this);
192
193 if (fLogo && fLogo->IsValid()) {
194 this->GetListOfPrimitives()->Add(fLogoPad);
195 }
196 this->GetListOfPrimitives()->Add(fCollSystem);
3661cb6f 197 if ((fStatus == kWorkInProgress) || (fStatus == kThisWork))
5e2810e1 198 this->GetListOfPrimitives()->Add(fStatusPad);
199 this->GetListOfPrimitives()->Add(fDataSample);
3661cb6f 200 // this->GetListOfPrimitives()->Add(fDate);
5e2810e1 201 this->GetListOfPrimitives()->Add(fTag);
202
203 this->Modified(kTRUE);
204 TCanvas::Update();
205}
206
207void AliFigure::SetStatus(Status_t status)
208{
209 // set the figure status, i.e. "work in progress", "performance",
210 // "preliminary", or "final"
211
212 fStatus = status;
213 fStatusPad->SetText(fStatusPad->GetX(), fStatusPad->GetY(), fStatusString[fStatus]);
214
215 UpdateLogo();
216
217 this->Modified(kTRUE);
218}
219
220void AliFigure::SetLogoFilename(Status_t status, TString filename)
221{
222 // set the filename for the logo for the given figure status
223
224 fLogoFilename[status] = filename;
225}
226
227void AliFigure::UpdateLogo()
228{
229 // update the logo
230
231 if (fLogo)
232 fLogoPad->GetListOfPrimitives()->Remove(fLogo);
233 delete fLogo;
234
235 if (fLogoFilename[fStatus].Length() > 0) {
236 fLogo = new TASImage(fLogoFilename[fStatus]);
237 if (fLogo->IsValid()) {
238 fLogo->SetImageQuality(TASImage::kImgBest);
239 // fLogo->Crop(70, 93, 634, 600);
240 }
241 }
242 else
243 fLogo = 0x0;
244
245 this->UpdateLogoPos();
246}
247
248void AliFigure::SetLogoPos(Float_t x, Float_t y)
249{
250 // set the position of the logo
251
252 fLogoPosX = x;
253 fLogoPosY = y;
254
255 this->UpdateLogoPos();
256}
257
258void AliFigure::SetLogoPos(Pos_t pos)
259{
260 // set the logo position
261 // as north (kN), north-east (kNE), ...
262
263 switch (pos) {
264 case kN:
265 SetLogoPos(0.5, 0.8);
266 break;
267 case kNE:
268 SetLogoPos(0.8, 0.8);
269 break;
270 case kE:
271 SetLogoPos(0.8, 0.5);
272 break;
273 case kSE:
274 SetLogoPos(0.8, 0.2);
275 break;
276 case kS:
277 SetLogoPos(0.5, 0.2);
278 break;
279 case kSW:
3661cb6f 280 SetLogoPos(0.25, 0.2);
5e2810e1 281 break;
282 case kW:
3661cb6f 283 SetLogoPos(0.25, 0.5);
5e2810e1 284 break;
285 case kNW:
3661cb6f 286 SetLogoPos(0.25, 0.8);
5e2810e1 287 break;
288 case kCenter:
289 SetLogoPos(0.5, 0.5);
290 break;
291 default:
292 this->Error(__FUNCTION__, "Unknown position specifier");
293 }
294}
295
296void AliFigure::SetLogoSize(Float_t size)
297{
298 // set the height of the logo as a fraction of the canvas height
299
300 fLogoHeight = this->GetWh() * size;
301
302 this->UpdateLogoPos();
303}
304
305void AliFigure::SetCollSystem(TString txt)
306{
307 // set the text for the collision system
308
309 fCollSystem->SetText(fCollSystem->GetX(), fCollSystem->GetY(), txt);
310}
311
312void AliFigure::SetCollSystemPos(Float_t x, Float_t y)
313{
314 // set the position for the collision system
315
316 fCollSystem->SetX(x);
317 fCollSystem->SetY(y);
318}
319
320void AliFigure::SetDataSample(TString txt)
321{
322 // set the description of the data sample
323
324 fDataSample->SetText(fDataSample->GetX(), fDataSample->GetY(), txt);
325}
326
327TStyle* AliFigure::Style()
328{
329 // return the figure style
330
331 if (!fgStyle) {
332 // we start from the current style
333 // how can we start from a well-defined style, e.g. plain?
334 fgStyle = new TStyle(*gStyle);
335 fgStyle->SetName("alice");
336 fgStyle->SetTitle("ALICE figure style");
337
3661cb6f 338 const int font = 43;
5e2810e1 339 fgStyle->SetFrameBorderMode(0);
340 fgStyle->SetFrameFillColor(0);
341 fgStyle->SetCanvasBorderMode(0);
342 fgStyle->SetPadBorderMode(0);
343 fgStyle->SetPadColor(10);
344 fgStyle->SetCanvasColor(10);
3661cb6f 345 fgStyle->SetOptTitle(0);
5e2810e1 346 fgStyle->SetTitleFillColor(10);
347 fgStyle->SetTitleBorderSize(0);
3661cb6f 348 if ((font % 10) == 3)
349 fgStyle->SetTitleFontSize(30);
350 else
351 fgStyle->SetTitleFontSize(0.08);
5e2810e1 352 fgStyle->SetStatColor(10);
353 fgStyle->SetStatBorderSize(1);
354 // legend settings
355 // fgStyle->SetLegendBorderSize(1);
356 // fgStyle->SetLegendFont(43);
357 // fgStyle->SetLegendFillColor(0);
358
359 fgStyle->SetDrawBorder(0);
360 fgStyle->SetTextFont(font);
361 fgStyle->SetStatFont(font);
362 fgStyle->SetStatFontSize(0.05);
363 fgStyle->SetStatX(0.97);
364 fgStyle->SetStatY(0.98);
365 fgStyle->SetStatH(0.03);
366 fgStyle->SetStatW(0.3);
367 fgStyle->SetTickLength(0.02,"y");
368 fgStyle->SetEndErrorSize(3);
3661cb6f 369 if ((font % 10) == 3)
370 fgStyle->SetLabelSize(30, "xyz");
371 else
372 fgStyle->SetLabelSize(0.05,"xyz");
5e2810e1 373 fgStyle->SetLabelFont(font,"xyz");
374 fgStyle->SetLabelOffset(0.01,"xyz");
375 fgStyle->SetTitleFont(font,"xyz");
3661cb6f 376 fgStyle->SetTitleOffset(1.,"xyz");
377 if ((font % 10) == 3)
378 fgStyle->SetTitleSize(34, "xyz");
379 else
380 fgStyle->SetTitleSize(0.06,"xyz");
5e2810e1 381 fgStyle->SetMarkerSize(1);
382 fgStyle->SetPalette(1,0);
383 if (kFALSE) {
384 fgStyle->SetOptStat(1111);
385 fgStyle->SetOptFit(1111);
386 }
387 else {
388 fgStyle->SetOptStat(0);
389 fgStyle->SetOptFit(0);
390 }
391 }
392
393 return fgStyle;
394}
395
396void AliFigure::SetTextSize(Float_t size)
397{
398 // specify the text size
399
400 fTextSize = size;
401 fStatusPad->SetTextSize(fTextSize);
402
403 this->UpdateLogoPos();
404 this->UpdatePad(this);
405}
406
407void AliFigure::UpdateLogoPos()
408{
409 // move the logo to the correct position
410
411 Float_t ratio = 1.;
412 Float_t height = 0.;
413 Float_t width = 0.;
414
415 if (fLogo && fLogo->IsValid()) {
416 ratio = fLogo->GetWidth();
417 ratio /= (Float_t) fLogo->GetHeight();
418 ratio *= (Float_t) this->GetWh();
419 ratio /= (Float_t) this->GetWw();
420 height = fLogoHeight / this->GetWh();
421 width = height*ratio;
422 fLogoPad->SetPad(fLogoPosX - width/2, fLogoPosY - height/2,
423 fLogoPosX + width/2, fLogoPosY + height/2);
424 }
425
426 Float_t offset = - (0.*fTextSize)/this->GetWh();
427
428 if ((fStatus == kPerformance) ||
429 (fStatus == kWorkInProgress)) {
430 fStatusPad->SetX(fLogoPosX);
431 fStatusPad->SetY(fLogoPosY - height/2 + offset);
432 offset -= (1.2*fTextSize)/this->GetWh();
433 }
3661cb6f 434 else if (fStatus == kThisWork) {
435 fStatusPad->SetX(0.25);
436 fStatusPad->SetY(0.95);
437 }
5e2810e1 438
439 fDate->SetX(fLogoPosX);
440 fDate->SetY(fLogoPosY - height/2 + offset);
441
442 offset -= (1.2*fTextSize)/this->GetWh();
443
444 fTag->SetX(fLogoPosX);
445 fTag->SetY(fLogoPosY - height/2 + offset);
446
447 this->Modified();
448}
449
450void AliFigure::UpdatePad(TPad *pad)
451{
452 // enforce settings of the given pad
453 // and walk through all children
454
455 // set the geometry for the pad
456 pad->SetLeftMargin(0.15);
457 pad->SetRightMargin(0.04);
5e2810e1 458 pad->SetBottomMargin(0.15);
459
3661cb6f 460 fCollSystem->SetX(.96);
461
5e2810e1 462 // now walk through all the children
463 TList *listOfPrimitives = pad->GetListOfPrimitives();
464 TIter iter(listOfPrimitives);
465
466 TObject *obj = 0x0;
467 while ((obj = iter())) {
468 if ((obj == fCollSystem) || (obj == fStatusPad) || (obj == fLogoPad) || (obj == fDate) || (obj == fTag) || (obj == fDataSample)) {
469 listOfPrimitives->Remove(obj);
470 }
471 else {
472 // make sure that the current style is used
473 // obj->UseCurrentStyle();
474 // if (obj->InheritsFrom("TGraphErrors")) {
475 // TGraphErrors *graph = (TGraphErrors*) obj;
476 // graph->SetMarkerSize(5);
477 // // graph->SetMarkerStyle(currentMarkerStyle);
478 // // graph->SetMarkerColor(currentMarkerColor);
479 // // graph->SetLineStyle(currentLineStyle);
480 // // graph->SetLineColor(currentLineColor);
481 // }
482 if (obj->InheritsFrom("TPad")) {
3661cb6f 483 // this->UpdatePad((TPad*) obj);
484 }
485 else if (obj->InheritsFrom("TH2")) {
486 pad->SetRightMargin(.18);
487 fCollSystem->SetX(.82);
5e2810e1 488 }
489 else if (obj->InheritsFrom("TLegend")) {
490 TLegend *leg = (TLegend*) obj;
3661cb6f 491 // leg->SetTextFont(43);
5e2810e1 492 leg->SetBorderSize(1);
493 leg->SetFillStyle(0);
494 leg->SetFillColor(1);
495 leg->SetShadowColor(0);
496 leg->SetMargin(0.25);
497 leg->SetTextSize(fTextSize);
498 leg->SetEntrySeparation(0.25);
499 }
500 }
501 }
502}