Accessing stats panel from histo

From: Jose Helder Lopes <helder_at_if.ufrj.br>
Date: Sun, 17 Feb 2008 17:29:50 -0300 (BRT)


Dear rooters,

I want to change some properties of the stat panel of a TH1F inside a macro. The following commands work interactively, with the final plot showing stat text in red:

ROOT 5.17/08 (trunk_at_21355, De 28 2007, 13:45:00 on linuxx8664gcc) CINT/ROOT C/C++ Interpreter version 5.16.27, Oct 25, 2007 Type ? for help. Commands must be C++ statements. Enclose multiple statements between { }. root [0] TH1F *hpx = new TH1F("hpx","This is the px distribution",100,-4,4);

root [1]    gRandom->SetSeed();
root [2]    for (Int_t i = 0; i < 25000; i++) hpx->Fill(gRandom->Gaus());
root [3]    hpx->Draw();

<TCanvas::MakeDefCanvas>: created default TCanvas with name c1 root [4] TPaveStats * st = (TPaveStats *)hpx->GetListOfFunctions()->FindObject("stats"); root [5] if( st ) st->SetTextColor(kRed); else std::cout << "Null pointer to TPaveStats: " << st << std::endl; root [6] hpx->Draw();

However when I put them in a macro test.C they fail:

The macro:

#include <TROOT.h>
#include <TSystem.h>
#include <TH1F.h>
#include <TRandom.h>
#include <TPaveStats.h>

#include <iostream>

void test()
{

   TH1F *hpx = new TH1F("hpx","This is the px distribution",100,-4,4);    

   // Fill histograms randomly
   gRandom->SetSeed();
   for (Int_t i = 0; i < 25000; i++) hpx->Fill(gRandom->Gaus());    hpx->Draw();
   TPaveStats * st = (TPaveStats *)hpx->GetListOfFunctions()->FindObject("stats");    if( st ) st->SetTextColor(kRed); else std::cout << "Null pointer to TPaveStats: " << st << std::endl;    hpx->Draw();
}

Executing :

ROOT 5.17/08 (trunk_at_21355, De 28 2007, 13:45:00 on linuxx8664gcc) CINT/ROOT C/C++ Interpreter version 5.16.27, Oct 25, 2007 Type ? for help. Commands must be C++ statements. Enclose multiple statements between { }. root [0] .x test.C+
Info in <TUnixSystem::ACLiC>: creating shared library /home/helder/B02MuMuKstar/R_Kstar/./test_C.so <TCanvas::MakeDefCanvas>: created default TCanvas with name c1 Null pointer to TPaveStats: 0
root [1] .q

What can be wrong?
By the way, is there a simpler way to do this? I dont like to have to do the first hpx->Draw().

Thank you for any help.
Best regards,
Helder

-- 
Jose' Helder Lopes                          Tel:(+55-21)2562-7894
Instituto de Fisica                         Fax:(+55-21)2562-7368
Universidade Federal do Rio de Janeiro      Tel. CERN:+41 22 767 6152
CP 68528   CEP 21945-970                    e-mail: helder_at_if.ufrj.br
Rio de Janeiro, RJ, Brasil                  e-mail: Helder.Lopes_at_cern.ch
Received on Sun Feb 17 2008 - 21:36:18 CET

This archive was generated by hypermail 2.2.0 : Sun Feb 17 2008 - 23:50:01 CET