Adding text to statistics box

Hello,

I’m trying to add a new line of text to a statistics box associated to a histogram. I’m using the following code:

TPaveStats *st = (TPaveStats*)h[i]->GetListOfFunctions()->FindObject("stats"); sprintf(name, "N_sig = %.0f", Nsig); TString text_line = TString(name); st->AddText(text_line.Data()); st->Print();

Where I’ve used the last line to check whether the text is being added or not. The printout indicates that the text is being added as can be observed in the following output:

TPaveStats X1=0.658533 Y1=12210.338759 X2=2.396133 Y2=20426.641152 FillColor=19 FillStyle=1001 Text X=0.000000 Y=0.000000 Text=Entries = 402056 Font=0 Size=0.000000 Color=0 Align=0 Text X=0.000000 Y=0.000000 Text=#chi^{2} / ndf = 321.5 / 26 Font=0 Size=0.000000 Color=0 Align=0 Text X=0.000000 Y=0.000000 Text=Amp = 8142 #pm 68.2 Font=0 Size=0.000000 Color=0 Align=0 Text X=0.000000 Y=0.000000 Text=Mean = 0.2462 #pm 0.0001 Font=0 Size=0.000000 Color=0 Align=0 Text X=0.000000 Y=0.000000 Text=Sigma = 0.01855 #pm 0.00017 Font=0 Size=0.000000 Color=0 Align=0 Text X=0.000000 Y=0.000000 Text=a0 = 2678 #pm 59.5 Font=0 Size=0.000000 Color=0 Align=0 Text X=0.000000 Y=0.000000 Text=a1 = 3179 #pm 679.7 Font=0 Size=0.000000 Color=0 Align=0 Text X=0.000000 Y=0.000000 Text=a2 = -1.572e+04 #pm 1530 Font=0 Size=0.000000 Color=0 Align=0 Text X=0.000000 Y=0.000000 Text=N_sig = 36137 Font=0 Size=0.000000 Color=0 Align=0

But, when I run my code the newly added text does not appear. Could anyone please help me with this? I’m attaching my macro and root file to this post.

Thanks,
bharat211.
fit.root (15.1 KB)
mmhistsmacro.cxx (2.84 KB)

The statistics box is recreated each time the hitogram is painted. That is why the added text does not show. I can propose you the follwoing solution:

{
   TFile f("hsimple.root");
   hpx->Draw();
   gPad->Update();
   TPaveStats *st=(TPaveStats*)hpx->GetListOfFunctions()->FindObject("stats");   
   st->AddText("aaa = 33");
   st->DrawClone();
}

May be there is a btter way but I cannot think of one right now.
hsimple.root is created by $ROOTSYS/tutorials/hsimple.C

[quote=“couet”]The statistics box is recreated each time the hitogram is painted. That is why the added text does not show. I can propose you the follwoing solution:

{
   TFile f("hsimple.root");
   hpx->Draw();
   gPad->Update();
   TPaveStats *st=(TPaveStats*)hpx->GetListOfFunctions()->FindObject("stats");   
   st->AddText("aaa = 33");
   st->DrawClone();
}

May be there is a btter way but I cannot think of one right now.
hsimple.root is created by $ROOTSYS/tutorials/hsimple.C[/quote]

that worked wonderfully. Thanks. :slight_smile: