From 53019e74438a5d2238e7b4286517f208e31afbad Mon Sep 17 00:00:00 2001
From: Olivier Couet <olivier.couet@gmail.com>
Date: Wed, 5 Dec 2018 11:00:44 +0100
Subject: [PATCH] Fix https://sft.its.cern.ch/jira/browse/ROOT-9854

In case the array of sums of TH1 was created before
painting the stack (for instance by calling GetMaximum() on the stack),
the automatic colouring of the stack was not working.
---
 hist/hist/src/THStack.cxx | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hist/hist/src/THStack.cxx b/hist/hist/src/THStack.cxx
index c59d6a1a189..75a7a821256 100644
--- a/hist/hist/src/THStack.cxx
+++ b/hist/hist/src/THStack.cxx
@@ -715,6 +715,7 @@ void THStack::Paint(Option_t *choptin)
       if (ws.IsWhitespace()) strncpy(option,"\0",1);
       TObjOptLink *lnk = (TObjOptLink*)fHists->FirstLink();
       TH1* hAti;
+      TH1* hsAti;
       Int_t nhists = fHists->GetSize();
       Int_t ic;
       gPad->IncrementPaletteColor(nhists, opt1);
@@ -724,6 +725,12 @@ void THStack::Paint(Option_t *choptin)
          if (l1) hAti->SetFillColor(ic);
          if (l2) hAti->SetLineColor(ic);
          if (l3) hAti->SetMarkerColor(ic);
+         if (fStack) {
+            hsAti = (TH1*)fStack->At(i);
+            if (l1) hsAti->SetFillColor(ic);
+            if (l2) hsAti->SetLineColor(ic);
+            if (l3) hsAti->SetMarkerColor(ic);
+         }
          lnk = (TObjOptLink*)lnk->Next();
       }
    }
-- 
GitLab