Problem drawing TPaveText over TCanvas

Hi

I am trying to put some text using TPaveText on superimposed TH1 using as example the hadd -

so, what I am doing, is looping over some files, get the object with the same TH1 name and superimposed them - Part of the code looks like

[code] TFile *first_source = (TFile *) sourcelist->First ();
first_source->cd (path);
TDirectory *current_sourcedir = gDirectory;
Bool_t status = TH1::AddDirectoryStatus ();
TH1::AddDirectory (kFALSE);

TChain *globChain = 0;
TIter nextkey (current_sourcedir->GetListOfKeys ());
TKey *key, *oldkey = 0;
while ((key = (TKey *) nextkey ())) {

//keep only the highest cycle number for each key
if (oldkey && !strcmp (oldkey->GetName (), key->GetName ()))
  continue;

// read object from first source file and create a canvas
first_source->cd (path);
TObject *obj = key->ReadObj ();
TCanvas *c1 = new TCanvas ("c1", obj->GetName (), 500, 500);


TPaveText *pave = new TPaveText(-3.78,500,-1.2,750);
  pave->SetFillColor(kBlue);
 TText *t1=pave->AddText("ttbar_0j");
 t1->SetTextColor(1);
  t1->SetTextSize(0.05);
  
  TText *t2=pave->AddText("ttbar_01j");
  t2->SetTextColor(2);
  TText *t3=pave->AddText("T2tt_01j");
  t3->SetTextColor(3);


if (obj->IsA ()->InheritsFrom ("TH1F")) {

  TH1F *h1 = (TH1F *) obj;  
  TFile *nextsource = (TFile *) sourcelist->After (first_source);
 
    h1->Draw();
  while (nextsource) {

    // make sure we are at the correct directory level by cd'ing to path
nextsource->cd (path);
TKey *key2 = (TKey *) gDirectory->GetListOfKeys ()->FindObject (h1->GetName ());
     TH1F *h2;
      if (key2) {
        h2 = (TH1F*) key2->ReadObj ();
           
        h2->Draw("SAMES");
         
  }


nextsource = (TFile *) sourcelist->After (nextsource);
  }				// while ( nextsource )
}


  // loop over all source files create a chain of Trees "globChain"
  const char *obj_name = obj->GetName ();

  globChain = new TChain (obj_name);
  globChain->Add (first_source->GetName ());
  TFile *nextsource = (TFile *) sourcelist->After (first_source);
  //      const char* file_name = nextsource->GetName();
  // cout << "file name  " << file_name << endl;
  while (nextsource) {

globChain->Add (nextsource->GetName ());
nextsource = (TFile *) sourcelist->After (nextsource);
  }

}

if (obj) {
  target->cd ();
  if (obj->IsA ()->InheritsFrom ("TTree"))	// not tested
globChain->Merge (target->GetFile (), 0, "keep");
  else
    c1->cd();
    pave->Draw();
    c1->Write (key->GetName ());
      }

} // while ( ( TKey key = (TKey)nextkey() ) )

[/code]

Problem is that I cannot get the TPaveText over the Canvas…

Thanks in advance

Can you post a running example showing the problem ?

Hi

Problem solved by using TLegend class

thanks