Skip to content

Issue using TColor and saving canvas to ROOT format #16560

@ttedeschi

Description

@ttedeschi

Check duplicate issues.

  • Checked for duplicates

Description

It seems that when saving a canvas to a ROOT file (SaveAs("c.root")), colors defined with TColor::GetColor are not preserved whereas builtin colors are. This can be seen saving the canvas to both . png .root formats, then load the .root and save it again as a .png, and compare the two pngs created.

Tagging CMS CAT conveners @lenzip @anigamova and DPROC subconveners @oglez @ttedeschi

Reproducer

Define a save.C macro:

{
  TRandom3 r;
  TH1F h = TH1F("test","Test",100,-1.0,1.0);
  for (int i=0;i<=1000;++i) {
    h.Fill(r.Rndm());
  }

  TCanvas c = TCanvas();
  c.Draw();

  h.SetFillStyle(1001);
  h.SetFillColor(TColor::GetColor("#F5BB54"));

  //h.SetFillColor(kRed);
  h.Draw("HIST");

  c.SaveAs("c.root");
  c.SaveAs("c.png");
}

and a load.C macro:

{
TFile *f = new TFile("c.root");
TH1F *h1 = (TH1F*)f->Get("c1");
h1->Draw();
h1->SaveAs("loaded_c.png")
}

If h.SetFillColor(TColor::GetColor("#F5BB54")); is uncommented and h.SetFillColor(kRed) is commented, c.png and loaded_c.png differ (the latter lacks the color), whereas if h.SetFillColor(TColor::GetColor("#F5BB54")) is commented and h.SetFillColor(kRed) is uncommented, c.png and loaded_c.png are the same (both properly showing the red fill color).

ROOT version

6.32.04

Installation method

Docker image

Operating system

Ubuntu 24.04⁠

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions