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