Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
hist060_TH1_stats.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_hist
3/// \notebook
4/// \preview 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/// \date August 2016
14/// \author Olivier Couet
15
16void hist060_TH1_stats()
17{
18 // Create and plot a test histogram with stats
19 TCanvas *se = new TCanvas;
20 TH1F *h = new TH1F("h", "test", 100, -3, 3);
21 h->FillRandom("gaus", 3000);
22 gStyle->SetOptStat();
23 h->Draw();
24 se->Update();
25
26 // Retrieve the stat box
27 TPaveStats *ps = (TPaveStats *)se->GetPrimitive("stats");
28 ps->SetName("mystats");
29 TList *listOfLines = ps->GetListOfLines();
30
31 // Remove the RMS line
32 TText *tconst = ps->GetLineWith("RMS");
33 listOfLines->Remove(tconst);
34
35 // Add a new line in the stat box.
36 // Note that "=" is a control character
37 TLatex *myt = new TLatex(0, 0, "Test = 10");
38 myt->SetTextFont(42);
39 myt->SetTextSize(0.04);
40 myt->SetTextColor(kRed);
41 listOfLines->Add(myt);
42
43 // the following line is needed to avoid that the automatic redrawing of stats
44 h->SetStats(0);
45
46 se->Modified();
47}
#define h(i)
Definition RSha256.hxx:106
@ kRed
Definition Rtypes.h:67
externTStyle * gStyle
Definition TStyle.h:442
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:50
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:52
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:53
The Canvas class.
Definition TCanvas.h:23
void Update() override
Update canvas pad buffers.
Definition TCanvas.cxx:2486
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:878
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:952
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
Definition TPad.cxx:7351
TObject * GetPrimitive(const char *name) const override
Get primitive.
Definition TPad.cxx:3010
virtual TList * GetListOfLines() const
Definition TPaveText.h:48
virtual TText * GetLineWith(const char *text) const
virtual void SetName(const char *name="")
Definition TPave.h:81
Definition TText.h:22