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