Understanding root color indexes

Dear ROOTers,
I’m writing a simple GUI that sets the color of the histogram. I use the modified axis editor from ROOT with TGColorSelect. When I pick up the color and apply it to the histogram, everything looks fine.
However, when I use the value obtained in this program and try to apply it in another macro - it sometimes doesn’t work.
For example:

  • I opened editor, pickup up “kRed” and got “2”, which is weird because kRed is 632
  • I opened editor pick up kRed-4, I would expect -2, or 638, but I got 1184
    I know that “2” might be a predefined value, but what is the logic behind 1184? Why do such setting colors work with macros with GUI but sometimes don’t work with other macros?

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi Daniel,

Let me add in the loop @couet , whose expertise might be of help here.

Cheers,
D

Thanks for your post. I will try to reproduce what you explain here.

Do you have some reproducer (root macro) I can try ? Because with ROOT and the standard editors, I can’t see what you describe here.

Hi,
In attached file there is a “minimal” macro that prints colors.
However I see it’s works slightly differently :slight_smile: Now kRed is 2 :slight_smile: but kRed-4=1180 whereas kRed-7 is 625.
It’s also surprising that when I set Fill(1180) at the begin of macro I get white fill even with SetFillStyle(1001) (works with kRed);

debug.C (4,1 KB)

1 Like

I think I understand. In the editor menu the red color used is takien in the basics colors. Whereas kRed is coming from the color wheel. Both are red (r=1,g=0,b=0), the indeces are differents.

This is something that I thought but there is another issue.
For example:
a) kRed =2 (ok, basic color)
b) kRed+1 = 633 (ok, color wheel + 1)
c) kRed-2 = 1181 why? this is like kRed+559!
The a and b colors will work with any root macro, c will not.
I also noticed that this “suspicious id’s” are present only for some rows in colors (marked with lines)
Bez nazwy

The Colour wheel doc page linked by Couet tells you that “It is better to use these keywords in user code instead of hardcoded color numbers”.
Look at the code of CreateColorWheel (see here). Taking kRed for example, the pure red should be (255,0,0), so find that in the array

   UChar_t red[46]    = {255,204,204
                        ,255,153,153, 204,153,153
                        ,255,102,102, 204,102,102, 153,102,102
                        ,255, 51, 51, 204, 51, 51, 153, 51, 51, 102, 51, 51
                        ,255,  0,  0, 204,  0,  0, 153,  0,  0, 102,  0,  0,  51,  0,  0};

It’s in the last line. If you move forward by 1 group of 3 positions from there (i.e. for kRed+1) you get (204,0,0), which is what we see in the Colour Wheel (use a colour picker in a graphics software to check it). If you move back 2 groups of 3, for kRed-2, we have (153, 51, 51), which again matches what we see in the wheel. I don’t think there’s a real logic to the numbers, it’s just what the developer/s did. So, follow their advice :slight_smile:

1 Like

Indeed that’s not what I see with the lastest root:

root [3] TColor::ListColors(622,24)
   +------+-------+-------+-------+-------+--------------------+--------------------+
   | Idx  | Red   | Green | Blue  | Alpha |     Color Name     |    Color Title     |
   +------+-------+-------+-------+-------+--------------------+--------------------+
   |  622 | 1.000 | 0.800 | 0.800 | 1.000 |            kRed-10 |            #ffcccc |
   |  623 | 1.000 | 0.600 | 0.600 | 1.000 |             kRed-9 |            #ff9999 |
   |  624 | 0.800 | 0.600 | 0.600 | 1.000 |             kRed-8 |            #cc9999 |
   |  625 | 1.000 | 0.400 | 0.400 | 1.000 |             kRed-7 |            #ff6666 |
   |  626 | 0.800 | 0.400 | 0.400 | 1.000 |             kRed-6 |            #cc6666 |
   |  627 | 0.600 | 0.400 | 0.400 | 1.000 |             kRed-5 |            #996666 |
   |  628 | 1.000 | 0.200 | 0.200 | 1.000 |             kRed-4 |            #ff3333 |
   |  629 | 0.800 | 0.200 | 0.200 | 1.000 |             kRed-3 |            #cc3333 |
   |  630 | 0.600 | 0.200 | 0.200 | 1.000 |             kRed-2 |            #993333 |
   |  631 | 0.400 | 0.200 | 0.200 | 1.000 |             kRed-1 |            #663333 |
   |  632 | 1.000 | 0.000 | 0.000 | 1.000 |               kRed |            #ff0000 |
   |  633 | 0.800 | 0.000 | 0.000 | 1.000 |             kRed+1 |            #cc0000 |
   |  634 | 0.600 | 0.000 | 0.000 | 1.000 |             kRed+2 |            #990000 |
   |  635 | 0.400 | 0.000 | 0.000 | 1.000 |             kRed+3 |            #660000 |
   |  636 | 0.200 | 0.000 | 0.000 | 1.000 |             kRed+4 |            #330000 |
   +------+-------+-------+-------+-------+--------------------+--------------------+
   | Number of possible colors = 2000                                               |
   | Number of defined colors between  622 and  646 =   15                          |
   | Number of free indeces between  622 and  646   =    9                          |
   +--------------------------------------------------------------------------------+

root [4] kRed
(EColor) (kRed) : (unsigned int) 632
root [5] kRed-10
(int) 622
root [6] 

Hi,
but still I cannot understood the convention of values returned by wheel color
As in attached picture in some lines the returned value corresponds to kRed+/-expected value (eg. kRed+1.+2+3+4 or kRed-5,-6,-7, whereas for kRed-1,-2,-3,-4 I got values like 11xx - much more that I would expect (500-700).

In the table I sent you one can see:

kRed. = 632
kRed-1 = 631
kRed-2 = 630

etc…
I do not get 11xx … as I said that’s the latest ROOT.

So let me rephares my question:

  • is there a bug i color picker? or
  • am I using color picker in a wrong way?
    The macro debug.C with root 6.32.04 returns sometimes wrong indexes of colors.
    For colors like kRed+1,kRed+2) I obtain values that are correct - I mean agrees with your table.
    But for some colors like kRed-1,kRed-2 I get those values like 1182 that doesnt work.

I tried again your macro.
I see the little GUI it creates.
When I select te red from the basic color menu I get red= 2
Then I go to the color wheel in the same little GUI and select the red-2 in the wheel your macro prints 630 as in the table I sent you.

It’s interesting, I still got bad values, I switched to ROOT 6-30 and still got bad Id’s.
I used your method to print colors around 1180, it’s interesting when I load macro this lists looks like:


+------+-------+-------+-------+-------+--------------------+--------------------+
  | Idx  | Red   | Green | Blue  | Alpha |     Color Name     |    Color Title     |
  +------+-------+-------+-------+-------+--------------------+--------------------+
  +------+-------+-------+-------+-------+--------------------+--------------------+
  | Number of possible colors = 2000                                               |
  | Number of defined colors between 1180 and 1220 =    0                          |
  | Number of free indeces between 1180 and 1220   =   40                          |
  +--------------------------------------------------------------------------------+

but after picking colors

   +------+-------+-------+-------+-------+--------------------+--------------------+
   | Idx  | Red   | Green | Blue  | Alpha |     Color Name     |    Color Title     |
   +------+-------+-------+-------+-------+--------------------+--------------------+
   | 1180 | 0.400 | 0.192 | 0.192 | 1.000 |            #663131 |                    |
   +------+-------+-------+-------+-------+--------------------+--------------------+
   | Number of possible colors = 2000                                               |
   | Number of defined colors between 1180 and 1220 =    1                          |
   | Number of free indeces between 1180 and 1220   =   39                          |
   +--------------------------------------------------------------------------------+

So it seems that ROOT create some new colors when I use color picker. I probably have to check this on different OS.

Can you try the following interactively:

root [1] TColor::GetColorByName("kRed")
(int) 632
root [2] TColor::GetColorByName("kRed-1")
(int) 631
root [3] TColor::GetColorByName("kRed-2")
(int) 630

I’ve got exactly the same values as you.
It’ seems that some extra colors are addes “somewhere”.

To be sure: what do you call the color picker ? the color wheel ?

I tried to list the color 1180 before and after “picking” and I do not see any new color after picking.

Can you clarify what you mean exactly by picking ?

What I did is:

  1. open the color wheel from your little GUI
  2. click on kRed-2
  3. click on OK

Hi,
It seems that this is a issue related to my computer only, I tried on different machine and got expected values :confused:

One which kind of computer are you running ?

On more thing: I might be that there is something else in your rootlogon.C file. Can you start root with option -n ie:

$ root -n

and check if you get the same result ?