library: libHist #include "THStack.h"

# THStack

class description - source file - inheritance tree (.pdf)

## class THStack : public TNamed

| Inheritance Chart:
`TObject`
| <- | `TNamed`
| <- | `THStack` |

        protected:

          void BuildStack()

        public:

                           THStack()
                           THStack(const char* name, const char* title)
                           THStack(const TH1* hist, Option_t* axis = "x", const char* name = "0", const char* title = "0", Int_t firstbin = -1, Int_t lastbin = -1, Int_t firstbin2 = -1, Int_t lastbin2 = -1, Option_t* proj_option = "", Option_t* draw_option = "")
                           THStack(const THStack& hstack)
                   virtual ~THStack()
              virtual void Add(TH1* h, Option_t* option = "")
              virtual void Browse(TBrowser* b)
            static TClass* Class()
             virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
              virtual void Draw(Option_t* chopt = "")
                      TH1* GetHistogram() const
                    TList* GetHists() const
          virtual Double_t GetMaximum(Option_t* option = "")
          virtual Double_t GetMinimum(Option_t* option = "")
                TObjArray* GetStack()
                    TAxis* GetXaxis() const
                    TAxis* GetYaxis() const
           virtual TClass* IsA() const
              virtual void ls(Option_t* option = "") const
              virtual void Modified()
                  THStack& operator=(const THStack&)
              virtual void Paint(Option_t* chopt = "")
              virtual void Print(Option_t* chopt = "") const
              virtual void RecursiveRemove(TObject* obj)
              virtual void SavePrimitive(ofstream& out, Option_t* option)
              virtual void SetMaximum(Double_t maximum = -1111)
              virtual void SetMinimum(Double_t minimum = -1111)
              virtual void ShowMembers(TMemberInspector& insp, char* parent)
              virtual void Streamer(TBuffer& b)
                      void StreamerNVirtual(TBuffer& b)

### Data Members

        protected:

              TList* fHists      Pointer to array of TH1
          TObjArray* fStack      !Pointer to array of sums of TH1
                TH1* fHistogram  !Pointer to histogram used for drawing axis
            Double_t fMaximum    Maximum value for plotting along y
            Double_t fMinimum    Minimum value for plotting along y

## Class Description

       A THStack is a collection of TH1 (or derived) objects
       Use THStack::Add to add a new histogram to the list.
       The THStack owns the objects in the list.
       By default (if option "nostack" is not specified), histograms will be paint
       stacked on top of each other.
       Example;
          THStack hs("hs","test stacked histograms");
          TH1F *h1 = new TH1F("h1","test hstack",100,-4,4);
          h1->FillRandom("gaus",20000);
          h1->SetFillColor(kRed);
          hs.Add(h1);
          TH1F *h2 = new TH1F("h2","test hstack",100,-4,4);
          h2->FillRandom("gaus",15000);
          h2->SetFillColor(kBlue);
          hs.Add(h2);
          TH1F *h3 = new TH1F("h3","test hstack",100,-4,4);
          h3->FillRandom("gaus",10000);
          h3->SetFillColor(kGreen);
          hs.Add(h3);
          TCanvas c1("c1","stacked hists",10,10,700,900);
          c1.Divide(1,2);
          c1.cd(1);
          hs.Draw();
          c1.cd(2);
          hs->Draw("nostack");

      See a more complex example in $ROOTSYS/tutorials/hstack.C

      Note that picking is supported for all drawing modes.

THStack(): TNamed()

     THStack default constructor

THStack(const char *name, const char *title) : TNamed(name,title)

     constructor with name and title

THStack(const TH1* hist, Option_t *axis /*="x"*/, const char *name /*=0*/, const char *title /*=0*/, Int_t firstbin /*=-1*/, Int_t lastbin /*=-1*/, Int_t firstbin2 /*=-1*/, Int_t lastbin2 /*=-1*/, Option_t* proj_option /*=""*/, Option_t* draw_option /*=""*/): TNamed(name, title)

     Creates a new THStack from a TH2 or TH3
     It is filled with the 1D histograms from GetProjectionX or GetProjectionY
     for each bin of the histogram. It illustrates the differences and total
     sum along an axis.

     Parameters:
     - hist:  the histogram used for the projections. Can be an object deriving
              from TH2 or TH3.
     - axis:  for TH2: "x" for ProjectionX, "y" for ProjectionY.
              for TH3: see TH3::Project3D.
     - name:  fName is set to name if given, otherwise to histo's name with
              "_stack_<axis>" appended, where <axis> is the value of the
              parameter axis.
     - title: fTitle is set to title if given, otherwise to histo's title
              with ", stack of <axis> projections" appended.
     - firstbin, lastbin:
              for each bin within [firstbin,lastbin] a stack entry is created.
              See TH2::ProjectionX/Y for use overflow bins.
              Defaults to "all bins"
     - firstbin2, lastbin2:
              Other axis range for TH3::Project3D, defaults to "all bins".
              Ignored for TH2s
     - proj_option:
              option passed to TH2::ProjectionX/Y and TH3::Project3D (along
              with axis)
     - draw_option:
              option passed to THStack::Add.

~THStack()

     THStack destructor

THStack(const THStack &hstack) : TNamed(hstack)

     THStack copy constructor

void Add(TH1 *h1, Option_t *option)

     add a new histogram to the list
     Only 1-d and 2-d histograms currently supported.
     A drawing option may be specified

void Browse(TBrowser *b)

void BuildStack()

      build sum of all histograms
      Build a separate list fStack containing the running sum of all histograms

Int_t DistancetoPrimitive(Int_t px, Int_t py)

     Compute distance from point px,py to each graph

void Draw(Option_t *option)

    *-*-*-*-*-*-*-*-*-*-*Draw this multihist with its current attributes*-*-*-*-*-*-*
    *-*                  ==========================================

       Options to draw histograms  are described in THistPainter::Paint
     By default (if option "nostack" is not specified), histograms will be paint
     stacked on top of each other.

TH1* GetHistogram() const

        Returns a pointer to the histogram used to draw the axis
        Takes into account the two following cases.
           1- option 'A' was specified in THStack::Draw. Return fHistogram
           2- user had called TPad::DrawFrame. return pointer to hframe histogram

     IMPORTANT NOTE
      You must call Draw before calling this function. The returned histogram
      depends on the selected Draw options.

Double_t GetMaximum(Option_t *option)

      returns the maximum of all added histograms
      returns the maximum of all histograms if option "nostack".

Double_t GetMinimum(Option_t *option)

      returns the minimum of all added histograms
      returns the minimum of all histograms if option "nostack".

TObjArray* GetStack()

     Return pointer to Stack. Build it if not yet done

TAxis* GetXaxis() const

     Get x axis of the histogram used to draw the stack.

     IMPORTANT NOTE
      You must call Draw before calling this function. The returned histogram
      depends on the selected Draw options.

TAxis* GetYaxis() const

     Get x axis of the histogram used to draw the stack.

     IMPORTANT NOTE
      You must call Draw before calling this function. The returned histogram
      depends on the selected Draw options.

void ls(Option_t *option) const

     List histograms in the stack

void Modified()

     invalidate sum of histograms

void Paint(Option_t *option)

     paint the list of histograms
     By default, histograms are shown stacked.
        -the first histogram is paint
        -then the sum of the first and second, etc

     If option "nostack" is specified, histograms are all paint in the same pad
     as if the option "same" had been specified.

     if option "pads" is specified, the current pad/canvas is subdivided into
     a number of pads equal to the number of histograms and each histogram
     is paint into a separate pad.

     See THistPainter::Paint for a list of valid options.

void Print(Option_t *option) const

     Print the list of histograms

void RecursiveRemove(TObject *obj)

     Recursively remove object from the list of histograms

void SavePrimitive(ofstream &out, Option_t *option)

     Save primitive as a C++ statement(s) on output stream out

void SetMaximum(Double_t maximum)

void SetMinimum(Double_t minimum)

### Inline Functions

                 TList* GetHists() const
                TClass* Class()
                TClass* IsA() const
                   void ShowMembers(TMemberInspector& insp, char* parent)
                   void Streamer(TBuffer& b)
                   void StreamerNVirtual(TBuffer& b)
               THStack& operator=(const THStack&)

Author: Rene Brun 10/12/2001
Last update: root/hist:$Name: $:$Id: THStack.cxx,v 1.35 2005/03/08 17:43:54 brun Exp $
Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. *