# THSTack does not stack when one histogram is scaled

**URL:** <https://root-forum.cern.ch/t/thstack-does-not-stack-when-one-histogram-is-scaled/33336>\
**Category:** Newbie\
**Created:** [March 27, 2019, 3:57pm UTC](https://root-forum.cern.ch/t/thstack-does-not-stack-when-one-histogram-is-scaled/33336 "2019-03-27T15:57:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/marta/32/18269_2.png) [@Marta](https://root-forum.cern.ch/u/Marta)\
**Post date:** [March 27, 2019, 3:57pm UTC](https://root-forum.cern.ch/t/thstack-does-not-stack-when-one-histogram-is-scaled/33336/1 "2019-03-27T15:57:35Z")

</div>

Hello,  
I have a problem when I create THStack. I have multiple histograms that I want to add together and I need to multiply one of them by a constant. It works just fine without multiplying, but when I try to add the histograms, the scaled one is drawn behind (on in front of) the others. I cannot get it to be added on top of the others.  
This is how the program looks like:

```auto
#include "TCanvas.h"
#include "TROOT.h"
#include <iostream>
#include <TH2.h>
#include "TFile.h"
        
void hstack(){
  THStack *a =new THStack("a","something");

  TFile *foo = TFile::Open("foo.root");
  TH1D *h = (TH1D*)foo->Get("something");
  h->Scale(1000);

  TFile *bar = TFile::Open("bar");
  TH1D *g = (TH1D*)bar->Get("something");
 
  a->Add(g);
  a->Add(h);
    
TCanvas *C = new TCanvas("C", "something", 1000, 800);
 C->cd();
 C->SetLogy();
 a->Draw("hist");
return C;
}

```

I suppose I am using wrong method or using it in a wrong place or something like that, but I just cannot find a different way.  
Thank you very much in advance for your help!

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 27, 2019, 4:04pm UTC](https://root-forum.cern.ch/t/thstack-does-not-stack-when-one-histogram-is-scaled/33336/2 "2019-03-27T16:04:53Z")

</div>

“h” and “g” are both TH1D …  
I do not see any reason why it does not work.  
Can you provide a small script we can run reproducing the problem ?

---

<div class="post-metadata">

**Author:** ![Marta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/marta/32/18269_2.png) [@Marta](https://root-forum.cern.ch/u/Marta)\
**Post date:** [March 27, 2019, 4:28pm UTC](https://root-forum.cern.ch/t/thstack-does-not-stack-when-one-histogram-is-scaled/33336/3 "2019-03-27T16:28:30Z")

</div>

The real data that I am working with are way too big to send, but I will try to find another way to make a small script.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 27, 2019, 4:40pm UTC](https://root-forum.cern.ch/t/thstack-does-not-stack-when-one-histogram-is-scaled/33336/4 "2019-03-27T16:40:32Z")

</div>

Yes if you can make a small reproducer with fake data it will be useful .  
Just looking at the pseudo-code you sent I do not see any reason why it should not work.

---

<div class="post-metadata">

**Author:** ![Marta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/marta/32/18269_2.png) [@Marta](https://root-forum.cern.ch/u/Marta)\
**Post date:** [March 28, 2019, 8:20am UTC](https://root-forum.cern.ch/t/thstack-does-not-stack-when-one-histogram-is-scaled/33336/5 "2019-03-28T08:20:08Z")

</div>

Ok, I think I solved the problem, and I guess it is the most stupid thing someone has ever posted here. The problem was that one of the histograms has, after scaling, far larger values than the other - so when I first stack the large one, and then the smaller one, with logarithmic axis I cannot see the smaller one, and it appears not to be there…  
Thank you for trying to help me and sorry for bothering you with such stupidity.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 28, 2019, 8:25am UTC](https://root-forum.cern.ch/t/thstack-does-not-stack-when-one-histogram-is-scaled/33336/6 "2019-03-28T08:25:55Z")

</div>

Ok no problem. Often posting a problem helps to resolve it. 🙂
