Problem with THStack

hi all

i’m having some problems with THStack. the fact is pretty strange because i’m using a simple code that has worked some time ago. the problem is that the stack does not draw the histograms one on top of the other, but “behind”. here is the code:

TFile* inFile = TFile::Open(“finalOutputFile.root”);

TH1D* h1_Rch = (TH1D*)inFile->Get(“Rch_vs_eta_PFItCone5”);
h1_Rch->GetYaxis()->SetRangeUser(0., 1.);

TH1D* h1_Rgamma = (TH1D*)inFile->Get(“Rgamma_vs_eta_PFItCone5”);
h1_Rgamma->GetYaxis()->SetRangeUser(0., 1.);

TH1D* h1_Rnh = (TH1D*)inFile->Get(“Rnh_vs_eta_PFItCone5”);
h1_Rnh->GetYaxis()->SetRangeUser(0., 1.);

THStack* stack = new THStack(“stack”, “”);
stack->Add(h1_Rch, “HIST”);
stack->Add(h1_Rgamma, “HIST”);
stack->Add(h1_Rnh, “HIST”);

does anybody have some ideas?


i forgot to add that the histograms i get from the inFile are TProfile’s that i get with a pointer to TH1D. this is the reason why i need to specify the drawing option “HIST” (bins have errors). could this be the problem?

Did you specify teh option “nostack” when calling stack.Draw() ?
see tutorial hstack.C


no, i don’t use nostack. but i solved the problem (without understanding how): when i use the nostack option, the histograms are actually drawn one on top of the other. in my problematic case, the thing was quite different. i noticed that the the three histograms that were drawn where different from the original ones.

i solved the problem by doing this: i get the TProfiles from the rootfile. the i create an additional TH1F for each TProfile and set the bin content of each bin of the TH1F equal to the bin content of the TProfile. then i add these TH1F’s to the stack and draw the stack. strangely enough, this works fine.

thank anyways,