TPostScript scoping

Hi all,

I’m wondering how I can make the following script work:

void testPs()
{ 
  gROOT->SetStyle("Plain");

  TH1F* h = new TH1F("h","ht",100,-5,5);
  TPostScript* ps = new TPostScript("testPs.ps",114);
  TCanvas* c = new TCanvas;

  ps->NewPage();
  c->Clear();
  c->Divide(2,1);
  TVirtualPad* pad = c->cd(2);
  h->FillRandom("gaus",10000);
  h->Draw();
  c->Update();

  ps->NewPage();
  c->Clear();
  c->Divide(2,1);
  pad = c->cd(1);
  h->Draw();
  pad->Print("myTest.eps");
  ps->On();
  pad = c->cd(2);
  h->Draw();
  c->Update();

  ps->NewPage();
  c->Clear();
  c->Divide(1);
  c->cd(1);
  h->Draw();

  ps->Close();
  c->Close();
}

What I want to happen is that the first pad in the second page is going to be written to the main .ps file (testPs.ps) and also to a separate eps file (myTest.eps). What currently happens is that the .eps file is written, but the pad is empty in the main ps file.

Cheers,
N.

So this can be done like this:

void testPs()
{ 
  gROOT->SetStyle("Plain");

  TPostScript* ps = new TPostScript("testPs.ps",114) ;
  TCanvas* c = new TCanvas("canvas","canvas",600,700);
  TH1F* h = new TH1F("h","ht",100,-5,5);
  TH1F* h2 = new TH1F("h2","ht",100,-5,5);
  h->FillRandom("gaus",10000);
  h2->FillRandom("gaus",8000);

  TPaveText pave(0.9,0.9,1,1);
  pave.AddText("1");
  ps->NewPage();
  c->Clear();
  c->Divide(2,2);
  for (int i=0; i<4; ++i) { 
    pad = c->cd(i+1);
    h->Draw();
    h2->Draw("SAME");
    h2->SetLineColor(kRed);
    pad->Clone()->Print("myTest1.eps");
    ps->On();
    pad->Draw();
  }
  c->Update();
  c->cd(0);
  pave.Draw("SAME");
  //  c->Update();                                                                                                                                                                                          

  ps->Close();
  c->Close();
}

The problem is that I want to draw a page number at the top of the main ps file.
I can do this by:

c->cd(0);
pave.Draw("SAME");
c->Update();

But this method doesn’t work when I have pad->Draw(); in my loop.

N.

Try something like:

void testPs()
{
   gROOT->SetStyle("Plain");
 
   TPostScript* ps = new TPostScript("testPs.ps",114) ;
   TCanvas* c = new TCanvas("canvas","canvas",600,700);
   TH1F* h = new TH1F("h","ht",100,-5,5);
   TH1F* h2 = new TH1F("h2","ht",100,-5,5);
   h->FillRandom("gaus",10000);
   h2->FillRandom("gaus",8000);
 
   TText t; 
   ps->NewPage();
   c->Clear();
   c->Divide(2,2);
   for (int i=0; i<4; ++i) {
      pad = c->cd(i+1);
      h->Draw();
      h2->Draw("SAME");
      h2->SetLineColor(kRed);
      if (i==1) t.DrawTextNDC(.5.,.95,"Page: 1");
      pad->Clone()->Print("myTest1.eps");
      ps->On();
      pad->Draw();
   }
   ps->Close();
   c->Close();
}