How to remove tree->Draw's first argument from BuildLegend


when I do a:

gStyle->SetTitle(0); gStyle->SetOptTitle(0); tree->Draw("Vbias:event") ; TGraph *gr=(TGraph *)gPad->GetListOfPrimitives()->Last() ; gr->SetTitle("Bias vs event"); c1->BuildLegend()
then I always get 2 lines in the legend. The first line contains the argument of Draw, and the second the name I gave to the graph. I guess I do something wrong…

How can I manage to get the legend with just the name I give?

I can reproduce this effect with the simple nature produced by hsimple.C.

root [0] ntuple->Draw("px:py");
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [1] c1->BuildLegend()
(TLegend *) 0x7fea7c207eb0
root [2] gPad->ls()
Canvas Name=c1 Title=c1 Option=
 TCanvas fXlowNDC=0 fYlowNDC=0 fWNDC=1 fHNDC=1 Name= c1 Title= c1 Option=
  OBJ: TList	TList	Doubly linked list : 0
   TFrame  X1= -4.500000 Y1=-4.500000 X2=5.000000 Y2=5.000000
   OBJ: TH2F	htemp	px:py : 1 at: 0x7fea76a3d000
   OBJ: TPaveText	title  	X1= -0.413163 Y1=5.475000 X2=0.913163 Y2=6.128125
   OBJ: TGraph	Graph	Graph : 1 at: 0x7fea7a65c900
   OBJ: TLegend	TPave  	X1= 0.250000 Y1=2.268750 X2=4.762500 Y2=4.762500
root [3] 

I get also a two lines legend. Which is normal according to the list of primitives in the pad. (see gPad->ls())
BuiLlegend is a completely automatic functionality which creates the legend from the objects in the pad. After a simple Draw of two TTree variables, the frame is drawn with an empty TH2F and the points with a TGraph. You see them in the list. These two objects enter the legend. If you do ntuple->Draw(“px:py”,"",“COL”); you will see only one line in the legend. I will see what can be done in that case.

You could maybe try to to define the graph beforehand?

gr = new TGraph(); gr->SetName("gr"); gr->SetTitle("Bias vs event"); tree->Draw("Vbias:event >> gr ");

yes, that might be a way … but in that case you may have to turn off the graphics:

tree->Draw("Vbias:event >> gr ","","goff");

and draw the graph yourself after:


Note that depending on the number of lines you need to add, it might be as simple to create the legend yourself (with BuildLegend).