# Can't access the "status" box of TGraph

**URL:** <https://root-forum.cern.ch/t/cant-access-the-status-box-of-tgraph/18939>\
**Category:** Roofit and RooStats\
**Created:** [March 10, 2015, 5:23pm UTC](https://root-forum.cern.ch/t/cant-access-the-status-box-of-tgraph/18939 "2015-03-10T17:23:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![junhui.private](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/779978/32.png) [@junhui.private](https://root-forum.cern.ch/u/junhui.private)\
**Post date:** [March 10, 2015, 5:23pm UTC](https://root-forum.cern.ch/t/cant-access-the-status-box-of-tgraph/18939/1 "2015-03-10T17:23:21Z")

</div>

Hi,

It’s weird that I can’t access the “status” box of a TGraph.  
Though an almost same line is shown in this link : [root.cern.ch/root/roottalk/roottalk02/2843.html](https://root.cern.ch/root/roottalk/roottalk02/2843.html).

My code is like this :

```auto
TCanvas, c1, definition;
TGraph, gr, definition ; 
A linear fit to the data of TGraph;
gPad->Modified();
gPad->Updated();
TPaveStats *Lccd_st = (TPaveStats*)gr->GetListOfFunctions()->FindObject("stats");
```

The error message is  
" Error: illegal pointer to class object Lccd\_st 0x0 3161 "

Could any people have a comment please ?

Thanks !

Best,  
Junhui

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 10, 2015, 6:03pm UTC](https://root-forum.cern.ch/t/cant-access-the-status-box-of-tgraph/18939/2 "2015-03-10T18:03:13Z")

</div>

I’m afraid we need a simple macro which reproduces your problem (the “error message” that you show does not come from the “code” that you show).  
BTW. I assume that after you execute “gPad-\>Update();”, you do see the “statistics box” displayed. If not, make sure that you execute “gStyle-\>SetOptFit(1);” before you try to fit your graph.

---

<div class="post-metadata">

**Author:** ![junhui.private](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/779978/32.png) [@junhui.private](https://root-forum.cern.ch/u/junhui.private)\
**Post date:** [March 10, 2015, 8:39pm UTC](https://root-forum.cern.ch/t/cant-access-the-status-box-of-tgraph/18939/3 "2015-03-10T20:39:21Z")

</div>

Hi, Wile,

You got it !  
After being added the line of “gStyle-\>SetOptFit(1)”, it worked well.

However, another problem arises, ☹ .  
I’d like to add some fit results to the statistical box.  
The problem is, I can’t put it into the box although I can print the results on my screen.  
At the same time, there is no any error displayed either when running it.  
It just can’t display the stuffs.

The code as following is coped from a TH1 version which works perfectly.  
The only line I’ve commented is " ///gr-\>GetListOfFunctions()-\>SetStats(0);"  
I commented because if I keep it, my script can’t pass compiling.

Do you have any comments ?  
Thanks !

Best,  
Junhui

```auto
              gStyle->SetOptFit(1);
              TF1 *pol1_LCCD = new TF1("pol1","pol1",0,maxColumn);
              gr->Fit(pol1_LCCD,"R");
              gPad->Modified();
              gPad->Update(); // make sure it's (re)drawn

              TPaveStats *Lccd_st = (TPaveStats*)(gr->GetListOfFunctions()->FindObject("stats"));
              Lccd_st->SetOptFit(1);
              gPad->Modified();
              gPad->Update(); // make sure it's (re)drawn
              Lccd_st->SetX1NDC(0.7);
              Lccd_st->SetX2NDC(0.99);
              Lccd_st->SetY1NDC(0.2);
              Lccd_st->SetY2NDC(0.5);

              Lccd_st->SetName("mystatus");
              ///gr->GetListOfFunctions()->SetStats(0);

              TList *list = Lccd_st->GetListOfLines();
              TLatex *myt = new TLatex(0,0,TString::Format("CTI = %g", pol1_LCCD->GetParameter("p1") / pol1_LCCD->GetParameter("p0")));
              cout << endl << "CTI =" << pol1_LCCD->GetParameter("p1") / pol1_LCCD->GetParameter("p0") << endl;
              myt->SetTextFont(42);
              myt->SetTextSize(0.04);
              myt->SetTextColor(kRed);
              list->Add(myt);

              gPad->Modified();
              gPad->Update(); // make sure it's (re)drawn

```

---

<div class="post-metadata">

**Author:** ![junhui.private](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/779978/32.png) [@junhui.private](https://root-forum.cern.ch/u/junhui.private)\
**Post date:** [March 10, 2015, 10:43pm UTC](https://root-forum.cern.ch/t/cant-access-the-status-box-of-tgraph/18939/4 "2015-03-10T22:43:57Z")

</div>

Hi, Wile,

Also, I realized actually in TGraph, one can’t displaying similarly as in a histogram by calling “gStyle-\>SetOptStat(000001111);”(In my script, this line is right after the line of “gStyle-\>SetOptFit(1);” ) .  
There is no error too.

TGraph itself has no classes of “SetOptStat()”, [root.cern.ch/root/html/TGraph.html](https://root.cern.ch/root/html/TGraph.html) .  
But gStyle has, [root.cern.ch/root/html/TStyle.html](https://root.cern.ch/root/html/TStyle.html), Why can’t work neither ?

Thanks !

Best,  
Junhui

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 10, 2015, 11:55pm UTC](https://root-forum.cern.ch/t/cant-access-the-status-box-of-tgraph/18939/5 "2015-03-10T23:55:29Z")

</div>

Try:

```cpp
// ...
Lccd_st->SetName("mystatus"); // actually, you do not need it
gr->GetListOfFunctions()->Remove(Lccd_st); Lccd_st->Draw();
//...

```

P.S. Note that the [TStyle::SetOptStat](https://root.cern.ch/root/html534/TStyle.html#TStyle:SetOptStat) method is relevant for histograms only (see also the [TH1::SetStats](https://root.cern.ch/root/html534/TH1.html#TH1:SetStats) method).

---

<div class="post-metadata">

**Author:** ![junhui.private](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/779978/32.png) [@junhui.private](https://root-forum.cern.ch/u/junhui.private)\
**Post date:** [March 11, 2015, 2:59am UTC](https://root-forum.cern.ch/t/cant-access-the-status-box-of-tgraph/18939/6 "2015-03-11T02:59:49Z")

</div>

![](https://root-forum.cern.ch/uploads/default/original/2X/6/62bb1735b26536010454e2f8398c623e362ef77d.png)  
Hi, Wile,

Thanks, you got it again !

However, there is another small problem : two statistical boxes appeared.  
As the attached plot.

I figured out a “dirty” way to get rid of the upper one which is commenting the four lines of Lccd\_st-\>SetNDC to overlap two boxes.  
Do you have an alternative way to kill the upper statistical box ?

Thanks !

Best,  
Junhui

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 11, 2015, 8:53am UTC](https://root-forum.cern.ch/t/cant-access-the-status-box-of-tgraph/18939/7 "2015-03-11T08:53:33Z")

</div>

Try (I’m not sure if this is the right way, though):

```cpp
gr->GetListOfFunctions()->Remove(Lccd_st); gStyle->SetOptFit(0); Lccd_st->Draw();

```

---

<div class="post-metadata">

**Author:** ![junhui.private](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/779978/32.png) [@junhui.private](https://root-forum.cern.ch/u/junhui.private)\
**Post date:** [March 11, 2015, 4:17pm UTC](https://root-forum.cern.ch/t/cant-access-the-status-box-of-tgraph/18939/8 "2015-03-11T16:17:31Z")

</div>

Hi, Wile,

You made it !  
Thanks !

Best,  
Junhui
