Pdf -> Color in TLegend?

Hi,

I’m experience the following problem:

I have plotted some pdfs, each one with a different color
and i want to add this color of each pdf on TLegend
However, it doesn’t work the same way as it works with usual histograms

I tried this one (which i found somewhere online):

TLegend *leg = new TLegend(0.75,0.7,0.92,0.9);
leg->AddEntry(frame->findObject(“pdf_qcd_mvacut1”),“mva>0.4”,“f”);

but it doesn’t work.
Does anyone know how to solve this?

Thanks in advance

Can you provide a small reproducer ?

sure,

  //opening 6th MC file
   TFile *fTemplates_mvacut6 = TFile::Open("templates_TuneCUETP8M2T4_13TeV-powheg-pythia8_mvacut6_workspace.root");
   RooWorkspace *wTemplates_mvacut6 = (RooWorkspace*)fTemplates_mvacut6->Get("w");
   RooAbsPdf *pdf_qcd_mvacut6 = (RooAbsPdf*)wTemplates_mvacut6->pdf("qcd_pdf");

   //----------declaring frames----------

   //----signal----
  RooPlot *frame = x->frame();
  frame->SetTitle("QCD pdf for all mva cuts");
  pdf_qcd_mvacut6->plotOn(frame,RooFit::LineColor(kCyan),RooFit::LineWidth(2));

  frame->Draw();
  
  TLegend *leg = new TLegend(0.75,0.7,0.92,0.9);
  //doesn't work the way below:
  leg->AddEntry(frame->findObject("pdf_qcd_mvacut1"),"mva>0.4","f");
  //doesn't work the way below either:
   leg->AddEntry(pdf_qcd_mvacut6,"mva>0.9","f");
  leg->SetHeader("QCD bkg","C");
  leg->SetFillColor(0);
  leg->SetFillStyle(0);
  leg->SetTextFont(42);
  leg->SetTextSize(0.04);
  leg->Draw();

Thanks. Would it be possible also to have the root file ? (or a reduce version of it containing the needed data you are using to produce the legend).

how can i add the root file here?
The Legend is created, the only problem is that the boxes are white and they don’t reproduce the color of the pdf

Using the upload button.

Hi eandread,

The object “pdf_qcd_mvacut” is TAttLine or TAttFill object ?

Best,
M.

That’s what I wanted to know … That why I am asking for the ROOT file.

it’s a RooAbsPDF object actually

RooAbsPDF doesn’t inherit from any of the TAttXXX classes. Therefore a legend cannot be build for it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.