TH2


class description - source file - inheritance tree

class TH2 : public TH1


    protected:
virtual Int_t BufferFill(Axis_t, Stat_t) virtual Int_t BufferFill(Axis_t x, Axis_t y, Stat_t w) public:
TH2() TH2(const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup, Int_t nbinsy, Axis_t ylow, Axis_t yup) TH2(const char* name, const char* title, Int_t nbinsx, const Double_t* xbins, Int_t nbinsy, Axis_t ylow, Axis_t yup) TH2(const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup, Int_t nbinsy, const Double_t* ybins) TH2(const char* name, const char* title, Int_t nbinsx, const Double_t* xbins, Int_t nbinsy, const Double_t* ybins) TH2(const char* name, const char* title, Int_t nbinsx, const Float_t* xbins, Int_t nbinsy, const Float_t* ybins) TH2(const TH2&) virtual ~TH2() virtual Int_t BufferEmpty(Bool_t deleteBuffer = kFALSE) static TClass* Class() virtual void Copy(TObject& hnew) const virtual Int_t Fill(Axis_t) virtual Int_t Fill(const char*, Stat_t) virtual Int_t Fill(Axis_t x, Axis_t y) virtual Int_t Fill(Axis_t x, Axis_t y, Stat_t w) virtual Int_t Fill(Axis_t x, const char* namey, Stat_t w) virtual Int_t Fill(const char* namex, Axis_t y, Stat_t w) virtual Int_t Fill(const char* namex, const char* namey, Stat_t w) virtual void FillN(Int_t, const Axis_t*, const Double_t*, Int_t) virtual void FillN(Int_t ntimes, const Axis_t* x, const Axis_t* y, const Double_t* w, Int_t stride = 1) virtual void FillRandom(const char* fname, Int_t ntimes = 5000) virtual void FillRandom(TH1* h, Int_t ntimes = 5000) virtual void FitSlicesX(TF1* f1 = 0, Int_t binmin = 1, Int_t binmax = 0, Int_t cut = 0, Option_t* option = "QNR") virtual void FitSlicesY(TF1* f1 = 0, Int_t binmin = 1, Int_t binmax = 0, Int_t cut = 0, Option_t* option = "QNR") virtual Stat_t GetCorrelationFactor(Int_t axis1 = 1, Int_t axis2 = 2) const virtual Stat_t GetCovariance(Int_t axis1 = 1, Int_t axis2 = 2) const virtual void GetRandom2(Axis_t& x, Axis_t& y) virtual void GetStats(Stat_t* stats) const virtual Stat_t Integral(Option_t* option) const virtual Stat_t Integral(Int_t, Int_t, Option_t*) const virtual Stat_t Integral(Int_t binx1, Int_t binx2, Int_t biny1, Int_t biny2, Option_t* option) const virtual Stat_t Integral(Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Option_t*) const virtual TClass* IsA() const virtual Double_t KolmogorovTest(TH1* h2, Option_t* option) const virtual Int_t Merge(TCollection* list) TProfile* ProfileX(const char* name = "_pfx", Int_t firstybin = -1, Int_t lastybin = -1, Option_t* option) const TProfile* ProfileY(const char* name = "_pfy", Int_t firstxbin = -1, Int_t lastxbin = -1, Option_t* option) const TH1D* ProjectionX(const char* name = "_px", Int_t firstybin = -1, Int_t lastybin = -1, Option_t* option) const TH1D* ProjectionY(const char* name = "_py", Int_t firstxbin = -1, Int_t lastxbin = -1, Option_t* option) const virtual void PutStats(Stat_t* stats) virtual void Reset(Option_t* option) virtual void ShowMembers(TMemberInspector& insp, char* parent) virtual void Streamer(TBuffer& b) void StreamerNVirtual(TBuffer& b)

Data Members


    protected:
Stat_t fScalefactor Scale factor Stat_t fTsumwy Total Sum of weight*Y Stat_t fTsumwy2 Total Sum of weight*Y*Y Stat_t fTsumwxy Total Sum of weight*X*Y


See also

TH2C, TH2D, TH2F, TH2I, TH2S

Class Description

 Service class for 2-Dim histogram classes

  TH2C a 2-D histogram with one byte per cell (char)
  TH2S a 2-D histogram with two bytes per cell (short integer)
  TH2I a 2-D histogram with four bytes per cell (32 bits integer)
  TH2F a 2-D histogram with four bytes per cell (float)
  TH2D a 2-D histogram with eight bytes per cell (double)


TH2()

TH2(const char *name,const char *title,Int_t nbinsx,Axis_t xlow,Axis_t xup ,Int_t nbinsy,Axis_t ylow,Axis_t yup) :TH1(name,title,nbinsx,xlow,xup)
 see comments in the TH1 base class constructors

TH2(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins ,Int_t nbinsy,Axis_t ylow,Axis_t yup) :TH1(name,title,nbinsx,xbins)
 see comments in the TH1 base class constructors

TH2(const char *name,const char *title,Int_t nbinsx,Axis_t xlow,Axis_t xup ,Int_t nbinsy,const Double_t *ybins) :TH1(name,title,nbinsx,xlow,xup)
 see comments in the TH1 base class constructors

TH2(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins ,Int_t nbinsy,const Double_t *ybins) :TH1(name,title,nbinsx,xbins)
 see comments in the TH1 base class constructors

TH2(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins ,Int_t nbinsy,const Float_t *ybins) :TH1(name,title,nbinsx,xbins)
 see comments in the TH1 base class constructors

TH2(const TH2 &h) : TH1()
 Copy constructor.
 The list of functions is not copied. (Use Clone if needed)

~TH2()

Int_t BufferEmpty(Bool_t deleteBuffer)
 Fill histogram with all entries in the buffer.
 The buffer is deleted if deleteBuffer is true.

Int_t BufferFill(Axis_t x, Axis_t y, Stat_t w)
 accumulate arguments in buffer. When buffer is full, empty the buffer
 fBuffer[0] = number of entries in buffer
 fBuffer[1] = w of first entry
 fBuffer[2] = x of first entry
 fBuffer[3] = y of first entry

void Copy(TObject &obj) const

Int_t Fill(Axis_t x,Axis_t y)
*-*-*-*-*-*-*-*-*-*-*Increment cell defined by x,y by 1*-*-*-*-*-*-*-*-*-*
*-*                  ==================================
*-*
*-* if x or/and y is less than the low-edge of the corresponding axis first bin,
*-*   the Underflow cell is incremented.
*-* if x or/and y is greater than the upper edge of corresponding axis last bin,
*-*   the Overflow cell is incremented.
*-*
*-* If the storage of the sum of squares of weights has been triggered,
*-* via the function Sumw2, then the sum of the squares of weights is incremented
*-* by 1in the cell corresponding to x,y.
*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

Int_t Fill(Axis_t x, Axis_t y, Stat_t w)
*-*-*-*-*-*-*-*-*-*-*Increment cell defined by x,y by a weight w*-*-*-*-*-*
*-*                  ===========================================
*-*
*-* if x or/and y is less than the low-edge of the corresponding axis first bin,
*-*   the Underflow cell is incremented.
*-* if x or/and y is greater than the upper edge of corresponding axis last bin,
*-*   the Overflow cell is incremented.
*-*
*-* If the storage of the sum of squares of weights has been triggered,
*-* via the function Sumw2, then the sum of the squares of weights is incremented
*-* by w^2 in the cell corresponding to x,y.
*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

Int_t Fill(const char *namex, const char *namey, Stat_t w)
 Increment cell defined by namex,namey by a weight w

 if x or/and y is less than the low-edge of the corresponding axis first bin,
   the Underflow cell is incremented.
 if x or/and y is greater than the upper edge of corresponding axis last bin,
   the Overflow cell is incremented.

 If the storage of the sum of squares of weights has been triggered,
 via the function Sumw2, then the sum of the squares of weights is incremented
 by w^2 in the cell corresponding to x,y.


Int_t Fill(const char *namex, Axis_t y, Stat_t w)
 Increment cell defined by namex,y by a weight w

 if x or/and y is less than the low-edge of the corresponding axis first bin,
   the Underflow cell is incremented.
 if x or/and y is greater than the upper edge of corresponding axis last bin,
   the Overflow cell is incremented.

 If the storage of the sum of squares of weights has been triggered,
 via the function Sumw2, then the sum of the squares of weights is incremented
 by w^2 in the cell corresponding to x,y.


Int_t Fill(Axis_t x, const char *namey, Stat_t w)
 Increment cell defined by x,namey by a weight w

 if x or/and y is less than the low-edge of the corresponding axis first bin,
   the Underflow cell is incremented.
 if x or/and y is greater than the upper edge of corresponding axis last bin,
   the Overflow cell is incremented.

 If the storage of the sum of squares of weights has been triggered,
 via the function Sumw2, then the sum of the squares of weights is incremented
 by w^2 in the cell corresponding to x,y.


void FillN(Int_t ntimes, const Axis_t *x, const Axis_t *y, const Double_t *w, Int_t stride)
*-*-*-*-*-*-*Fill a 2-D histogram with an array of values and weights*-*-*-*
*-*          ========================================================
*-*
*-* ntimes:  number of entries in arrays x and w (array size must be ntimes*stride)
*-* x:       array of x values to be histogrammed
*-* y:       array of y values to be histogrammed
*-* w:       array of weights
*-* stride:  step size through arrays x, y and w
*-*
*-* If the storage of the sum of squares of weights has been triggered,
*-* via the function Sumw2, then the sum of the squares of weights is incremented
*-* by w[i]^2 in the cell corresponding to x[i],y[i].
*-* if w is NULL each entry is assumed a weight=1
*-*
*-* NB: function only valid for a TH2x object
*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

void FillRandom(const char *fname, Int_t ntimes)
*-*-*-*-*-*-*Fill histogram following distribution in function fname*-*-*-*
*-*          =======================================================
*-*
*-*   The distribution contained in the function fname (TF2) is integrated
*-*   over the channel contents.
*-*   It is normalized to 1.
*-*   Getting one random number implies:
*-*     - Generating a random number between 0 and 1 (say r1)
*-*     - Look in which bin in the normalized integral r1 corresponds to
*-*     - Fill histogram channel
*-*   ntimes random numbers are generated
*-*
*-*  One can also call TF2::GetRandom2 to get a random variate from a function.
*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*

void FillRandom(TH1 *h, Int_t ntimes)
*-*-*-*-*-*-*Fill histogram following distribution in histogram h*-*-*-*
*-*          ====================================================
*-*
*-*   The distribution contained in the histogram h (TH2) is integrated
*-*   over the channel contents.
*-*   It is normalized to 1.
*-*   Getting one random number implies:
*-*     - Generating a random number between 0 and 1 (say r1)
*-*     - Look in which bin in the normalized integral r1 corresponds to
*-*     - Fill histogram channel
*-*   ntimes random numbers are generated
*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*

void FitSlicesX(TF1 *f1, Int_t binmin, Int_t binmax, Int_t cut, Option_t *option)
 Project slices along X in case of a 2-D histogram, then fit each slice
 with function f1 and make a histogram for each fit parameter
 Only bins along Y between binmin and binmax are considered.
 if f1=0, a gaussian is assumed
 Before invoking this function, one can set a subrange to be fitted along X
 via f1->SetRange(xmin,xmax)
 The argument option (default="QNR") can be used to change the fit options.
     "Q" means Quiet mode
     "N" means do not show the result of the fit
     "R" means fit the function in the specified function range

 Note that the generated histograms are added to the list of objects
 in the current directory. It is the user's responsability to delete
 these histograms.

  Example: Assume a 2-d histogram h2
   Root > h2->FitSlicesX(); produces 4 TH1D histograms
          with h2_0 containing parameter 0(Constant) for a Gaus fit
                    of each bin in Y projected along X
          with h2_1 containing parameter 1(Mean) for a gaus fit
          with h2_2 containing parameter 2(RMS)  for a gaus fit
          with h2_chi2 containing the chisquare/number of degrees of freedom for a gaus fit

   Root > h2->FitSlicesX(0,15,22,10);
          same as above, but only for bins 15 to 22 along Y
          and only for bins in Y for which the corresponding projection
          along X has more than cut bins filled.

  NOTE: To access the generated histograms in the current directory, do eg:
     TH1D *h2_1 = (TH1D*)gDirectory->Get("h2_1");

void FitSlicesY(TF1 *f1, Int_t binmin, Int_t binmax, Int_t cut, Option_t *option)
 Project slices along Y in case of a 2-D histogram, then fit each slice
 with function f1 and make a histogram for each fit parameter
 Only bins along X between binmin and binmax are considered.
 if f1=0, a gaussian is assumed
 Before invoking this function, one can set a subrange to be fitted along Y
 via f1->SetRange(ymin,ymax)
 The argument option (default="QNR") can be used to change the fit options.
     "Q" means Quiet mode
     "N" means do not show the result of the fit
     "R" means fit the function in the specified function range

 Note that the generated histograms are added to the list of objects
 in the current directory. It is the user's responsability to delete
 these histograms.

  Example: Assume a 2-d histogram h2
   Root > h2->FitSlicesY(); produces 4 TH1D histograms
          with h2_0 containing parameter 0(Constant) for a Gaus fit
                    of each bin in X projected along Y
          with h2_1 containing parameter 1(Mean) for a gaus fit
          with h2_2 containing parameter 2(RMS)  for a gaus fit
          with h2_chi2 containing the chisquare/number of degrees of freedom for a gaus fit

   Root > h2->FitSlicesY(0,15,22,10);
          same as above, but only for bins 15 to 22 along X
          and only for bins in X for which the corresponding projection
          along Y has more than cut bins filled.

  NOTE: To access the generated histograms in the current directory, do eg:
     TH1D *h2_1 = (TH1D*)gDirectory->Get("h2_1");

 A complete example of this function is given in 
tutorial:fitslicesy.C
 with the following output:
/* */

Stat_t GetCorrelationFactor(Int_t axis1, Int_t axis2) const
*-*-*-*-*-*-*-*Return correlation factor between axis1 and axis2*-*-*-*-*
*-*            ====================================================

Stat_t GetCovariance(Int_t axis1, Int_t axis2) const
*-*-*-*-*-*-*-*Return covariance between axis1 and axis2*-*-*-*-*
*-*            ====================================================

void GetRandom2(Axis_t &x, Axis_t &y)
 return 2 random numbers along axis x and y distributed according
 the cellcontents of a 2-dim histogram

void GetStats(Stat_t *stats) const
 fill the array stats from the contents of this histogram
 The array stats must be correctly dimensionned in the calling program.
 stats[0] = sumw
 stats[1] = sumw2
 stats[2] = sumwx
 stats[3] = sumwx2
 stats[4] = sumwy
 stats[5] = sumwy2
 stats[6] = sumwxy

Stat_t Integral(Option_t *option) const
Return integral of bin contents. Only bins in the bins range are considered.
 By default the integral is computed as the sum of bin contents in the range.
 if option "width" is specified, the integral is the sum of
 the bin contents multiplied by the bin width in x and in y.

Stat_t Integral(Int_t binx1, Int_t binx2, Int_t biny1, Int_t biny2, Option_t *option) const
Return integral of bin contents in range [binx1,binx2],[biny1,biny2]
 for a 2-D histogram
 By default the integral is computed as the sum of bin contents in the range.
 if option "width" is specified, the integral is the sum of
 the bin contents multiplied by the bin width in x and in y.

Double_t KolmogorovTest(TH1 *h2, Option_t *option) const
  Statistical test of compatibility in shape between
  THIS histogram and h2, using Kolmogorov test.
     Default: Ignore under- and overflow bins in comparison

     option is a character string to specify options
         "U" include Underflows in test
         "O" include Overflows
         "N" include comparison of normalizations
         "D" Put out a line of "Debug" printout

   The returned function value is the probability of test
       (much less than one means NOT compatible)

  Code adapted by Rene Brun from original HBOOK routine HDIFF

Int_t Merge(TCollection *list)
Add all histograms in the collection to this histogram.
This function computes the min/max for the axes,
compute a new number of bins, if necessary,
add bin contents, errors and statistics.
The function returns the merged number of entries if the merge is
successfull, -1 otherwise.

IMPORTANT remark. The 2 axis x and y may have different number
of bins and different limits, BUT the largest bin width must be
a multiple of the smallest bin width.

TProfile* ProfileX(const char *name, Int_t firstybin, Int_t lastybin, Option_t *option) const
*-*-*-*-*Project a 2-D histogram into a profile histogram along X*-*-*-*-*-*
*-*      ========================================================

   The projection is made from the channels along the Y axis
   ranging from firstybin to lastybin included.
   By default, bins 1 to ny are included
   When all bins are included, the number of entries in the projection
   is set to the number of entries of the 2-D histogram, otherwise
   the number of entries is incremented by 1 for all non empty cells.

   if option "d" is specified, the profile is drawn in the current pad.

   NOTE that if a TProfile named name exists in the current directory or pad,
   the histogram is reset and filled again with the current contents of the TH2.

TProfile* ProfileY(const char *name, Int_t firstxbin, Int_t lastxbin, Option_t *option) const
*-*-*-*-*Project a 2-D histogram into a profile histogram along Y*-*-*-*-*-*
*-*      ========================================================

   The projection is made from the channels along the X axis
   ranging from firstxbin to lastxbin included.
   By default, bins 1 to nx are included
   When all bins are included, the number of entries in the projection
   is set to the number of entries of the 2-D histogram, otherwise
   the number of entries is incremented by 1 for all non empty cells.

   if option "d" is specified, the profile is drawn in the current pad.

   NOTE that if a TProfile named name exists in the current directory or pad,
   the histogram is reset and filled again with the current contents of the TH2.

TH1D* ProjectionX(const char *name, Int_t firstybin, Int_t lastybin, Option_t *option) const
*-*-*-*-*Project a 2-D histogram into a 1-D histogram along X*-*-*-*-*-*-*
*-*      ====================================================

   The projection is always of the type TH1D.
   The projection is made from the channels along the Y axis
   ranging from firstybin to lastybin included.
   By default, bins 1 to ny are included
   When all bins are included, the number of entries in the projection
   is set to the number of entries of the 2-D histogram, otherwise
   the number of entries is incremented by 1 for all non empty cells.

   To make the projection in X of the underflow bin in Y, use firstybin=lastybin=0;
   To make the projection in X of the overflow bin in Y, use firstybin=lastybin=ny+1;

   if option "e" is specified, the errors are computed.
   if option "d" is specified, the projection is drawn in the current pad.

   NOTE that if a TH1D named name exists in the current directory or pad,
   the histogram is reset and filled again with the current contents of the TH2.

TH1D* ProjectionY(const char *name, Int_t firstxbin, Int_t lastxbin, Option_t *option) const
*-*-*-*-*Project a 2-D histogram into a 1-D histogram along Y*-*-*-*-*-*-*
*-*      ====================================================

   The projection is always of the type TH1D.
   The projection is made from the channels along the X axis
   ranging from firstxbin to lastxbin included.
   By default, bins 1 to nx are included
   When all bins are included, the number of entries in the projection
   is set to the number of entries of the 2-D histogram, otherwise
   the number of entries is incremented by 1 for all non empty cells.

   To make the projection in Y of the underflow bin in X, use firstxbin=lastxbin=0;
   To make the projection in Y of the overflow bin in X, use firstxbin=lastxbin=nx+1;

   if option "e" is specified, the errors are computed.
   if option "d" is specified, the projection is drawn in the current pad.

   NOTE that if a TH1D named name exists in the current directory or pad,
   the histogram is reset and filled again with the current contents of the TH2.

void PutStats(Stat_t *stats)
 Replace current statistics with the values in array stats

void Reset(Option_t *option)
*-*-*-*-*-*-*-*Reset this histogram: contents, errors, etc*-*-*-*-*-*-*-*
*-*            ===========================================

void Streamer(TBuffer &R__b)
 Stream an object of class TH2.



Inline Functions


              Int_t BufferFill(Axis_t x, Axis_t y, Stat_t w)
              Int_t Fill(const char* namex, Axis_t y, Stat_t w)
              Int_t Fill(const char* namex, const char* namey, Stat_t w)
               void FillN(Int_t ntimes, const Axis_t* x, const Axis_t* y, const Double_t* w, Int_t stride = 1)
             Stat_t Integral(Int_t binx1, Int_t binx2, Int_t biny1, Int_t biny2, Option_t* option) const
             Stat_t Integral(Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Option_t*) const
            TClass* Class()
            TClass* IsA() const
               void ShowMembers(TMemberInspector& insp, char* parent)
               void StreamerNVirtual(TBuffer& b)


Author: Rene Brun 26/12/94
Last update: root/hist:$Name: $:$Id: TH2.cxx,v 1.47 2003/11/07 08:59:12 brun Exp $
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *


ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.