forked from erkcan/ROOTmacros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LegendTools.C
26 lines (26 loc) · 1.14 KB
/
LegendTools.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// A macro to print out a TLegend - can be considered a smarter TLegend::ls().
// If no TLegend pointer is passed, it loops over the TLegends drawn on current TPad.
void PrintLegend(TLegend *leg=0) {
if ( leg==0 ) {
if (gROOT->GetListOfCanvases()->GetEntries()==0) return;
TList *padprim = gPad->GetListOfPrimitives();
for (int i=0; i<padprim->GetEntries(); i++) {
TObject *myobj = gROOT->FindObject(padprim->At(i)->GetName());
if ( myobj != 0 && myobj->InheritsFrom("TLegend") )
PrintLegend((TLegend*)myobj); }
return;
}
TList *ents = leg->GetListOfPrimitives();
for (int i=0; i<ents->GetEntries(); i++) {
TLegendEntry *le = (TLegendEntry*)ents->At(i);
TString s( le->GetLabel() );
TObject *obj = le->GetObject();
if (!obj) continue; // if no object, this can be the title line, so skip
TString color = "???";
if ( obj->InheritsFrom("TH1") )
color = gROOT->GetListOfColors()->At(((TH1*)obj)->GetLineColor())->GetName();
cout << "Item "; cout.width(2); cout.fill('0'); cout << i << " plotted in ";
cout.width(7); cout.fill(' '); cout << color << " : " << s << endl;
}
//leg->ls();
}