ROOT » GRAF2D » GRAF » TPaveStats

class TPaveStats: public TPaveText


The histogram statistics painter class

A PaveStats is a PaveText to draw histogram statistics and fit parameters.

Statistics Display

The type of information shown in the histogram statistics box can be selected with:
      gStyle->SetOptStat(mode);

The "mode" has up to nine digits that can be set to on (1 or 2), off (0).

      mode = ksiourmen  (default = 000001111)
      k = 1;  kurtosis printed
      k = 2;  kurtosis and kurtosis error printed
      s = 1;  skewness printed
      s = 2;  skewness and skewness error printed
      i = 1;  integral of bins printed
      o = 1;  number of overflows printed
      u = 1;  number of underflows printed
      r = 1;  rms printed
      r = 2;  rms and rms error printed
      m = 1;  mean value printed
      m = 2;  mean and mean error values printed
      e = 1;  number of entries printed
      n = 1;  name of histogram is printed

For example:

      gStyle->SetOptStat(11);
displays only the name of histogram and the number of entries, whereas:
      gStyle->SetOptStat(1101);
displays the name of histogram, mean value and RMS.

WARNING 1: never do:

      gStyle->SetOptStat(0001111);
but instead do:
      gStyle->SetOptStat(1111);
because 0001111 will be taken as an octal number!

WARNING 2: for backward compatibility with older versions

      gStyle->SetOptStat(1);
is taken as:
      gStyle->SetOptStat(1111)
To print only the name of the histogram do:
      gStyle->SetOptStat(1000000001);

NOTE that in case of 2D histograms, when selecting only underflow (10000) or overflow (100000), the statistics box will show all combinations of underflow/overflows and not just one single number.

The parameter mode can be any combination of the letters kKsSiourRmMen

      k :  kurtosis printed
      K :  kurtosis and kurtosis error printed
      s :  skewness printed
      S :  skewness and skewness error printed
      i :  integral of bins printed
      o :  number of overflows printed
      u :  number of underflows printed
      r :  rms printed
      R :  rms and rms error printed
      m :  mean value printed
      M :  mean value mean error values printed
      e :  number of entries printed
      n :  name of histogram is printed

For example, to print only name of histogram and number of entries do:

      gStyle->SetOptStat("ne");

To print only the name of the histogram do:

      gStyle->SetOptStat("n");

The default value is:

      gStyle->SetOptStat("nemr");

When a histogram is painted, a TPaveStats object is created and added to the list of functions of the histogram. If a TPaveStats object already exists in the histogram list of functions, the existing object is just updated with the current histogram parameters.

Once a histogram is painted, the statistics box can be accessed using h->FindObject("stats"). In the command line it is enough to do:

      Root > h->Draw()
      Root > TPaveStats *st = (TPaveStats*)h->FindObject("stats")

because after h->Draw() the histogram is automatically painted. But in a script file the painting should be forced using gPad->Update() in order to make sure the statistics box is created:

      h->Draw();
      gPad->Update();
      TPaveStats *st = (TPaveStats*)h->FindObject("stats");

Without gPad->Update() the line h->FindObject("stats") returns a null pointer.

When a histogram is drawn with the option "SAME", the statistics box is not drawn. To force the statistics box drawing with the option "SAME", the option "SAMES" must be used. If the new statistics box hides the previous statistics box, one can change its position with these lines ("h" being the pointer to the histogram):

      Root > TPaveStats *st = (TPaveStats*)h->FindObject("stats")
      Root > st->SetX1NDC(newx1); //new x start position
      Root > st->SetX2NDC(newx2); //new x end position

To change the type of information for an histogram with an existing TPaveStats one should do:

      st->SetOptStat(mode);
Where "mode" has the same meaning than when calling gStyle->SetOptStat(mode) (see above).

One can delete the statistics box for a histogram TH1* h with:

      h->SetStats(0)

and activate it again with:

      h->SetStats(1).

Fit Statistics

The type of information about fit parameters printed in the histogram statistics box can be selected via the parameter mode. The parameter mode can be = pcev (default = 0111)
      p = 1;  print Probability
      c = 1;  print Chisquare/Number of degrees of freedom
      e = 1;  print errors (if e=1, v must be 1)
      v = 1;  print name/values of parameters
Example:
      gStyle->SetOptFit(1011);
print fit probability, parameter names/values and errors.
  1. When "v" = 1 is specified, only the non-fixed parameters are shown.
  2. When "v" = 2 all parameters are shown.
Note: gStyle->SetOptFit(1) means "default value", so it is equivalent to gStyle->SetOptFit(111)

Statistics box editing

The following example show how to remove and add a line in a statistics box.
output of htmldoc/MACRO_TPaveStats_1.gif
TCanvas *statsEditing() {
// This example shows:
//    - how to remove a stat element from the stat box
//    - how to add a new one
//
//  Author: Olivier Couet

   // Create and plot a test histogram with stats
   TCanvas *se = new TCanvas;
   TH1F *h = new TH1F("h","test",100,-3,3);
   h->FillRandom("gaus",3000);
   gStyle->SetOptStat();
   h->Draw();
   se->Update();

   // Retrieve the stat box
   TPaveStats *ps = (TPaveStats*)se->GetPrimitive("stats");
   ps->SetName("mystats");
   TList *list = ps->GetListOfLines();

   // Remove the RMS line
   TText *tconst = ps->GetLineWith("RMS");
   list->Remove(tconst);

   // Add a new line in the stat box.
   // Note that "=" is a control character
   TLatex *myt = new TLatex(0,0,"Test = 10");
   myt ->SetTextFont(42);
   myt ->SetTextSize(0.04);
   myt ->SetTextColor(kRed);
   list->Add(myt);

   // the following line is needed to avoid that the automatic redrawing of stats
   h->SetStats(0);

   se->Modified();
   return se;
}
 

Function Members (Methods)

public:
virtual~TPaveStats()
voidTObject::AbstractMethod(const char* method) const
virtual TBox*AddBox(Double_t, Double_t, Double_t, Double_t)
virtual TLine*AddLine(Double_t, Double_t, Double_t, Double_t)
virtual TText*TPaveText::AddText(const char* label)
virtual TText*TPaveText::AddText(Double_t x1, Double_t y1, const char* label)
virtual voidTObject::AppendPad(Option_t* option = "")
virtual voidTObject::Browse(TBrowser* b)
static TClass*Class()
virtual const char*TObject::ClassName() const
virtual voidTPaveText::Clear(Option_t* option = "")MENU
virtual TObject*TObject::Clone(const char* newname = "") const
virtual Int_tTObject::Compare(const TObject* obj) const
virtual voidTPave::ConvertNDCtoPad()
virtual voidTPave::Copy(TObject& pave) const
virtual voidTObject::Delete(Option_t* option = "")MENU
virtual voidDeleteText()
Int_tTAttLine::DistancetoLine(Int_t px, Int_t py, Double_t xp1, Double_t yp1, Double_t xp2, Double_t yp2)
virtual Int_tTPave::DistancetoPrimitive(Int_t px, Int_t py)
virtual voidTPaveText::Draw(Option_t* option = "")
virtual TBox*TBox::DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
virtual voidTObject::DrawClass() constMENU
virtual TObject*TObject::DrawClone(Option_t* option = "") constMENU
virtual voidTPaveText::DrawFile(const char* filename, Option_t* option = "")
virtual voidTPave::DrawPave(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Int_t bordersize = 4, Option_t* option = "br")
virtual voidTObject::Dump() constMENU
virtual voidEditText()
virtual voidTObject::Error(const char* method, const char* msgfmt) const
virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0)
virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0)
virtual voidTPave::ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual voidTObject::Fatal(const char* method, const char* msgfmt) const
virtual TObject*TObject::FindObject(const char* name) const
virtual TObject*TObject::FindObject(const TObject* obj) const
virtual Rectangle_tTBox::GetBBox()
virtual TPointTBox::GetBBoxCenter()
Int_tTPave::GetBorderSize() const
Double_tTPave::GetCornerRadius() const
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
virtual Color_tTAttFill::GetFillColor() const
virtual Style_tTAttFill::GetFillStyle() const
virtual const char*GetFitFormat() const
virtual const char*TObject::GetIconName() const
const char*TPaveText::GetLabel() const
virtual TText*TPaveText::GetLine(Int_t number) const
virtual Color_tTAttLine::GetLineColor() const
virtual Style_tTAttLine::GetLineStyle() const
virtual Width_tTAttLine::GetLineWidth() const
virtual TText*TPaveText::GetLineWith(const char* text) const
virtual TList*TPaveText::GetListOfLines() const
Float_tTPaveText::GetMargin() const
virtual Option_t*TPave::GetName() const
virtual TObject*TPaveText::GetObject(Double_t& ymouse, Double_t& yobj) const
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
static Bool_tTObject::GetObjectStat()
Int_tGetOptFit() const
virtual Option_t*TPave::GetOption() const
Int_tGetOptStat() const
TObject*GetParent() const
Int_tTPave::GetShadowColor() const
virtual Int_tTPaveText::GetSize() const
virtual const char*GetStatFormat() const
virtual Short_tTAttText::GetTextAlign() const
virtual Float_tTAttText::GetTextAngle() const
virtual Color_tTAttText::GetTextColor() const
virtual Font_tTAttText::GetTextFont() const
virtual Float_tTAttText::GetTextSize() const
virtual const char*TObject::GetTitle() const
virtual UInt_tTObject::GetUniqueID() const
Double_tTBox::GetX1() const
Double_tTPave::GetX1NDC() const
Double_tTBox::GetX2() const
Double_tTPave::GetX2NDC() const
Double_tTBox::GetY1() const
Double_tTPave::GetY1NDC() const
Double_tTBox::GetY2() const
Double_tTPave::GetY2NDC() const
virtual Bool_tTObject::HandleTimer(TTimer* timer)
virtual ULong_tTPave::Hash() const
virtual voidTBox::HideToolTip(Int_t event)
virtual voidTObject::Info(const char* method, const char* msgfmt) const
virtual Bool_tTObject::InheritsFrom(const char* classname) const
virtual Bool_tTObject::InheritsFrom(const TClass* cl) const
virtual voidInsertLine()
virtual voidInsertText(const char*)
virtual voidTObject::Inspect() constMENU
voidTObject::InvertBit(UInt_t f)
virtual TClass*IsA() const
Bool_tTBox::IsBeingResized() const
virtual Bool_tTObject::IsEqual(const TObject* obj) const
virtual Bool_tTObject::IsFolder() const
virtual Int_tTBox::IsInside(Double_t x, Double_t y) const
Bool_tTObject::IsOnHeap() const
virtual Bool_tTPave::IsSortable() const
virtual Bool_tTAttFill::IsTransparent() const
Bool_tTObject::IsZombie() const
virtual voidTPave::ls(Option_t* option = "") const
voidTObject::MayNotUse(const char* method) const
virtual voidTAttLine::Modify()
virtual Bool_tTObject::Notify()
voidTObject::Obsolete(const char* method, const char* asOfVers, const char* removedFromVers) const
voidTObject::operator delete(void* ptr)
voidTObject::operator delete(void* ptr, void* vp)
voidTObject::operator delete[](void* ptr)
voidTObject::operator delete[](void* ptr, void* vp)
void*TObject::operator new(size_t sz)
void*TObject::operator new(size_t sz, void* vp)
void*TObject::operator new[](size_t sz)
void*TObject::operator new[](size_t sz, void* vp)
TPaveStats&operator=(const TPaveStats&)
virtual voidPaint(Option_t* option = "")
virtual voidTBox::PaintBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Option_t* option = "")
virtual voidTPave::PaintPave(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Int_t bordersize = 4, Option_t* option = "br")
virtual voidTPave::PaintPaveArc(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Int_t bordersize = 4, Option_t* option = "br")
virtual voidTPaveText::PaintPrimitives(Int_t mode)
virtual voidTObject::Pop()
virtual voidTPaveText::Print(Option_t* option = "") const
virtual Int_tTObject::Read(const char* name)
virtual voidReadFile(const char*, Option_t*, Int_t, Int_t)
virtual voidTObject::RecursiveRemove(TObject* obj)
virtual voidTAttFill::ResetAttFill(Option_t* option = "")
virtual voidTAttLine::ResetAttLine(Option_t* option = "")
virtual voidTAttText::ResetAttText(Option_t* toption = "")
voidTObject::ResetBit(UInt_t f)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidTAttFill::SaveFillAttributes(ostream& out, const char* name, Int_t coldef = 1, Int_t stydef = 1001)
virtual voidTAttLine::SaveLineAttributes(ostream& out, const char* name, Int_t coldef = 1, Int_t stydef = 1, Int_t widdef = 1)
virtual voidTPaveText::SaveLines(ostream& out, const char* name)
virtual voidSavePrimitive(ostream& out, Option_t* option = "")
virtual voidSaveStyle()MENU
virtual voidTAttText::SaveTextAttributes(ostream& out, const char* name, Int_t alidef = 12, Float_t angdef = 0, Int_t coldef = 1, Int_t fondef = 61, Float_t sizdef = 1)
virtual voidSetAllWith(const char*, Option_t*, Double_t)
virtual voidTBox::SetBBoxCenter(const TPoint& p)
virtual voidTBox::SetBBoxCenterX(const Int_t x)
virtual voidTBox::SetBBoxCenterY(const Int_t y)
virtual voidTBox::SetBBoxX1(const Int_t x)
virtual voidTBox::SetBBoxX2(const Int_t x)
virtual voidTBox::SetBBoxY1(const Int_t y)
virtual voidTBox::SetBBoxY2(const Int_t y)
voidTObject::SetBit(UInt_t f)
voidTObject::SetBit(UInt_t f, Bool_t set)
virtual voidTPave::SetBorderSize(Int_t bordersize = 4)MENU
virtual voidTPave::SetCornerRadius(Double_t rad = 0.20000000000000001)MENU
virtual voidTObject::SetDrawOption(Option_t* option = "")MENU
static voidTObject::SetDtorOnly(void* obj)
virtual voidTAttFill::SetFillAttributes()MENU
virtual voidTAttFill::SetFillColor(Color_t fcolor)
virtual voidTAttFill::SetFillColorAlpha(Color_t fcolor, Float_t falpha)
virtual voidTAttFill::SetFillStyle(Style_t fstyle)
virtual voidSetFitFormat(const char* format = "5.4g")MENU
virtual voidTPaveText::SetLabel(const char* label)MENU
virtual voidTAttLine::SetLineAttributes()MENU
virtual voidTAttLine::SetLineColor(Color_t lcolor)
virtual voidTAttLine::SetLineColorAlpha(Color_t lcolor, Float_t lalpha)
virtual voidTAttLine::SetLineStyle(Style_t lstyle)
virtual voidTAttLine::SetLineWidth(Width_t lwidth)
virtual voidSetMargin(Float_t)
virtual voidTPave::SetName(const char* name = "")MENU
static voidTObject::SetObjectStat(Bool_t stat)
voidSetOptFit(Int_t fit = 1)MENU
virtual voidTPave::SetOption(Option_t* option = "br")
voidSetOptStat(Int_t stat = 1)MENU
voidSetParent(TObject* obj)
virtual voidTPave::SetShadowColor(Int_t color)MENU
virtual voidSetStatFormat(const char* format = "6.4g")MENU
virtual voidTAttText::SetTextAlign(Short_t align = 11)
virtual voidTAttText::SetTextAngle(Float_t tangle = 0)MENU
virtual voidTAttText::SetTextAttributes()MENU
virtual voidTAttText::SetTextColor(Color_t tcolor = 1)
virtual voidTAttText::SetTextColorAlpha(Color_t tcolor, Float_t talpha)
virtual voidTAttText::SetTextFont(Font_t tfont = 62)
virtual voidTAttText::SetTextSize(Float_t tsize = 1)
virtual voidTAttText::SetTextSizePixels(Int_t npixels)
virtual voidTBox::SetToolTipText(const char* text, Long_t delayms = 1000)
virtual voidTObject::SetUniqueID(UInt_t uid)
virtual voidTPave::SetX1(Double_t x1)
virtual voidTPave::SetX1NDC(Double_t x1)
virtual voidTPave::SetX2(Double_t x2)
virtual voidTPave::SetX2NDC(Double_t x2)
virtual voidTPave::SetY1(Double_t y1)
virtual voidTPave::SetY1NDC(Double_t y1)
virtual voidTPave::SetY2(Double_t y2)
virtual voidTPave::SetY2NDC(Double_t y2)
virtual voidShowMembers(TMemberInspector& insp) const
virtual voidStreamer(TBuffer&)
voidStreamerNVirtual(TBuffer& ClassDef_StreamerNVirtual_b)
virtual voidTObject::SysError(const char* method, const char* msgfmt) const
Bool_tTObject::TestBit(UInt_t f) const
Int_tTObject::TestBits(UInt_t f) const
TPaveStats()
TPaveStats(const TPaveStats&)
TPaveStats(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Option_t* option = "br")
virtual voidUseCurrentStyle()
virtual voidTObject::Warning(const char* method, const char* msgfmt) const
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0)
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const
protected:
virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const
voidTObject::MakeZombie()

Data Members

public:
static TObject::(anonymous)TObject::kBitMask
static TObject::EStatusBitsTObject::kCanDelete
static TBox::(anonymous)TBox::kCannotMove
static TObject::EStatusBitsTObject::kCannotPick
static TObject::EStatusBitsTObject::kHasUUID
static TObject::EStatusBitsTObject::kInvalidObject
static TObject::(anonymous)TObject::kIsOnHeap
static TObject::EStatusBitsTObject::kIsReferenced
static TObject::EStatusBitsTObject::kMustCleanup
static TPave::(anonymous)TPave::kNameIsAction
static TObject::EStatusBitsTObject::kNoContextMenu
static TObject::(anonymous)TObject::kNotDeleted
static TObject::EStatusBitsTObject::kObjInCanvas
static TObject::(anonymous)TObject::kOverwrite
static TObject::(anonymous)TObject::kSingleKey
static TObject::(anonymous)TObject::kWriteDelete
static TObject::(anonymous)TObject::kZombie
protected:
Int_tTPave::fBorderSizewindow box bordersize in pixels
Double_tTPave::fCornerRadiusCorner radius in case of option arc
Color_tTAttFill::fFillColorfill area color
Style_tTAttFill::fFillStylefill area style
TStringfFitFormatPrinting format for fit parameters
Int_tTPave::fInit(=0 if transformation to NDC not yet done)
TStringTPaveText::fLabelLabel written at the top of the pavetext
Color_tTAttLine::fLineColorline color
Style_tTAttLine::fLineStyleline style
Width_tTAttLine::fLineWidthline width
TList*TPaveText::fLinesList of labels
Int_tTPaveText::fLongestLength of the longest line
Float_tTPaveText::fMarginText margin
TStringTPave::fNamePave name
Int_tfOptFitoption Fit
Int_tfOptStatoption Stat
TStringTPave::fOptionPave style
TObject*fParentowner of this TPaveStats
Bool_tTBox::fResizing!True if box is being resized
Int_tTPave::fShadowColorColor of the pave's shadow
TStringfStatFormatPrinting format for stats
Short_tTAttText::fTextAlignText alignment
Float_tTAttText::fTextAngleText angle
Color_tTAttText::fTextColorText color index
Font_tTAttText::fTextFontText font number
Float_tTAttText::fTextSizeText size
Double_tTBox::fX1X of 1st point
Double_tTPave::fX1NDCX1 point in NDC coordinates
Double_tTBox::fX2X of 2nd point
Double_tTPave::fX2NDCX2 point in NDC coordinates
Double_tTBox::fY1Y of 1st point
Double_tTPave::fY1NDCY1 point in NDC coordinates
Double_tTBox::fY2Y of 2nd point
Double_tTPave::fY2NDCY2 point in NDC coordinates

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

TPaveStats()
   TPaveStats default constructor.
   
 
TPaveStats(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Option_t* option = "br")
   TPaveStats normal constructor.
   
 
~TPaveStats()
   TPaveStats default destructor.
   
 
Int_t GetOptFit() const
   Return the fit option.
   
 
Int_t GetOptStat() const
   Return the stat option.
   
 
void SaveStyle()
   Save This TPaveStats options in current style.
   
 
void SetFitFormat(const char* format = "5.4g")
   Change (i.e. set) the format for printing fit parameters in statistics box.
   
 
void SetOptFit(Int_t fit = 1)
   Set the fit option.
   
 
void SetOptStat(Int_t stat = 1)
   Set the stat option.
   
 
void SetStatFormat(const char* format = "6.4g")
   Change (i.e. set) the format for printing statistics.
   
 
void Paint(Option_t* option = "")
   Paint the pave stat.
   
 
void SavePrimitive(ostream& out, Option_t* option = "")
   Save primitive as a C++ statement(s) on output stream out.
   
 
void Streamer(TBuffer& )
   Stream an object of class TPaveStats.
   
 
void UseCurrentStyle()
   Replace current attributes by current style.
   
 
TPaveStats()
TBox * AddBox(Double_t , Double_t , Double_t , Double_t )
{return 0;}
TLine * AddLine(Double_t , Double_t , Double_t , Double_t )
{return 0;}
void DeleteText()
{ }
void EditText()
{ }
const char * GetFitFormat() const
{return fFitFormat.Data();}
const char * GetStatFormat() const
{return fStatFormat.Data();}
TObject * GetParent() const
{return fParent;}
void InsertText(const char* )
{ }
void InsertLine()
{ }
void ReadFile(const char* , Option_t* , Int_t , Int_t )
{ }
void SetAllWith(const char* , Option_t* , Double_t )
{ }
void SetMargin(Float_t )
{ }
void SetParent(TObject* obj)
{fParent = obj;}