Hi Matthieu,
When you leave the scope of the function start, all objects craeted in
the stack (not created with new) are automatically deleted by C++.
In your case the object F is deleted together with all objects (histograms)
associated with this file.
Replace the two lines:
TFile F("~/scratch1/ntuplesLH/mytrees/MyTree_W1000.root");
TTree* T=(TTree*)gDirectory->Get("T");
by
TFile *F=new TFile("~/scratch1/ntuplesLH/mytrees/MyTree_W1000.root");
TTree* T=(TTree*)F->Get("T");
Concerning the problem with "stats", see
http://root.cern.ch/root/htmldoc/THistPainter.html#THistPainter:Paint
look at section "Statistics Display"
Rene Brun
Matthieu Lechowski wrote:
>
> Hello,
>
> I have always this problem:
> in a macro, when I try to draw a tree's variable and put the result in a
> histogram, the plot disappears as soon it's drawn.
> example:
> void start()
> {
> TFile F("~/scratch1/ntuplesLH/mytrees/MyTree_W1000.root");
> TTree* T=(TTree*)gDirectory->Get("T");
> T->Draw("mmax2_YY>>h","abs(eta_Y[i1max2_YY])<2.5 &&
> abs(eta_Y[i2max2_YY])<2.5 && pt_Y[i1max2_YY]>25 &&
> pt_Y[i2max2_YY]>25 && mmax2_YY>110");
> TH1F* H=(TH1F*)gDirectory->Get("h");
> H->Draw();
> }
>
> Is there a thing to do to avoid this ? (maybe it's a basic thing to
> know, but...)
> I know the solution of transferring data of the tree in tables, then
> filling a histogram with them, but it's heavy.
>
> I think that an other problem I have is related to this one.
> When I try to do (as described in the user guide)
> TPaveStats *st=(TPaveStats*) canvas->GetPrimitive("stats");
> st->SetFillColor(10);
> H->Draw("SAMES");
> it doesn't work ("st" not known at the second line).
> I think "stats" is not known anymore.
>
> Thank you.
>
> Matthieu.
>
> ( I'm using /afs/cern.ch/sw/root/v3.05.05/rh73_gcc2952/root )
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:12 MET