User Tools

Site Tools


root:thstack

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

root:thstack [2012/08/16 11:58] (current)
nchiap created
Line 1: Line 1:
 +====== Using and Troubleshooting THStack ======
 +
 +===== Basic Code =====
 +<code c++>
 +  TH1F *h;
 +  THStack *hs = new THStack("​hs","​Stacked 1D histograms"​);​
 +  //create three 1-d histograms
 +  for (int i = 0; i < 3; i++) {
 +    h = new TH1F("​h"​+i,"​test hstack",​100,​-4,​4);​
 +    h->​FillRandom("​gaus",​20000-i*5000);​
 +    h->​SetFillColor(i+2);​
 +    h->​SetMarkerColor(i+2);​
 +    hs->​Add(h);​
 +  }
 +  TCanvas *cst = new TCanvas("​cst","​stacked hists",​10,​10,​700,​700);​
 +  cst->​SetFillColor(41);​
 +  hs->​Draw()
 +</​code>​
 +
 +===== Troubleshooting =====
 +==== Y Axis Range ====
 +see [[root:​setaxisrange#​y_axis_of_a_thstack | Set Display Range of Axis]]
 +
 +==== Scaling/​Normalising Histograms ====
 +**Do not use** ''​SetNormFactor(normFactor)''​! ​
 +
 +If ''​SetNormFactor''​ on a histogram has been called, this histogram will not be stacked, but is painted seperately (as with ''​nostack''​).
 +Instead use the following code to normalise histogram ''​h''​
 +<code c++>
 +h->​Scale(normFactor/​h->​Integral());​
 +</​code>​
 +
 +
 +
  
root/thstack.txt ยท Last modified: 2012/08/16 11:58 by nchiap