Confused by TPostscript

Hi

TPostscript has become the bane of my existence. I understand the simple examples available at root.cern.ch but these do not always work and I’ve found it incredibly sensistive to the order of canvas updates. In the example code below (which is actually compiled in root4star, root version 4.04/02g) I had to update the canvas in order to get the canvas to draw properly in one function and I couldn’t update the canvas in the other or else I would get a blank page. These two functions currently work but I don’t understand why they have to be different – the only difference is between the loops in which the histograms are drawn.

Basically I don’t really understand why TPostscript seems so highly sensitive to the order in which I do things when creating one and am wondering what the ideal combination of updating the canvas, writing the postscript, and clearing the postscript is. Any insight would be welcome.

Thanks
Christine

void LadderSummaryWriter::WritePostscript(char *name){
TPostScript *postscript = new TPostScript(name);
postscript->NewPage();//necessary so that there is a page to draw on
pageNum =0;
postscript->On();

TCanvas *canvas = new TCanvas(“canvas”,“canvas”,width,height);//width then height
canvas->SetGridx(kFALSE);
canvas->SetGridy(kFALSE);
canvas->Range(0,0,20,24);//sets range to that of letter paper I think
canvas->Divide(numXCanvases,numYCanvases);

//MakeSummaryPlots();

int canvasNum=1;
canvas->cd(canvasNum);
hdphitLadder->Draw();
canvasNum++;
canvas->cd(canvasNum);
hdphidLadder->Draw();
canvasNum++;
canvas->cd(canvasNum);
hdphinLadder->Draw();
canvasNum++;
canvas->cd(canvasNum);
hdXtLadder->Draw();
canvasNum++;
canvas->cd(canvasNum);
hdXdLadder->Draw();
canvasNum++;
canvas->cd(canvasNum);
hdXnLadder->Draw();
canvasNum++;

canvas->Update();
canvas->Print();
//postscript->Write();
//postscript->Clear();

int lastLadder[]={8,12,16};

for(int barrelNum=0;barrelNum<nBarrels;barrelNum++){
for(int ladderNum=0;ladderNum<lastLadder[barrelNum];ladderNum++){
//MakeAlignerPlots(waferaligner[i]);
canvasNum=1;
postscript->On();
postscript->NewPage();

  if(ladderaligner[barrelNum][ladderNum].IsSolved()){

//canvas->Clear();
pageNum++;
//canvas->Clear();
//canvas->Divide(numXCanvases,numYCanvases);

canvas->cd(canvasNum);
ladderaligner[barrelNum][ladderNum].GetdAVSNegB()->Draw();
canvasNum++;
//canvas->Update();
canvas->cd(canvasNum);
ladderaligner[barrelNum][ladderNum].GetdAOverVdnVSA()->Draw();
canvasNum++;
//canvas->Update();
canvas->cd(canvasNum);
ladderaligner[barrelNum][ladderNum].GetdAOverVdnVSNegB()->Draw();
canvasNum++;
//canvas->Update();
canvas->cd(canvasNum);
ladderaligner[barrelNum][ladderNum].GetNegdA()->Draw();
canvasNum++;
//canvas->Update();
canvas->cd(canvasNum);
ladderaligner[barrelNum][ladderNum].GetdAOverVdn()->Draw();
canvasNum++;
//canvas->Update();
canvas->cd(canvasNum);

ladderaligner[barrelNum][ladderNum].GetdBVSA()->Draw();
canvasNum++;
//canvas->Update();
canvas->cd(canvasNum);
ladderaligner[barrelNum][ladderNum].GetdBOverVtnVSA()->Draw();
canvasNum++;
//canvas->Update();
canvas->cd(canvasNum);
ladderaligner[barrelNum][ladderNum].GetdBOverVtnVSNegB()->Draw();
canvasNum++;
//canvas->Update();
canvas->cd(canvasNum);
ladderaligner[barrelNum][ladderNum].GetNegdB()->Draw();

canvasNum++;
//canvas->Update();
canvas->cd(canvasNum);
ladderaligner[barrelNum][ladderNum].GetdBOverVtn()->Draw();
canvasNum++;
//for this class this line must be uncommented or else the resulting page is blank:
canvas->Update();
  }
}
canvas->Update();
//canvas->Print();

}
postscript->Close();
delete postscript;
}

void WaferSummaryWriter::WritePostscript(char *name){
TPostScript *postscript = new TPostScript(name);
postscript->NewPage();//necessary so that there is a page to draw on
pageNum =0;
postscript->On();

TCanvas *canvas = new TCanvas(“canvas”,“canvas”,width,height);//width then height
canvas->SetGridx(kFALSE);
canvas->SetGridy(kFALSE);
canvas->Range(0,0,20,24);//sets range to that of letter paper I think
canvas->Divide(numXCanvases,numYCanvases);

//MakeSummaryPlots();

int canvasNum=1;
canvas->cd(canvasNum);
hdphitWafer->Draw();
canvasNum++;
canvas->cd(canvasNum);
hdphidWafer->Draw();
canvasNum++;
canvas->cd(canvasNum);
hdphinWafer->Draw();
canvasNum++;
canvas->cd(canvasNum);
hdXtWafer->Draw();
canvasNum++;
canvas->cd(canvasNum);
hdXdWafer->Draw();
canvasNum++;
canvas->cd(canvasNum);
hdXnWafer->Draw();
canvasNum++;

canvas->Update();
canvas->Print();
//postscript->Write();
//postscript->Clear();

for(int i=firstWafer;i<=lastWafer;i++){
//MakeAlignerPlots(waferaligner[i]);
canvasNum=1;
postscript->On();
postscript->NewPage();

if(waferaligner[i].IsSolved()){
  
  //canvas->Clear();
  pageNum++;
  //canvas->Clear();
  //canvas->Divide(numXCanvases,numYCanvases);
  
  canvas->cd(canvasNum);
  waferaligner[i].GetdAVSNegB()->Draw();
  canvasNum++;
  //canvas->Update();
  canvas->cd(canvasNum);
  waferaligner[i].GetdAOverVdnVSA()->Draw();
  canvasNum++;
  //canvas->Update();
  canvas->cd(canvasNum);
  waferaligner[i].GetdAOverVdnVSNegB()->Draw();
  canvasNum++;
  //canvas->Update();
  canvas->cd(canvasNum);
  waferaligner[i].GetNegdA()->Draw();
  canvasNum++;
  //canvas->Update();
  canvas->cd(canvasNum);
  waferaligner[i].GetdAOverVdn()->Draw();
  canvasNum++;
  //canvas->Update();
  canvas->cd(canvasNum);
  
  waferaligner[i].GetdBVSA()->Draw();
  canvasNum++;
  //canvas->Update();
  canvas->cd(canvasNum);
  waferaligner[i].GetdBOverVtnVSA()->Draw();
  canvasNum++;
  //canvas->Update();
  canvas->cd(canvasNum);
  waferaligner[i].GetdBOverVtnVSNegB()->Draw();
  canvasNum++;
  //canvas->Update();
  canvas->cd(canvasNum);
  waferaligner[i].GetNegdB()->Draw();
  
  canvasNum++;
  //canvas->Update();
  canvas->cd(canvasNum);
  waferaligner[i].GetdBOverVtn()->Draw();
  canvasNum++;
  //For this class this line MUST be commented out or else the resulting page is blank:
  //canvas->Update();
}

canvas->Update();
//canvas->Print();

}
postscript->Close();
delete postscript;
}

In most cases you do not need to use the TPostScript class directly in order to produce a PS output. You just have to use the Print() method of TPad. If you want to print several plots in the same file you can use the open and close paranthesis mechanism. One need to use TPostScript in some very special cases, for instance to write several PS files in parallel. May you provide some small running example showing the difficulties you encountered ? (The two examples you sent cannot be run)

Yes I know thanks but this is making on the order of 216 pages and I don’t want to dump all of that crap into my directory under 216 different names, nor do I want to add that many attachments when trying to email things to people. Can anyone help with TPostscript?

I think that you should really make a very small effort to read the documentation and follow Olivier’s advice.
Using the {,} or {,} notation in TPad::Print, you can perfectly make
one single file out of many canvases.

Rene