Logo ROOT   6.08/07
Reference Guide
TH3.cxx
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 #include "TROOT.h"
13 #include "TClass.h"
14 #include "THashList.h"
15 #include "TH3.h"
16 #include "TProfile2D.h"
17 #include "TH2.h"
18 #include "TF1.h"
19 #include "TVirtualPad.h"
20 #include "TVirtualHistPainter.h"
21 #include "THLimitsFinder.h"
22 #include "TRandom.h"
23 #include "TError.h"
24 #include "TMath.h"
25 #include "TObjString.h"
26 
28 
29 /** \addtogroup Hist
30 @{
31 \class TH3C
32 \brief tomato 3-D histogram with a byte per channel (see TH1 documentation)
33 \class TH3S
34 \brief tomato 3-D histogram with a short per channel (see TH1 documentation)
35 \class TH3I
36 \brief tomato 3-D histogram with an int per channel (see TH1 documentation)}
37 \class TH3F
38 \brief tomato 3-D histogram with a float per channel (see TH1 documentation)}
39 \class TH3D
40 \brief tomato 3-D histogram with a double per channel (see TH1 documentation)}
41 @}
42 */
43 
44 /** \class TH3
45  \ingroup Hist
46 The 3-D histogram classes derived from the 1-D histogram classes.
47 All operations are supported (fill, fit).
48 Drawing is currently restricted to one single option.
49 A cloud of points is drawn. The number of points is proportional to
50 cell content.
51 
52 - TH3C a 3-D histogram with one byte per cell (char)
53 - TH3S a 3-D histogram with two bytes per cell (short integer)
54 - TH3I a 3-D histogram with four bytes per cell (32 bits integer)
55 - TH3F a 3-D histogram with four bytes per cell (float)
56 - TH3D a 3-D histogram with eight bytes per cell (double)
57 */
58 
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Default constructor.
62 
63 TH3::TH3()
64 {
65  fDimension = 3;
66  fTsumwy = fTsumwy2 = fTsumwxy = 0;
67  fTsumwz = fTsumwz2 = fTsumwxz = fTsumwyz = 0;
68 }
69 
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// Normal constructor for fix bin size 3-D histograms.
73 
74 TH3::TH3(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
75  ,Int_t nbinsy,Double_t ylow,Double_t yup
76  ,Int_t nbinsz,Double_t zlow,Double_t zup)
77  :TH1(name,title,nbinsx,xlow,xup),
78  TAtt3D()
79 {
80  fDimension = 3;
81  if (nbinsy <= 0) {Warning("TH3","nbinsy is <=0 - set to nbinsy = 1"); nbinsy = 1; }
82  if (nbinsz <= 0) nbinsz = 1;
83  fYaxis.Set(nbinsy,ylow,yup);
84  fZaxis.Set(nbinsz,zlow,zup);
85  fNcells = (nbinsx+2)*(nbinsy+2)*(nbinsz+2);
86  fTsumwy = fTsumwy2 = fTsumwxy = 0;
88 }
89 
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 /// Normal constructor for variable bin size 3-D histograms.
93 
94 TH3::TH3(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
95  ,Int_t nbinsy,const Float_t *ybins
96  ,Int_t nbinsz,const Float_t *zbins)
97  :TH1(name,title,nbinsx,xbins),
98  TAtt3D()
99 {
100  fDimension = 3;
101  if (nbinsy <= 0) {Warning("TH3","nbinsy is <=0 - set to nbinsy = 1"); nbinsy = 1; }
102  if (nbinsz <= 0) nbinsz = 1;
103  if (ybins) fYaxis.Set(nbinsy,ybins);
104  else fYaxis.Set(nbinsy,0,1);
105  if (zbins) fZaxis.Set(nbinsz,zbins);
106  else fZaxis.Set(nbinsz,0,1);
107  fNcells = (nbinsx+2)*(nbinsy+2)*(nbinsz+2);
108  fTsumwy = fTsumwy2 = fTsumwxy = 0;
109  fTsumwz = fTsumwz2 = fTsumwxz = fTsumwyz = 0;
110 }
111 
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Normal constructor for variable bin size 3-D histograms.
115 
116 TH3::TH3(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
117  ,Int_t nbinsy,const Double_t *ybins
118  ,Int_t nbinsz,const Double_t *zbins)
119  :TH1(name,title,nbinsx,xbins),
120  TAtt3D()
121 {
122  fDimension = 3;
123  if (nbinsy <= 0) {Warning("TH3","nbinsy is <=0 - set to nbinsy = 1"); nbinsy = 1; }
124  if (nbinsz <= 0) nbinsz = 1;
125  if (ybins) fYaxis.Set(nbinsy,ybins);
126  else fYaxis.Set(nbinsy,0,1);
127  if (zbins) fZaxis.Set(nbinsz,zbins);
128  else fZaxis.Set(nbinsz,0,1);
129  fNcells = (nbinsx+2)*(nbinsy+2)*(nbinsz+2);
130  fTsumwy = fTsumwy2 = fTsumwxy = 0;
131  fTsumwz = fTsumwz2 = fTsumwxz = fTsumwyz = 0;
132 }
133 
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 /// Copy constructor.
137 /// The list of functions is not copied. (Use Clone if needed)
138 
139 TH3::TH3(const TH3 &h) : TH1(), TAtt3D()
140 {
141  ((TH3&)h).Copy(*this);
142 }
143 
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Destructor.
147 
149 {
150 }
151 
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// Copy.
155 
156 void TH3::Copy(TObject &obj) const
157 {
158  TH1::Copy(obj);
159  ((TH3&)obj).fTsumwy = fTsumwy;
160  ((TH3&)obj).fTsumwy2 = fTsumwy2;
161  ((TH3&)obj).fTsumwxy = fTsumwxy;
162  ((TH3&)obj).fTsumwz = fTsumwz;
163  ((TH3&)obj).fTsumwz2 = fTsumwz2;
164  ((TH3&)obj).fTsumwxz = fTsumwxz;
165  ((TH3&)obj).fTsumwyz = fTsumwyz;
166 }
167 
168 
169 ////////////////////////////////////////////////////////////////////////////////
170 /// Fill histogram with all entries in the buffer.
171 /// action = -1 histogram is reset and refilled from the buffer (called by THistPainter::Paint)
172 /// action = 0 histogram is filled from the buffer
173 /// action = 1 histogram is filled and buffer is deleted
174 /// The buffer is automatically deleted when the number of entries
175 /// in the buffer is greater than the number of entries in the histogram
176 
178 {
179  // do we need to compute the bin size?
180  if (!fBuffer) return 0;
181  Int_t nbentries = (Int_t)fBuffer[0];
182  if (!nbentries) return 0;
183  Double_t *buffer = fBuffer;
184  if (nbentries < 0) {
185  if (action == 0) return 0;
186  nbentries = -nbentries;
187  fBuffer=0;
188  Reset("ICES");
189  fBuffer = buffer;
190  }
191  if (CanExtendAllAxes() || fXaxis.GetXmax() <= fXaxis.GetXmin() ||
192  fYaxis.GetXmax() <= fYaxis.GetXmin() ||
193  fZaxis.GetXmax() <= fZaxis.GetXmin()) {
194  //find min, max of entries in buffer
195  Double_t xmin = fBuffer[2];
196  Double_t xmax = xmin;
197  Double_t ymin = fBuffer[3];
198  Double_t ymax = ymin;
199  Double_t zmin = fBuffer[4];
200  Double_t zmax = zmin;
201  for (Int_t i=1;i<nbentries;i++) {
202  Double_t x = fBuffer[4*i+2];
203  if (x < xmin) xmin = x;
204  if (x > xmax) xmax = x;
205  Double_t y = fBuffer[4*i+3];
206  if (y < ymin) ymin = y;
207  if (y > ymax) ymax = y;
208  Double_t z = fBuffer[4*i+4];
209  if (z < zmin) zmin = z;
210  if (z > zmax) zmax = z;
211  }
212  if (fXaxis.GetXmax() <= fXaxis.GetXmin() || fYaxis.GetXmax() <= fYaxis.GetXmin() || fZaxis.GetXmax() <= fZaxis.GetXmin()) {
213  THLimitsFinder::GetLimitsFinder()->FindGoodLimits(this,xmin,xmax,ymin,ymax,zmin,zmax);
214  } else {
215  fBuffer = 0;
216  Int_t keep = fBufferSize; fBufferSize = 0;
217  if (xmin < fXaxis.GetXmin()) ExtendAxis(xmin,&fXaxis);
218  if (xmax >= fXaxis.GetXmax()) ExtendAxis(xmax,&fXaxis);
219  if (ymin < fYaxis.GetXmin()) ExtendAxis(ymin,&fYaxis);
220  if (ymax >= fYaxis.GetXmax()) ExtendAxis(ymax,&fYaxis);
221  if (zmin < fZaxis.GetXmin()) ExtendAxis(zmin,&fZaxis);
222  if (zmax >= fZaxis.GetXmax()) ExtendAxis(zmax,&fZaxis);
223  fBuffer = buffer;
224  fBufferSize = keep;
225  }
226  }
227  fBuffer = 0;
228 
229  for (Int_t i=0;i<nbentries;i++) {
230  Fill(buffer[4*i+2],buffer[4*i+3],buffer[4*i+4],buffer[4*i+1]);
231  }
232  fBuffer = buffer;
233 
234  if (action > 0) { delete [] fBuffer; fBuffer = 0; fBufferSize = 0;}
235  else {
236  if (nbentries == (Int_t)fEntries) fBuffer[0] = -nbentries;
237  else fBuffer[0] = 0;
238  }
239  return nbentries;
240 }
241 
242 
243 ////////////////////////////////////////////////////////////////////////////////
244 /// accumulate arguments in buffer. When buffer is full, empty the buffer
245 /// fBuffer[0] = number of entries in buffer
246 /// fBuffer[1] = w of first entry
247 /// fBuffer[2] = x of first entry
248 /// fBuffer[3] = y of first entry
249 /// fBuffer[4] = z of first entry
250 
252 {
253  if (!fBuffer) return -3;
254  Int_t nbentries = (Int_t)fBuffer[0];
255  if (nbentries < 0) {
256  nbentries = -nbentries;
257  fBuffer[0] = nbentries;
258  if (fEntries > 0) {
259  Double_t *buffer = fBuffer; fBuffer=0;
260  Reset("ICES");
261  fBuffer = buffer;
262  }
263  }
264  if (4*nbentries+4 >= fBufferSize) {
265  BufferEmpty(1);
266  return Fill(x,y,z,w);
267  }
268  fBuffer[4*nbentries+1] = w;
269  fBuffer[4*nbentries+2] = x;
270  fBuffer[4*nbentries+3] = y;
271  fBuffer[4*nbentries+4] = z;
272  fBuffer[0] += 1;
273  return -3;
274 }
275 
276 
277 ////////////////////////////////////////////////////////////////////////////////
278 /// Invalid Fill method
279 
281 {
282  Error("Fill", "Invalid signature - do nothing");
283  return -1;
284 }
285 
286 
287 ////////////////////////////////////////////////////////////////////////////////
288 /// Increment cell defined by x,y,z by 1 .
289 ///
290 /// The function returns the corresponding global bin number which has its content
291 /// incremented by 1
292 
294 {
295  if (fBuffer) return BufferFill(x,y,z,1);
296 
297  Int_t binx, biny, binz, bin;
298  fEntries++;
299  binx = fXaxis.FindBin(x);
300  biny = fYaxis.FindBin(y);
301  binz = fZaxis.FindBin(z);
302  if (binx <0 || biny <0 || binz<0) return -1;
303  bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
304  if (fSumw2.fN) ++fSumw2.fArray[bin];
305  AddBinContent(bin);
306  if (binx == 0 || binx > fXaxis.GetNbins()) {
307  if (!fgStatOverflows) return -1;
308  }
309 
310  if (biny == 0 || biny > fYaxis.GetNbins()) {
311  if (!fgStatOverflows) return -1;
312  }
313  if (binz == 0 || binz > fZaxis.GetNbins()) {
314  if (!fgStatOverflows) return -1;
315  }
316  ++fTsumw;
317  ++fTsumw2;
318  fTsumwx += x;
319  fTsumwx2 += x*x;
320  fTsumwy += y;
321  fTsumwy2 += y*y;
322  fTsumwxy += x*y;
323  fTsumwz += z;
324  fTsumwz2 += z*z;
325  fTsumwxz += x*z;
326  fTsumwyz += y*z;
327  return bin;
328 }
329 
330 
331 ////////////////////////////////////////////////////////////////////////////////
332 /// Increment cell defined by x,y,z by a weight w.
333 ///
334 /// If the weight is not equal to 1, the storage of the sum of squares of
335 /// weights is automatically triggered and the sum of the squares of weights is incremented
336 /// by w^2 in the cell corresponding to x,y,z.
337 ///
338 /// The function returns the corresponding global bin number which has its content
339 /// incremented by w
340 
342 {
343  if (fBuffer) return BufferFill(x,y,z,w);
344 
345  Int_t binx, biny, binz, bin;
346  fEntries++;
347  binx = fXaxis.FindBin(x);
348  biny = fYaxis.FindBin(y);
349  binz = fZaxis.FindBin(z);
350  if (binx <0 || biny <0 || binz<0) return -1;
351  bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
352  if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before AddBinContent
353  if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
354  AddBinContent(bin,w);
355  if (binx == 0 || binx > fXaxis.GetNbins()) {
356  if (!fgStatOverflows) return -1;
357  }
358  if (biny == 0 || biny > fYaxis.GetNbins()) {
359  if (!fgStatOverflows) return -1;
360  }
361  if (binz == 0 || binz > fZaxis.GetNbins()) {
362  if (!fgStatOverflows) return -1;
363  }
364  fTsumw += w;
365  fTsumw2 += w*w;
366  fTsumwx += w*x;
367  fTsumwx2 += w*x*x;
368  fTsumwy += w*y;
369  fTsumwy2 += w*y*y;
370  fTsumwxy += w*x*y;
371  fTsumwz += w*z;
372  fTsumwz2 += w*z*z;
373  fTsumwxz += w*x*z;
374  fTsumwyz += w*y*z;
375  return bin;
376 }
377 
378 
379 ////////////////////////////////////////////////////////////////////////////////
380 /// Increment cell defined by namex,namey,namez by a weight w
381 ///
382 /// If the weight is not equal to 1, the storage of the sum of squares of
383 /// weights is automatically triggered and the sum of the squares of weights is incremented
384 /// by w^2 in the corresponding cell.
385 /// The function returns the corresponding global bin number which has its content
386 /// incremented by w
387 
388 Int_t TH3::Fill(const char *namex, const char *namey, const char *namez, Double_t w)
389 {
390  Int_t binx, biny, binz, bin;
391  fEntries++;
392  binx = fXaxis.FindBin(namex);
393  biny = fYaxis.FindBin(namey);
394  binz = fZaxis.FindBin(namez);
395  if (binx <0 || biny <0 || binz<0) return -1;
396  bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
397  if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before AddBinContent
398  if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
399  AddBinContent(bin,w);
400  if (binx == 0 || binx > fXaxis.GetNbins()) return -1;
401  if (biny == 0 || biny > fYaxis.GetNbins()) return -1;
402  if (binz == 0 || binz > fZaxis.GetNbins()) return -1;
403  Double_t x = fXaxis.GetBinCenter(binx);
404  Double_t y = fYaxis.GetBinCenter(biny);
405  Double_t z = fZaxis.GetBinCenter(binz);
406  Double_t v = w;
407  fTsumw += v;
408  fTsumw2 += v*v;
409  fTsumwx += v*x;
410  fTsumwx2 += v*x*x;
411  fTsumwy += v*y;
412  fTsumwy2 += v*y*y;
413  fTsumwxy += v*x*y;
414  fTsumwz += v*z;
415  fTsumwz2 += v*z*z;
416  fTsumwxz += v*x*z;
417  fTsumwyz += v*y*z;
418  return bin;
419 }
420 
421 
422 ////////////////////////////////////////////////////////////////////////////////
423 /// Increment cell defined by namex,y,namez by a weight w
424 ///
425 /// If the weight is not equal to 1, the storage of the sum of squares of
426 /// weights is automatically triggered and the sum of the squares of weights is incremented
427 /// by w^2 in the corresponding cell.
428 /// The function returns the corresponding global bin number which has its content
429 /// incremented by w
430 
431 Int_t TH3::Fill(const char *namex, Double_t y, const char *namez, Double_t w)
432 {
433  Int_t binx, biny, binz, bin;
434  fEntries++;
435  binx = fXaxis.FindBin(namex);
436  biny = fYaxis.FindBin(y);
437  binz = fZaxis.FindBin(namez);
438  if (binx <0 || biny <0 || binz<0) return -1;
439  bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
440  if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before AddBinContent
441  if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
442  AddBinContent(bin,w);
443  if (binx == 0 || binx > fXaxis.GetNbins()) return -1;
444  if (biny == 0 || biny > fYaxis.GetNbins()) {
445  if (!fgStatOverflows) return -1;
446  }
447  if (binz == 0 || binz > fZaxis.GetNbins()) return -1;
448  Double_t x = fXaxis.GetBinCenter(binx);
449  Double_t z = fZaxis.GetBinCenter(binz);
450  Double_t v = w;
451  fTsumw += v;
452  fTsumw2 += v*v;
453  fTsumwx += v*x;
454  fTsumwx2 += v*x*x;
455  fTsumwy += v*y;
456  fTsumwy2 += v*y*y;
457  fTsumwxy += v*x*y;
458  fTsumwz += v*z;
459  fTsumwz2 += v*z*z;
460  fTsumwxz += v*x*z;
461  fTsumwyz += v*y*z;
462  return bin;
463 }
464 
465 
466 ////////////////////////////////////////////////////////////////////////////////
467 /// Increment cell defined by namex,namey,z by a weight w
468 ///
469 /// If the weight is not equal to 1, the storage of the sum of squares of
470 /// weights is automatically triggered and the sum of the squares of weights is incremented
471 /// by w^2 in the corresponding cell.
472 /// The function returns the corresponding global bin number which has its content
473 /// incremented by w
474 
475 Int_t TH3::Fill(const char *namex, const char *namey, Double_t z, Double_t w)
476 {
477  Int_t binx, biny, binz, bin;
478  fEntries++;
479  binx = fXaxis.FindBin(namex);
480  biny = fYaxis.FindBin(namey);
481  binz = fZaxis.FindBin(z);
482  if (binx <0 || biny <0 || binz<0) return -1;
483  bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
484  if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before AddBinContent
485  if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
486  AddBinContent(bin,w);
487  if (binx == 0 || binx > fXaxis.GetNbins()) return -1;
488  if (biny == 0 || biny > fYaxis.GetNbins()) return -1;
489  if (binz == 0 || binz > fZaxis.GetNbins()) {
490  if (!fgStatOverflows) return -1;
491  }
492  Double_t x = fXaxis.GetBinCenter(binx);
493  Double_t y = fYaxis.GetBinCenter(biny);
494  Double_t v = w;
495  fTsumw += v;
496  fTsumw2 += v*v;
497  fTsumwx += v*x;
498  fTsumwx2 += v*x*x;
499  fTsumwy += v*y;
500  fTsumwy2 += v*y*y;
501  fTsumwxy += v*x*y;
502  fTsumwz += v*z;
503  fTsumwz2 += v*z*z;
504  fTsumwxz += v*x*z;
505  fTsumwyz += v*y*z;
506  return bin;
507 }
508 
509 
510 ////////////////////////////////////////////////////////////////////////////////
511 /// Increment cell defined by x,namey,namezz by a weight w
512 ///
513 /// If the weight is not equal to 1, the storage of the sum of squares of
514 /// weights is automatically triggered and the sum of the squares of weights is incremented
515 /// by w^2 in the corresponding cell.
516 /// The function returns the corresponding global bin number which has its content
517 /// incremented by w
518 
519 Int_t TH3::Fill(Double_t x, const char *namey, const char *namez, Double_t w)
520 {
521  Int_t binx, biny, binz, bin;
522  fEntries++;
523  binx = fXaxis.FindBin(x);
524  biny = fYaxis.FindBin(namey);
525  binz = fZaxis.FindBin(namez);
526  if (binx <0 || biny <0 || binz<0) return -1;
527  bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
528  if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before AddBinContent
529  if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
530  AddBinContent(bin,w);
531  if (binx == 0 || binx > fXaxis.GetNbins()) {
532  if (!fgStatOverflows) return -1;
533  }
534  if (biny == 0 || biny > fYaxis.GetNbins()) return -1;
535  if (binz == 0 || binz > fZaxis.GetNbins()) return -1;
536  Double_t y = fYaxis.GetBinCenter(biny);
537  Double_t z = fZaxis.GetBinCenter(binz);
538  Double_t v = w;
539  fTsumw += v;
540  fTsumw2 += v*v;
541  fTsumwx += v*x;
542  fTsumwx2 += v*x*x;
543  fTsumwy += v*y;
544  fTsumwy2 += v*y*y;
545  fTsumwxy += v*x*y;
546  fTsumwz += v*z;
547  fTsumwz2 += v*z*z;
548  fTsumwxz += v*x*z;
549  fTsumwyz += v*y*z;
550  return bin;
551 }
552 
553 
554 ////////////////////////////////////////////////////////////////////////////////
555 /// Increment cell defined by x,namey,z by a weight w
556 ///
557 /// If the weight is not equal to 1, the storage of the sum of squares of
558 /// weights is automatically triggered and the sum of the squares of weights is incremented
559 /// by w^2 in the corresponding cell.
560 /// The function returns the corresponding global bin number which has its content
561 /// incremented by w
562 
563 Int_t TH3::Fill(Double_t x, const char *namey, Double_t z, Double_t w)
564 {
565  Int_t binx, biny, binz, bin;
566  fEntries++;
567  binx = fXaxis.FindBin(x);
568  biny = fYaxis.FindBin(namey);
569  binz = fZaxis.FindBin(z);
570  if (binx <0 || biny <0 || binz<0) return -1;
571  bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
572  if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before AddBinContent
573  if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
574  AddBinContent(bin,w);
575  if (binx == 0 || binx > fXaxis.GetNbins()) {
576  if (!fgStatOverflows) return -1;
577  }
578  if (biny == 0 || biny > fYaxis.GetNbins()) return -1;
579  if (binz == 0 || binz > fZaxis.GetNbins()) {
580  if (!fgStatOverflows) return -1;
581  }
582  Double_t y = fYaxis.GetBinCenter(biny);
583  Double_t v = w;
584  fTsumw += v;
585  fTsumw2 += v*v;
586  fTsumwx += v*x;
587  fTsumwx2 += v*x*x;
588  fTsumwy += v*y;
589  fTsumwy2 += v*y*y;
590  fTsumwxy += v*x*y;
591  fTsumwz += v*z;
592  fTsumwz2 += v*z*z;
593  fTsumwxz += v*x*z;
594  fTsumwyz += v*y*z;
595  return bin;
596 }
597 
598 
599 ////////////////////////////////////////////////////////////////////////////////
600 /// Increment cell defined by x,y,namez by a weight w
601 ///
602 /// If the weight is not equal to 1, the storage of the sum of squares of
603 /// weights is automatically triggered and the sum of the squares of weights is incremented
604 /// by w^2 in the corresponding cell.
605 /// The function returns the corresponding global bin number which has its content
606 /// incremented by w
607 
608 Int_t TH3::Fill(Double_t x, Double_t y, const char *namez, Double_t w)
609 {
610  Int_t binx, biny, binz, bin;
611  fEntries++;
612  binx = fXaxis.FindBin(x);
613  biny = fYaxis.FindBin(y);
614  binz = fZaxis.FindBin(namez);
615  if (binx <0 || biny <0 || binz<0) return -1;
616  bin = binx + (fXaxis.GetNbins()+2)*(biny + (fYaxis.GetNbins()+2)*binz);
617  if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before AddBinContent
618  if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
619  AddBinContent(bin,w);
620  if (binx == 0 || binx > fXaxis.GetNbins()) {
621  if (!fgStatOverflows) return -1;
622  }
623  if (biny == 0 || biny > fYaxis.GetNbins()) {
624  if (!fgStatOverflows) return -1;
625  }
626  if (binz == 0 || binz > fZaxis.GetNbins()) return -1;
627  Double_t z = fZaxis.GetBinCenter(binz);
628  Double_t v = w;
629  fTsumw += v;
630  fTsumw2 += v*v;
631  fTsumwx += v*x;
632  fTsumwx2 += v*x*x;
633  fTsumwy += v*y;
634  fTsumwy2 += v*y*y;
635  fTsumwxy += v*x*y;
636  fTsumwz += v*z;
637  fTsumwz2 += v*z*z;
638  fTsumwxz += v*x*z;
639  fTsumwyz += v*y*z;
640  return bin;
641 }
642 
643 
644 ////////////////////////////////////////////////////////////////////////////////
645 /// Fill histogram following distribution in function fname.
646 ///
647 /// The distribution contained in the function fname (TF1) is integrated
648 /// over the channel contents.
649 /// It is normalized to 1.
650 /// Getting one random number implies:
651 /// - Generating a random number between 0 and 1 (say r1)
652 /// - Look in which bin in the normalized integral r1 corresponds to
653 /// - Fill histogram channel
654 /// ntimes random numbers are generated
655 ///
656 /// One can also call TF1::GetRandom to get a random variate from a function.
657 
658 void TH3::FillRandom(const char *fname, Int_t ntimes)
659 {
660  Int_t bin, binx, biny, binz, ibin, loop;
661  Double_t r1, x, y,z, xv[3];
662  // Search for fname in the list of ROOT defined functions
663  TF1 *f1 = (TF1*)gROOT->GetFunction(fname);
664  if (!f1) { Error("FillRandom", "Unknown function: %s",fname); return; }
665 
666  // Allocate temporary space to store the integral and compute integral
667  Int_t nbinsx = GetNbinsX();
668  Int_t nbinsy = GetNbinsY();
669  Int_t nbinsz = GetNbinsZ();
670  Int_t nxy = nbinsx*nbinsy;
671  Int_t nbins = nxy*nbinsz;
672 
673  Double_t *integral = new Double_t[nbins+1];
674  ibin = 0;
675  integral[ibin] = 0;
676  for (binz=1;binz<=nbinsz;binz++) {
677  xv[2] = fZaxis.GetBinCenter(binz);
678  for (biny=1;biny<=nbinsy;biny++) {
679  xv[1] = fYaxis.GetBinCenter(biny);
680  for (binx=1;binx<=nbinsx;binx++) {
681  xv[0] = fXaxis.GetBinCenter(binx);
682  ibin++;
683  integral[ibin] = integral[ibin-1] + f1->Eval(xv[0],xv[1],xv[2]);
684  }
685  }
686  }
687 
688  // Normalize integral to 1
689  if (integral[nbins] == 0 ) {
690  delete [] integral;
691  Error("FillRandom", "Integral = zero"); return;
692  }
693  for (bin=1;bin<=nbins;bin++) integral[bin] /= integral[nbins];
694 
695  // Start main loop ntimes
696  if (fDimension < 2) nbinsy = -1;
697  if (fDimension < 3) nbinsz = -1;
698  for (loop=0;loop<ntimes;loop++) {
699  r1 = gRandom->Rndm();
700  ibin = TMath::BinarySearch(nbins,&integral[0],r1);
701  binz = ibin/nxy;
702  biny = (ibin - nxy*binz)/nbinsx;
703  binx = 1 + ibin - nbinsx*(biny + nbinsy*binz);
704  if (nbinsz) binz++;
705  if (nbinsy) biny++;
706  x = fXaxis.GetBinCenter(binx);
707  y = fYaxis.GetBinCenter(biny);
708  z = fZaxis.GetBinCenter(binz);
709  Fill(x,y,z, 1.);
710  }
711  delete [] integral;
712 }
713 
714 
715 ////////////////////////////////////////////////////////////////////////////////
716 /// Fill histogram following distribution in histogram h.
717 ///
718 /// The distribution contained in the histogram h (TH3) is integrated
719 /// over the channel contents.
720 /// It is normalized to 1.
721 /// Getting one random number implies:
722 /// - Generating a random number between 0 and 1 (say r1)
723 /// - Look in which bin in the normalized integral r1 corresponds to
724 /// - Fill histogram channel
725 /// ntimes random numbers are generated
726 
727 void TH3::FillRandom(TH1 *h, Int_t ntimes)
728 {
729  if (!h) { Error("FillRandom", "Null histogram"); return; }
730  if (fDimension != h->GetDimension()) {
731  Error("FillRandom", "Histograms with different dimensions"); return;
732  }
733 
734  if (h->ComputeIntegral() == 0) return;
735 
736  TH3 *h3 = (TH3*)h;
737  Int_t loop;
738  Double_t x,y,z;
739  for (loop=0;loop<ntimes;loop++) {
740  h3->GetRandom3(x,y,z);
741  Fill(x,y,z);
742  }
743 }
744 
745 
746 ////////////////////////////////////////////////////////////////////////////////
747 /// Find first bin with content > threshold for axis (1=x, 2=y, 3=z)
748 /// if no bins with content > threshold is found the function returns -1.
749 
751 {
752  if (axis < 1 || axis > 3) {
753  Warning("FindFirstBinAbove","Invalid axis number : %d, axis x assumed\n",axis);
754  axis = 1;
755  }
756  Int_t nbinsx = fXaxis.GetNbins();
757  Int_t nbinsy = fYaxis.GetNbins();
758  Int_t nbinsz = fZaxis.GetNbins();
759  Int_t binx, biny, binz;
760  if (axis == 1) {
761  for (binx=1;binx<=nbinsx;binx++) {
762  for (biny=1;biny<=nbinsy;biny++) {
763  for (binz=1;binz<=nbinsz;binz++) {
764  if (GetBinContent(binx,biny,binz) > threshold) return binx;
765  }
766  }
767  }
768  } else if (axis == 2) {
769  for (biny=1;biny<=nbinsy;biny++) {
770  for (binx=1;binx<=nbinsx;binx++) {
771  for (binz=1;binz<=nbinsz;binz++) {
772  if (GetBinContent(binx,biny,binz) > threshold) return biny;
773  }
774  }
775  }
776  } else {
777  for (binz=1;binz<=nbinsz;binz++) {
778  for (binx=1;binx<=nbinsx;binx++) {
779  for (biny=1;biny<=nbinsy;biny++) {
780  if (GetBinContent(binx,biny,binz) > threshold) return binz;
781  }
782  }
783  }
784  }
785  return -1;
786 }
787 
788 
789 ////////////////////////////////////////////////////////////////////////////////
790 /// Find last bin with content > threshold for axis (1=x, 2=y, 3=z)
791 /// if no bins with content > threshold is found the function returns -1.
792 
794 {
795  if (axis < 1 || axis > 3) {
796  Warning("FindLastBinAbove","Invalid axis number : %d, axis x assumed\n",axis);
797  axis = 1;
798  }
799  Int_t nbinsx = fXaxis.GetNbins();
800  Int_t nbinsy = fYaxis.GetNbins();
801  Int_t nbinsz = fZaxis.GetNbins();
802  Int_t binx, biny, binz;
803  if (axis == 1) {
804  for (binx=nbinsx;binx>=1;binx--) {
805  for (biny=1;biny<=nbinsy;biny++) {
806  for (binz=1;binz<=nbinsz;binz++) {
807  if (GetBinContent(binx,biny,binz) > threshold) return binx;
808  }
809  }
810  }
811  } else if (axis == 2) {
812  for (biny=nbinsy;biny>=1;biny--) {
813  for (binx=1;binx<=nbinsx;binx++) {
814  for (binz=1;binz<=nbinsz;binz++) {
815  if (GetBinContent(binx,biny,binz) > threshold) return biny;
816  }
817  }
818  }
819  } else {
820  for (binz=nbinsz;binz>=1;binz--) {
821  for (binx=1;binx<=nbinsx;binx++) {
822  for (biny=1;biny<=nbinsy;biny++) {
823  if (GetBinContent(binx,biny,binz) > threshold) return binz;
824  }
825  }
826  }
827  }
828  return -1;
829 }
830 
831 
832 ////////////////////////////////////////////////////////////////////////////////
833 /// Project slices along Z in case of a 3-D histogram, then fit each slice
834 /// with function f1 and make a 2-d histogram for each fit parameter
835 /// Only cells in the bin range [binminx,binmaxx] and [binminy,binmaxy] are considered.
836 /// if f1=0, a gaussian is assumed
837 /// Before invoking this function, one can set a subrange to be fitted along Z
838 /// via f1->SetRange(zmin,zmax)
839 /// The argument option (default="QNR") can be used to change the fit options.
840 /// "Q" means Quiet mode
841 /// "N" means do not show the result of the fit
842 /// "R" means fit the function in the specified function range
843 ///
844 /// Note that the generated histograms are added to the list of objects
845 /// in the current directory. It is the user's responsability to delete
846 /// these histograms.
847 ///
848 /// Example: Assume a 3-d histogram h3
849 /// Root > h3->FitSlicesZ(); produces 4 TH2D histograms
850 /// with h3_0 containing parameter 0(Constant) for a Gaus fit
851 /// of each cell in X,Y projected along Z
852 /// with h3_1 containing parameter 1(Mean) for a gaus fit
853 /// with h3_2 containing parameter 2(StdDev) for a gaus fit
854 /// with h3_chi2 containing the chisquare/number of degrees of freedom for a gaus fit
855 ///
856 /// Root > h3->Fit(0,15,22,0,0,10);
857 /// same as above, but only for bins 15 to 22 along X
858 /// and only for cells in X,Y for which the corresponding projection
859 /// along Z has more than cut bins filled.
860 ///
861 /// NOTE: To access the generated histograms in the current directory, do eg:
862 /// TH2D *h3_1 = (TH2D*)gDirectory->Get("h3_1");
863 
864 void TH3::FitSlicesZ(TF1 *f1, Int_t binminx, Int_t binmaxx, Int_t binminy, Int_t binmaxy, Int_t cut, Option_t *option)
865 {
866  Int_t nbinsx = fXaxis.GetNbins();
867  Int_t nbinsy = fYaxis.GetNbins();
868  Int_t nbinsz = fZaxis.GetNbins();
869  if (binminx < 1) binminx = 1;
870  if (binmaxx > nbinsx) binmaxx = nbinsx;
871  if (binmaxx < binminx) {binminx = 1; binmaxx = nbinsx;}
872  if (binminy < 1) binminy = 1;
873  if (binmaxy > nbinsy) binmaxy = nbinsy;
874  if (binmaxy < binminy) {binminy = 1; binmaxy = nbinsy;}
875 
876  //default is to fit with a gaussian
877  if (f1 == 0) {
878  f1 = (TF1*)gROOT->GetFunction("gaus");
879  if (f1 == 0) f1 = new TF1("gaus","gaus",fZaxis.GetXmin(),fZaxis.GetXmax());
880  else f1->SetRange(fZaxis.GetXmin(),fZaxis.GetXmax());
881  }
882  const char *fname = f1->GetName();
883  Int_t npar = f1->GetNpar();
884  Double_t *parsave = new Double_t[npar];
885  f1->GetParameters(parsave);
886 
887  //Create one 2-d histogram for each function parameter
888  Int_t ipar;
889  char name[80], title[80];
890  TH2D *hlist[25];
891  const TArrayD *xbins = fXaxis.GetXbins();
892  const TArrayD *ybins = fYaxis.GetXbins();
893  for (ipar=0;ipar<npar;ipar++) {
894  snprintf(name,80,"%s_%d",GetName(),ipar);
895  snprintf(title,80,"Fitted value of par[%d]=%s",ipar,f1->GetParName(ipar));
896  if (xbins->fN == 0) {
897  hlist[ipar] = new TH2D(name, title,
898  nbinsx, fXaxis.GetXmin(), fXaxis.GetXmax(),
899  nbinsy, fYaxis.GetXmin(), fYaxis.GetXmax());
900  } else {
901  hlist[ipar] = new TH2D(name, title,
902  nbinsx, xbins->fArray,
903  nbinsy, ybins->fArray);
904  }
905  hlist[ipar]->GetXaxis()->SetTitle(fXaxis.GetTitle());
906  hlist[ipar]->GetYaxis()->SetTitle(fYaxis.GetTitle());
907  }
908  snprintf(name,80,"%s_chi2",GetName());
909  TH2D *hchi2 = new TH2D(name,"chisquare", nbinsx, fXaxis.GetXmin(), fXaxis.GetXmax()
910  , nbinsy, fYaxis.GetXmin(), fYaxis.GetXmax());
911 
912  //Loop on all cells in X,Y generate a projection along Z
913  TH1D *hpz = new TH1D("R_temp","_temp",nbinsz, fZaxis.GetXmin(), fZaxis.GetXmax());
914  Int_t bin,binx,biny,binz;
915  for (biny=binminy;biny<=binmaxy;biny++) {
916  Float_t y = fYaxis.GetBinCenter(biny);
917  for (binx=binminx;binx<=binmaxx;binx++) {
918  Float_t x = fXaxis.GetBinCenter(binx);
919  hpz->Reset();
920  Int_t nfill = 0;
921  for (binz=1;binz<=nbinsz;binz++) {
922  bin = GetBin(binx,biny,binz);
923  Float_t w = RetrieveBinContent(bin);
924  if (w == 0) continue;
925  hpz->Fill(fZaxis.GetBinCenter(binz),w);
926  hpz->SetBinError(binz,GetBinError(bin));
927  nfill++;
928  }
929  if (nfill < cut) continue;
930  f1->SetParameters(parsave);
931  hpz->Fit(fname,option);
932  Int_t npfits = f1->GetNumberFitPoints();
933  if (npfits > npar && npfits >= cut) {
934  for (ipar=0;ipar<npar;ipar++) {
935  hlist[ipar]->Fill(x,y,f1->GetParameter(ipar));
936  hlist[ipar]->SetBinError(binx,biny,f1->GetParError(ipar));
937  }
938  hchi2->SetBinContent(binx,biny,f1->GetChisquare()/(npfits-npar));
939  }
940  }
941  }
942  delete [] parsave;
943  delete hpz;
944 }
945 
946 
947 ////////////////////////////////////////////////////////////////////////////////
948 /// See comments in TH1::GetBin
949 
950 Int_t TH3::GetBin(Int_t binx, Int_t biny, Int_t binz) const
951 {
952  Int_t ofy = fYaxis.GetNbins() + 1; // code duplication unavoidable because TH3 does not inherit from TH2
953  if (biny < 0) biny = 0;
954  if (biny > ofy) biny = ofy;
955 
956  Int_t ofz = fZaxis.GetNbins() + 1; // overflow bin
957  if (binz < 0) binz = 0;
958  if (binz > ofz) binz = ofz;
959 
960  return TH1::GetBin(binx) + (fXaxis.GetNbins() + 2) * (biny + (fYaxis.GetNbins() + 2) * binz);
961 }
962 
963 
964 ////////////////////////////////////////////////////////////////////////////////
965 /// Compute first cell (binx,biny,binz) in the range [firstx,lastx](firsty,lasty][firstz,lastz] for which
966 /// diff = abs(cell_content-c) <= maxdiff
967 /// In case several cells in the specified range with diff=0 are found
968 /// the first cell found is returned in binx,biny,binz.
969 /// In case several cells in the specified range satisfy diff <=maxdiff
970 /// the cell with the smallest difference is returned in binx,biny,binz.
971 /// In all cases the function returns the smallest difference.
972 ///
973 /// NOTE1: if firstx <= 0, firstx is set to bin 1
974 /// if (lastx < firstx then firstx is set to the number of bins in X
975 /// ie if firstx=0 and lastx=0 (default) the search is on all bins in X.
976 /// if firsty <= 0, firsty is set to bin 1
977 /// if (lasty < firsty then firsty is set to the number of bins in Y
978 /// ie if firsty=0 and lasty=0 (default) the search is on all bins in Y.
979 /// if firstz <= 0, firstz is set to bin 1
980 /// if (lastz < firstz then firstz is set to the number of bins in Z
981 /// ie if firstz=0 and lastz=0 (default) the search is on all bins in Z.
982 /// NOTE2: if maxdiff=0 (default), the first cell with content=c is returned.
983 
985  Int_t firstx, Int_t lastx,
986  Int_t firsty, Int_t lasty,
987  Int_t firstz, Int_t lastz,
988  Double_t maxdiff) const
989 {
990  if (fDimension != 3) {
991  binx = 0;
992  biny = 0;
993  binz = 0;
994  Error("GetBinWithContent3","function is only valid for 3-D histograms");
995  return 0;
996  }
997  if (firstx <= 0) firstx = 1;
998  if (lastx < firstx) lastx = fXaxis.GetNbins();
999  if (firsty <= 0) firsty = 1;
1000  if (lasty < firsty) lasty = fYaxis.GetNbins();
1001  if (firstz <= 0) firstz = 1;
1002  if (lastz < firstz) lastz = fZaxis.GetNbins();
1003  Int_t binminx = 0, binminy=0, binminz=0;
1004  Double_t diff, curmax = 1.e240;
1005  for (Int_t k=firstz;k<=lastz;k++) {
1006  for (Int_t j=firsty;j<=lasty;j++) {
1007  for (Int_t i=firstx;i<=lastx;i++) {
1008  diff = TMath::Abs(GetBinContent(i,j,k)-c);
1009  if (diff <= 0) {binx = i; biny=j; binz=k; return diff;}
1010  if (diff < curmax && diff <= maxdiff) {curmax = diff, binminx=i; binminy=j;binminz=k;}
1011  }
1012  }
1013  }
1014  binx = binminx;
1015  biny = binminy;
1016  binz = binminz;
1017  return curmax;
1018 }
1019 
1020 
1021 ////////////////////////////////////////////////////////////////////////////////
1022 /// Return correlation factor between axis1 and axis2.
1023 
1025 {
1026  if (axis1 < 1 || axis2 < 1 || axis1 > 3 || axis2 > 3) {
1027  Error("GetCorrelationFactor","Wrong parameters");
1028  return 0;
1029  }
1030  if (axis1 == axis2) return 1;
1031  Double_t stddev1 = GetStdDev(axis1);
1032  if (stddev1 == 0) return 0;
1033  Double_t stddev2 = GetStdDev(axis2);
1034  if (stddev2 == 0) return 0;
1035  return GetCovariance(axis1,axis2)/stddev1/stddev2;
1036 }
1037 
1038 
1039 ////////////////////////////////////////////////////////////////////////////////
1040 /// Return covariance between axis1 and axis2.
1041 
1043 {
1044  if (axis1 < 1 || axis2 < 1 || axis1 > 3 || axis2 > 3) {
1045  Error("GetCovariance","Wrong parameters");
1046  return 0;
1047  }
1048  Double_t stats[kNstat];
1049  GetStats(stats);
1050  Double_t sumw = stats[0];
1051  Double_t sumw2 = stats[1];
1052  Double_t sumwx = stats[2];
1053  Double_t sumwx2 = stats[3];
1054  Double_t sumwy = stats[4];
1055  Double_t sumwy2 = stats[5];
1056  Double_t sumwxy = stats[6];
1057  Double_t sumwz = stats[7];
1058  Double_t sumwz2 = stats[8];
1059  Double_t sumwxz = stats[9];
1060  Double_t sumwyz = stats[10];
1061 
1062  if (sumw == 0) return 0;
1063  if (axis1 == 1 && axis2 == 1) {
1064  return TMath::Abs(sumwx2/sumw - sumwx*sumwx/sumw2);
1065  }
1066  if (axis1 == 2 && axis2 == 2) {
1067  return TMath::Abs(sumwy2/sumw - sumwy*sumwy/sumw2);
1068  }
1069  if (axis1 == 3 && axis2 == 3) {
1070  return TMath::Abs(sumwz2/sumw - sumwz*sumwz/sumw2);
1071  }
1072  if ((axis1 == 1 && axis2 == 2) || (axis1 == 2 && axis2 == 1)) {
1073  return sumwxy/sumw - sumwx/sumw*sumwy/sumw;
1074  }
1075  if ((axis1 == 1 && axis2 == 3) || (axis1 == 3 && axis2 == 1)) {
1076  return sumwxz/sumw - sumwx/sumw*sumwz/sumw;
1077  }
1078  if ((axis1 == 2 && axis2 == 3) || (axis1 == 3 && axis2 == 2)) {
1079  return sumwyz/sumw - sumwy/sumw*sumwz/sumw;
1080  }
1081  return 0;
1082 }
1083 
1084 
1085 ////////////////////////////////////////////////////////////////////////////////
1086 /// Return 3 random numbers along axis x , y and z distributed according
1087 /// the cellcontents of a 3-dim histogram
1088 
1090 {
1091  Int_t nbinsx = GetNbinsX();
1092  Int_t nbinsy = GetNbinsY();
1093  Int_t nbinsz = GetNbinsZ();
1094  Int_t nxy = nbinsx*nbinsy;
1095  Int_t nbins = nxy*nbinsz;
1096  Double_t integral;
1097  // compute integral checking that all bins have positive content (see ROOT-5894)
1098  if (fIntegral) {
1099  if (fIntegral[nbins+1] != fEntries) integral = ComputeIntegral(true);
1100  else integral = fIntegral[nbins];
1101  } else {
1102  integral = ComputeIntegral(true);
1103  }
1104  if (integral == 0 ) { x = 0; y = 0; z = 0; return;}
1105  // case histogram has negative bins
1106  if (integral == TMath::QuietNaN() ) { x = TMath::QuietNaN(); y = TMath::QuietNaN(); z = TMath::QuietNaN(); return;}
1107 
1108  Double_t r1 = gRandom->Rndm();
1109  Int_t ibin = TMath::BinarySearch(nbins,fIntegral,(Double_t) r1);
1110  Int_t binz = ibin/nxy;
1111  Int_t biny = (ibin - nxy*binz)/nbinsx;
1112  Int_t binx = ibin - nbinsx*(biny + nbinsy*binz);
1113  x = fXaxis.GetBinLowEdge(binx+1);
1114  if (r1 > fIntegral[ibin]) x +=
1115  fXaxis.GetBinWidth(binx+1)*(r1-fIntegral[ibin])/(fIntegral[ibin+1] - fIntegral[ibin]);
1116  y = fYaxis.GetBinLowEdge(biny+1) + fYaxis.GetBinWidth(biny+1)*gRandom->Rndm();
1117  z = fZaxis.GetBinLowEdge(binz+1) + fZaxis.GetBinWidth(binz+1)*gRandom->Rndm();
1118 }
1119 
1120 
1121 ////////////////////////////////////////////////////////////////////////////////
1122 /// Fill the array stats from the contents of this histogram
1123 /// The array stats must be correctly dimensionned in the calling program.
1124 /// stats[0] = sumw
1125 /// stats[1] = sumw2
1126 /// stats[2] = sumwx
1127 /// stats[3] = sumwx2
1128 /// stats[4] = sumwy
1129 /// stats[5] = sumwy2
1130 /// stats[6] = sumwxy
1131 /// stats[7] = sumwz
1132 /// stats[8] = sumwz2
1133 /// stats[9] = sumwxz
1134 /// stats[10]= sumwyz
1135 
1136 void TH3::GetStats(Double_t *stats) const
1137 {
1138  if (fBuffer) ((TH3*)this)->BufferEmpty();
1139 
1140  Int_t bin, binx, biny, binz;
1141  Double_t w,err;
1142  Double_t x,y,z;
1144  for (bin=0;bin<9;bin++) stats[bin] = 0;
1145 
1146  Int_t firstBinX = fXaxis.GetFirst();
1147  Int_t lastBinX = fXaxis.GetLast();
1148  Int_t firstBinY = fYaxis.GetFirst();
1149  Int_t lastBinY = fYaxis.GetLast();
1150  Int_t firstBinZ = fZaxis.GetFirst();
1151  Int_t lastBinZ = fZaxis.GetLast();
1152  // include underflow/overflow if TH1::StatOverflows(kTRUE) in case no range is set on the axis
1153  if (fgStatOverflows) {
1154  if ( !fXaxis.TestBit(TAxis::kAxisRange) ) {
1155  if (firstBinX == 1) firstBinX = 0;
1156  if (lastBinX == fXaxis.GetNbins() ) lastBinX += 1;
1157  }
1158  if ( !fYaxis.TestBit(TAxis::kAxisRange) ) {
1159  if (firstBinY == 1) firstBinY = 0;
1160  if (lastBinY == fYaxis.GetNbins() ) lastBinY += 1;
1161  }
1162  if ( !fZaxis.TestBit(TAxis::kAxisRange) ) {
1163  if (firstBinZ == 1) firstBinZ = 0;
1164  if (lastBinZ == fZaxis.GetNbins() ) lastBinZ += 1;
1165  }
1166  }
1167  for (binz = firstBinZ; binz <= lastBinZ; binz++) {
1168  z = fZaxis.GetBinCenter(binz);
1169  for (biny = firstBinY; biny <= lastBinY; biny++) {
1170  y = fYaxis.GetBinCenter(biny);
1171  for (binx = firstBinX; binx <= lastBinX; binx++) {
1172  bin = GetBin(binx,biny,binz);
1173  x = fXaxis.GetBinCenter(binx);
1174  //w = TMath::Abs(GetBinContent(bin));
1175  w = RetrieveBinContent(bin);
1176  err = TMath::Abs(GetBinError(bin));
1177  stats[0] += w;
1178  stats[1] += err*err;
1179  stats[2] += w*x;
1180  stats[3] += w*x*x;
1181  stats[4] += w*y;
1182  stats[5] += w*y*y;
1183  stats[6] += w*x*y;
1184  stats[7] += w*z;
1185  stats[8] += w*z*z;
1186  stats[9] += w*x*z;
1187  stats[10]+= w*y*z;
1188  }
1189  }
1190  }
1191  } else {
1192  stats[0] = fTsumw;
1193  stats[1] = fTsumw2;
1194  stats[2] = fTsumwx;
1195  stats[3] = fTsumwx2;
1196  stats[4] = fTsumwy;
1197  stats[5] = fTsumwy2;
1198  stats[6] = fTsumwxy;
1199  stats[7] = fTsumwz;
1200  stats[8] = fTsumwz2;
1201  stats[9] = fTsumwxz;
1202  stats[10]= fTsumwyz;
1203  }
1204 }
1205 
1206 
1207 ////////////////////////////////////////////////////////////////////////////////
1208 /// Return integral of bin contents. Only bins in the bins range are considered.
1209 /// By default the integral is computed as the sum of bin contents in the range.
1210 /// if option "width" is specified, the integral is the sum of
1211 /// the bin contents multiplied by the bin width in x, y and in z.
1212 
1214 {
1215  return Integral(fXaxis.GetFirst(),fXaxis.GetLast(),
1217  fZaxis.GetFirst(),fZaxis.GetLast(),option);
1218 }
1219 
1220 
1221 ////////////////////////////////////////////////////////////////////////////////
1222 /// Return integral of bin contents in range [binx1,binx2],[biny1,biny2],[binz1,binz2]
1223 /// for a 3-D histogram
1224 /// By default the integral is computed as the sum of bin contents in the range.
1225 /// if option "width" is specified, the integral is the sum of
1226 /// the bin contents multiplied by the bin width in x, y and in z.
1227 
1228 Double_t TH3::Integral(Int_t binx1, Int_t binx2, Int_t biny1, Int_t biny2,
1229  Int_t binz1, Int_t binz2, Option_t *option) const
1230 {
1231  Double_t err = 0;
1232  return DoIntegral(binx1,binx2,biny1,biny2,binz1,binz2,err,option);
1233 }
1234 
1235 
1236 ////////////////////////////////////////////////////////////////////////////////
1237 /// Return integral of bin contents in range [binx1,binx2],[biny1,biny2],[binz1,binz2]
1238 /// for a 3-D histogram. Calculates also the integral error using error propagation
1239 /// from the bin errors assumming that all the bins are uncorrelated.
1240 /// By default the integral is computed as the sum of bin contents in the range.
1241 /// if option "width" is specified, the integral is the sum of
1242 /// the bin contents multiplied by the bin width in x, y and in z.
1243 
1245  Int_t binz1, Int_t binz2,
1246  Double_t & error, Option_t *option) const
1247 {
1248  return DoIntegral(binx1,binx2,biny1,biny2,binz1,binz2,error,option,kTRUE);
1249 }
1250 
1251 
1252 ////////////////////////////////////////////////////////////////////////////////
1253 ///Not yet implemented
1254 
1256 {
1257  Error("Interpolate","This function must be called with 3 arguments for a TH3");
1258  return 0;
1259 }
1260 
1261 
1262 ////////////////////////////////////////////////////////////////////////////////
1263 ///Not yet implemented
1264 
1266 {
1267  Error("Interpolate","This function must be called with 3 arguments for a TH3");
1268  return 0;
1269 }
1270 
1271 
1272 ////////////////////////////////////////////////////////////////////////////////
1273 /// Given a point P(x,y,z), Interpolate approximates the value via trilinear interpolation
1274 /// based on the 8 nearest bin center points ( corner of the cube surronding the points)
1275 /// The Algorithm is described in http://en.wikipedia.org/wiki/Trilinear_interpolation
1276 /// The given values (x,y,z) must be between first bin center and last bin center for each coordinate:
1277 ///
1278 /// fXAxis.GetBinCenter(1) < x < fXaxis.GetBinCenter(nbinX) AND
1279 /// fYAxis.GetBinCenter(1) < y < fYaxis.GetBinCenter(nbinY) AND
1280 /// fZAxis.GetBinCenter(1) < z < fZaxis.GetBinCenter(nbinZ)
1281 
1283 {
1284  Int_t ubx = fXaxis.FindBin(x);
1285  if ( x < fXaxis.GetBinCenter(ubx) ) ubx -= 1;
1286  Int_t obx = ubx + 1;
1287 
1288  Int_t uby = fYaxis.FindBin(y);
1289  if ( y < fYaxis.GetBinCenter(uby) ) uby -= 1;
1290  Int_t oby = uby + 1;
1291 
1292  Int_t ubz = fZaxis.FindBin(z);
1293  if ( z < fZaxis.GetBinCenter(ubz) ) ubz -= 1;
1294  Int_t obz = ubz + 1;
1295 
1296 
1297 // if ( IsBinUnderflow(GetBin(ubx, uby, ubz)) ||
1298 // IsBinOverflow (GetBin(obx, oby, obz)) ) {
1299  if (ubx <=0 || uby <=0 || ubz <= 0 ||
1300  obx > fXaxis.GetNbins() || oby > fYaxis.GetNbins() || obz > fZaxis.GetNbins() ) {
1301  Error("Interpolate","Cannot interpolate outside histogram domain.");
1302  return 0;
1303  }
1304 
1305  Double_t xw = fXaxis.GetBinCenter(obx) - fXaxis.GetBinCenter(ubx);
1306  Double_t yw = fYaxis.GetBinCenter(oby) - fYaxis.GetBinCenter(uby);
1307  Double_t zw = fZaxis.GetBinCenter(obz) - fZaxis.GetBinCenter(ubz);
1308 
1309  Double_t xd = (x - fXaxis.GetBinCenter(ubx)) / xw;
1310  Double_t yd = (y - fYaxis.GetBinCenter(uby)) / yw;
1311  Double_t zd = (z - fZaxis.GetBinCenter(ubz)) / zw;
1312 
1313 
1314  Double_t v[] = { GetBinContent( ubx, uby, ubz ), GetBinContent( ubx, uby, obz ),
1315  GetBinContent( ubx, oby, ubz ), GetBinContent( ubx, oby, obz ),
1316  GetBinContent( obx, uby, ubz ), GetBinContent( obx, uby, obz ),
1317  GetBinContent( obx, oby, ubz ), GetBinContent( obx, oby, obz ) };
1318 
1319 
1320  Double_t i1 = v[0] * (1 - zd) + v[1] * zd;
1321  Double_t i2 = v[2] * (1 - zd) + v[3] * zd;
1322  Double_t j1 = v[4] * (1 - zd) + v[5] * zd;
1323  Double_t j2 = v[6] * (1 - zd) + v[7] * zd;
1324 
1325 
1326  Double_t w1 = i1 * (1 - yd) + i2 * yd;
1327  Double_t w2 = j1 * (1 - yd) + j2 * yd;
1328 
1329 
1330  Double_t result = w1 * (1 - xd) + w2 * xd;
1331 
1332  return result;
1333 }
1334 
1335 
1336 ////////////////////////////////////////////////////////////////////////////////
1337 /// Statistical test of compatibility in shape between
1338 /// THIS histogram and h2, using Kolmogorov test.
1339 /// Default: Ignore under- and overflow bins in comparison
1340 ///
1341 /// option is a character string to specify options
1342 /// "U" include Underflows in test
1343 /// "O" include Overflows
1344 /// "N" include comparison of normalizations
1345 /// "D" Put out a line of "Debug" printout
1346 /// "M" Return the Maximum Kolmogorov distance instead of prob
1347 ///
1348 /// The returned function value is the probability of test
1349 /// (much less than one means NOT compatible)
1350 ///
1351 /// The KS test uses the distance between the pseudo-CDF's obtained
1352 /// from the histogram. Since in more than 1D the order for generating the pseudo-CDF is
1353 /// arbitrary, we use the pseudo-CDF's obtained from all the possible 6 combinatons of the 3 axis.
1354 /// The average of all the maximum distances obtained is used in the tests.
1355 
1356 Double_t TH3::KolmogorovTest(const TH1 *h2, Option_t *option) const
1357 {
1358  TString opt = option;
1359  opt.ToUpper();
1360 
1361  Double_t prb = 0;
1362  TH1 *h1 = (TH1*)this;
1363  if (h2 == 0) return 0;
1364  const TAxis *xaxis1 = h1->GetXaxis();
1365  const TAxis *xaxis2 = h2->GetXaxis();
1366  const TAxis *yaxis1 = h1->GetYaxis();
1367  const TAxis *yaxis2 = h2->GetYaxis();
1368  const TAxis *zaxis1 = h1->GetZaxis();
1369  const TAxis *zaxis2 = h2->GetZaxis();
1370  Int_t ncx1 = xaxis1->GetNbins();
1371  Int_t ncx2 = xaxis2->GetNbins();
1372  Int_t ncy1 = yaxis1->GetNbins();
1373  Int_t ncy2 = yaxis2->GetNbins();
1374  Int_t ncz1 = zaxis1->GetNbins();
1375  Int_t ncz2 = zaxis2->GetNbins();
1376 
1377  // Check consistency of dimensions
1378  if (h1->GetDimension() != 3 || h2->GetDimension() != 3) {
1379  Error("KolmogorovTest","Histograms must be 3-D\n");
1380  return 0;
1381  }
1382 
1383  // Check consistency in number of channels
1384  if (ncx1 != ncx2) {
1385  Error("KolmogorovTest","Number of channels in X is different, %d and %d\n",ncx1,ncx2);
1386  return 0;
1387  }
1388  if (ncy1 != ncy2) {
1389  Error("KolmogorovTest","Number of channels in Y is different, %d and %d\n",ncy1,ncy2);
1390  return 0;
1391  }
1392  if (ncz1 != ncz2) {
1393  Error("KolmogorovTest","Number of channels in Z is different, %d and %d\n",ncz1,ncz2);
1394  return 0;
1395  }
1396 
1397  // Check consistency in channel edges
1398  Bool_t afunc1 = kFALSE;
1399  Bool_t afunc2 = kFALSE;
1400  Double_t difprec = 1e-5;
1401  Double_t diff1 = TMath::Abs(xaxis1->GetXmin() - xaxis2->GetXmin());
1402  Double_t diff2 = TMath::Abs(xaxis1->GetXmax() - xaxis2->GetXmax());
1403  if (diff1 > difprec || diff2 > difprec) {
1404  Error("KolmogorovTest","histograms with different binning along X");
1405  return 0;
1406  }
1407  diff1 = TMath::Abs(yaxis1->GetXmin() - yaxis2->GetXmin());
1408  diff2 = TMath::Abs(yaxis1->GetXmax() - yaxis2->GetXmax());
1409  if (diff1 > difprec || diff2 > difprec) {
1410  Error("KolmogorovTest","histograms with different binning along Y");
1411  return 0;
1412  }
1413  diff1 = TMath::Abs(zaxis1->GetXmin() - zaxis2->GetXmin());
1414  diff2 = TMath::Abs(zaxis1->GetXmax() - zaxis2->GetXmax());
1415  if (diff1 > difprec || diff2 > difprec) {
1416  Error("KolmogorovTest","histograms with different binning along Z");
1417  return 0;
1418  }
1419 
1420  // Should we include Uflows, Oflows?
1421  Int_t ibeg = 1, jbeg = 1, kbeg = 1;
1422  Int_t iend = ncx1, jend = ncy1, kend = ncz1;
1423  if (opt.Contains("U")) {ibeg = 0; jbeg = 0; kbeg = 0;}
1424  if (opt.Contains("O")) {iend = ncx1+1; jend = ncy1+1; kend = ncz1+1;}
1425 
1426  Int_t i,j,k,bin;
1427  Double_t sum1 = 0;
1428  Double_t sum2 = 0;
1429  Double_t w1 = 0;
1430  Double_t w2 = 0;
1431  for (i = ibeg; i <= iend; i++) {
1432  for (j = jbeg; j <= jend; j++) {
1433  for (k = kbeg; k <= kend; k++) {
1434  bin = h1->GetBin(i,j,k);
1435  sum1 += h1->GetBinContent(bin);
1436  sum2 += h2->GetBinContent(bin);
1437  Double_t ew1 = h1->GetBinError(bin);
1438  Double_t ew2 = h2->GetBinError(bin);
1439  w1 += ew1*ew1;
1440  w2 += ew2*ew2;
1441  }
1442  }
1443  }
1444 
1445 
1446  // Check that both scatterplots contain events
1447  if (sum1 == 0) {
1448  Error("KolmogorovTest","Integral is zero for h1=%s\n",h1->GetName());
1449  return 0;
1450  }
1451  if (sum2 == 0) {
1452  Error("KolmogorovTest","Integral is zero for h2=%s\n",h2->GetName());
1453  return 0;
1454  }
1455  // calculate the effective entries.
1456  // the case when errors are zero (w1 == 0 or w2 ==0) are equivalent to
1457  // compare to a function. In that case the rescaling is done only on sqrt(esum2) or sqrt(esum1)
1458  Double_t esum1 = 0, esum2 = 0;
1459  if (w1 > 0)
1460  esum1 = sum1 * sum1 / w1;
1461  else
1462  afunc1 = kTRUE; // use later for calculating z
1463 
1464  if (w2 > 0)
1465  esum2 = sum2 * sum2 / w2;
1466  else
1467  afunc2 = kTRUE; // use later for calculating z
1468 
1469  if (afunc2 && afunc1) {
1470  Error("KolmogorovTest","Errors are zero for both histograms\n");
1471  return 0;
1472  }
1473 
1474  // Find Kolmogorov distance
1475  // order is arbitrary take average of all possible 6 starting orders x,y,z
1476  int order[3] = {0,1,2};
1477  int binbeg[3];
1478  int binend[3];
1479  int ibin[3];
1480  binbeg[0] = ibeg; binbeg[1] = jbeg; binbeg[2] = kbeg;
1481  binend[0] = iend; binend[1] = jend; binend[2] = kend;
1482  Double_t vdfmax[6]; // there are in total 6 combinations
1483  int icomb = 0;
1484  Double_t s1 = 1./(6.*sum1);
1485  Double_t s2 = 1./(6.*sum2);
1486  Double_t rsum1=0, rsum2=0;
1487  do {
1488  // loop on bins
1489  Double_t dmax = 0;
1490  for (i = binbeg[order[0] ]; i <= binend[order[0] ]; i++) {
1491  for ( j = binbeg[order[1] ]; j <= binend[order[1] ]; j++) {
1492  for ( k = binbeg[order[2] ]; k <= binend[order[2] ]; k++) {
1493  ibin[ order[0] ] = i;
1494  ibin[ order[1] ] = j;
1495  ibin[ order[2] ] = k;
1496  bin = h1->GetBin(ibin[0],ibin[1],ibin[2]);
1497  rsum1 += s1*h1->GetBinContent(bin);
1498  rsum2 += s2*h2->GetBinContent(bin);
1499  dmax = TMath::Max(dmax, TMath::Abs(rsum1-rsum2));
1500  }
1501  }
1502  }
1503  vdfmax[icomb] = dmax;
1504  icomb++;
1505  } while (TMath::Permute(3,order) );
1506 
1507 
1508  // get average of distances
1509  Double_t dfmax = TMath::Mean(6,vdfmax);
1510 
1511  // Get Kolmogorov probability
1512  Double_t factnm;
1513  if (afunc1) factnm = TMath::Sqrt(sum2);
1514  else if (afunc2) factnm = TMath::Sqrt(sum1);
1515  else factnm = TMath::Sqrt(sum1*sum2/(sum1+sum2));
1516  Double_t z = dfmax*factnm;
1517 
1518  prb = TMath::KolmogorovProb(z);
1519 
1520  Double_t prb1 = 0, prb2 = 0;
1521  // option N to combine normalization makes sense if both afunc1 and afunc2 are false
1522  if (opt.Contains("N") && !(afunc1 || afunc2 ) ) {
1523  // Combine probabilities for shape and normalization
1524  prb1 = prb;
1525  Double_t d12 = esum1-esum2;
1526  Double_t chi2 = d12*d12/(esum1+esum2);
1527  prb2 = TMath::Prob(chi2,1);
1528  // see Eadie et al., section 11.6.2
1529  if (prb > 0 && prb2 > 0) prb = prb*prb2*(1-TMath::Log(prb*prb2));
1530  else prb = 0;
1531  }
1532 
1533  // debug printout
1534  if (opt.Contains("D")) {
1535  printf(" Kolmo Prob h1 = %s, sum1=%g\n",h1->GetName(),sum1);
1536  printf(" Kolmo Prob h2 = %s, sum2=%g\n",h2->GetName(),sum2);
1537  printf(" Kolmo Probabil = %f, Max Dist = %g\n",prb,dfmax);
1538  if (opt.Contains("N"))
1539  printf(" Kolmo Probabil = %f for shape alone, =%f for normalisation alone\n",prb1,prb2);
1540  }
1541  // This numerical error condition should never occur:
1542  if (TMath::Abs(rsum1-1) > 0.002) Warning("KolmogorovTest","Numerical problems with h1=%s\n",h1->GetName());
1543  if (TMath::Abs(rsum2-1) > 0.002) Warning("KolmogorovTest","Numerical problems with h2=%s\n",h2->GetName());
1544 
1545  if (opt.Contains("M")) return dfmax; // return avergae of max distance
1546 
1547  return prb;
1548 }
1549 
1550 
1551 ////////////////////////////////////////////////////////////////////////////////
1552 /// Project a 3-D histogram into a 1-D histogram along X.
1553 ///
1554 /// The projection is always of the type TH1D.
1555 /// The projection is made from the cells along the X axis
1556 /// ranging from iymin to iymax and izmin to izmax included.
1557 /// By default, underflow and overflows are included in both the Y and Z axis.
1558 /// By Setting iymin=1 and iymax=NbinsY the underflow and/or overflow in Y will be excluded
1559 /// By setting izmin=1 and izmax=NbinsZ the underflow and/or overflow in Z will be excluded
1560 ///
1561 /// if option "e" is specified, the errors are computed.
1562 /// if option "d" is specified, the projection is drawn in the current pad.
1563 /// if option "o" original axis range of the target axes will be
1564 /// kept, but only bins inside the selected range will be filled.
1565 ///
1566 /// NOTE that if a TH1D named "name" exists in the current directory or pad
1567 /// the histogram is reset and filled again with the projected contents of the TH3.
1568 ///
1569 /// implemented using Project3D
1570 
1571 TH1D *TH3::ProjectionX(const char *name, Int_t iymin, Int_t iymax,
1572  Int_t izmin, Int_t izmax, Option_t *option) const
1573 {
1574  // in case of default name append the parent name
1575  TString hname = name;
1576  if (hname == "_px") hname = TString::Format("%s%s", GetName(), name);
1577  TString title = TString::Format("%s ( Projection X )",GetTitle());
1578 
1579  return DoProject1D(hname, title, iymin, iymax, izmin, izmax, &fXaxis, &fYaxis, &fZaxis, option);
1580 }
1581 
1582 
1583 ////////////////////////////////////////////////////////////////////////////////
1584 /// Project a 3-D histogram into a 1-D histogram along Y.
1585 ///
1586 /// The projection is always of the type TH1D.
1587 /// The projection is made from the cells along the Y axis
1588 /// ranging from ixmin to ixmax and izmin to izmax included.
1589 /// By default, underflow and overflow are included in both the X and Z axis.
1590 /// By setting ixmin=1 and ixmax=NbinsX the underflow and/or overflow in X will be excluded
1591 /// By setting izmin=1 and izmax=NbinsZ the underflow and/or overflow in Z will be excluded
1592 ///
1593 /// if option "e" is specified, the errors are computed.
1594 /// if option "d" is specified, the projection is drawn in the current pad.
1595 /// if option "o" original axis range of the target axes will be
1596 /// kept, but only bins inside the selected range will be filled.
1597 ///
1598 /// NOTE that if a TH1D named "name" exists in the current directory or pad,
1599 /// the histogram is reset and filled again with the projected contents of the TH3.
1600 ///
1601 /// implemented using Project3D
1602 
1603 TH1D *TH3::ProjectionY(const char *name, Int_t ixmin, Int_t ixmax,
1604  Int_t izmin, Int_t izmax, Option_t *option) const
1605 {
1606  TString hname = name;
1607  if (hname == "_py") hname = TString::Format("%s%s", GetName(), name);
1608  TString title = TString::Format("%s ( Projection Y )",GetTitle());
1609 
1610  return DoProject1D(hname, title, ixmin, ixmax, izmin, izmax, &fYaxis, &fXaxis, &fZaxis, option);
1611 }
1612 
1613 ////////////////////////////////////////////////////////////////////////////////
1614 /// Project a 3-D histogram into a 1-D histogram along Z.
1615 ///
1616 /// The projection is always of the type TH1D.
1617 /// The projection is made from the cells along the Z axis
1618 /// ranging from ixmin to ixmax and iymin to iymax included.
1619 /// By default, bins 1 to nx and 1 to ny are included
1620 /// By default, underflow and overflow are included in both the X and Y axis.
1621 /// By Setting ixmin=1 and ixmax=NbinsX the underflow and/or overflow in X will be excluded
1622 /// By setting iymin=1 and/or iymax=NbinsY the underflow and/or overflow in Y will be excluded
1623 ///
1624 /// if option "e" is specified, the errors are computed.
1625 /// if option "d" is specified, the projection is drawn in the current pad.
1626 /// if option "o" original axis range of the target axes will be
1627 /// kept, but only bins inside the selected range will be filled.
1628 ///
1629 /// NOTE that if a TH1D named "name" exists in the current directory or pad,
1630 /// the histogram is reset and filled again with the projected contents of the TH3.
1631 ///
1632 /// implemented using Project3D
1633 
1634 TH1D *TH3::ProjectionZ(const char *name, Int_t ixmin, Int_t ixmax,
1635  Int_t iymin, Int_t iymax, Option_t *option) const
1636 {
1637 
1638  TString hname = name;
1639  if (hname == "_pz") hname = TString::Format("%s%s", GetName(), name);
1640  TString title = TString::Format("%s ( Projection Z )",GetTitle());
1641 
1642  return DoProject1D(hname, title, ixmin, ixmax, iymin, iymax, &fZaxis, &fXaxis, &fYaxis, option);
1643 }
1644 
1645 
1646 ////////////////////////////////////////////////////////////////////////////////
1647 /// internal methdod performing the projection to 1D histogram
1648 /// called from TH3::Project3D
1649 
1650 TH1D *TH3::DoProject1D(const char* name, const char * title, int imin1, int imax1, int imin2, int imax2,
1651  const TAxis* projAxis, const TAxis * axis1, const TAxis * axis2, Option_t * option) const
1652 {
1653 
1654  TString opt = option;
1655  opt.ToLower();
1656 
1657  Int_t iminOld1 = axis1->GetFirst();
1658  Int_t imaxOld1 = axis1->GetLast();
1659  Int_t iminOld2 = axis2->GetFirst();
1660  Int_t imaxOld2 = axis2->GetLast();
1661 
1662  // need to cast-away constness to set range
1663  const_cast<TAxis*>(axis1)->SetRange(imin1,imax1);
1664  const_cast<TAxis*>(axis2)->SetRange(imin2,imax2);
1665 
1666  Bool_t computeErrors = GetSumw2N();
1667  if (opt.Contains("e") ) {
1668  computeErrors = kTRUE;
1669  opt.Remove(opt.First("e"),1);
1670  }
1671  Bool_t originalRange = kFALSE;
1672  if (opt.Contains('o') ) {
1673  originalRange = kTRUE;
1674  opt.Remove(opt.First("o"),1);
1675  }
1676 
1677  TH1D * h1 = DoProject1D(name, title, projAxis, computeErrors, originalRange,true,true);
1678 
1679  // restore original range
1680  if (axis1->TestBit(TAxis::kAxisRange)) const_cast<TAxis*>(axis1)->SetRange(iminOld1,imaxOld1);
1681  if (axis2->TestBit(TAxis::kAxisRange)) const_cast<TAxis*>(axis2)->SetRange(iminOld2,imaxOld2);
1682 
1683  // draw in current pad
1684  if (h1 && opt.Contains("d")) {
1685  opt.Remove(opt.First("d"),1);
1686  TVirtualPad *padsav = gPad;
1687  TVirtualPad *pad = gROOT->GetSelectedPad();
1688  if (pad) pad->cd();
1689  if (!gPad || !gPad->FindObject(h1)) {
1690  h1->Draw(opt);
1691  } else {
1692  h1->Paint(opt);
1693  }
1694  if (padsav) padsav->cd();
1695  }
1696 
1697  return h1;
1698 }
1699 
1700 TH1D *TH3::DoProject1D(const char* name, const char * title, const TAxis* projX,
1701  bool computeErrors, bool originalRange,
1702  bool useUF, bool useOF) const
1703 {
1704  // internal methdod performing the projection to 1D histogram
1705  // called from other TH3::DoProject1D
1706 
1707 
1708  // Create the projection histogram
1709  TH1D *h1 = 0;
1710 
1711  // Get range to use as well as bin limits
1712  Int_t ixmin = projX->GetFirst();
1713  Int_t ixmax = projX->GetLast();
1714 // if (ixmin == 0 && ixmax == 0) { ixmin = 1; ixmax = projX->GetNbins(); }
1715  Int_t nx = ixmax-ixmin+1;
1716 
1717  // Create the histogram, either reseting a preexisting one
1718  TObject *h1obj = gROOT->FindObject(name);
1719  if (h1obj && h1obj->InheritsFrom(TH1::Class())) {
1720  if (h1obj->IsA() != TH1D::Class() ) {
1721  Error("DoProject1D","Histogram with name %s must be a TH1D and is a %s",name,h1obj->ClassName());
1722  return 0;
1723  }
1724  h1 = (TH1D*)h1obj;
1725  // reset histogram and re-set the axis in any case
1726  h1->Reset();
1727  const TArrayD *bins = projX->GetXbins();
1728  if ( originalRange )
1729  {
1730  if (bins->fN == 0) {
1731  h1->SetBins(projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
1732  } else {
1733  h1->SetBins(projX->GetNbins(),bins->fArray);
1734  }
1735  } else {
1736  if (bins->fN == 0) {
1737  h1->SetBins(nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
1738  } else {
1739  h1->SetBins(nx,&bins->fArray[ixmin-1]);
1740  }
1741  }
1742  }
1743 
1744  if (!h1) {
1745  const TArrayD *bins = projX->GetXbins();
1746  if ( originalRange )
1747  {
1748  if (bins->fN == 0) {
1749  h1 = new TH1D(name,title,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
1750  } else {
1751  h1 = new TH1D(name,title,projX->GetNbins(),bins->fArray);
1752  }
1753  } else {
1754  if (bins->fN == 0) {
1755  h1 = new TH1D(name,title,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
1756  } else {
1757  h1 = new TH1D(name,title,nx,&bins->fArray[ixmin-1]);
1758  }
1759  }
1760  }
1761 
1762  // Copy the axis attributes and the axis labels if needed.
1763  h1->GetXaxis()->ImportAttributes(projX);
1764  THashList* labels = projX->GetLabels();
1765  if (labels) {
1766  TIter iL(labels);
1767  TObjString* lb;
1768  Int_t i = 1;
1769  while ((lb=(TObjString*)iL())) {
1770  h1->GetXaxis()->SetBinLabel(i,lb->String().Data());
1771  i++;
1772  }
1773  }
1774  h1->SetLineColor(this->GetLineColor());
1775  h1->SetFillColor(this->GetFillColor());
1776  h1->SetMarkerColor(this->GetMarkerColor());
1777  h1->SetMarkerStyle(this->GetMarkerStyle());
1778 
1779  // Activate errors
1780  if ( computeErrors ) h1->Sumw2();
1781 
1782  // Set references to the axis, so that the bucle has no branches.
1783  const TAxis* out1 = 0;
1784  const TAxis* out2 = 0;
1785  if ( projX == GetXaxis() ) {
1786  out1 = GetYaxis();
1787  out2 = GetZaxis();
1788  } else if ( projX == GetYaxis() ) {
1789  out1 = GetZaxis();
1790  out2 = GetXaxis();
1791  } else {
1792  out1 = GetYaxis();
1793  out2 = GetXaxis();
1794  }
1795 
1796  Int_t *refX = 0, *refY = 0, *refZ = 0;
1797  Int_t ixbin, out1bin, out2bin;
1798  if ( projX == GetXaxis() ) { refX = &ixbin; refY = &out1bin; refZ = &out2bin; }
1799  if ( projX == GetYaxis() ) { refX = &out2bin; refY = &ixbin; refZ = &out1bin; }
1800  if ( projX == GetZaxis() ) { refX = &out2bin; refY = &out1bin; refZ = &ixbin; }
1801  R__ASSERT (refX != 0 && refY != 0 && refZ != 0);
1802 
1803  // Fill the projected histogram excluding underflow/overflows if considered in the option
1804  // if specified in the option (by default they considered)
1805  Double_t totcont = 0;
1806 
1807  Int_t out1min = out1->GetFirst();
1808  Int_t out1max = out1->GetLast();
1809  // GetFirst(), GetLast() can return (0,0) when the range bit is set artifically (see TAxis::SetRange)
1810  //if (out1min == 0 && out1max == 0) { out1min = 1; out1max = out1->GetNbins(); }
1811  // correct for underflow/overflows
1812  if (useUF && !out1->TestBit(TAxis::kAxisRange) ) out1min -= 1;
1813  if (useOF && !out1->TestBit(TAxis::kAxisRange) ) out1max += 1;
1814  Int_t out2min = out2->GetFirst();
1815  Int_t out2max = out2->GetLast();
1816 // if (out2min == 0 && out2max == 0) { out2min = 1; out2max = out2->GetNbins(); }
1817  if (useUF && !out2->TestBit(TAxis::kAxisRange) ) out2min -= 1;
1818  if (useOF && !out2->TestBit(TAxis::kAxisRange) ) out2max += 1;
1819 
1820  for (ixbin=0;ixbin<=1+projX->GetNbins();ixbin++) {
1821  if ( projX->TestBit(TAxis::kAxisRange) && ( ixbin < ixmin || ixbin > ixmax )) continue;
1822 
1823  Double_t cont = 0;
1824  Double_t err2 = 0;
1825 
1826  // loop on the bins to be integrated (outbin should be called inbin)
1827  for (out1bin = out1min; out1bin <= out1max; out1bin++) {
1828  for (out2bin = out2min; out2bin <= out2max; out2bin++) {
1829 
1830  Int_t bin = GetBin(*refX, *refY, *refZ);
1831 
1832  // sum the bin contents and errors if needed
1833  cont += RetrieveBinContent(bin);
1834  if (computeErrors) {
1835  Double_t exyz = GetBinError(bin);
1836  err2 += exyz*exyz;
1837  }
1838  }
1839  }
1840  Int_t ix = h1->FindBin( projX->GetBinCenter(ixbin) );
1841  h1->SetBinContent(ix ,cont);
1842  if (computeErrors) h1->SetBinError(ix, TMath::Sqrt(err2) );
1843  // sum all content
1844  totcont += cont;
1845 
1846  }
1847 
1848  // since we use a combination of fill and SetBinError we need to reset and recalculate the statistics
1849  // for weighted histograms otherwise sumw2 will be wrong.
1850  // We can keep the original statistics from the TH3 if the projected sumw is consistent with original one
1851  // i.e. when no events are thrown away
1852  bool resetStats = true;
1853  double eps = 1.E-12;
1854  if (IsA() == TH3F::Class() ) eps = 1.E-6;
1855  if (fTsumw != 0 && TMath::Abs( fTsumw - totcont) < TMath::Abs(fTsumw) * eps) resetStats = false;
1856 
1857  bool resetEntries = resetStats;
1858  // entries are calculated using underflow/overflow. If excluded entries must be reset
1859  resetEntries |= !useUF || !useOF;
1860 
1861 
1862  if (!resetStats) {
1863  Double_t stats[kNstat];
1864  GetStats(stats);
1865  if ( projX == GetYaxis() ) {
1866  stats[2] = stats[4];
1867  stats[3] = stats[5];
1868  }
1869  else if ( projX == GetZaxis() ) {
1870  stats[2] = stats[7];
1871  stats[3] = stats[8];
1872  }
1873  h1->PutStats(stats);
1874  }
1875  else {
1876  // reset statistics
1877  h1->ResetStats();
1878  }
1879  if (resetEntries) {
1880  // in case of error calculation (i.e. when Sumw2() is set)
1881  // use the effective entries for the entries
1882  // since this is the only way to estimate them
1883  Double_t entries = TMath::Floor( totcont + 0.5); // to avoid numerical rounding
1884  if (computeErrors) entries = h1->GetEffectiveEntries();
1885  h1->SetEntries( entries );
1886  }
1887  else {
1888  h1->SetEntries( fEntries );
1889  }
1890 
1891  return h1;
1892 }
1893 
1894 
1895 ////////////////////////////////////////////////////////////////////////////////
1896 /// internal method performing the projection to a 2D histogram
1897 /// called from TH3::Project3D
1898 
1899 TH2D *TH3::DoProject2D(const char* name, const char * title, const TAxis* projX, const TAxis* projY,
1900  bool computeErrors, bool originalRange,
1901  bool useUF, bool useOF) const
1902 {
1903  TH2D *h2 = 0;
1904 
1905  // Get range to use as well as bin limits
1906  Int_t ixmin = projX->GetFirst();
1907  Int_t ixmax = projX->GetLast();
1908  Int_t iymin = projY->GetFirst();
1909  Int_t iymax = projY->GetLast();
1910  if (ixmin == 0 && ixmax == 0) { ixmin = 1; ixmax = projX->GetNbins(); }
1911  if (iymin == 0 && iymax == 0) { iymin = 1; iymax = projY->GetNbins(); }
1912  Int_t nx = ixmax-ixmin+1;
1913  Int_t ny = iymax-iymin+1;
1914 
1915  // Create the histogram, either reseting a preexisting one
1916  // or creating one from scratch.
1917  // Does an object with the same name exists?
1918  TObject *h2obj = gROOT->FindObject(name);
1919  if (h2obj && h2obj->InheritsFrom(TH1::Class())) {
1920  if ( h2obj->IsA() != TH2D::Class() ) {
1921  Error("DoProject2D","Histogram with name %s must be a TH2D and is a %s",name,h2obj->ClassName());
1922  return 0;
1923  }
1924  h2 = (TH2D*)h2obj;
1925  // reset histogram and its axes
1926  h2->Reset();
1927  const TArrayD *xbins = projX->GetXbins();
1928  const TArrayD *ybins = projY->GetXbins();
1929  if ( originalRange ) {
1930  h2->SetBins(projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
1931  ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
1932  // set bins for mixed axis do not exists - need to set afterwards the variable bins
1933  if (ybins->fN != 0)
1934  h2->GetXaxis()->Set(projY->GetNbins(),&ybins->fArray[iymin-1]);
1935  if (xbins->fN != 0)
1936  h2->GetYaxis()->Set(projX->GetNbins(),&xbins->fArray[ixmin-1]);
1937  } else {
1938  h2->SetBins(ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
1939  ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
1940  if (ybins->fN != 0)
1941  h2->GetXaxis()->Set(ny,&ybins->fArray[iymin-1]);
1942  if (xbins->fN != 0)
1943  h2->GetYaxis()->Set(nx,&xbins->fArray[ixmin-1]);
1944  }
1945  }
1946 
1947 
1948  if (!h2) {
1949  const TArrayD *xbins = projX->GetXbins();
1950  const TArrayD *ybins = projY->GetXbins();
1951  if ( originalRange )
1952  {
1953  if (xbins->fN == 0 && ybins->fN == 0) {
1954  h2 = new TH2D(name,title,projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
1955  ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
1956  } else if (ybins->fN == 0) {
1957  h2 = new TH2D(name,title,projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
1958  ,projX->GetNbins(),&xbins->fArray[ixmin-1]);
1959  } else if (xbins->fN == 0) {
1960  h2 = new TH2D(name,title,projY->GetNbins(),&ybins->fArray[iymin-1]
1961  ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
1962  } else {
1963  h2 = new TH2D(name,title,projY->GetNbins(),&ybins->fArray[iymin-1],projX->GetNbins(),&xbins->fArray[ixmin-1]);
1964  }
1965  } else {
1966  if (xbins->fN == 0 && ybins->fN == 0) {
1967  h2 = new TH2D(name,title,ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
1968  ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
1969  } else if (ybins->fN == 0) {
1970  h2 = new TH2D(name,title,ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
1971  ,nx,&xbins->fArray[ixmin-1]);
1972  } else if (xbins->fN == 0) {
1973  h2 = new TH2D(name,title,ny,&ybins->fArray[iymin-1]
1974  ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
1975  } else {
1976  h2 = new TH2D(name,title,ny,&ybins->fArray[iymin-1],nx,&xbins->fArray[ixmin-1]);
1977  }
1978  }
1979  }
1980 
1981  // Copy the axis attributes and the axis labels if needed.
1982  THashList* labels1 = 0;
1983  THashList* labels2 = 0;
1984  // "xy"
1985  h2->GetXaxis()->ImportAttributes(projY);
1986  h2->GetYaxis()->ImportAttributes(projX);
1987  labels1 = projY->GetLabels();
1988  labels2 = projX->GetLabels();
1989  if (labels1) {
1990  TIter iL(labels1);
1991  TObjString* lb;
1992  Int_t i = 1;
1993  while ((lb=(TObjString*)iL())) {
1994  h2->GetXaxis()->SetBinLabel(i,lb->String().Data());
1995  i++;
1996  }
1997  }
1998  if (labels2) {
1999  TIter iL(labels2);
2000  TObjString* lb;
2001  Int_t i = 1;
2002  while ((lb=(TObjString*)iL())) {
2003  h2->GetYaxis()->SetBinLabel(i,lb->String().Data());
2004  i++;
2005  }
2006  }
2007  h2->SetLineColor(this->GetLineColor());
2008  h2->SetFillColor(this->GetFillColor());
2009  h2->SetMarkerColor(this->GetMarkerColor());
2010  h2->SetMarkerStyle(this->GetMarkerStyle());
2011 
2012  // Activate errors
2013  if ( computeErrors) h2->Sumw2();
2014 
2015  // Set references to the axis, so that the bucle has no branches.
2016  const TAxis* out = 0;
2017  if ( projX != GetXaxis() && projY != GetXaxis() ) {
2018  out = GetXaxis();
2019  } else if ( projX != GetYaxis() && projY != GetYaxis() ) {
2020  out = GetYaxis();
2021  } else {
2022  out = GetZaxis();
2023  }
2024 
2025  Int_t *refX = 0, *refY = 0, *refZ = 0;
2026  Int_t ixbin, iybin, outbin;
2027  if ( projX == GetXaxis() && projY == GetYaxis() ) { refX = &ixbin; refY = &iybin; refZ = &outbin; }
2028  if ( projX == GetYaxis() && projY == GetXaxis() ) { refX = &iybin; refY = &ixbin; refZ = &outbin; }
2029  if ( projX == GetXaxis() && projY == GetZaxis() ) { refX = &ixbin; refY = &outbin; refZ = &iybin; }
2030  if ( projX == GetZaxis() && projY == GetXaxis() ) { refX = &iybin; refY = &outbin; refZ = &ixbin; }
2031  if ( projX == GetYaxis() && projY == GetZaxis() ) { refX = &outbin; refY = &ixbin; refZ = &iybin; }
2032  if ( projX == GetZaxis() && projY == GetYaxis() ) { refX = &outbin; refY = &iybin; refZ = &ixbin; }
2033  R__ASSERT (refX != 0 && refY != 0 && refZ != 0);
2034 
2035  // Fill the projected histogram excluding underflow/overflows if considered in the option
2036  // if specified in the option (by default they considered)
2037  Double_t totcont = 0;
2038 
2039  Int_t outmin = out->GetFirst();
2040  Int_t outmax = out->GetLast();
2041  // GetFirst(), GetLast() can return (0,0) when the range bit is set artifically (see TAxis::SetRange)
2042  if (outmin == 0 && outmax == 0) { outmin = 1; outmax = out->GetNbins(); }
2043  // correct for underflow/overflows
2044  if (useUF && !out->TestBit(TAxis::kAxisRange) ) outmin -= 1;
2045  if (useOF && !out->TestBit(TAxis::kAxisRange) ) outmax += 1;
2046 
2047  for (ixbin=0;ixbin<=1+projX->GetNbins();ixbin++) {
2048  if ( projX->TestBit(TAxis::kAxisRange) && ( ixbin < ixmin || ixbin > ixmax )) continue;
2049  Int_t ix = h2->GetYaxis()->FindBin( projX->GetBinCenter(ixbin) );
2050 
2051  for (iybin=0;iybin<=1+projY->GetNbins();iybin++) {
2052  if ( projY->TestBit(TAxis::kAxisRange) && ( iybin < iymin || iybin > iymax )) continue;
2053  Int_t iy = h2->GetXaxis()->FindBin( projY->GetBinCenter(iybin) );
2054 
2055  Double_t cont = 0;
2056  Double_t err2 = 0;
2057 
2058  // loop on the bins to be integrated (outbin should be called inbin)
2059  for (outbin = outmin; outbin <= outmax; outbin++) {
2060 
2061  Int_t bin = GetBin(*refX,*refY,*refZ);
2062 
2063  // sum the bin contents and errors if needed
2064  cont += RetrieveBinContent(bin);
2065  if (computeErrors) {
2066  Double_t exyz = GetBinError(bin);
2067  err2 += exyz*exyz;
2068  }
2069 
2070  }
2071 
2072  // remember axis are inverted
2073  h2->SetBinContent(iy , ix, cont);
2074  if (computeErrors) h2->SetBinError(iy, ix, TMath::Sqrt(err2) );
2075  // sum all content
2076  totcont += cont;
2077 
2078  }
2079  }
2080 
2081  // since we use fill we need to reset and recalculate the statistics (see comment in DoProject1D )
2082  // or keep original statistics if consistent sumw2
2083  bool resetStats = true;
2084  double eps = 1.E-12;
2085  if (IsA() == TH3F::Class() ) eps = 1.E-6;
2086  if (fTsumw != 0 && TMath::Abs( fTsumw - totcont) < TMath::Abs(fTsumw) * eps) resetStats = false;
2087 
2088  bool resetEntries = resetStats;
2089  // entries are calculated using underflow/overflow. If excluded entries must be reset
2090  resetEntries |= !useUF || !useOF;
2091 
2092  if (!resetStats) {
2093  Double_t stats[kNstat];
2094  Double_t oldst[kNstat]; // old statistics
2095  for (Int_t i = 0; i < kNstat; ++i) { oldst[i] = 0; }
2096  GetStats(oldst);
2097  std::copy(oldst,oldst+kNstat,stats);
2098  // not that projX refer to Y axis and projX refer to the X axis of projected histogram
2099  // nothing to do for projection in Y vs X
2100  if ( projY == GetXaxis() && projX == GetZaxis() ) { // case XZ
2101  stats[4] = oldst[7];
2102  stats[5] = oldst[8];
2103  stats[6] = oldst[9];
2104  }
2105  if ( projY == GetYaxis() ) {
2106  stats[2] = oldst[4];
2107  stats[3] = oldst[5];
2108  if ( projX == GetXaxis() ) { // case YX
2109  stats[4] = oldst[2];
2110  stats[5] = oldst[3];
2111  }
2112  if ( projX == GetZaxis() ) { // case YZ
2113  stats[4] = oldst[7];
2114  stats[5] = oldst[8];
2115  stats[6] = oldst[10];
2116  }
2117  }
2118  else if ( projY == GetZaxis() ) {
2119  stats[2] = oldst[7];
2120  stats[3] = oldst[8];
2121  if ( projX == GetXaxis() ) { // case ZX
2122  stats[4] = oldst[2];
2123  stats[5] = oldst[3];
2124  stats[6] = oldst[9];
2125  }
2126  if ( projX == GetYaxis() ) { // case ZY
2127  stats[4] = oldst[4];
2128  stats[5] = oldst[5];
2129  stats[6] = oldst[10];
2130  }
2131  }
2132  // set the new statistics
2133  h2->PutStats(stats);
2134  }
2135  else {
2136  // recalculate the statistics
2137  h2->ResetStats();
2138  }
2139 
2140  if (resetEntries) {
2141  // use the effective entries for the entries
2142  // since this is the only way to estimate them
2143  Double_t entries = h2->GetEffectiveEntries();
2144  if (!computeErrors) entries = TMath::Floor( entries + 0.5); // to avoid numerical rounding
2145  h2->SetEntries( entries );
2146  }
2147  else {
2148  h2->SetEntries( fEntries );
2149  }
2150 
2151 
2152  return h2;
2153 }
2154 
2155 
2156 ////////////////////////////////////////////////////////////////////////////////
2157 /// Project a 3-d histogram into 1 or 2-d histograms depending on the
2158 /// option parameter
2159 /// option may contain a combination of the characters x,y,z,e
2160 /// option = "x" return the x projection into a TH1D histogram
2161 /// option = "y" return the y projection into a TH1D histogram
2162 /// option = "z" return the z projection into a TH1D histogram
2163 /// option = "xy" return the x versus y projection into a TH2D histogram
2164 /// option = "yx" return the y versus x projection into a TH2D histogram
2165 /// option = "xz" return the x versus z projection into a TH2D histogram
2166 /// option = "zx" return the z versus x projection into a TH2D histogram
2167 /// option = "yz" return the y versus z projection into a TH2D histogram
2168 /// option = "zy" return the z versus y projection into a TH2D histogram
2169 /// NB: the notation "a vs b" means "a" vertical and "b" horizontal
2170 ///
2171 /// option = "o" original axis range of the target axes will be
2172 /// kept, but only bins inside the selected range will be filled.
2173 ///
2174 /// If option contains the string "e", errors are computed
2175 ///
2176 /// The projection is made for the selected bins only.
2177 /// To select a bin range along an axis, use TAxis::SetRange, eg
2178 /// h3.GetYaxis()->SetRange(23,56);
2179 ///
2180 /// NOTE 1: The generated histogram is named th3name + option
2181 /// eg if the TH3* h histogram is named "myhist", then
2182 /// h->Project3D("xy"); produces a TH2D histogram named "myhist_xy"
2183 /// if a histogram of the same type already exists, it is overwritten.
2184 /// The following sequence
2185 /// h->Project3D("xy");
2186 /// h->Project3D("xy2");
2187 /// will generate two TH2D histograms named "myhist_xy" and "myhist_xy2"
2188 /// A different name can be generated by attaching a string to the option
2189 /// For example h->Project3D("name_xy") will generate an histogram with the name: h3dname_name_xy.
2190 ///
2191 /// NOTE 2: If an histogram of the same type already exists,
2192 /// the histogram is reset and filled again with the projected contents of the TH3.
2193 ///
2194 /// NOTE 3: The number of entries in the projected histogram is estimated from the number of
2195 /// effective entries for all the cells included in the projection.
2196 ///
2197 /// NOTE 4: underflow/overflow are included by default in the projection
2198 /// To exclude underflow and/or overflow (for both axis in case of a projection to a 1D histogram) use option "NUF" and/or "NOF"
2199 /// With SetRange() you can have all bins except underflow/overflow only if you set the axis bit range as
2200 /// following after having called SetRange: axis->SetRange(1, axis->GetNbins());
2201 
2202 TH1 *TH3::Project3D(Option_t *option) const
2203 {
2204  TString opt = option; opt.ToLower();
2205  Int_t pcase = 0;
2206  TString ptype;
2207  if (opt.Contains("x")) { pcase = 1; ptype = "x"; }
2208  if (opt.Contains("y")) { pcase = 2; ptype = "y"; }
2209  if (opt.Contains("z")) { pcase = 3; ptype = "z"; }
2210  if (opt.Contains("xy")) { pcase = 4; ptype = "xy"; }
2211  if (opt.Contains("yx")) { pcase = 5; ptype = "yx"; }
2212  if (opt.Contains("xz")) { pcase = 6; ptype = "xz"; }
2213  if (opt.Contains("zx")) { pcase = 7; ptype = "zx"; }
2214  if (opt.Contains("yz")) { pcase = 8; ptype = "yz"; }
2215  if (opt.Contains("zy")) { pcase = 9; ptype = "zy"; }
2216 
2217  if (pcase == 0) {
2218  Error("Project3D","No projection axis specified - return a NULL pointer");
2219  return 0;
2220  }
2221  // do not remove ptype from opt to use later in the projected histo name
2222 
2223  Bool_t computeErrors = GetSumw2N();
2224  if (opt.Contains("e") ) {
2225  computeErrors = kTRUE;
2226  opt.Remove(opt.First("e"),1);
2227  }
2228 
2229  Bool_t useUF = kTRUE;
2230  Bool_t useOF = kTRUE;
2231  if (opt.Contains("nuf") ) {
2232  useUF = kFALSE;
2233  opt.Remove(opt.Index("nuf"),3);
2234  }
2235  if (opt.Contains("nof") ) {
2236  useOF = kFALSE;
2237  opt.Remove(opt.Index("nof"),3);
2238  }
2239 
2240  Bool_t originalRange = kFALSE;
2241  if (opt.Contains('o') ) {
2242  originalRange = kTRUE;
2243  opt.Remove(opt.First("o"),1);
2244  }
2245 
2246 
2247  // Create the projection histogram
2248  TH1 *h = 0;
2249 
2250  TString name = GetName();
2251  TString title = GetTitle();
2252  name += "_"; name += opt; // opt may include a user defined name
2253  title += " "; title += ptype; title += " projection";
2254 
2255  switch (pcase) {
2256  case 1:
2257  // "x"
2258  h = DoProject1D(name, title, this->GetXaxis(),
2259  computeErrors, originalRange, useUF, useOF);
2260  break;
2261 
2262  case 2:
2263  // "y"
2264  h = DoProject1D(name, title, this->GetYaxis(),
2265  computeErrors, originalRange, useUF, useOF);
2266  break;
2267 
2268  case 3:
2269  // "z"
2270  h = DoProject1D(name, title, this->GetZaxis(),
2271  computeErrors, originalRange, useUF, useOF);
2272  break;
2273 
2274  case 4:
2275  // "xy"
2276  h = DoProject2D(name, title, this->GetXaxis(),this->GetYaxis(),
2277  computeErrors, originalRange, useUF, useOF);
2278  break;
2279 
2280  case 5:
2281  // "yx"
2282  h = DoProject2D(name, title, this->GetYaxis(),this->GetXaxis(),
2283  computeErrors, originalRange, useUF, useOF);
2284  break;
2285 
2286  case 6:
2287  // "xz"
2288  h = DoProject2D(name, title, this->GetXaxis(),this->GetZaxis(),
2289  computeErrors, originalRange, useUF, useOF);
2290  break;
2291 
2292  case 7:
2293  // "zx"
2294  h = DoProject2D(name, title, this->GetZaxis(),this->GetXaxis(),
2295  computeErrors, originalRange, useUF, useOF);
2296  break;
2297 
2298  case 8:
2299  // "yz"
2300  h = DoProject2D(name, title, this->GetYaxis(),this->GetZaxis(),
2301  computeErrors, originalRange, useUF, useOF);
2302  break;
2303 
2304  case 9:
2305  // "zy"
2306  h = DoProject2D(name, title, this->GetZaxis(),this->GetYaxis(),
2307  computeErrors, originalRange, useUF, useOF);
2308  break;
2309 
2310  }
2311 
2312  // draw in current pad
2313  if (h && opt.Contains("d")) {
2314  opt.Remove(opt.First("d"),1);
2315  TVirtualPad *padsav = gPad;
2316  TVirtualPad *pad = gROOT->GetSelectedPad();
2317  if (pad) pad->cd();
2318  if (!gPad || !gPad->FindObject(h)) {
2319  h->Draw(opt);
2320  } else {
2321  h->Paint(opt);
2322  }
2323  if (padsav) padsav->cd();
2324  }
2325 
2326  return h;
2327 }
2328 
2329 
2330 ////////////////////////////////////////////////////////////////////////////////
2331 /// internal function to fill the bins of the projected profile 2D histogram
2332 /// called from DoProjectProfile2D
2333 
2335  const TAxis & a1, const TAxis & a2, const TAxis & a3,
2336  Int_t bin1, Int_t bin2, Int_t bin3,
2337  Int_t inBin, Bool_t useWeights ) const {
2338  Double_t cont = GetBinContent(inBin);
2339  if (!cont) return;
2340  TArrayD & binSumw2 = *(p2->GetBinSumw2());
2341  if (useWeights && binSumw2.fN <= 0) useWeights = false;
2342  if (!useWeights) p2->SetBit(TH1::kIsNotW); // to use Fill for setting the bin contents of the Profile
2343  // the following fill update wrongly the fBinSumw2- need to save it before
2344  Double_t u = a1.GetBinCenter(bin1);
2345  Double_t v = a2.GetBinCenter(bin2);
2346  Double_t w = a3.GetBinCenter(bin3);
2347  Int_t outBin = p2->FindBin(u, v);
2348  if (outBin <0) return;
2349  Double_t tmp = 0;
2350  if ( useWeights ) tmp = binSumw2.fArray[outBin];
2351  p2->Fill( u , v, w, cont);
2352  if (useWeights ) binSumw2.fArray[outBin] = tmp + fSumw2.fArray[inBin];
2353 }
2354 
2355 
2356 ////////////////////////////////////////////////////////////////////////////////
2357 /// internal method to project to a 2D Profile
2358 /// called from TH3::Project3DProfile
2359 
2360 TProfile2D *TH3::DoProjectProfile2D(const char* name, const char * title, const TAxis* projX, const TAxis* projY,
2361  bool originalRange, bool useUF, bool useOF) const
2362 {
2363  // Get the ranges where we will work.
2364  Int_t ixmin = projX->GetFirst();
2365  Int_t ixmax = projX->GetLast();
2366  Int_t iymin = projY->GetFirst();
2367  Int_t iymax = projY->GetLast();
2368  if (ixmin == 0 && ixmax == 0) { ixmin = 1; ixmax = projX->GetNbins(); }
2369  if (iymin == 0 && iymax == 0) { iymin = 1; iymax = projY->GetNbins(); }
2370  Int_t nx = ixmax-ixmin+1;
2371  Int_t ny = iymax-iymin+1;
2372 
2373  // Create the projected profiles
2374  TProfile2D *p2 = 0;
2375 
2376  // Create the histogram, either reseting a preexisting one
2377  // Does an object with the same name exists?
2378  TObject *p2obj = gROOT->FindObject(name);
2379  if (p2obj && p2obj->InheritsFrom(TH1::Class())) {
2380  if (p2obj->IsA() != TProfile2D::Class() ) {
2381  Error("DoProjectProfile2D","Histogram with name %s must be a TProfile2D and is a %s",name,p2obj->ClassName());
2382  return 0;
2383  }
2384  p2 = (TProfile2D*)p2obj;
2385  // reset existing profile and re-set bins
2386  p2->Reset();
2387  const TArrayD *xbins = projX->GetXbins();
2388  const TArrayD *ybins = projY->GetXbins();
2389  if ( originalRange ) {
2390  p2->SetBins(projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
2391  ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
2392  // set bins for mixed axis do not exists - need to set afterwards the variable bins
2393  if (ybins->fN != 0)
2394  p2->GetXaxis()->Set(projY->GetNbins(),&ybins->fArray[iymin-1]);
2395  if (xbins->fN != 0)
2396  p2->GetYaxis()->Set(projX->GetNbins(),&xbins->fArray[ixmin-1]);
2397  } else {
2398  p2->SetBins(ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
2399  ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
2400  if (ybins->fN != 0)
2401  p2->GetXaxis()->Set(ny,&ybins->fArray[iymin-1]);
2402  if (xbins->fN != 0)
2403  p2->GetYaxis()->Set(nx,&xbins->fArray[ixmin-1]);
2404  }
2405  }
2406 
2407  if (!p2) {
2408  const TArrayD *xbins = projX->GetXbins();
2409  const TArrayD *ybins = projY->GetXbins();
2410  if ( originalRange ) {
2411  if (xbins->fN == 0 && ybins->fN == 0) {
2412  p2 = new TProfile2D(name,title,projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
2413  ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
2414  } else if (ybins->fN == 0) {
2415  p2 = new TProfile2D(name,title,projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
2416  ,projX->GetNbins(),&xbins->fArray[ixmin-1]);
2417  } else if (xbins->fN == 0) {
2418  p2 = new TProfile2D(name,title,projY->GetNbins(),&ybins->fArray[iymin-1]
2419  ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
2420  } else {
2421  p2 = new TProfile2D(name,title,projY->GetNbins(),&ybins->fArray[iymin-1],projX->GetNbins(),&xbins->fArray[ixmin-1]);
2422  }
2423  } else {
2424  if (xbins->fN == 0 && ybins->fN == 0) {
2425  p2 = new TProfile2D(name,title,ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
2426  ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
2427  } else if (ybins->fN == 0) {
2428  p2 = new TProfile2D(name,title,ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
2429  ,nx,&xbins->fArray[ixmin-1]);
2430  } else if (xbins->fN == 0) {
2431  p2 = new TProfile2D(name,title,ny,&ybins->fArray[iymin-1]
2432  ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
2433  } else {
2434  p2 = new TProfile2D(name,title,ny,&ybins->fArray[iymin-1],nx,&xbins->fArray[ixmin-1]);
2435  }
2436  }
2437  }
2438 
2439  // Set references to the axis, so that the loop has no branches.
2440  const TAxis* outAxis = 0;
2441  if ( projX != GetXaxis() && projY != GetXaxis() ) {
2442  outAxis = GetXaxis();
2443  } else if ( projX != GetYaxis() && projY != GetYaxis() ) {
2444  outAxis = GetYaxis();
2445  } else {
2446  outAxis = GetZaxis();
2447  }
2448 
2449  // Weights management
2450  bool useWeights = (GetSumw2N() > 0);
2451  if (useWeights ) p2->Sumw2(); // store sum of w2 in profile if histo is weighted
2452 
2453  // Set references to the bins, so that the loop has no branches.
2454  Int_t *refX = 0, *refY = 0, *refZ = 0;
2455  Int_t ixbin, iybin, outbin;
2456  if ( projX == GetXaxis() && projY == GetYaxis() ) { refX = &ixbin; refY = &iybin; refZ = &outbin; }
2457  if ( projX == GetYaxis() && projY == GetXaxis() ) { refX = &iybin; refY = &ixbin; refZ = &outbin; }
2458  if ( projX == GetXaxis() && projY == GetZaxis() ) { refX = &ixbin; refY = &outbin; refZ = &iybin; }
2459  if ( projX == GetZaxis() && projY == GetXaxis() ) { refX = &iybin; refY = &outbin; refZ = &ixbin; }
2460  if ( projX == GetYaxis() && projY == GetZaxis() ) { refX = &outbin; refY = &ixbin; refZ = &iybin; }
2461  if ( projX == GetZaxis() && projY == GetYaxis() ) { refX = &outbin; refY = &iybin; refZ = &ixbin; }
2462  R__ASSERT (refX != 0 && refY != 0 && refZ != 0);
2463 
2464  Int_t outmin = outAxis->GetFirst();
2465  Int_t outmax = outAxis->GetLast();
2466  // GetFirst(), GetLast() can return (0,0) when the range bit is set artifically (see TAxis::SetRange)
2467  if (outmin == 0 && outmax == 0) { outmin = 1; outmax = outAxis->GetNbins(); }
2468  // correct for underflow/overflows
2469  if (useUF && !outAxis->TestBit(TAxis::kAxisRange) ) outmin -= 1;
2470  if (useOF && !outAxis->TestBit(TAxis::kAxisRange) ) outmax += 1;
2471 
2472  TArrayD & binSumw2 = *(p2->GetBinSumw2());
2473  if (useWeights && binSumw2.fN <= 0) useWeights = false;
2474  if (!useWeights) p2->SetBit(TH1::kIsNotW);
2475 
2476  // Call specific method for the projection
2477  for (ixbin=0;ixbin<=1+projX->GetNbins();ixbin++) {
2478  if ( (ixbin < ixmin || ixbin > ixmax) && projX->TestBit(TAxis::kAxisRange)) continue;
2479  for ( iybin=0;iybin<=1+projY->GetNbins();iybin++) {
2480  if ( (iybin < iymin || iybin > iymax) && projX->TestBit(TAxis::kAxisRange)) continue;
2481 
2482  // profile output bin
2483  Int_t poutBin = p2->FindBin(projY->GetBinCenter(iybin), projX->GetBinCenter(ixbin));
2484  if (poutBin <0) continue;
2485  // loop on the bins to be integrated (outbin should be called inbin)
2486  for (outbin = outmin; outbin <= outmax; outbin++) {
2487 
2488  Int_t bin = GetBin(*refX,*refY,*refZ);
2489 
2490  //DoFillProfileProjection(p2, *projY, *projX, *outAxis, iybin, ixbin, outbin, bin, useWeights);
2491 
2492  Double_t cont = RetrieveBinContent(bin);
2493  if (!cont) continue;
2494 
2495  Double_t tmp = 0;
2496  // the following fill update wrongly the fBinSumw2- need to save it before
2497  if ( useWeights ) tmp = binSumw2.fArray[poutBin];
2498  p2->Fill( projY->GetBinCenter(iybin) , projX->GetBinCenter(ixbin), outAxis->GetBinCenter(outbin), cont);
2499  if (useWeights ) binSumw2.fArray[poutBin] = tmp + fSumw2.fArray[bin];
2500 
2501  }
2502  }
2503  }
2504 
2505  // recompute statistics for the projected profiles
2506  // forget about preserving old statistics
2507  bool resetStats = true;
2508  Double_t stats[kNstat];
2509  // reset statistics
2510  if (resetStats)
2511  for (Int_t i=0;i<kNstat;i++) stats[i] = 0;
2512 
2513  p2->PutStats(stats);
2514  Double_t entries = fEntries;
2515  // recalculate the statistics
2516  if (resetStats) {
2517  entries = p2->GetEffectiveEntries();
2518  if (!useWeights) entries = TMath::Floor( entries + 0.5); // to avoid numerical rounding
2519  p2->SetEntries( entries );
2520  }
2521 
2522  p2->SetEntries(entries);
2523 
2524  return p2;
2525 }
2526 
2527 
2528 ////////////////////////////////////////////////////////////////////////////////
2529 /// Project a 3-d histogram into a 2-d profile histograms depending
2530 /// on the option parameter
2531 /// option may contain a combination of the characters x,y,z
2532 /// option = "xy" return the x versus y projection into a TProfile2D histogram
2533 /// option = "yx" return the y versus x projection into a TProfile2D histogram
2534 /// option = "xz" return the x versus z projection into a TProfile2D histogram
2535 /// option = "zx" return the z versus x projection into a TProfile2D histogram
2536 /// option = "yz" return the y versus z projection into a TProfile2D histogram
2537 /// option = "zy" return the z versus y projection into a TProfile2D histogram
2538 /// NB: the notation "a vs b" means "a" vertical and "b" horizontal
2539 ///
2540 /// option = "o" original axis range of the target axes will be
2541 /// kept, but only bins inside the selected range will be filled.
2542 ///
2543 /// The projection is made for the selected bins only.
2544 /// To select a bin range along an axis, use TAxis::SetRange, eg
2545 /// h3.GetYaxis()->SetRange(23,56);
2546 ///
2547 /// NOTE 1: The generated histogram is named th3name + "_p" + option
2548 /// eg if the TH3* h histogram is named "myhist", then
2549 /// h->Project3D("xy"); produces a TProfile2D histogram named "myhist_pxy".
2550 /// The following sequence
2551 /// h->Project3DProfile("xy");
2552 /// h->Project3DProfile("xy2");
2553 /// will generate two TProfile2D histograms named "myhist_pxy" and "myhist_pxy2"
2554 /// So, passing additional characters in the option string one can customize the name.
2555 ///
2556 /// NOTE 2: If a profile of the same type already exists with compatible axes,
2557 /// the profile is reset and filled again with the projected contents of the TH3.
2558 /// In the case of axes incompatibility, an error is reported and a NULL pointer is returned.
2559 ///
2560 /// NOTE 3: The number of entries in the projected profile is estimated from the number of
2561 /// effective entries for all the cells included in the projection.
2562 ///
2563 /// NOTE 4: underflow/overflow are by default excluded from the projection
2564 /// (Note that this is a different default behavior compared to the projection to an histogram)
2565 /// To include the underflow and/or overflow use option "UF" and/or "OF"
2566 
2568 {
2569  TString opt = option; opt.ToLower();
2570  Int_t pcase = 0;
2571  TString ptype;
2572  if (opt.Contains("xy")) { pcase = 4; ptype = "xy"; }
2573  if (opt.Contains("yx")) { pcase = 5; ptype = "yx"; }
2574  if (opt.Contains("xz")) { pcase = 6; ptype = "xz"; }
2575  if (opt.Contains("zx")) { pcase = 7; ptype = "zx"; }
2576  if (opt.Contains("yz")) { pcase = 8; ptype = "yz"; }
2577  if (opt.Contains("zy")) { pcase = 9; ptype = "zy"; }
2578 
2579  if (pcase == 0) {
2580  Error("Project3D","No projection axis specified - return a NULL pointer");
2581  return 0;
2582  }
2583  // do not remove ptype from opt to use later in the projected histo name
2584 
2585  Bool_t useUF = kFALSE;
2586  if (opt.Contains("uf") ) {
2587  useUF = kTRUE;
2588  opt.Remove(opt.Index("uf"),2);
2589  }
2590  Bool_t useOF = kFALSE;
2591  if (opt.Contains("of") ) {
2592  useOF = kTRUE;
2593  opt.Remove(opt.Index("of"),2);
2594  }
2595 
2596  Bool_t originalRange = kFALSE;
2597  if (opt.Contains('o') ) {
2598  originalRange = kTRUE;
2599  opt.Remove(opt.First("o"),1);
2600  }
2601 
2602  // Create the projected profile
2603  TProfile2D *p2 = 0;
2604  TString name = GetName();
2605  TString title = GetTitle();
2606  name += "_p"; name += opt; // opt may include a user defined name
2607  title += " profile "; title += ptype; title += " projection";
2608 
2609  // Call the method with the specific projected axes.
2610  switch (pcase) {
2611  case 4:
2612  // "xy"
2613  p2 = DoProjectProfile2D(name, title, GetXaxis(), GetYaxis(), originalRange, useUF, useOF);
2614  break;
2615 
2616  case 5:
2617  // "yx"
2618  p2 = DoProjectProfile2D(name, title, GetYaxis(), GetXaxis(), originalRange, useUF, useOF);
2619  break;
2620 
2621  case 6:
2622  // "xz"
2623  p2 = DoProjectProfile2D(name, title, GetXaxis(), GetZaxis(), originalRange, useUF, useOF);
2624  break;
2625 
2626  case 7:
2627  // "zx"
2628  p2 = DoProjectProfile2D(name, title, GetZaxis(), GetXaxis(), originalRange, useUF, useOF);
2629  break;
2630 
2631  case 8:
2632  // "yz"
2633  p2 = DoProjectProfile2D(name, title, GetYaxis(), GetZaxis(), originalRange, useUF, useOF);
2634  break;
2635 
2636  case 9:
2637  // "zy"
2638  p2 = DoProjectProfile2D(name, title, GetZaxis(), GetYaxis(), originalRange, useUF, useOF);
2639  break;
2640 
2641  }
2642 
2643  return p2;
2644 }
2645 
2646 
2647 ////////////////////////////////////////////////////////////////////////////////
2648 /// Replace current statistics with the values in array stats
2649 
2651 {
2652  TH1::PutStats(stats);
2653  fTsumwy = stats[4];
2654  fTsumwy2 = stats[5];
2655  fTsumwxy = stats[6];
2656  fTsumwz = stats[7];
2657  fTsumwz2 = stats[8];
2658  fTsumwxz = stats[9];
2659  fTsumwyz = stats[10];
2660 }
2661 
2662 
2663 ////////////////////////////////////////////////////////////////////////////////
2664 /// Rebin only the X axis
2665 /// see Rebin3D
2666 
2667 TH3 *TH3::RebinX(Int_t ngroup, const char *newname)
2668 {
2669  return Rebin3D(ngroup, 1, 1, newname);
2670 }
2671 
2672 
2673 ////////////////////////////////////////////////////////////////////////////////
2674 /// Rebin only the Y axis
2675 /// see Rebin3D
2676 
2677 TH3 *TH3::RebinY(Int_t ngroup, const char *newname)
2678 {
2679  return Rebin3D(1, ngroup, 1, newname);
2680 }
2681 
2682 
2683 ////////////////////////////////////////////////////////////////////////////////
2684 /// Rebin only the Z axis
2685 /// see Rebin3D
2686 
2687 TH3 *TH3::RebinZ(Int_t ngroup, const char *newname)
2688 {
2689  return Rebin3D(1, 1, ngroup, newname);
2690 
2691 }
2692 
2693 
2694 ////////////////////////////////////////////////////////////////////////////////
2695 /// Rebin this histogram grouping nxgroup/nygroup/nzgroup bins along the xaxis/yaxis/zaxis together.
2696 ///
2697 /// if newname is not blank a new temporary histogram hnew is created.
2698 /// else the current histogram is modified (default)
2699 /// The parameter nxgroup/nygroup indicate how many bins along the xaxis/yaxis of this
2700 /// have to me merged into one bin of hnew
2701 /// If the original histogram has errors stored (via Sumw2), the resulting
2702 /// histograms has new errors correctly calculated.
2703 ///
2704 /// examples: if hpxpy is an existing TH3 histogram with 40 x 40 x 40 bins
2705 /// hpxpypz->Rebin3D(); // merges two bins along the xaxis and yaxis in one in hpxpypz
2706 /// // Carefull: previous contents of hpxpy are lost
2707 /// hpxpypz->RebinX(5); //merges five bins along the xaxis in one in hpxpypz
2708 /// TH3 *hnew = hpxpypz->RebinY(5,"hnew"); // creates a new histogram hnew
2709 /// // merging 5 bins of h1 along the yaxis in one bin
2710 ///
2711 /// NOTE : If nxgroup/nygroup is not an exact divider of the number of bins,
2712 /// along the xaxis/yaxis the top limit(s) of the rebinned histogram
2713 /// is changed to the upper edge of the xbin=newxbins*nxgroup resp.
2714 /// ybin=newybins*nygroup and the corresponding bins are added to
2715 /// the overflow bin.
2716 /// Statistics will be recomputed from the new bin contents.
2717 
2718 TH3 *TH3::Rebin3D(Int_t nxgroup, Int_t nygroup, Int_t nzgroup, const char *newname)
2719 {
2720  Int_t i,j,k,xbin,ybin,zbin;
2721  Int_t nxbins = fXaxis.GetNbins();
2722  Int_t nybins = fYaxis.GetNbins();
2723  Int_t nzbins = fZaxis.GetNbins();
2728  Double_t zmin = fZaxis.GetXmin();
2729  Double_t zmax = fZaxis.GetXmax();
2730  if ((nxgroup <= 0) || (nxgroup > nxbins)) {
2731  Error("Rebin", "Illegal value of nxgroup=%d",nxgroup);
2732  return 0;
2733  }
2734  if ((nygroup <= 0) || (nygroup > nybins)) {
2735  Error("Rebin", "Illegal value of nygroup=%d",nygroup);
2736  return 0;
2737  }
2738  if ((nzgroup <= 0) || (nzgroup > nzbins)) {
2739  Error("Rebin", "Illegal value of nzgroup=%d",nzgroup);
2740  return 0;
2741  }
2742 
2743  Int_t newxbins = nxbins/nxgroup;
2744  Int_t newybins = nybins/nygroup;
2745  Int_t newzbins = nzbins/nzgroup;
2746 
2747  // Save old bin contents into a new array
2748  Double_t entries = fEntries;
2749  Double_t *oldBins = new Double_t[fNcells];
2750  for (Int_t ibin = 0; ibin < fNcells; ibin++) {
2751  oldBins[ibin] = RetrieveBinContent(ibin);
2752  }
2753  Double_t *oldSumw2 = 0;
2754  if (fSumw2.fN != 0) {
2755  oldSumw2 = new Double_t[fNcells];
2756  for (Int_t ibin = 0; ibin < fNcells; ibin++) {
2757  oldSumw2[ibin] = fSumw2.fArray[ibin];
2758  }
2759  }
2760 
2761  // create a clone of the old histogram if newname is specified
2762  TH3 *hnew = this;
2763  if (newname && strlen(newname)) {
2764  hnew = (TH3*)Clone();
2765  hnew->SetName(newname);
2766  }
2767 
2768  // save original statistics
2769  Double_t stat[kNstat];
2770  GetStats(stat);
2771  bool resetStat = false;
2772 
2773 
2774  // change axis specs and rebuild bin contents array
2775  if (newxbins*nxgroup != nxbins) {
2776  xmax = fXaxis.GetBinUpEdge(newxbins*nxgroup);
2777  resetStat = true; //stats must be reset because top bins will be moved to overflow bin
2778  }
2779  if (newybins*nygroup != nybins) {
2780  ymax = fYaxis.GetBinUpEdge(newybins*nygroup);
2781  resetStat = true; //stats must be reset because top bins will be moved to overflow bin
2782  }
2783  if (newzbins*nzgroup != nzbins) {
2784  zmax = fZaxis.GetBinUpEdge(newzbins*nzgroup);
2785  resetStat = true; //stats must be reset because top bins will be moved to overflow bin
2786  }
2787  // save the TAttAxis members (reset by SetBins) for x axis
2788  Int_t nXdivisions = fXaxis.GetNdivisions();
2789  Color_t xAxisColor = fXaxis.GetAxisColor();
2790  Color_t xLabelColor = fXaxis.GetLabelColor();
2791  Style_t xLabelFont = fXaxis.GetLabelFont();
2792  Float_t xLabelOffset = fXaxis.GetLabelOffset();
2793  Float_t xLabelSize = fXaxis.GetLabelSize();
2794  Float_t xTickLength = fXaxis.GetTickLength();
2795  Float_t xTitleOffset = fXaxis.GetTitleOffset();
2796  Float_t xTitleSize = fXaxis.GetTitleSize();
2797  Color_t xTitleColor = fXaxis.GetTitleColor();
2798  Style_t xTitleFont = fXaxis.GetTitleFont();
2799  // save the TAttAxis members (reset by SetBins) for y axis
2800  Int_t nYdivisions = fYaxis.GetNdivisions();
2801  Color_t yAxisColor = fYaxis.GetAxisColor();
2802  Color_t yLabelColor = fYaxis.GetLabelColor();
2803  Style_t yLabelFont = fYaxis.GetLabelFont();
2804  Float_t yLabelOffset = fYaxis.GetLabelOffset();
2805  Float_t yLabelSize = fYaxis.GetLabelSize();
2806  Float_t yTickLength = fYaxis.GetTickLength();
2807  Float_t yTitleOffset = fYaxis.GetTitleOffset();
2808  Float_t yTitleSize = fYaxis.GetTitleSize();
2809  Color_t yTitleColor = fYaxis.GetTitleColor();
2810  Style_t yTitleFont = fYaxis.GetTitleFont();
2811  // save the TAttAxis members (reset by SetBins) for z axis
2812  Int_t nZdivisions = fZaxis.GetNdivisions();
2813  Color_t zAxisColor = fZaxis.GetAxisColor();
2814  Color_t zLabelColor = fZaxis.GetLabelColor();
2815  Style_t zLabelFont = fZaxis.GetLabelFont();
2816  Float_t zLabelOffset = fZaxis.GetLabelOffset();
2817  Float_t zLabelSize = fZaxis.GetLabelSize();
2818  Float_t zTickLength = fZaxis.GetTickLength();
2819  Float_t zTitleOffset = fZaxis.GetTitleOffset();
2820  Float_t zTitleSize = fZaxis.GetTitleSize();
2821  Color_t zTitleColor = fZaxis.GetTitleColor();
2822  Style_t zTitleFont = fZaxis.GetTitleFont();
2823 
2824  // copy merged bin contents (ignore under/overflows)
2825  if (nxgroup != 1 || nygroup != 1 || nzgroup != 1) {
2826  if (fXaxis.GetXbins()->GetSize() > 0 || fYaxis.GetXbins()->GetSize() > 0 || fZaxis.GetXbins()->GetSize() > 0) {
2827  // variable bin sizes in x or y, don't treat both cases separately
2828  Double_t *xbins = new Double_t[newxbins+1];
2829  for (i = 0; i <= newxbins; ++i) xbins[i] = fXaxis.GetBinLowEdge(1+i*nxgroup);
2830  Double_t *ybins = new Double_t[newybins+1];
2831  for (i = 0; i <= newybins; ++i) ybins[i] = fYaxis.GetBinLowEdge(1+i*nygroup);
2832  Double_t *zbins = new Double_t[newzbins+1];
2833  for (i = 0; i <= newzbins; ++i) zbins[i] = fZaxis.GetBinLowEdge(1+i*nzgroup);
2834  hnew->SetBins(newxbins,xbins, newybins, ybins, newzbins, zbins);//changes also errors array (if any)
2835  delete [] xbins;
2836  delete [] ybins;
2837  delete [] zbins;
2838  } else {
2839  hnew->SetBins(newxbins, xmin, xmax, newybins, ymin, ymax, newzbins, zmin, zmax);//changes also errors array
2840  }
2841 
2842  Double_t binContent, binSumw2;
2843  Int_t oldxbin = 1;
2844  Int_t oldybin = 1;
2845  Int_t oldzbin = 1;
2846  Int_t bin;
2847  for (xbin = 1; xbin <= newxbins; xbin++) {
2848  oldybin=1;
2849  oldzbin=1;
2850  for (ybin = 1; ybin <= newybins; ybin++) {
2851  oldzbin=1;
2852  for (zbin = 1; zbin <= newzbins; zbin++) {
2853  binContent = 0;
2854  binSumw2 = 0;
2855  for (i = 0; i < nxgroup; i++) {
2856  if (oldxbin+i > nxbins) break;
2857  for (j =0; j < nygroup; j++) {
2858  if (oldybin+j > nybins) break;
2859  for (k =0; k < nzgroup; k++) {
2860  if (oldzbin+k > nzbins) break;
2861  //get global bin (same conventions as in TH1::GetBin(xbin,ybin)
2862  bin = oldxbin + i + (oldybin + j)*(nxbins + 2) + (oldzbin + k)*(nxbins + 2)*(nybins + 2);
2863  binContent += oldBins[bin];
2864  if (oldSumw2) binSumw2 += oldSumw2[bin];
2865  }
2866  }
2867  }
2868  Int_t ibin = hnew->GetBin(xbin,ybin,zbin); // new bin number
2869  hnew->SetBinContent(ibin, binContent);
2870  if (oldSumw2) hnew->fSumw2.fArray[ibin] = binSumw2;
2871  oldzbin += nzgroup;
2872  }
2873  oldybin += nygroup;
2874  }
2875  oldxbin += nxgroup;
2876  }
2877 
2878  // compute new underflow/overflows for the 8 vertices
2879  for (Int_t xover = 0; xover <= 1; xover++) {
2880  for (Int_t yover = 0; yover <= 1; yover++) {
2881  for (Int_t zover = 0; zover <= 1; zover++) {
2882  binContent = 0;
2883  binSumw2 = 0;
2884  // make loop in case of only underflow/overflow
2885  for (xbin = xover*oldxbin; xbin <= xover*(nxbins+1); xbin++) {
2886  for (ybin = yover*oldybin; ybin <= yover*(nybins+1); ybin++) {
2887  for (zbin = zover*oldzbin; zbin <= zover*(nzbins+1); zbin++) {
2888  bin = GetBin(xbin,ybin,zbin);
2889  binContent += oldBins[bin];
2890  if (oldSumw2) binSumw2 += oldSumw2[bin];
2891  }
2892  }
2893  }
2894  Int_t binNew = hnew->GetBin( xover *(newxbins+1),
2895  yover*(newybins+1), zover*(newzbins+1) );
2896  hnew->SetBinContent(binNew,binContent);
2897  if (oldSumw2) hnew->fSumw2.fArray[binNew] = binSumw2;
2898  }
2899  }
2900  }
2901 
2902  Double_t binContent0, binContent2, binContent3, binContent4;
2903  Double_t binError0, binError2, binError3, binError4;
2904  Int_t oldxbin2, oldybin2, oldzbin2;
2905  Int_t ufbin, ofbin, ofbin2, ofbin3, ofbin4;
2906 
2907  // recompute under/overflow contents in y for the new x and z bins
2908  oldxbin2 = 1;
2909  oldybin2 = 1;
2910  oldzbin2 = 1;
2911  for (xbin = 1; xbin<=newxbins; xbin++) {
2912  oldzbin2 = 1;
2913  for (zbin = 1; zbin<=newzbins; zbin++) {
2914  binContent0 = binContent2 = 0;
2915  binError0 = binError2 = 0;
2916  for (i=0; i<nxgroup; i++) {
2917  if (oldxbin2+i > nxbins) break;
2918  for (k=0; k<nzgroup; k++) {
2919  if (oldzbin2+k > nzbins) break;
2920  //old underflow bin (in y)
2921  ufbin = oldxbin2 + i + (nxbins+2)*(nybins+2)*(oldzbin2+k);
2922  binContent0 += oldBins[ufbin];
2923  if (oldSumw2) binError0 += oldSumw2[ufbin];
2924  for (ybin = oldybin; ybin <= nybins + 1; ybin++) {
2925  //old overflow bin (in y)
2926  ofbin = ufbin + ybin*(nxbins+2);
2927  binContent2 += oldBins[ofbin];
2928  if (oldSumw2) binError2 += oldSumw2[ofbin];
2929  }
2930  }
2931  }
2932  hnew->SetBinContent(xbin,0,zbin,binContent0);
2933  hnew->SetBinContent(xbin,newybins+1,zbin,binContent2);
2934  if (oldSumw2) {
2935  hnew->SetBinError(xbin,0,zbin,TMath::Sqrt(binError0));
2936  hnew->SetBinError(xbin,newybins+1,zbin,TMath::Sqrt(binError2) );
2937  }
2938  oldzbin2 += nzgroup;
2939  }
2940  oldxbin2 += nxgroup;
2941  }
2942 
2943  // recompute under/overflow contents in x for the new y and z bins
2944  oldxbin2 = 1;
2945  oldybin2 = 1;
2946  oldzbin2 = 1;
2947  for (ybin = 1; ybin<=newybins; ybin++) {
2948  oldzbin2 = 1;
2949  for (zbin = 1; zbin<=newzbins; zbin++) {
2950  binContent0 = binContent2 = 0;
2951  binError0 = binError2 = 0;
2952  for (j=0; j<nygroup; j++) {
2953  if (oldybin2+j > nybins) break;
2954  for (k=0; k<nzgroup; k++) {
2955  if (oldzbin2+k > nzbins) break;
2956  //old underflow bin (in y)
2957  ufbin = (oldybin2 + j)*(nxbins+2) + (nxbins+2)*(nybins+2)*(oldzbin2+k);
2958  binContent0 += oldBins[ufbin];
2959  if (oldSumw2) binError0 += oldSumw2[ufbin];
2960  for (xbin = oldxbin; xbin <= nxbins + 1; xbin++) {
2961  //old overflow bin (in x)
2962  ofbin = ufbin + xbin;
2963  binContent2 += oldBins[ofbin];
2964  if (oldSumw2) binError2 += oldSumw2[ofbin];
2965  }
2966  }
2967  }
2968  hnew->SetBinContent(0,ybin,zbin,binContent0);
2969  hnew->SetBinContent(newxbins+1,ybin,zbin,binContent2);
2970  if (oldSumw2) {
2971  hnew->SetBinError(0,ybin,zbin,TMath::Sqrt(binError0));
2972  hnew->SetBinError(newxbins+1,ybin,zbin,TMath::Sqrt(binError2) );
2973  }
2974  oldzbin2 += nzgroup;
2975  }
2976  oldybin2 += nygroup;
2977  }
2978 
2979  // recompute under/overflow contents in z for the new x and y bins
2980  oldxbin2 = 1;
2981  oldybin2 = 1;
2982  oldzbin2 = 1;
2983  for (xbin = 1; xbin<=newxbins; xbin++) {
2984  oldybin2 = 1;
2985  for (ybin = 1; ybin<=newybins; ybin++) {
2986  binContent0 = binContent2 = 0;
2987  binError0 = binError2 = 0;
2988  for (i=0; i<nxgroup; i++) {
2989  if (oldxbin2+i > nxbins) break;
2990  for (j=0; j<nygroup; j++) {
2991  if (oldybin2+j > nybins) break;
2992  //old underflow bin (in z)
2993  ufbin = oldxbin2 + i + (nxbins+2)*(oldybin2+j);
2994  binContent0 += oldBins[ufbin];
2995  if (oldSumw2) binError0 += oldSumw2[ufbin];
2996  for (zbin = oldzbin; zbin <= nzbins + 1; zbin++) {
2997  //old overflow bin (in z)
2998  ofbin = ufbin + (nxbins+2)*(nybins+2)*zbin;
2999  binContent2 += oldBins[ofbin];
3000  if (oldSumw2) binError2 += oldSumw2[ofbin];
3001  }
3002  }
3003  }
3004  hnew->SetBinContent(xbin,ybin,0,binContent0);
3005  hnew->SetBinContent(xbin,ybin,newzbins+1,binContent2);
3006  if (oldSumw2) {
3007  hnew->SetBinError(xbin,ybin,0,TMath::Sqrt(binError0));
3008  hnew->SetBinError(xbin,ybin,newzbins+1,TMath::Sqrt(binError2) );
3009  }
3010  oldybin2 += nygroup;
3011  }
3012  oldxbin2 += nxgroup;
3013  }
3014 
3015  // recompute under/overflow contents in y, z for the new x
3016  oldxbin2 = 1;
3017  oldybin2 = 1;
3018  oldzbin2 = 1;
3019  for (xbin = 1; xbin<=newxbins; xbin++) {
3020  binContent0 = 0;
3021  binContent2 = 0;
3022  binContent3 = 0;
3023  binContent4 = 0;
3024  binError0 = 0;
3025  binError2 = 0;
3026  binError3 = 0;
3027  binError4 = 0;
3028  for (i=0; i<nxgroup; i++) {
3029  if (oldxbin2+i > nxbins) break;
3030  ufbin = oldxbin2 + i; //
3031  binContent0 += oldBins[ufbin];
3032  if (oldSumw2) binError0 += oldSumw2[ufbin];
3033  for (ybin = oldybin; ybin <= nybins + 1; ybin++) {
3034  ofbin3 = ufbin+ybin*(nxbins+2);
3035  binContent3 += oldBins[ ofbin3 ];
3036  if (oldSumw2) binError3 += oldSumw2[ofbin3];
3037  for (zbin = oldzbin; zbin <= nzbins + 1; zbin++) {
3038  //old overflow bin (in z)
3039  ofbin4 = oldxbin2 + i + ybin*(nxbins+2) + (nxbins+2)*(nybins+2)*zbin;
3040  binContent4 += oldBins[ofbin4];
3041  if (oldSumw2) binError4 += oldSumw2[ofbin4];
3042  }
3043  }
3044  for (zbin = oldzbin; zbin <= nzbins + 1; zbin++) {
3045  ofbin2 = ufbin+zbin*(nxbins+2)*(nybins+2);
3046  binContent2 += oldBins[ ofbin2 ];
3047  if (oldSumw2) binError2 += oldSumw2[ofbin2];
3048  }
3049  }
3050  hnew->SetBinContent(xbin,0,0,binContent0);
3051  hnew->SetBinContent(xbin,0,newzbins+1,binContent2);
3052  hnew->SetBinContent(xbin,newybins+1,0,binContent3);
3053  hnew->SetBinContent(xbin,newybins+1,newzbins+1,binContent4);
3054  if (oldSumw2) {
3055  hnew->SetBinError(xbin,0,0,TMath::Sqrt(binError0));
3056  hnew->SetBinError(xbin,0,newzbins+1,TMath::Sqrt(binError2) );
3057  hnew->SetBinError(xbin,newybins+1,0,TMath::Sqrt(binError3) );
3058  hnew->SetBinError(xbin,newybins+1,newzbins+1,TMath::Sqrt(binError4) );
3059  }
3060  oldxbin2 += nxgroup;
3061  }
3062 
3063  // recompute under/overflow contents in x, y for the new z
3064  oldxbin2 = 1;
3065  oldybin2 = 1;
3066  oldzbin2 = 1;
3067  for (zbin = 1; zbin<=newzbins; zbin++) {
3068  binContent0 = 0;
3069  binContent2 = 0;
3070  binContent3 = 0;
3071  binContent4 = 0;
3072  binError0 = 0;
3073  binError2 = 0;
3074  binError3 = 0;
3075  binError4 = 0;
3076  for (i=0; i<nzgroup; i++) {
3077  if (oldzbin2+i > nzbins) break;
3078  ufbin = (oldzbin2 + i)*(nxbins+2)*(nybins+2); //
3079  binContent0 += oldBins[ufbin];
3080  if (oldSumw2) binError0 += oldSumw2[ufbin];
3081  for (ybin = oldybin; ybin <= nybins + 1; ybin++) {
3082  ofbin3 = ufbin+ybin*(nxbins+2);
3083  binContent3 += oldBins[ ofbin3 ];
3084  if (oldSumw2) binError3 += oldSumw2[ofbin3];
3085  for (xbin = oldxbin; xbin <= nxbins + 1; xbin++) {
3086  //old overflow bin (in z)
3087  ofbin4 = ufbin + xbin + ybin*(nxbins+2);
3088  binContent4 += oldBins[ofbin4];
3089  if (oldSumw2) binError4 += oldSumw2[ofbin4];
3090  }
3091  }
3092  for (xbin = oldxbin; xbin <= nxbins + 1; xbin++) {
3093  ofbin2 = xbin +(oldzbin2+i)*(nxbins+2)*(nybins+2);
3094  binContent2 += oldBins[ ofbin2 ];
3095  if (oldSumw2) binError2 += oldSumw2[ofbin2];
3096  }
3097  }
3098  hnew->SetBinContent(0,0,zbin,binContent0);
3099  hnew->SetBinContent(0,newybins+1,zbin,binContent3);
3100  hnew->SetBinContent(newxbins+1,0,zbin,binContent2);
3101  hnew->SetBinContent(newxbins+1,newybins+1,zbin,binContent4);
3102  if (oldSumw2) {
3103  hnew->SetBinError(0,0,zbin,TMath::Sqrt(binError0));
3104  hnew->SetBinError(0,newybins+1,zbin,TMath::Sqrt(binError3) );
3105  hnew->SetBinError(newxbins+1,0,zbin,TMath::Sqrt(binError2) );
3106  hnew->SetBinError(newxbins+1,newybins+1,zbin,TMath::Sqrt(binError4) );
3107  }
3108  oldzbin2 += nzgroup;
3109  }
3110 
3111  // recompute under/overflow contents in x, z for the new y
3112  oldxbin2 = 1;
3113  oldybin2 = 1;
3114  oldzbin2 = 1;
3115  for (ybin = 1; ybin<=newybins; ybin++) {
3116  binContent0 = 0;
3117  binContent2 = 0;
3118  binContent3 = 0;
3119  binContent4 = 0;
3120  binError0 = 0;
3121  binError2 = 0;
3122  binError3 = 0;
3123  binError4 = 0;
3124  for (i=0; i<nygroup; i++) {
3125  if (oldybin2+i > nybins) break;
3126  ufbin = (oldybin2 + i)*(nxbins+2); //
3127  binContent0 += oldBins[ufbin];
3128  if (oldSumw2) binError0 += oldSumw2[ufbin];
3129  for (xbin = oldxbin; xbin <= nxbins + 1; xbin++) {
3130  ofbin3 = ufbin+xbin;
3131  binContent3 += oldBins[ ofbin3 ];
3132  if (oldSumw2) binError3 += oldSumw2[ofbin3];
3133  for (zbin = oldzbin; zbin <= nzbins + 1; zbin++) {
3134  //old overflow bin (in z)
3135  ofbin4 = xbin + (nxbins+2)*(nybins+2)*zbin+(oldybin2+i)*(nxbins+2);
3136  binContent4 += oldBins[ofbin4];
3137  if (oldSumw2) binError4 += oldSumw2[ofbin4];
3138  }
3139  }
3140  for (zbin = oldzbin; zbin <= nzbins + 1; zbin++) {
3141  ofbin2 = (oldybin2+i)*(nxbins+2)+zbin*(nxbins+2)*(nybins+2);
3142  binContent2 += oldBins[ ofbin2 ];
3143  if (oldSumw2) binError2 += oldSumw2[ofbin2];
3144  }
3145  }
3146  hnew->SetBinContent(0,ybin,0,binContent0);
3147  hnew->SetBinContent(0,ybin,newzbins+1,binContent2);
3148  hnew->SetBinContent(newxbins+1,ybin,0,binContent3);
3149  hnew->SetBinContent(newxbins+1,ybin,newzbins+1,binContent4);
3150  if (oldSumw2) {
3151  hnew->SetBinError(0,ybin,0,TMath::Sqrt(binError0));
3152  hnew->SetBinError(0,ybin,newzbins+1,TMath::Sqrt(binError2) );
3153  hnew->SetBinError(newxbins+1,ybin,0,TMath::Sqrt(binError3) );
3154  hnew->SetBinError(newxbins+1,ybin,newzbins+1,TMath::Sqrt(binError4) );
3155  }
3156  oldybin2 += nygroup;
3157  }
3158  }
3159 
3160  // Restore x axis attributes
3161  fXaxis.SetNdivisions(nXdivisions);
3162  fXaxis.SetAxisColor(xAxisColor);
3163  fXaxis.SetLabelColor(xLabelColor);
3164  fXaxis.SetLabelFont(xLabelFont);
3165  fXaxis.SetLabelOffset(xLabelOffset);
3166  fXaxis.SetLabelSize(xLabelSize);
3167  fXaxis.SetTickLength(xTickLength);
3168  fXaxis.SetTitleOffset(xTitleOffset);
3169  fXaxis.SetTitleSize(xTitleSize);
3170  fXaxis.SetTitleColor(xTitleColor);
3171  fXaxis.SetTitleFont(xTitleFont);
3172  // Restore y axis attributes
3173  fYaxis.SetNdivisions(nYdivisions);
3174  fYaxis.SetAxisColor(yAxisColor);
3175  fYaxis.SetLabelColor(yLabelColor);
3176  fYaxis.SetLabelFont(yLabelFont);
3177  fYaxis.SetLabelOffset(yLabelOffset);
3178  fYaxis.SetLabelSize(yLabelSize);
3179  fYaxis.SetTickLength(yTickLength);
3180  fYaxis.SetTitleOffset(yTitleOffset);
3181  fYaxis.SetTitleSize(yTitleSize);
3182  fYaxis.SetTitleColor(yTitleColor);
3183  fYaxis.SetTitleFont(yTitleFont);
3184  // Restore z axis attributes
3185  fZaxis.SetNdivisions(nZdivisions);
3186  fZaxis.SetAxisColor(zAxisColor);
3187  fZaxis.SetLabelColor(zLabelColor);
3188  fZaxis.SetLabelFont(zLabelFont);
3189  fZaxis.SetLabelOffset(zLabelOffset);
3190  fZaxis.SetLabelSize(zLabelSize);
3191  fZaxis.SetTickLength(zTickLength);
3192  fZaxis.SetTitleOffset(zTitleOffset);
3193  fZaxis.SetTitleSize(zTitleSize);
3194  fZaxis.SetTitleColor(zTitleColor);
3195  fZaxis.SetTitleFont(zTitleFont);
3196 
3197  //restore statistics and entries modified by SetBinContent
3198  hnew->SetEntries(entries);
3199  if (!resetStat) hnew->PutStats(stat);
3200 
3201  delete [] oldBins;
3202  if (oldSumw2) delete [] oldSumw2;
3203  return hnew;
3204 }
3205 
3206 
3207 ////////////////////////////////////////////////////////////////////////////////
3208 /// Reset this histogram: contents, errors, etc.
3209 
3210 void TH3::Reset(Option_t *option)
3211 {
3212  TH1::Reset(option);
3213  TString opt = option;
3214  opt.ToUpper();
3215  if (opt.Contains("ICE") && !opt.Contains("S")) return;
3216  fTsumwy = 0;
3217  fTsumwy2 = 0;
3218  fTsumwxy = 0;
3219  fTsumwz = 0;
3220  fTsumwz2 = 0;
3221  fTsumwxz = 0;
3222  fTsumwyz = 0;
3223 }
3224 
3225 
3226 ////////////////////////////////////////////////////////////////////////////////
3227 /// Set bin content.
3228 
3230 {
3231  fEntries++;
3232  fTsumw = 0;
3233  if (bin < 0) return;
3234  if (bin >= fNcells) return;
3235  UpdateBinContent(bin, content);
3236 }
3237 
3238 
3239 ////////////////////////////////////////////////////////////////////////////////
3240 /// Stream an object of class TH3.
3241 
3242 void TH3::Streamer(TBuffer &R__b)
3243 {
3244  if (R__b.IsReading()) {
3245  UInt_t R__s, R__c;
3246  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
3247  if (R__v > 2) {
3248  R__b.ReadClassBuffer(TH3::Class(), this, R__v, R__s, R__c);
3249  return;
3250  }
3251  //====process old versions before automatic schema evolution
3252  TH1::Streamer(R__b);
3253  TAtt3D::Streamer(R__b);
3254  R__b.CheckByteCount(R__s, R__c, TH3::IsA());
3255  //====end of old versions
3256 
3257  } else {
3258  R__b.WriteClassBuffer(TH3::Class(),this);
3259  }
3260 }
3261 
3262 
3263 //______________________________________________________________________________
3264 // TH3C methods
3265 // TH3C a 3-D histogram with one byte per cell (char)
3266 //______________________________________________________________________________
3267 
3268 ClassImp(TH3C)
3269 
3270 
3271 ////////////////////////////////////////////////////////////////////////////////
3272 /// Constructor.
3273 
3275 {
3276  SetBinsLength(27);
3277  if (fgDefaultSumw2) Sumw2();
3278 }
3279 
3280 
3281 ////////////////////////////////////////////////////////////////////////////////
3282 /// Destructor.
3283 
3285 {
3286 }
3287 
3288 
3289 ////////////////////////////////////////////////////////////////////////////////
3290 /// Normal constructor for fix bin size 3-D histograms.
3291 
3292 TH3C::TH3C(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3293  ,Int_t nbinsy,Double_t ylow,Double_t yup
3294  ,Int_t nbinsz,Double_t zlow,Double_t zup)
3295  :TH3(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,zlow,zup)
3296 {
3298  if (fgDefaultSumw2) Sumw2();
3299 
3300  if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
3301 }
3302 
3303 
3304 ////////////////////////////////////////////////////////////////////////////////
3305 /// Normal constructor for variable bin size 3-D histograms.
3306 
3307 TH3C::TH3C(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
3308  ,Int_t nbinsy,const Float_t *ybins
3309  ,Int_t nbinsz,const Float_t *zbins)
3310  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3311 {
3313  if (fgDefaultSumw2) Sumw2();
3314 }
3315 
3316 
3317 ////////////////////////////////////////////////////////////////////////////////
3318 /// Normal constructor for variable bin size 3-D histograms.
3319 
3320 TH3C::TH3C(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
3321  ,Int_t nbinsy,const Double_t *ybins
3322  ,Int_t nbinsz,const Double_t *zbins)
3323  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3324 {
3326  if (fgDefaultSumw2) Sumw2();
3327 }
3328 
3329 
3330 ////////////////////////////////////////////////////////////////////////////////
3331 /// Copy constructor.
3332 
3333 TH3C::TH3C(const TH3C &h3c) : TH3(), TArrayC()
3334 {
3335  ((TH3C&)h3c).Copy(*this);
3336 }
3337 
3338 
3339 ////////////////////////////////////////////////////////////////////////////////
3340 /// Increment bin content by 1.
3341 
3343 {
3344  if (fArray[bin] < 127) fArray[bin]++;
3345 }
3346 
3347 
3348 ////////////////////////////////////////////////////////////////////////////////
3349 /// Increment bin content by w.
3350 
3352 {
3353  Int_t newval = fArray[bin] + Int_t(w);
3354  if (newval > -128 && newval < 128) {fArray[bin] = Char_t(newval); return;}
3355  if (newval < -127) fArray[bin] = -127;
3356  if (newval > 127) fArray[bin] = 127;
3357 }
3358 
3359 
3360 ////////////////////////////////////////////////////////////////////////////////
3361 /// Copy this 3-D histogram structure to newth3.
3362 
3363 void TH3C::Copy(TObject &newth3) const
3364 {
3365  TH3::Copy((TH3C&)newth3);
3366 }
3367 
3368 
3369 ////////////////////////////////////////////////////////////////////////////////
3370 /// Reset this histogram: contents, errors, etc.
3371 
3372 void TH3C::Reset(Option_t *option)
3373 {
3374  TH3::Reset(option);
3375  TArrayC::Reset();
3376  // should also reset statistics once statistics are implemented for TH3
3377 }
3378 
3379 
3380 ////////////////////////////////////////////////////////////////////////////////
3381 /// Set total number of bins including under/overflow
3382 /// Reallocate bin contents array
3383 
3385 {
3386  if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2)*(fZaxis.GetNbins()+2);
3387  fNcells = n;
3388  TArrayC::Set(n);
3389 }
3390 
3391 
3392 ////////////////////////////////////////////////////////////////////////////////
3393 /// When the mouse is moved in a pad containing a 3-d view of this histogram
3394 /// a second canvas shows a projection type given as option.
3395 /// To stop the generation of the projections, delete the canvas
3396 /// containing the projection.
3397 /// option may contain a combination of the characters x,y,z,e
3398 /// option = "x" return the x projection into a TH1D histogram
3399 /// option = "y" return the y projection into a TH1D histogram
3400 /// option = "z" return the z projection into a TH1D histogram
3401 /// option = "xy" return the x versus y projection into a TH2D histogram
3402 /// option = "yx" return the y versus x projection into a TH2D histogram
3403 /// option = "xz" return the x versus z projection into a TH2D histogram
3404 /// option = "zx" return the z versus x projection into a TH2D histogram
3405 /// option = "yz" return the y versus z projection into a TH2D histogram
3406 /// option = "zy" return the z versus y projection into a TH2D histogram
3407 /// option can also include the drawing option for the projection, eg to draw
3408 /// the xy projection using the draw option "box" do
3409 /// myhist.SetShowProjection("xy box");
3410 /// This function is typically called from the context menu.
3411 /// NB: the notation "a vs b" means "a" vertical and "b" horizontal
3412 
3413 void TH3::SetShowProjection(const char *option,Int_t nbins)
3414 {
3415  GetPainter();
3416 
3417  if (fPainter) fPainter->SetShowProjection(option,nbins);
3418 }
3419 
3420 
3421 ////////////////////////////////////////////////////////////////////////////////
3422 /// Stream an object of class TH3C.
3423 
3424 void TH3C::Streamer(TBuffer &R__b)
3425 {
3426  if (R__b.IsReading()) {
3427  UInt_t R__s, R__c;
3428  if (R__b.GetParent() && R__b.GetVersionOwner() < 22300) return;
3429  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
3430  if (R__v > 2) {
3431  R__b.ReadClassBuffer(TH3C::Class(), this, R__v, R__s, R__c);
3432  return;
3433  }
3434  //====process old versions before automatic schema evolution
3435  if (R__v < 2) {
3436  R__b.ReadVersion();
3437  TH1::Streamer(R__b);
3438  TArrayC::Streamer(R__b);
3439  R__b.ReadVersion(&R__s, &R__c);
3440  TAtt3D::Streamer(R__b);
3441  } else {
3442  TH3::Streamer(R__b);
3443  TArrayC::Streamer(R__b);
3444  R__b.CheckByteCount(R__s, R__c, TH3C::IsA());
3445  }
3446  //====end of old versions
3447 
3448  } else {
3449  R__b.WriteClassBuffer(TH3C::Class(),this);
3450  }
3451 }
3452 
3453 
3454 ////////////////////////////////////////////////////////////////////////////////
3455 /// Operator =
3456 
3458 {
3459  if (this != &h1) ((TH3C&)h1).Copy(*this);
3460  return *this;
3461 }
3462 
3463 
3464 ////////////////////////////////////////////////////////////////////////////////
3465 /// Operator *
3466 
3468 {
3469  TH3C hnew = h1;
3470  hnew.Scale(c1);
3471  hnew.SetDirectory(0);
3472  return hnew;
3473 }
3474 
3475 
3476 ////////////////////////////////////////////////////////////////////////////////
3477 /// Operator +
3478 
3480 {
3481  TH3C hnew = h1;
3482  hnew.Add(&h2,1);
3483  hnew.SetDirectory(0);
3484  return hnew;
3485 }
3486 
3487 
3488 ////////////////////////////////////////////////////////////////////////////////
3489 /// Operator -
3490 
3492 {
3493  TH3C hnew = h1;
3494  hnew.Add(&h2,-1);
3495  hnew.SetDirectory(0);
3496  return hnew;
3497 }
3498 
3499 
3500 ////////////////////////////////////////////////////////////////////////////////
3501 /// Operator *
3502 
3504 {
3505  TH3C hnew = h1;
3506  hnew.Multiply(&h2);
3507  hnew.SetDirectory(0);
3508  return hnew;
3509 }
3510 
3511 
3512 ////////////////////////////////////////////////////////////////////////////////
3513 /// Operator /
3514 
3516 {
3517  TH3C hnew = h1;
3518  hnew.Divide(&h2);
3519  hnew.SetDirectory(0);
3520  return hnew;
3521 }
3522 
3523 
3524 //______________________________________________________________________________
3525 // TH3S methods
3526 // TH3S a 3-D histogram with two bytes per cell (short integer)
3527 //______________________________________________________________________________
3528 
3529 ClassImp(TH3S)
3530 
3531 
3532 ////////////////////////////////////////////////////////////////////////////////
3533 /// Constructor.
3534 
3536 {
3537  SetBinsLength(27);
3538  if (fgDefaultSumw2) Sumw2();
3539 }
3540 
3541 
3542 ////////////////////////////////////////////////////////////////////////////////
3543 /// Destructor.
3544 
3546 {
3547 }
3548 
3549 
3550 ////////////////////////////////////////////////////////////////////////////////
3551 /// Normal constructor for fix bin size 3-D histograms.
3552 
3553 TH3S::TH3S(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3554  ,Int_t nbinsy,Double_t ylow,Double_t yup
3555  ,Int_t nbinsz,Double_t zlow,Double_t zup)
3556  :TH3(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,zlow,zup)
3557 {
3558  TH3S::Set(fNcells);
3559  if (fgDefaultSumw2) Sumw2();
3560 
3561  if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
3562 }
3563 
3564 
3565 ////////////////////////////////////////////////////////////////////////////////
3566 /// Normal constructor for variable bin size 3-D histograms.
3567 
3568 TH3S::TH3S(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
3569  ,Int_t nbinsy,const Float_t *ybins
3570  ,Int_t nbinsz,const Float_t *zbins)
3571  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3572 {
3573  TH3S::Set(fNcells);
3574  if (fgDefaultSumw2) Sumw2();
3575 }
3576 
3577 
3578 ////////////////////////////////////////////////////////////////////////////////
3579 /// Normal constructor for variable bin size 3-D histograms.
3580 
3581 TH3S::TH3S(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
3582  ,Int_t nbinsy,const Double_t *ybins
3583  ,Int_t nbinsz,const Double_t *zbins)
3584  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3585 {
3586  TH3S::Set(fNcells);
3587  if (fgDefaultSumw2) Sumw2();
3588 }
3589 
3590 
3591 ////////////////////////////////////////////////////////////////////////////////
3592 /// Copy Constructor.
3593 
3594 TH3S::TH3S(const TH3S &h3s) : TH3(), TArrayS()
3595 {
3596  ((TH3S&)h3s).Copy(*this);
3597 }
3598 
3599 
3600 ////////////////////////////////////////////////////////////////////////////////
3601 /// Increment bin content by 1.
3602 
3604 {
3605  if (fArray[bin] < 32767) fArray[bin]++;
3606 }
3607 
3608 
3609 ////////////////////////////////////////////////////////////////////////////////
3610 /// Increment bin content by w.
3611 
3613 {
3614  Int_t newval = fArray[bin] + Int_t(w);
3615  if (newval > -32768 && newval < 32768) {fArray[bin] = Short_t(newval); return;}
3616  if (newval < -32767) fArray[bin] = -32767;
3617  if (newval > 32767) fArray[bin] = 32767;
3618 }
3619 
3620 
3621 ////////////////////////////////////////////////////////////////////////////////
3622 /// Copy this 3-D histogram structure to newth3.
3623 
3624 void TH3S::Copy(TObject &newth3) const
3625 {
3626  TH3::Copy((TH3S&)newth3);
3627 }
3628 
3629 
3630 ////////////////////////////////////////////////////////////////////////////////
3631 /// Reset this histogram: contents, errors, etc.
3632 
3633 void TH3S::Reset(Option_t *option)
3634 {
3635  TH3::Reset(option);
3636  TArrayS::Reset();
3637  // should also reset statistics once statistics are implemented for TH3
3638 }
3639 
3640 
3641 ////////////////////////////////////////////////////////////////////////////////
3642 /// Set total number of bins including under/overflow
3643 /// Reallocate bin contents array
3644 
3646 {
3647  if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2)*(fZaxis.GetNbins()+2);
3648  fNcells = n;
3649  TArrayS::Set(n);
3650 }
3651 
3652 
3653 ////////////////////////////////////////////////////////////////////////////////
3654 /// Stream an object of class TH3S.
3655 
3656 void TH3S::Streamer(TBuffer &R__b)
3657 {
3658  if (R__b.IsReading()) {
3659  UInt_t R__s, R__c;
3660  if (R__b.GetParent() && R__b.GetVersionOwner() < 22300) return;
3661  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
3662  if (R__v > 2) {
3663  R__b.ReadClassBuffer(TH3S::Class(), this, R__v, R__s, R__c);
3664  return;
3665  }
3666  //====process old versions before automatic schema evolution
3667  if (R__v < 2) {
3668  R__b.ReadVersion();
3669  TH1::Streamer(R__b);
3670  TArrayS::Streamer(R__b);
3671  R__b.ReadVersion(&R__s, &R__c);
3672  TAtt3D::Streamer(R__b);
3673  } else {
3674  TH3::Streamer(R__b);
3675  TArrayS::Streamer(R__b);
3676  R__b.CheckByteCount(R__s, R__c, TH3S::IsA());
3677  }
3678  //====end of old versions
3679 
3680  } else {
3681  R__b.WriteClassBuffer(TH3S::Class(),this);
3682  }
3683 }
3684 
3685 
3686 ////////////////////////////////////////////////////////////////////////////////
3687 /// Operator =
3688 
3690 {
3691  if (this != &h1) ((TH3S&)h1).Copy(*this);
3692  return *this;
3693 }
3694 
3695 
3696 ////////////////////////////////////////////////////////////////////////////////
3697 /// Operator *
3698 
3700 {
3701  TH3S hnew = h1;
3702  hnew.Scale(c1);
3703  hnew.SetDirectory(0);
3704  return hnew;
3705 }
3706 
3707 
3708 ////////////////////////////////////////////////////////////////////////////////
3709 /// Operator +
3710 
3712 {
3713  TH3S hnew = h1;
3714  hnew.Add(&h2,1);
3715  hnew.SetDirectory(0);
3716  return hnew;
3717 }
3718 
3719 
3720 ////////////////////////////////////////////////////////////////////////////////
3721 /// Operator -
3722 
3724 {
3725  TH3S hnew = h1;
3726  hnew.Add(&h2,-1);
3727  hnew.SetDirectory(0);
3728  return hnew;
3729 }
3730 
3731 
3732 ////////////////////////////////////////////////////////////////////////////////
3733 /// Operator *
3734 
3736 {
3737  TH3S hnew = h1;
3738  hnew.Multiply(&h2);
3739  hnew.SetDirectory(0);
3740  return hnew;
3741 }
3742 
3743 
3744 ////////////////////////////////////////////////////////////////////////////////
3745 /// Operator /
3746 
3748 {
3749  TH3S hnew = h1;
3750  hnew.Divide(&h2);
3751  hnew.SetDirectory(0);
3752  return hnew;
3753 }
3754 
3755 
3756 //______________________________________________________________________________
3757 // TH3I methods
3758 // TH3I a 3-D histogram with four bytes per cell (32 bits integer)
3759 //______________________________________________________________________________
3760 
3761 ClassImp(TH3I)
3762 
3763 
3764 ////////////////////////////////////////////////////////////////////////////////
3765 /// Constructor.
3766 
3768 {
3769  SetBinsLength(27);
3770  if (fgDefaultSumw2) Sumw2();
3771 }
3772 
3773 
3774 ////////////////////////////////////////////////////////////////////////////////
3775 /// Destructor.
3776 
3778 {
3779 }
3780 
3781 
3782 ////////////////////////////////////////////////////////////////////////////////
3783 /// Normal constructor for fix bin size 3-D histograms.
3784 
3785 TH3I::TH3I(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3786  ,Int_t nbinsy,Double_t ylow,Double_t yup
3787  ,Int_t nbinsz,Double_t zlow,Double_t zup)
3788  :TH3(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,zlow,zup)
3789 {
3790  TH3I::Set(fNcells);
3791  if (fgDefaultSumw2) Sumw2();
3792 
3793  if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
3794 }
3795 
3796 
3797 ////////////////////////////////////////////////////////////////////////////////
3798 /// Normal constructor for variable bin size 3-D histograms.
3799 
3800 TH3I::TH3I(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
3801  ,Int_t nbinsy,const Float_t *ybins
3802  ,Int_t nbinsz,const Float_t *zbins)
3803  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3804 {
3806  if (fgDefaultSumw2) Sumw2();
3807 }
3808 
3809 
3810 ////////////////////////////////////////////////////////////////////////////////
3811 /// Normal constructor for variable bin size 3-D histograms.
3812 
3813 TH3I::TH3I(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
3814  ,Int_t nbinsy,const Double_t *ybins
3815  ,Int_t nbinsz,const Double_t *zbins)
3816  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3817 {
3819  if (fgDefaultSumw2) Sumw2();
3820 }
3821 
3822 
3823 ////////////////////////////////////////////////////////////////////////////////
3824 /// Copy constructor.
3825 
3826 TH3I::TH3I(const TH3I &h3i) : TH3(), TArrayI()
3827 {
3828  ((TH3I&)h3i).Copy(*this);
3829 }
3830 
3831 
3832 ////////////////////////////////////////////////////////////////////////////////
3833 /// Increment bin content by 1.
3834 
3836 {
3837  if (fArray[bin] < 2147483647) fArray[bin]++;
3838 }
3839 
3840 
3841 ////////////////////////////////////////////////////////////////////////////////
3842 /// Increment bin content by w.
3843 
3845 {
3846  Int_t newval = fArray[bin] + Int_t(w);
3847  if (newval > -2147483647 && newval < 2147483647) {fArray[bin] = Int_t(newval); return;}
3848  if (newval < -2147483647) fArray[bin] = -2147483647;
3849  if (newval > 2147483647) fArray[bin] = 2147483647;
3850 }
3851 
3852 
3853 ////////////////////////////////////////////////////////////////////////////////
3854 /// Copy this 3-D histogram structure to newth3.
3855 
3856 void TH3I::Copy(TObject &newth3) const
3857 {
3858  TH3::Copy((TH3I&)newth3);
3859 }
3860 
3861 
3862 ////////////////////////////////////////////////////////////////////////////////
3863 /// Reset this histogram: contents, errors, etc.
3864 
3865 void TH3I::Reset(Option_t *option)
3866 {
3867  TH3::Reset(option);
3868  TArrayI::Reset();
3869  // should also reset statistics once statistics are implemented for TH3
3870 }
3871 
3872 
3873 ////////////////////////////////////////////////////////////////////////////////
3874 /// Set total number of bins including under/overflow
3875 /// Reallocate bin contents array
3876 
3878 {
3879  if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2)*(fZaxis.GetNbins()+2);
3880  fNcells = n;
3881  TArrayI::Set(n);
3882 }
3883 
3884 
3885 ////////////////////////////////////////////////////////////////////////////////
3886 /// Operator =
3887 
3889 {
3890  if (this != &h1) ((TH3I&)h1).Copy(*this);
3891  return *this;
3892 }
3893 
3894 
3895 ////////////////////////////////////////////////////////////////////////////////
3896 /// Operator *
3897 
3899 {
3900  TH3I hnew = h1;
3901  hnew.Scale(c1);
3902  hnew.SetDirectory(0);
3903  return hnew;
3904 }
3905 
3906 
3907 ////////////////////////////////////////////////////////////////////////////////
3908 /// Operator +
3909 
3911 {
3912  TH3I hnew = h1;
3913  hnew.Add(&h2,1);
3914  hnew.SetDirectory(0);
3915  return hnew;
3916 }
3917 
3918 
3919 ////////////////////////////////////////////////////////////////////////////////
3920 /// Operator _
3921 
3923 {
3924  TH3I hnew = h1;
3925  hnew.Add(&h2,-1);
3926  hnew.SetDirectory(0);
3927  return hnew;
3928 }
3929 
3930 
3931 ////////////////////////////////////////////////////////////////////////////////
3932 /// Operator *
3933 
3935 {
3936  TH3I hnew = h1;
3937  hnew.Multiply(&h2);
3938  hnew.SetDirectory(0);
3939  return hnew;
3940 }
3941 
3942 
3943 ////////////////////////////////////////////////////////////////////////////////
3944 /// Operator /
3945 
3947 {
3948  TH3I hnew = h1;
3949  hnew.Divide(&h2);
3950  hnew.SetDirectory(0);
3951  return hnew;
3952 }
3953 
3954 
3955 //______________________________________________________________________________
3956 // TH3F methods
3957 // TH3F a 3-D histogram with four bytes per cell (float)
3958 //______________________________________________________________________________
3959 
3960 ClassImp(TH3F)
3961 
3962 
3963 ////////////////////////////////////////////////////////////////////////////////
3964 /// Constructor.
3965 
3967 {
3968  SetBinsLength(27);
3969  if (fgDefaultSumw2) Sumw2();
3970 }
3971 
3972 
3973 ////////////////////////////////////////////////////////////////////////////////
3974 /// Destructor.
3975 
3977 {
3978 }
3979 
3980 
3981 ////////////////////////////////////////////////////////////////////////////////
3982 /// Normal constructor for fix bin size 3-D histograms.
3983 
3984 TH3F::TH3F(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3985  ,Int_t nbinsy,Double_t ylow,Double_t yup
3986  ,Int_t nbinsz,Double_t zlow,Double_t zup)
3987  :TH3(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,zlow,zup)
3988 {
3990  if (fgDefaultSumw2) Sumw2();
3991 
3992  if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
3993 }
3994 
3995 
3996 ////////////////////////////////////////////////////////////////////////////////
3997 /// Normal constructor for variable bin size 3-D histograms.
3998 
3999 TH3F::TH3F(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
4000  ,Int_t nbinsy,const Float_t *ybins
4001  ,Int_t nbinsz,const Float_t *zbins)
4002  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
4003 {
4005  if (fgDefaultSumw2) Sumw2();
4006 }
4007 
4008 
4009 ////////////////////////////////////////////////////////////////////////////////
4010 /// Normal constructor for variable bin size 3-D histograms.
4011 
4012 TH3F::TH3F(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
4013  ,Int_t nbinsy,const Double_t *ybins
4014  ,Int_t nbinsz,const Double_t *zbins)
4015  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
4016 {
4018  if (fgDefaultSumw2) Sumw2();
4019 }
4020 
4021 
4022 ////////////////////////////////////////////////////////////////////////////////
4023 /// Copy constructor.
4024 
4025 TH3F::TH3F(const TH3F &h3f) : TH3(), TArrayF()
4026 {
4027  ((TH3F&)h3f).Copy(*this);
4028 }
4029 
4030 
4031 ////////////////////////////////////////////////////////////////////////////////
4032 /// Copy this 3-D histogram structure to newth3.
4033 
4034 void TH3F::Copy(TObject &newth3) const
4035 {
4036  TH3::Copy((TH3F&)newth3);
4037 }
4038 
4039 
4040 ////////////////////////////////////////////////////////////////////////////////
4041 /// Reset this histogram: contents, errors, etc.
4042 
4043 void TH3F::Reset(Option_t *option)
4044 {
4045  TH3::Reset(option);
4046  TArrayF::Reset();
4047  // should also reset statistics once statistics are implemented for TH3
4048 }
4049 
4050 
4051 ////////////////////////////////////////////////////////////////////////////////
4052 /// Set total number of bins including under/overflow
4053 /// Reallocate bin contents array
4054 
4056 {
4057  if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2)*(fZaxis.GetNbins()+2);
4058  fNcells = n;
4059  TArrayF::Set(n);
4060 }
4061 
4062 
4063 ////////////////////////////////////////////////////////////////////////////////
4064 /// Stream an object of class TH3F.
4065 
4066 void TH3F::Streamer(TBuffer &R__b)
4067 {
4068  if (R__b.IsReading()) {
4069  UInt_t R__s, R__c;
4070  if (R__b.GetParent() && R__b.GetVersionOwner() < 22300) return;
4071  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
4072  if (R__v > 2) {
4073  R__b.ReadClassBuffer(TH3F::Class(), this, R__v, R__s, R__c);
4074  return;
4075  }
4076  //====process old versions before automatic schema evolution
4077  if (R__v < 2) {
4078  R__b.ReadVersion();
4079  TH1::Streamer(R__b);
4080  TArrayF::Streamer(R__b);
4081  R__b.ReadVersion(&R__s, &R__c);
4082  TAtt3D::Streamer(R__b);
4083  } else {
4084  TH3::Streamer(R__b);
4085  TArrayF::Streamer(R__b);
4086  R__b.CheckByteCount(R__s, R__c, TH3F::IsA());
4087  }
4088  //====end of old versions
4089 
4090  } else {
4091  R__b.WriteClassBuffer(TH3F::Class(),this);
4092  }
4093 }
4094 
4095 
4096 ////////////////////////////////////////////////////////////////////////////////
4097 /// Operator =
4098 
4100 {
4101  if (this != &h1) ((TH3F&)h1).Copy(*this);
4102  return *this;
4103 }
4104 
4105 
4106 ////////////////////////////////////////////////////////////////////////////////
4107 /// Operator *
4108 
4110 {
4111  TH3F hnew = h1;
4112  hnew.Scale(c1);
4113  hnew.SetDirectory(0);
4114  return hnew;
4115 }
4116 
4117 
4118 ////////////////////////////////////////////////////////////////////////////////
4119 /// Operator +
4120 
4122 {
4123  TH3F hnew = h1;
4124  hnew.Add(&h2,1);
4125  hnew.SetDirectory(0);
4126  return hnew;
4127 }
4128 
4129 
4130 ////////////////////////////////////////////////////////////////////////////////
4131 /// Operator -
4132 
4134 {
4135  TH3F hnew = h1;
4136  hnew.Add(&h2,-1);
4137  hnew.SetDirectory(0);
4138  return hnew;
4139 }
4140 
4141 
4142 ////////////////////////////////////////////////////////////////////////////////
4143 /// Operator *
4144 
4146 {
4147  TH3F hnew = h1;
4148  hnew.Multiply(&h2);
4149  hnew.SetDirectory(0);
4150  return hnew;
4151 }
4152 
4153 
4154 ////////////////////////////////////////////////////////////////////////////////
4155 /// Operator /
4156 
4158 {
4159  TH3F hnew = h1;
4160  hnew.Divide(&h2);
4161  hnew.SetDirectory(0);
4162  return hnew;
4163 }
4164 
4165 
4166 //______________________________________________________________________________
4167 // TH3D methods
4168 // TH3D a 3-D histogram with eight bytes per cell (double)
4169 //______________________________________________________________________________
4170 
4171 ClassImp(TH3D)
4172 
4173 
4174 ////////////////////////////////////////////////////////////////////////////////
4175 /// Constructor.
4176 
4178 {
4179  SetBinsLength(27);
4180  if (fgDefaultSumw2) Sumw2();
4181 }
4182 
4183 
4184 ////////////////////////////////////////////////////////////////////////////////
4185 /// Destructor.
4186 
4188 {
4189 }
4190 
4191 
4192 ////////////////////////////////////////////////////////////////////////////////
4193 /// Normal constructor for fix bin size 3-D histograms.
4194 
4195 TH3D::TH3D(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
4196  ,Int_t nbinsy,Double_t ylow,Double_t yup
4197  ,Int_t nbinsz,Double_t zlow,Double_t zup)
4198  :TH3(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,zlow,zup)
4199 {
4201  if (fgDefaultSumw2) Sumw2();
4202 
4203  if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
4204 }
4205 
4206 
4207 ////////////////////////////////////////////////////////////////////////////////
4208 /// Normal constructor for variable bin size 3-D histograms.
4209 
4210 TH3D::TH3D(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
4211  ,Int_t nbinsy,const Float_t *ybins
4212  ,Int_t nbinsz,const Float_t *zbins)
4213  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
4214 {
4216  if (fgDefaultSumw2) Sumw2();
4217 }
4218 
4219 
4220 ////////////////////////////////////////////////////////////////////////////////
4221 /// Normal constructor for variable bin size 3-D histograms.
4222 
4223 TH3D::TH3D(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
4224  ,Int_t nbinsy,const Double_t *ybins
4225  ,Int_t nbinsz,const Double_t *zbins)
4226  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
4227 {
4229  if (fgDefaultSumw2) Sumw2();
4230 }
4231 
4232 
4233 ////////////////////////////////////////////////////////////////////////////////
4234 /// Copy constructor.
4235 
4236 TH3D::TH3D(const TH3D &h3d) : TH3(), TArrayD()
4237 {
4238  ((TH3D&)h3d).Copy(*this);
4239 }
4240 
4241 
4242 ////////////////////////////////////////////////////////////////////////////////
4243 /// Copy this 3-D histogram structure to newth3.
4244 
4245 void TH3D::Copy(TObject &newth3) const
4246 {
4247  TH3::Copy((TH3D&)newth3);
4248 }
4249 
4250 
4251 ////////////////////////////////////////////////////////////////////////////////
4252 /// Reset this histogram: contents, errors, etc.
4253 
4254 void TH3D::Reset(Option_t *option)
4255 {
4256  TH3::Reset(option);
4257  TArrayD::Reset();
4258  // should also reset statistics once statistics are implemented for TH3
4259 }
4260 
4261 
4262 ////////////////////////////////////////////////////////////////////////////////
4263 /// Set total number of bins including under/overflow
4264 /// Reallocate bin contents array
4265 
4267 {
4268  if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2)*(fZaxis.GetNbins()+2);
4269  fNcells = n;
4270  TArrayD::Set(n);
4271 }
4272 
4273 
4274 ////////////////////////////////////////////////////////////////////////////////
4275 /// Stream an object of class TH3D.
4276 
4277 void TH3D::Streamer(TBuffer &R__b)
4278 {
4279  if (R__b.IsReading()) {
4280  UInt_t R__s, R__c;
4281  if (R__b.GetParent() && R__b.GetVersionOwner() < 22300) return;
4282  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
4283  if (R__v > 2) {
4284  R__b.ReadClassBuffer(TH3D::Class(), this, R__v, R__s, R__c);
4285  return;
4286  }
4287  //====process old versions before automatic schema evolution
4288  if (R__v < 2) {
4289  R__b.ReadVersion();
4290  TH1::Streamer(R__b);
4291  TArrayD::Streamer(R__b);
4292  R__b.ReadVersion(&R__s, &R__c);
4293  TAtt3D::Streamer(R__b);
4294  } else {
4295  TH3::Streamer(R__b);
4296  TArrayD::Streamer(R__b);
4297  R__b.CheckByteCount(R__s, R__c, TH3D::IsA());
4298  }
4299  //====end of old versions
4300 
4301  } else {
4302  R__b.WriteClassBuffer(TH3D::Class(),this);
4303  }
4304 }
4305 
4306 
4307 ////////////////////////////////////////////////////////////////////////////////
4308 /// Operator =
4309 
4311 {
4312  if (this != &h1) ((TH3D&)h1).Copy(*this);
4313  return *this;
4314 }
4315 
4316 
4317 ////////////////////////////////////////////////////////////////////////////////
4318 /// Operator *
4319 
4321 {
4322  TH3D hnew = h1;
4323  hnew.Scale(c1);
4324  hnew.SetDirectory(0);
4325  return hnew;
4326 }
4327 
4328 
4329 ////////////////////////////////////////////////////////////////////////////////
4330 /// Operator +
4331 
4333 {
4334  TH3D hnew = h1;
4335  hnew.Add(&h2,1);
4336  hnew.SetDirectory(0);
4337  return hnew;
4338 }
4339 
4340 
4341 ////////////////////////////////////////////////////////////////////////////////
4342 /// Operator -
4343 
4345 {
4346  TH3D hnew = h1;
4347  hnew.Add(&h2,-1);
4348  hnew.SetDirectory(0);
4349  return hnew;
4350 }
4351 
4352 
4353 ////////////////////////////////////////////////////////////////////////////////
4354 /// Operator *
4355 
4357 {
4358  TH3D hnew = h1;
4359  hnew.Multiply(&h2);
4360  hnew.SetDirectory(0);
4361  return hnew;
4362 }
4363 
4364 
4365 ////////////////////////////////////////////////////////////////////////////////
4366 /// Operator /
4367 
4369 {
4370  TH3D hnew = h1;
4371  hnew.Divide(&h2);
4372  hnew.SetDirectory(0);
4373  return hnew;
4374 }
const int nx
Definition: kalman.C:16
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:262
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
Bool_t IsReading() const
Definition: TBuffer.h:83
virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
Return Global bin number corresponding to x,y,z.
Definition: TH1.cxx:3440
virtual Float_t GetTickLength() const
Definition: TAttAxis.h:49
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
Definition: TH1.cxx:5936
virtual Double_t GetEffectiveEntries() const
Number of effective entries of the histogram.
Definition: TH1.cxx:4078
virtual void Paint(Option_t *option="")
Control routine to paint any kind of histograms.
Definition: TH1.cxx:5538
TH3()
Default constructor.
Definition: TH3.cxx:63
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:439
float xmin
Definition: THbookFile.cxx:93
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
friend TH3D operator*(Float_t c1, TH3D &h1)
Operator *.
Definition: TH3.cxx:4320
Double_t Floor(Double_t x)
Definition: TMath.h:473
void Set(Int_t n)
Set size of this array to n chars.
Definition: TArrayC.cxx:105
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition: TAxis.cxx:444
virtual void Copy(TObject &hnew) const
Copy this 3-D histogram structure to newth3.
Definition: TH3.cxx:4034
virtual void SetBinsLength(Int_t n=-1)
Set total number of bins including under/overflow Reallocate bin contents array.
Definition: TH3.cxx:3645
void Copy(TArrayI &array) const
Definition: TArrayI.h:44
virtual void Copy(TObject &hnew) const
Copy this 3-D histogram structure to newth3.
Definition: TH3.cxx:3624
short Style_t
Definition: RtypesCore.h:76
virtual TH1 * Project3D(Option_t *option="x") const
Project a 3-d histogram into 1 or 2-d histograms depending on the option parameter option may contain...
Definition: TH3.cxx:2202
virtual TH3 * RebinX(Int_t ngroup=2, const char *newname="")
Rebin only the X axis see Rebin3D.
Definition: TH3.cxx:2667
Double_t Log(Double_t x)
Definition: TMath.h:526
virtual void Sumw2(Bool_t flag=kTRUE)
Create/Delete structure to store sum of squares of weights per bin This is needed to compute the corr...
short Version_t
Definition: RtypesCore.h:61
virtual void PutStats(Double_t *stats)
Replace current statistics with the values in array stats.
Definition: TH2.cxx:2341
friend TH3F operator+(TH3F &h1, TH3F &h2)
Operator +.
Definition: TH3.cxx:4121
static Bool_t fgDefaultSumw2
!flag to call TH1::Sumw2 automatically at histogram creation time
Definition: TH1.h:131
TVirtualHistPainter * GetPainter(Option_t *option="")
Return pointer to painter.
Definition: TH1.cxx:4099
Collectable string class.
Definition: TObjString.h:32
float Float_t
Definition: RtypesCore.h:53
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH3.cxx:658
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
Definition: TH1.cxx:8051
friend TH3F operator/(TH3F &h1, TH3F &h2)
Operator /.
Definition: TH3.cxx:4157
virtual Float_t GetLabelOffset() const
Definition: TAttAxis.h:45
tomato 3-D histogram with a float per channel (see TH1 documentation)}
Definition: TH3.h:271
virtual TProfile2D * DoProjectProfile2D(const char *name, const char *title, const TAxis *projX, const TAxis *projY, bool originalRange, bool useUF, bool useOF) const
internal method to project to a 2D Profile called from TH3::Project3DProfile
Definition: TH3.cxx:2360
Short_t * fArray
Definition: TArrayS.h:32
return c
const char Option_t
Definition: RtypesCore.h:62
friend TH3I operator+(TH3I &h1, TH3I &h2)
Operator +.
Definition: TH3.cxx:3910
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition: TAxis.cxx:504
Double_t KolmogorovProb(Double_t z)
Calculates the Kolmogorov distribution function,.
Definition: TMath.cxx:665
return c1
Definition: legend1.C:41
void Reset()
Definition: TArrayD.h:49
float ymin
Definition: THbookFile.cxx:93
TObject * GetParent() const
Return pointer to parent of this buffer.
Definition: TBuffer.cxx:231
Double_t QuietNaN()
Definition: TMath.h:622
TAxis fYaxis
Y axis descriptor.
Definition: TH1.h:105
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content.
Definition: TH3.cxx:3229
virtual void PutStats(Double_t *stats)
Replace current statistics with the values in array stats.
Definition: TH1.cxx:7070
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:157
virtual void SetBins(Int_t nx, Double_t xmin, Double_t xmax)
Redefine x axis parameters.
Definition: TH1.cxx:7881
virtual TH3 * Rebin3D(Int_t nxgroup=2, Int_t nygroup=2, Int_t nzgroup=2, const char *newname="")
Rebin this histogram grouping nxgroup/nygroup/nzgroup bins along the xaxis/yaxis/zaxis together...
Definition: TH3.cxx:2718
virtual Color_t GetAxisColor() const
Definition: TAttAxis.h:42
TH1 * h
Definition: legend2.C:5
static Bool_t fgStatOverflows
!flag to use under/overflows in statistics
Definition: TH1.h:130
virtual void SetLabelColor(Color_t color=1, Float_t alpha=1.)
Set color of labels.
Definition: TAttAxis.cxx:173
virtual TH1D * ProjectionZ(const char *name="_pz", Int_t ixmin=0, Int_t ixmax=-1, Int_t iymin=0, Int_t iymax=-1, Option_t *option="") const
Project a 3-D histogram into a 1-D histogram along Z.
Definition: TH3.cxx:1634
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4638
TH3F()
Constructor.
Definition: TH3.cxx:3966
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition: TAttAxis.cxx:229
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Definition: TF1.cxx:3240
virtual Int_t GetBin(Int_t binx, Int_t biny, Int_t binz) const
See comments in TH1::GetBin.
Definition: TH3.cxx:950
Use this attribute class when an object should have 3D capabilities.
Definition: TAtt3D.h:21
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1102
TH3S & operator=(const TH3S &h1)
Operator =.
Definition: TH3.cxx:3689
virtual Int_t FindLastBinAbove(Double_t threshold=0, Int_t axis=1) const
Find last bin with content > threshold for axis (1=x, 2=y, 3=z) if no bins with content > threshold i...
Definition: TH3.cxx:793
friend TH3D operator-(TH3D &h1, TH3D &h2)
Operator -.
Definition: TH3.cxx:4344
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
friend TH3C operator+(TH3C &h1, TH3C &h2)
Operator +.
Definition: TH3.cxx:3479
virtual Int_t GetNbinsZ() const
Definition: TH1.h:303
#define R__ASSERT(e)
Definition: TError.h:98
static THLimitsFinder * GetLimitsFinder()
Return pointer to the current finder.
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
#define gROOT
Definition: TROOT.h:364
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
virtual ~TH3D()
Destructor.
Definition: TH3.cxx:4187
Double_t fTsumwy
Definition: TH3.h:38
Basic string class.
Definition: TString.h:137
Array of floats (32 bits per element).
Definition: TArrayF.h:29
virtual void SetTitleFont(Style_t font=62)
Set the title font.
Definition: TAttAxis.cxx:290
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1089
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
friend TH3F operator*(Float_t c1, TH3F &h1)
Operator *.
Definition: TH3.cxx:4109
Double_t fTsumwz
Definition: TH3.h:41
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
Definition: TF1.cxx:1642
int nbins[3]
TArrayD fSumw2
Array of sum of squares of weights.
Definition: TH1.h:118
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH3.h:95
friend TH3I operator/(TH3I &h1, TH3I &h2)
Operator /.
Definition: TH3.cxx:3946
void Copy(TArrayC &array) const
Definition: TArrayC.h:44
virtual Float_t GetLabelSize() const
Definition: TAttAxis.h:46
void Reset()
Definition: TArrayF.h:49
const char * Class
Definition: TXMLSetup.cxx:64
virtual TProfile2D * Project3DProfile(Option_t *option="xy") const
Project a 3-d histogram into a 2-d profile histograms depending on the option parameter option may co...
Definition: TH3.cxx:2567
virtual Int_t FindGoodLimits(TH1 *h, Double_t xmin, Double_t xmax)
compute the best axis limits for the X axis.
virtual Int_t FindFirstBinAbove(Double_t threshold=0, Int_t axis=1) const
Find first bin with content > threshold for axis (1=x, 2=y, 3=z) if no bins with content > threshold ...
Definition: TH3.cxx:750
TAxis fZaxis
Z axis descriptor.
Definition: TH1.h:106
virtual Bool_t Multiply(TF1 *h1, Double_t c1=1)
Performs the operation: this = this*c1*f1 if errors are defined (see TH1::Sumw2), errors are also rec...
Definition: TH1.cxx:5363
Double_t fTsumwyz
Definition: TH3.h:44
friend TH3F operator-(TH3F &h1, TH3F &h2)
Operator -.
Definition: TH3.cxx:4133
virtual Double_t GetCovariance(Int_t axis1=1, Int_t axis2=2) const
Return covariance between axis1 and axis2.
Definition: TH3.cxx:1042
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels The distance is expressed in per cent of the pad width...
Definition: TAttAxis.cxx:193
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
virtual Int_t BufferFill(Double_t x, Double_t y, Double_t z, Double_t w)
accumulate arguments in buffer.
Definition: TH3.cxx:251
Double_t Prob(Double_t chi2, Int_t ndf)
Computation of the probability for a certain Chi-squared (chi2) and number of degrees of freedom (ndf...
Definition: TMath.cxx:624
Array of integers (32 bits per element).
Definition: TArrayI.h:29
void Reset(Char_t val=0)
Definition: TArrayC.h:49
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:739
virtual void SetBuffer(Int_t buffersize, Option_t *option="")
Set the maximum number of entries to be kept in the buffer.
Definition: TH1.cxx:7580
Double_t fTsumwx2
Total Sum of weight*X*X.
Definition: TH1.h:113
virtual Bool_t CanExtendAllAxes() const
Returns true if all axes are extendable.
Definition: TH1.cxx:5960
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
Definition: TH1.cxx:6418
Histogram is forced to be not weighted even when the histogram is filled with weighted different than...
Definition: TH1.h:179
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition: TAxis.cxx:514
virtual Double_t Integral(Option_t *option="") const
Return integral of bin contents.
Definition: TH3.cxx:1213
virtual void SetLabelFont(Style_t font=62)
Set labels&#39; font.
Definition: TAttAxis.cxx:183
TH3D()
Constructor.
Definition: TH3.cxx:4177
virtual Style_t GetMarkerStyle() const
Return the marker style.
Definition: TAttMarker.h:37
virtual Style_t GetTitleFont() const
Definition: TAttAxis.h:51
virtual Int_t GetDimension() const
Definition: TH1.h:287
Int_t Fill(const Double_t *v)
Definition: TProfile2D.h:54
virtual TH2D * DoProject2D(const char *name, const char *title, const TAxis *projX, const TAxis *projY, bool computeErrors, bool originalRange, bool useUF, bool useOF) const
internal method performing the projection to a 2D histogram called from TH3::Project3D ...
Definition: TH3.cxx:1899
Double_t GetXmin() const
Definition: TAxis.h:139
TH3S()
Constructor.
Definition: TH3.cxx:3535
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:188
Double_t x[n]
Definition: legend1.C:17
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2335
Double_t fTsumwxz
Definition: TH3.h:43
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
virtual Double_t KolmogorovTest(const TH1 *h2, Option_t *option="") const
Statistical test of compatibility in shape between THIS histogram and h2, using Kolmogorov test...
Definition: TH3.cxx:1356
friend TH3D operator+(TH3D &h1, TH3D &h2)
Operator +.
Definition: TH3.cxx:4332
virtual Int_t GetVersionOwner() const =0
virtual TH1D * ProjectionY(const char *name="_py", Int_t ixmin=0, Int_t ixmax=-1, Int_t izmin=0, Int_t izmax=-1, Option_t *option="") const
Project a 3-D histogram into a 1-D histogram along Y.
Definition: TH3.cxx:1603
const int ny
Definition: kalman.C:17
virtual TH3 * RebinY(Int_t ngroup=2, const char *newname="")
Rebin only the Y axis see Rebin3D.
Definition: TH3.cxx:2677
virtual Double_t GetCorrelationFactor(Int_t axis1=1, Int_t axis2=2) const
Return correlation factor between axis1 and axis2.
Definition: TH3.cxx:1024
friend TH3C operator*(Float_t c1, TH3C &h1)
Operator *.
Definition: TH3.cxx:3467
virtual void AddBinContent(Int_t bin)
Increment bin content by 1.
Definition: TH3.cxx:3342
THashList * GetLabels() const
Definition: TAxis.h:123
static double p2(double t, double a, double b, double c)
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:464
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:43
Double_t * fArray
Definition: TArrayD.h:32
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:467
virtual void AddBinContent(Int_t bin)
Increment bin content by 1.
Definition: TH3.cxx:3835
TH1F * h1
Definition: legend1.C:5
virtual void AddBinContent(Int_t bin)
Increment bin content by 1.
Definition: TH1.cxx:1193
virtual void ResetStats()
Reset the statistics including the number of entries and replace with values calculates from bin cont...
Definition: TH1.cxx:7085
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
void Set(Int_t n)
Set size of this array to n ints.
Definition: TArrayI.cxx:105
virtual void Reset(Option_t *option="")
Reset.
Definition: TH1.cxx:9386
virtual void SetBinError(Int_t bin, Double_t error)
See convention for numbering bins in TH1::GetBin.
Definition: TH1.cxx:8309
virtual Double_t ComputeIntegral(Bool_t onlyPositive=false)
Compute integral (cumulative sum of bins) The result stored in fIntegral is used by the GetRandom fun...
Definition: TH1.cxx:2355
virtual Color_t GetLabelColor() const
Definition: TAttAxis.h:43
virtual void GetStats(Double_t *stats) const
Fill the array stats from the contents of this histogram The array stats must be correctly dimensionn...
Definition: TH3.cxx:1136
The 3-D histogram classes derived from the 1-D histogram classes.
Definition: TH3.h:35
short Color_t
Definition: RtypesCore.h:79
Double_t fTsumwx
Total Sum of weight*X.
Definition: TH1.h:112
virtual void SetBinsLength(Int_t n=-1)
Set total number of bins including under/overflow Reallocate bin contents array.
Definition: TH3.cxx:3877
tomato 3-D histogram with an int per channel (see TH1 documentation)}
Definition: TH3.h:234
virtual Bool_t Divide(TF1 *f1, Double_t c1=1)
Performs the operation: this = this/(c1*f1) if errors are defined (see TH1::Sumw2), errors are also recalculated.
Definition: TH1.cxx:2606
virtual Int_t GetNdivisions() const
Definition: TAttAxis.h:41
virtual ~TH3I()
Destructor.
Definition: TH3.cxx:3777
virtual ~TH3S()
Destructor.
Definition: TH3.cxx:3545
void Set(Int_t n)
Set size of this array to n shorts.
Definition: TArrayS.cxx:105
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:512
virtual void ImportAttributes(const TAxis *axis)
Copy axis attributes to this.
Definition: TAxis.cxx:616
virtual const char * GetParName(Int_t ipar) const
Definition: TF1.h:370
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
Return integral of bin contents in range [binx1,binx2],[biny1,biny2],[binz1,binz2] for a 3-D histogra...
Definition: TH3.cxx:1244
virtual void ExtendAxis(Double_t x, TAxis *axis)
Histogram is resized along axis such that x is in the axis range.
Definition: TH1.cxx:5838
void Reset()
Definition: TArrayS.h:49
tomato 3-D histogram with a short per channel (see TH1 documentation)
Definition: TH3.h:198
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:46
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
Definition: TH3.cxx:3372
Int_t fN
Definition: TArray.h:40
TH3C & operator=(const TH3C &h1)
Operator =.
Definition: TH3.cxx:3457
float ymax
Definition: THbookFile.cxx:93
friend TH3S operator-(TH3S &h1, TH3S &h2)
Operator -.
Definition: TH3.cxx:3723
void Copy(TArrayF &array) const
Definition: TArrayF.h:44
TH3C()
Constructor.
Definition: TH3.cxx:3274
Int_t GetLast() const
Return last bin on the axis i.e.
Definition: TAxis.cxx:455
const char * GetTitle() const
Returns title of object.
Definition: TAxis.h:135
Class to manage histogram axis.
Definition: TAxis.h:36
friend TH3S operator+(TH3S &h1, TH3S &h2)
Operator +.
Definition: TH3.cxx:3711
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2851
tomato 3-D histogram with a double per channel (see TH1 documentation)}
Definition: TH3.h:308
Array of shorts (16 bits per element).
Definition: TArrayS.h:29
Int_t GetSize() const
Definition: TArray.h:49
SVector< double, 2 > v
Definition: Dict.h:5
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:42
virtual Int_t GetNumberFitPoints() const
Definition: TF1.h:356
virtual void FitSlicesZ(TF1 *f1=0, Int_t binminx=1, Int_t binmaxx=0, Int_t binminy=1, Int_t binmaxy=0, Int_t cut=0, Option_t *option="QNR")
Project slices along Z in case of a 3-D histogram, then fit each slice with function f1 and make a 2-...
Definition: TH3.cxx:864
unsigned int r1[N_CITIES]
Definition: simanTSP.cxx:321
Double_t fTsumwy2
Definition: TH3.h:39
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:488
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Definition: TH1.cxx:8323
Bool_t Permute(Int_t n, Int_t *a)
Simple recursive algorithm to find the permutations of n natural numbers, not necessarily all distinc...
Definition: TMath.cxx:2501
static Int_t fgBufferSize
!default buffer size for automatic histograms
Definition: TH1.h:128
Double_t Mean(Long64_t n, const T *a, const Double_t *w=0)
Definition: TMath.h:811
virtual void PutStats(Double_t *stats)
Replace current statistics with the values in array stats.
Double_t fEntries
Number of entries.
Definition: TH1.h:109
virtual TH1D * DoProject1D(const char *name, const char *title, int imin1, int imax1, int imin2, int imax2, const TAxis *projAxis, const TAxis *axis1, const TAxis *axis2, Option_t *option) const
internal methdod performing the projection to 1D histogram called from TH3::Project3D ...
Definition: TH3.cxx:1650
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual Float_t GetTitleOffset() const
Definition: TAttAxis.h:47
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
virtual void Copy(TObject &hnew) const
Copy this histogram structure to newth1.
Definition: TH1.cxx:2468
virtual void PutStats(Double_t *stats)
Replace current statistics with the values in array stats.
Definition: TH3.cxx:2650
short Short_t
Definition: RtypesCore.h:35
virtual void SetShowProjection(const char *option="xy", Int_t nbins=1)
When the mouse is moved in a pad containing a 3-d view of this histogram a second canvas shows a proj...
Definition: TH3.cxx:3413
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition: TAttMarker.h:45
TAxis * GetYaxis()
Definition: TH1.h:325
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH3.cxx:280
float xmax
Definition: THbookFile.cxx:93
virtual void Copy(TObject &hnew) const
Copy.
Definition: TH3.cxx:156
virtual Color_t GetTitleColor() const
Definition: TAttAxis.h:50
Double_t * fIntegral
!Integral of bins used by GetRandom
Definition: TH1.h:125
virtual TH1D * ProjectionX(const char *name="_px", Int_t iymin=0, Int_t iymax=-1, Int_t izmin=0, Int_t izmax=-1, Option_t *option="") const
Project a 3-D histogram into a 1-D histogram along X.
Definition: TH3.cxx:1571
R__EXTERN TRandom * gRandom
Definition: TRandom.h:66
tomato 1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:618
friend TH3I operator-(TH3I &h1, TH3I &h2)
Operator _.
Definition: TH3.cxx:3922
virtual Int_t GetBin(Int_t binx, Int_t biny=0, Int_t binz=0) const
Return Global bin number corresponding to binx,y,z.
Definition: TH1.cxx:4540
virtual void SetAxisColor(Color_t color=1, Float_t alpha=1.)
Set color of the line axis and tick marks.
Definition: TAttAxis.cxx:163
TString & String()
Definition: TObjString.h:52
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels The size is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:204
virtual void SetTitleColor(Color_t color=1)
Set color of axis title.
Definition: TAttAxis.cxx:281
virtual void SetTitleSize(Float_t size=0.04)
Set size of axis title The size is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:272
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
Definition: TH3.cxx:3210
virtual Double_t RetrieveBinContent(Int_t bin) const
Raw retrieval of bin content on internal data structure see convention for numbering bins in TH1::Get...
Definition: TH1.cxx:8541
virtual Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:39
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:279
virtual void SetName(const char *name)
Change the name of this histogram.
Definition: TH1.cxx:8071
friend TH3S operator/(TH3S &h1, TH3S &h2)
Operator /.
Definition: TH3.cxx:3747
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Int_t GetSumw2N() const
Definition: TH1.h:319
Double_t GetChisquare() const
Definition: TF1.h:336
Double_t fTsumw2
Total Sum of squares of weights.
Definition: TH1.h:111
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Evaluate this function.
Definition: TF1.cxx:1196
Double_t fTsumwz2
Definition: TH3.h:42
#define ClassImp(name)
Definition: Rtypes.h:279
virtual void Copy(TObject &hnew) const
Copy this 3-D histogram structure to newth3.
Definition: TH3.cxx:3363
virtual void Reset(Option_t *option="")
-*Reset contents of a Profile2D histogram *-* ======================================= ...
friend TH3D operator/(TH3D &h1, TH3D &h2)
Operator /.
Definition: TH3.cxx:4368
double Double_t
Definition: RtypesCore.h:55
virtual Int_t BufferEmpty(Int_t action=0)
Fill histogram with all entries in the buffer.
Definition: TH3.cxx:177
Int_t * fArray
Definition: TArrayI.h:32
TH3D & operator=(const TH3D &h1)
Operator =.
Definition: TH3.cxx:4310
Double_t fTsumw
Total Sum of weights.
Definition: TH1.h:110
virtual void SetBinsLength(Int_t n=-1)
Set total number of bins including under/overflow Reallocate bin contents array.
Definition: TH3.cxx:4266
virtual void AddBinContent(Int_t bin)
Increment bin content by 1.
Definition: TH3.cxx:3603
virtual void SetShowProjection(const char *option, Int_t nbins)=0
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
internal function to fill the bins of the projected profile 2D histogram called from DoProjectProfile...
Definition: TH3.cxx:2334
friend TH3C operator-(TH3C &h1, TH3C &h2)
Operator -.
Definition: TH3.cxx:3491
Double_t y[n]
Definition: legend1.C:17
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:35
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
The TH1 histogram class.
Definition: TH1.h:80
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
tomato 3-D histogram with a byte per channel (see TH1 documentation)
Definition: TH3.h:162
THist< 2, double, THistStatContent, THistStatUncertainty > TH2D
Definition: THist.hxx:307
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition: TAxis.cxx:808
virtual Float_t GetTitleSize() const
Definition: TAttAxis.h:48
Profile2D histograms are used to display the mean value of Z and its RMS for each cell in X...
Definition: TProfile2D.h:31
Array of doubles (64 bits per element).
Definition: TArrayD.h:29
friend TH3I operator*(Float_t c1, TH3I &h1)
Operator *.
Definition: TH3.cxx:3898
virtual void Copy(TObject &hnew) const
Copy this 3-D histogram structure to newth3.
Definition: TH3.cxx:4245
virtual void SetBinsLength(Int_t n=-1)
Set total number of bins including under/overflow Reallocate bin contents array.
Definition: TH3.cxx:4055
virtual Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="")
Performs the operation: this = this + c1*f1 if errors are defined (see TH1::Sumw2), errors are also recalculated.
Definition: TH1.cxx:770
TAxis * GetZaxis()
Definition: TH1.h:326
Mother of all ROOT objects.
Definition: TObject.h:37
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
char Char_t
Definition: RtypesCore.h:29
virtual Int_t GetNpar() const
Definition: TF1.h:349
friend TH3C operator/(TH3C &h1, TH3C &h2)
Operator /.
Definition: TH3.cxx:3515
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
Definition: TAxis.cxx:526
TVirtualHistPainter * fPainter
!pointer to histogram painter
Definition: TH1.h:126
Double_t fTsumwxy
Definition: TH3.h:40
virtual void Copy(TObject &hnew) const
Copy this 3-D histogram structure to newth3.
Definition: TH3.cxx:3856
virtual ~TH3C()
Destructor.
Definition: TH3.cxx:3284
virtual TH3 * RebinZ(Int_t ngroup=2, const char *newname="")
Rebin only the Z axis see Rebin3D.
Definition: TH3.cxx:2687
virtual void GetRandom3(Double_t &x, Double_t &y, Double_t &z)
Return 3 random numbers along axis x , y and z distributed according the cellcontents of a 3-dim hist...
Definition: TH3.cxx:1089
Int_t fBufferSize
fBuffer size
Definition: TH1.h:121
virtual Double_t GetParameter(Int_t ipar) const
Definition: TF1.h:359
virtual Double_t DoIntegral(Int_t ix1, Int_t ix2, Int_t iy1, Int_t iy2, Int_t iz1, Int_t iz2, Double_t &err, Option_t *opt, Bool_t doerr=kFALSE) const
Internal function compute integral and optionally the error between the limits specified by the bin n...
Definition: TH1.cxx:7160
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
1-Dim function class
Definition: TF1.h:149
virtual void SetBinsLength(Int_t=-1)
Definition: TH1.h:377
Char_t * fArray
Definition: TArrayC.h:32
virtual ~TH3F()
Destructor.
Definition: TH3.cxx:3976
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition: TH1.cxx:8130
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
Definition: TH1.cxx:2544
TF1 * f1
Definition: legend1.C:11
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
Compute first cell (binx,biny,binz) in the range [firstx,lastx](firsty,lasty][firstz,lastz] for which diff = abs(cell_content-c) <= maxdiff In case several cells in the specified range with diff=0 are found the first cell found is returned in binx,biny,binz.
Definition: TH3.cxx:984
#define snprintf
Definition: civetweb.c:822
Int_t fDimension
!Histogram dimension (1, 2 or 3 dim)
Definition: TH1.h:124
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
Definition: THist.hxx:301
#define gPad
Definition: TVirtualPad.h:289
void Reset()
Definition: TArrayI.h:49
virtual void SetTickLength(Float_t length=0.03)
Set tick mark length The length is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:249
virtual Double_t * GetParameters() const
Definition: TF1.h:365
void Set(Int_t n)
Set size of this array to n floats.
Definition: TArrayF.cxx:105
virtual void SetEntries(Double_t n)
Definition: TH1.h:387
virtual void SetBinsLength(Int_t n=-1)
Set total number of bins including under/overflow Reallocate bin contents array.
Definition: TH3.cxx:3384
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
Definition: TH2.cxx:3811
TAxis fXaxis
X axis descriptor.
Definition: TH1.h:104
double result[121]
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content.
Definition: TH2.cxx:2475
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition: TAttMarker.h:36
virtual Int_t GetNbinsX() const
Definition: TH1.h:301
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
virtual ~TH3()
Destructor.
Definition: TH3.cxx:148
TH3F & operator=(const TH3F &h1)
Operator =.
Definition: TH3.cxx:4099
Int_t GetNbins() const
Definition: TAxis.h:127
TH3I()
Constructor.
Definition: TH3.cxx:3767
friend TH3S operator*(Float_t c1, TH3S &h1)
Operator *.
Definition: TH3.cxx:3699
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition: TAxis.cxx:716
virtual Double_t Interpolate(Double_t x)
Not yet implemented.
Definition: TH3.cxx:1255
const Bool_t kTRUE
Definition: Rtypes.h:91
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:292
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:155
void SetBins(const Int_t *nbins, const Double_t *range)
Definition: TProfile2D.h:52
Double_t * fBuffer
[fBufferSize] entry buffer
Definition: TH1.h:122
virtual void UpdateBinContent(Int_t bin, Double_t content)
Raw update of bin content on internal data structure see convention for numbering bins in TH1::GetBin...
Definition: TH1.cxx:8551
virtual Double_t GetStdDev(Int_t axis=1) const
Returns the Standard Deviation (Sigma).
Definition: TH1.cxx:6814
void Set(Int_t n)
Set size of this array to n doubles.
Definition: TArrayD.cxx:105
Double_t GetXmax() const
Definition: TAxis.h:140
void Copy(TArrayD &array) const
Definition: TArrayD.h:44
const Int_t n
Definition: legend1.C:16
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Definition: TMath.h:931
char name[80]
Definition: TGX11.cxx:109
const TArrayD * GetXbins() const
Definition: TAxis.h:136
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:911
TAxis * GetXaxis()
Definition: TH1.h:324
virtual Style_t GetLabelFont() const
Definition: TAttAxis.h:44
void Copy(TArrayS &array) const
Definition: TArrayS.h:44
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
virtual Int_t GetNbinsY() const
Definition: TH1.h:302
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition: TH1.cxx:8173
Int_t fNcells
number of bins(1D), cells (2D) +U/Overflows
Definition: TH1.h:103
tomato 2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:296
const char * Data() const
Definition: TString.h:349
Array of chars or bytes (8 bits per element).
Definition: TArrayC.h:29
virtual TArrayD * GetBinSumw2()
Definition: TProfile2D.h:118
TH3I & operator=(const TH3I &h1)
Operator =.
Definition: TH3.cxx:3888