Re: [ROOT] TLegend

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Nov 02 2000 - 17:58:46 MET


I do not see anything a priori wrong with your script.
Unfortunatly, you do not mention which version/OS you are using.
You will find below a small variant of your script and I checked
that it runs correctly.

Rene Brun

void sutton(){
      TH1F *h1 = new TH1F("h1","zeus",100,-3,3);
      h1->FillRandom("gaus",10000);
      h1->SetMarkerStyle(21);
      h1->SetMarkerColor(1);
      TH1F *h2 = new TH1F("h2","h2",100,-3,3);
      h2->FillRandom("gaus",5000);
      h2->SetFillColor(38);
      TH1F *h3 = new TH1F("h3","h3",100,-3,3);
      h3->FillRandom("gaus",3000);
      h3->SetFillColor(44);
      h1->Draw("ep");
      h2->Draw("same");
      h3->Draw("same");
      TLegend *tleg = new TLegend(0.15,0.65,0.40,0.85);
      cout << "ptr: " << tleg << endl;
      tleg->SetFillColor(0);
      tleg->SetBorderSize(0);
      tleg->AddEntry(h1,"ZEUS 96+97","p");
      tleg->AddEntry(h2,"HERWIG (dir + res)","f");
      tleg->AddEntry(h3,"HERWIG direct","f");
      tleg->Draw();
}

M.R.Sutton wrote:
> 
> Why might this be giving me a segmentation violation?
> 
>       TLegend *tleg = new TLegend(0.2,0.65,0.45,0.85);
>       cout << "ptr: " << tleg << endl;
>       tleg->SetFillColor(0);
>       tleg->SetBorderSize(0);
>       tleg->AddEntry(data_dist,"ZEUS 96+97","p");
>       tleg->AddEntry(res_dist,"HERWIG (dir + res)","f");
>       tleg->AddEntry(dir_dist,"HERWIG direct","f");
>       tleg->Draw();
> 
> the pointers  {data,dir,res}_dist *are* all defined and plotable
> and the objects pointed to *are* in scope as is the pointer
> tleg after the declaration, yet still the segmentation violation
> occurs.
> 
> I have traced it to the Draw command  following the AddEntry.
> If I *DO NOT* use AddEntry, then the segmentation violation
> does NOT occur. Does this not suggest a problem with the
> TList of the TLegend?
> 
> Surely if everything properly conforms to the data hiding
> paradigm etc then nothing I have done previously should  be
> able to stop the TLegend behaving properly and suggests some
> hidden dependence on some additional global object which
> isn't in the right state?
> 
> Or maybe I am just a victim of ignorance and am doing
> something wrong?
> 
> Unnecessary Dependence on Global Objects? JUST SAY NO!!!!!



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:36 MET