AliPhysics  58f3d52 (58f3d52)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliCanvas.cxx
Go to the documentation of this file.
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 
17 //
18 // Generic canvas for ALICE figures
19 //
20 // This class inherits from TCanvas and can be used instead of it. It
21 // places the ALICE logo, and other things according to the figure status.
22 //
23 // Author: Jochen Klein <jochen.klein@cern.ch>
24 //
26 
27 #include "TCanvas.h"
28 #include "TList.h"
29 #include "TDatime.h"
30 
31 #include "TStyle.h"
32 #include "TColor.h"
33 #include "TText.h"
34 #include "TASImage.h"
35 #include "TLatex.h"
36 #include "TLegend.h"
37 #include "TGraphErrors.h"
38 #include "TH1.h"
39 #include "TH2.h"
40 #include "TH3.h"
41 
42 #include "AliCanvas.h"
43 
44 TStyle *AliCanvas::fgStyle;
45 
46 AliCanvas::AliCanvas(const char* name, const char* title, Int_t ww, Int_t wh) :
47  TCanvas(name, title, ww, wh),
48  fDisabled(kFALSE),
49  fDisabledMargin(kFALSE),
50  isMC(kFALSE),
51  fStatus(kWorkInProgress),
52  fDateFormat("%d/%m/%Y"),
53  fTextSize(20),
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";
70  fStatusString[kThisWork] = "- this work -";
71  fStatusString[kPerformance] = "Performance";
72  fStatusString[kPreliminary] = "Preliminary";
73  fStatusString[kFinal] = "";
74 
77  fLogoFilename[kPerformance] = "$ALICE_PHYSICS/PWG/Tools/fig/2011-Nov-24-ALICE_logo_WithoutStrapline.eps";
78  // fLogoFilename[kPerformance] = "$ALICE_PHYSICS/PWG/Tools/fig/2011-Nov-24-ALICE_PERFORMANCE_logo_BLACK_small_usage_design.eps";
79  fLogoFilename[kPreliminary] = "$ALICE_PHYSICS/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 
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);
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  if (fLogo)
140  fLogoPad->GetListOfPrimitives()->Add(fLogo);
141 
142  UpdateLogoPos();
143 }
144 
146 {
147  // destructor
148 
149 };
150 
152 {
153  // just passing on to the TCanvas method
154 
155  TCanvas::Draw(option);
156 }
157 
159 {
160  // just passing on to the TCanvas method
161 
162  TCanvas::Paint(option);
163 }
164 
166 {
167  // clean up
168 
169  // now walk through all the children
170  TList *listOfPrimitives = this->GetListOfPrimitives();
171  TIter iter(listOfPrimitives);
172 
173  TObject *obj = 0x0;
174  while ((obj = iter())) {
175  if ((obj == fCollSystem) || (obj == fStatusPad) || (obj == fLogoPad) || (obj == fDate) || (obj == fTag) || (obj == fDataSample)) {
176  listOfPrimitives->Remove(obj);
177  }
178  }
179 
180  TCanvas::Clear(option);
181 }
182 
184 {
185  // while updating make sure that the additional logo and text
186  // get drawn last
187 
188  if (fDisabled)
189  return;
190 
191  this->UpdateLogoPos();
192  this->UpdatePad(this);
193 
194  if (fLogo && fLogo->IsValid()) {
195  this->GetListOfPrimitives()->Add(fLogoPad);
196  }
197  this->GetListOfPrimitives()->Add(fCollSystem);
198  if ((fStatus == kWorkInProgress) || (fStatus == kThisWork))
199  this->GetListOfPrimitives()->Add(fStatusPad);
200  this->GetListOfPrimitives()->Add(fDataSample);
201  // this->GetListOfPrimitives()->Add(fDate);
202  this->GetListOfPrimitives()->Add(fTag);
203 
204  this->Modified(kTRUE);
205  TCanvas::Update();
206 }
207 
209 {
210  // set the figure status, i.e. "work in progress", "performance",
211  // "preliminary", or "final"
212 
213  fStatus = status;
214  fStatusPad->SetText(fStatusPad->GetX(), fStatusPad->GetY(), fStatusString[fStatus]);
215 
216  UpdateLogo();
217 
218  this->Modified(kTRUE);
219 }
220 
222 {
223  // set the filename for the logo for the given figure status
224 
225  fLogoFilename[status] = filename;
226 }
227 
229 {
230  // update the logo
231 
232  if (fLogo)
233  fLogoPad->GetListOfPrimitives()->Remove(fLogo);
234  delete fLogo;
235 
236  if (fLogoFilename[fStatus].Length() > 0) {
237  fLogo = new TASImage(fLogoFilename[fStatus]);
238  if (fLogo->IsValid()) {
239  fLogo->SetImageQuality(TASImage::kImgBest);
240  // fLogo->Crop(70, 93, 634, 600);
241  }
242  }
243  else
244  fLogo = 0x0;
245 
246  this->UpdateLogoPos();
247 }
248 
250 {
251  // set the position of the logo
252 
253  fLogoPosX = x;
254  fLogoPosY = y;
255 
256  this->UpdateLogoPos();
257 }
258 
260 {
261  // set the logo position
262  // as north (kN), north-east (kNE), ...
263 
264  switch (pos) {
265  case kN:
266  SetLogoPos(0.5, 0.8);
267  break;
268  case kNE:
269  SetLogoPos(0.8, 0.8);
270  break;
271  case kE:
272  SetLogoPos(0.8, 0.5);
273  break;
274  case kSE:
275  SetLogoPos(0.8, 0.2);
276  break;
277  case kS:
278  SetLogoPos(0.5, 0.2);
279  break;
280  case kSW:
281  SetLogoPos(0.25, 0.2);
282  break;
283  case kW:
284  SetLogoPos(0.25, 0.5);
285  break;
286  case kNW:
287  SetLogoPos(0.25, 0.8);
288  break;
289  case kCenter:
290  SetLogoPos(0.5, 0.5);
291  break;
292  default:
293  this->Error(__FUNCTION__, "Unknown position specifier");
294  }
295 }
296 
298 {
299  // set the height of the logo as a fraction of the canvas height
300 
301  fLogoHeight = this->GetWh() * size;
302 
303  this->UpdateLogoPos();
304 }
305 
307 {
308  // set the text for the collision system
309 
310  fCollSystem->SetText(fCollSystem->GetX(), fCollSystem->GetY(), txt);
311 }
312 
314 {
315  // set the position for the collision system
316 
317  fCollSystem->SetX(x);
318  fCollSystem->SetY(y);
319 }
320 
322 {
323  // set the description of the data sample
324 
325  fDataSample->SetText(fDataSample->GetX(), fDataSample->GetY(), txt);
326 }
327 
329 {
330  // return the figure style
331 
332  if (!fgStyle) {
333  // we start from the current style
334  // how can we start from a well-defined style, e.g. plain?
335  fgStyle = new TStyle(*gStyle);
336  fgStyle->SetName("alice");
337  fgStyle->SetTitle("ALICE figure style");
338 
339  const int font = 43;
340  fgStyle->SetFrameBorderMode(0);
341  fgStyle->SetFrameFillColor(0);
342  fgStyle->SetCanvasBorderMode(0);
343  fgStyle->SetPadBorderMode(0);
344  fgStyle->SetPadColor(10);
345  fgStyle->SetCanvasColor(10);
346  fgStyle->SetOptTitle(0);
347  fgStyle->SetTitleFillColor(10);
348  fgStyle->SetTitleBorderSize(0);
349  if ((font % 10) == 3)
350  fgStyle->SetTitleFontSize(30);
351  else
352  fgStyle->SetTitleFontSize(0.08);
353  fgStyle->SetStatColor(10);
354  fgStyle->SetStatBorderSize(1);
355  // legend settings
356  // fgStyle->SetLegendBorderSize(1);
357  // fgStyle->SetLegendFont(43);
358  // fgStyle->SetLegendFillColor(0);
359 
360  fgStyle->SetDrawBorder(0);
361  fgStyle->SetTextFont(font);
362  fgStyle->SetStatFont(font);
363  fgStyle->SetStatFontSize(0.05);
364  fgStyle->SetStatX(0.97);
365  fgStyle->SetStatY(0.98);
366  fgStyle->SetStatH(0.03);
367  fgStyle->SetStatW(0.3);
368  fgStyle->SetTickLength(0.02,"y");
369  fgStyle->SetEndErrorSize(3);
370  if ((font % 10) == 3)
371  fgStyle->SetLabelSize(30, "xyz");
372  else
373  fgStyle->SetLabelSize(0.05,"xyz");
374  fgStyle->SetLabelFont(font,"xyz");
375  fgStyle->SetLabelOffset(0.01,"xyz");
376  fgStyle->SetTitleFont(font,"xyz");
377  fgStyle->SetTitleOffset(1.,"xyz");
378  if ((font % 10) == 3)
379  fgStyle->SetTitleSize(34, "xyz");
380  else
381  fgStyle->SetTitleSize(0.06,"xyz");
382  fgStyle->SetMarkerSize(1);
383  fgStyle->SetPalette(1,0);
384  if (kFALSE) {
385  fgStyle->SetOptStat(1111);
386  fgStyle->SetOptFit(1111);
387  }
388  else {
389  fgStyle->SetOptStat(0);
390  fgStyle->SetOptFit(0);
391  }
392 
393  fgStyle->SetLegendFont(font);
394  }
395 
396  return fgStyle;
397 }
398 
400 {
401  // specify the text size
402 
403  fTextSize = size;
404  fStatusPad->SetTextSize(fTextSize);
405 
406  this->UpdateLogoPos();
407  this->UpdatePad(this);
408 }
409 
411 {
412  // move the logo to the correct position
413 
414  Float_t ratio = 1.;
415  Float_t height = 0.;
416  Float_t width = 0.;
417 
418  if (fLogo && fLogo->IsValid()) {
419  ratio = fLogo->GetWidth();
420  ratio /= (Float_t) fLogo->GetHeight();
421  ratio *= (Float_t) this->GetWh();
422  ratio /= (Float_t) this->GetWw();
423  height = fLogoHeight / this->GetWh();
424  width = height*ratio;
425  fLogoPad->SetPad(fLogoPosX - width/2, fLogoPosY - height/2,
426  fLogoPosX + width/2, fLogoPosY + height/2);
427  }
428 
429  Float_t offset = - (0.*fTextSize)/this->GetWh();
430 
431  if (fStatus == kPerformance) {
432  fStatusPad->SetX(fLogoPosX);
433  fStatusPad->SetY(fLogoPosY - height/2 + offset);
434  offset -= (1.2*fTextSize)/this->GetWh();
435  }
436  else if ((fStatus == kThisWork) ||
437  (fStatus == kWorkInProgress)) {
438  fStatusPad->SetX(0.25);
439  fStatusPad->SetY(0.95);
440  }
441 
442  fDate->SetX(fLogoPosX);
443  fDate->SetY(fLogoPosY - height/2 + offset);
444 
445  offset -= (1.2*fTextSize)/this->GetWh();
446 
447  fTag->SetX(fLogoPosX);
448  fTag->SetY(fLogoPosY - height/2 + offset);
449 
450  this->Modified();
451 }
452 
453 void AliCanvas::UpdatePad(TPad *pad)
454 {
455  // enforce settings of the given pad
456  // and walk through all children
457 
458  // set the geometry for the pad
459  if (!fDisabledMargin) {
460  pad->SetLeftMargin(0.15);
461  pad->SetRightMargin(0.04);
462  pad->SetBottomMargin(0.15);
463  }
464 
465  fCollSystem->SetX(.96);
466 
467  // now walk through all the children
468  TList *listOfPrimitives = pad->GetListOfPrimitives();
469  TIter iter(listOfPrimitives);
470 
471  TObject *obj = 0x0;
472  while ((obj = iter())) {
473  if ((obj == fCollSystem) || (obj == fStatusPad) || (obj == fLogoPad) || (obj == fDate) || (obj == fTag) || (obj == fDataSample)) {
474  listOfPrimitives->Remove(obj);
475  }
476  else {
477  // make sure that the current style is used
478  // obj->UseCurrentStyle();
479  // if (obj->InheritsFrom("TGraphErrors")) {
480  // TGraphErrors *graph = (TGraphErrors*) obj;
481  // graph->SetMarkerSize(5);
482  // // graph->SetMarkerStyle(currentMarkerStyle);
483  // // graph->SetMarkerColor(currentMarkerColor);
484  // // graph->SetLineStyle(currentLineStyle);
485  // // graph->SetLineColor(currentLineColor);
486  // }
487  if (obj->InheritsFrom("TPad")) {
488  // this->UpdatePad((TPad*) obj);
489  }
490  else if (obj->InheritsFrom("TH2")) {
491  const TString drawOption = ((TH2*) obj)->GetDrawOption();
492  if (drawOption.Contains("surf")) {
493  pad->SetLeftMargin(.2);
494  ((TH2*) obj)->SetTitleOffset(1.3,"z");
495  ((TH2*) obj)->SetTitleOffset(1.3,"y");
496  ((TH2*) obj)->GetXaxis()->CenterTitle();
497  ((TH2*) obj)->GetYaxis()->CenterTitle();
498  }
499  else {
500  pad->SetRightMargin(.18);
501  fCollSystem->SetX(.82);
502  }
503  }
504  else if (obj->InheritsFrom("TLegend")) {
505  TLegend *leg = (TLegend*) obj;
506  leg->SetTextFont(43);
507  leg->SetBorderSize(1);
508  leg->SetFillStyle(0);
509  leg->SetFillColor(1);
510  leg->SetShadowColor(0);
511  leg->SetMargin(0.25);
512  leg->SetTextSize(fTextSize);
513  leg->SetEntrySeparation(0.25);
514  }
515  }
516  }
517 }
void SetCollSystemPos(Float_t x, Float_t y)
Definition: AliCanvas.cxx:313
const char * filename
Definition: TestFCM.C:1
TString fLogoFilename[kStatusLast]
Definition: AliCanvas.h:88
AliCanvas(const char *name="", const char *title="", Int_t ww=800, Int_t wh=600)
Definition: AliCanvas.cxx:46
void Draw(const char *filename, const char *title="", const char *others="ALL", const char *options="DEFAULT", const char *outFlg="ALL", UShort_t rebin=5, Float_t eff=0, const char *base="")
Definition: DrawdNdeta.C:3603
const char * title
Definition: MakeQAPdf.C:27
void SetTextSize(Float_t size)
Definition: AliCanvas.cxx:399
TText * fTag
Definition: AliCanvas.h:98
TPad * fLogoPad
Definition: AliCanvas.h:93
TLatex * fCollSystem
Definition: AliCanvas.h:96
void UpdateLogo()
Definition: AliCanvas.cxx:228
void SetLogoPos(Float_t x, Float_t y)
Definition: AliCanvas.cxx:249
void SetCollSystem(TString txt)
Definition: AliCanvas.cxx:306
Bool_t fDisabledMargin
Definition: AliCanvas.h:79
void Update()
Definition: AliCanvas.cxx:183
TString fDateFormat
Definition: AliCanvas.h:84
int Int_t
Definition: External.C:63
void Clear(Option_t *option="")
Definition: AliCanvas.cxx:165
Float_t fLogoPosY
Definition: AliCanvas.h:90
void Draw(Option_t *option="")
Definition: AliCanvas.cxx:151
float Float_t
Definition: External.C:68
TLatex * fDataSample
Definition: AliCanvas.h:97
Bool_t fDisabled
Definition: AliCanvas.h:78
void SetLogoSize(Float_t size)
Definition: AliCanvas.cxx:297
void SetDataSample(TString txt)
Definition: AliCanvas.cxx:321
void UpdatePad(TPad *pad)
Definition: AliCanvas.cxx:453
static TStyle * fgStyle
Definition: AliCanvas.h:103
TASImage * fLogo
Definition: AliCanvas.h:99
Bool_t isMC
Float_t fTextSize
Definition: AliCanvas.h:85
TText * fDate
Definition: AliCanvas.h:94
Definition: External.C:220
static TStyle * Style()
Definition: AliCanvas.cxx:328
Color_t fTextColor
Definition: AliCanvas.h:86
void SetStatus(Status_t status)
Definition: AliCanvas.cxx:208
void Paint(Option_t *option="")
Definition: AliCanvas.cxx:158
const char Option_t
Definition: External.C:48
Status_t fStatus
Definition: AliCanvas.h:82
Float_t fLogoPosX
Definition: AliCanvas.h:89
Float_t fLogoHeight
Definition: AliCanvas.h:91
const char * fStatusString[kStatusLast]
Definition: AliCanvas.h:101
void SetLogoFilename(Status_t status, TString filename)
Definition: AliCanvas.cxx:221
void UpdateLogoPos()
Definition: AliCanvas.cxx:410
TText * fStatusPad
Definition: AliCanvas.h:95