220 const UInt_t kTakeStyle = BIT(17); 
 
  225 TPaveStats::TPaveStats(): TPaveText()
 
  228    fOptFit  = gStyle->GetOptFit();
 
  229    fOptStat = gStyle->GetOptStat();
 
  235 TPaveStats::TPaveStats(Double_t x1, Double_t y1,Double_t x2, Double_t  y2, Option_t *option)
 
  236            :TPaveText(x1,y1,x2,y2,option)
 
  239    fOptFit  = gStyle->GetOptFit();
 
  240    fOptStat = gStyle->GetOptStat();
 
  241    SetFitFormat(gStyle->GetFitFormat());
 
  242    SetStatFormat(gStyle->GetStatFormat());
 
  248 TPaveStats::~TPaveStats()
 
  250    if ( fParent && !fParent->TestBit(kInvalidObject)) fParent->RecursiveRemove(
this);
 
  256 Int_t TPaveStats::GetOptFit()
 const 
  258    if (TestBit(kTakeStyle)) 
return gStyle->GetOptFit();
 
  265 Int_t TPaveStats::GetOptStat()
 const 
  267    if (TestBit(kTakeStyle)) 
return gStyle->GetOptStat();
 
  274 void TPaveStats::SaveStyle()
 
  276    gStyle->SetOptFit(fOptFit);
 
  277    gStyle->SetOptStat(fOptStat);
 
  278    gStyle->SetFitFormat(fFitFormat.Data());
 
  279    gStyle->SetStatFormat(fStatFormat.Data());
 
  285 void TPaveStats::SetFitFormat(
const char *form)
 
  293 void TPaveStats::SetOptFit(Int_t fit)
 
  296    ResetBit(kTakeStyle);
 
  302 void TPaveStats::SetOptStat(Int_t stat)
 
  305    ResetBit(kTakeStyle);
 
  311 void TPaveStats::SetStatFormat(
const char *form)
 
  319 void TPaveStats::Paint(Option_t *option)
 
  321    TPave::ConvertNDCtoPad();
 
  322    TPave::PaintPave(fX1,fY1,fX2,fY2,GetBorderSize(),option);
 
  326    Double_t y2ref = TMath::Max(fY1,fY2);
 
  327    Double_t x1ref = TMath::Min(fX1,fX2);
 
  328    Double_t x2ref = TMath::Max(fX1,fX2);
 
  329    Double_t dx    = TMath::Abs(fX2 - fX1);
 
  330    Double_t dy    = TMath::Abs(fY2 - fY1);
 
  331    Double_t titlesize=0;
 
  332    Double_t textsize = GetTextSize();
 
  333    Int_t nlines = GetSize();
 
  334    if (nlines == 0) nlines = 5;
 
  335    Int_t print_name = fOptStat%10;
 
  338    Double_t y1       = gPad->GetY1();
 
  339    Double_t y2       = gPad->GetY2();
 
  340    Float_t margin    = fMargin*dx;
 
  341    Double_t yspace   = dy/Double_t(nlines);
 
  342    Double_t textsave = textsize;
 
  344    TLatex *latex, *latex_tok;
 
  346    Double_t longest = 0, titlelength = 0;
 
  350       textsize = 0.92*yspace/(y2 - y1);
 
  351       titlesize = textsize;
 
  352       wtok[0] = 0; wtok[1] = 0;
 
  353       while ((line = (TObject*) next())) {
 
  354          if (line->IsA() == TLatex::Class()) {
 
  355             latex = (TLatex*)line;
 
  356             Int_t nchs = strlen(latex->GetTitle());
 
  357             sl = 
new char[nchs+1];
 
  358             strlcpy(sl, latex->GetTitle(),nchs+1);
 
  359             if (strpbrk(sl, 
"=") !=0 && print_name == 0) {
 
  360                st = strtok(sl, 
"=");
 
  363                   latex_tok = 
new TLatex(0.,0.,st);
 
  364                   Style_t tfont = latex->GetTextFont();
 
  365                   if (tfont == 0) tfont = GetTextFont();
 
  366                   latex_tok->SetTextFont(tfont);
 
  367                   latex_tok->SetTextSize(textsize);
 
  368                   w = latex_tok->GetXsize();
 
  369                   if (w > wtok[itok]) wtok[itok] = w;
 
  374             } 
else if (strpbrk(sl, 
"|") !=0) {
 
  377                Style_t tfont = latex->GetTextFont();
 
  378                if (tfont == 0) latex->SetTextFont(GetTextFont());
 
  379                latex->SetTextSize(titlesize);
 
  380                titlelength = latex->GetXsize()+2.*margin;
 
  381                if (titlelength > 0.98*dx) titlesize *= 0.98*dx/titlelength;
 
  382                latex->SetTextFont(tfont);
 
  384             delete [] sl; sl = 0;
 
  387       longest = wtok[0]+wtok[1]+2.*margin;
 
  388       if (longest > 0.98*dx) textsize *= 0.98*dx/longest;
 
  389       SetTextSize(textsize);
 
  391       titlesize = textsize;
 
  393    Double_t ytext = y2ref + 0.5*yspace;
 
  395    print_name = fOptStat%10;
 
  400    while ((line = (TObject*) next())) {
 
  401       if (line->IsA() == TLatex::Class()) {
 
  402          latex = (TLatex*)line;
 
  404          Double_t xl    = latex->GetX();
 
  405          Double_t yl    = latex->GetY();
 
  406          Short_t talign = latex->GetTextAlign();
 
  407          Color_t tcolor = latex->GetTextColor();
 
  408          Style_t tfont  = latex->GetTextFont();
 
  409          Size_t  tsize  = latex->GetTextSize();
 
  410          if (tcolor == 0) latex->SetTextColor(GetTextColor());
 
  411          if (tfont  == 0) latex->SetTextFont(GetTextFont());
 
  412          if (tsize  == 0) latex->SetTextSize(GetTextSize());
 
  414          Int_t nchs = strlen(latex->GetTitle());
 
  415          sl = 
new char[nchs+1];
 
  416          strlcpy(sl, latex->GetTitle(),nchs+1);
 
  418          if (strpbrk(sl, 
"=") !=0 && print_name == 0) {
 
  419             st = strtok(sl, 
"=");
 
  423                latex->SetTextAlign(halign);
 
  424                if (halign == 12) xtext = x1ref + margin;
 
  426                   xtext = x2ref - margin;
 
  427                   typolabel = typolabel.Strip();
 
  428                   typolabel.ReplaceAll(
"-",
"#minus");
 
  430                latex->PaintLatex(xtext,ytext,latex->GetTextAngle(),
 
  431                                              latex->GetTextSize(),
 
  437          } 
else if (strpbrk(sl, 
"|") !=0) {
 
  438             Double_t yline1 = ytext+yspace/2.;
 
  439             Double_t yline2 = ytext-yspace/2.;
 
  440             Double_t xline1 = dx/3+x1ref;
 
  441             Double_t xline2 = 2*dx/3+x1ref;
 
  442             gPad->PaintLine(x1ref,yline1,x2ref,yline1);
 
  443             gPad->PaintLine(xline1,yline1,xline1,yline2);
 
  444             gPad->PaintLine(xline2,yline1,xline2,yline2);
 
  445             st = strtok(sl, 
"|");
 
  448                latex->SetTextAlign(22);
 
  449                if (theIndex == 0) xtext = 0.5*(x1ref+xline1);
 
  450                if (theIndex == 1) xtext = 0.5*(x1ref+x2ref);
 
  451                if (theIndex == 2) xtext = 0.5*(xline2+x2ref);
 
  453                typolabel.ReplaceAll(
"-", 
"#minus");
 
  454                latex->PaintLatex(xtext,ytext,latex->GetTextAngle(),
 
  455                                              latex->GetTextSize(),
 
  463             latex->SetTextAlign(22);
 
  464             xtext = 0.5*(x1ref+x2ref);
 
  465             latex->PaintLatex(xtext,ytext,latex->GetTextAngle(),
 
  468             gPad->PaintLine(x1ref,y2ref-yspace,x2ref,y2ref-yspace);
 
  472          latex->SetTextAlign(talign);
 
  473          latex->SetTextColor(tcolor);
 
  474          latex->SetTextFont(tfont);
 
  475          latex->SetTextSize(tsize);
 
  480    SetTextSize(textsave);
 
  483    if (fLabel.Length() > 0) {
 
  485       dy = gPad->GetY2() - gPad->GetY1();
 
  486       x1 = x1ref + 0.25*dx;
 
  487       x2 = x2ref - 0.25*dx;
 
  488       y1 = y2ref - 0.02*dy;
 
  489       y2 = y2ref + 0.02*dy;
 
  490       TPaveLabel *title = 
new TPaveLabel(x1,y1,x2,y2,fLabel.Data(),GetDrawOption());
 
  491       title->SetFillColor(GetFillColor());
 
  492       title->SetTextColor(GetTextColor());
 
  493       title->SetTextFont(GetTextFont());
 
  502 void TPaveStats::SavePrimitive(std::ostream &out, Option_t * )
 
  506    Bool_t saved = gROOT->ClassSaved(TPaveStats::Class());
 
  510       out<<
"   "<<ClassName()<<
" *";
 
  512    if (fOption.Contains(
"NDC")) {
 
  513       out<<
"ptstats = new "<<ClassName()<<
"("<<fX1NDC<<
","<<fY1NDC<<
","<<fX2NDC<<
","<<fY2NDC
 
  514       <<
","<<quote<<fOption<<quote<<
");"<<std::endl;
 
  516       out<<
"ptstats = new "<<ClassName()<<
"("<<fX1<<
","<<fY1<<
","<<fX2<<
","<<fY2
 
  517       <<
","<<quote<<fOption<<quote<<
");"<<std::endl;
 
  519    if (strcmp(GetName(),
"TPave")) {
 
  520       out<<
"   ptstats->SetName("<<quote<<GetName()<<quote<<
");"<<std::endl;
 
  522    if (fBorderSize != 4) {
 
  523       out<<
"   ptstats->SetBorderSize("<<fBorderSize<<
");"<<std::endl;
 
  525    SaveFillAttributes(out,
"ptstats",19,1001);
 
  526    SaveLineAttributes(out,
"ptstats",1,1,1);
 
  527    SaveTextAttributes(out,
"ptstats",22,0,1,62,0);
 
  528    SaveLines(out,
"ptstats",saved);
 
  529    out<<
"   ptstats->SetOptStat("<<GetOptStat()<<
");"<<std::endl;
 
  530    out<<
"   ptstats->SetOptFit("<<GetOptFit()<<
");"<<std::endl;
 
  531    out<<
"   ptstats->Draw();"<<std::endl;
 
  537 void TPaveStats::Streamer(TBuffer &R__b)
 
  539    if (R__b.IsReading()) {
 
  541       Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
 
  543          R__b.ReadClassBuffer(TPaveStats::Class(), 
this, R__v, R__s, R__c);
 
  547       TPaveText::Streamer(R__b);
 
  550       if (R__v > 1 || R__b.GetVersionOwner() == 22304) {
 
  551          fFitFormat.Streamer(R__b);
 
  552          fStatFormat.Streamer(R__b);
 
  557       R__b.CheckByteCount(R__s, R__c, TPaveStats::IsA());
 
  561       R__b.WriteClassBuffer(TPaveStats::Class(),
this);
 
  568 void TPaveStats::UseCurrentStyle()
 
  570    if (gStyle->IsReading()) {
 
  571       SetOptStat(gStyle->GetOptStat());
 
  572       SetOptFit(gStyle->GetOptFit());
 
  573       SetStatFormat(gStyle->GetStatFormat());
 
  574       SetFitFormat(gStyle->GetFitFormat());
 
  575       SetBorderSize(gStyle->GetStatBorderSize());
 
  576       SetFillColor(gStyle->GetStatColor());
 
  577       SetFillStyle(gStyle->GetStatStyle());
 
  578       SetTextFont(gStyle->GetStatFont());
 
  579       SetTextSize(gStyle->GetStatFontSize());
 
  580       SetTextColor(gStyle->GetStatTextColor());
 
  581       SetX2NDC(gStyle->GetStatX());
 
  582       SetY2NDC(gStyle->GetStatY());
 
  583       SetX1NDC(gStyle->GetStatX()-gStyle->GetStatW());
 
  584       SetY1NDC(gStyle->GetStatY()-gStyle->GetStatH());
 
  586       gStyle->SetOptStat(GetOptStat());
 
  587       gStyle->SetOptFit(GetOptFit());
 
  588       gStyle->SetStatFormat(GetStatFormat());
 
  589       gStyle->SetFitFormat(GetFitFormat());
 
  590       gStyle->SetStatBorderSize(GetBorderSize());
 
  591       gStyle->SetTextColor(GetTextColor());
 
  592       gStyle->SetStatColor(GetFillColor());
 
  593       gStyle->SetStatStyle(GetFillStyle());
 
  594       gStyle->SetTextFont(GetTextFont());
 
  595       gStyle->SetStatFontSize(GetTextSize());
 
  596       gStyle->SetStatTextColor(GetTextColor());
 
  597       gStyle->SetStatX(GetX2NDC());
 
  598       gStyle->SetStatY(GetY2NDC());
 
  599       gStyle->SetStatW(GetX2NDC()-GetX1NDC());
 
  600       gStyle->SetStatH(GetY2NDC()-GetY1NDC());