ROOT Version: 6.18/04
Platform: Linux
I am trying to add a legend to a plot that consists of 3 histograms that were created in a for loop, they are called ratio[i], where i goes from 0 to 2, and refers to the elements in the following vector:
std::vector<std::string> Cut = {"L_J20", "L_J30", "L_J40"}
I have given each histogram a different colour by writing:
if (i == 0) ratio[i]->SetLineColor(kRed);
else if (i == 1) ratio[i]->SetLineColor(kBlue);
else ratio[i]->SetLineColor(kYellow);
This works, but I was wondering if there is a quicker way to do this (in the form of a loop perhaps). But then my main question is, how do I now create a legend for these histograms? I have tried:
auto legend = new TLegend (.1, .7, .3, .9);
legend->AddEntry(ratio[0], "J20")
legend->AddEntry(ratio[1], "J30")
legend->AddEntry(ratio[2], "J40")
legend->Draw("same")
This doesn’t work (it crashes, but I get no error). Anyone got any idea on how to solve this?