1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // Canvas for ALICE figures
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.
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
28 // Author: Jochen Klein <jochen.klein@cern.ch>
41 #include "TGraphErrors.h"
43 #include "AliFigure.h"
45 TStyle *AliFigure::fgStyle;
47 AliFigure::AliFigure(const char* name, const char* title, Int_t ww, Int_t wh) :
48 TCanvas(name, title, ww, wh),
51 fStatus(kWorkInProgress),
52 fDateFormat("%d/%m/%Y"),
69 fStatusString[kWorkInProgress] = "work in progress";
70 fStatusString[kThisWork] = "- this work -";
71 fStatusString[kPerformance] = "Performance";
72 fStatusString[kPreliminary] = "Preliminary";
73 fStatusString[kFinal] = "";
75 fLogoFilename[kWorkInProgress] = "$ALICE_ROOT/PWG/Tools/fig/2011-Nov-24-ALICE_logo_WithoutStrapline.eps";
76 fLogoFilename[kThisWork] = "";
77 fLogoFilename[kPerformance] = "$ALICE_ROOT/PWG/Tools/fig/2011-Nov-24-ALICE_logo_WithoutStrapline.eps";
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] = "";
82 this->SetLeftMargin(0.15);
83 this->SetRightMargin(0.04);
84 this->SetRightMargin(0.04);
85 this->SetBottomMargin(0.15);
89 time_t t = (time_t) now.Convert();
90 struct tm* loctis = localtime(&t);
91 strftime(date, 30, fDateFormat.Data(), loctis);
93 fCollSystem = new TLatex(0.96, 0.95, "pp #sqrt{s} = 7 TeV");
94 fCollSystem->SetNDC();
95 fCollSystem->SetTextSize(fTextSize);
96 fCollSystem->SetTextFont(43);
97 fCollSystem->SetTextAlign(33);
98 fCollSystem->SetTextColor(fTextColor);
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);
107 fDate = new TText(0.5, 0., date);
109 fDate->SetTextSize(fTextSize);
110 fDate->SetTextFont(43);
111 fDate->SetTextAlign(22);
112 fDate->SetTextColor(fTextColor);
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);
121 fTag = new TText(0.5, 0., "");
123 fTag->SetTextSize(fTextSize);
124 fTag->SetTextFont(43);
125 fTag->SetTextAlign(22);
126 fTag->SetTextColor(fTextColor);
128 // fLogoPad->ResetBit(kCanDelete);
129 // fCollSystem->ResetBit(kCanDelete);
130 // fStatusPad->ResetBit(kCanDelete);
131 // fDate->ResetBit(kCanDelete);
133 // GetListOfPrimitives()->SetOwner(kFALSE);
135 // now compose the logo with the additional text
136 fLogoPad = new TPad("aliceLogo", "Pad for ALICE Logo", .2, .2, .4, .4);
139 fLogoPad->GetListOfPrimitives()->Add(fLogo);
144 AliFigure::~AliFigure()
150 void AliFigure::Draw(Option_t *option)
152 // so far just passing on to the TCanvas method
154 TCanvas::Draw(option);
157 void AliFigure::Paint(Option_t *option)
159 // anything to be done here?
161 TCanvas::Paint(option);
164 void AliFigure::Clear(Option_t *option)
168 // now walk through all the children
169 TList *listOfPrimitives = this->GetListOfPrimitives();
170 TIter iter(listOfPrimitives);
173 while ((obj = iter())) {
174 if ((obj == fCollSystem) || (obj == fStatusPad) || (obj == fLogoPad) || (obj == fDate) || (obj == fTag) || (obj == fDataSample)) {
175 listOfPrimitives->Remove(obj);
179 TCanvas::Clear(option);
182 void AliFigure::Update()
184 // while updating make sure that the additional logo and text
190 this->UpdateLogoPos();
191 this->UpdatePad(this);
193 if (fLogo && fLogo->IsValid()) {
194 this->GetListOfPrimitives()->Add(fLogoPad);
196 this->GetListOfPrimitives()->Add(fCollSystem);
197 if ((fStatus == kWorkInProgress) || (fStatus == kThisWork))
198 this->GetListOfPrimitives()->Add(fStatusPad);
199 this->GetListOfPrimitives()->Add(fDataSample);
200 // this->GetListOfPrimitives()->Add(fDate);
201 this->GetListOfPrimitives()->Add(fTag);
203 this->Modified(kTRUE);
207 void AliFigure::SetStatus(Status_t status)
209 // set the figure status, i.e. "work in progress", "performance",
210 // "preliminary", or "final"
213 fStatusPad->SetText(fStatusPad->GetX(), fStatusPad->GetY(), fStatusString[fStatus]);
217 this->Modified(kTRUE);
220 void AliFigure::SetLogoFilename(Status_t status, TString filename)
222 // set the filename for the logo for the given figure status
224 fLogoFilename[status] = filename;
227 void AliFigure::UpdateLogo()
232 fLogoPad->GetListOfPrimitives()->Remove(fLogo);
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);
245 this->UpdateLogoPos();
248 void AliFigure::SetLogoPos(Float_t x, Float_t y)
250 // set the position of the logo
255 this->UpdateLogoPos();
258 void AliFigure::SetLogoPos(Pos_t pos)
260 // set the logo position
261 // as north (kN), north-east (kNE), ...
265 SetLogoPos(0.5, 0.8);
268 SetLogoPos(0.8, 0.8);
271 SetLogoPos(0.8, 0.5);
274 SetLogoPos(0.8, 0.2);
277 SetLogoPos(0.5, 0.2);
280 SetLogoPos(0.25, 0.2);
283 SetLogoPos(0.25, 0.5);
286 SetLogoPos(0.25, 0.8);
289 SetLogoPos(0.5, 0.5);
292 this->Error(__FUNCTION__, "Unknown position specifier");
296 void AliFigure::SetLogoSize(Float_t size)
298 // set the height of the logo as a fraction of the canvas height
300 fLogoHeight = this->GetWh() * size;
302 this->UpdateLogoPos();
305 void AliFigure::SetCollSystem(TString txt)
307 // set the text for the collision system
309 fCollSystem->SetText(fCollSystem->GetX(), fCollSystem->GetY(), txt);
312 void AliFigure::SetCollSystemPos(Float_t x, Float_t y)
314 // set the position for the collision system
316 fCollSystem->SetX(x);
317 fCollSystem->SetY(y);
320 void AliFigure::SetDataSample(TString txt)
322 // set the description of the data sample
324 fDataSample->SetText(fDataSample->GetX(), fDataSample->GetY(), txt);
327 TStyle* AliFigure::Style()
329 // return the figure style
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");
339 fgStyle->SetFrameBorderMode(0);
340 fgStyle->SetFrameFillColor(0);
341 fgStyle->SetCanvasBorderMode(0);
342 fgStyle->SetPadBorderMode(0);
343 fgStyle->SetPadColor(10);
344 fgStyle->SetCanvasColor(10);
345 fgStyle->SetOptTitle(0);
346 fgStyle->SetTitleFillColor(10);
347 fgStyle->SetTitleBorderSize(0);
348 if ((font % 10) == 3)
349 fgStyle->SetTitleFontSize(30);
351 fgStyle->SetTitleFontSize(0.08);
352 fgStyle->SetStatColor(10);
353 fgStyle->SetStatBorderSize(1);
355 // fgStyle->SetLegendBorderSize(1);
356 // fgStyle->SetLegendFont(43);
357 // fgStyle->SetLegendFillColor(0);
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);
369 if ((font % 10) == 3)
370 fgStyle->SetLabelSize(30, "xyz");
372 fgStyle->SetLabelSize(0.05,"xyz");
373 fgStyle->SetLabelFont(font,"xyz");
374 fgStyle->SetLabelOffset(0.01,"xyz");
375 fgStyle->SetTitleFont(font,"xyz");
376 fgStyle->SetTitleOffset(1.,"xyz");
377 if ((font % 10) == 3)
378 fgStyle->SetTitleSize(34, "xyz");
380 fgStyle->SetTitleSize(0.06,"xyz");
381 fgStyle->SetMarkerSize(1);
382 fgStyle->SetPalette(1,0);
384 fgStyle->SetOptStat(1111);
385 fgStyle->SetOptFit(1111);
388 fgStyle->SetOptStat(0);
389 fgStyle->SetOptFit(0);
396 void AliFigure::SetTextSize(Float_t size)
398 // specify the text size
401 fStatusPad->SetTextSize(fTextSize);
403 this->UpdateLogoPos();
404 this->UpdatePad(this);
407 void AliFigure::UpdateLogoPos()
409 // move the logo to the correct position
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);
426 Float_t offset = - (0.*fTextSize)/this->GetWh();
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();
434 else if (fStatus == kThisWork) {
435 fStatusPad->SetX(0.25);
436 fStatusPad->SetY(0.95);
439 fDate->SetX(fLogoPosX);
440 fDate->SetY(fLogoPosY - height/2 + offset);
442 offset -= (1.2*fTextSize)/this->GetWh();
444 fTag->SetX(fLogoPosX);
445 fTag->SetY(fLogoPosY - height/2 + offset);
450 void AliFigure::UpdatePad(TPad *pad)
452 // enforce settings of the given pad
453 // and walk through all children
455 // set the geometry for the pad
456 pad->SetLeftMargin(0.15);
457 pad->SetRightMargin(0.04);
458 pad->SetBottomMargin(0.15);
460 fCollSystem->SetX(.96);
462 // now walk through all the children
463 TList *listOfPrimitives = pad->GetListOfPrimitives();
464 TIter iter(listOfPrimitives);
467 while ((obj = iter())) {
468 if ((obj == fCollSystem) || (obj == fStatusPad) || (obj == fLogoPad) || (obj == fDate) || (obj == fTag) || (obj == fDataSample)) {
469 listOfPrimitives->Remove(obj);
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);
482 if (obj->InheritsFrom("TPad")) {
483 // this->UpdatePad((TPad*) obj);
485 else if (obj->InheritsFrom("TH2")) {
486 pad->SetRightMargin(.18);
487 fCollSystem->SetX(.82);
489 else if (obj->InheritsFrom("TLegend")) {
490 TLegend *leg = (TLegend*) obj;
491 // leg->SetTextFont(43);
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);