Logo ROOT   6.08/07
Reference Guide
statsEditing.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// \notebook
4 /// Edit statistics box.
5 ///
6 /// This example shows:
7 /// - how to remove a stat element from the stat box
8 /// - how to add a new one
9 ///
10 /// \macro_image
11 /// \macro_code
12 ///
13 /// \author Olivier Couet
14 
15 TCanvas *statsEditing() {
16  // Create and plot a test histogram with stats
17  TCanvas *se = new TCanvas;
18  TH1F *h = new TH1F("h","test",100,-3,3);
19  h->FillRandom("gaus",3000);
20  gStyle->SetOptStat();
21  h->Draw();
22  se->Update();
23 
24  // Retrieve the stat box
25  TPaveStats *ps = (TPaveStats*)se->GetPrimitive("stats");
26  ps->SetName("mystats");
27  TList *listOfLines = ps->GetListOfLines();
28 
29  // Remove the RMS line
30  TText *tconst = ps->GetLineWith("RMS");
31  listOfLines->Remove(tconst);
32 
33  // Add a new line in the stat box.
34  // Note that "=" is a control character
35  TLatex *myt = new TLatex(0,0,"Test = 10");
36  myt ->SetTextFont(42);
37  myt ->SetTextSize(0.04);
38  myt ->SetTextColor(kRed);
39  listOfLines->Add(myt);
40 
41  // the following line is needed to avoid that the automatic redrawing of stats
42  h->SetStats(0);
43 
44  se->Modified();
45  return se;
46 }
virtual void SetName(const char *name="")
Definition: TPave.h:76
Definition: Rtypes.h:61
R__EXTERN TStyle * gStyle
Definition: TStyle.h:418
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:302
TH1 * h
Definition: legend2.C:5
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:575
The histogram statistics painter class.
Definition: TPaveStats.h:20
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:51
To draw Mathematical Formula.
Definition: TLatex.h:25
Base class for several text objects.
Definition: TText.h:33
A doubly linked list.
Definition: TList.h:47
virtual TText * GetLineWith(const char *text) const
Get Pointer to first containing string text in this pavetext.
Definition: TPaveText.cxx:267
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3293
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2851
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:675
virtual TObject * GetPrimitive(const char *name) const
Get primitive.
Definition: TPad.cxx:2770
virtual TList * GetListOfLines() const
Definition: TPaveText.h:55
The Canvas class.
Definition: TCanvas.h:41
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:1257
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:49
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:52
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2183
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8101
void Modified(Bool_t flag=1)
Definition: TPad.h:399