TPostScript question

I have the followind passage in my code:

TCanvas c1("c1", "canavas", 800, 600); cout << "1" << endl; TPostScript ps ("ppp.ps", 111); cout << "2" << endl; ps.Range(16,24); cout << "3" << endl; hist->Draw(); cout << "4" << endl; c1.Update(); cout << "5" << endl; ps.Close(); cout << "6" << endl;

if I comment out the hist->Draw() row, my code compiles, and I get a ps file with a canavas in it. If I leave the line in (the hist is a TH1I empty, but defined histogram), the code crashes with output:

1
2
3
4

 *** Break *** segmentation violation
 Generating stack trace...
 0x4271d5c8 in <unknown> from /lib/libc.so.6
IOT Trap

Do you have any ideas what do I do wrong?

Hi Ivane,
It is not

but

:slight_smile: :slight_smile: :slight_smile:

The probelm probably is that you didn’t alocate space for the histo
the folowing code is working (5.06/00):

void
bar ()
{
  TH1F* hist = new TH1F ("hist", "glushkov", 100, 0, 1);
  TCanvas c1("c1", "canavas", 800, 600);
  cout << "1" << endl;
  TPostScript ps ("ppp.ps", 111);
  cout << "2" << endl;
  ps.Range(16,24);
  cout << "3" << endl;
  hist->Draw();
  cout << "4" << endl;
  c1.Update();
  cout << "5" << endl;
  ps.Close();
  cout << "6" << endl;
}

Hi Jimmy,
well I know that this should be that easy, but it is not working in my case. Some more details maybe will clear the situation:
My main program is in fortran, I am declaring all my C functions as external, and I am using C++/ROOT objects in them. So basically all my histos are declared as external and by calling some function I am filling them event by event. In the end of my loop I create in a separate function (let’s say my_end()) a root file and fill it with the histograms which are in the memory already. It works perfectly. In the same function I would like to fill some histograms in a ps file. Yes, you are right, this code:

 TH1F* hist = new TH1F ("hist", "glushkov", 100, 0, 1);
  hist->FillRandom("gaus");
  TCanvas c1("c1", "canavas", 800, 600);
  TPostScript ps ("ppp.ps", 111);
  ps.Range(16,24);
  hist->Draw();
  c1.Update();
  ps.Close(); 

produces a nice histo on a ps file if you run it as a macro, or compile it as a standalone piece of code. But no, in my case it again results in sigmentation fault… And I really have no idea why!

10x, though

why don’t you use c1->Print(“c1.ps”); ?

I tried already.
The code:

		TH1F* hist = new TH1F ("hist", "glushkov", 100, 0, 1);
		hist->FillRandom("gaus");
		TCanvas c1("c1", "canvas", 800, 600);
		cout << "1" << endl;
		hist->Draw();
		cout << "2" << endl;
		c1.Update();
		cout << "3" << endl;
		c1.Print("myfile.ps");
		cout << "4" << endl;

The result:

1
2

 *** Break *** segmentation violation
 Generating stack trace...
 0x4271d5c8 in <unknown> from /lib/libc.so.6
IOT Trap
zsh: 14097 abort      run < rec.in

I do not have any problem with your example:

root [0] .x ps1.C
Processing ps1.C...
1
2
3
Info in <TCanvas::Print>: ps file myfile.ps has been created
4
root [1]

I am using the latest ROOTversion on Linux