Re: TCanvas saved in batch mode

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Tue, 30 Dec 2008 07:46:07 +0100


Simplify your script Test.C as shown below and run it with

    root -b -q Test.C

Rene

void Test()
{
  TFile *f = new TFile("Test.root", "RECREATE");   TH1D *h = new TH1D("histo", "Histo", 10, 0., 10.);   h->Fill(5.);
  TCanvas *c = new TCanvas("canvas", "Canvas", 0, 0, 400, 400);   h->Draw();
  c->Write();
  delete f;
}

Dr. Manuel Mussini wrote:
> Hi,
> I would like to save (into a TFile) a TCanvas containing a TH1D ...
> but ... working in batch!
> The second step will be to loop over some histograms and do some fits.
> I've tried the simple code below and it seems to work ... but:
> - this means that I can simply use a code that works in a non batch
> session and add at the top of it gROOT->SetBatch() ? Even if I have to
> fit the histos with functions or other histos?
> - with this code the canvas is saved but there is also a copy of the
> histo ... how can I aviod it?
> - is there any example/tutorial about this issue?
>
> Thanks a lot!
>
>
> void Test()
> {
> gROOT->SetBatch();
> TFile *f = new TFile("Test.root", "RECREATE");
> TH1D *h = new TH1D("histo", "Histo", 10, 0., 10.);
> h->Fill(5.);
> TCanvas *c = new TCanvas("canvas", "Canvas", 0, 0, 400, 400);
> f->Add(c);
> c->cd();
> h->Draw();
> f->Write();
> }
>
>
> Bye...
>
Received on Tue Dec 30 2008 - 07:46:37 CET

This archive was generated by hypermail 2.2.0 : Thu Jan 01 2009 - 11:50:02 CET