How I can now get the colours assigned to each of these histograms to reuse them later? vHist[itHist] -> GetLineColor(); (after drawing) returns always the colour number 602 which is obviously wrong.
So, right now I can get all colours from palette this way: auto paletteColours = TColor::GetPalette();
The size is 255 elements, so I can do some simple math and select corresponding colour by paletteColours.At() at even intervals – but why GetLineColor() does not work?
When the option PLC is passed to TH1::Draw() a color index id is picked inside the current color palette and SetLineColor with that color index id is called. Therefore if you call GetLineColor just after you find the color index that was just set. But if you come later in another ROOT session and, for instance, omit to call SetPalette with the same palette (in your case RainBow) the color index id will not point to the same color.
Please, see my working example in some previous post: 5 histograms are drawn on the same canvas simultaneously one after another with the “PLC same” option, and they are drawn with different line colours. But the colour id returned by the GetLineColor() is the same.
I can call GetLineColor() right after drawing too and get the same id’s:
As the color indices are equally distributed on the color map they can be computed only at painting time when all the objects stored in the current pad are in place. Therefore, in a macro, after a gPad->Update():
Thank you.
But I need to know the indices after first n histograms are drawn to reuse them later on other m packets by n histograms (now with SetLineColor() and with different line styles).
So, there is no any solution other than in Get color id used for the histogram with the "PLC" option - #7 by vkireyeu ?
The number of objects that will be put/drawn in the pad with the drawing option PLC is not known in advance. It is known only at painting time when all the objects are drawn (see the difference between Draw and Paint). So after you have painted (with gPad->Update()) the first n histograms you can retrieve the indices and use them on another set of histograms.