Logo ROOT   6.10/09
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  // Projected range must be inside and not outside original one (ROOT-8781)
1713  Int_t ixmin = std::max(projX->GetFirst(),1);
1714  Int_t ixmax = std::min(projX->GetLast(),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 = std::max(projX->GetFirst(),1);
1907  Int_t ixmax = std::min(projX->GetLast(),projX->GetNbins());
1908  Int_t iymin = std::max(projY->GetFirst(),1);
1909  Int_t iymax = std::min(projY->GetLast(),projY->GetNbins());
1910 
1911  Int_t nx = ixmax-ixmin+1;
1912  Int_t ny = iymax-iymin+1;
1913 
1914  // Create the histogram, either reseting a preexisting one
1915  // or creating one from scratch.
1916  // Does an object with the same name exists?
1917  TObject *h2obj = gROOT->FindObject(name);
1918  if (h2obj && h2obj->InheritsFrom(TH1::Class())) {
1919  if ( h2obj->IsA() != TH2D::Class() ) {
1920  Error("DoProject2D","Histogram with name %s must be a TH2D and is a %s",name,h2obj->ClassName());
1921  return 0;
1922  }
1923  h2 = (TH2D*)h2obj;
1924  // reset histogram and its axes
1925  h2->Reset();
1926  const TArrayD *xbins = projX->GetXbins();
1927  const TArrayD *ybins = projY->GetXbins();
1928  if ( originalRange ) {
1929  h2->SetBins(projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
1930  ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
1931  // set bins for mixed axis do not exists - need to set afterwards the variable bins
1932  if (ybins->fN != 0)
1933  h2->GetXaxis()->Set(projY->GetNbins(),&ybins->fArray[iymin-1]);
1934  if (xbins->fN != 0)
1935  h2->GetYaxis()->Set(projX->GetNbins(),&xbins->fArray[ixmin-1]);
1936  } else {
1937  h2->SetBins(ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
1938  ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
1939  if (ybins->fN != 0)
1940  h2->GetXaxis()->Set(ny,&ybins->fArray[iymin-1]);
1941  if (xbins->fN != 0)
1942  h2->GetYaxis()->Set(nx,&xbins->fArray[ixmin-1]);
1943  }
1944  }
1945 
1946 
1947  if (!h2) {
1948  const TArrayD *xbins = projX->GetXbins();
1949  const TArrayD *ybins = projY->GetXbins();
1950  if ( originalRange )
1951  {
1952  if (xbins->fN == 0 && ybins->fN == 0) {
1953  h2 = new TH2D(name,title,projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
1954  ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
1955  } else if (ybins->fN == 0) {
1956  h2 = new TH2D(name,title,projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
1957  ,projX->GetNbins(),&xbins->fArray[ixmin-1]);
1958  } else if (xbins->fN == 0) {
1959  h2 = new TH2D(name,title,projY->GetNbins(),&ybins->fArray[iymin-1]
1960  ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
1961  } else {
1962  h2 = new TH2D(name,title,projY->GetNbins(),&ybins->fArray[iymin-1],projX->GetNbins(),&xbins->fArray[ixmin-1]);
1963  }
1964  } else {
1965  if (xbins->fN == 0 && ybins->fN == 0) {
1966  h2 = new TH2D(name,title,ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
1967  ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
1968  } else if (ybins->fN == 0) {
1969  h2 = new TH2D(name,title,ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
1970  ,nx,&xbins->fArray[ixmin-1]);
1971  } else if (xbins->fN == 0) {
1972  h2 = new TH2D(name,title,ny,&ybins->fArray[iymin-1]
1973  ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
1974  } else {
1975  h2 = new TH2D(name,title,ny,&ybins->fArray[iymin-1],nx,&xbins->fArray[ixmin-1]);
1976  }
1977  }
1978  }
1979 
1980  // Copy the axis attributes and the axis labels if needed.
1981  THashList* labels1 = 0;
1982  THashList* labels2 = 0;
1983  // "xy"
1984  h2->GetXaxis()->ImportAttributes(projY);
1985  h2->GetYaxis()->ImportAttributes(projX);
1986  labels1 = projY->GetLabels();
1987  labels2 = projX->GetLabels();
1988  if (labels1) {
1989  TIter iL(labels1);
1990  TObjString* lb;
1991  Int_t i = 1;
1992  while ((lb=(TObjString*)iL())) {
1993  h2->GetXaxis()->SetBinLabel(i,lb->String().Data());
1994  i++;
1995  }
1996  }
1997  if (labels2) {
1998  TIter iL(labels2);
1999  TObjString* lb;
2000  Int_t i = 1;
2001  while ((lb=(TObjString*)iL())) {
2002  h2->GetYaxis()->SetBinLabel(i,lb->String().Data());
2003  i++;
2004  }
2005  }
2006  h2->SetLineColor(this->GetLineColor());
2007  h2->SetFillColor(this->GetFillColor());
2008  h2->SetMarkerColor(this->GetMarkerColor());
2009  h2->SetMarkerStyle(this->GetMarkerStyle());
2010 
2011  // Activate errors
2012  if ( computeErrors) h2->Sumw2();
2013 
2014  // Set references to the axis, so that the bucle has no branches.
2015  const TAxis* out = 0;
2016  if ( projX != GetXaxis() && projY != GetXaxis() ) {
2017  out = GetXaxis();
2018  } else if ( projX != GetYaxis() && projY != GetYaxis() ) {
2019  out = GetYaxis();
2020  } else {
2021  out = GetZaxis();
2022  }
2023 
2024  Int_t *refX = 0, *refY = 0, *refZ = 0;
2025  Int_t ixbin, iybin, outbin;
2026  if ( projX == GetXaxis() && projY == GetYaxis() ) { refX = &ixbin; refY = &iybin; refZ = &outbin; }
2027  if ( projX == GetYaxis() && projY == GetXaxis() ) { refX = &iybin; refY = &ixbin; refZ = &outbin; }
2028  if ( projX == GetXaxis() && projY == GetZaxis() ) { refX = &ixbin; refY = &outbin; refZ = &iybin; }
2029  if ( projX == GetZaxis() && projY == GetXaxis() ) { refX = &iybin; refY = &outbin; refZ = &ixbin; }
2030  if ( projX == GetYaxis() && projY == GetZaxis() ) { refX = &outbin; refY = &ixbin; refZ = &iybin; }
2031  if ( projX == GetZaxis() && projY == GetYaxis() ) { refX = &outbin; refY = &iybin; refZ = &ixbin; }
2032  R__ASSERT (refX != 0 && refY != 0 && refZ != 0);
2033 
2034  // Fill the projected histogram excluding underflow/overflows if considered in the option
2035  // if specified in the option (by default they considered)
2036  Double_t totcont = 0;
2037 
2038  Int_t outmin = out->GetFirst();
2039  Int_t outmax = out->GetLast();
2040  // GetFirst(), GetLast() can return (0,0) when the range bit is set artifically (see TAxis::SetRange)
2041  if (outmin == 0 && outmax == 0) { outmin = 1; outmax = out->GetNbins(); }
2042  // correct for underflow/overflows
2043  if (useUF && !out->TestBit(TAxis::kAxisRange) ) outmin -= 1;
2044  if (useOF && !out->TestBit(TAxis::kAxisRange) ) outmax += 1;
2045 
2046  for (ixbin=0;ixbin<=1+projX->GetNbins();ixbin++) {
2047  if ( projX->TestBit(TAxis::kAxisRange) && ( ixbin < ixmin || ixbin > ixmax )) continue;
2048  Int_t ix = h2->GetYaxis()->FindBin( projX->GetBinCenter(ixbin) );
2049 
2050  for (iybin=0;iybin<=1+projY->GetNbins();iybin++) {
2051  if ( projY->TestBit(TAxis::kAxisRange) && ( iybin < iymin || iybin > iymax )) continue;
2052  Int_t iy = h2->GetXaxis()->FindBin( projY->GetBinCenter(iybin) );
2053 
2054  Double_t cont = 0;
2055  Double_t err2 = 0;
2056 
2057  // loop on the bins to be integrated (outbin should be called inbin)
2058  for (outbin = outmin; outbin <= outmax; outbin++) {
2059 
2060  Int_t bin = GetBin(*refX,*refY,*refZ);
2061 
2062  // sum the bin contents and errors if needed
2063  cont += RetrieveBinContent(bin);
2064  if (computeErrors) {
2065  Double_t exyz = GetBinError(bin);
2066  err2 += exyz*exyz;
2067  }
2068 
2069  }
2070 
2071  // remember axis are inverted
2072  h2->SetBinContent(iy , ix, cont);
2073  if (computeErrors) h2->SetBinError(iy, ix, TMath::Sqrt(err2) );
2074  // sum all content
2075  totcont += cont;
2076 
2077  }
2078  }
2079 
2080  // since we use fill we need to reset and recalculate the statistics (see comment in DoProject1D )
2081  // or keep original statistics if consistent sumw2
2082  bool resetStats = true;
2083  double eps = 1.E-12;
2084  if (IsA() == TH3F::Class() ) eps = 1.E-6;
2085  if (fTsumw != 0 && TMath::Abs( fTsumw - totcont) < TMath::Abs(fTsumw) * eps) resetStats = false;
2086 
2087  bool resetEntries = resetStats;
2088  // entries are calculated using underflow/overflow. If excluded entries must be reset
2089  resetEntries |= !useUF || !useOF;
2090 
2091  if (!resetStats) {
2092  Double_t stats[kNstat];
2093  Double_t oldst[kNstat]; // old statistics
2094  for (Int_t i = 0; i < kNstat; ++i) { oldst[i] = 0; }
2095  GetStats(oldst);
2096  std::copy(oldst,oldst+kNstat,stats);
2097  // not that projX refer to Y axis and projX refer to the X axis of projected histogram
2098  // nothing to do for projection in Y vs X
2099  if ( projY == GetXaxis() && projX == GetZaxis() ) { // case XZ
2100  stats[4] = oldst[7];
2101  stats[5] = oldst[8];
2102  stats[6] = oldst[9];
2103  }
2104  if ( projY == GetYaxis() ) {
2105  stats[2] = oldst[4];
2106  stats[3] = oldst[5];
2107  if ( projX == GetXaxis() ) { // case YX
2108  stats[4] = oldst[2];
2109  stats[5] = oldst[3];
2110  }
2111  if ( projX == GetZaxis() ) { // case YZ
2112  stats[4] = oldst[7];
2113  stats[5] = oldst[8];
2114  stats[6] = oldst[10];
2115  }
2116  }
2117  else if ( projY == GetZaxis() ) {
2118  stats[2] = oldst[7];
2119  stats[3] = oldst[8];
2120  if ( projX == GetXaxis() ) { // case ZX
2121  stats[4] = oldst[2];
2122  stats[5] = oldst[3];
2123  stats[6] = oldst[9];
2124  }
2125  if ( projX == GetYaxis() ) { // case ZY
2126  stats[4] = oldst[4];
2127  stats[5] = oldst[5];
2128  stats[6] = oldst[10];
2129  }
2130  }
2131  // set the new statistics
2132  h2->PutStats(stats);
2133  }
2134  else {
2135  // recalculate the statistics
2136  h2->ResetStats();
2137  }
2138 
2139  if (resetEntries) {
2140  // use the effective entries for the entries
2141  // since this is the only way to estimate them
2142  Double_t entries = h2->GetEffectiveEntries();
2143  if (!computeErrors) entries = TMath::Floor( entries + 0.5); // to avoid numerical rounding
2144  h2->SetEntries( entries );
2145  }
2146  else {
2147  h2->SetEntries( fEntries );
2148  }
2149 
2150 
2151  return h2;
2152 }
2153 
2154 
2155 ////////////////////////////////////////////////////////////////////////////////
2156 /// Project a 3-d histogram into 1 or 2-d histograms depending on the
2157 /// option parameter, which may contain a combination of the characters x,y,z,e
2158 /// - option = "x" return the x projection into a TH1D histogram
2159 /// - option = "y" return the y projection into a TH1D histogram
2160 /// - option = "z" return the z projection into a TH1D histogram
2161 /// - option = "xy" return the x versus y projection into a TH2D histogram
2162 /// - option = "yx" return the y versus x projection into a TH2D histogram
2163 /// - option = "xz" return the x versus z projection into a TH2D histogram
2164 /// - option = "zx" return the z versus x projection into a TH2D histogram
2165 /// - option = "yz" return the y versus z projection into a TH2D histogram
2166 /// - option = "zy" return the z versus y projection into a TH2D histogram
2167 ///
2168 /// NB: the notation "a vs b" means "a" vertical and "b" horizontal
2169 ///
2170 /// option = "o" original axis range of the target axes will be
2171 /// kept, but only bins inside the selected range will be filled.
2172 ///
2173 /// If option contains the string "e", errors are computed
2174 ///
2175 /// The projection is made for the selected bins only.
2176 /// To select a bin range along an axis, use TAxis::SetRange, eg
2177 /// h3.GetYaxis()->SetRange(23,56);
2178 ///
2179 /// NOTE 1: The generated histogram is named th3name + option
2180 /// eg if the TH3* h histogram is named "myhist", then
2181 /// h->Project3D("xy"); produces a TH2D histogram named "myhist_xy"
2182 /// if a histogram of the same type already exists, it is overwritten.
2183 /// The following sequence
2184 /// h->Project3D("xy");
2185 /// h->Project3D("xy2");
2186 /// will generate two TH2D histograms named "myhist_xy" and "myhist_xy2"
2187 /// A different name can be generated by attaching a string to the option
2188 /// For example h->Project3D("name_xy") will generate an histogram with the name: h3dname_name_xy.
2189 ///
2190 /// NOTE 2: If an histogram of the same type already exists,
2191 /// the histogram is reset and filled again with the projected contents of the TH3.
2192 ///
2193 /// NOTE 3: The number of entries in the projected histogram is estimated from the number of
2194 /// effective entries for all the cells included in the projection.
2195 ///
2196 /// NOTE 4: underflow/overflow are included by default in the projection
2197 /// To exclude underflow and/or overflow (for both axis in case of a projection to a 1D histogram) use option "NUF" and/or "NOF"
2198 /// With SetRange() you can have all bins except underflow/overflow only if you set the axis bit range as
2199 /// following after having called SetRange: axis->SetRange(1, axis->GetNbins());
2200 
2201 TH1 *TH3::Project3D(Option_t *option) const
2202 {
2203  TString opt = option; opt.ToLower();
2204  Int_t pcase = 0;
2205  TString ptype;
2206  if (opt.Contains("x")) { pcase = 1; ptype = "x"; }
2207  if (opt.Contains("y")) { pcase = 2; ptype = "y"; }
2208  if (opt.Contains("z")) { pcase = 3; ptype = "z"; }
2209  if (opt.Contains("xy")) { pcase = 4; ptype = "xy"; }
2210  if (opt.Contains("yx")) { pcase = 5; ptype = "yx"; }
2211  if (opt.Contains("xz")) { pcase = 6; ptype = "xz"; }
2212  if (opt.Contains("zx")) { pcase = 7; ptype = "zx"; }
2213  if (opt.Contains("yz")) { pcase = 8; ptype = "yz"; }
2214  if (opt.Contains("zy")) { pcase = 9; ptype = "zy"; }
2215 
2216  if (pcase == 0) {
2217  Error("Project3D","No projection axis specified - return a NULL pointer");
2218  return 0;
2219  }
2220  // do not remove ptype from opt to use later in the projected histo name
2221 
2222  Bool_t computeErrors = GetSumw2N();
2223  if (opt.Contains("e") ) {
2224  computeErrors = kTRUE;
2225  opt.Remove(opt.First("e"),1);
2226  }
2227 
2228  Bool_t useUF = kTRUE;
2229  Bool_t useOF = kTRUE;
2230  if (opt.Contains("nuf") ) {
2231  useUF = kFALSE;
2232  opt.Remove(opt.Index("nuf"),3);
2233  }
2234  if (opt.Contains("nof") ) {
2235  useOF = kFALSE;
2236  opt.Remove(opt.Index("nof"),3);
2237  }
2238 
2239  Bool_t originalRange = kFALSE;
2240  if (opt.Contains('o') ) {
2241  originalRange = kTRUE;
2242  opt.Remove(opt.First("o"),1);
2243  }
2244 
2245 
2246  // Create the projection histogram
2247  TH1 *h = 0;
2248 
2249  TString name = GetName();
2250  TString title = GetTitle();
2251  name += "_"; name += opt; // opt may include a user defined name
2252  title += " "; title += ptype; title += " projection";
2253 
2254  switch (pcase) {
2255  case 1:
2256  // "x"
2257  h = DoProject1D(name, title, this->GetXaxis(),
2258  computeErrors, originalRange, useUF, useOF);
2259  break;
2260 
2261  case 2:
2262  // "y"
2263  h = DoProject1D(name, title, this->GetYaxis(),
2264  computeErrors, originalRange, useUF, useOF);
2265  break;
2266 
2267  case 3:
2268  // "z"
2269  h = DoProject1D(name, title, this->GetZaxis(),
2270  computeErrors, originalRange, useUF, useOF);
2271  break;
2272 
2273  case 4:
2274  // "xy"
2275  h = DoProject2D(name, title, this->GetXaxis(),this->GetYaxis(),
2276  computeErrors, originalRange, useUF, useOF);
2277  break;
2278 
2279  case 5:
2280  // "yx"
2281  h = DoProject2D(name, title, this->GetYaxis(),this->GetXaxis(),
2282  computeErrors, originalRange, useUF, useOF);
2283  break;
2284 
2285  case 6:
2286  // "xz"
2287  h = DoProject2D(name, title, this->GetXaxis(),this->GetZaxis(),
2288  computeErrors, originalRange, useUF, useOF);
2289  break;
2290 
2291  case 7:
2292  // "zx"
2293  h = DoProject2D(name, title, this->GetZaxis(),this->GetXaxis(),
2294  computeErrors, originalRange, useUF, useOF);
2295  break;
2296 
2297  case 8:
2298  // "yz"
2299  h = DoProject2D(name, title, this->GetYaxis(),this->GetZaxis(),
2300  computeErrors, originalRange, useUF, useOF);
2301  break;
2302 
2303  case 9:
2304  // "zy"
2305  h = DoProject2D(name, title, this->GetZaxis(),this->GetYaxis(),
2306  computeErrors, originalRange, useUF, useOF);
2307  break;
2308 
2309  }
2310 
2311  // draw in current pad
2312  if (h && opt.Contains("d")) {
2313  opt.Remove(opt.First("d"),1);
2314  TVirtualPad *padsav = gPad;
2315  TVirtualPad *pad = gROOT->GetSelectedPad();
2316  if (pad) pad->cd();
2317  if (!gPad || !gPad->FindObject(h)) {
2318  h->Draw(opt);
2319  } else {
2320  h->Paint(opt);
2321  }
2322  if (padsav) padsav->cd();
2323  }
2324 
2325  return h;
2326 }
2327 
2328 
2329 ////////////////////////////////////////////////////////////////////////////////
2330 /// internal function to fill the bins of the projected profile 2D histogram
2331 /// called from DoProjectProfile2D
2332 
2334  const TAxis & a1, const TAxis & a2, const TAxis & a3,
2335  Int_t bin1, Int_t bin2, Int_t bin3,
2336  Int_t inBin, Bool_t useWeights ) const {
2337  Double_t cont = GetBinContent(inBin);
2338  if (!cont) return;
2339  TArrayD & binSumw2 = *(p2->GetBinSumw2());
2340  if (useWeights && binSumw2.fN <= 0) useWeights = false;
2341  if (!useWeights) p2->SetBit(TH1::kIsNotW); // to use Fill for setting the bin contents of the Profile
2342  // the following fill update wrongly the fBinSumw2- need to save it before
2343  Double_t u = a1.GetBinCenter(bin1);
2344  Double_t v = a2.GetBinCenter(bin2);
2345  Double_t w = a3.GetBinCenter(bin3);
2346  Int_t outBin = p2->FindBin(u, v);
2347  if (outBin <0) return;
2348  Double_t tmp = 0;
2349  if ( useWeights ) tmp = binSumw2.fArray[outBin];
2350  p2->Fill( u , v, w, cont);
2351  if (useWeights ) binSumw2.fArray[outBin] = tmp + fSumw2.fArray[inBin];
2352 }
2353 
2354 
2355 ////////////////////////////////////////////////////////////////////////////////
2356 /// internal method to project to a 2D Profile
2357 /// called from TH3::Project3DProfile
2358 
2359 TProfile2D *TH3::DoProjectProfile2D(const char* name, const char * title, const TAxis* projX, const TAxis* projY,
2360  bool originalRange, bool useUF, bool useOF) const
2361 {
2362  // Get the ranges where we will work.
2363  Int_t ixmin = std::max(projX->GetFirst(),1);
2364  Int_t ixmax = std::min(projX->GetLast(),projX->GetNbins());
2365  Int_t iymin = std::max(projY->GetFirst(),1);
2366  Int_t iymax = std::min(projY->GetLast(),projY->GetNbins());
2367 
2368  Int_t nx = ixmax-ixmin+1;
2369  Int_t ny = iymax-iymin+1;
2370 
2371  // Create the projected profiles
2372  TProfile2D *p2 = 0;
2373 
2374  // Create the histogram, either reseting a preexisting one
2375  // Does an object with the same name exists?
2376  TObject *p2obj = gROOT->FindObject(name);
2377  if (p2obj && p2obj->InheritsFrom(TH1::Class())) {
2378  if (p2obj->IsA() != TProfile2D::Class() ) {
2379  Error("DoProjectProfile2D","Histogram with name %s must be a TProfile2D and is a %s",name,p2obj->ClassName());
2380  return 0;
2381  }
2382  p2 = (TProfile2D*)p2obj;
2383  // reset existing profile and re-set bins
2384  p2->Reset();
2385  const TArrayD *xbins = projX->GetXbins();
2386  const TArrayD *ybins = projY->GetXbins();
2387  if ( originalRange ) {
2388  p2->SetBins(projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
2389  ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
2390  // set bins for mixed axis do not exists - need to set afterwards the variable bins
2391  if (ybins->fN != 0)
2392  p2->GetXaxis()->Set(projY->GetNbins(),&ybins->fArray[iymin-1]);
2393  if (xbins->fN != 0)
2394  p2->GetYaxis()->Set(projX->GetNbins(),&xbins->fArray[ixmin-1]);
2395  } else {
2396  p2->SetBins(ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
2397  ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
2398  if (ybins->fN != 0)
2399  p2->GetXaxis()->Set(ny,&ybins->fArray[iymin-1]);
2400  if (xbins->fN != 0)
2401  p2->GetYaxis()->Set(nx,&xbins->fArray[ixmin-1]);
2402  }
2403  }
2404 
2405  if (!p2) {
2406  const TArrayD *xbins = projX->GetXbins();
2407  const TArrayD *ybins = projY->GetXbins();
2408  if ( originalRange ) {
2409  if (xbins->fN == 0 && ybins->fN == 0) {
2410  p2 = new TProfile2D(name,title,projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
2411  ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
2412  } else if (ybins->fN == 0) {
2413  p2 = new TProfile2D(name,title,projY->GetNbins(),projY->GetXmin(),projY->GetXmax()
2414  ,projX->GetNbins(),&xbins->fArray[ixmin-1]);
2415  } else if (xbins->fN == 0) {
2416  p2 = new TProfile2D(name,title,projY->GetNbins(),&ybins->fArray[iymin-1]
2417  ,projX->GetNbins(),projX->GetXmin(),projX->GetXmax());
2418  } else {
2419  p2 = new TProfile2D(name,title,projY->GetNbins(),&ybins->fArray[iymin-1],projX->GetNbins(),&xbins->fArray[ixmin-1]);
2420  }
2421  } else {
2422  if (xbins->fN == 0 && ybins->fN == 0) {
2423  p2 = new TProfile2D(name,title,ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
2424  ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
2425  } else if (ybins->fN == 0) {
2426  p2 = new TProfile2D(name,title,ny,projY->GetBinLowEdge(iymin),projY->GetBinUpEdge(iymax)
2427  ,nx,&xbins->fArray[ixmin-1]);
2428  } else if (xbins->fN == 0) {
2429  p2 = new TProfile2D(name,title,ny,&ybins->fArray[iymin-1]
2430  ,nx,projX->GetBinLowEdge(ixmin),projX->GetBinUpEdge(ixmax));
2431  } else {
2432  p2 = new TProfile2D(name,title,ny,&ybins->fArray[iymin-1],nx,&xbins->fArray[ixmin-1]);
2433  }
2434  }
2435  }
2436 
2437  // Set references to the axis, so that the loop has no branches.
2438  const TAxis* outAxis = 0;
2439  if ( projX != GetXaxis() && projY != GetXaxis() ) {
2440  outAxis = GetXaxis();
2441  } else if ( projX != GetYaxis() && projY != GetYaxis() ) {
2442  outAxis = GetYaxis();
2443  } else {
2444  outAxis = GetZaxis();
2445  }
2446 
2447  // Weights management
2448  bool useWeights = (GetSumw2N() > 0);
2449  if (useWeights ) p2->Sumw2(); // store sum of w2 in profile if histo is weighted
2450 
2451  // Set references to the bins, so that the loop has no branches.
2452  Int_t *refX = 0, *refY = 0, *refZ = 0;
2453  Int_t ixbin, iybin, outbin;
2454  if ( projX == GetXaxis() && projY == GetYaxis() ) { refX = &ixbin; refY = &iybin; refZ = &outbin; }
2455  if ( projX == GetYaxis() && projY == GetXaxis() ) { refX = &iybin; refY = &ixbin; refZ = &outbin; }
2456  if ( projX == GetXaxis() && projY == GetZaxis() ) { refX = &ixbin; refY = &outbin; refZ = &iybin; }
2457  if ( projX == GetZaxis() && projY == GetXaxis() ) { refX = &iybin; refY = &outbin; refZ = &ixbin; }
2458  if ( projX == GetYaxis() && projY == GetZaxis() ) { refX = &outbin; refY = &ixbin; refZ = &iybin; }
2459  if ( projX == GetZaxis() && projY == GetYaxis() ) { refX = &outbin; refY = &iybin; refZ = &ixbin; }
2460  R__ASSERT (refX != 0 && refY != 0 && refZ != 0);
2461 
2462  Int_t outmin = outAxis->GetFirst();
2463  Int_t outmax = outAxis->GetLast();
2464  // GetFirst, GetLast can return underflow or overflow bins
2465  // correct for underflow/overflows
2466  if (useUF && !outAxis->TestBit(TAxis::kAxisRange) ) outmin -= 1;
2467  if (useOF && !outAxis->TestBit(TAxis::kAxisRange) ) outmax += 1;
2468 
2469  TArrayD & binSumw2 = *(p2->GetBinSumw2());
2470  if (useWeights && binSumw2.fN <= 0) useWeights = false;
2471  if (!useWeights) p2->SetBit(TH1::kIsNotW);
2472 
2473  // Call specific method for the projection
2474  for (ixbin=0;ixbin<=1+projX->GetNbins();ixbin++) {
2475  if ( (ixbin < ixmin || ixbin > ixmax) && projX->TestBit(TAxis::kAxisRange)) continue;
2476  for ( iybin=0;iybin<=1+projY->GetNbins();iybin++) {
2477  if ( (iybin < iymin || iybin > iymax) && projX->TestBit(TAxis::kAxisRange)) continue;
2478 
2479  // profile output bin
2480  Int_t poutBin = p2->FindBin(projY->GetBinCenter(iybin), projX->GetBinCenter(ixbin));
2481  if (poutBin <0) continue;
2482  // loop on the bins to be integrated (outbin should be called inbin)
2483  for (outbin = outmin; outbin <= outmax; outbin++) {
2484 
2485  Int_t bin = GetBin(*refX,*refY,*refZ);
2486 
2487  //DoFillProfileProjection(p2, *projY, *projX, *outAxis, iybin, ixbin, outbin, bin, useWeights);
2488 
2489  Double_t cont = RetrieveBinContent(bin);
2490  if (!cont) continue;
2491 
2492  Double_t tmp = 0;
2493  // the following fill update wrongly the fBinSumw2- need to save it before
2494  if ( useWeights ) tmp = binSumw2.fArray[poutBin];
2495  p2->Fill( projY->GetBinCenter(iybin) , projX->GetBinCenter(ixbin), outAxis->GetBinCenter(outbin), cont);
2496  if (useWeights ) binSumw2.fArray[poutBin] = tmp + fSumw2.fArray[bin];
2497 
2498  }
2499  }
2500  }
2501 
2502  // recompute statistics for the projected profiles
2503  // forget about preserving old statistics
2504  bool resetStats = true;
2505  Double_t stats[kNstat];
2506  // reset statistics
2507  if (resetStats)
2508  for (Int_t i=0;i<kNstat;i++) stats[i] = 0;
2509 
2510  p2->PutStats(stats);
2511  Double_t entries = fEntries;
2512  // recalculate the statistics
2513  if (resetStats) {
2514  entries = p2->GetEffectiveEntries();
2515  if (!useWeights) entries = TMath::Floor( entries + 0.5); // to avoid numerical rounding
2516  p2->SetEntries( entries );
2517  }
2518 
2519  p2->SetEntries(entries);
2520 
2521  return p2;
2522 }
2523 
2524 
2525 ////////////////////////////////////////////////////////////////////////////////
2526 /// Project a 3-d histogram into a 2-d profile histograms depending
2527 /// on the option parameter
2528 /// option may contain a combination of the characters x,y,z
2529 /// option = "xy" return the x versus y projection into a TProfile2D histogram
2530 /// option = "yx" return the y versus x projection into a TProfile2D histogram
2531 /// option = "xz" return the x versus z projection into a TProfile2D histogram
2532 /// option = "zx" return the z versus x projection into a TProfile2D histogram
2533 /// option = "yz" return the y versus z projection into a TProfile2D histogram
2534 /// option = "zy" return the z versus y projection into a TProfile2D histogram
2535 /// NB: the notation "a vs b" means "a" vertical and "b" horizontal
2536 ///
2537 /// option = "o" original axis range of the target axes will be
2538 /// kept, but only bins inside the selected range will be filled.
2539 ///
2540 /// The projection is made for the selected bins only.
2541 /// To select a bin range along an axis, use TAxis::SetRange, eg
2542 /// h3.GetYaxis()->SetRange(23,56);
2543 ///
2544 /// NOTE 1: The generated histogram is named th3name + "_p" + option
2545 /// eg if the TH3* h histogram is named "myhist", then
2546 /// h->Project3D("xy"); produces a TProfile2D histogram named "myhist_pxy".
2547 /// The following sequence
2548 /// h->Project3DProfile("xy");
2549 /// h->Project3DProfile("xy2");
2550 /// will generate two TProfile2D histograms named "myhist_pxy" and "myhist_pxy2"
2551 /// So, passing additional characters in the option string one can customize the name.
2552 ///
2553 /// NOTE 2: If a profile of the same type already exists with compatible axes,
2554 /// the profile is reset and filled again with the projected contents of the TH3.
2555 /// In the case of axes incompatibility, an error is reported and a NULL pointer is returned.
2556 ///
2557 /// NOTE 3: The number of entries in the projected profile is estimated from the number of
2558 /// effective entries for all the cells included in the projection.
2559 ///
2560 /// NOTE 4: underflow/overflow are by default excluded from the projection
2561 /// (Note that this is a different default behavior compared to the projection to an histogram)
2562 /// To include the underflow and/or overflow use option "UF" and/or "OF"
2563 
2565 {
2566  TString opt = option; opt.ToLower();
2567  Int_t pcase = 0;
2568  TString ptype;
2569  if (opt.Contains("xy")) { pcase = 4; ptype = "xy"; }
2570  if (opt.Contains("yx")) { pcase = 5; ptype = "yx"; }
2571  if (opt.Contains("xz")) { pcase = 6; ptype = "xz"; }
2572  if (opt.Contains("zx")) { pcase = 7; ptype = "zx"; }
2573  if (opt.Contains("yz")) { pcase = 8; ptype = "yz"; }
2574  if (opt.Contains("zy")) { pcase = 9; ptype = "zy"; }
2575 
2576  if (pcase == 0) {
2577  Error("Project3D","No projection axis specified - return a NULL pointer");
2578  return 0;
2579  }
2580  // do not remove ptype from opt to use later in the projected histo name
2581 
2582  Bool_t useUF = kFALSE;
2583  if (opt.Contains("uf") ) {
2584  useUF = kTRUE;
2585  opt.Remove(opt.Index("uf"),2);
2586  }
2587  Bool_t useOF = kFALSE;
2588  if (opt.Contains("of") ) {
2589  useOF = kTRUE;
2590  opt.Remove(opt.Index("of"),2);
2591  }
2592 
2593  Bool_t originalRange = kFALSE;
2594  if (opt.Contains('o') ) {
2595  originalRange = kTRUE;
2596  opt.Remove(opt.First("o"),1);
2597  }
2598 
2599  // Create the projected profile
2600  TProfile2D *p2 = 0;
2601  TString name = GetName();
2602  TString title = GetTitle();
2603  name += "_p"; name += opt; // opt may include a user defined name
2604  title += " profile "; title += ptype; title += " projection";
2605 
2606  // Call the method with the specific projected axes.
2607  switch (pcase) {
2608  case 4:
2609  // "xy"
2610  p2 = DoProjectProfile2D(name, title, GetXaxis(), GetYaxis(), originalRange, useUF, useOF);
2611  break;
2612 
2613  case 5:
2614  // "yx"
2615  p2 = DoProjectProfile2D(name, title, GetYaxis(), GetXaxis(), originalRange, useUF, useOF);
2616  break;
2617 
2618  case 6:
2619  // "xz"
2620  p2 = DoProjectProfile2D(name, title, GetXaxis(), GetZaxis(), originalRange, useUF, useOF);
2621  break;
2622 
2623  case 7:
2624  // "zx"
2625  p2 = DoProjectProfile2D(name, title, GetZaxis(), GetXaxis(), originalRange, useUF, useOF);
2626  break;
2627 
2628  case 8:
2629  // "yz"
2630  p2 = DoProjectProfile2D(name, title, GetYaxis(), GetZaxis(), originalRange, useUF, useOF);
2631  break;
2632 
2633  case 9:
2634  // "zy"
2635  p2 = DoProjectProfile2D(name, title, GetZaxis(), GetYaxis(), originalRange, useUF, useOF);
2636  break;
2637 
2638  }
2639 
2640  return p2;
2641 }
2642 
2643 
2644 ////////////////////////////////////////////////////////////////////////////////
2645 /// Replace current statistics with the values in array stats
2646 
2648 {
2649  TH1::PutStats(stats);
2650  fTsumwy = stats[4];
2651  fTsumwy2 = stats[5];
2652  fTsumwxy = stats[6];
2653  fTsumwz = stats[7];
2654  fTsumwz2 = stats[8];
2655  fTsumwxz = stats[9];
2656  fTsumwyz = stats[10];
2657 }
2658 
2659 
2660 ////////////////////////////////////////////////////////////////////////////////
2661 /// Rebin only the X axis
2662 /// see Rebin3D
2663 
2664 TH3 *TH3::RebinX(Int_t ngroup, const char *newname)
2665 {
2666  return Rebin3D(ngroup, 1, 1, newname);
2667 }
2668 
2669 
2670 ////////////////////////////////////////////////////////////////////////////////
2671 /// Rebin only the Y axis
2672 /// see Rebin3D
2673 
2674 TH3 *TH3::RebinY(Int_t ngroup, const char *newname)
2675 {
2676  return Rebin3D(1, ngroup, 1, newname);
2677 }
2678 
2679 
2680 ////////////////////////////////////////////////////////////////////////////////
2681 /// Rebin only the Z axis
2682 /// see Rebin3D
2683 
2684 TH3 *TH3::RebinZ(Int_t ngroup, const char *newname)
2685 {
2686  return Rebin3D(1, 1, ngroup, newname);
2687 
2688 }
2689 
2690 
2691 ////////////////////////////////////////////////////////////////////////////////
2692 /// Rebin this histogram grouping nxgroup/nygroup/nzgroup bins along the xaxis/yaxis/zaxis together.
2693 ///
2694 /// if newname is not blank a new temporary histogram hnew is created.
2695 /// else the current histogram is modified (default)
2696 /// The parameter nxgroup/nygroup indicate how many bins along the xaxis/yaxis of this
2697 /// have to me merged into one bin of hnew
2698 /// If the original histogram has errors stored (via Sumw2), the resulting
2699 /// histograms has new errors correctly calculated.
2700 ///
2701 /// examples: if hpxpy is an existing TH3 histogram with 40 x 40 x 40 bins
2702 /// hpxpypz->Rebin3D(); // merges two bins along the xaxis and yaxis in one in hpxpypz
2703 /// // Carefull: previous contents of hpxpy are lost
2704 /// hpxpypz->RebinX(5); //merges five bins along the xaxis in one in hpxpypz
2705 /// TH3 *hnew = hpxpypz->RebinY(5,"hnew"); // creates a new histogram hnew
2706 /// // merging 5 bins of h1 along the yaxis in one bin
2707 ///
2708 /// NOTE : If nxgroup/nygroup is not an exact divider of the number of bins,
2709 /// along the xaxis/yaxis the top limit(s) of the rebinned histogram
2710 /// is changed to the upper edge of the xbin=newxbins*nxgroup resp.
2711 /// ybin=newybins*nygroup and the corresponding bins are added to
2712 /// the overflow bin.
2713 /// Statistics will be recomputed from the new bin contents.
2714 
2715 TH3 *TH3::Rebin3D(Int_t nxgroup, Int_t nygroup, Int_t nzgroup, const char *newname)
2716 {
2717  Int_t i,j,k,xbin,ybin,zbin;
2718  Int_t nxbins = fXaxis.GetNbins();
2719  Int_t nybins = fYaxis.GetNbins();
2720  Int_t nzbins = fZaxis.GetNbins();
2725  Double_t zmin = fZaxis.GetXmin();
2726  Double_t zmax = fZaxis.GetXmax();
2727  if ((nxgroup <= 0) || (nxgroup > nxbins)) {
2728  Error("Rebin", "Illegal value of nxgroup=%d",nxgroup);
2729  return 0;
2730  }
2731  if ((nygroup <= 0) || (nygroup > nybins)) {
2732  Error("Rebin", "Illegal value of nygroup=%d",nygroup);
2733  return 0;
2734  }
2735  if ((nzgroup <= 0) || (nzgroup > nzbins)) {
2736  Error("Rebin", "Illegal value of nzgroup=%d",nzgroup);
2737  return 0;
2738  }
2739 
2740  Int_t newxbins = nxbins/nxgroup;
2741  Int_t newybins = nybins/nygroup;
2742  Int_t newzbins = nzbins/nzgroup;
2743 
2744  // Save old bin contents into a new array
2745  Double_t entries = fEntries;
2746  Double_t *oldBins = new Double_t[fNcells];
2747  for (Int_t ibin = 0; ibin < fNcells; ibin++) {
2748  oldBins[ibin] = RetrieveBinContent(ibin);
2749  }
2750  Double_t *oldSumw2 = 0;
2751  if (fSumw2.fN != 0) {
2752  oldSumw2 = new Double_t[fNcells];
2753  for (Int_t ibin = 0; ibin < fNcells; ibin++) {
2754  oldSumw2[ibin] = fSumw2.fArray[ibin];
2755  }
2756  }
2757 
2758  // create a clone of the old histogram if newname is specified
2759  TH3 *hnew = this;
2760  if (newname && strlen(newname)) {
2761  hnew = (TH3*)Clone();
2762  hnew->SetName(newname);
2763  }
2764 
2765  // save original statistics
2766  Double_t stat[kNstat];
2767  GetStats(stat);
2768  bool resetStat = false;
2769 
2770 
2771  // change axis specs and rebuild bin contents array
2772  if (newxbins*nxgroup != nxbins) {
2773  xmax = fXaxis.GetBinUpEdge(newxbins*nxgroup);
2774  resetStat = true; //stats must be reset because top bins will be moved to overflow bin
2775  }
2776  if (newybins*nygroup != nybins) {
2777  ymax = fYaxis.GetBinUpEdge(newybins*nygroup);
2778  resetStat = true; //stats must be reset because top bins will be moved to overflow bin
2779  }
2780  if (newzbins*nzgroup != nzbins) {
2781  zmax = fZaxis.GetBinUpEdge(newzbins*nzgroup);
2782  resetStat = true; //stats must be reset because top bins will be moved to overflow bin
2783  }
2784  // save the TAttAxis members (reset by SetBins) for x axis
2785  Int_t nXdivisions = fXaxis.GetNdivisions();
2786  Color_t xAxisColor = fXaxis.GetAxisColor();
2787  Color_t xLabelColor = fXaxis.GetLabelColor();
2788  Style_t xLabelFont = fXaxis.GetLabelFont();
2789  Float_t xLabelOffset = fXaxis.GetLabelOffset();
2790  Float_t xLabelSize = fXaxis.GetLabelSize();
2791  Float_t xTickLength = fXaxis.GetTickLength();
2792  Float_t xTitleOffset = fXaxis.GetTitleOffset();
2793  Float_t xTitleSize = fXaxis.GetTitleSize();
2794  Color_t xTitleColor = fXaxis.GetTitleColor();
2795  Style_t xTitleFont = fXaxis.GetTitleFont();
2796  // save the TAttAxis members (reset by SetBins) for y axis
2797  Int_t nYdivisions = fYaxis.GetNdivisions();
2798  Color_t yAxisColor = fYaxis.GetAxisColor();
2799  Color_t yLabelColor = fYaxis.GetLabelColor();
2800  Style_t yLabelFont = fYaxis.GetLabelFont();
2801  Float_t yLabelOffset = fYaxis.GetLabelOffset();
2802  Float_t yLabelSize = fYaxis.GetLabelSize();
2803  Float_t yTickLength = fYaxis.GetTickLength();
2804  Float_t yTitleOffset = fYaxis.GetTitleOffset();
2805  Float_t yTitleSize = fYaxis.GetTitleSize();
2806  Color_t yTitleColor = fYaxis.GetTitleColor();
2807  Style_t yTitleFont = fYaxis.GetTitleFont();
2808  // save the TAttAxis members (reset by SetBins) for z axis
2809  Int_t nZdivisions = fZaxis.GetNdivisions();
2810  Color_t zAxisColor = fZaxis.GetAxisColor();
2811  Color_t zLabelColor = fZaxis.GetLabelColor();
2812  Style_t zLabelFont = fZaxis.GetLabelFont();
2813  Float_t zLabelOffset = fZaxis.GetLabelOffset();
2814  Float_t zLabelSize = fZaxis.GetLabelSize();
2815  Float_t zTickLength = fZaxis.GetTickLength();
2816  Float_t zTitleOffset = fZaxis.GetTitleOffset();
2817  Float_t zTitleSize = fZaxis.GetTitleSize();
2818  Color_t zTitleColor = fZaxis.GetTitleColor();
2819  Style_t zTitleFont = fZaxis.GetTitleFont();
2820 
2821  // copy merged bin contents (ignore under/overflows)
2822  if (nxgroup != 1 || nygroup != 1 || nzgroup != 1) {
2823  if (fXaxis.GetXbins()->GetSize() > 0 || fYaxis.GetXbins()->GetSize() > 0 || fZaxis.GetXbins()->GetSize() > 0) {
2824  // variable bin sizes in x or y, don't treat both cases separately
2825  Double_t *xbins = new Double_t[newxbins+1];
2826  for (i = 0; i <= newxbins; ++i) xbins[i] = fXaxis.GetBinLowEdge(1+i*nxgroup);
2827  Double_t *ybins = new Double_t[newybins+1];
2828  for (i = 0; i <= newybins; ++i) ybins[i] = fYaxis.GetBinLowEdge(1+i*nygroup);
2829  Double_t *zbins = new Double_t[newzbins+1];
2830  for (i = 0; i <= newzbins; ++i) zbins[i] = fZaxis.GetBinLowEdge(1+i*nzgroup);
2831  hnew->SetBins(newxbins,xbins, newybins, ybins, newzbins, zbins);//changes also errors array (if any)
2832  delete [] xbins;
2833  delete [] ybins;
2834  delete [] zbins;
2835  } else {
2836  hnew->SetBins(newxbins, xmin, xmax, newybins, ymin, ymax, newzbins, zmin, zmax);//changes also errors array
2837  }
2838 
2839  Double_t binContent, binSumw2;
2840  Int_t oldxbin = 1;
2841  Int_t oldybin = 1;
2842  Int_t oldzbin = 1;
2843  Int_t bin;
2844  for (xbin = 1; xbin <= newxbins; xbin++) {
2845  oldybin=1;
2846  oldzbin=1;
2847  for (ybin = 1; ybin <= newybins; ybin++) {
2848  oldzbin=1;
2849  for (zbin = 1; zbin <= newzbins; zbin++) {
2850  binContent = 0;
2851  binSumw2 = 0;
2852  for (i = 0; i < nxgroup; i++) {
2853  if (oldxbin+i > nxbins) break;
2854  for (j =0; j < nygroup; j++) {
2855  if (oldybin+j > nybins) break;
2856  for (k =0; k < nzgroup; k++) {
2857  if (oldzbin+k > nzbins) break;
2858  //get global bin (same conventions as in TH1::GetBin(xbin,ybin)
2859  bin = oldxbin + i + (oldybin + j)*(nxbins + 2) + (oldzbin + k)*(nxbins + 2)*(nybins + 2);
2860  binContent += oldBins[bin];
2861  if (oldSumw2) binSumw2 += oldSumw2[bin];
2862  }
2863  }
2864  }
2865  Int_t ibin = hnew->GetBin(xbin,ybin,zbin); // new bin number
2866  hnew->SetBinContent(ibin, binContent);
2867  if (oldSumw2) hnew->fSumw2.fArray[ibin] = binSumw2;
2868  oldzbin += nzgroup;
2869  }
2870  oldybin += nygroup;
2871  }
2872  oldxbin += nxgroup;
2873  }
2874 
2875  // compute new underflow/overflows for the 8 vertices
2876  for (Int_t xover = 0; xover <= 1; xover++) {
2877  for (Int_t yover = 0; yover <= 1; yover++) {
2878  for (Int_t zover = 0; zover <= 1; zover++) {
2879  binContent = 0;
2880  binSumw2 = 0;
2881  // make loop in case of only underflow/overflow
2882  for (xbin = xover*oldxbin; xbin <= xover*(nxbins+1); xbin++) {
2883  for (ybin = yover*oldybin; ybin <= yover*(nybins+1); ybin++) {
2884  for (zbin = zover*oldzbin; zbin <= zover*(nzbins+1); zbin++) {
2885  bin = GetBin(xbin,ybin,zbin);
2886  binContent += oldBins[bin];
2887  if (oldSumw2) binSumw2 += oldSumw2[bin];
2888  }
2889  }
2890  }
2891  Int_t binNew = hnew->GetBin( xover *(newxbins+1),
2892  yover*(newybins+1), zover*(newzbins+1) );
2893  hnew->SetBinContent(binNew,binContent);
2894  if (oldSumw2) hnew->fSumw2.fArray[binNew] = binSumw2;
2895  }
2896  }
2897  }
2898 
2899  Double_t binContent0, binContent2, binContent3, binContent4;
2900  Double_t binError0, binError2, binError3, binError4;
2901  Int_t oldxbin2, oldybin2, oldzbin2;
2902  Int_t ufbin, ofbin, ofbin2, ofbin3, ofbin4;
2903 
2904  // recompute under/overflow contents in y for the new x and z bins
2905  oldxbin2 = 1;
2906  oldybin2 = 1;
2907  oldzbin2 = 1;
2908  for (xbin = 1; xbin<=newxbins; xbin++) {
2909  oldzbin2 = 1;
2910  for (zbin = 1; zbin<=newzbins; zbin++) {
2911  binContent0 = binContent2 = 0;
2912  binError0 = binError2 = 0;
2913  for (i=0; i<nxgroup; i++) {
2914  if (oldxbin2+i > nxbins) break;
2915  for (k=0; k<nzgroup; k++) {
2916  if (oldzbin2+k > nzbins) break;
2917  //old underflow bin (in y)
2918  ufbin = oldxbin2 + i + (nxbins+2)*(nybins+2)*(oldzbin2+k);
2919  binContent0 += oldBins[ufbin];
2920  if (oldSumw2) binError0 += oldSumw2[ufbin];
2921  for (ybin = oldybin; ybin <= nybins + 1; ybin++) {
2922  //old overflow bin (in y)
2923  ofbin = ufbin + ybin*(nxbins+2);
2924  binContent2 += oldBins[ofbin];
2925  if (oldSumw2) binError2 += oldSumw2[ofbin];
2926  }
2927  }
2928  }
2929  hnew->SetBinContent(xbin,0,zbin,binContent0);
2930  hnew->SetBinContent(xbin,newybins+1,zbin,binContent2);
2931  if (oldSumw2) {
2932  hnew->SetBinError(xbin,0,zbin,TMath::Sqrt(binError0));
2933  hnew->SetBinError(xbin,newybins+1,zbin,TMath::Sqrt(binError2) );
2934  }
2935  oldzbin2 += nzgroup;
2936  }
2937  oldxbin2 += nxgroup;
2938  }
2939 
2940  // recompute under/overflow contents in x for the new y and z bins
2941  oldxbin2 = 1;
2942  oldybin2 = 1;
2943  oldzbin2 = 1;
2944  for (ybin = 1; ybin<=newybins; ybin++) {
2945  oldzbin2 = 1;
2946  for (zbin = 1; zbin<=newzbins; zbin++) {
2947  binContent0 = binContent2 = 0;
2948  binError0 = binError2 = 0;
2949  for (j=0; j<nygroup; j++) {
2950  if (oldybin2+j > nybins) break;
2951  for (k=0; k<nzgroup; k++) {
2952  if (oldzbin2+k > nzbins) break;
2953  //old underflow bin (in y)
2954  ufbin = (oldybin2 + j)*(nxbins+2) + (nxbins+2)*(nybins+2)*(oldzbin2+k);
2955  binContent0 += oldBins[ufbin];
2956  if (oldSumw2) binError0 += oldSumw2[ufbin];
2957  for (xbin = oldxbin; xbin <= nxbins + 1; xbin++) {
2958  //old overflow bin (in x)
2959  ofbin = ufbin + xbin;
2960  binContent2 += oldBins[ofbin];
2961  if (oldSumw2) binError2 += oldSumw2[ofbin];
2962  }
2963  }
2964  }
2965  hnew->SetBinContent(0,ybin,zbin,binContent0);
2966  hnew->SetBinContent(newxbins+1,ybin,zbin,binContent2);
2967  if (oldSumw2) {
2968  hnew->SetBinError(0,ybin,zbin,TMath::Sqrt(binError0));
2969  hnew->SetBinError(newxbins+1,ybin,zbin,TMath::Sqrt(binError2) );
2970  }
2971  oldzbin2 += nzgroup;
2972  }
2973  oldybin2 += nygroup;
2974  }
2975 
2976  // recompute under/overflow contents in z for the new x and y bins
2977  oldxbin2 = 1;
2978  oldybin2 = 1;
2979  oldzbin2 = 1;
2980  for (xbin = 1; xbin<=newxbins; xbin++) {
2981  oldybin2 = 1;
2982  for (ybin = 1; ybin<=newybins; ybin++) {
2983  binContent0 = binContent2 = 0;
2984  binError0 = binError2 = 0;
2985  for (i=0; i<nxgroup; i++) {
2986  if (oldxbin2+i > nxbins) break;
2987  for (j=0; j<nygroup; j++) {
2988  if (oldybin2+j > nybins) break;
2989  //old underflow bin (in z)
2990  ufbin = oldxbin2 + i + (nxbins+2)*(oldybin2+j);
2991  binContent0 += oldBins[ufbin];
2992  if (oldSumw2) binError0 += oldSumw2[ufbin];
2993  for (zbin = oldzbin; zbin <= nzbins + 1; zbin++) {
2994  //old overflow bin (in z)
2995  ofbin = ufbin + (nxbins+2)*(nybins+2)*zbin;
2996  binContent2 += oldBins[ofbin];
2997  if (oldSumw2) binError2 += oldSumw2[ofbin];
2998  }
2999  }
3000  }
3001  hnew->SetBinContent(xbin,ybin,0,binContent0);
3002  hnew->SetBinContent(xbin,ybin,newzbins+1,binContent2);
3003  if (oldSumw2) {
3004  hnew->SetBinError(xbin,ybin,0,TMath::Sqrt(binError0));
3005  hnew->SetBinError(xbin,ybin,newzbins+1,TMath::Sqrt(binError2) );
3006  }
3007  oldybin2 += nygroup;
3008  }
3009  oldxbin2 += nxgroup;
3010  }
3011 
3012  // recompute under/overflow contents in y, z for the new x
3013  oldxbin2 = 1;
3014  oldybin2 = 1;
3015  oldzbin2 = 1;
3016  for (xbin = 1; xbin<=newxbins; xbin++) {
3017  binContent0 = 0;
3018  binContent2 = 0;
3019  binContent3 = 0;
3020  binContent4 = 0;
3021  binError0 = 0;
3022  binError2 = 0;
3023  binError3 = 0;
3024  binError4 = 0;
3025  for (i=0; i<nxgroup; i++) {
3026  if (oldxbin2+i > nxbins) break;
3027  ufbin = oldxbin2 + i; //
3028  binContent0 += oldBins[ufbin];
3029  if (oldSumw2) binError0 += oldSumw2[ufbin];
3030  for (ybin = oldybin; ybin <= nybins + 1; ybin++) {
3031  ofbin3 = ufbin+ybin*(nxbins+2);
3032  binContent3 += oldBins[ ofbin3 ];
3033  if (oldSumw2) binError3 += oldSumw2[ofbin3];
3034  for (zbin = oldzbin; zbin <= nzbins + 1; zbin++) {
3035  //old overflow bin (in z)
3036  ofbin4 = oldxbin2 + i + ybin*(nxbins+2) + (nxbins+2)*(nybins+2)*zbin;
3037  binContent4 += oldBins[ofbin4];
3038  if (oldSumw2) binError4 += oldSumw2[ofbin4];
3039  }
3040  }
3041  for (zbin = oldzbin; zbin <= nzbins + 1; zbin++) {
3042  ofbin2 = ufbin+zbin*(nxbins+2)*(nybins+2);
3043  binContent2 += oldBins[ ofbin2 ];
3044  if (oldSumw2) binError2 += oldSumw2[ofbin2];
3045  }
3046  }
3047  hnew->SetBinContent(xbin,0,0,binContent0);
3048  hnew->SetBinContent(xbin,0,newzbins+1,binContent2);
3049  hnew->SetBinContent(xbin,newybins+1,0,binContent3);
3050  hnew->SetBinContent(xbin,newybins+1,newzbins+1,binContent4);
3051  if (oldSumw2) {
3052  hnew->SetBinError(xbin,0,0,TMath::Sqrt(binError0));
3053  hnew->SetBinError(xbin,0,newzbins+1,TMath::Sqrt(binError2) );
3054  hnew->SetBinError(xbin,newybins+1,0,TMath::Sqrt(binError3) );
3055  hnew->SetBinError(xbin,newybins+1,newzbins+1,TMath::Sqrt(binError4) );
3056  }
3057  oldxbin2 += nxgroup;
3058  }
3059 
3060  // recompute under/overflow contents in x, y for the new z
3061  oldxbin2 = 1;
3062  oldybin2 = 1;
3063  oldzbin2 = 1;
3064  for (zbin = 1; zbin<=newzbins; zbin++) {
3065  binContent0 = 0;
3066  binContent2 = 0;
3067  binContent3 = 0;
3068  binContent4 = 0;
3069  binError0 = 0;
3070  binError2 = 0;
3071  binError3 = 0;
3072  binError4 = 0;
3073  for (i=0; i<nzgroup; i++) {
3074  if (oldzbin2+i > nzbins) break;
3075  ufbin = (oldzbin2 + i)*(nxbins+2)*(nybins+2); //
3076  binContent0 += oldBins[ufbin];
3077  if (oldSumw2) binError0 += oldSumw2[ufbin];
3078  for (ybin = oldybin; ybin <= nybins + 1; ybin++) {
3079  ofbin3 = ufbin+ybin*(nxbins+2);
3080  binContent3 += oldBins[ ofbin3 ];
3081  if (oldSumw2) binError3 += oldSumw2[ofbin3];
3082  for (xbin = oldxbin; xbin <= nxbins + 1; xbin++) {
3083  //old overflow bin (in z)
3084  ofbin4 = ufbin + xbin + ybin*(nxbins+2);
3085  binContent4 += oldBins[ofbin4];
3086  if (oldSumw2) binError4 += oldSumw2[ofbin4];
3087  }
3088  }
3089  for (xbin = oldxbin; xbin <= nxbins + 1; xbin++) {
3090  ofbin2 = xbin +(oldzbin2+i)*(nxbins+2)*(nybins+2);
3091  binContent2 += oldBins[ ofbin2 ];
3092  if (oldSumw2) binError2 += oldSumw2[ofbin2];
3093  }
3094  }
3095  hnew->SetBinContent(0,0,zbin,binContent0);
3096  hnew->SetBinContent(0,newybins+1,zbin,binContent3);
3097  hnew->SetBinContent(newxbins+1,0,zbin,binContent2);
3098  hnew->SetBinContent(newxbins+1,newybins+1,zbin,binContent4);
3099  if (oldSumw2) {
3100  hnew->SetBinError(0,0,zbin,TMath::Sqrt(binError0));
3101  hnew->SetBinError(0,newybins+1,zbin,TMath::Sqrt(binError3) );
3102  hnew->SetBinError(newxbins+1,0,zbin,TMath::Sqrt(binError2) );
3103  hnew->SetBinError(newxbins+1,newybins+1,zbin,TMath::Sqrt(binError4) );
3104  }
3105  oldzbin2 += nzgroup;
3106  }
3107 
3108  // recompute under/overflow contents in x, z for the new y
3109  oldxbin2 = 1;
3110  oldybin2 = 1;
3111  oldzbin2 = 1;
3112  for (ybin = 1; ybin<=newybins; ybin++) {
3113  binContent0 = 0;
3114  binContent2 = 0;
3115  binContent3 = 0;
3116  binContent4 = 0;
3117  binError0 = 0;
3118  binError2 = 0;
3119  binError3 = 0;
3120  binError4 = 0;
3121  for (i=0; i<nygroup; i++) {
3122  if (oldybin2+i > nybins) break;
3123  ufbin = (oldybin2 + i)*(nxbins+2); //
3124  binContent0 += oldBins[ufbin];
3125  if (oldSumw2) binError0 += oldSumw2[ufbin];
3126  for (xbin = oldxbin; xbin <= nxbins + 1; xbin++) {
3127  ofbin3 = ufbin+xbin;
3128  binContent3 += oldBins[ ofbin3 ];
3129  if (oldSumw2) binError3 += oldSumw2[ofbin3];
3130  for (zbin = oldzbin; zbin <= nzbins + 1; zbin++) {
3131  //old overflow bin (in z)
3132  ofbin4 = xbin + (nxbins+2)*(nybins+2)*zbin+(oldybin2+i)*(nxbins+2);
3133  binContent4 += oldBins[ofbin4];
3134  if (oldSumw2) binError4 += oldSumw2[ofbin4];
3135  }
3136  }
3137  for (zbin = oldzbin; zbin <= nzbins + 1; zbin++) {
3138  ofbin2 = (oldybin2+i)*(nxbins+2)+zbin*(nxbins+2)*(nybins+2);
3139  binContent2 += oldBins[ ofbin2 ];
3140  if (oldSumw2) binError2 += oldSumw2[ofbin2];
3141  }
3142  }
3143  hnew->SetBinContent(0,ybin,0,binContent0);
3144  hnew->SetBinContent(0,ybin,newzbins+1,binContent2);
3145  hnew->SetBinContent(newxbins+1,ybin,0,binContent3);
3146  hnew->SetBinContent(newxbins+1,ybin,newzbins+1,binContent4);
3147  if (oldSumw2) {
3148  hnew->SetBinError(0,ybin,0,TMath::Sqrt(binError0));
3149  hnew->SetBinError(0,ybin,newzbins+1,TMath::Sqrt(binError2) );
3150  hnew->SetBinError(newxbins+1,ybin,0,TMath::Sqrt(binError3) );
3151  hnew->SetBinError(newxbins+1,ybin,newzbins+1,TMath::Sqrt(binError4) );
3152  }
3153  oldybin2 += nygroup;
3154  }
3155  }
3156 
3157  // Restore x axis attributes
3158  fXaxis.SetNdivisions(nXdivisions);
3159  fXaxis.SetAxisColor(xAxisColor);
3160  fXaxis.SetLabelColor(xLabelColor);
3161  fXaxis.SetLabelFont(xLabelFont);
3162  fXaxis.SetLabelOffset(xLabelOffset);
3163  fXaxis.SetLabelSize(xLabelSize);
3164  fXaxis.SetTickLength(xTickLength);
3165  fXaxis.SetTitleOffset(xTitleOffset);
3166  fXaxis.SetTitleSize(xTitleSize);
3167  fXaxis.SetTitleColor(xTitleColor);
3168  fXaxis.SetTitleFont(xTitleFont);
3169  // Restore y axis attributes
3170  fYaxis.SetNdivisions(nYdivisions);
3171  fYaxis.SetAxisColor(yAxisColor);
3172  fYaxis.SetLabelColor(yLabelColor);
3173  fYaxis.SetLabelFont(yLabelFont);
3174  fYaxis.SetLabelOffset(yLabelOffset);
3175  fYaxis.SetLabelSize(yLabelSize);
3176  fYaxis.SetTickLength(yTickLength);
3177  fYaxis.SetTitleOffset(yTitleOffset);
3178  fYaxis.SetTitleSize(yTitleSize);
3179  fYaxis.SetTitleColor(yTitleColor);
3180  fYaxis.SetTitleFont(yTitleFont);
3181  // Restore z axis attributes
3182  fZaxis.SetNdivisions(nZdivisions);
3183  fZaxis.SetAxisColor(zAxisColor);
3184  fZaxis.SetLabelColor(zLabelColor);
3185  fZaxis.SetLabelFont(zLabelFont);
3186  fZaxis.SetLabelOffset(zLabelOffset);
3187  fZaxis.SetLabelSize(zLabelSize);
3188  fZaxis.SetTickLength(zTickLength);
3189  fZaxis.SetTitleOffset(zTitleOffset);
3190  fZaxis.SetTitleSize(zTitleSize);
3191  fZaxis.SetTitleColor(zTitleColor);
3192  fZaxis.SetTitleFont(zTitleFont);
3193 
3194  //restore statistics and entries modified by SetBinContent
3195  hnew->SetEntries(entries);
3196  if (!resetStat) hnew->PutStats(stat);
3197 
3198  delete [] oldBins;
3199  if (oldSumw2) delete [] oldSumw2;
3200  return hnew;
3201 }
3202 
3203 
3204 ////////////////////////////////////////////////////////////////////////////////
3205 /// Reset this histogram: contents, errors, etc.
3206 
3207 void TH3::Reset(Option_t *option)
3208 {
3209  TH1::Reset(option);
3210  TString opt = option;
3211  opt.ToUpper();
3212  if (opt.Contains("ICE") && !opt.Contains("S")) return;
3213  fTsumwy = 0;
3214  fTsumwy2 = 0;
3215  fTsumwxy = 0;
3216  fTsumwz = 0;
3217  fTsumwz2 = 0;
3218  fTsumwxz = 0;
3219  fTsumwyz = 0;
3220 }
3221 
3222 
3223 ////////////////////////////////////////////////////////////////////////////////
3224 /// Set bin content.
3225 
3227 {
3228  fEntries++;
3229  fTsumw = 0;
3230  if (bin < 0) return;
3231  if (bin >= fNcells) return;
3232  UpdateBinContent(bin, content);
3233 }
3234 
3235 
3236 ////////////////////////////////////////////////////////////////////////////////
3237 /// Stream an object of class TH3.
3238 
3239 void TH3::Streamer(TBuffer &R__b)
3240 {
3241  if (R__b.IsReading()) {
3242  UInt_t R__s, R__c;
3243  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
3244  if (R__v > 2) {
3245  R__b.ReadClassBuffer(TH3::Class(), this, R__v, R__s, R__c);
3246  return;
3247  }
3248  //====process old versions before automatic schema evolution
3249  TH1::Streamer(R__b);
3250  TAtt3D::Streamer(R__b);
3251  R__b.CheckByteCount(R__s, R__c, TH3::IsA());
3252  //====end of old versions
3253 
3254  } else {
3255  R__b.WriteClassBuffer(TH3::Class(),this);
3256  }
3257 }
3258 
3259 
3260 //______________________________________________________________________________
3261 // TH3C methods
3262 // TH3C a 3-D histogram with one byte per cell (char)
3263 //______________________________________________________________________________
3264 
3265 ClassImp(TH3C)
3266 
3267 
3268 ////////////////////////////////////////////////////////////////////////////////
3269 /// Constructor.
3270 
3272 {
3273  SetBinsLength(27);
3274  if (fgDefaultSumw2) Sumw2();
3275 }
3276 
3277 
3278 ////////////////////////////////////////////////////////////////////////////////
3279 /// Destructor.
3280 
3282 {
3283 }
3284 
3285 
3286 ////////////////////////////////////////////////////////////////////////////////
3287 /// Normal constructor for fix bin size 3-D histograms.
3288 
3289 TH3C::TH3C(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3290  ,Int_t nbinsy,Double_t ylow,Double_t yup
3291  ,Int_t nbinsz,Double_t zlow,Double_t zup)
3292  :TH3(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,zlow,zup)
3293 {
3295  if (fgDefaultSumw2) Sumw2();
3296 
3297  if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
3298 }
3299 
3300 
3301 ////////////////////////////////////////////////////////////////////////////////
3302 /// Normal constructor for variable bin size 3-D histograms.
3303 
3304 TH3C::TH3C(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
3305  ,Int_t nbinsy,const Float_t *ybins
3306  ,Int_t nbinsz,const Float_t *zbins)
3307  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3308 {
3310  if (fgDefaultSumw2) Sumw2();
3311 }
3312 
3313 
3314 ////////////////////////////////////////////////////////////////////////////////
3315 /// Normal constructor for variable bin size 3-D histograms.
3316 
3317 TH3C::TH3C(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
3318  ,Int_t nbinsy,const Double_t *ybins
3319  ,Int_t nbinsz,const Double_t *zbins)
3320  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3321 {
3323  if (fgDefaultSumw2) Sumw2();
3324 }
3325 
3326 
3327 ////////////////////////////////////////////////////////////////////////////////
3328 /// Copy constructor.
3329 
3330 TH3C::TH3C(const TH3C &h3c) : TH3(), TArrayC()
3331 {
3332  ((TH3C&)h3c).Copy(*this);
3333 }
3334 
3335 
3336 ////////////////////////////////////////////////////////////////////////////////
3337 /// Increment bin content by 1.
3338 
3340 {
3341  if (fArray[bin] < 127) fArray[bin]++;
3342 }
3343 
3344 
3345 ////////////////////////////////////////////////////////////////////////////////
3346 /// Increment bin content by w.
3347 
3349 {
3350  Int_t newval = fArray[bin] + Int_t(w);
3351  if (newval > -128 && newval < 128) {fArray[bin] = Char_t(newval); return;}
3352  if (newval < -127) fArray[bin] = -127;
3353  if (newval > 127) fArray[bin] = 127;
3354 }
3355 
3356 
3357 ////////////////////////////////////////////////////////////////////////////////
3358 /// Copy this 3-D histogram structure to newth3.
3359 
3360 void TH3C::Copy(TObject &newth3) const
3361 {
3362  TH3::Copy((TH3C&)newth3);
3363 }
3364 
3365 
3366 ////////////////////////////////////////////////////////////////////////////////
3367 /// Reset this histogram: contents, errors, etc.
3368 
3369 void TH3C::Reset(Option_t *option)
3370 {
3371  TH3::Reset(option);
3372  TArrayC::Reset();
3373  // should also reset statistics once statistics are implemented for TH3
3374 }
3375 
3376 
3377 ////////////////////////////////////////////////////////////////////////////////
3378 /// Set total number of bins including under/overflow
3379 /// Reallocate bin contents array
3380 
3382 {
3383  if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2)*(fZaxis.GetNbins()+2);
3384  fNcells = n;
3385  TArrayC::Set(n);
3386 }
3387 
3388 
3389 ////////////////////////////////////////////////////////////////////////////////
3390 /// When the mouse is moved in a pad containing a 3-d view of this histogram
3391 /// a second canvas shows a projection type given as option.
3392 /// To stop the generation of the projections, delete the canvas
3393 /// containing the projection.
3394 /// option may contain a combination of the characters x,y,z,e
3395 /// option = "x" return the x projection into a TH1D histogram
3396 /// option = "y" return the y projection into a TH1D histogram
3397 /// option = "z" return the z projection into a TH1D histogram
3398 /// option = "xy" return the x versus y projection into a TH2D histogram
3399 /// option = "yx" return the y versus x projection into a TH2D histogram
3400 /// option = "xz" return the x versus z projection into a TH2D histogram
3401 /// option = "zx" return the z versus x projection into a TH2D histogram
3402 /// option = "yz" return the y versus z projection into a TH2D histogram
3403 /// option = "zy" return the z versus y projection into a TH2D histogram
3404 /// option can also include the drawing option for the projection, eg to draw
3405 /// the xy projection using the draw option "box" do
3406 /// myhist.SetShowProjection("xy box");
3407 /// This function is typically called from the context menu.
3408 /// NB: the notation "a vs b" means "a" vertical and "b" horizontal
3409 
3410 void TH3::SetShowProjection(const char *option,Int_t nbins)
3411 {
3412  GetPainter();
3413 
3414  if (fPainter) fPainter->SetShowProjection(option,nbins);
3415 }
3416 
3417 
3418 ////////////////////////////////////////////////////////////////////////////////
3419 /// Stream an object of class TH3C.
3420 
3421 void TH3C::Streamer(TBuffer &R__b)
3422 {
3423  if (R__b.IsReading()) {
3424  UInt_t R__s, R__c;
3425  if (R__b.GetParent() && R__b.GetVersionOwner() < 22300) return;
3426  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
3427  if (R__v > 2) {
3428  R__b.ReadClassBuffer(TH3C::Class(), this, R__v, R__s, R__c);
3429  return;
3430  }
3431  //====process old versions before automatic schema evolution
3432  if (R__v < 2) {
3433  R__b.ReadVersion();
3434  TH1::Streamer(R__b);
3435  TArrayC::Streamer(R__b);
3436  R__b.ReadVersion(&R__s, &R__c);
3437  TAtt3D::Streamer(R__b);
3438  } else {
3439  TH3::Streamer(R__b);
3440  TArrayC::Streamer(R__b);
3441  R__b.CheckByteCount(R__s, R__c, TH3C::IsA());
3442  }
3443  //====end of old versions
3444 
3445  } else {
3446  R__b.WriteClassBuffer(TH3C::Class(),this);
3447  }
3448 }
3449 
3450 
3451 ////////////////////////////////////////////////////////////////////////////////
3452 /// Operator =
3453 
3455 {
3456  if (this != &h1) ((TH3C&)h1).Copy(*this);
3457  return *this;
3458 }
3459 
3460 
3461 ////////////////////////////////////////////////////////////////////////////////
3462 /// Operator *
3463 
3465 {
3466  TH3C hnew = h1;
3467  hnew.Scale(c1);
3468  hnew.SetDirectory(0);
3469  return hnew;
3470 }
3471 
3472 
3473 ////////////////////////////////////////////////////////////////////////////////
3474 /// Operator +
3475 
3477 {
3478  TH3C hnew = h1;
3479  hnew.Add(&h2,1);
3480  hnew.SetDirectory(0);
3481  return hnew;
3482 }
3483 
3484 
3485 ////////////////////////////////////////////////////////////////////////////////
3486 /// Operator -
3487 
3489 {
3490  TH3C hnew = h1;
3491  hnew.Add(&h2,-1);
3492  hnew.SetDirectory(0);
3493  return hnew;
3494 }
3495 
3496 
3497 ////////////////////////////////////////////////////////////////////////////////
3498 /// Operator *
3499 
3501 {
3502  TH3C hnew = h1;
3503  hnew.Multiply(&h2);
3504  hnew.SetDirectory(0);
3505  return hnew;
3506 }
3507 
3508 
3509 ////////////////////////////////////////////////////////////////////////////////
3510 /// Operator /
3511 
3513 {
3514  TH3C hnew = h1;
3515  hnew.Divide(&h2);
3516  hnew.SetDirectory(0);
3517  return hnew;
3518 }
3519 
3520 
3521 //______________________________________________________________________________
3522 // TH3S methods
3523 // TH3S a 3-D histogram with two bytes per cell (short integer)
3524 //______________________________________________________________________________
3525 
3526 ClassImp(TH3S)
3527 
3528 
3529 ////////////////////////////////////////////////////////////////////////////////
3530 /// Constructor.
3531 
3533 {
3534  SetBinsLength(27);
3535  if (fgDefaultSumw2) Sumw2();
3536 }
3537 
3538 
3539 ////////////////////////////////////////////////////////////////////////////////
3540 /// Destructor.
3541 
3543 {
3544 }
3545 
3546 
3547 ////////////////////////////////////////////////////////////////////////////////
3548 /// Normal constructor for fix bin size 3-D histograms.
3549 
3550 TH3S::TH3S(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3551  ,Int_t nbinsy,Double_t ylow,Double_t yup
3552  ,Int_t nbinsz,Double_t zlow,Double_t zup)
3553  :TH3(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,zlow,zup)
3554 {
3555  TH3S::Set(fNcells);
3556  if (fgDefaultSumw2) Sumw2();
3557 
3558  if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
3559 }
3560 
3561 
3562 ////////////////////////////////////////////////////////////////////////////////
3563 /// Normal constructor for variable bin size 3-D histograms.
3564 
3565 TH3S::TH3S(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
3566  ,Int_t nbinsy,const Float_t *ybins
3567  ,Int_t nbinsz,const Float_t *zbins)
3568  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3569 {
3570  TH3S::Set(fNcells);
3571  if (fgDefaultSumw2) Sumw2();
3572 }
3573 
3574 
3575 ////////////////////////////////////////////////////////////////////////////////
3576 /// Normal constructor for variable bin size 3-D histograms.
3577 
3578 TH3S::TH3S(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
3579  ,Int_t nbinsy,const Double_t *ybins
3580  ,Int_t nbinsz,const Double_t *zbins)
3581  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3582 {
3583  TH3S::Set(fNcells);
3584  if (fgDefaultSumw2) Sumw2();
3585 }
3586 
3587 
3588 ////////////////////////////////////////////////////////////////////////////////
3589 /// Copy Constructor.
3590 
3591 TH3S::TH3S(const TH3S &h3s) : TH3(), TArrayS()
3592 {
3593  ((TH3S&)h3s).Copy(*this);
3594 }
3595 
3596 
3597 ////////////////////////////////////////////////////////////////////////////////
3598 /// Increment bin content by 1.
3599 
3601 {
3602  if (fArray[bin] < 32767) fArray[bin]++;
3603 }
3604 
3605 
3606 ////////////////////////////////////////////////////////////////////////////////
3607 /// Increment bin content by w.
3608 
3610 {
3611  Int_t newval = fArray[bin] + Int_t(w);
3612  if (newval > -32768 && newval < 32768) {fArray[bin] = Short_t(newval); return;}
3613  if (newval < -32767) fArray[bin] = -32767;
3614  if (newval > 32767) fArray[bin] = 32767;
3615 }
3616 
3617 
3618 ////////////////////////////////////////////////////////////////////////////////
3619 /// Copy this 3-D histogram structure to newth3.
3620 
3621 void TH3S::Copy(TObject &newth3) const
3622 {
3623  TH3::Copy((TH3S&)newth3);
3624 }
3625 
3626 
3627 ////////////////////////////////////////////////////////////////////////////////
3628 /// Reset this histogram: contents, errors, etc.
3629 
3630 void TH3S::Reset(Option_t *option)
3631 {
3632  TH3::Reset(option);
3633  TArrayS::Reset();
3634  // should also reset statistics once statistics are implemented for TH3
3635 }
3636 
3637 
3638 ////////////////////////////////////////////////////////////////////////////////
3639 /// Set total number of bins including under/overflow
3640 /// Reallocate bin contents array
3641 
3643 {
3644  if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2)*(fZaxis.GetNbins()+2);
3645  fNcells = n;
3646  TArrayS::Set(n);
3647 }
3648 
3649 
3650 ////////////////////////////////////////////////////////////////////////////////
3651 /// Stream an object of class TH3S.
3652 
3653 void TH3S::Streamer(TBuffer &R__b)
3654 {
3655  if (R__b.IsReading()) {
3656  UInt_t R__s, R__c;
3657  if (R__b.GetParent() && R__b.GetVersionOwner() < 22300) return;
3658  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
3659  if (R__v > 2) {
3660  R__b.ReadClassBuffer(TH3S::Class(), this, R__v, R__s, R__c);
3661  return;
3662  }
3663  //====process old versions before automatic schema evolution
3664  if (R__v < 2) {
3665  R__b.ReadVersion();
3666  TH1::Streamer(R__b);
3667  TArrayS::Streamer(R__b);
3668  R__b.ReadVersion(&R__s, &R__c);
3669  TAtt3D::Streamer(R__b);
3670  } else {
3671  TH3::Streamer(R__b);
3672  TArrayS::Streamer(R__b);
3673  R__b.CheckByteCount(R__s, R__c, TH3S::IsA());
3674  }
3675  //====end of old versions
3676 
3677  } else {
3678  R__b.WriteClassBuffer(TH3S::Class(),this);
3679  }
3680 }
3681 
3682 
3683 ////////////////////////////////////////////////////////////////////////////////
3684 /// Operator =
3685 
3687 {
3688  if (this != &h1) ((TH3S&)h1).Copy(*this);
3689  return *this;
3690 }
3691 
3692 
3693 ////////////////////////////////////////////////////////////////////////////////
3694 /// Operator *
3695 
3697 {
3698  TH3S hnew = h1;
3699  hnew.Scale(c1);
3700  hnew.SetDirectory(0);
3701  return hnew;
3702 }
3703 
3704 
3705 ////////////////////////////////////////////////////////////////////////////////
3706 /// Operator +
3707 
3709 {
3710  TH3S hnew = h1;
3711  hnew.Add(&h2,1);
3712  hnew.SetDirectory(0);
3713  return hnew;
3714 }
3715 
3716 
3717 ////////////////////////////////////////////////////////////////////////////////
3718 /// Operator -
3719 
3721 {
3722  TH3S hnew = h1;
3723  hnew.Add(&h2,-1);
3724  hnew.SetDirectory(0);
3725  return hnew;
3726 }
3727 
3728 
3729 ////////////////////////////////////////////////////////////////////////////////
3730 /// Operator *
3731 
3733 {
3734  TH3S hnew = h1;
3735  hnew.Multiply(&h2);
3736  hnew.SetDirectory(0);
3737  return hnew;
3738 }
3739 
3740 
3741 ////////////////////////////////////////////////////////////////////////////////
3742 /// Operator /
3743 
3745 {
3746  TH3S hnew = h1;
3747  hnew.Divide(&h2);
3748  hnew.SetDirectory(0);
3749  return hnew;
3750 }
3751 
3752 
3753 //______________________________________________________________________________
3754 // TH3I methods
3755 // TH3I a 3-D histogram with four bytes per cell (32 bits integer)
3756 //______________________________________________________________________________
3757 
3758 ClassImp(TH3I)
3759 
3760 
3761 ////////////////////////////////////////////////////////////////////////////////
3762 /// Constructor.
3763 
3765 {
3766  SetBinsLength(27);
3767  if (fgDefaultSumw2) Sumw2();
3768 }
3769 
3770 
3771 ////////////////////////////////////////////////////////////////////////////////
3772 /// Destructor.
3773 
3775 {
3776 }
3777 
3778 
3779 ////////////////////////////////////////////////////////////////////////////////
3780 /// Normal constructor for fix bin size 3-D histograms.
3781 
3782 TH3I::TH3I(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3783  ,Int_t nbinsy,Double_t ylow,Double_t yup
3784  ,Int_t nbinsz,Double_t zlow,Double_t zup)
3785  :TH3(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,zlow,zup)
3786 {
3787  TH3I::Set(fNcells);
3788  if (fgDefaultSumw2) Sumw2();
3789 
3790  if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
3791 }
3792 
3793 
3794 ////////////////////////////////////////////////////////////////////////////////
3795 /// Normal constructor for variable bin size 3-D histograms.
3796 
3797 TH3I::TH3I(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
3798  ,Int_t nbinsy,const Float_t *ybins
3799  ,Int_t nbinsz,const Float_t *zbins)
3800  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3801 {
3803  if (fgDefaultSumw2) Sumw2();
3804 }
3805 
3806 
3807 ////////////////////////////////////////////////////////////////////////////////
3808 /// Normal constructor for variable bin size 3-D histograms.
3809 
3810 TH3I::TH3I(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
3811  ,Int_t nbinsy,const Double_t *ybins
3812  ,Int_t nbinsz,const Double_t *zbins)
3813  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
3814 {
3816  if (fgDefaultSumw2) Sumw2();
3817 }
3818 
3819 
3820 ////////////////////////////////////////////////////////////////////////////////
3821 /// Copy constructor.
3822 
3823 TH3I::TH3I(const TH3I &h3i) : TH3(), TArrayI()
3824 {
3825  ((TH3I&)h3i).Copy(*this);
3826 }
3827 
3828 
3829 ////////////////////////////////////////////////////////////////////////////////
3830 /// Increment bin content by 1.
3831 
3833 {
3834  if (fArray[bin] < 2147483647) fArray[bin]++;
3835 }
3836 
3837 
3838 ////////////////////////////////////////////////////////////////////////////////
3839 /// Increment bin content by w.
3840 
3842 {
3843  Int_t newval = fArray[bin] + Int_t(w);
3844  if (newval > -2147483647 && newval < 2147483647) {fArray[bin] = Int_t(newval); return;}
3845  if (newval < -2147483647) fArray[bin] = -2147483647;
3846  if (newval > 2147483647) fArray[bin] = 2147483647;
3847 }
3848 
3849 
3850 ////////////////////////////////////////////////////////////////////////////////
3851 /// Copy this 3-D histogram structure to newth3.
3852 
3853 void TH3I::Copy(TObject &newth3) const
3854 {
3855  TH3::Copy((TH3I&)newth3);
3856 }
3857 
3858 
3859 ////////////////////////////////////////////////////////////////////////////////
3860 /// Reset this histogram: contents, errors, etc.
3861 
3862 void TH3I::Reset(Option_t *option)
3863 {
3864  TH3::Reset(option);
3865  TArrayI::Reset();
3866  // should also reset statistics once statistics are implemented for TH3
3867 }
3868 
3869 
3870 ////////////////////////////////////////////////////////////////////////////////
3871 /// Set total number of bins including under/overflow
3872 /// Reallocate bin contents array
3873 
3875 {
3876  if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2)*(fZaxis.GetNbins()+2);
3877  fNcells = n;
3878  TArrayI::Set(n);
3879 }
3880 
3881 
3882 ////////////////////////////////////////////////////////////////////////////////
3883 /// Operator =
3884 
3886 {
3887  if (this != &h1) ((TH3I&)h1).Copy(*this);
3888  return *this;
3889 }
3890 
3891 
3892 ////////////////////////////////////////////////////////////////////////////////
3893 /// Operator *
3894 
3896 {
3897  TH3I hnew = h1;
3898  hnew.Scale(c1);
3899  hnew.SetDirectory(0);
3900  return hnew;
3901 }
3902 
3903 
3904 ////////////////////////////////////////////////////////////////////////////////
3905 /// Operator +
3906 
3908 {
3909  TH3I hnew = h1;
3910  hnew.Add(&h2,1);
3911  hnew.SetDirectory(0);
3912  return hnew;
3913 }
3914 
3915 
3916 ////////////////////////////////////////////////////////////////////////////////
3917 /// Operator _
3918 
3920 {
3921  TH3I hnew = h1;
3922  hnew.Add(&h2,-1);
3923  hnew.SetDirectory(0);
3924  return hnew;
3925 }
3926 
3927 
3928 ////////////////////////////////////////////////////////////////////////////////
3929 /// Operator *
3930 
3932 {
3933  TH3I hnew = h1;
3934  hnew.Multiply(&h2);
3935  hnew.SetDirectory(0);
3936  return hnew;
3937 }
3938 
3939 
3940 ////////////////////////////////////////////////////////////////////////////////
3941 /// Operator /
3942 
3944 {
3945  TH3I hnew = h1;
3946  hnew.Divide(&h2);
3947  hnew.SetDirectory(0);
3948  return hnew;
3949 }
3950 
3951 
3952 //______________________________________________________________________________
3953 // TH3F methods
3954 // TH3F a 3-D histogram with four bytes per cell (float)
3955 //______________________________________________________________________________
3956 
3957 ClassImp(TH3F)
3958 
3959 
3960 ////////////////////////////////////////////////////////////////////////////////
3961 /// Constructor.
3962 
3964 {
3965  SetBinsLength(27);
3966  if (fgDefaultSumw2) Sumw2();
3967 }
3968 
3969 
3970 ////////////////////////////////////////////////////////////////////////////////
3971 /// Destructor.
3972 
3974 {
3975 }
3976 
3977 
3978 ////////////////////////////////////////////////////////////////////////////////
3979 /// Normal constructor for fix bin size 3-D histograms.
3980 
3981 TH3F::TH3F(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3982  ,Int_t nbinsy,Double_t ylow,Double_t yup
3983  ,Int_t nbinsz,Double_t zlow,Double_t zup)
3984  :TH3(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,zlow,zup)
3985 {
3987  if (fgDefaultSumw2) Sumw2();
3988 
3989  if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
3990 }
3991 
3992 
3993 ////////////////////////////////////////////////////////////////////////////////
3994 /// Normal constructor for variable bin size 3-D histograms.
3995 
3996 TH3F::TH3F(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
3997  ,Int_t nbinsy,const Float_t *ybins
3998  ,Int_t nbinsz,const Float_t *zbins)
3999  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
4000 {
4002  if (fgDefaultSumw2) Sumw2();
4003 }
4004 
4005 
4006 ////////////////////////////////////////////////////////////////////////////////
4007 /// Normal constructor for variable bin size 3-D histograms.
4008 
4009 TH3F::TH3F(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
4010  ,Int_t nbinsy,const Double_t *ybins
4011  ,Int_t nbinsz,const Double_t *zbins)
4012  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
4013 {
4015  if (fgDefaultSumw2) Sumw2();
4016 }
4017 
4018 
4019 ////////////////////////////////////////////////////////////////////////////////
4020 /// Copy constructor.
4021 
4022 TH3F::TH3F(const TH3F &h3f) : TH3(), TArrayF()
4023 {
4024  ((TH3F&)h3f).Copy(*this);
4025 }
4026 
4027 
4028 ////////////////////////////////////////////////////////////////////////////////
4029 /// Copy this 3-D histogram structure to newth3.
4030 
4031 void TH3F::Copy(TObject &newth3) const
4032 {
4033  TH3::Copy((TH3F&)newth3);
4034 }
4035 
4036 
4037 ////////////////////////////////////////////////////////////////////////////////
4038 /// Reset this histogram: contents, errors, etc.
4039 
4040 void TH3F::Reset(Option_t *option)
4041 {
4042  TH3::Reset(option);
4043  TArrayF::Reset();
4044  // should also reset statistics once statistics are implemented for TH3
4045 }
4046 
4047 
4048 ////////////////////////////////////////////////////////////////////////////////
4049 /// Set total number of bins including under/overflow
4050 /// Reallocate bin contents array
4051 
4053 {
4054  if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2)*(fZaxis.GetNbins()+2);
4055  fNcells = n;
4056  TArrayF::Set(n);
4057 }
4058 
4059 
4060 ////////////////////////////////////////////////////////////////////////////////
4061 /// Stream an object of class TH3F.
4062 
4063 void TH3F::Streamer(TBuffer &R__b)
4064 {
4065  if (R__b.IsReading()) {
4066  UInt_t R__s, R__c;
4067  if (R__b.GetParent() && R__b.GetVersionOwner() < 22300) return;
4068  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
4069  if (R__v > 2) {
4070  R__b.ReadClassBuffer(TH3F::Class(), this, R__v, R__s, R__c);
4071  return;
4072  }
4073  //====process old versions before automatic schema evolution
4074  if (R__v < 2) {
4075  R__b.ReadVersion();
4076  TH1::Streamer(R__b);
4077  TArrayF::Streamer(R__b);
4078  R__b.ReadVersion(&R__s, &R__c);
4079  TAtt3D::Streamer(R__b);
4080  } else {
4081  TH3::Streamer(R__b);
4082  TArrayF::Streamer(R__b);
4083  R__b.CheckByteCount(R__s, R__c, TH3F::IsA());
4084  }
4085  //====end of old versions
4086 
4087  } else {
4088  R__b.WriteClassBuffer(TH3F::Class(),this);
4089  }
4090 }
4091 
4092 
4093 ////////////////////////////////////////////////////////////////////////////////
4094 /// Operator =
4095 
4097 {
4098  if (this != &h1) ((TH3F&)h1).Copy(*this);
4099  return *this;
4100 }
4101 
4102 
4103 ////////////////////////////////////////////////////////////////////////////////
4104 /// Operator *
4105 
4107 {
4108  TH3F hnew = h1;
4109  hnew.Scale(c1);
4110  hnew.SetDirectory(0);
4111  return hnew;
4112 }
4113 
4114 
4115 ////////////////////////////////////////////////////////////////////////////////
4116 /// Operator +
4117 
4119 {
4120  TH3F hnew = h1;
4121  hnew.Add(&h2,1);
4122  hnew.SetDirectory(0);
4123  return hnew;
4124 }
4125 
4126 
4127 ////////////////////////////////////////////////////////////////////////////////
4128 /// Operator -
4129 
4131 {
4132  TH3F hnew = h1;
4133  hnew.Add(&h2,-1);
4134  hnew.SetDirectory(0);
4135  return hnew;
4136 }
4137 
4138 
4139 ////////////////////////////////////////////////////////////////////////////////
4140 /// Operator *
4141 
4143 {
4144  TH3F hnew = h1;
4145  hnew.Multiply(&h2);
4146  hnew.SetDirectory(0);
4147  return hnew;
4148 }
4149 
4150 
4151 ////////////////////////////////////////////////////////////////////////////////
4152 /// Operator /
4153 
4155 {
4156  TH3F hnew = h1;
4157  hnew.Divide(&h2);
4158  hnew.SetDirectory(0);
4159  return hnew;
4160 }
4161 
4162 
4163 //______________________________________________________________________________
4164 // TH3D methods
4165 // TH3D a 3-D histogram with eight bytes per cell (double)
4166 //______________________________________________________________________________
4167 
4168 ClassImp(TH3D)
4169 
4170 
4171 ////////////////////////////////////////////////////////////////////////////////
4172 /// Constructor.
4173 
4175 {
4176  SetBinsLength(27);
4177  if (fgDefaultSumw2) Sumw2();
4178 }
4179 
4180 
4181 ////////////////////////////////////////////////////////////////////////////////
4182 /// Destructor.
4183 
4185 {
4186 }
4187 
4188 
4189 ////////////////////////////////////////////////////////////////////////////////
4190 /// Normal constructor for fix bin size 3-D histograms.
4191 
4192 TH3D::TH3D(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
4193  ,Int_t nbinsy,Double_t ylow,Double_t yup
4194  ,Int_t nbinsz,Double_t zlow,Double_t zup)
4195  :TH3(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,zlow,zup)
4196 {
4198  if (fgDefaultSumw2) Sumw2();
4199 
4200  if (xlow >= xup || ylow >= yup || zlow >= zup) SetBuffer(fgBufferSize);
4201 }
4202 
4203 
4204 ////////////////////////////////////////////////////////////////////////////////
4205 /// Normal constructor for variable bin size 3-D histograms.
4206 
4207 TH3D::TH3D(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
4208  ,Int_t nbinsy,const Float_t *ybins
4209  ,Int_t nbinsz,const Float_t *zbins)
4210  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
4211 {
4213  if (fgDefaultSumw2) Sumw2();
4214 }
4215 
4216 
4217 ////////////////////////////////////////////////////////////////////////////////
4218 /// Normal constructor for variable bin size 3-D histograms.
4219 
4220 TH3D::TH3D(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
4221  ,Int_t nbinsy,const Double_t *ybins
4222  ,Int_t nbinsz,const Double_t *zbins)
4223  :TH3(name,title,nbinsx,xbins,nbinsy,ybins,nbinsz,zbins)
4224 {
4226  if (fgDefaultSumw2) Sumw2();
4227 }
4228 
4229 
4230 ////////////////////////////////////////////////////////////////////////////////
4231 /// Copy constructor.
4232 
4233 TH3D::TH3D(const TH3D &h3d) : TH3(), TArrayD()
4234 {
4235  ((TH3D&)h3d).Copy(*this);
4236 }
4237 
4238 
4239 ////////////////////////////////////////////////////////////////////////////////
4240 /// Copy this 3-D histogram structure to newth3.
4241 
4242 void TH3D::Copy(TObject &newth3) const
4243 {
4244  TH3::Copy((TH3D&)newth3);
4245 }
4246 
4247 
4248 ////////////////////////////////////////////////////////////////////////////////
4249 /// Reset this histogram: contents, errors, etc.
4250 
4251 void TH3D::Reset(Option_t *option)
4252 {
4253  TH3::Reset(option);
4254  TArrayD::Reset();
4255  // should also reset statistics once statistics are implemented for TH3
4256 }
4257 
4258 
4259 ////////////////////////////////////////////////////////////////////////////////
4260 /// Set total number of bins including under/overflow
4261 /// Reallocate bin contents array
4262 
4264 {
4265  if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2)*(fZaxis.GetNbins()+2);
4266  fNcells = n;
4267  TArrayD::Set(n);
4268 }
4269 
4270 
4271 ////////////////////////////////////////////////////////////////////////////////
4272 /// Stream an object of class TH3D.
4273 
4274 void TH3D::Streamer(TBuffer &R__b)
4275 {
4276  if (R__b.IsReading()) {
4277  UInt_t R__s, R__c;
4278  if (R__b.GetParent() && R__b.GetVersionOwner() < 22300) return;
4279  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
4280  if (R__v > 2) {
4281  R__b.ReadClassBuffer(TH3D::Class(), this, R__v, R__s, R__c);
4282  return;
4283  }
4284  //====process old versions before automatic schema evolution
4285  if (R__v < 2) {
4286  R__b.ReadVersion();
4287  TH1::Streamer(R__b);
4288  TArrayD::Streamer(R__b);
4289  R__b.ReadVersion(&R__s, &R__c);
4290  TAtt3D::Streamer(R__b);
4291  } else {
4292  TH3::Streamer(R__b);
4293  TArrayD::Streamer(R__b);
4294  R__b.CheckByteCount(R__s, R__c, TH3D::IsA());
4295  }
4296  //====end of old versions
4297 
4298  } else {
4299  R__b.WriteClassBuffer(TH3D::Class(),this);
4300  }
4301 }
4302 
4303 
4304 ////////////////////////////////////////////////////////////////////////////////
4305 /// Operator =
4306 
4308 {
4309  if (this != &h1) ((TH3D&)h1).Copy(*this);
4310  return *this;
4311 }
4312 
4313 
4314 ////////////////////////////////////////////////////////////////////////////////
4315 /// Operator *
4316 
4318 {
4319  TH3D hnew = h1;
4320  hnew.Scale(c1);
4321  hnew.SetDirectory(0);
4322  return hnew;
4323 }
4324 
4325 
4326 ////////////////////////////////////////////////////////////////////////////////
4327 /// Operator +
4328 
4330 {
4331  TH3D hnew = h1;
4332  hnew.Add(&h2,1);
4333  hnew.SetDirectory(0);
4334  return hnew;
4335 }
4336 
4337 
4338 ////////////////////////////////////////////////////////////////////////////////
4339 /// Operator -
4340 
4342 {
4343  TH3D hnew = h1;
4344  hnew.Add(&h2,-1);
4345  hnew.SetDirectory(0);
4346  return hnew;
4347 }
4348 
4349 
4350 ////////////////////////////////////////////////////////////////////////////////
4351 /// Operator *
4352 
4354 {
4355  TH3D hnew = h1;
4356  hnew.Multiply(&h2);
4357  hnew.SetDirectory(0);
4358  return hnew;
4359 }
4360 
4361 
4362 ////////////////////////////////////////////////////////////////////////////////
4363 /// Operator /
4364 
4366 {
4367  TH3D hnew = h1;
4368  hnew.Divide(&h2);
4369  hnew.SetDirectory(0);
4370  return hnew;
4371 }
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:47
Bool_t IsReading() const
Definition: TBuffer.h:81
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:3441
virtual Float_t GetTickLength() const
Definition: TAttAxis.h:44
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
Definition: TH1.cxx:5937
virtual Double_t GetEffectiveEntries() const
Number of effective entries of the histogram.
Definition: TH1.cxx:4079
virtual void Paint(Option_t *option="")
Control routine to paint any kind of histograms.
Definition: TH1.cxx:5539
TH3()
Default constructor.
Definition: TH3.cxx:63
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:588
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:4317
Double_t Floor(Double_t x)
Definition: TMath.h:600
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:4031
virtual void SetBinsLength(Int_t n=-1)
Set total number of bins including under/overflow Reallocate bin contents array.
Definition: TH3.cxx:3642
void Copy(TArrayI &array) const
Definition: TArrayI.h:42
virtual void Copy(TObject &hnew) const
Copy this 3-D histogram structure to newth3.
Definition: TH3.cxx:3621
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, which may contain a combination of the characters x,y,z,e.
Definition: TH3.cxx:2201
virtual TH3 * RebinX(Int_t ngroup=2, const char *newname="")
Rebin only the X axis see Rebin3D.
Definition: TH3.cxx:2664
Double_t Log(Double_t x)
Definition: TMath.h:649
virtual void Sumw2(Bool_t flag=kTRUE)
Create/Delete structure to store sum of squares of weights per bin.
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:2337
friend TH3F operator+(TH3F &h1, TH3F &h2)
Operator +.
Definition: TH3.cxx:4118
static Bool_t fgDefaultSumw2
!flag to call TH1::Sumw2 automatically at histogram creation time
Definition: TH1.h:107
TVirtualHistPainter * GetPainter(Option_t *option="")
Return pointer to painter.
Definition: TH1.cxx:4100
Collectable string class.
Definition: TObjString.h:28
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:8053
friend TH3F operator/(TH3F &h1, TH3F &h2)
Operator /.
Definition: TH3.cxx:4154
virtual Float_t GetLabelOffset() const
Definition: TAttAxis.h:40
tomato 3-D histogram with a float per channel (see TH1 documentation)}
Definition: TH3.h:267
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:2359
Short_t * fArray
Definition: TArrayS.h:30
const char Option_t
Definition: RtypesCore.h:62
friend TH3I operator+(TH3I &h1, TH3I &h2)
Operator +.
Definition: TH3.cxx:3907
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:47
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:784
TAxis fYaxis
Y axis descriptor.
Definition: TH1.h:81
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content.
Definition: TH3.cxx:3226
virtual void PutStats(Double_t *stats)
Replace current statistics with the values in array stats.
Definition: TH1.cxx:7073
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:159
virtual void SetBins(Int_t nx, Double_t xmin, Double_t xmax)
Redefine x axis parameters.
Definition: TH1.cxx:7883
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:2715
virtual Color_t GetAxisColor() const
Definition: TAttAxis.h:37
TH1 * h
Definition: legend2.C:5
static Bool_t fgStatOverflows
!flag to use under/overflows in statistics
Definition: TH1.h:106
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:4639
TH3F()
Constructor.
Definition: TH3.cxx:3963
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:3288
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:19
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1112
TH3S & operator=(const TH3S &h1)
Operator =.
Definition: TH3.cxx:3686
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:4341
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
friend TH3C operator+(TH3C &h1, TH3C &h2)
Operator +.
Definition: TH3.cxx:3476
virtual Int_t GetNbinsZ() const
Definition: TH1.h:279
#define R__ASSERT(e)
Definition: TError.h:96
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:375
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:587
virtual ~TH3D()
Destructor.
Definition: TH3.cxx:4184
Double_t fTsumwy
Definition: TH3.h:34
Basic string class.
Definition: TString.h:129
Array of floats (32 bits per element).
Definition: TArrayF.h:27
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:1099
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
friend TH3F operator*(Float_t c1, TH3F &h1)
Operator *.
Definition: TH3.cxx:4106
Double_t fTsumwz
Definition: TH3.h:37
Histogram is forced to be not weighted even when the histogram is filled with weighted different than...
Definition: TH1.h:155
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
Definition: TF1.cxx:1656
int nbins[3]
TArrayD fSumw2
Array of sum of squares of weights.
Definition: TH1.h:94
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH3.h:91
friend TH3I operator/(TH3I &h1, TH3I &h2)
Operator /.
Definition: TH3.cxx:3943
void Copy(TArrayC &array) const
Definition: TArrayC.h:42
virtual Float_t GetLabelSize() const
Definition: TAttAxis.h:41
void Reset()
Definition: TArrayF.h:47
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:2564
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:82
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:5364
Double_t fTsumwyz
Definition: TH3.h:40
friend TH3F operator-(TH3F &h1, TH3F &h2)
Operator -.
Definition: TH3.cxx:4130
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:108
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:27
void Reset(Char_t val=0)
Definition: TArrayC.h:47
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:687
virtual void SetBuffer(Int_t buffersize, Option_t *option="")
Set the maximum number of entries to be kept in the buffer.
Definition: TH1.cxx:7582
Double_t fTsumwx2
Total Sum of weight*X*X.
Definition: TH1.h:89
virtual Bool_t CanExtendAllAxes() const
Returns true if all axes are extendable.
Definition: TH1.cxx:5961
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
Definition: TH1.cxx:6419
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:4174
virtual Style_t GetMarkerStyle() const
Return the marker style.
Definition: TAttMarker.h:32
virtual Style_t GetTitleFont() const
Definition: TAttAxis.h:46
virtual Int_t GetDimension() const
Definition: TH1.h:263
Int_t Fill(const Double_t *v)
Definition: TProfile2D.h:50
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:133
TH3S()
Constructor.
Definition: TH3.cxx:3532
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:135
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:2345
Double_t fTsumwxz
Definition: TH3.h:39
void Class()
Definition: Class.C:29
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:34
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:4329
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:2674
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:3464
virtual void AddBinContent(Int_t bin)
Increment bin content by 1.
Definition: TH3.cxx:3339
THashList * GetLabels() const
Definition: TAxis.h:117
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:38
Double_t * fArray
Definition: TArrayD.h:30
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:477
virtual void AddBinContent(Int_t bin)
Increment bin content by 1.
Definition: TH3.cxx:3832
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:7088
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:49
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:9388
virtual void SetBinError(Int_t bin, Double_t error)
See convention for numbering bins in TH1::GetBin.
Definition: TH1.cxx:8311
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:38
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:31
short Color_t
Definition: RtypesCore.h:79
Double_t fTsumwx
Total Sum of weight*X.
Definition: TH1.h:88
virtual void SetBinsLength(Int_t n=-1)
Set total number of bins including under/overflow Reallocate bin contents array.
Definition: TH3.cxx:3874
tomato 3-D histogram with an int per channel (see TH1 documentation)}
Definition: TH3.h:230
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:36
virtual ~TH3I()
Destructor.
Definition: TH3.cxx:3774
virtual ~TH3S()
Destructor.
Definition: TH3.cxx:3542
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:617
virtual const char * GetParName(Int_t ipar) const
Definition: TF1.h:483
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:5839
void Reset()
Definition: TArrayS.h:47
tomato 3-D histogram with a short per channel (see TH1 documentation)
Definition: TH3.h:194
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
Definition: TH3.cxx:3369
Int_t fN
Definition: TArray.h:38
TH3C & operator=(const TH3C &h1)
Operator =.
Definition: TH3.cxx:3454
float ymax
Definition: THbookFile.cxx:93
friend TH3S operator-(TH3S &h1, TH3S &h2)
Operator -.
Definition: TH3.cxx:3720
void Copy(TArrayF &array) const
Definition: TArrayF.h:42
TH3C()
Constructor.
Definition: TH3.cxx:3271
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:129
Class to manage histogram axis.
Definition: TAxis.h:30
friend TH3S operator+(TH3S &h1, TH3S &h2)
Operator +.
Definition: TH3.cxx:3708
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:304
Array of shorts (16 bits per element).
Definition: TArrayS.h:27
Int_t GetSize() const
Definition: TArray.h:47
SVector< double, 2 > v
Definition: Dict.h:5
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual Int_t GetNumberFitPoints() const
Definition: TF1.h:457
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:35
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:436
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:8325
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:2503
static Int_t fgBufferSize
!default buffer size for automatic histograms
Definition: TH1.h:104
Double_t Mean(Long64_t n, const T *a, const Double_t *w=0)
Definition: TMath.h:973
virtual void PutStats(Double_t *stats)
Replace current statistics with the values in array stats.
Double_t fEntries
Number of entries.
Definition: TH1.h:85
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:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:873
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:2647
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:3410
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition: TAttMarker.h:40
TAxis * GetYaxis()
Definition: TH1.h:301
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:45
Double_t * fIntegral
!Integral of bins used by GetRandom
Definition: TH1.h:101
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:62
tomato 1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:594
friend TH3I operator-(TH3I &h1, TH3I &h2)
Operator _.
Definition: TH3.cxx:3919
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:4541
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:49
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:3207
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:8543
const Bool_t kFALSE
Definition: RtypesCore.h:92
virtual Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:33
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:8073
friend TH3S operator/(TH3S &h1, TH3S &h2)
Operator /.
Definition: TH3.cxx:3744
TString & Remove(Ssiz_t pos)
Definition: TString.h:621
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Int_t GetSumw2N() const
Definition: TH1.h:295
Double_t GetChisquare() const
Definition: TF1.h:398
Double_t fTsumw2
Total Sum of squares of weights.
Definition: TH1.h:87
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:1197
Double_t fTsumwz2
Definition: TH3.h:38
#define ClassImp(name)
Definition: Rtypes.h:336
virtual void Copy(TObject &hnew) const
Copy this 3-D histogram structure to newth3.
Definition: TH3.cxx:3360
virtual void Reset(Option_t *option="")
Reset contents of a Profile2D histogram.
friend TH3D operator/(TH3D &h1, TH3D &h2)
Operator /.
Definition: TH3.cxx:4365
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:30
TH3D & operator=(const TH3D &h1)
Operator =.
Definition: TH3.cxx:4307
Double_t fTsumw
Total Sum of weights.
Definition: TH1.h:86
virtual void SetBinsLength(Int_t n=-1)
Set total number of bins including under/overflow Reallocate bin contents array.
Definition: TH3.cxx:4263
virtual void AddBinContent(Int_t bin)
Increment bin content by 1.
Definition: TH3.cxx:3600
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:2333
friend TH3C operator-(TH3C &h1, TH3C &h2)
Operator -.
Definition: TH3.cxx:3488
Double_t y[n]
Definition: legend1.C:17
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:572
The TH1 histogram class.
Definition: TH1.h:56
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:158
THist< 2, double, THistStatContent, THistStatUncertainty > TH2D
Definition: THist.hxx:316
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition: TAxis.cxx:809
virtual Float_t GetTitleSize() const
Definition: TAttAxis.h:43
Profile2D histograms are used to display the mean value of Z and its RMS for each cell in X...
Definition: TProfile2D.h:27
Array of doubles (64 bits per element).
Definition: TArrayD.h:27
friend TH3I operator*(Float_t c1, TH3I &h1)
Operator *.
Definition: TH3.cxx:3895
virtual void Copy(TObject &hnew) const
Copy this 3-D histogram structure to newth3.
Definition: TH3.cxx:4242
virtual void SetBinsLength(Int_t n=-1)
Set total number of bins including under/overflow Reallocate bin contents array.
Definition: TH3.cxx:4052
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:302
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:435
friend TH3C operator/(TH3C &h1, TH3C &h2)
Operator /.
Definition: TH3.cxx:3512
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
Definition: TAxis.cxx:526
TVirtualHistPainter * fPainter
!pointer to histogram painter
Definition: TH1.h:102
Double_t fTsumwxy
Definition: TH3.h:36
virtual void Copy(TObject &hnew) const
Copy this 3-D histogram structure to newth3.
Definition: TH3.cxx:3853
virtual ~TH3C()
Destructor.
Definition: TH3.cxx:3281
virtual TH3 * RebinZ(Int_t ngroup=2, const char *newname="")
Rebin only the Z axis see Rebin3D.
Definition: TH3.cxx:2684
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:97
virtual Double_t GetParameter(Int_t ipar) const
Definition: TF1.h:466
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:7163
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:200
1-Dim function class
Definition: TF1.h:150
virtual void SetBinsLength(Int_t=-1)
Definition: TH1.h:353
Char_t * fArray
Definition: TArrayC.h:30
virtual ~TH3F()
Destructor.
Definition: TH3.cxx:3973
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition: TH1.cxx:8132
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:100
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
Definition: THist.hxx:310
#define gPad
Definition: TVirtualPad.h:284
void Reset()
Definition: TArrayI.h:47
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:474
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:363
virtual void SetBinsLength(Int_t n=-1)
Set total number of bins including under/overflow Reallocate bin contents array.
Definition: TH3.cxx:3381
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
Definition: TH2.cxx:3807
TAxis fXaxis
X axis descriptor.
Definition: TH1.h:80
double result[121]
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content.
Definition: TH2.cxx:2471
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition: TAttMarker.h:31
virtual Int_t GetNbinsX() const
Definition: TH1.h:277
Double_t Sqrt(Double_t x)
Definition: TMath.h:591
virtual ~TH3()
Destructor.
Definition: TH3.cxx:148
TH3F & operator=(const TH3F &h1)
Operator =.
Definition: TH3.cxx:4096
Int_t GetNbins() const
Definition: TAxis.h:121
TH3I()
Constructor.
Definition: TH3.cxx:3764
friend TH3S operator*(Float_t c1, TH3S &h1)
Operator *.
Definition: TH3.cxx:3696
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition: TAxis.cxx:717
virtual Double_t Interpolate(Double_t x)
Not yet implemented.
Definition: TH3.cxx:1255
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:48
Double_t * fBuffer
[fBufferSize] entry buffer
Definition: TH1.h:98
const Bool_t kTRUE
Definition: RtypesCore.h:91
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:8553
virtual Double_t GetStdDev(Int_t axis=1) const
Returns the Standard Deviation (Sigma).
Definition: TH1.cxx:6817
void Set(Int_t n)
Set size of this array to n doubles.
Definition: TArrayD.cxx:105
Double_t GetXmax() const
Definition: TAxis.h:134
void Copy(TArrayD &array) const
Definition: TArrayD.h:42
const Int_t n
Definition: legend1.C:16
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Definition: TMath.h:1093
const TArrayD * GetXbins() const
Definition: TAxis.h:130
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:859
TAxis * GetXaxis()
Definition: TH1.h:300
virtual Style_t GetLabelFont() const
Definition: TAttAxis.h:39
void Copy(TArrayS &array) const
Definition: TArrayS.h:42
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:48
virtual Int_t GetNbinsY() const
Definition: TH1.h:278
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition: TH1.cxx:8175
Int_t fNcells
number of bins(1D), cells (2D) +U/Overflows
Definition: TH1.h:79
tomato 2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:290
const char * Data() const
Definition: TString.h:347
Array of chars or bytes (8 bits per element).
Definition: TArrayC.h:27
virtual TArrayD * GetBinSumw2()
Definition: TProfile2D.h:114
TH3I & operator=(const TH3I &h1)
Operator =.
Definition: TH3.cxx:3885