Incorrect legend displayed

I am plotting two histograms together. One histogram is plotted in black line and the other in red line. But the legend shows black color for both the histograms. The relevant part of my script is below. I have also uploaded the plot i get.

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
TFile* file = new TFile(“cpangle_comb.root”);
TH1F* h_phistar_combined_Even = (TH1F*)file->Get(“h_phistar_combined_Even”);
TH1F* h_phistar_combined_Odd = (TH1F*)file->Get(“h_phistar_combined_Odd”);
TH1F* h_phistar_combined_DY = (TH1F*)file->Get(“h_phistar_combined_DY”);
TH1F* h_phistar_combined_Even_normalised = (TH1F*)h_phistar_combined_Even->Clone();
h_phistar_combined_Even_normalised->Divide(h_phistar_combined_DY);
TH1F* h_phistar_combined_Odd_normalised = (TH1F*)h_phistar_combined_Odd->Clone();
h_phistar_combined_Odd_normalised->Divide(h_phistar_combined_DY);
TCanvas* c = new TCanvas();
h_phistar_combined_Even_normalised->SetLineColor(1);
h_phistar_combined_Even_normalised->Draw();
h_phistar_combined_Even_normalised->SetAxisRange(8., 22.,“Y”);
h_phistar_combined_Odd_normalised->SetLineColor(2);
h_phistar_combined_Odd_normalised->Draw(“same”);
h_phistar_combined_Odd_normalised->SetAxisRange(8., 22.,“Y”);
TLegend* leg_normalised = new TLegend(0.3,0.8,0.48,0.9);
leg_normalised->AddEntry(“h_phistar_combined_Even_normalised”,“Even”);
leg_normalised->AddEntry(“h_phistar_combined_Odd_normalised”,“Odd”);
leg_normalised->Draw();
c->SaveAs(“test.pdf”);

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
test.pdf (13.4 KB)

Try:

leg_normalised->AddEntry(h_phistar_combined_Even_normalised, "Even");
leg_normalised->AddEntry(h_phistar_combined_Odd_normalised, "Odd");

Worked perfectly. Thank you. I do not understand it though because i had always put the histogram name in quotes and it always plotted legend correctly.

As long as “histogram names” correspond to “histogram pointers”, it will be fine.