Diana Software
QDianaLabel.cc
Go to the documentation of this file.
1 #include "QDianaLabel.hh"
2 #include <iostream>
3 #include <TPad.h>
4 #include <TColor.h>
5 #include <TMath.h>
6 
8 
9 QDianaLabel::QDianaLabel(double x1,double y1,double x2,double y2,
10  int bordersize,const char *ExpName,
11  double Exposure,bool isPrelim,
12  const char *options)
13 : TPave(x1,y1,x2,y2,bordersize,Form("%s:NDC",options)),
14  fExperimentName(ExpName),
15  fSecondLine(""),
16  fExposure(Exposure),
17  fIsPrelim(isPrelim),
18  fIsIsoExp(false),
19  fExperimentColor(TColor::GetColor(176,19,59)),
20  fDataColor(TColor::GetColor(176,19,59)),
21  fExperimentLine(NULL),
22  fExposureLine(NULL)
23 {
24  if(bordersize<=1)
25  SetFillColor(0);
26  SetTextAlign(12);
27  fExperimentLine=new TLatex();
28  fExposureLine=new TLatex();
29 
30 }
33  if(fExposureLine) delete fExposureLine;
34 }
35 void QDianaLabel::Draw(const char *option) {
36  TPave::AppendPad(option);
37  fExperimentLine->AppendPad(option);
38  if(fExposure>0)
39  fExposureLine->AppendPad(option);
40 }
41 TString QDianaLabel::GetSecondLine() const {
42  TString DatText;
43  if(fSecondLine!="")
44  DatText=fSecondLine;
45  else if(fIsIsoExp)
46  DatText=Form("Isotopic Exposure: %4.1f kg#upointyr",fExposure);
47  else
48  DatText=Form("Exposure: %4.1f kg#upointyr",fExposure);
49  return DatText;
50 }
51 void QDianaLabel::Paint(const char *option) {
52  TPave::ConvertNDCtoPad();
53  TPave::PaintPave(fX1,fY1,fX2,fY2,GetBorderSize(),option);
55 }
57 
58  TString ExpText=fExperimentName;
59  if(fIsPrelim)
60  ExpText+=" Preliminary";
61  TString DatText = GetSecondLine();
62 
63  Double_t x1=fX1NDC;
64  Double_t y1=fY1NDC;
65  Double_t x2=fX2NDC;
66  Double_t y2=fY2NDC;
67 
68  Double_t textsize=1;
69 
70  // Create the experiment name line
71  fExperimentLine->SetText(x1,y1,ExpText);
72  TAttText::Copy(*fExperimentLine);
73  fExperimentLine->SetNDC();
74  fExperimentLine->SetTextSize(textsize);
75  fExperimentLine->SetTextFont(GetTextFont());
76 
77  // Create exposure line
78  fExposureLine->SetText(x1,y1,DatText);
79  TAttText::Copy(*fExposureLine);
80  fExposureLine->SetNDC();
81  fExposureLine->SetTextFont(GetTextFont());
82  fExposureLine->SetTextSize(.8*textsize);
83 
84  Double_t maxHeight=0,maxWidth=0;
85  // Figure the max size of the text
86  maxHeight=fExperimentLine->GetYsize();
87  maxWidth=fExperimentLine->GetXsize();
88  if(fExposure>0 || fSecondLine != ""){
89  maxHeight+=fExposureLine->GetYsize();
90  maxWidth=TMath::Max(maxWidth,fExposureLine->GetXsize());
91  }
92  Double_t tmpsize_h=0.75*(fY2-fY1)/maxHeight;
93  Double_t tmpsize_w=0.9*(fX2-fX1)/maxWidth;
94  textsize*=TMath::Min(tmpsize_h,tmpsize_w);
95 
96  fExperimentLine->SetTextSize(textsize);
97  fExposureLine->SetTextSize(.8*textsize);
98 
99  double dpx=(fX2NDC-fX1NDC)/(fX2-fX1);
100  double dpy=(fY2NDC-fY1NDC)/(fY2-fY1);
101 
102  if((GetTextAlign()/10)==1){
103  x1=.05*dpx*fExperimentLine->GetXsize()+fX1NDC;
104  x2=.05*dpx*fExperimentLine->GetXsize()+fX1NDC;
105  }
106  else if((GetTextAlign()/10)==2){
107  x2=x1=0.5*(fX1NDC+fX2NDC);
108  }
109  else{
110  x1=-.05*dpx*fExperimentLine->GetXsize()+fX2NDC;
111  x2=-.05*dpx*fExperimentLine->GetXsize()+fX2NDC;
112  }
113 
114  if(fExposure>0 || fSecondLine!=""){
115  y1=.5*(fY1NDC+fY2NDC)+.5*dpy*fExperimentLine->GetYsize();
116  y2=.5*(fY1NDC+fY2NDC)-.5*dpy*fExperimentLine->GetYsize();
117  }
118  else
119  y1=.5*(fY2NDC+fY1NDC);
120 
121  // std::cout << fExperimentLine->GetTextSize() << std::endl;
122  // std::cout << x1 << " " << y1 << " " << x2 << " " << y2 << std::endl;
123 
124  fExperimentLine->SetText(x1,y1,ExpText);
125  fExperimentLine->SetNDC();
126  fExperimentLine->SetTextColor(fExperimentColor);
127  fExperimentLine->Paint();
128  if(fExposure>0){
129  fExposureLine->SetText(x2,y2,DatText);
130  fExposureLine->SetTextColor(fDataColor);
131  fExposureLine->Paint();
132  }
133 
134 }
135 
136 
ClassImp(QDianaLabel) QDianaLabel
Definition: QDianaLabel.cc:7
virtual void PaintPrimitives()
Definition: QDianaLabel.cc:56
TString fExperimentName
Definition: QDianaLabel.hh:41
TLatex * fExposureLine
Definition: QDianaLabel.hh:57
double fExposure
Definition: QDianaLabel.hh:45
virtual ~QDianaLabel()
Definition: QDianaLabel.cc:31
QDianaLabel(double x1, double y1, double x2, double y2, int bordersize=4, const char *ExpName="DIANA", double Exposure=-1, bool isPrelim=true, const char *options="br")
TLatex * fExperimentLine
Definition: QDianaLabel.hh:55
virtual void Draw(const char *option="NDC")
Definition: QDianaLabel.cc:35
TString fSecondLine
Definition: QDianaLabel.hh:43
bool fIsPrelim
Definition: QDianaLabel.hh:47
int fExperimentColor
Definition: QDianaLabel.hh:51
bool fIsIsoExp
Definition: QDianaLabel.hh:49
virtual TString GetSecondLine() const
Definition: QDianaLabel.cc:41
virtual void Paint(const char *option)
Definition: QDianaLabel.cc:51