Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 }