ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
statsEditing.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// Edit statistics box.
4 ///
5 /// This example shows:
6 /// - how to remove a stat element from the stat box
7 /// - how to add a new one
8 ///
9 /// \macro_image
10 /// \macro_code
11 ///
12 /// \author Olivier Couet
13 
14 TCanvas *statsEditing() {
15  // Create and plot a test histogram with stats
16  TCanvas *se = new TCanvas;
17  TH1F *h = new TH1F("h","test",100,-3,3);
18  h->FillRandom("gaus",3000);
19  gStyle->SetOptStat();
20  h->Draw();
21  se->Update();
22 
23  // Retrieve the stat box
24  TPaveStats *ps = (TPaveStats*)se->GetPrimitive("stats");
25  ps->SetName("mystats");
26  TList *list = ps->GetListOfLines();
27 
28  // Remove the RMS line
29  TText *tconst = ps->GetLineWith("RMS");
30  list->Remove(tconst);
31 
32  // Add a new line in the stat box.
33  // Note that "=" is a control character
34  TLatex *myt = new TLatex(0,0,"Test = 10");
35  myt ->SetTextFont(42);
36  myt ->SetTextSize(0.04);
37  myt ->SetTextColor(kRed);
38  list->Add(myt);
39 
40  // the following line is needed to avoid that the automatic redrawing of stats
41  h->SetStats(0);
42 
43  se->Modified();
44  return se;
45 }
virtual void SetName(const char *name="")
Definition: TPave.h:84
virtual TObject * GetPrimitive(const char *name) const
Get primitive.
Definition: TPad.cxx:2753
Definition: Rtypes.h:61
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
virtual TList * GetListOfLines() const
Definition: TPaveText.h:63
The histogram statistics painter class.
Definition: TPaveStats.h:28
virtual void SetTextFont(Font_t tfont=62)
Definition: TAttText.h:59
To draw Mathematical Formula.
Definition: TLatex.h:33
Base class for several text objects.
Definition: TText.h:42
A doubly linked list.
Definition: TList.h:47
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3330
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:675
The Canvas class.
Definition: TCanvas.h:48
virtual void Add(TObject *obj)
Definition: TList.h:81
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition: TStyle.cxx:1252
virtual void SetTextColor(Color_t tcolor=1)
Definition: TAttText.h:57
virtual void SetTextSize(Float_t tsize=1)
Definition: TAttText.h:60
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2179
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8320
void Modified(Bool_t flag=1)
Definition: TPad.h:407
virtual TText * GetLineWith(const char *text) const
Get Pointer to first containing string text in this pavetext.
Definition: TPaveText.cxx:267