TH2F and TEllipse

Hello,
I have a problem in small subroutine. I would like to draw an ellipse over a 2D-histogram. This is my code

[code]//
/* This routine plots energy loss dE versus energy E. */
/
/

#include <TFile.h>
#include <TTree.h>
#include <TH2F.h>
#include <TCanvas.h>
#include <TEllipse.h>

using namespace std;

void plot_dE_E()
{
TCanvas *c = new TCanvas(“c”,“dE_E”);

TFile f = new TFile("/space/mydata.root");
TTree
t = (TTree*)f->Get(“Analysed_Data”);

TH2F *h = new TH2F(“h”,"",800,0,800,350,100,450);
t->Project(“h”,“dE:SiET”,“SiET>0.”);
h->Draw(“col”);

TEllipse el(100.,300.,75.,125.,0.,360.,0.);
el.SetLineColor(3);
el.SetLineWidth(6);
el.SetFillStyle(0000);
el.Draw();

c->Save(“save.eps”);
}[/code]
My problem is when I run this subroutine, I see briefly my ellipse and then it disappears.

But If I run this subroutine

[code]//
/* This routine plots energy loss dE versus energy E. */
/
/

#include <TFile.h>
#include <TTree.h>
#include <TH2F.h>
#include <TCanvas.h>

using namespace std;

void plot_dE_E()
{
TCanvas *c = new TCanvas(“c”,“dE_E”);

TFile f = new TFile("/physique/Physique/space/machaine.root");
TTree
t = (TTree*)f->Get(“Analysed_Data”);

TH2F *h = new TH2F(“h”,"",800,0,800,350,100,450);
t->Project(“h”,“dE:SiET”,“SiET>0.”);
h->Draw(“col”);

c->Save(“save.eps”);
}[/code]
and then this one

{ TEllipse el(100.,300.,75.,125.,0.,360.,0.); el.SetLineColor(6); el.SetLineWidth(6); el.SetFillStyle(0000); el.Draw(); }
my ellipse stay printing on the screen.
Do you know what is the problem? I would like put in the same subroutine TH2F and TEllipse.

In fact, ellipse disappears after saving my canvas. After saving, I do not see ellipse but ellipse appears in save.eps. So there is not really a problem.

Hi,

Since you build the Ellipse as an object on the stack (as opposed to calling new TEllipse), the object is automatically deleted once the routine comes to an end. Once a (graphical) object is deleted, it is removed from any canvas its drawn on.

Cheers,
Philippe.

I cannot reproduce your problem. I can draw an ellipse on top a TH2F using the histogram coordinates. I can save the result in a PS file. all is working fine.