How to save a histogram in jpeg and eps by using "project"

Hi, Rooter,

I’m using a tree to do a cut then save the histogram in jpeg and eps formats.
Here is my script[1].
It works well however, this script has to open a canvas and display it on a screen.

From ROOT manual, I know one can use the class of project of a Tree without displaying.
Like, hitSumm->project(“E1”, “E1 cut condition”);
But, I’d like to save this histogram into jpeg and eps files.
I tried this [2] but failed.
Could you please tell me how to do it?
Thanks a lot in advance !

Best regards,

hitSumm->Draw(“E1”, " E1 cut condition");
c1->Print(“E1-smallhits.eps”);//Print() works either

hitSumm->Project(“E1”, “E1 cut condition”);

Hello, you can try the SaveAs method instead of the Print one

hitSumm->Project("E1", "E1 cut condition"); hname->SaveAs("E1-smallhits.jpeg"); hname->SaveAs("E1-smallhits.eps");

Print or SaveAs should not make any difference.
Just Start ROOT wit the option -b to avoid the canvas opening.

To pamputt and couet,
Print and Saveas both resulted same message as[3].

To couet,
the problem is solved after following your suggestion !
Thanks a lot !

Error: Symbol hname is not defined in current scope CreateHistogram.C:9:
Error: Failed to evaluate hname->SaveAs(“E1-smallhits.jpeg”)
*** Interpreter error recovered ***