Move stat box in histogram generated from Branch of TTree

Hi, I have to move stat box in histogram generated automatically from data in branch of TTree, but i don’t know how. Doing this, it doesn’t work. (pair_tree is my TTree, instead pairID is the branch)

pair_tree.Draw("pairID","","COL");
pad5 =root.TPad("pad1","pad1",0,0,1,1);
pad5.Draw()
pad5.cd()
pad5.Update()
h = pair_tree.FindObject("htemp");
h.SetX1NDC(0.)
h.SetX2NDC(0.)
h.SetY1NDC(0.)
h.SetY2NDC(0.)
pad5.Modified()
c1.cd();

Welcome to the ROOT forum.

You should change the position of the stats, the new positions you gave (all 0. by the way) are on the histogram.

see: h->FindObject("stats") here

pair_tree.Draw("pairID","","COL");
pad5 =root.TPad("pad1","pad1",0,0,1,1);
pad5.Draw()
pad5.cd()
pad5.Update()
h = pad5.FindObject("htemp")
s = h.FindObject("stats")
s.SetX1NDC(...)
s.SetX2NDC(...)
s.SetY1NDC(...)
s.SetY2NDC(...)
pad5.Update()

Hi Couet, doing in this way it doesn’t work, could I do something alse?
pair_tree.Draw(“pairID”,“”,“COL”);
pad5 =root.TPad(“pad1”,“pad1”,0,0,1,1);
pad5.Draw()
pad5.cd()
pad5.Update()
h = pad5.FindObject(“htemp”)
s = h.FindObject(“stats”)
s.SetX1NDC(0.7)
s.SetX2NDC(0.9)
s.SetY1NDC(0.65)
s.SetY2NDC(0.9)
pad5.Modified()
c1.cd();

This is the error:
s = h.FindObject(“stats”)
TypeError: none of the 2 overloaded methods succeeded. Full details:
attempt to access a null-pointer
TObject* TObject::FindObject(const TObject* obj) =>
TypeError: could not convert argument 1

Example:

void move_htemp_pstats() {
   auto f = new TFile("hsimple.root");
   auto n = (TNtuple*)f->Get("ntuple");
   n->Draw("px");
   gPad->Update();
   TH1F *h = (TH1F *)gROOT->FindObject("htemp");
   TPaveStats *s = (TPaveStats *)h->FindObject("stats");
   s->SetX1NDC(0.5);
   gPad->Modified();
   gPad->Update();
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.