示例#1
0
void Legend::SetOrientation(Orientation orientation, std::string const& title)
{
    INFO0;
    if(!legend_.GetListOfPrimitives()) return;
    std::vector<std::string> entries;
    auto list = legend_.GetListOfPrimitives()->MakeIterator();
    TLegendEntry* entry;
    while ((entry = static_cast<TLegendEntry*>(list->Next()))) entries.emplace_back(entry->GetLabel());
    SetOrientation(orientation, entries, title);
    SetTitle(title);
}
示例#2
0
void PlotAlignmentValidation::modifySSHistAndLegend(THStack* hs, TLegend* legend)
{
  // Add mean-y-values to the legend and scale the histograms.

  Double_t legendY = 0.80;
  if (hs->GetHists()->GetSize() > 3)
    legendY -= 0.01 * (hs->GetHists()->GetSize() - 3);
  if (legendY < 0.6) {
    std::cerr << "Warning: Huge legend!" << std::endl;
    legendY = 0.6;
  }
  legend->SetY1(legendY);

  // Loop over all profiles
  TProfile* prof = 0;
  TIter next(hs->GetHists());
  Int_t index = 0;
  while ((prof = (TProfile*)next())) {
    //Scaling: from cm to um
    Double_t scale = 10000;
    prof->Scale(scale);

    Double_t stats[6] = {0};
    prof->GetStats(stats);

    std::ostringstream legendtext;
    legendtext.precision(3);
    legendtext << fixed; // to always show 3 decimals
    legendtext << ": y mean = " << stats[4]/stats[0]*scale << " #mum";

    TLegendEntry* entry = (TLegendEntry*)legend->GetListOfPrimitives()->At(index);
    if (entry == 0)
      cout << "PlotAlignmentValidation::PlotAlignmentValidation::modifySSLegend: Bad legend!" << endl;
    else
      entry->SetLabel((entry->GetLabel() + legendtext.str()).c_str());
    index++;
  }

}
示例#3
0
// 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();
}