Hatched histogram legends and compiled code

Hi all,

I am trying to produce hatched histograms in a postscript file. The code

TCanvas* c = new TCanvas("c", "c");
TH1F* h = new TH1F("h","h",10, -4, 4);
h->FillRandom("gaus", 1000);
h->SetLineColor(kBlack);
h->SetFillStyle(3335);
h->SetFillColor(kBlack);
h->Draw();
TLegend* leg=new TLegend(0.7, 0.5, .95, 0.6);
leg->AddEntry(h, "Hatched hist", "f");
leg->Draw();
c->Print("hatch_tst.ps");

works fine if pasting it into the interactive ROOT-interpreter. However, trying to compile the same code (file hatch_tst.cc)

#include "TCanvas.h"
#include "TLegend.h"
#include "TH1F.h"

int main(void) {
   TCanvas* c = new TCanvas("c", "c");
   
   TH1F* h = new TH1F("h","h",10, -4, 4);
   h->FillRandom("gaus", 1000);
   h->SetLineColor(kBlack);
   h->SetFillStyle(3335);
   h->SetFillColor(kBlack);
   h->Draw();
   
   TLegend* leg=new TLegend(0.7, 0.5, .95, 0.6);
   leg->AddEntry(h, "Hatched hist", "f");
   leg->Draw();
   
   c->Print("hatch_tst.ps");

   return 0;
}

with

gcc -Wall -I/home/ersmark/sim/root/include/root -L/home/ersmark/sim/root/lib/root -lCore -lCint -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -ldl hatch_tst.cc -o hatch_tst

and running it produces a postscript without any hatching.

Any ideas how I can get this to work? Using the “bar” option when drawing the histogram works to produce a hatching of the histogram. The symbol in the legend isn’t hatched however.

(using ROOT 4.04.02b)

Thanks in advance.

Cheers,
Tore

This seems to be a side effect of running in batch mode.
You should run with a TAppilcation or TRint object in your program.
See examples in $ROOTSYS/test.
I keep repeating that it is in general a very bad idea to run with your own main program, unless you have your own event loop with
TApplication/TRint or equivalent.
Simply run a script (interpreted or compiled) from the interactive ROOT.

Olivier will investigate the problem with batch once he will be back in a few days.

Rene

This problem is now fixed in the CVS head. Thanks to have reported it.