FairRoot/PandaRoot
PandaSmartLabel.C
Go to the documentation of this file.
1 int PandaSmartLabel(TString align="Rprel", Double_t xpos=-1, Double_t ypos=-1, Double_t scale=-1, TString str="-1", Double_t scale2=-1) {
2  // H as the first parameter triggers printing comamnd options
3  if (align == "H") {
4  cout
5  << endl
6  << " USAGE: PandaSmartLabel(\"align\",xpos,ypos,scale,\"str\",scale2);" << endl
7  << " Prints the official BaBar label on the active ROOT pad" << endl
8  << " align R or L, optionally with additional 'prel' or 'front': str is aligned to the right (default) or left edge of the \"PANDA\" label" << endl
9  << " xpos X position of the \"PANDA\" label\'s bottom right (align==R)/left (==L) corner, 0 < xpos < 1, defaults to (L) left margin + 0.02 or (R) 1.0 - right margin - 0.02" << endl
10  << " ypos Y position of the \"PANDA\" label\'s bottom right (align==R)/left (==L) corner, 0 < ypos < 1, defaults to 1 - top margin - 0.08" << endl
11  << " scale relative size of the label, defaults to 0.9" << endl
12  << " str LaTeX-style text that goes under the PANDA label." << endl
13  << " scale2 relative size of the second line of text, defaults to 0.45" << endl;
14  cout <<endl
15  << " Examples: " << endl
16  << " PandaSmartLabel(\"H\") -> Prints out this help text" << endl
17  << " PandaSmartLabel() -> Label 'PANDA//MC simulation' in top right corner" << endl
18  << " PandaSmartLabel(\"L\") -> Label 'PANDA//MC simulation' in top left corner" << endl
19  << " PandaSmartLabel(\"-1\",-1,-1,-1,\"preliminary\",0.4) -> Label 'PANDA//preliminary' in top right corner " << endl
20  << " PandaSmartLabel(\"Rprel\") -> Label 'PANDA' in top right corner with a large 'PRELIMINARY' across the plot behind histograms (works only with gStyle->SetFrameFillStyle(0))" << endl
21  << " PandaSmartLabel(\"Lprelfront\")-> Label 'PANDA' in top left corner with a large 'PRELIMINARY' across the plot behind histograms (works only with gStyle->SetFrameFillStyle(0))" << endl << endl;
22  return();
23  }
24 
25  if (gPad==0) return;
26 
27  // Making -1 a placeholder for function's default value
28  if (align=="") align="R";
29 
30  bool rightalign = !(align.Contains("L"));
31  bool preliminary = align.Contains("prel");
32  bool front = align.Contains("front");
33 
34  double mt = gPad->GetTopMargin();
35  double mb = gPad->GetBottomMargin();
36  double ml = gPad->GetLeftMargin();
37  double mr = gPad->GetRightMargin();
38 
39  if (ypos==-1) ypos = 1.0 - mt - 0.08;
40 
41  if (rightalign) // Right align
42  {
43  if (xpos==-1) xpos = 1.0 - mr - 0.02;
44  }
45  else
46  { // Left align
47  if (xpos==-1) xpos = ml + 0.02;
48  }
49 
50  if (scale == -1) scale = 0.9;
51  if (str == "-1") str = "MC simulation";
52  if (scale2 == -1) scale2 = 0.45;
53 
54 
55  // Draw the label
56  TLatex *panda = new TLatex();
57  panda->SetNDC(kTRUE);
58  double fcx=1., fcy=1., dx=1.0-xpos, dy = 1.0-ypos;
59 //
60  double padSizeX = gPad->GetWw()*gPad->GetWNDC(); // Get pad's dimensions
61  double padSizeY = gPad->GetWh()*gPad->GetHNDC();
62 // if (padSizeX>padSizeY) fcx=padSizeY/padSizeX;
63 // if (padSizeX<padSizeY) fcy=padSizeX/padSizeY;
64 //
65 // cout <<padSizeX<<" "<<padSizeY<<" : "<<fcx<<" "<<fcy<<endl;
66 //
67  panda->SetNDC(kTRUE);
68 
69  if (preliminary)
70  {
71  panda->SetTextFont(42);
72  panda->SetTextColor(17);
73  panda->SetTextSize(0.17*(1.-ml-mr));
74  panda->SetTextAlign(22);
75  double sizeX = padSizeX*(1. - ml - mr);
76  double sizeY = padSizeY*(1. - mt - mb);
77  double posX = (ml+(1.-mr))*0.5;
78  double posY = (mb+(1.-mt))*0.42;
79  panda->SetTextAngle(atan(sizeY/sizeX)/3.1415*142.);
80  panda->DrawLatex(posX,posY,"PRELIMINARY");
81 
82  TList *ll=gPad->GetListOfPrimitives();
83  if (!front) ll->AddAt(ll->RemoveAt(ll->GetEntries()-1),0);
84  }
85 
86  panda->SetTextColor(13);
87  panda->SetTextAngle(0);
88 
89  panda->SetTextFont(62); // Bold helvetiva
90  if (rightalign) panda->SetTextAlign(31); // Right-Bottom
91  else panda->SetTextAlign(11); // Left bottom
92  panda->SetTextSize(0.07*scale);
93  panda->DrawLatex(xpos*fcy,ypos*fcx,"#bar{P}ANDA");
94 
95  panda->SetTextFont(42); // Helvetica
96  if (rightalign) panda->SetTextAlign(33); // Right-Bottom
97  else panda->SetTextAlign(13); // Left bottom
98  panda->SetTextSize(0.08*scale2);
99  panda->DrawLatex(xpos*fcx,ypos*fcy*0.99,str);
100 
101  delete panda;
102 
103  return 0;
104 }
double dy
Double_t
double dx
int PandaSmartLabel(TString align="Rprel", Double_t xpos=-1, Double_t ypos=-1, Double_t scale=-1, TString str="-1", Double_t scale2=-1)