Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TH3.h
Go to the documentation of this file.
1 // @(#)root/hist:$Id$
2 // Author: Rene Brun 27/10/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TH3
13 #define ROOT_TH3
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TH3 //
19 // //
20 // 3-Dim histogram base class. //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include "TH1.h"
25 
26 #include "TAtt3D.h"
27 
28 class TH2D;
29 class TProfile2D;
30 
31 class TH3 : public TH1, public TAtt3D {
32 
33 protected:
34  Double_t fTsumwy; //Total Sum of weight*Y
35  Double_t fTsumwy2; //Total Sum of weight*Y*Y
36  Double_t fTsumwxy; //Total Sum of weight*X*Y
37  Double_t fTsumwz; //Total Sum of weight*Z
38  Double_t fTsumwz2; //Total Sum of weight*Z*Z
39  Double_t fTsumwxz; //Total Sum of weight*X*Z
40  Double_t fTsumwyz; //Total Sum of weight*Y*Z
41 
42  TH3();
43  TH3(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
44  ,Int_t nbinsy,Double_t ylow,Double_t yup
45  ,Int_t nbinsz,Double_t zlow,Double_t zup);
46  TH3(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
47  ,Int_t nbinsy,const Float_t *ybins
48  ,Int_t nbinsz,const Float_t *zbins);
49  TH3(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
50  ,Int_t nbinsy,const Double_t *ybins
51  ,Int_t nbinsz,const Double_t *zbins);
52  virtual Int_t BufferFill(Double_t x, Double_t y, Double_t z, Double_t w);
53 
54  void DoFillProfileProjection(TProfile2D * p2, const TAxis & a1, const TAxis & a2, const TAxis & a3, Int_t bin1, Int_t bin2, Int_t bin3, Int_t inBin, Bool_t useWeights) const;
55 
56  virtual Int_t BufferFill(Double_t, Double_t) {return -2;} //may not use
57  virtual Int_t BufferFill(Double_t, Double_t, Double_t) {return -2;} //may not use
58  Int_t Fill(Double_t); //MayNotUse
59  Int_t Fill(Double_t,Double_t) {return Fill(0.);} //MayNotUse
60  Int_t Fill(const char*, Double_t) {return Fill(0);} //MayNotUse
61  Int_t Fill(Double_t,const char*,Double_t) {return Fill(0);} //MayNotUse
62  Int_t Fill(const char*,Double_t,Double_t) {return Fill(0);} //MayNotUse
63  Int_t Fill(const char*,const char*,Double_t) {return Fill(0);} //MayNotUse
64 
65  virtual Double_t Interpolate(Double_t x, Double_t y) const; // May not use
66  virtual Double_t Interpolate(Double_t x) const; // MayNotUse
67 
68 private:
69 
70  TH3(const TH3&);
71  TH3& operator=(const TH3&); // Not implemented
72 
73  using TH1::Integral;
74  using TH1::IntegralAndError;
75 
76 public:
77  virtual ~TH3();
78  virtual Int_t BufferEmpty(Int_t action=0);
79  virtual void Copy(TObject &hnew) const;
80  virtual Int_t Fill(Double_t x, Double_t y, Double_t z);
81  virtual Int_t Fill(Double_t x, Double_t y, Double_t z, Double_t w);
82 
83  virtual Int_t Fill(const char *namex, const char *namey, const char *namez, Double_t w);
84  virtual Int_t Fill(const char *namex, Double_t y, const char *namez, Double_t w);
85  virtual Int_t Fill(const char *namex, const char *namey, Double_t z, Double_t w);
86  virtual Int_t Fill(Double_t x, const char *namey, const char *namez, Double_t w);
87  virtual Int_t Fill(Double_t x, const char *namey, Double_t z, Double_t w);
88  virtual Int_t Fill(Double_t x, Double_t y, const char *namez, Double_t w);
89 
90  virtual void FillRandom(const char *fname, Int_t ntimes=5000);
91  virtual void FillRandom(TH1 *h, Int_t ntimes=5000);
92  virtual void FitSlicesZ(TF1 *f1=0,Int_t binminx=1, Int_t binmaxx=0,Int_t binminy=1, Int_t binmaxy=0,
93  Int_t cut=0 ,Option_t *option="QNR"); // *MENU*
94  virtual Int_t GetBin(Int_t binx, Int_t biny, Int_t binz) const;
95  virtual Double_t GetBinContent(Int_t bin) const { return TH1::GetBinContent(bin); }
96  virtual Double_t GetBinContent(Int_t bin, Int_t) const { return TH1::GetBinContent(bin); }
97  virtual Double_t GetBinContent(Int_t binx, Int_t biny, Int_t binz) const { return TH1::GetBinContent( GetBin(binx, biny, binz) ); }
98  using TH1::GetBinErrorLow;
99  using TH1::GetBinErrorUp;
100  virtual Double_t GetBinErrorLow(Int_t binx, Int_t biny, Int_t binz) { return TH1::GetBinErrorLow( GetBin(binx, biny, binz) ); }
101  virtual Double_t GetBinErrorUp(Int_t binx, Int_t biny, Int_t binz) { return TH1::GetBinErrorUp( GetBin(binx, biny, binz) ); }
102  virtual Double_t GetBinWithContent3(Double_t c, Int_t &binx, Int_t &biny, Int_t &binz, Int_t firstx=0, Int_t lastx=0,Int_t firsty=0, Int_t lasty=0, Int_t firstz=0, Int_t lastz=0, Double_t maxdiff=0) const;
103  virtual Double_t GetCorrelationFactor(Int_t axis1=1,Int_t axis2=2) const;
104  virtual Double_t GetCovariance(Int_t axis1=1,Int_t axis2=2) const;
105  virtual void GetRandom3(Double_t &x, Double_t &y, Double_t &z);
106  virtual void GetStats(Double_t *stats) const;
107  virtual Double_t Integral(Option_t *option="") const;
108  virtual Double_t Integral(Int_t binx1, Int_t binx2, Int_t biny1, Int_t biny2, Int_t binz1, Int_t binz2, Option_t *option="") const;
109  virtual Double_t IntegralAndError(Int_t binx1, Int_t binx2, Int_t biny1, Int_t biny2, Int_t binz1, Int_t binz2, Double_t & err, Option_t *option="") const;
110  virtual Double_t Interpolate(Double_t x, Double_t y, Double_t z) const;
111  virtual Double_t KolmogorovTest(const TH1 *h2, Option_t *option="") const;
112  virtual TH1D *ProjectionX(const char *name="_px", Int_t iymin=0, Int_t iymax=-1, Int_t izmin=0,
113  Int_t izmax=-1, Option_t *option="") const; // *MENU*
114  virtual TH1D *ProjectionY(const char *name="_py", Int_t ixmin=0, Int_t ixmax=-1, Int_t izmin=0,
115  Int_t izmax=-1, Option_t *option="") const; // *MENU*
116  virtual TH1D *ProjectionZ(const char *name="_pz", Int_t ixmin=0, Int_t ixmax=-1, Int_t iymin=0,
117  Int_t iymax=-1, Option_t *option="") const; // *MENU*
118  virtual TH1 *Project3D(Option_t *option="x") const; // *MENU*
119  virtual TProfile2D *Project3DProfile(Option_t *option="xy") const; // *MENU*
120  virtual void PutStats(Double_t *stats);
121  virtual TH3 *RebinX(Int_t ngroup = 2, const char *newname = "");
122  virtual TH3 *RebinY(Int_t ngroup = 2, const char *newname = "");
123  virtual TH3 *RebinZ(Int_t ngroup = 2, const char *newname = "");
124  virtual TH3 *Rebin3D(Int_t nxgroup = 2, Int_t nygroup = 2, Int_t nzgroup = 2, const char *newname = "");
125  virtual void Reset(Option_t *option="");
126  virtual void SetBinContent(Int_t bin, Double_t content);
127  virtual void SetBinContent(Int_t bin, Int_t, Double_t content) { SetBinContent(bin, content); }
128  virtual void SetBinContent(Int_t binx, Int_t biny, Int_t binz, Double_t content) { SetBinContent(GetBin(binx, biny, binz), content); }
129  virtual void SetShowProjection(const char *option="xy",Int_t nbins=1); // *MENU*
130 
131 protected:
132 
133  virtual TH1D *DoProject1D(const char* name, const char * title, int imin1, int imax1, int imin2, int imax2,
134  const TAxis* projAxis, const TAxis * axis1, const TAxis * axis2, Option_t * option) const;
135  virtual TH1D *DoProject1D(const char *name, const char *title, const TAxis *projAxis, const TAxis *axis1,
136  const TAxis *axis2, bool computeErrors, bool originalRange, bool useUF, bool useOF) const;
137  virtual TH2D *DoProject2D(const char* name, const char * title, const TAxis* projX, const TAxis* projY,
138  bool computeErrors, bool originalRange,
139  bool useUF, bool useOF) const;
140  virtual TProfile2D *DoProjectProfile2D(const char* name, const char * title, const TAxis* projX, const TAxis* projY,
141  bool originalRange, bool useUF, bool useOF) const;
142 
143  // these functions are need to be used inside TProfile3D::DoProjectProfile2D
144  static TH1D *DoProject1D(const TH3 & h, const char* name, const char * title, const TAxis* projX,
145  bool computeErrors, bool originalRange, bool useUF, bool useOF) {
146  return h.DoProject1D(name, title, projX, nullptr, nullptr, computeErrors, originalRange, useUF, useOF);
147  }
148  static TH2D *DoProject2D(const TH3 & h, const char* name, const char * title, const TAxis* projX, const TAxis* projY,
149  bool computeErrors, bool originalRange, bool useUF, bool useOF) {
150  return h.DoProject2D(name, title, projX,projY, computeErrors, originalRange, useUF, useOF);
151  }
152 
153  ClassDef(TH3,6) //3-Dim histogram base class
154 };
155 
156 //________________________________________________________________________
157 
158 class TH3C : public TH3, public TArrayC {
159 public:
160  TH3C();
161  TH3C(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
162  ,Int_t nbinsy,Double_t ylow,Double_t yup
163  ,Int_t nbinsz,Double_t zlow,Double_t zup);
164  TH3C(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
165  ,Int_t nbinsy,const Float_t *ybins
166  ,Int_t nbinsz,const Float_t *zbins);
167  TH3C(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
168  ,Int_t nbinsy,const Double_t *ybins
169  ,Int_t nbinsz,const Double_t *zbins);
170  TH3C(const TH3C &h3c);
171  virtual ~TH3C();
172  virtual void AddBinContent(Int_t bin);
173  virtual void AddBinContent(Int_t bin, Double_t w);
174  virtual void Copy(TObject &hnew) const;
175  virtual void Reset(Option_t *option="");
176  virtual void SetBinsLength(Int_t n=-1);
177  TH3C& operator=(const TH3C &h1);
178  friend TH3C operator*(Float_t c1, TH3C &h1);
179  friend TH3C operator*(TH3C &h1, Float_t c1) {return operator*(c1,h1);}
180  friend TH3C operator+(TH3C &h1, TH3C &h2);
181  friend TH3C operator-(TH3C &h1, TH3C &h2);
182  friend TH3C operator*(TH3C &h1, TH3C &h2);
183  friend TH3C operator/(TH3C &h1, TH3C &h2);
184 
185 protected:
186  virtual Double_t RetrieveBinContent(Int_t bin) const { return Double_t (fArray[bin]); }
187  virtual void UpdateBinContent(Int_t bin, Double_t content) { fArray[bin] = Char_t (content); }
188 
189  ClassDef(TH3C,4) //3-Dim histograms (one char per channel)
190 };
191 
192 //________________________________________________________________________
193 
194 class TH3S : public TH3, public TArrayS {
195 public:
196  TH3S();
197  TH3S(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
198  ,Int_t nbinsy,Double_t ylow,Double_t yup
199  ,Int_t nbinsz,Double_t zlow,Double_t zup);
200  TH3S(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
201  ,Int_t nbinsy,const Float_t *ybins
202  ,Int_t nbinsz,const Float_t *zbins);
203  TH3S(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
204  ,Int_t nbinsy,const Double_t *ybins
205  ,Int_t nbinsz,const Double_t *zbins);
206  TH3S(const TH3S &h3s);
207  virtual ~TH3S();
208  virtual void AddBinContent(Int_t bin);
209  virtual void AddBinContent(Int_t bin, Double_t w);
210  virtual void Copy(TObject &hnew) const;
211  virtual void Reset(Option_t *option="");
212  virtual void SetBinsLength(Int_t n=-1);
213  TH3S& operator=(const TH3S &h1);
214  friend TH3S operator*(Float_t c1, TH3S &h1);
215  friend TH3S operator*(TH3S &h1, Float_t c1) {return operator*(c1,h1);}
216  friend TH3S operator+(TH3S &h1, TH3S &h2);
217  friend TH3S operator-(TH3S &h1, TH3S &h2);
218  friend TH3S operator*(TH3S &h1, TH3S &h2);
219  friend TH3S operator/(TH3S &h1, TH3S &h2);
220 
221 protected:
222  virtual Double_t RetrieveBinContent(Int_t bin) const { return Double_t (fArray[bin]); }
223  virtual void UpdateBinContent(Int_t bin, Double_t content) { fArray[bin] = Short_t (content); }
224 
225  ClassDef(TH3S,4) //3-Dim histograms (one short per channel)
226 };
227 
228 //________________________________________________________________________
229 
230 class TH3I : public TH3, public TArrayI {
231 public:
232  TH3I();
233  TH3I(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
234  ,Int_t nbinsy,Double_t ylow,Double_t yup
235  ,Int_t nbinsz,Double_t zlow,Double_t zup);
236  TH3I(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
237  ,Int_t nbinsy,const Float_t *ybins
238  ,Int_t nbinsz,const Float_t *zbins);
239  TH3I(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
240  ,Int_t nbinsy,const Double_t *ybins
241  ,Int_t nbinsz,const Double_t *zbins);
242  TH3I(const TH3I &h3i);
243  virtual ~TH3I();
244  virtual void AddBinContent(Int_t bin);
245  virtual void AddBinContent(Int_t bin, Double_t w);
246  virtual void Copy(TObject &hnew) const;
247  virtual void Reset(Option_t *option="");
248  virtual void SetBinsLength(Int_t n=-1);
249  TH3I& operator=(const TH3I &h1);
250  friend TH3I operator*(Float_t c1, TH3I &h1);
251  friend TH3I operator*(TH3I &h1, Float_t c1) {return operator*(c1,h1);}
252  friend TH3I operator+(TH3I &h1, TH3I &h2);
253  friend TH3I operator-(TH3I &h1, TH3I &h2);
254  friend TH3I operator*(TH3I &h1, TH3I &h2);
255  friend TH3I operator/(TH3I &h1, TH3I &h2);
256 
257 protected:
258  virtual Double_t RetrieveBinContent(Int_t bin) const { return Double_t (fArray[bin]); }
259  virtual void UpdateBinContent(Int_t bin, Double_t content) { fArray[bin] = Int_t (content); }
260 
261  ClassDef(TH3I,4) //3-Dim histograms (one 32 bits integer per channel)
262 };
263 
264 
265 //________________________________________________________________________
266 
267 class TH3F : public TH3, public TArrayF {
268 public:
269  TH3F();
270  TH3F(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
271  ,Int_t nbinsy,Double_t ylow,Double_t yup
272  ,Int_t nbinsz,Double_t zlow,Double_t zup);
273  TH3F(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
274  ,Int_t nbinsy,const Float_t *ybins
275  ,Int_t nbinsz,const Float_t *zbins);
276  TH3F(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
277  ,Int_t nbinsy,const Double_t *ybins
278  ,Int_t nbinsz,const Double_t *zbins);
279  TH3F(const TH3F &h3f);
280  virtual ~TH3F();
281  virtual void AddBinContent(Int_t bin) {++fArray[bin];}
282  virtual void AddBinContent(Int_t bin, Double_t w)
283  {fArray[bin] += Float_t (w);}
284  virtual void Copy(TObject &hnew) const;
285  virtual void Reset(Option_t *option="");
286  virtual void SetBinsLength(Int_t n=-1);
287  TH3F& operator=(const TH3F &h1);
288  friend TH3F operator*(Float_t c1, TH3F &h1);
289  friend TH3F operator*(TH3F &h1, Float_t c1) {return operator*(c1,h1);}
290  friend TH3F operator+(TH3F &h1, TH3F &h2);
291  friend TH3F operator-(TH3F &h1, TH3F &h2);
292  friend TH3F operator*(TH3F &h1, TH3F &h2);
293  friend TH3F operator/(TH3F &h1, TH3F &h2);
294 
295 protected:
296  virtual Double_t RetrieveBinContent(Int_t bin) const { return Double_t (fArray[bin]); }
297  virtual void UpdateBinContent(Int_t bin, Double_t content) { fArray[bin] = Float_t (content); }
298 
299  ClassDef(TH3F,4) //3-Dim histograms (one float per channel)
300 };
301 
302 //________________________________________________________________________
303 
304 class TH3D : public TH3, public TArrayD {
305 public:
306  TH3D();
307  TH3D(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
308  ,Int_t nbinsy,Double_t ylow,Double_t yup
309  ,Int_t nbinsz,Double_t zlow,Double_t zup);
310  TH3D(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
311  ,Int_t nbinsy,const Float_t *ybins
312  ,Int_t nbinsz,const Float_t *zbins);
313  TH3D(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
314  ,Int_t nbinsy,const Double_t *ybins
315  ,Int_t nbinsz,const Double_t *zbins);
316  TH3D(const TH3D &h3d);
317  virtual ~TH3D();
318  virtual void AddBinContent(Int_t bin) {++fArray[bin];}
319  virtual void AddBinContent(Int_t bin, Double_t w)
320  {fArray[bin] += Double_t (w);}
321  virtual void Copy(TObject &hnew) const;
322  virtual void Reset(Option_t *option="");
323  virtual void SetBinsLength(Int_t n=-1);
324  TH3D& operator=(const TH3D &h1);
325  friend TH3D operator*(Float_t c1, TH3D &h1);
326  friend TH3D operator*(TH3D &h1, Float_t c1) {return operator*(c1,h1);}
327  friend TH3D operator+(TH3D &h1, TH3D &h2);
328  friend TH3D operator-(TH3D &h1, TH3D &h2);
329  friend TH3D operator*(TH3D &h1, TH3D &h2);
330  friend TH3D operator/(TH3D &h1, TH3D &h2);
331 
332 protected:
333  virtual Double_t RetrieveBinContent(Int_t bin) const { return fArray[bin]; }
334  virtual void UpdateBinContent(Int_t bin, Double_t content) { fArray[bin] = content; }
335 
336  ClassDef(TH3D,4) //3-Dim histograms (one double per channel)
337 };
338 
339 #endif