Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TH2.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Rene Brun 26/12/94
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 "TH2.h"
17#include "TVirtualPad.h"
18#include "TF2.h"
19#include "TProfile.h"
20#include "TRandom.h"
21#include "TMatrixFBase.h"
22#include "TMatrixDBase.h"
23#include "THLimitsFinder.h"
24#include "TError.h"
25#include "TMath.h"
26#include "TObjString.h"
27#include "TObjArray.h"
28#include "TVirtualHistPainter.h"
29#include "snprintf.h"
30
31
32/** \addtogroup Histograms
33@{
34\class TH2C
35\brief 2-D histogram with a byte per channel (see TH1 documentation)
36\class TH2S
37\brief 2-D histogram with a short per channel (see TH1 documentation)
38\class TH2I
39\brief 2-D histogram with an int per channel (see TH1 documentation)
40\class TH2L
41\brief 2-D histogram with a long64 per channel (see TH1 documentation)
42\class TH2F
43\brief 2-D histogram with a float per channel (see TH1 documentation)
44\class TH2D
45\brief 2-D histogram with a double per channel (see TH1 documentation)
46@}
47*/
48
49/** \class TH2
50 Service class for 2-D histogram classes
51
52- TH2C a 2-D histogram with one byte per cell (char). Maximum bin content = 127
53- TH2S a 2-D histogram with two bytes per cell (short integer). Maximum bin content = 32767
54- TH2I a 2-D histogram with four bytes per cell (32 bit integer). Maximum bin content = INT_MAX (\ref intmax2 "*")
55- TH2L a 2-D histogram with eight bytes per cell (64 bit integer). Maximum bin content = LLONG_MAX (\ref llongmax2 "**")
56- TH2F a 2-D histogram with four bytes per cell (float). Maximum precision 7 digits, maximum integer bin content = +/-16777216 (\ref floatmax2 "***")
57- TH2D a 2-D histogram with eight bytes per cell (double). Maximum precision 14 digits, maximum integer bin content = +/-9007199254740992 (\ref doublemax2 "****")
58
59<sup>
60\anchor intmax2 (*) 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>
61\anchor llongmax2 (**) 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>
62\anchor floatmax2 (***) 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>
63\anchor doublemax2 (****) 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)
64</sup>
65
66*/
67
68
69////////////////////////////////////////////////////////////////////////////////
70/// 2-D histogram default constructor.
71
73{
74 fDimension = 2;
75 fScalefactor = 1;
77}
78
79
80////////////////////////////////////////////////////////////////////////////////
81/// Constructor for fix bin size 2-D histograms.
82/// Creates the main histogram structure.
83///
84/// \param[in] name name of histogram (avoid blanks)
85/// \param[in] title histogram title.
86/// If title is of the form `stringt;stringx;stringy;stringz`,
87/// the histogram title is set to `stringt`,
88/// the x axis title to `stringx`, the y axis title to `stringy`, etc.
89/// \param[in] nbinsx number of bins along the X axis
90/// \param[in] xlow low edge of the X axis first bin
91/// \param[in] xup upper edge of the X axis last bin (not included in last bin)
92/// \param[in] nbinsy number of bins along the Y axis
93/// \param[in] ylow low edge of the Y axis first bin
94/// \param[in] yup upper edge of the Y axis last bin (not included in last bin)
95
96TH2::TH2(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
97 ,Int_t nbinsy,Double_t ylow,Double_t yup)
98 :TH1(name,title,nbinsx,xlow,xup)
99{
100 fDimension = 2;
101 fScalefactor = 1;
102 fTsumwy = fTsumwy2 = fTsumwxy = 0;
103 if (nbinsy <= 0) {Warning("TH2","nbinsy is <=0 - set to nbinsy = 1"); nbinsy = 1; }
104 fYaxis.Set(nbinsy,ylow,yup);
105 fNcells = fNcells*(nbinsy+2); // fNCells is set in the TH1 constructor
106}
107
108
109////////////////////////////////////////////////////////////////////////////////
110/// Constructor for variable bin size (along X axis) 2-D histograms using an input array
111/// of type double.
112///
113/// \param[in] name name of histogram (avoid blanks)
114/// \param[in] title histogram title.
115/// If title is of the form `stringt;stringx;stringy;stringz`
116/// the histogram title is set to `stringt`,
117/// the x axis title to `stringx`, the y axis title to `stringy`, etc.
118/// \param[in] nbinsx number of bins
119/// \param[in] xbins array of low-edges for each bin.
120/// This is an array of type double and size nbinsx+1
121/// \param[in] nbinsy number of bins along the Y axis
122/// \param[in] ylow low edge of the Y axis first bin
123/// \param[in] yup upper edge of the Y axis last bin (not included in last bin)
124
125TH2::TH2(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
126 ,Int_t nbinsy,Double_t ylow,Double_t yup)
127 :TH1(name,title,nbinsx,xbins)
128{
129 fDimension = 2;
130 fScalefactor = 1;
131 fTsumwy = fTsumwy2 = fTsumwxy = 0;
132 if (nbinsy <= 0) {Warning("TH2","nbinsy is <=0 - set to nbinsy = 1"); nbinsy = 1; }
133 fYaxis.Set(nbinsy,ylow,yup);
134 fNcells = fNcells*(nbinsy+2); // fNCells is set in the TH1 constructor
135}
136
137
138////////////////////////////////////////////////////////////////////////////////
139/// Constructor for Double_t variable bin size (along Y axis) 2-D histograms.
140///
141/// \param[in] name name of histogram (avoid blanks)
142/// \param[in] title histogram title.
143/// If title is of the form `stringt;stringx;stringy;stringz`
144/// the histogram title is set to `stringt`,
145/// the x axis title to `stringx`, the y axis title to `stringy`, etc.
146/// \param[in] nbinsx number of bins along the X axis
147/// \param[in] xlow low edge of the X axis first bin
148/// \param[in] xup upper edge of the X axis last bin (not included in last bin)
149/// \param[in] nbinsy number of bins
150/// \param[in] ybins array of low-edges for each bin.
151/// This is an array of type double and size nbinsy+1
152
153TH2::TH2(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
154 ,Int_t nbinsy,const Double_t *ybins)
155 :TH1(name,title,nbinsx,xlow,xup)
156{
157 fDimension = 2;
158 fScalefactor = 1;
159 fTsumwy = fTsumwy2 = fTsumwxy = 0;
160 if (nbinsy <= 0) {Warning("TH2","nbinsy is <=0 - set to nbinsy = 1"); nbinsy = 1; }
162 else fYaxis.Set(nbinsy,0,1);
163 fNcells = fNcells*(nbinsy+2); // fNCells is set in the TH1 constructor
164}
165
166
167////////////////////////////////////////////////////////////////////////////////
168/// Constructor for Double_t variable bin size 2-D histograms.
169///
170/// \param[in] name name of histogram (avoid blanks)
171/// \param[in] title histogram title.
172/// If title is of the form `stringt;stringx;stringy;stringz`
173/// the histogram title is set to `stringt`,
174/// the x axis title to `stringx`, the y axis title to `stringy`, etc.
175/// \param[in] nbinsx number of bins
176/// \param[in] xbins array of low-edges for each bin.
177/// This is an array of type double and size nbinsx+1
178/// \param[in] nbinsy number of bins
179/// \param[in] ybins array of low-edges for each bin.
180/// This is an array of type double and size nbinsy+1
181
182TH2::TH2(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
183 ,Int_t nbinsy,const Double_t *ybins)
184 :TH1(name,title,nbinsx,xbins)
185{
186 fDimension = 2;
187 fScalefactor = 1;
188 fTsumwy = fTsumwy2 = fTsumwxy = 0;
189 if (nbinsy <= 0) {Warning("TH2","nbinsy is <=0 - set to nbinsy = 1"); nbinsy = 1; }
191 else fYaxis.Set(nbinsy,0,1);
192 fNcells = fNcells*(nbinsy+2); // fNCells is set in the TH1 constructor
193}
194
195
196////////////////////////////////////////////////////////////////////////////////
197/// Constructor for variable bin size (along X and Y axis) 2-D histograms using input
198/// arrays of type float.
199///
200/// \param[in] name name of histogram (avoid blanks)
201/// \param[in] title histogram title.
202/// If title is of the form `stringt;stringx;stringy;stringz`
203/// the histogram title is set to `stringt`,
204/// the x axis title to `stringx`, the y axis title to `stringy`, etc.
205/// \param[in] nbinsx number of bins
206/// \param[in] xbins array of low-edges for each bin.
207/// This is an array of type float and size nbinsx+1
208/// \param[in] nbinsy number of bins
209/// \param[in] ybins array of low-edges for each bin.
210/// This is an array of type float and size nbinsy+1
211
212TH2::TH2(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
213 ,Int_t nbinsy,const Float_t *ybins)
214 :TH1(name,title,nbinsx,xbins)
215{
216 fDimension = 2;
217 fScalefactor = 1;
218 fTsumwy = fTsumwy2 = fTsumwxy = 0;
219 if (nbinsy <= 0) {Warning("TH2","nbinsy is <=0 - set to nbinsy = 1"); nbinsy = 1; }
221 else fYaxis.Set(nbinsy,0,1);
222 fNcells = fNcells*(nbinsy+2); // fNCells is set in the TH1 constructor.
223}
224
225
226////////////////////////////////////////////////////////////////////////////////
227/// Destructor.
228
230{
231}
232
233////////////////////////////////////////////////////////////////////////////////
234/// Fill histogram with all entries in the buffer.
235/// - action = -1 histogram is reset and refilled from the buffer (called by THistPainter::Paint)
236/// - action = 0 histogram is filled from the buffer
237/// - action = 1 histogram is filled and buffer is deleted
238/// The buffer is automatically deleted when the number of entries
239/// in the buffer is greater than the number of entries in the histogram
240
242{
243 // do we need to compute the bin size?
244 if (!fBuffer) return 0;
246
247 // nbentries correspond to the number of entries of histogram
248
249 if (nbentries == 0) return 0;
250 if (nbentries < 0 && action == 0) return 0; // case histogram has been already filled from the buffer
251
252 Double_t *buffer = fBuffer;
253 if (nbentries < 0) {
255 // a reset might call BufferEmpty() giving an infinite loop
256 // Protect it by setting fBuffer = 0
257 fBuffer=nullptr;
258 //do not reset the list of functions
259 Reset("ICES");
260 fBuffer = buffer;
261 }
262
264 //find min, max of entries in buffer
265 Double_t xmin = fBuffer[2];
267 Double_t ymin = fBuffer[3];
269 for (Int_t i=1;i<nbentries;i++) {
270 Double_t x = fBuffer[3*i+2];
271 if (x < xmin) xmin = x;
272 if (x > xmax) xmax = x;
273 Double_t y = fBuffer[3*i+3];
274 if (y < ymin) ymin = y;
275 if (y > ymax) ymax = y;
276 }
277 if (fXaxis.GetXmax() <= fXaxis.GetXmin() || fYaxis.GetXmax() <= fYaxis.GetXmin()) {
278 THLimitsFinder::GetLimitsFinder()->FindGoodLimits(this,xmin,xmax,ymin,ymax);
279 } else {
280 fBuffer = nullptr;
286 fBuffer = buffer;
288 }
289 }
290
291 fBuffer = nullptr;
292 for (Int_t i=0;i<nbentries;i++) {
293 Fill(buffer[3*i+2],buffer[3*i+3],buffer[3*i+1]);
294 }
295 fBuffer = buffer;
296
297 if (action > 0) { delete [] fBuffer; fBuffer = nullptr; fBufferSize = 0;}
298 else {
300 else fBuffer[0] = 0;
301 }
302 return nbentries;
303}
304
305
306////////////////////////////////////////////////////////////////////////////////
307/// accumulate arguments in buffer. When buffer is full, empty the buffer
308/// ~~~ {.cpp}
309/// fBuffer[0] = number of entries in buffer
310/// fBuffer[1] = w of first entry
311/// fBuffer[2] = x of first entry
312/// fBuffer[3] = y of first entry
313/// ~~~
314
316{
317 if (!fBuffer) return -3;
319 if (nbentries < 0) {
321 fBuffer[0] = nbentries;
322 if (fEntries > 0) {
323 Double_t *buffer = fBuffer; fBuffer=nullptr;
324 Reset("ICES");
325 fBuffer = buffer;
326 }
327 }
328 if (3*nbentries+3 >= fBufferSize) {
329 BufferEmpty(1);
330 return Fill(x,y,w);
331 }
332 fBuffer[3*nbentries+1] = w;
333 fBuffer[3*nbentries+2] = x;
334 fBuffer[3*nbentries+3] = y;
335 fBuffer[0] += 1;
336 return -3;
337}
338
339
340////////////////////////////////////////////////////////////////////////////////
341/// Copy.
342
343void TH2::Copy(TObject &obj) const
344{
345 TH1::Copy(obj);
346 ((TH2&)obj).fScalefactor = fScalefactor;
347 ((TH2&)obj).fTsumwy = fTsumwy;
348 ((TH2&)obj).fTsumwy2 = fTsumwy2;
349 ((TH2&)obj).fTsumwxy = fTsumwxy;
350}
351
352
353////////////////////////////////////////////////////////////////////////////////
354/// Invalid Fill method.
355
357{
358 Error("Fill", "Invalid signature - do nothing");
359 return -1;
360}
361
362
363////////////////////////////////////////////////////////////////////////////////
364/// Increment cell defined by x,y by 1.
365///
366/// - if x or/and y is less than the low-edge of the corresponding axis first bin,
367/// the Underflow cell is incremented.
368/// - if x or/and y is equal to or greater than the upper edge of corresponding axis last bin,
369/// the Overflow cell is incremented.
370///
371/// - If the storage of the sum of squares of weights has been triggered,
372/// via the function Sumw2, then the sum of the squares of weights is incremented
373/// by 1 in the cell corresponding to x,y.
374///
375/// The function returns the corresponding global bin number which has its content
376/// incremented by 1
377
379{
380 if (fBuffer) return BufferFill(x,y,1);
381
382 Int_t binx, biny, bin;
383 fEntries++;
384 binx = fXaxis.FindBin(x);
385 biny = fYaxis.FindBin(y);
386 if (binx <0 || biny <0) return -1;
387 bin = biny*(fXaxis.GetNbins()+2) + binx;
388 AddBinContent(bin);
389 if (fSumw2.fN) ++fSumw2.fArray[bin];
390 if (binx == 0 || binx > fXaxis.GetNbins()) {
391 if (!GetStatOverflowsBehaviour()) return -1;
392 }
393 if (biny == 0 || biny > fYaxis.GetNbins()) {
394 if (!GetStatOverflowsBehaviour()) return -1;
395 }
396 ++fTsumw;
397 ++fTsumw2;
398 fTsumwx += x;
399 fTsumwx2 += x*x;
400 fTsumwy += y;
401 fTsumwy2 += y*y;
402 fTsumwxy += x*y;
403 return bin;
404}
405
406
407////////////////////////////////////////////////////////////////////////////////
408/// Increment cell defined by x,y by a weight w.
409///
410/// - if x or/and y is less than the low-edge of the corresponding axis first bin,
411/// the Underflow cell is incremented.
412/// - if x or/and y is equal to or greater than the upper edge of corresponding axis last bin,
413/// the Overflow cell is incremented.
414///
415/// - If the weight is not equal to 1, the storage of the sum of squares of
416/// weights is automatically triggered and the sum of the squares of weights is incremented
417/// by w^2 in the bin corresponding to x,y
418///
419/// The function returns the corresponding global bin number which has its content
420/// incremented by w
421
423{
424 if (fBuffer) return BufferFill(x,y,w);
425
426 Int_t binx, biny, bin;
427 fEntries++;
428 binx = fXaxis.FindBin(x);
429 biny = fYaxis.FindBin(y);
430 if (binx <0 || biny <0) return -1;
431 bin = biny*(fXaxis.GetNbins()+2) + binx;
432 if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before AddBinContent
433 if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
434 AddBinContent(bin,w);
435 if (binx == 0 || binx > fXaxis.GetNbins()) {
436 if (!GetStatOverflowsBehaviour()) return -1;
437 }
438 if (biny == 0 || biny > fYaxis.GetNbins()) {
439 if (!GetStatOverflowsBehaviour()) return -1;
440 }
441 Double_t z= w;
442 fTsumw += z;
443 fTsumw2 += z*z;
444 fTsumwx += z*x;
445 fTsumwx2 += z*x*x;
446 fTsumwy += z*y;
447 fTsumwy2 += z*y*y;
448 fTsumwxy += z*x*y;
449 return bin;
450}
451
452
453////////////////////////////////////////////////////////////////////////////////
454/// Increment cell defined by namex,namey by a weight w
455///
456/// - if x or/and y is less than the low-edge of the corresponding axis first bin,
457/// the Underflow cell is incremented.
458/// - if x or/and y is equal to or greater than the upper edge of corresponding axis last bin,
459/// the Overflow cell is incremented.
460///
461/// - If the weight is not equal to 1, the storage of the sum of squares of
462/// weights is automatically triggered and the sum of the squares of weights is incremented
463/// by w^2 in the bin corresponding to namex,namey
464///
465/// The function returns the corresponding global bin number which has its content
466/// incremented by w
467
468Int_t TH2::Fill(const char *namex, const char *namey, Double_t w)
469{
470 Int_t binx, biny, bin;
471 fEntries++;
474 if (binx <0 || biny <0) return -1;
475 bin = biny*(fXaxis.GetNbins()+2) + binx;
476 if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before AddBinContent
477 if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
478 AddBinContent(bin,w);
479 if (binx == 0 || binx > fXaxis.GetNbins()) return -1;
480 if (biny == 0 || biny > fYaxis.GetNbins()) return -1;
481
482 Double_t z= w;
483 fTsumw += z;
484 fTsumw2 += z*z;
485 // skip computation of the statistics along axis that have labels (can be extended and are alphanumeric)
490 fTsumwx += z * x;
491 fTsumwx2 += z * x * x;
492 fTsumwy += z * y;
493 fTsumwy2 += z * y * y;
494 fTsumwxy += z * x * y;
495 }
496 return bin;
497}
498
499
500////////////////////////////////////////////////////////////////////////////////
501/// Increment cell defined by namex,y by a weight w
502///
503/// - if x or/and y is less than the low-edge of the corresponding axis first bin,
504/// the Underflow cell is incremented.
505/// - if x or/and y is equal to or greater than the upper edge of corresponding axis last bin,
506/// the Overflow cell is incremented.
507///
508/// - If the weight is not equal to 1, the storage of the sum of squares of
509/// weights is automatically triggered and the sum of the squares of weights is incremented
510/// by w^2 in the bin corresponding to namex,y
511///
512/// The function returns the corresponding global bin number which has its content
513/// incremented by w
514
516{
517 Int_t binx, biny, bin;
518 fEntries++;
520 biny = fYaxis.FindBin(y);
521 if (binx <0 || biny <0) return -1;
522 bin = biny*(fXaxis.GetNbins()+2) + binx;
523 if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before AddBinContent
524 if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
525 AddBinContent(bin,w);
526 if (binx == 0 || binx > fXaxis.GetNbins()) return -1;
527 if (biny == 0 || biny > fYaxis.GetNbins()) {
528 if (!GetStatOverflowsBehaviour()) return -1;
529 }
530 Double_t z= w; //(w > 0 ? w : -w);
531 fTsumw += z;
532 fTsumw2 += z*z;
533 fTsumwy += z*y;
534 fTsumwy2 += z*y*y;
535 // skip statistics along x axis, for only one axis no need to use bit mask from GetAxisLabelStatus
536 if (!fXaxis.CanExtend() || !fXaxis.IsAlphanumeric()) {
538 fTsumwx += z * x;
539 fTsumwx2 += z * x * x;
540 fTsumwxy += z * x * y;
541 }
542 return bin;
543}
544
545
546////////////////////////////////////////////////////////////////////////////////
547/// Increment cell defined by x,namey by a weight w
548///
549/// - if x or/and y is less than the low-edge of the corresponding axis first bin,
550/// the Underflow cell is incremented.
551/// - if x or/and y is equal to or greater than the upper edge of corresponding axis last bin,
552/// the Overflow cell is incremented.
553///
554/// - If the weight is not equal to 1, the storage of the sum of squares of
555/// weights is automatically triggered and the sum of the squares of weights is incremented
556/// by w^2 in the bin corresponding to x,y.
557///
558/// The function returns the corresponding global bin number which has its content
559/// incremented by w
560
562{
563 Int_t binx, biny, bin;
564 fEntries++;
565 binx = fXaxis.FindBin(x);
567 if (binx <0 || biny <0) return -1;
568 bin = biny*(fXaxis.GetNbins()+2) + binx;
569 if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2(); // must be called before AddBinContent
570 if (fSumw2.fN) fSumw2.fArray[bin] += w*w;
571 AddBinContent(bin,w);
572 if (binx == 0 || binx > fXaxis.GetNbins()) {
573 if (!GetStatOverflowsBehaviour()) return -1;
574 }
575 if (biny == 0 || biny > fYaxis.GetNbins()) return -1;
576
577 Double_t z= w; //(w > 0 ? w : -w);
578 fTsumw += z;
579 fTsumw2 += z*z;
580 fTsumwx += z*x;
581 fTsumwx2 += z*x*x;
582 // skip statistics along y axis
583 if (!fYaxis.CanExtend() || !fYaxis.IsAlphanumeric()) {
585 fTsumwy += z * y;
586 fTsumwy2 += z * y * y;
587 fTsumwxy += z * x * y;
588 }
589 return bin;
590}
591
592
593////////////////////////////////////////////////////////////////////////////////
594/// Fill a 2-D histogram with an array of values and weights.
595///
596/// - ntimes: number of entries in arrays x and w (array size must be ntimes*stride)
597/// - x: array of x values to be histogrammed
598/// - y: array of y values to be histogrammed
599/// - w: array of weights
600/// - stride: step size through arrays x, y and w
601///
602/// - If the weight is not equal to 1, the storage of the sum of squares of
603/// weights is automatically triggered and the sum of the squares of weights is incremented
604/// by w[i]^2 in the bin corresponding to x[i],y[i].
605/// - If w is NULL each entry is assumed a weight=1
606///
607/// NB: function only valid for a TH2x object
608
610{
611 Int_t binx, biny, bin, i;
612 ntimes *= stride;
613 Int_t ifirst = 0;
614
615 //If a buffer is activated, fill buffer
616 // (note that this function must not be called from TH2::BufferEmpty)
617 if (fBuffer) {
618 for (i=0;i<ntimes;i+=stride) {
619 if (!fBuffer) break; // buffer can be deleted in BufferFill when is empty
620 if (w) BufferFill(x[i],y[i],w[i]);
621 else BufferFill(x[i], y[i], 1.);
622 }
623 // fill the remaining entries if the buffer has been deleted
624 if (i < ntimes && fBuffer==nullptr)
625 ifirst = i;
626 else
627 return;
628 }
629
630 Double_t ww = 1;
631 for (i=ifirst;i<ntimes;i+=stride) {
632 fEntries++;
633 binx = fXaxis.FindBin(x[i]);
634 biny = fYaxis.FindBin(y[i]);
635 if (binx <0 || biny <0) continue;
636 bin = biny*(fXaxis.GetNbins()+2) + binx;
637 if (w) ww = w[i];
638 if (!fSumw2.fN && ww != 1.0 && !TestBit(TH1::kIsNotW)) Sumw2();
639 if (fSumw2.fN) fSumw2.fArray[bin] += ww*ww;
640 AddBinContent(bin,ww);
641 if (binx == 0 || binx > fXaxis.GetNbins()) {
642 if (!GetStatOverflowsBehaviour()) continue;
643 }
644 if (biny == 0 || biny > fYaxis.GetNbins()) {
645 if (!GetStatOverflowsBehaviour()) continue;
646 }
647 Double_t z= ww; //(ww > 0 ? ww : -ww);
648 fTsumw += z;
649 fTsumw2 += z*z;
650 fTsumwx += z*x[i];
651 fTsumwx2 += z*x[i]*x[i];
652 fTsumwy += z*y[i];
653 fTsumwy2 += z*y[i]*y[i];
654 fTsumwxy += z*x[i]*y[i];
655 }
656}
657
658
659////////////////////////////////////////////////////////////////////////////////
660/// Fill histogram following distribution in function fname.
661///
662/// @param fname : Function name used for filling the histogram
663/// @param ntimes : number of times the histogram is filled
664/// @param rng : (optional) Random number generator used to sample
665///
666/// The distribution contained in the function fname (TF2) is integrated
667/// over the channel contents.
668/// It is normalized to 1.
669/// Getting one random number implies:
670/// - Generating a random number between 0 and 1 (say r1)
671/// - Look in which bin in the normalized integral r1 corresponds to
672/// - Fill histogram channel
673/// ntimes random numbers are generated
674///
675/// One can also call TF2::GetRandom2 to get a random variate from a function.
676
678{
679 Int_t bin, binx, biny, ibin, loop;
680 Double_t r1, x, y;
681 TF2 * f1 = dynamic_cast<TF2*>(fobj);
682 if (!f1) { Error("FillRandom", "Function: %s is not a TF2, is a %s",fobj->GetName(),fobj->IsA()->GetName()); return; }
683
684
685 TAxis & xAxis = fXaxis;
686 TAxis & yAxis = fYaxis;
687
688 // in case axes of histogram are not defined use the function axis
689 if (fXaxis.GetXmax() <= fXaxis.GetXmin() || fYaxis.GetXmax() <= fYaxis.GetXmin()) {
692 Info("FillRandom","Using function axis and range ([%g,%g],[%g,%g])",xmin, xmax,ymin,ymax);
693 xAxis = *(f1->GetHistogram()->GetXaxis());
694 yAxis = *(f1->GetHistogram()->GetYaxis());
695 }
696
697
698 // Allocate temporary space to store the integral and compute integral
699 Int_t nbinsx = xAxis.GetNbins();
700 Int_t nbinsy = yAxis.GetNbins();
701 Int_t nbins = nbinsx*nbinsy;
702
703
704 Double_t *integral = new Double_t[nbins+1];
705 ibin = 0;
706 integral[ibin] = 0;
707 for (biny=1;biny<=nbinsy;biny++) {
708 for (binx=1;binx<=nbinsx;binx++) {
709 ibin++;
710 Double_t fint = f1->Integral(xAxis.GetBinLowEdge(binx), xAxis.GetBinUpEdge(binx), yAxis.GetBinLowEdge(biny), yAxis.GetBinUpEdge(biny));
711 integral[ibin] = integral[ibin-1] + fint;
712 }
713 }
714
715 // Normalize integral to 1
716 if (integral[nbins] == 0 ) {
717 delete [] integral;
718 Error("FillRandom", "Integral = zero"); return;
719 }
720 for (bin=1;bin<=nbins;bin++) integral[bin] /= integral[nbins];
721
722 // Start main loop ntimes
723 for (loop=0;loop<ntimes;loop++) {
724 r1 = (rng) ? rng->Rndm() : gRandom->Rndm();
725 ibin = TMath::BinarySearch(nbins,&integral[0],r1);
726 biny = ibin/nbinsx;
727 binx = 1 + ibin - nbinsx*biny;
728 biny++;
729 x = xAxis.GetBinCenter(binx);
730 y = yAxis.GetBinCenter(biny);
731 Fill(x,y);
732 }
733 delete [] integral;
734}
735
736
737////////////////////////////////////////////////////////////////////////////////
738/// Fill histogram following distribution in histogram h.
739///
740/// @param h : Histogram pointer used for sampling random number
741/// @param ntimes : number of times the histogram is filled
742/// @param rng : (optional) Random number generator used for sampling
743///
744/// The distribution contained in the histogram h (TH2) is integrated
745/// over the channel contents.
746/// It is normalized to 1.
747/// Getting one random number implies:
748/// - Generating a random number between 0 and 1 (say r1)
749/// - Look in which bin in the normalized integral r1 corresponds to
750/// - Fill histogram channel
751/// ntimes random numbers are generated
752
754{
755 if (!h) { Error("FillRandom", "Null histogram"); return; }
756 if (fDimension != h->GetDimension()) {
757 Error("FillRandom", "Histograms with different dimensions"); return;
758 }
759
760 if (h->ComputeIntegral() == 0) return;
761
762 Int_t loop;
763 Double_t x,y;
764 TH2 *h2 = (TH2*)h;
765 for (loop=0;loop<ntimes;loop++) {
766 h2->GetRandom2(x,y,rng);
767 Fill(x,y);
768 }
769}
770
771
772////////////////////////////////////////////////////////////////////////////////
773
776{
779
780 Int_t nbins = outerAxis.GetNbins();
781 // get correct first last bins for outer axis
782 // when using default values (0,-1) check if an axis range is set in outer axis
783 // do same as in DoProjection for inner axis
784 if ( lastbin < firstbin && outerAxis.TestBit(TAxis::kAxisRange) ) {
785 firstbin = outerAxis.GetFirst();
786 lastbin = outerAxis.GetLast();
787 // For special case of TAxis::SetRange, when first == 1 and last
788 // = N and the range bit has been set, the TAxis will return 0
789 // for both.
790 if (firstbin == 0 && lastbin == 0) {
791 firstbin = 1;
792 lastbin = nbins;
793 }
794 }
795 if (firstbin < 0) firstbin = 0;
796 if (lastbin < 0 || lastbin > nbins + 1) lastbin = nbins + 1;
797 if (lastbin < firstbin) {firstbin = 0; lastbin = nbins + 1;}
798
799
800 TString opt = option;
801 TString proj_opt = "e";
802 Int_t i1 = opt.Index("[");
803 Int_t i2 = opt.Index("]");
804 if (i1>=0 && i2>i1) {
805 proj_opt += opt(i1,i2-i1+1);
806 opt.Remove(i1, i2-i1+1);
807 }
808 opt.ToLower();
809 Int_t ngroup = 1;
810 if (opt.Contains("g2")) {ngroup = 2; opt.ReplaceAll("g2","");}
811 if (opt.Contains("g3")) {ngroup = 3; opt.ReplaceAll("g3","");}
812 if (opt.Contains("g4")) {ngroup = 4; opt.ReplaceAll("g4","");}
813 if (opt.Contains("g5")) {ngroup = 5; opt.ReplaceAll("g5","");}
814
815 // implement option S sliding merge for each bin using in conjunction with a given Gn
817 if (opt.Contains("s")) nstep = 1;
818
819 //default is to fit with a gaussian
820 if (f1 == nullptr) {
821 f1 = (TF1*)gROOT->GetFunction("gaus");
822 if (f1 == nullptr) f1 = new TF1("gaus","gaus",innerAxis.GetXmin(),innerAxis.GetXmax());
823 else f1->SetRange(innerAxis.GetXmin(),innerAxis.GetXmax());
824 }
825 Int_t npar = f1->GetNpar();
826 if (npar <= 0) return;
829
830 if (arr) {
831 arr->SetOwner();
832 arr->Expand(npar + 1);
833 }
834
835 //Create one histogram for each function parameter
836 Int_t ipar;
837 TH1D **hlist = new TH1D*[npar];
838 char *name = new char[2000];
839 char *title = new char[2000];
840 const TArrayD *bins = outerAxis.GetXbins();
841 // outer axis boundaries used for creating reported histograms are different
842 // than the limits used in the projection loop (firstbin,lastbin)
843 Int_t firstOutBin = outerAxis.TestBit(TAxis::kAxisRange) ? std::max(firstbin,1) : 1;
844 Int_t lastOutBin = outerAxis.TestBit(TAxis::kAxisRange) ? std::min(lastbin,outerAxis.GetNbins() ) : outerAxis.GetNbins();
846 // merge bins if use nstep > 1 and fixed bins
847 if (bins->fN == 0) nOutBins /= nstep;
848 for (ipar=0;ipar<npar;ipar++) {
849 snprintf(name,2000,"%s_%d",GetName(),ipar);
850 snprintf(title,2000,"Fitted value of par[%d]=%s",ipar,f1->GetParName(ipar));
851 delete gDirectory->FindObject(name);
852 if (bins->fN == 0) {
853 hlist[ipar] = new TH1D(name,title, nOutBins, outerAxis.GetBinLowEdge(firstOutBin), outerAxis.GetBinUpEdge(lastOutBin));
854 } else {
855 hlist[ipar] = new TH1D(name,title, nOutBins, &bins->fArray[firstOutBin-1]);
856 }
857 hlist[ipar]->GetXaxis()->SetTitle(outerAxis.GetTitle());
858 if (arr)
859 (*arr)[ipar] = hlist[ipar];
860 }
861 snprintf(name,2000,"%s_chi2",GetName());
862 delete gDirectory->FindObject(name);
863 TH1D *hchi2 = nullptr;
864 if (bins->fN == 0) {
865 hchi2 = new TH1D(name,"chisquare", nOutBins, outerAxis.GetBinLowEdge(firstOutBin), outerAxis.GetBinUpEdge(lastOutBin));
866 } else {
867 hchi2 = new TH1D(name,"chisquare", nOutBins, &bins->fArray[firstOutBin-1]);
868 }
869 hchi2->GetXaxis()->SetTitle(outerAxis.GetTitle());
870 if (arr)
871 (*arr)[npar] = hchi2;
872
873 //Loop on all bins in Y, generate a projection along X
874 Int_t bin;
875 // in case of sliding merge nstep=1, i.e. do slices starting for every bin
876 // now do not slices case with overflow (makes more sense)
877 // when fitting add the option "N". We don;t want to display and store the function
878 // for the temporary histograms that are created and fitted
879 opt += " n ";
880 TH1D *hp = nullptr;
881 for (bin=firstbin;bin+ngroup-1<=lastbin;bin += nstep) {
882 if (onX)
883 hp= ProjectionX("_temp",bin,bin+ngroup-1,proj_opt);
884 else
885 hp= ProjectionY("_temp",bin,bin+ngroup-1,proj_opt);
886 if (hp == nullptr) continue;
887 // nentries can be the effective entries and it could be a very small number but not zero!
888 Double_t nentries = hp->GetEntries();
889 if ( nentries <= 0 || nentries < cut) {
890 if (!opt.Contains("q"))
891 Info("DoFitSlices","Slice %d skipped, the number of entries is zero or smaller than the given cut value, n=%f",bin,nentries);
892 continue;
893 }
895 Int_t binOn = hlist[0]->FindBin(outerAxis.GetBinCenter(bin+ngroup/2));
896 if (!opt.Contains("q"))
897 Info("DoFitSlices","Slice fit %d (%f,%f)",binOn,hlist[0]->GetXaxis()->GetBinLowEdge(binOn),hlist[0]->GetXaxis()->GetBinUpEdge(binOn));
898 hp->Fit(f1,opt.Data());
900 if (npfits > npar && npfits >= cut) {
901 for (ipar=0;ipar<npar;ipar++) {
902 hlist[ipar]->SetBinContent(binOn,f1->GetParameter(ipar));
903 hlist[ipar]->SetBinError(binOn,f1->GetParError(ipar));
904 }
905 hchi2->SetBinContent(binOn,f1->GetChisquare()/(npfits-npar));
906 }
907 else {
908 if (!opt.Contains("q"))
909 Info("DoFitSlices","Fitted slice %d skipped, the number of fitted points is too small, n=%d",bin,npfits);
910 }
911 // don't need to delete hp. If histogram has the same name it is re-used in TH2::Projection
912 }
913 delete hp;
914 delete [] parsave;
915 delete [] name;
916 delete [] title;
917 delete [] hlist;
918}
919
920
921////////////////////////////////////////////////////////////////////////////////
922/// Project slices along X in case of a 2-D histogram, then fit each slice
923/// with function f1 and make a histogram for each fit parameter
924/// Only bins along Y between firstybin and lastybin are considered.
925/// By default (firstybin == 0, lastybin == -1), all bins in y including
926/// over- and underflows are taken into account.
927/// If f1=0, a gaussian is assumed
928/// Before invoking this function, one can set a subrange to be fitted along X
929/// via f1->SetRange(xmin,xmax)
930/// The argument option (default="QNR") can be used to change the fit options.
931/// - "Q" means Quiet mode
932/// - "N" means do not show the result of the fit
933/// - "R" means fit the function in the specified function range
934/// - "G2" merge 2 consecutive bins along X
935/// - "G3" merge 3 consecutive bins along X
936/// - "G4" merge 4 consecutive bins along X
937/// - "G5" merge 5 consecutive bins along X
938/// - "S" sliding merge: merge n consecutive bins along X accordingly to what Gn is given.
939/// It makes sense when used together with a Gn option
940///
941/// The generated histograms are returned by adding them to arr, if arr is not NULL.
942/// arr's SetOwner() is called, to signal that it is the user's responsibility to
943/// delete the histograms, possibly by deleting the array.
944/// ~~~ {.cpp}
945/// TObjArray aSlices;
946/// h2->FitSlicesX(func, 0, -1, 0, "QNR", &aSlices);
947/// ~~~
948/// will already delete the histograms once aSlice goes out of scope. aSlices will
949/// contain the histogram for the i-th parameter of the fit function at aSlices[i];
950/// aSlices[n] (n being the number of parameters) contains the chi2 distribution of
951/// the fits.
952///
953/// If arr is NULL, the generated histograms are added to the list of objects
954/// in the current directory. It is the user's responsibility to delete
955/// these histograms.
956///
957/// Example: Assume a 2-d histogram h2
958/// ~~~ {.cpp}
959/// Root > h2->FitSlicesX(); produces 4 TH1D histograms
960/// with h2_0 containing parameter 0(Constant) for a Gaus fit
961/// of each bin in Y projected along X
962/// with h2_1 containing parameter 1(Mean) for a gaus fit
963/// with h2_2 containing parameter 2(StdDev) for a gaus fit
964/// with h2_chi2 containing the chisquare/number of degrees of freedom for a gaus fit
965///
966/// Root > h2->FitSlicesX(0,15,22,10);
967/// same as above, but only for bins 15 to 22 along Y
968/// and only for bins in Y for which the corresponding projection
969/// along X has more than cut bins filled.
970/// ~~~
971/// NOTE: To access the generated histograms in the current directory, do eg:
972/// ~~~ {.cpp}
973/// TH1D *h2_1 = (TH1D*)gDirectory->Get("h2_1");
974/// ~~~
975
981
982
983////////////////////////////////////////////////////////////////////////////////
984/// Project slices along Y in case of a 2-D histogram, then fit each slice
985/// with function f1 and make a histogram for each fit parameter
986/// Only bins along X between firstxbin and lastxbin are considered.
987/// By default (firstxbin == 0, lastxbin == -1), all bins in x including
988/// over- and underflows are taken into account.
989/// If f1=0, a gaussian is assumed
990/// Before invoking this function, one can set a subrange to be fitted along Y
991/// via f1->SetRange(ymin,ymax)
992/// The argument option (default="QNR") can be used to change the fit options.
993/// - "Q" means Quiet mode
994/// - "N" means do not show the result of the fit
995/// - "R" means fit the function in the specified function range
996/// - "G2" merge 2 consecutive bins along Y
997/// - "G3" merge 3 consecutive bins along Y
998/// - "G4" merge 4 consecutive bins along Y
999/// - "G5" merge 5 consecutive bins along Y
1000/// - "S" sliding merge: merge n consecutive bins along Y accordingly to what Gn is given.
1001/// It makes sense when used together with a Gn option
1002///
1003/// The generated histograms are returned by adding them to arr, if arr is not NULL.
1004/// arr's SetOwner() is called, to signal that it is the user's responsibility to
1005/// delete the histograms, possibly by deleting the array.
1006/// ~~~ {.cpp}
1007/// TObjArray aSlices;
1008/// h2->FitSlicesY(func, 0, -1, 0, "QNR", &aSlices);
1009/// ~~~
1010/// will already delete the histograms once aSlice goes out of scope. aSlices will
1011/// contain the histogram for the i-th parameter of the fit function at aSlices[i];
1012/// aSlices[n] (n being the number of parameters) contains the chi2 distribution of
1013/// the fits.
1014///
1015/// If arr is NULL, the generated histograms are added to the list of objects
1016/// in the current directory. It is the user's responsibility to delete
1017/// these histograms.
1018///
1019/// Example: Assume a 2-d histogram h2
1020/// ~~~ {.cpp}
1021/// Root > h2->FitSlicesY(); produces 4 TH1D histograms
1022/// with h2_0 containing parameter 0(Constant) for a Gaus fit
1023/// of each bin in X projected along Y
1024/// with h2_1 containing parameter 1(Mean) for a gaus fit
1025/// with h2_2 containing parameter 2(StdDev) for a gaus fit
1026/// with h2_chi2 containing the chisquare/number of degrees of freedom for a gaus fit
1027///
1028/// Root > h2->FitSlicesY(0,15,22,10);
1029/// same as above, but only for bins 15 to 22 along X
1030/// and only for bins in X for which the corresponding projection
1031/// along Y has more than cut bins filled.
1032/// ~~~
1033///
1034/// NOTE: To access the generated histograms in the current directory, do eg:
1035/// ~~~ {.cpp}
1036/// TH1D *h2_1 = (TH1D*)gDirectory->Get("h2_1");
1037/// ~~~
1038///
1039/// A complete example of this function is given in tutorial:fitslicesy.C.
1040
1045
1047{
1048 // See comments in TH1::GetBin
1049 Int_t ofy = fYaxis.GetNbins() + 1; // overflow bin
1050 if (biny < 0) biny = 0;
1051 if (biny > ofy) biny = ofy;
1052
1053 return TH1::GetBin(binx) + (fXaxis.GetNbins() + 2) * biny;
1054}
1055
1056
1057////////////////////////////////////////////////////////////////////////////////
1058/// compute first cell (binx,biny) in the range [firstxbin,lastxbin][firstybin,lastybin] for which
1059/// diff = abs(cell_content-c) <= maxdiff
1060/// In case several cells in the specified range with diff=0 are found
1061/// the first cell found is returned in binx,biny.
1062/// In case several cells in the specified range satisfy diff <=maxdiff
1063/// the cell with the smallest difference is returned in binx,biny.
1064/// In all cases the function returns the smallest difference.
1065///
1066/// NOTE1: if firstxbin < 0, firstxbin is set to 1
1067/// if (lastxbin < firstxbin then lastxbin is set to the number of bins in X
1068/// ie if firstxbin=1 and lastxbin=0 (default) the search is on all bins in X except
1069/// for X's under- and overflow bins.
1070/// if firstybin < 0, firstybin is set to 1
1071/// if (lastybin < firstybin then lastybin is set to the number of bins in Y
1072/// ie if firstybin=1 and lastybin=0 (default) the search is on all bins in Y except
1073/// for Y's under- and overflow bins.
1074///
1075/// NOTE2: if maxdiff=0 (default), the first cell with content=c is returned.
1076
1079{
1080 if (fDimension != 2) {
1081 binx = -1;
1082 biny = -1;
1083 Error("GetBinWithContent2","function is only valid for 2-D histograms");
1084 return 0;
1085 }
1086 if (firstxbin < 0) firstxbin = 1;
1088 if (firstybin < 0) firstybin = 1;
1090 Double_t diff, curmax = 1.e240;
1091 for (Int_t j = firstybin; j <= lastybin; j++) {
1092 for (Int_t i = firstxbin; i <= lastxbin; i++) {
1094 if (diff <= 0) {binx = i; biny=j; return diff;}
1095 if (diff < curmax && diff <= maxdiff) {curmax = diff, binx=i; biny=j;}
1096 }
1097 }
1098 return curmax;
1099}
1100
1101
1102////////////////////////////////////////////////////////////////////////////////
1103/// Return correlation factor between axis1 and axis2.
1104
1106{
1107 if (axis1 < 1 || axis2 < 1 || axis1 > 2 || axis2 > 2) {
1108 Error("GetCorrelationFactor","Wrong parameters");
1109 return 0;
1110 }
1111 if (axis1 == axis2) return 1;
1113 if (stddev1 == 0) return 0;
1115 if (stddev2 == 0) return 0;
1117}
1118
1119
1120////////////////////////////////////////////////////////////////////////////////
1121/// Return covariance between axis1 and axis2.
1122
1124{
1125 if (axis1 < 1 || axis2 < 1 || axis1 > 2 || axis2 > 2) {
1126 Error("GetCovariance","Wrong parameters");
1127 return 0;
1128 }
1130 GetStats(stats);
1131 Double_t sumw = stats[0];
1132 //Double_t sumw2 = stats[1];
1133 Double_t sumwx = stats[2];
1134 Double_t sumwx2 = stats[3];
1135 Double_t sumwy = stats[4];
1136 Double_t sumwy2 = stats[5];
1137 Double_t sumwxy = stats[6];
1138
1139 if (sumw == 0) return 0;
1140 if (axis1 == 1 && axis2 == 1) {
1142 }
1143 if (axis1 == 2 && axis2 == 2) {
1145 }
1146 return sumwxy/sumw - sumwx/sumw*sumwy/sumw;
1147}
1148
1149
1150////////////////////////////////////////////////////////////////////////////////
1151/// Return 2 random numbers along axis x and y distributed according
1152/// to the cell-contents of this 2-D histogram.
1153///
1154/// Return a NaN if the histogram has a bin with negative content
1155///
1156/// @param[out] x reference to random generated x value
1157/// @param[out] y reference to random generated y value
1158/// @param[in] rng (optional) Random number generator pointer used (default is gRandom)
1159
1161{
1164 Int_t nbins = nbinsx*nbinsy;
1165 Double_t integral;
1166 // compute integral checking that all bins have positive content (see ROOT-5894)
1167 if (fIntegral) {
1168 if (fIntegral[nbins+1] != fEntries) integral = ComputeIntegral(true);
1169 else integral = fIntegral[nbins];
1170 } else {
1171 integral = ComputeIntegral(true);
1172 }
1173 if (integral == 0 ) { x = 0; y = 0; return;}
1174 // case histogram has negative bins
1175 if (integral == TMath::QuietNaN() ) { x = TMath::QuietNaN(); y = TMath::QuietNaN(); return;}
1176
1177 if (!rng) rng = gRandom;
1178 Double_t r1 = rng->Rndm();
1183 if (r1 > fIntegral[ibin]) x +=
1185 y = fYaxis.GetBinLowEdge(biny+1) + fYaxis.GetBinWidth(biny+1)*rng->Rndm();
1186}
1187
1188
1189////////////////////////////////////////////////////////////////////////////////
1190/// Fill the array stats from the contents of this histogram
1191/// The array stats must be correctly dimensioned in the calling program.
1192/// ~~~ {.cpp}
1193/// stats[0] = sumw
1194/// stats[1] = sumw2
1195/// stats[2] = sumwx
1196/// stats[3] = sumwx2
1197/// stats[4] = sumwy
1198/// stats[5] = sumwy2
1199/// stats[6] = sumwxy
1200/// ~~~
1201///
1202/// If no axis-subranges are specified (via TAxis::SetRange), the array stats
1203/// is simply a copy of the statistics quantities computed at filling time.
1204/// If sub-ranges are specified, the function recomputes these quantities
1205/// from the bin contents in the current axis ranges.
1206///
1207/// Note that the mean value/StdDev is computed using the bins in the currently
1208/// defined ranges (see TAxis::SetRange). By default the ranges include
1209/// all bins from 1 to nbins included, excluding underflows and overflows.
1210/// To force the underflows and overflows in the computation, one must
1211/// call the static function TH1::StatOverflows(kTRUE) before filling
1212/// the histogram.
1213
1215{
1216 if (fBuffer) ((TH2*)this)->BufferEmpty();
1217
1219 std::fill(stats, stats + 7, 0);
1220
1225 // include underflow/overflow if TH1::StatOverflows(kTRUE) in case no range is set on the axis
1228 if (firstBinX == 1) firstBinX = 0;
1229 if (lastBinX == fXaxis.GetNbins() ) lastBinX += 1;
1230 }
1232 if (firstBinY == 1) firstBinY = 0;
1233 if (lastBinY == fYaxis.GetNbins() ) lastBinY += 1;
1234 }
1235 }
1236 // check for labels axis. In that case corresponding statistics do not make sense and it is set to zero
1237 Bool_t labelXaxis = ((const_cast<TAxis&>(fXaxis)).GetLabels() && fXaxis.CanExtend() );
1238 Bool_t labelYaxis = ((const_cast<TAxis&>(fYaxis)).GetLabels() && fYaxis.CanExtend() );
1239
1240 for (Int_t biny = firstBinY; biny <= lastBinY; ++biny) {
1242 for (Int_t binx = firstBinX; binx <= lastBinX; ++binx) {
1244 //w = TMath::Abs(GetBinContent(bin));
1245 Int_t bin = GetBin(binx,biny);
1247 Double_t wx = w * x; // avoid some extra multiplications at the expense of some clarity
1248 Double_t wy = w * y;
1249
1250 stats[0] += w;
1251 stats[1] += GetBinErrorSqUnchecked(bin);
1252 stats[2] += wx;
1253 stats[3] += wx * x;
1254 stats[4] += wy;
1255 stats[5] += wy * y;
1256 stats[6] += wx * y;
1257 }
1258 }
1259 } else {
1260 stats[0] = fTsumw;
1261 stats[1] = fTsumw2;
1262 stats[2] = fTsumwx;
1263 stats[3] = fTsumwx2;
1264 stats[4] = fTsumwy;
1265 stats[5] = fTsumwy2;
1266 stats[6] = fTsumwxy;
1267 }
1268}
1269
1270
1271////////////////////////////////////////////////////////////////////////////////
1272/// Return integral of bin contents. Only bins in the bins range are considered.
1273/// By default the integral is computed as the sum of bin contents in the range.
1274/// if option "width" is specified, the integral is the sum of
1275/// the bin contents multiplied by the bin width in x and in y.
1276
1282
1283
1284////////////////////////////////////////////////////////////////////////////////
1285/// Return integral of bin contents in range [firstxbin,lastxbin],[firstybin,lastybin]
1286/// for a 2-D histogram
1287/// By default the integral is computed as the sum of bin contents in the range.
1288/// if option "width" is specified, the integral is the sum of
1289/// the bin contents multiplied by the bin width in x and in y.
1290
1296
1297////////////////////////////////////////////////////////////////////////////////
1298/// Return integral of bin contents in range [firstxbin,lastxbin],[firstybin,lastybin]
1299/// for a 2-D histogram. Calculates also the integral error using error propagation
1300/// from the bin errors assuming that all the bins are uncorrelated.
1301/// By default the integral is computed as the sum of bin contents in the range.
1302/// if option "width" is specified, the integral is the sum of
1303/// the bin contents multiplied by the bin width in x and in y.
1304
1309
1310////////////////////////////////////////////////////////////////////////////////
1311///illegal for a TH2
1312
1314{
1315 Error("Interpolate","This function must be called with 2 arguments for a TH2");
1316 return 0;
1317}
1318
1319////////////////////////////////////////////////////////////////////////////////
1320/// Given a point P(x,y), Interpolate approximates the value via bilinear
1321/// interpolation based on the four nearest bin centers
1322/// see Wikipedia, Bilinear Interpolation
1323/// Andy Mastbaum 10/8/2008
1324/// vaguely based on R.Raja 6-Sep-2008
1325
1327{
1328 Double_t f=0;
1329 Double_t x1=0,x2=0,y1=0,y2=0;
1330 Double_t dx,dy;
1334 Error("Interpolate","Cannot interpolate outside histogram domain.");
1335 return 0;
1336 }
1337 Int_t quadrant = 0; // CCW from UR 1,2,3,4
1338 // which quadrant of the bin (bin_P) are we in?
1342 quadrant = 1; // upper right
1344 quadrant = 2; // upper left
1346 quadrant = 3; // lower left
1348 quadrant = 4; // lower right
1349 switch(quadrant) {
1350 case 1:
1355 break;
1356 case 2:
1361 break;
1362 case 3:
1367 break;
1368 case 4:
1373 break;
1374 }
1376 if(bin_x1<1) bin_x1=1;
1380 if(bin_y1<1) bin_y1=1;
1391 Double_t d = 1.0*(x2-x1)*(y2-y1);
1392 f = 1.0*q11/d*(x2-x)*(y2-y)+1.0*q21/d*(x-x1)*(y2-y)+1.0*q12/d*(x2-x)*(y-y1)+1.0*q22/d*(x-x1)*(y-y1);
1393 return f;
1394}
1395
1396
1397////////////////////////////////////////////////////////////////////////////////
1398///illegal for a TH2
1399
1401{
1402 Error("Interpolate","This function must be called with 2 arguments for a TH2");
1403 return 0;
1404}
1405
1406
1407////////////////////////////////////////////////////////////////////////////////
1408/// Statistical test of compatibility in shape between
1409/// THIS histogram and h2, using Kolmogorov test.
1410/// Default: Ignore under- and overflow bins in comparison
1411///
1412/// option is a character string to specify options
1413/// - "U" include Underflows in test
1414/// - "O" include Overflows
1415/// - "N" include comparison of normalizations
1416/// - "D" Put out a line of "Debug" printout
1417/// - "M" Return the Maximum Kolmogorov distance instead of prob
1418///
1419/// The returned function value is the probability of test
1420/// (much less than one means NOT compatible)
1421///
1422/// The KS test uses the distance between the pseudo-CDF's obtained
1423/// from the histogram. Since in 2D the order for generating the pseudo-CDF is
1424/// arbitrary, two pairs of pseudo-CDF are used, one starting from the x axis the
1425/// other from the y axis and the maximum distance is the average of the two maximum
1426/// distances obtained.
1427///
1428/// Code adapted by Rene Brun from original HBOOK routine HDIFF
1429
1431{
1432 TString opt = option;
1433 opt.ToUpper();
1434
1435 Double_t prb = 0;
1436 TH1 *h1 = (TH1*)this;
1437 if (h2 == nullptr) return 0;
1438 const TAxis *xaxis1 = h1->GetXaxis();
1439 const TAxis *xaxis2 = h2->GetXaxis();
1440 const TAxis *yaxis1 = h1->GetYaxis();
1441 const TAxis *yaxis2 = h2->GetYaxis();
1442 Int_t ncx1 = xaxis1->GetNbins();
1443 Int_t ncx2 = xaxis2->GetNbins();
1444 Int_t ncy1 = yaxis1->GetNbins();
1445 Int_t ncy2 = yaxis2->GetNbins();
1446
1447 // Check consistency of dimensions
1448 if (h1->GetDimension() != 2 || h2->GetDimension() != 2) {
1449 Error("KolmogorovTest","Histograms must be 2-D\n");
1450 return 0;
1451 }
1452
1453 // Check consistency in number of channels
1454 if (ncx1 != ncx2) {
1455 Error("KolmogorovTest","Number of channels in X is different, %d and %d\n",ncx1,ncx2);
1456 return 0;
1457 }
1458 if (ncy1 != ncy2) {
1459 Error("KolmogorovTest","Number of channels in Y is different, %d and %d\n",ncy1,ncy2);
1460 return 0;
1461 }
1462
1463 // Check consistency in channel edges
1466 Double_t difprec = 1e-5;
1467 Double_t diff1 = TMath::Abs(xaxis1->GetXmin() - xaxis2->GetXmin());
1468 Double_t diff2 = TMath::Abs(xaxis1->GetXmax() - xaxis2->GetXmax());
1469 if (diff1 > difprec || diff2 > difprec) {
1470 Error("KolmogorovTest","histograms with different binning along X");
1471 return 0;
1472 }
1473 diff1 = TMath::Abs(yaxis1->GetXmin() - yaxis2->GetXmin());
1474 diff2 = TMath::Abs(yaxis1->GetXmax() - yaxis2->GetXmax());
1475 if (diff1 > difprec || diff2 > difprec) {
1476 Error("KolmogorovTest","histograms with different binning along Y");
1477 return 0;
1478 }
1479
1480 // Should we include Uflows, Oflows?
1481 Int_t ibeg = 1, jbeg = 1;
1482 Int_t iend = ncx1, jend = ncy1;
1483 if (opt.Contains("U")) {ibeg = 0; jbeg = 0;}
1484 if (opt.Contains("O")) {iend = ncx1+1; jend = ncy1+1;}
1485
1486 Int_t i,j;
1487 Double_t sum1 = 0;
1488 Double_t sum2 = 0;
1489 Double_t w1 = 0;
1490 Double_t w2 = 0;
1491 for (i = ibeg; i <= iend; i++) {
1492 for (j = jbeg; j <= jend; j++) {
1493 sum1 += h1->GetBinContent(i,j);
1494 sum2 += h2->GetBinContent(i,j);
1495 Double_t ew1 = h1->GetBinError(i,j);
1496 Double_t ew2 = h2->GetBinError(i,j);
1497 w1 += ew1*ew1;
1498 w2 += ew2*ew2;
1499
1500 }
1501 }
1502
1503 // Check that both scatterplots contain events
1504 if (sum1 == 0) {
1505 Error("KolmogorovTest","Integral is zero for h1=%s\n",h1->GetName());
1506 return 0;
1507 }
1508 if (sum2 == 0) {
1509 Error("KolmogorovTest","Integral is zero for h2=%s\n",h2->GetName());
1510 return 0;
1511 }
1512 // calculate the effective entries.
1513 // the case when errors are zero (w1 == 0 or w2 ==0) are equivalent to
1514 // compare to a function. In that case the rescaling is done only on sqrt(esum2) or sqrt(esum1)
1515 Double_t esum1 = 0, esum2 = 0;
1516 if (w1 > 0)
1517 esum1 = sum1 * sum1 / w1;
1518 else
1519 afunc1 = kTRUE; // use later for calculating z
1520
1521 if (w2 > 0)
1522 esum2 = sum2 * sum2 / w2;
1523 else
1524 afunc2 = kTRUE; // use later for calculating z
1525
1526 if (afunc2 && afunc1) {
1527 Error("KolmogorovTest","Errors are zero for both histograms\n");
1528 return 0;
1529 }
1530
1531 // Find first Kolmogorov distance
1532 Double_t s1 = 1/sum1;
1533 Double_t s2 = 1/sum2;
1534 Double_t dfmax1 = 0;
1535 Double_t rsum1=0, rsum2=0;
1536 for (i=ibeg;i<=iend;i++) {
1537 for (j=jbeg;j<=jend;j++) {
1538 rsum1 += s1*h1->GetBinContent(i,j);
1539 rsum2 += s2*h2->GetBinContent(i,j);
1541 }
1542 }
1543
1544 // Find second Kolmogorov distance
1545 Double_t dfmax2 = 0;
1546 rsum1=0, rsum2=0;
1547 for (j=jbeg;j<=jend;j++) {
1548 for (i=ibeg;i<=iend;i++) {
1549 rsum1 += s1*h1->GetBinContent(i,j);
1550 rsum2 += s2*h2->GetBinContent(i,j);
1552 }
1553 }
1554
1555 // Get Kolmogorov probability: use effective entries, esum1 or esum2, for normalizing it
1558 else if (afunc2) factnm = TMath::Sqrt(esum1);
1560
1561 // take average of the two distances
1562 Double_t dfmax = 0.5*(dfmax1+dfmax2);
1563 Double_t z = dfmax*factnm;
1564
1566
1567 Double_t prb1 = 0, prb2 = 0;
1568 // option N to combine normalization makes sense if both afunc1 and afunc2 are false
1569 if (opt.Contains("N") && !(afunc1 || afunc2 ) ) {
1570 // Combine probabilities for shape and normalization
1571 prb1 = prb;
1574 prb2 = TMath::Prob(chi2,1);
1575 // see Eadie et al., section 11.6.2
1576 if (prb > 0 && prb2 > 0) prb = prb*prb2*(1-TMath::Log(prb*prb2));
1577 else prb = 0;
1578 }
1579
1580 // debug printout
1581 if (opt.Contains("D")) {
1582 printf(" Kolmo Prob h1 = %s, sum1=%g\n",h1->GetName(),sum1);
1583 printf(" Kolmo Prob h2 = %s, sum2=%g\n",h2->GetName(),sum2);
1584 printf(" Kolmo Probabil = %f, Max Dist = %g\n",prb,dfmax);
1585 if (opt.Contains("N"))
1586 printf(" Kolmo Probabil = %f for shape alone, =%f for normalisation alone\n",prb1,prb2);
1587 }
1588 // This numerical error condition should never occur:
1589 if (TMath::Abs(rsum1-1) > 0.002) Warning("KolmogorovTest","Numerical problems with h1=%s\n",h1->GetName());
1590 if (TMath::Abs(rsum2-1) > 0.002) Warning("KolmogorovTest","Numerical problems with h2=%s\n",h2->GetName());
1591
1592 if(opt.Contains("M")) return dfmax; // return average of max distance
1593
1594 return prb;
1595}
1596
1597
1598////////////////////////////////////////////////////////////////////////////////
1599/// Rebin only the X axis
1600/// see Rebin2D
1601
1603{
1604 return Rebin2D(ngroup, 1, newname);
1605}
1606
1607
1608////////////////////////////////////////////////////////////////////////////////
1609/// Rebin only the Y axis
1610/// see Rebin2D
1611
1613{
1614 return Rebin2D(1, ngroup, newname);
1615}
1616
1617////////////////////////////////////////////////////////////////////////////////
1618/// Override TH1::Rebin as TH2::RebinX
1619/// Rebinning in variable binning as for TH1 is not allowed
1620/// If a non-null pointer is given an error is flagged
1621/// see RebinX and Rebin2D
1622
1623TH2 * TH2::Rebin( Int_t ngroup, const char*newname, const Double_t *xbins)
1624{
1625 if (xbins != nullptr) {
1626 Error("Rebin","Rebinning a 2-d histogram into variable bins is not supported (it is possible only for 1-d histograms). Return a nullptr");
1627 return nullptr;
1628 }
1629 Info("Rebin","Rebinning only the x-axis. Use Rebin2D for rebinning both axes");
1630 return RebinX(ngroup, newname);
1631}
1632////////////////////////////////////////////////////////////////////////////////
1633/// Rebin this histogram grouping nxgroup/nygroup bins along the xaxis/yaxis together.
1634///
1635/// if newname is not blank a new temporary histogram hnew is created.
1636/// else the current histogram is modified (default)
1637/// The parameter nxgroup/nygroup indicate how many bins along the xaxis/yaxis of this
1638/// have to me merged into one bin of hnew
1639/// If the original histogram has errors stored (via Sumw2), the resulting
1640/// histograms has new errors correctly calculated.
1641///
1642/// examples: if hpxpy is an existing TH2 histogram with 40 x 40 bins
1643/// ~~~ {.cpp}
1644/// hpxpy->Rebin2D(); // merges two bins along the xaxis and yaxis in one in hpxpy
1645/// // Carefull: previous contents of hpxpy are lost
1646/// hpxpy->RebinX(5); //merges five bins along the xaxis in one in hpxpy
1647/// TH2 *hnew = hpxpy->RebinY(5,"hnew"); // creates a new histogram hnew
1648/// // merging 5 bins of h1 along the yaxis in one bin
1649/// ~~~
1650///
1651/// NOTE : If nxgroup/nygroup is not an exact divider of the number of bins,
1652/// along the xaxis/yaxis the top limit(s) of the rebinned histogram
1653/// is changed to the upper edge of the xbin=newxbins*nxgroup resp.
1654/// ybin=newybins*nygroup and the corresponding bins are added to
1655/// the overflow bin.
1656/// Statistics will be recomputed from the new bin contents.
1657
1659{
1662 Int_t nx = nxbins + 2; // normal bins + underflow and overflow
1663 Int_t ny = nybins + 2;
1668
1669 if (GetDimension() != 2) {
1670 Error("Rebin2D", "Histogram must be TH2. This histogram has %d dimensions.", GetDimension());
1671 return nullptr;
1672 }
1673 if ((nxgroup <= 0) || (nxgroup > nxbins)) {
1674 Error("Rebin2D", "Illegal value of nxgroup=%d",nxgroup);
1675 return nullptr;
1676 }
1677 if ((nygroup <= 0) || (nygroup > nybins)) {
1678 Error("Rebin2D", "Illegal value of nygroup=%d",nygroup);
1679 return nullptr;
1680 }
1681
1684 Int_t newnx = newxbins + 2; // regular bins + overflow / underflow
1685 Int_t newny = newybins + 2; // regular bins + overflow / underflow
1686
1687 // Save old bin contents into a new array
1689 for (Int_t i = 0; i < fNcells; ++i) oldBins[i] = RetrieveBinContent(i);
1690
1691 Double_t* oldErrors = nullptr;
1692 if (fSumw2.fN) {
1693 oldErrors = new Double_t[fNcells];
1694 for (Int_t i = 0; i < fNcells; ++i) oldErrors[i] = GetBinErrorSqUnchecked(i);
1695 }
1696
1697 // create a clone of the old histogram if newname is specified
1698 TH2* hnew = this;
1699 if (newname && strlen(newname)) {
1700 hnew = (TH2*)Clone();
1701 hnew->SetName(newname);
1702 }
1703
1704 bool resetStat = false;
1705
1706 // change axis specs and rebuild bin contents array
1707 if(newxbins * nxgroup != nxbins) {
1709 resetStat = true; // stats must be reset because top bins will be moved to overflow bin
1710 }
1711 if(newybins * nygroup != nybins) {
1713 resetStat = true; // stats must be reset because top bins will be moved to overflow bin
1714 }
1715
1716 // save the TAttAxis members (reset by SetBins) for x axis
1728 // save the TAttAxis members (reset by SetBins) for y axis
1740
1741
1742 // copy merged bin contents (ignore under/overflows)
1743 if (nxgroup != 1 || nygroup != 1) {
1744 if(fXaxis.GetXbins()->GetSize() > 0 || fYaxis.GetXbins()->GetSize() > 0){
1745 // variable bin sizes in x or y, don't treat both cases separately
1746 Double_t *xbins = new Double_t[newxbins + 1];
1747 for(Int_t i = 0; i <= newxbins; ++i) xbins[i] = fXaxis.GetBinLowEdge(1 + i * nxgroup);
1748 Double_t *ybins = new Double_t[newybins + 1];
1749 for(Int_t i = 0; i <= newybins; ++i) ybins[i] = fYaxis.GetBinLowEdge(1 + i * nygroup);
1750 hnew->SetBins(newxbins, xbins, newybins, ybins); // changes also errors array (if any)
1751 delete [] xbins;
1752 delete [] ybins;
1753 } else {
1754 hnew->SetBins(newxbins, xmin, xmax, newybins, ymin, ymax); //changes also errors array
1755 }
1756
1757 // (0, 0): x - underflow; y - underflow
1758 hnew->UpdateBinContent(0, oldBins[0]);
1759 if (oldErrors) hnew->fSumw2[0] = 0;
1760
1761 // (x, 0): x - regular / overflow; y - underflow
1762 for(Int_t binx = 1, oldbinx = 1; binx < newnx; ++binx, oldbinx += nxgroup){
1763 Double_t binContent = 0.0, binErrorSq = 0.0;
1764 for (Int_t i = 0; i < nxgroup && (oldbinx + i) < nx; ++i) {
1765 Int_t bin = oldbinx + i;
1766 binContent += oldBins[bin];
1767 if(oldErrors) binErrorSq += oldErrors[bin];
1768 }
1769 Int_t newbin = binx;
1770 hnew->UpdateBinContent(newbin, binContent);
1771 if (oldErrors) hnew->fSumw2[newbin] = binErrorSq;
1772 }
1773
1774 // (0, y): x - underflow; y - regular / overflow
1775 for(Int_t biny = 1, oldbiny = 1; biny < newny; ++biny, oldbiny += nygroup){
1776 Double_t binContent = 0.0, binErrorSq = 0.0;
1777 for (Int_t j = 0; j < nygroup && (oldbiny + j) < ny; ++j) {
1778 Int_t bin = (oldbiny + j) * nx;
1779 binContent += oldBins[bin];
1780 if(oldErrors) binErrorSq += oldErrors[bin];
1781 }
1782 Int_t newbin = biny * newnx;
1783 hnew->UpdateBinContent(newbin, binContent);
1784 if (oldErrors) hnew->fSumw2[newbin] = binErrorSq;
1785 }
1786
1787 // (x, y): x - regular / overflow; y - regular / overflow
1788 for (Int_t binx = 1, oldbinx = 1; binx < newnx; ++binx, oldbinx += nxgroup) {
1789 for (Int_t biny = 1, oldbiny = 1; biny < newny; ++biny, oldbiny += nygroup) {
1790 Double_t binContent = 0.0, binErrorSq = 0.0;
1791 for (Int_t i = 0; i < nxgroup && (oldbinx + i) < nx; ++i) {
1792 for (Int_t j = 0; j < nygroup && (oldbiny + j) < ny; ++j) {
1793 Int_t bin = oldbinx + i + (oldbiny + j) * nx;
1794 binContent += oldBins[bin];
1795 if (oldErrors) binErrorSq += oldErrors[bin];
1796 }
1797 }
1798 Int_t newbin = binx + biny * newnx;
1799 hnew->UpdateBinContent(newbin, binContent);
1800 if (oldErrors) hnew->fSumw2[newbin] = binErrorSq;
1801 }
1802 }
1803 }
1804
1805 // Restore x axis attributes
1817 // Restore y axis attributes
1829
1830 if (resetStat) hnew->ResetStats();
1831
1832 delete [] oldBins;
1833 if (oldErrors) delete [] oldErrors;
1834 return hnew;
1835}
1836
1837
1838////////////////////////////////////////////////////////////////////////////////
1839
1841{
1842 TString opt = option;
1843 // extract cut infor
1844 TString cut;
1845 Int_t i1 = opt.Index("[");
1846 if (i1>=0) {
1847 Int_t i2 = opt.Index("]");
1848 cut = opt(i1,i2-i1+1);
1849 }
1850 opt.ToLower();
1851 bool originalRange = opt.Contains("o");
1852
1853 const TAxis& outAxis = ( onX ? fXaxis : fYaxis );
1854 const TAxis& inAxis = ( onX ? fYaxis : fXaxis );
1855 Int_t inN = inAxis.GetNbins();
1856 const char *expectedName = ( onX ? "_pfx" : "_pfy" );
1857
1858 // outer axis cannot be outside original axis (this fixes ROOT-8781)
1859 // and firstOutBin and lastOutBin cannot be both equal to zero
1860 Int_t firstOutBin = std::max(outAxis.GetFirst(),1);
1861 Int_t lastOutBin = std::min(outAxis.GetLast(),outAxis.GetNbins() ) ;
1862
1863 if ( lastbin < firstbin && inAxis.TestBit(TAxis::kAxisRange) ) {
1864 firstbin = inAxis.GetFirst();
1865 lastbin = inAxis.GetLast();
1866 // For special case of TAxis::SetRange, when first == 1 and last
1867 // = N and the range bit has been set, the TAxis will return 0
1868 // for both.
1869 if (firstbin == 0 && lastbin == 0)
1870 {
1871 firstbin = 1;
1872 lastbin = inAxis.GetNbins();
1873 }
1874 }
1875 if (firstbin < 0) firstbin = 1;
1876 if (lastbin < 0) lastbin = inN;
1877 if (lastbin > inN+1) lastbin = inN;
1878
1879 // Create the profile histogram
1880 char *pname = (char*)name;
1881 if (name && strcmp(name, expectedName) == 0) {
1882 Int_t nch = strlen(GetName()) + 5;
1883 pname = new char[nch];
1884 snprintf(pname,nch,"%s%s",GetName(),name);
1885 }
1886 TProfile *h1=nullptr;
1887 //check if a profile with identical name exist
1888 // if compatible reset and re-use previous histogram
1889 TObject *h1obj = gROOT->FindObject(pname);
1890 if (h1obj && h1obj->InheritsFrom(TH1::Class())) {
1891 if (h1obj->IsA() != TProfile::Class() ) {
1892 Error("DoProfile","Histogram with name %s must be a TProfile and is a %s",name,h1obj->ClassName());
1893 return nullptr;
1894 }
1895 h1 = (TProfile*)h1obj;
1896 // reset the existing histogram and set always the new binning for the axis
1897 // This avoid problems when the histogram already exists and the histograms is rebinned or its range has changed
1898 // (see https://savannah.cern.ch/bugs/?94101 or https://savannah.cern.ch/bugs/?95808 )
1899 h1->Reset();
1900 const TArrayD *xbins = outAxis.GetXbins();
1901 if (xbins->fN == 0) {
1902 if ( originalRange )
1903 h1->SetBins(outAxis.GetNbins(),outAxis.GetXmin(),outAxis.GetXmax());
1904 else
1905 h1->SetBins(lastOutBin-firstOutBin+1,outAxis.GetBinLowEdge(firstOutBin),outAxis.GetBinUpEdge(lastOutBin));
1906 } else {
1907 // case variable bins
1908 if (originalRange )
1909 h1->SetBins(outAxis.GetNbins(),xbins->fArray);
1910 else
1911 h1->SetBins(lastOutBin-firstOutBin+1,&xbins->fArray[firstOutBin-1]);
1912 }
1913 }
1914
1915 Int_t ncuts = 0;
1916 if (opt.Contains("[")) {
1917 ((TH2 *)this)->GetPainter();
1918 if (fPainter) ncuts = fPainter->MakeCuts((char*)cut.Data());
1919 }
1920
1921 if (!h1) {
1922 const TArrayD *bins = outAxis.GetXbins();
1923 if (bins->fN == 0) {
1924 if ( originalRange )
1925 h1 = new TProfile(pname,GetTitle(),outAxis.GetNbins(),outAxis.GetXmin(),outAxis.GetXmax(),opt);
1926 else
1928 outAxis.GetBinLowEdge(firstOutBin),
1929 outAxis.GetBinUpEdge(lastOutBin), opt);
1930 } else {
1931 // case variable bins
1932 if (originalRange )
1933 h1 = new TProfile(pname,GetTitle(),outAxis.GetNbins(),bins->fArray,opt);
1934 else
1936 }
1937 }
1938 if (pname != name) delete [] pname;
1939
1940 // Copy attributes
1942 THashList* labels=outAxis.GetLabels();
1943 if (labels) {
1944 TIter iL(labels);
1945 TObjString* lb;
1946 Int_t i = 1;
1947 while ((lb=(TObjString*)iL())) {
1948 h1->GetXaxis()->SetBinLabel(i,lb->String().Data());
1949 i++;
1950 }
1951 }
1952
1953 h1->SetLineColor(this->GetLineColor());
1954 h1->SetFillColor(this->GetFillColor());
1955 h1->SetMarkerColor(this->GetMarkerColor());
1956 h1->SetMarkerStyle(this->GetMarkerStyle());
1957
1958 // check if histogram is weighted
1959 // in case need to store sum of weight square/bin for the profile
1960 TArrayD & binSumw2 = *(h1->GetBinSumw2());
1961 bool useWeights = (GetSumw2N() > 0);
1962 if (useWeights && (binSumw2.fN != h1->GetNcells()) ) h1->Sumw2();
1963 // we need to set this bit because we fill the profile using a single Fill for many entries
1964 // This is needed for the changes applied to make automatically the histogram weighted in ROOT 6 versions
1965 else h1->SetBit(TH1::kIsNotW);
1966
1967 // Fill the profile histogram
1968 // no entries/bin is available so can fill only using bin content as weight
1969
1970 // implement filling of projected histogram
1971 // outbin is bin number of outAxis (the projected axis). Loop is done on all bin of TH2 histograms
1972 // inbin is the axis being integrated. Loop is done only on the selected bins
1973 for ( Int_t outbin = 0; outbin <= outAxis.GetNbins() + 1; ++outbin) {
1975
1976 // find corresponding bin number in h1 for outbin (binOut)
1977 Double_t xOut = outAxis.GetBinCenter(outbin);
1979 if (binOut <0) continue;
1980
1981 for (Int_t inbin = firstbin ; inbin <= lastbin ; ++inbin) {
1982 Int_t binx, biny;
1983 if (onX) { binx = outbin; biny=inbin; }
1984 else { binx = inbin; biny=outbin; }
1985
1986 if (ncuts) {
1987 if (!fPainter->IsInside(binx,biny)) continue;
1988 }
1989 Int_t bin = GetBin(binx, biny);
1991
1992
1993 if (cxy) {
1994 Double_t tmp = 0;
1995 // the following fill update wrongly the fBinSumw2- need to save it before
1996 if ( useWeights ) tmp = binSumw2.fArray[binOut];
1997 h1->Fill( xOut, inAxis.GetBinCenter(inbin), cxy );
1998 if ( useWeights ) binSumw2.fArray[binOut] = tmp + fSumw2.fArray[bin];
1999 }
2000
2001 }
2002 }
2003
2004 // the statistics must be recalculated since by using the Fill method the total sum of weight^2 is
2005 // not computed correctly
2006 // for a profile does not much sense to re-use statistics of original TH2
2007 h1->ResetStats();
2008 // Also we need to set the entries since they have not been correctly calculated during the projection
2009 // we can only set them to the effective entries
2011
2012
2013 if (opt.Contains("d")) {
2014 TVirtualPad::TContext ctxt(gROOT->GetSelectedPad(), true, true);
2015 opt.Remove(opt.First("d"),1);
2016 if (!gPad || !gPad->FindObject(h1)) {
2017 h1->Draw(opt);
2018 } else {
2019 h1->Paint(opt);
2020 }
2021 }
2022 return h1;
2023}
2024
2025
2026////////////////////////////////////////////////////////////////////////////////
2027/// Project a 2-D histogram into a profile histogram along X.
2028///
2029/// The projection is made from the channels along the Y axis
2030/// ranging from firstybin to lastybin included.
2031/// By default, bins 1 to ny are included
2032/// When all bins are included, the number of entries in the projection
2033/// is set to the number of entries of the 2-D histogram, otherwise
2034/// the number of entries is incremented by 1 for all non empty cells.
2035///
2036/// if option "d" is specified, the profile is drawn in the current pad.
2037///
2038/// if option "o" original axis range of the target axes will be
2039/// kept, but only bins inside the selected range will be filled.
2040///
2041/// The option can also be used to specify the projected profile error type.
2042/// Values which can be used are 's', 'i', or 'g'. See TProfile::BuildOptions for details
2043///
2044/// Using a TCutG object, it is possible to select a sub-range of a 2-D histogram.
2045/// One must create a graphical cut (mouse or C++) and specify the name
2046/// of the cut between [] in the option.
2047/// For example, with a TCutG named "cutg", one can call:
2048/// myhist->ProfileX(" ",firstybin,lastybin,"[cutg]");
2049/// To invert the cut, it is enough to put a "-" in front of its name:
2050/// myhist->ProfileX(" ",firstybin,lastybin,"[-cutg]");
2051/// It is possible to apply several cuts ("," means logical AND):
2052/// myhist->ProfileX(" ",firstybin,lastybin,"[cutg1,cutg2]");
2053///
2054/// NOTE that if a TProfile named "name" exists in the current directory or pad with
2055/// a compatible axis the profile is reset and filled again with the projected contents of the TH2.
2056/// In the case of axis incompatibility an error is reported and a NULL pointer is returned.
2057///
2058/// NOTE that the X axis attributes of the TH2 are copied to the X axis of the profile.
2059///
2060/// NOTE that the default under- / overflow behavior differs from what ProjectionX
2061/// does! Profiles take the bin center into account, so here the under- and overflow
2062/// bins are ignored by default.
2063///
2064/// NOTE that the return profile histogram is computed using the Y bin center values instead of
2065/// the real Y values which are used to fill the 2d histogram. Therefore the obtained profile is just an approximation of the
2066/// correct profile histogram that would be obtained when filling it directly with the original data (see ROOT-7770)
2067
2068
2070{
2071 return DoProfile(true, name, firstybin, lastybin, option);
2072
2073}
2074
2075
2076////////////////////////////////////////////////////////////////////////////////
2077/// Project a 2-D histogram into a profile histogram along Y.
2078///
2079/// The projection is made from the channels along the X axis
2080/// ranging from firstxbin to lastxbin included.
2081/// By default, bins 1 to nx are included
2082/// When all bins are included, the number of entries in the projection
2083/// is set to the number of entries of the 2-D histogram, otherwise
2084/// the number of entries is incremented by 1 for all non empty cells.
2085///
2086/// if option "d" is specified, the profile is drawn in the current pad.
2087///
2088/// if option "o" , the original axis range of the target axis will be
2089/// kept, but only bins inside the selected range will be filled.
2090///
2091/// The option can also be used to specify the projected profile error type.
2092/// Values which can be used are 's', 'i', or 'g'. See TProfile::BuildOptions for details
2093/// Using a TCutG object, it is possible to select a sub-range of a 2-D histogram.
2094///
2095/// One must create a graphical cut (mouse or C++) and specify the name
2096/// of the cut between [] in the option.
2097/// For example, with a TCutG named "cutg", one can call:
2098/// myhist->ProfileY(" ",firstybin,lastybin,"[cutg]");
2099/// To invert the cut, it is enough to put a "-" in front of its name:
2100/// myhist->ProfileY(" ",firstybin,lastybin,"[-cutg]");
2101/// It is possible to apply several cuts:
2102/// myhist->ProfileY(" ",firstybin,lastybin,"[cutg1,cutg2]");
2103///
2104/// NOTE that if a TProfile named "name" exists in the current directory or pad with
2105/// a compatible axis the profile is reset and filled again with the projected contents of the TH2.
2106/// In the case of axis incompatibility an error is reported and a NULL pointer is returned.
2107///
2108/// NOTE that the Y axis attributes of the TH2 are copied to the X axis of the profile.
2109///
2110/// NOTE that the default under- / overflow behavior differs from what ProjectionX
2111/// does! Profiles take the bin center into account, so here the under- and overflow
2112/// bins are ignored by default.
2113///
2114/// NOTE that the return profile histogram is computed using the X bin center values instead of
2115/// the real X values which are used to fill the 2d histogram. Therefore the obtained profile is just an approximation of the
2116/// correct profile histogram that would be obtained when filling it directly with the original data (see ROOT-7770)
2117
2118
2120{
2121 return DoProfile(false, name, firstxbin, lastxbin, option);
2122}
2123
2124
2125////////////////////////////////////////////////////////////////////////////////
2126/// Internal (protected) method for performing projection on the X or Y axis
2127/// called by ProjectionX or ProjectionY
2128
2130{
2131 const char *expectedName = nullptr;
2132 Int_t inNbin;
2133 const TAxis* outAxis;
2134 const TAxis* inAxis;
2135
2136 TString opt = option;
2137 TString cut;
2138 Int_t i1 = opt.Index("[");
2139 if (i1>=0) {
2140 Int_t i2 = opt.Index("]");
2141 cut = opt(i1,i2-i1+1);
2142 }
2143 opt.ToLower(); //must be called after having parsed the cut name
2144 bool originalRange = opt.Contains("o");
2145
2146 if ( onX )
2147 {
2148 expectedName = "_px";
2150 outAxis = GetXaxis();
2151 inAxis = GetYaxis();
2152 }
2153 else
2154 {
2155 expectedName = "_py";
2157 outAxis = GetYaxis();
2158 inAxis = GetXaxis();
2159 }
2160
2161 // outer axis cannot be outside original axis (this fixes ROOT-8781)
2162 // and firstOutBin and lastOutBin cannot be both equal to zero
2163 Int_t firstOutBin = std::max(outAxis->GetFirst(),1);
2164 Int_t lastOutBin = std::min(outAxis->GetLast(),outAxis->GetNbins() ) ;
2165
2167 firstbin = inAxis->GetFirst();
2168 lastbin = inAxis->GetLast();
2169 // For special case of TAxis::SetRange, when first == 1 and last
2170 // = N and the range bit has been set, the TAxis will return 0
2171 // for both.
2172 if (firstbin == 0 && lastbin == 0)
2173 {
2174 firstbin = 1;
2175 lastbin = inAxis->GetNbins();
2176 }
2177 }
2178 if (firstbin < 0) firstbin = 0;
2179 if (lastbin < 0) lastbin = inNbin + 1;
2180 if (lastbin > inNbin+1) lastbin = inNbin + 1;
2181
2182 // Create the projection histogram
2183 char *pname = (char*)name;
2184 if (name && strcmp(name,expectedName) == 0) {
2185 Int_t nch = strlen(GetName()) + 4;
2186 pname = new char[nch];
2187 snprintf(pname,nch,"%s%s",GetName(),name);
2188 }
2189 TH1D *h1=nullptr;
2190 //check if histogram with identical name exist
2191 // if compatible reset and re-use previous histogram
2192 // (see https://savannah.cern.ch/bugs/?54340)
2193 TObject *h1obj = gROOT->FindObject(pname);
2194 if (h1obj && h1obj->InheritsFrom(TH1::Class())) {
2195 if (h1obj->IsA() != TH1D::Class() ) {
2196 Error("DoProjection","Histogram with name %s must be a TH1D and is a %s",name,h1obj->ClassName());
2197 return nullptr;
2198 }
2199 h1 = (TH1D*)h1obj;
2200 // reset the existing histogram and set always the new binning for the axis
2201 // This avoid problems when the histogram already exists and the histograms is rebinned or its range has changed
2202 // (see https://savannah.cern.ch/bugs/?94101 or https://savannah.cern.ch/bugs/?95808 )
2203 h1->Reset();
2204 const TArrayD *xbins = outAxis->GetXbins();
2205 if (xbins->fN == 0) {
2206 if ( originalRange )
2207 h1->SetBins(outAxis->GetNbins(),outAxis->GetXmin(),outAxis->GetXmax());
2208 else
2209 h1->SetBins(lastOutBin-firstOutBin+1,outAxis->GetBinLowEdge(firstOutBin),outAxis->GetBinUpEdge(lastOutBin));
2210 } else {
2211 // case variable bins
2212 if (originalRange )
2213 h1->SetBins(outAxis->GetNbins(),xbins->fArray);
2214 else
2215 h1->SetBins(lastOutBin-firstOutBin+1,&xbins->fArray[firstOutBin-1]);
2216 }
2217 }
2218
2219 Int_t ncuts = 0;
2220 if (opt.Contains("[")) {
2221 ((TH2 *)this)->GetPainter();
2222 if (fPainter) ncuts = fPainter->MakeCuts((char*)cut.Data());
2223 }
2224
2225 if (!h1) {
2226 const TArrayD *bins = outAxis->GetXbins();
2227 if (bins->fN == 0) {
2228 if ( originalRange )
2229 h1 = new TH1D(pname,GetTitle(),outAxis->GetNbins(),outAxis->GetXmin(),outAxis->GetXmax());
2230 else
2232 outAxis->GetBinLowEdge(firstOutBin),outAxis->GetBinUpEdge(lastOutBin));
2233 } else {
2234 // case variable bins
2235 if (originalRange )
2236 h1 = new TH1D(pname,GetTitle(),outAxis->GetNbins(),bins->fArray);
2237 else
2239 }
2240 if (opt.Contains("e") || GetSumw2N() ) h1->Sumw2();
2241 }
2242 if (pname != name) delete [] pname;
2243
2244 // Copy the axis attributes and the axis labels if needed.
2246 THashList* labels=outAxis->GetLabels();
2247 if (labels) {
2248 TIter iL(labels);
2249 TObjString* lb;
2250 Int_t i = 1;
2251 while ((lb=(TObjString*)iL())) {
2252 h1->GetXaxis()->SetBinLabel(i,lb->String().Data());
2253 i++;
2254 }
2255 }
2256
2257 h1->SetLineColor(this->GetLineColor());
2258 h1->SetFillColor(this->GetFillColor());
2259 h1->SetMarkerColor(this->GetMarkerColor());
2260 h1->SetMarkerStyle(this->GetMarkerStyle());
2261
2262 // Fill the projected histogram
2264 Double_t totcont = 0;
2266
2267 // implement filling of projected histogram
2268 // outbin is bin number of outAxis (the projected axis). Loop is done on all bin of TH2 histograms
2269 // inbin is the axis being integrated. Loop is done only on the selected bins
2270 // if the out axis has labels and is extendable, temporary make it non-extendable to avoid adding extra bins
2271 Bool_t extendable = outAxis->CanExtend();
2272 if ( labels && extendable ) h1->GetXaxis()->SetCanExtend(kFALSE);
2273 for ( Int_t outbin = 0; outbin <= outAxis->GetNbins() + 1; ++outbin) {
2274 err2 = 0;
2275 cont = 0;
2277
2278 for (Int_t inbin = firstbin ; inbin <= lastbin ; ++inbin) {
2279 Int_t binx, biny;
2280 if (onX) { binx = outbin; biny=inbin; }
2281 else { binx = inbin; biny=outbin; }
2282
2283 if (ncuts) {
2284 if (!fPainter->IsInside(binx,biny)) continue;
2285 }
2286 // sum bin content and error if needed
2288 if (computeErrors) {
2290 err2 += exy*exy;
2291 }
2292 }
2293 // find corresponding bin number in h1 for outbin
2294 Int_t binOut = h1->GetXaxis()->FindBin( outAxis->GetBinCenter(outbin) );
2297 // sum all content
2298 totcont += cont;
2299 }
2300 if ( labels ) h1->GetXaxis()->SetCanExtend(extendable);
2301
2302 // check if we can re-use the original statistics from the previous histogram
2303 bool reuseStats = false;
2304 if ( ( GetStatOverflowsBehaviour() == false && firstbin == 1 && lastbin == inNbin ) ||
2305 ( GetStatOverflowsBehaviour() == true && firstbin == 0 && lastbin == inNbin + 1 ) )
2306 reuseStats = true;
2307 else {
2308 // also if total content match we can re-use
2309 double eps = 1.E-12;
2310 if (IsA() == TH2F::Class() ) eps = 1.E-6;
2311 if (fTsumw != 0 && TMath::Abs( fTsumw - totcont) < TMath::Abs(fTsumw) * eps)
2312 reuseStats = true;
2313 }
2314 if (ncuts) reuseStats = false;
2315 // retrieve the statistics and set in projected histogram if we can re-use it
2316 bool reuseEntries = reuseStats;
2317 // can re-use entries if underflow/overflow are included
2318 reuseEntries &= (firstbin==0 && lastbin == inNbin+1);
2319 if (reuseStats) {
2321 GetStats(stats);
2322 if (!onX) { // case of projection on Y
2323 stats[2] = stats[4];
2324 stats[3] = stats[5];
2325 }
2326 h1->PutStats(stats);
2327 }
2328 else {
2329 // the statistics is automatically recalculated since it is reset by the call to SetBinContent
2330 // we just need to set the entries since they have not been correctly calculated during the projection
2331 // we can only set them to the effective entries
2333 }
2334 if (reuseEntries) {
2336 }
2337 else {
2338 // re-compute the entries
2339 // in case of error calculation (i.e. when Sumw2() is set)
2340 // use the effective entries for the entries
2341 // since this is the only way to estimate them
2342 Double_t entries = TMath::Floor( totcont + 0.5); // to avoid numerical rounding
2343 if (h1->GetSumw2N()) entries = h1->GetEffectiveEntries();
2344 h1->SetEntries( entries );
2345 }
2346
2347 if (opt.Contains("d")) {
2348 TVirtualPad::TContext ctxt(gROOT->GetSelectedPad(), true, true);
2349 opt.Remove(opt.First("d"),1);
2350 // remove also other options
2351 if (opt.Contains("e")) opt.Remove(opt.First("e"),1);
2352 if (!gPad || !gPad->FindObject(h1)) {
2353 h1->Draw(opt);
2354 } else {
2355 h1->Paint(opt);
2356 }
2357 }
2358
2359 return h1;
2360}
2361
2362
2363////////////////////////////////////////////////////////////////////////////////
2364/// Project a 2-D histogram into a 1-D histogram along X.
2365///
2366/// The projection is always of the type TH1D.
2367/// The projection is made from the channels along the Y axis
2368/// ranging from firstybin to lastybin included.
2369/// By default, all bins including under- and overflow are included.
2370/// The number of entries in the projection is estimated from the
2371/// number of effective entries for all the cells included in the projection.
2372///
2373/// To exclude the underflow bins in Y, use firstybin=1.
2374/// To exclude the overflow bins in Y, use lastybin=nx.
2375///
2376/// if option "e" is specified, the errors are computed.
2377/// if option "d" is specified, the projection is drawn in the current pad.
2378/// if option "o" original axis range of the target axes will be
2379/// kept, but only bins inside the selected range will be filled.
2380///
2381/// Using a TCutG object, it is possible to select a sub-range of a 2-D histogram.
2382/// One must create a graphical cut (mouse or C++) and specify the name
2383/// of the cut between [] in the option.
2384/// For example, with a TCutG named "cutg", one can call:
2385/// myhist->ProjectionX(" ",firstybin,lastybin,"[cutg]");
2386/// To invert the cut, it is enough to put a "-" in front of its name:
2387/// myhist->ProjectionX(" ",firstybin,lastybin,"[-cutg]");
2388/// It is possible to apply several cuts:
2389/// myhist->ProjectionX(" ",firstybin,lastybin,"[cutg1,cutg2]");
2390///
2391/// NOTE that if a TH1D named "name" exists in the current directory or pad
2392/// the histogram is reset and filled again with the projected contents of the TH2.
2393///
2394/// NOTE that the X axis attributes of the TH2 are copied to the X axis of the projection.
2395
2397{
2398 return DoProjection(true, name, firstybin, lastybin, option);
2399}
2400
2401
2402////////////////////////////////////////////////////////////////////////////////
2403/// Project a 2-D histogram into a 1-D histogram along Y.
2404///
2405/// The projection is always of the type TH1D.
2406/// The projection is made from the channels along the X axis
2407/// ranging from firstxbin to lastxbin included.
2408/// By default, all bins including under- and overflow are included.
2409/// The number of entries in the projection is estimated from the
2410/// number of effective entries for all the cells included in the projection
2411///
2412/// To exclude the underflow bins in X, use firstxbin=1.
2413/// To exclude the overflow bins in X, use lastxbin=nx.
2414///
2415/// if option "e" is specified, the errors are computed.
2416/// if option "d" is specified, the projection is drawn in the current pad.
2417/// if option "o" original axis range of the target axes will be
2418/// kept, but only bins inside the selected range will be filled.
2419///
2420/// Using a TCutG object, it is possible to select a sub-range of a 2-D histogram.
2421/// One must create a graphical cut (mouse or C++) and specify the name
2422/// of the cut between [] in the option.
2423/// For example, with a TCutG named "cutg", one can call:
2424/// myhist->ProjectionY(" ",firstxbin,lastxbin,"[cutg]");
2425/// To invert the cut, it is enough to put a "-" in front of its name:
2426/// myhist->ProjectionY(" ",firstxbin,lastxbin,"[-cutg]");
2427/// It is possible to apply several cuts:
2428/// myhist->ProjectionY(" ",firstxbin,lastxbin,"[cutg1,cutg2]");
2429///
2430/// NOTE that if a TH1D named "name" exists in the current directory or pad and having
2431/// a compatible axis, the histogram is reset and filled again with the projected contents of the TH2.
2432/// In the case of axis incompatibility, an error is reported and a NULL pointer is returned.
2433///
2434/// NOTE that the Y axis attributes of the TH2 are copied to the X axis of the projection.
2435
2437{
2438 return DoProjection(false, name, firstxbin, lastxbin, option);
2439}
2440
2441
2442////////////////////////////////////////////////////////////////////////////////
2443/// Replace current statistics with the values in array stats
2444
2446{
2448 fTsumwy = stats[4];
2449 fTsumwy2 = stats[5];
2450 fTsumwxy = stats[6];
2451}
2452
2453
2454////////////////////////////////////////////////////////////////////////////////
2455/// Compute the X distribution of quantiles in the other variable Y
2456/// name is the name of the returned histogram
2457/// prob is the probability content for the quantile (0.5 is the default for the median)
2458/// An approximate error for the quantile is computed assuming that the distribution in
2459/// the other variable is normal. According to this approximate formula the error on the quantile is
2460/// estimated as sqrt( p (1-p) / ( n * f(q)^2) ), where p is the probability content of the quantile and
2461/// n is the number of events used to compute the quantile and f(q) is the probability distribution for the
2462/// other variable evaluated at the obtained quantile. In the error estimation the probability is then assumed to be
2463/// a normal distribution.
2464
2465TH1D* TH2::QuantilesX( Double_t prob, const char * name) const
2466{
2467 return DoQuantiles(true, name, prob);
2468}
2469
2470
2471////////////////////////////////////////////////////////////////////////////////
2472/// Compute the Y distribution of quantiles in the other variable X
2473/// name is the name of the returned histogram
2474/// prob is the probability content for the quantile (0.5 is the default for the median)
2475/// An approximate error for the quantile is computed assuming that the distribution in
2476/// the other variable is normal.
2477
2478TH1D* TH2::QuantilesY( Double_t prob, const char * name) const
2479{
2480 return DoQuantiles(false, name, prob);
2481}
2482
2483
2484////////////////////////////////////////////////////////////////////////////////
2485/// Implementation of quantiles for x or y
2486
2487TH1D* TH2::DoQuantiles(bool onX, const char * name, Double_t prob) const
2488{
2489 const TAxis *outAxis = nullptr;
2490 if ( onX ) {
2491 outAxis = GetXaxis();
2492 } else {
2493 outAxis = GetYaxis();
2494 }
2495
2496 // build first name of returned histogram
2497 TString qname = name;
2498 if (qname.IsNull() || qname == "_qx" || qname == "_qy") {
2499 const char * qtype = (onX) ? "qx" : "qy";
2500 qname = TString::Format("%s_%s_%3.2f",GetName(),qtype, prob);
2501 }
2502 // check if the histogram is already existing
2503 TH1D *h1=nullptr;
2504 //check if histogram with identical name exist
2505 TObject *h1obj = gROOT->FindObject(qname);
2506 if (h1obj) {
2507 h1 = dynamic_cast<TH1D*>(h1obj);
2508 if (!h1) {
2509 Error("DoQuantiles","Histogram with name %s must be a TH1D and is a %s",qname.Data(),h1obj->ClassName());
2510 return nullptr;
2511 }
2512 }
2513 if (h1) {
2514 h1->Reset();
2515 } else {
2516 // create the histogram
2517 h1 = new TH1D(qname, GetTitle(), 1, 0, 1);
2518 }
2519 // set the bin content
2520 Int_t firstOutBin = std::max(outAxis->GetFirst(),1);
2521 Int_t lastOutBin = std::max(outAxis->GetLast(),outAxis->GetNbins());
2522 const TArrayD *xbins = outAxis->GetXbins();
2523 if (xbins->fN == 0)
2524 h1->SetBins(lastOutBin-firstOutBin+1,outAxis->GetBinLowEdge(firstOutBin),outAxis->GetBinUpEdge(lastOutBin));
2525 else
2526 h1->SetBins(lastOutBin-firstOutBin+1,&xbins->fArray[firstOutBin-1]);
2527
2528 // set the bin content of the histogram
2529 Double_t pp[1];
2530 pp[0] = prob;
2531
2532 TH1D * slice = nullptr;
2533 for (int ibin = outAxis->GetFirst() ; ibin <= outAxis->GetLast() ; ++ibin) {
2534 Double_t qq[1];
2535 // do a projection on the opposite axis
2536 slice = DoProjection(!onX, "tmp",ibin,ibin,"");
2537 if (!slice) break;
2538 if (slice->GetSum() == 0) continue;
2539 slice->GetQuantiles(1,qq,pp);
2540 h1->SetBinContent(ibin,qq[0]);
2541 // compute error using normal approximation
2542 // quantile error ~ sqrt (q*(1-q)/ *( n * f(xq)^2 ) from Kendall
2543 // where f(xq) is the p.d.f value at the quantile xq
2544 Double_t n = slice->GetEffectiveEntries();
2545 Double_t f = TMath::Gaus(qq[0], slice->GetMean(), slice->GetStdDev(), kTRUE);
2546 Double_t error = 0;
2547 // set the errors to zero in case of small statistics
2548 if (f > 0 && n > 1)
2549 error = TMath::Sqrt( prob*(1.-prob)/ (n * f * f) );
2550 h1->SetBinError(ibin, error);
2551 }
2552 if (slice) delete slice;
2553 return h1;
2554}
2555
2556
2557////////////////////////////////////////////////////////////////////////////////
2558/// Reset this histogram: contents, errors, etc.
2559
2561{
2563 TString opt = option;
2564 opt.ToUpper();
2565
2566 if (opt.Contains("ICE") && !opt.Contains("S")) return;
2567 fTsumwy = 0;
2568 fTsumwy2 = 0;
2569 fTsumwxy = 0;
2570}
2571
2572
2573////////////////////////////////////////////////////////////////////////////////
2574/// Set bin content
2575
2577{
2578 fEntries++;
2579 fTsumw = 0;
2580 if (bin < 0) return;
2581 if (bin >= fNcells) return;
2583}
2584
2585
2586////////////////////////////////////////////////////////////////////////////////
2587/// When the mouse is moved in a pad containing a 2-d view of this histogram
2588/// a second canvas shows the projection along X corresponding to the
2589/// mouse position along Y.
2590/// To stop the generation of the projections, delete the canvas
2591/// containing the projection.
2592/// \param nbins number of bins in Y to sum across for the projection
2593
2595{
2596 GetPainter();
2597
2598 if (fPainter) fPainter->SetShowProjection("x",nbins);
2599}
2600
2601
2602////////////////////////////////////////////////////////////////////////////////
2603/// When the mouse is moved in a pad containing a 2-d view of this histogram
2604/// a second canvas shows the projection along Y corresponding to the
2605/// mouse position along X.
2606/// To stop the generation of the projections, delete the canvas
2607/// containing the projection.
2608/// \param nbins number of bins in X to sum across for the projection
2609
2611{
2612 GetPainter();
2613
2614 if (fPainter) fPainter->SetShowProjection("y",nbins);
2615}
2616
2617
2618////////////////////////////////////////////////////////////////////////////////
2619/// When the mouse is moved in a pad containing a 2-d view of this histogram
2620/// two canvases show the projection along X and Y corresponding to the
2621/// mouse position along Y and X, respectively.
2622/// To stop the generation of the projections, delete the canvas
2623/// containing the projection.
2624/// \param nbinsY number of bins in Y to sum across for the x projection
2625/// \param nbinsX number of bins in X to sum across for the y projection
2626
2632
2633
2634////////////////////////////////////////////////////////////////////////////////
2635/// This function calculates the background spectrum in this histogram.
2636/// The background is returned as a histogram.
2637/// to be implemented (may be)
2638
2640{
2641
2642 return (TH1 *)gROOT->ProcessLineFast(TString::Format("TSpectrum2::StaticBackground((TH1*)0x%zx,%d,\"%s\")",
2643 (size_t)this, niter, option).Data());
2644}
2645
2646
2647////////////////////////////////////////////////////////////////////////////////
2648///Interface to TSpectrum2::Search
2649///the function finds peaks in this histogram where the width is > sigma
2650///and the peak maximum greater than threshold*maximum bin content of this.
2651///for more details see TSpectrum::Search.
2652///note the difference in the default value for option compared to TSpectrum2::Search
2653///option="" by default (instead of "goff")
2654
2656{
2657
2658 return (Int_t)gROOT->ProcessLineFast(TString::Format("TSpectrum2::StaticSearch((TH1*)0x%zx,%g,\"%s\",%g)",
2659 (size_t)this, sigma, option, threshold).Data());
2660}
2661
2662
2663////////////////////////////////////////////////////////////////////////////////
2664/// Smooth bin contents of this 2-d histogram using kernel algorithms
2665/// similar to the ones used in the raster graphics community.
2666/// Bin contents in the active range are replaced by their smooth values.
2667/// The algorithm retains the input dimension by using Kernel Crop at the input boundaries.
2668/// Kernel Crop sets any pixel in the kernel that extends past the input to zero and adjusts the
2669/// normalization accordingly.
2670/// If Errors are defined via Sumw2, they are also scaled and computed.
2671/// However, note the resulting errors will be correlated between different-bins, so
2672/// the errors should not be used blindly to perform any calculation involving several bins,
2673/// like fitting the histogram. One would need to compute also the bin by bin correlation matrix.
2674///
2675/// 3 kernels are proposed k5a, k5b and k3a.
2676/// k5a and k5b act on 5x5 cells (i-2,i-1,i,i+1,i+2, and same for j)
2677/// k5b is a bit more stronger in smoothing
2678/// k3a acts only on 3x3 cells (i-1,i,i+1, and same for j).
2679/// By default the kernel "k5a" is used. You can select the kernels "k5b" or "k3a"
2680/// via the option argument.
2681/// If TAxis::SetRange has been called on the x or/and y axis, only the bins
2682/// in the specified range are smoothed.
2683/// In the current implementation if the first argument is not used (default value=1).
2684///
2685/// implementation by David McKee (dmckee@bama.ua.edu). Extended by Rene Brun
2686
2688{
2689 Double_t k5a[5][5] = { { 0, 0, 1, 0, 0 },
2690 { 0, 2, 2, 2, 0 },
2691 { 1, 2, 5, 2, 1 },
2692 { 0, 2, 2, 2, 0 },
2693 { 0, 0, 1, 0, 0 } };
2694 Double_t k5b[5][5] = { { 0, 1, 2, 1, 0 },
2695 { 1, 2, 4, 2, 1 },
2696 { 2, 4, 8, 4, 2 },
2697 { 1, 2, 4, 2, 1 },
2698 { 0, 1, 2, 1, 0 } };
2699 Double_t k3a[3][3] = { { 0, 1, 0 },
2700 { 1, 2, 1 },
2701 { 0, 1, 0 } };
2702
2703 if (ntimes > 1) {
2704 Warning("Smooth","Currently only ntimes=1 is supported");
2705 }
2706 TString opt = option;
2707 opt.ToLower();
2708 Int_t ksize_x=5;
2709 Int_t ksize_y=5;
2710 Double_t *kernel = &k5a[0][0];
2711 if (opt.Contains("k5b")) kernel = &k5b[0][0];
2712 if (opt.Contains("k3a")) {
2713 kernel = &k3a[0][0];
2714 ksize_x=3;
2715 ksize_y=3;
2716 }
2717
2718 // find i,j ranges
2723
2724 // Determine the size of the bin buffer(s) needed
2726 Int_t nx = GetNbinsX();
2727 Int_t ny = GetNbinsY();
2728 Int_t bufSize = (nx+2)*(ny+2);
2729 Double_t *buf = new Double_t[bufSize];
2730 Double_t *ebuf = nullptr;
2731 if (fSumw2.fN) ebuf = new Double_t[bufSize];
2732
2733 // Copy all the data to the temporary buffers
2734 Int_t i,j,bin;
2735 for (i=ifirst; i<=ilast; i++){
2736 for (j=jfirst; j<=jlast; j++){
2737 bin = GetBin(i,j);
2738 buf[bin] = RetrieveBinContent(bin);
2739 if (ebuf) ebuf[bin]=GetBinError(bin);
2740 }
2741 }
2742
2743 // Kernel tail sizes (kernel sizes must be odd for this to work!)
2744 Int_t x_push = (ksize_x-1)/2;
2745 Int_t y_push = (ksize_y-1)/2;
2746
2747 // main work loop
2748 for (i=ifirst; i<=ilast; i++){
2749 for (j=jfirst; j<=jlast; j++) {
2750 Double_t content = 0.0;
2751 Double_t error = 0.0;
2752 Double_t norm = 0.0;
2753
2754 for (Int_t n=0; n<ksize_x; n++) {
2755 for (Int_t m=0; m<ksize_y; m++) {
2756 Int_t xb = i+(n-x_push);
2757 Int_t yb = j+(m-y_push);
2758 if ( (xb >= 1) && (xb <= nx) && (yb >= 1) && (yb <= ny) ) {
2759 bin = GetBin(xb,yb);
2760 Double_t k = kernel[n*ksize_y +m];
2761 //if ( (k != 0.0 ) && (buf[bin] != 0.0) ) { // General version probably does not want the second condition
2762 if ( k != 0.0 ) {
2763 norm += k;
2764 content += k*buf[bin];
2765 if (ebuf) error += k*k*ebuf[bin]*ebuf[bin];
2766 }
2767 }
2768 }
2769 }
2770
2771 if ( norm != 0.0 ) {
2773 if (ebuf) {
2774 error /= (norm*norm);
2775 SetBinError(i,j,sqrt(error));
2776 }
2777 }
2778 }
2779 }
2781
2782 delete [] buf;
2783 delete [] ebuf;
2784}
2785
2786
2787////////////////////////////////////////////////////////////////////////////////
2788/// Stream an object of class TH2.
2789
2791{
2792 if (R__b.IsReading()) {
2793 UInt_t R__s, R__c;
2794 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
2795 if (R__v > 2) {
2796 R__b.ReadClassBuffer(TH2::Class(), this, R__v, R__s, R__c);
2797 return;
2798 }
2799 //====process old versions before automatic schema evolution
2801 R__b >> fScalefactor;
2802 R__b >> fTsumwy;
2803 R__b >> fTsumwy2;
2804 R__b >> fTsumwxy;
2805 //====end of old versions
2806
2807 } else {
2808 R__b.WriteClassBuffer(TH2::Class(),this);
2809 }
2810}
2811
2812
2813//______________________________________________________________________________
2814// TH2C methods
2815// TH2C a 2-D histogram with one byte per cell (char)
2816//______________________________________________________________________________
2817
2818
2819
2820////////////////////////////////////////////////////////////////////////////////
2821/// Constructor.
2822
2824{
2825 SetBinsLength(9);
2826 if (fgDefaultSumw2) Sumw2();
2827}
2828
2829
2830////////////////////////////////////////////////////////////////////////////////
2831/// Destructor.
2832
2834
2835
2836////////////////////////////////////////////////////////////////////////////////
2837/// Constructor
2838/// (see TH2::TH2 for explanation of parameters)
2839
2840TH2C::TH2C(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
2841 ,Int_t nbinsy,Double_t ylow,Double_t yup)
2842 :TH2(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup)
2843{
2845 if (fgDefaultSumw2) Sumw2();
2846
2847 if (xlow >= xup || ylow >= yup) SetBuffer(fgBufferSize);
2848}
2849
2850
2851////////////////////////////////////////////////////////////////////////////////
2852/// Constructor
2853/// (see TH2::TH2 for explanation of parameters)
2854
2855TH2C::TH2C(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
2856 ,Int_t nbinsy,Double_t ylow,Double_t yup)
2857 :TH2(name,title,nbinsx,xbins,nbinsy,ylow,yup)
2858{
2860 if (fgDefaultSumw2) Sumw2();
2861}
2862
2863
2864////////////////////////////////////////////////////////////////////////////////
2865/// Constructor
2866/// (see TH2::TH2 for explanation of parameters)
2867
2868TH2C::TH2C(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
2869 ,Int_t nbinsy,const Double_t *ybins)
2870 :TH2(name,title,nbinsx,xlow,xup,nbinsy,ybins)
2871{
2873 if (fgDefaultSumw2) Sumw2();
2874}
2875
2876
2877////////////////////////////////////////////////////////////////////////////////
2878/// Constructor
2879/// (see TH2::TH2 for explanation of parameters)
2880
2881TH2C::TH2C(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
2882 ,Int_t nbinsy,const Double_t *ybins)
2883 :TH2(name,title,nbinsx,xbins,nbinsy,ybins)
2884{
2886 if (fgDefaultSumw2) Sumw2();
2887}
2888
2889
2890////////////////////////////////////////////////////////////////////////////////
2891/// Constructor
2892/// (see TH2::TH2 for explanation of parameters)
2893
2894TH2C::TH2C(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
2895 ,Int_t nbinsy,const Float_t *ybins)
2896 :TH2(name,title,nbinsx,xbins,nbinsy,ybins)
2897{
2899 if (fgDefaultSumw2) Sumw2();
2900}
2901
2902
2903////////////////////////////////////////////////////////////////////////////////
2904/// Copy constructor.
2905/// The list of functions is not copied. (Use Clone() if needed)
2906
2908{
2909 h2c.TH2C::Copy(*this);
2910}
2911
2912
2913////////////////////////////////////////////////////////////////////////////////
2914/// Increment bin content by 1.
2915/// Passing an out-of-range bin leads to undefined behavior
2916
2918{
2919 if (fArray[bin] < 127) fArray[bin]++;
2920}
2921
2922
2923////////////////////////////////////////////////////////////////////////////////
2924/// Increment bin content by w.
2925/// \warning The value of w is cast to `Int_t` before being added.
2926/// Passing an out-of-range bin leads to undefined behavior
2927
2929{
2930 Int_t newval = fArray[bin] + Int_t(w);
2931 if (newval > -128 && newval < 128) {fArray[bin] = Char_t(newval); return;}
2932 if (newval < -127) fArray[bin] = -127;
2933 if (newval > 127) fArray[bin] = 127;
2934}
2935
2936
2937////////////////////////////////////////////////////////////////////////////////
2938/// Copy.
2939
2941{
2943}
2944
2945
2946////////////////////////////////////////////////////////////////////////////////
2947/// Reset this histogram: contents, errors, etc.
2948
2950{
2953}
2954
2955
2956////////////////////////////////////////////////////////////////////////////////
2957/// Set total number of bins including under/overflow
2958/// Reallocate bin contents array
2959
2961{
2962 if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2);
2963 fNcells = n;
2964 TArrayC::Set(n);
2965}
2966
2967
2968////////////////////////////////////////////////////////////////////////////////
2969/// Stream an object of class TH2C.
2970
2972{
2973 if (R__b.IsReading()) {
2974 UInt_t R__s, R__c;
2975 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
2976 if (R__v > 2) {
2977 R__b.ReadClassBuffer(TH2C::Class(), this, R__v, R__s, R__c);
2978 return;
2979 }
2980 //====process old versions before automatic schema evolution
2981 if (R__v < 2) {
2982 R__b.ReadVersion();
2985 R__b.ReadVersion();
2986 R__b >> fScalefactor;
2987 R__b >> fTsumwy;
2988 R__b >> fTsumwy2;
2989 R__b >> fTsumwxy;
2990 } else {
2993 R__b.CheckByteCount(R__s, R__c, TH2C::IsA());
2994 }
2995 //====end of old versions
2996
2997 } else {
2998 R__b.WriteClassBuffer(TH2C::Class(),this);
2999 }
3000}
3001
3002
3003////////////////////////////////////////////////////////////////////////////////
3004/// Operator =
3005
3007{
3008 if (this != &h2c)
3009 h2c.TH2C::Copy(*this);
3010 return *this;
3011}
3012
3013
3014////////////////////////////////////////////////////////////////////////////////
3015/// Operator *
3016
3018{
3019 TH2C hnew = h1;
3020 hnew.Scale(c1);
3021 hnew.SetDirectory(nullptr);
3022 return hnew;
3023}
3024
3025
3026////////////////////////////////////////////////////////////////////////////////
3027/// Operator +
3028
3029TH2C operator+(TH2C const &h1, TH2C const &h2)
3030{
3031 TH2C hnew = h1;
3032 hnew.Add(&h2,1);
3033 hnew.SetDirectory(nullptr);
3034 return hnew;
3035}
3036
3037
3038////////////////////////////////////////////////////////////////////////////////
3039/// Operator -
3040
3041TH2C operator-(TH2C const &h1, TH2C const &h2)
3042{
3043 TH2C hnew = h1;
3044 hnew.Add(&h2,-1);
3045 hnew.SetDirectory(nullptr);
3046 return hnew;
3047}
3048
3049
3050////////////////////////////////////////////////////////////////////////////////
3051/// Operator *
3052
3053TH2C operator*(TH2C const &h1, TH2C const &h2)
3054{
3055 TH2C hnew = h1;
3056 hnew.Multiply(&h2);
3057 hnew.SetDirectory(nullptr);
3058 return hnew;
3059}
3060
3061
3062////////////////////////////////////////////////////////////////////////////////
3063/// Operator /
3064
3065TH2C operator/(TH2C const &h1, TH2C const &h2)
3066{
3067 TH2C hnew = h1;
3068 hnew.Divide(&h2);
3069 hnew.SetDirectory(nullptr);
3070 return hnew;
3071}
3072
3073
3074//______________________________________________________________________________
3075// TH2S methods
3076// TH2S a 2-D histogram with two bytes per cell (short integer)
3077//______________________________________________________________________________
3078
3079
3080
3081////////////////////////////////////////////////////////////////////////////////
3082/// Constructor.
3083
3085{
3086 SetBinsLength(9);
3087 if (fgDefaultSumw2) Sumw2();
3088}
3089
3090
3091////////////////////////////////////////////////////////////////////////////////
3092/// Destructor.
3093
3095{
3096}
3097
3098
3099////////////////////////////////////////////////////////////////////////////////
3100/// Constructor
3101/// (see TH2::TH2 for explanation of parameters)
3102
3103TH2S::TH2S(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3104 ,Int_t nbinsy,Double_t ylow,Double_t yup)
3105 :TH2(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup)
3106{
3108 if (fgDefaultSumw2) Sumw2();
3109
3110 if (xlow >= xup || ylow >= yup) SetBuffer(fgBufferSize);
3111}
3112
3113
3114////////////////////////////////////////////////////////////////////////////////
3115/// Constructor
3116/// (see TH2::TH2 for explanation of parameters)
3117
3118TH2S::TH2S(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
3119 ,Int_t nbinsy,Double_t ylow,Double_t yup)
3120 :TH2(name,title,nbinsx,xbins,nbinsy,ylow,yup)
3121{
3123 if (fgDefaultSumw2) Sumw2();
3124}
3125
3126
3127////////////////////////////////////////////////////////////////////////////////
3128/// Constructor
3129/// (see TH2::TH2 for explanation of parameters)
3130
3131TH2S::TH2S(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3132 ,Int_t nbinsy,const Double_t *ybins)
3133 :TH2(name,title,nbinsx,xlow,xup,nbinsy,ybins)
3134{
3136 if (fgDefaultSumw2) Sumw2();
3137}
3138
3139
3140////////////////////////////////////////////////////////////////////////////////
3141/// Constructor
3142/// (see TH2::TH2 for explanation of parameters)
3143
3144TH2S::TH2S(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
3145 ,Int_t nbinsy,const Double_t *ybins)
3146 :TH2(name,title,nbinsx,xbins,nbinsy,ybins)
3147{
3149 if (fgDefaultSumw2) Sumw2();
3150}
3151
3152
3153////////////////////////////////////////////////////////////////////////////////
3154/// Constructor
3155/// (see TH2::TH2 for explanation of parameters)
3156
3157TH2S::TH2S(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
3158 ,Int_t nbinsy,const Float_t *ybins)
3159 :TH2(name,title,nbinsx,xbins,nbinsy,ybins)
3160{
3162 if (fgDefaultSumw2) Sumw2();
3163}
3164
3165
3166////////////////////////////////////////////////////////////////////////////////
3167/// Copy constructor
3168/// The list of functions is not copied. (Use Clone() if needed)
3169
3171{
3172 h2s.TH2S::Copy(*this);
3173}
3174
3175
3176////////////////////////////////////////////////////////////////////////////////
3177/// Increment bin content by 1.
3178/// Passing an out-of-range bin leads to undefined behavior
3179
3181{
3182 if (fArray[bin] < 32767) fArray[bin]++;
3183}
3184
3185
3186////////////////////////////////////////////////////////////////////////////////
3187/// Increment bin content by w.
3188/// \warning The value of w is cast to `Int_t` before being added.
3189/// Passing an out-of-range bin leads to undefined behavior
3190
3192{
3193 Int_t newval = fArray[bin] + Int_t(w);
3194 if (newval > -32768 && newval < 32768) {fArray[bin] = Short_t(newval); return;}
3195 if (newval < -32767) fArray[bin] = -32767;
3196 if (newval > 32767) fArray[bin] = 32767;
3197}
3198
3199
3200////////////////////////////////////////////////////////////////////////////////
3201/// Copy.
3202
3204{
3206}
3207
3208
3209////////////////////////////////////////////////////////////////////////////////
3210/// Reset this histogram: contents, errors, etc.
3211
3213{
3216}
3217
3218
3219////////////////////////////////////////////////////////////////////////////////
3220/// Set total number of bins including under/overflow
3221/// Reallocate bin contents array
3222
3224{
3225 if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2);
3226 fNcells = n;
3227 TArrayS::Set(n);
3228}
3229
3230
3231////////////////////////////////////////////////////////////////////////////////
3232/// Stream an object of class TH2S.
3233
3235{
3236 if (R__b.IsReading()) {
3237 UInt_t R__s, R__c;
3238 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
3239 if (R__v > 2) {
3240 R__b.ReadClassBuffer(TH2S::Class(), this, R__v, R__s, R__c);
3241 return;
3242 }
3243 //====process old versions before automatic schema evolution
3244 if (R__v < 2) {
3245 R__b.ReadVersion();
3248 R__b.ReadVersion();
3249 R__b >> fScalefactor;
3250 R__b >> fTsumwy;
3251 R__b >> fTsumwy2;
3252 R__b >> fTsumwxy;
3253 } else {
3256 R__b.CheckByteCount(R__s, R__c, TH2S::IsA());
3257 }
3258 //====end of old versions
3259
3260 } else {
3261 R__b.WriteClassBuffer(TH2S::Class(),this);
3262 }
3263}
3264
3265
3266////////////////////////////////////////////////////////////////////////////////
3267/// Operator =
3268
3270{
3271 if (this != &h2s)
3272 h2s.TH2S::Copy(*this);
3273 return *this;
3274}
3275
3276
3277////////////////////////////////////////////////////////////////////////////////
3278/// Operator *
3279
3281{
3282 TH2S hnew = h2s;
3283 hnew.Scale(c1);
3284 hnew.SetDirectory(nullptr);
3285 return hnew;
3286}
3287
3288
3289////////////////////////////////////////////////////////////////////////////////
3290/// Operator +
3291
3292TH2S operator+(TH2S const &h1, TH2S const &h2)
3293{
3294 TH2S hnew = h1;
3295 hnew.Add(&h2,1);
3296 hnew.SetDirectory(nullptr);
3297 return hnew;
3298}
3299
3300
3301////////////////////////////////////////////////////////////////////////////////
3302/// Operator -
3303
3304TH2S operator-(TH2S const &h1, TH2S const &h2)
3305{
3306 TH2S hnew = h1;
3307 hnew.Add(&h2,-1);
3308 hnew.SetDirectory(nullptr);
3309 return hnew;
3310}
3311
3312
3313////////////////////////////////////////////////////////////////////////////////
3314/// Operator *
3315
3316TH2S operator*(TH2S const &h1, TH2S const &h2)
3317{
3318 TH2S hnew = h1;
3319 hnew.Multiply(&h2);
3320 hnew.SetDirectory(nullptr);
3321 return hnew;
3322}
3323
3324
3325////////////////////////////////////////////////////////////////////////////////
3326/// Operator /
3327
3328TH2S operator/(TH2S const &h1, TH2S const &h2)
3329{
3330 TH2S hnew = h1;
3331 hnew.Divide(&h2);
3332 hnew.SetDirectory(nullptr);
3333 return hnew;
3334}
3335
3336
3337//______________________________________________________________________________
3338// TH2I methods
3339// TH2I a 2-D histogram with four bytes per cell (32 bit integer)
3340//______________________________________________________________________________
3341
3342
3343
3344////////////////////////////////////////////////////////////////////////////////
3345/// Constructor.
3346
3348{
3349 SetBinsLength(9);
3350 if (fgDefaultSumw2) Sumw2();
3351}
3352
3353
3354////////////////////////////////////////////////////////////////////////////////
3355/// Destructor.
3356
3358{
3359}
3360
3361
3362////////////////////////////////////////////////////////////////////////////////
3363/// Constructor
3364/// (see TH2::TH2 for explanation of parameters)
3365
3366TH2I::TH2I(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3367 ,Int_t nbinsy,Double_t ylow,Double_t yup)
3368 :TH2(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup)
3369{
3371 if (fgDefaultSumw2) Sumw2();
3372
3373 if (xlow >= xup || ylow >= yup) SetBuffer(fgBufferSize);
3374}
3375
3376
3377////////////////////////////////////////////////////////////////////////////////
3378/// Constructor
3379/// (see TH2::TH2 for explanation of parameters)
3380
3381TH2I::TH2I(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
3382 ,Int_t nbinsy,Double_t ylow,Double_t yup)
3383 :TH2(name,title,nbinsx,xbins,nbinsy,ylow,yup)
3384{
3386 if (fgDefaultSumw2) Sumw2();
3387}
3388
3389
3390////////////////////////////////////////////////////////////////////////////////
3391/// Constructor
3392/// (see TH2::TH2 for explanation of parameters)
3393
3394TH2I::TH2I(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3395 ,Int_t nbinsy,const Double_t *ybins)
3396 :TH2(name,title,nbinsx,xlow,xup,nbinsy,ybins)
3397{
3399 if (fgDefaultSumw2) Sumw2();
3400}
3401
3402
3403////////////////////////////////////////////////////////////////////////////////
3404/// Constructor
3405/// (see TH2::TH2 for explanation of parameters)
3406
3407TH2I::TH2I(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
3408 ,Int_t nbinsy,const Double_t *ybins)
3409 :TH2(name,title,nbinsx,xbins,nbinsy,ybins)
3410{
3412 if (fgDefaultSumw2) Sumw2();
3413}
3414
3415
3416////////////////////////////////////////////////////////////////////////////////
3417/// Constructor
3418/// (see TH2::TH2 for explanation of parameters)
3419
3420TH2I::TH2I(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
3421 ,Int_t nbinsy,const Float_t *ybins)
3422 :TH2(name,title,nbinsx,xbins,nbinsy,ybins)
3423{
3425 if (fgDefaultSumw2) Sumw2();
3426}
3427
3428
3429////////////////////////////////////////////////////////////////////////////////
3430/// Copy constructor.
3431/// The list of functions is not copied. (Use Clone() if needed)
3432
3434{
3435 h2i.TH2I::Copy(*this);
3436}
3437
3438
3439////////////////////////////////////////////////////////////////////////////////
3440/// Increment bin content by 1.
3441/// Passing an out-of-range bin leads to undefined behavior
3442
3444{
3445 if (fArray[bin] < INT_MAX) fArray[bin]++;
3446}
3447
3448
3449////////////////////////////////////////////////////////////////////////////////
3450/// Increment bin content by w.
3451/// \warning The value of w is cast to `Long64_t` before being added.
3452/// Passing an out-of-range bin leads to undefined behavior
3453
3455{
3456 Long64_t newval = fArray[bin] + Long64_t(w);
3457 if (newval > -INT_MAX && newval < INT_MAX) {fArray[bin] = Int_t(newval); return;}
3458 if (newval < -INT_MAX) fArray[bin] = -INT_MAX;
3459 if (newval > INT_MAX) fArray[bin] = INT_MAX;
3460}
3461
3462
3463////////////////////////////////////////////////////////////////////////////////
3464/// Copy.
3465
3467{
3469}
3470
3471
3472////////////////////////////////////////////////////////////////////////////////
3473/// Reset this histogram: contents, errors, etc.
3474
3476{
3479}
3480
3481
3482////////////////////////////////////////////////////////////////////////////////
3483/// Set total number of bins including under/overflow
3484/// Reallocate bin contents array
3485
3487{
3488 if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2);
3489 fNcells = n;
3490 TArrayI::Set(n);
3491}
3492
3493
3494////////////////////////////////////////////////////////////////////////////////
3495/// Operator =
3496
3498{
3499 if (this != &h2i)
3500 h2i.TH2I::Copy(*this);
3501 return *this;
3502}
3503
3504
3505////////////////////////////////////////////////////////////////////////////////
3506/// Operator *
3507
3509{
3510 TH2I hnew = h2i;
3511 hnew.Scale(c1);
3512 hnew.SetDirectory(nullptr);
3513 return hnew;
3514}
3515
3516
3517////////////////////////////////////////////////////////////////////////////////
3518/// Operator +
3519
3520TH2I operator+(TH2I const &h1, TH2I const &h2)
3521{
3522 TH2I hnew = h1;
3523 hnew.Add(&h2,1);
3524 hnew.SetDirectory(nullptr);
3525 return hnew;
3526}
3527
3528
3529////////////////////////////////////////////////////////////////////////////////
3530/// Operator -
3531
3532TH2I operator-(TH2I const &h1, TH2I const &h2)
3533{
3534 TH2I hnew = h1;
3535 hnew.Add(&h2,-1);
3536 hnew.SetDirectory(nullptr);
3537 return hnew;
3538}
3539
3540
3541////////////////////////////////////////////////////////////////////////////////
3542/// Operator *
3543
3544TH2I operator*(TH2I const &h1, TH2I const &h2)
3545{
3546 TH2I hnew = h1;
3547 hnew.Multiply(&h2);
3548 hnew.SetDirectory(nullptr);
3549 return hnew;
3550}
3551
3552
3553////////////////////////////////////////////////////////////////////////////////
3554/// Operator /
3555
3556TH2I operator/(TH2I const &h1, TH2I const &h2)
3557{
3558 TH2I hnew = h1;
3559 hnew.Divide(&h2);
3560 hnew.SetDirectory(nullptr);
3561 return hnew;
3562}
3563
3564
3565//______________________________________________________________________________
3566// TH2L methods
3567// TH2L a 2-D histogram with eight bytes per cell (64 bit integer)
3568//______________________________________________________________________________
3569
3570
3571
3572////////////////////////////////////////////////////////////////////////////////
3573/// Constructor.
3574
3576{
3577 SetBinsLength(9);
3578 if (fgDefaultSumw2) Sumw2();
3579}
3580
3581
3582////////////////////////////////////////////////////////////////////////////////
3583/// Destructor.
3584
3586{
3587}
3588
3589
3590////////////////////////////////////////////////////////////////////////////////
3591/// Constructor
3592/// (see TH2::TH2 for explanation of parameters)
3593
3594TH2L::TH2L(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3595 ,Int_t nbinsy,Double_t ylow,Double_t yup)
3596 :TH2(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup)
3597{
3599 if (fgDefaultSumw2) Sumw2();
3600
3601 if (xlow >= xup || ylow >= yup) SetBuffer(fgBufferSize);
3602}
3603
3604
3605////////////////////////////////////////////////////////////////////////////////
3606/// Constructor
3607/// (see TH2::TH2 for explanation of parameters)
3608
3609TH2L::TH2L(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
3610 ,Int_t nbinsy,Double_t ylow,Double_t yup)
3611 :TH2(name,title,nbinsx,xbins,nbinsy,ylow,yup)
3612{
3614 if (fgDefaultSumw2) Sumw2();
3615}
3616
3617
3618////////////////////////////////////////////////////////////////////////////////
3619/// Constructor
3620/// (see TH2::TH2 for explanation of parameters)
3621
3622TH2L::TH2L(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3623 ,Int_t nbinsy,const Double_t *ybins)
3624 :TH2(name,title,nbinsx,xlow,xup,nbinsy,ybins)
3625{
3627 if (fgDefaultSumw2) Sumw2();
3628}
3629
3630
3631////////////////////////////////////////////////////////////////////////////////
3632/// Constructor
3633/// (see TH2::TH2 for explanation of parameters)
3634
3635TH2L::TH2L(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
3636 ,Int_t nbinsy,const Double_t *ybins)
3637 :TH2(name,title,nbinsx,xbins,nbinsy,ybins)
3638{
3640 if (fgDefaultSumw2) Sumw2();
3641}
3642
3643
3644////////////////////////////////////////////////////////////////////////////////
3645/// Constructor
3646/// (see TH2::TH2 for explanation of parameters)
3647
3648TH2L::TH2L(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
3649 ,Int_t nbinsy,const Float_t *ybins)
3650 :TH2(name,title,nbinsx,xbins,nbinsy,ybins)
3651{
3653 if (fgDefaultSumw2) Sumw2();
3654}
3655
3656
3657////////////////////////////////////////////////////////////////////////////////
3658/// Copy constructor.
3659/// The list of functions is not copied. (Use Clone() if needed)
3660
3662{
3663 h2l.TH2L::Copy(*this);
3664}
3665
3666
3667////////////////////////////////////////////////////////////////////////////////
3668/// Increment bin content by 1.
3669/// Passing an out-of-range bin leads to undefined behavior
3670
3672{
3673 if (fArray[bin] < LLONG_MAX) fArray[bin]++;
3674}
3675
3676
3677////////////////////////////////////////////////////////////////////////////////
3678/// Increment bin content by w.
3679/// \warning The value of w is cast to `Long64_t` before being added.
3680/// Passing an out-of-range bin leads to undefined behavior
3681
3683{
3684 Long64_t newval = fArray[bin] + Long64_t(w);
3685 if (newval > -LLONG_MAX && newval < LLONG_MAX) {fArray[bin] = Int_t(newval); return;}
3686 if (newval < -LLONG_MAX) fArray[bin] = -LLONG_MAX;
3687 if (newval > LLONG_MAX) fArray[bin] = LLONG_MAX;
3688}
3689
3690
3691////////////////////////////////////////////////////////////////////////////////
3692/// Copy.
3693
3695{
3697}
3698
3699
3700////////////////////////////////////////////////////////////////////////////////
3701/// Reset this histogram: contents, errors, etc.
3702
3708
3709
3710////////////////////////////////////////////////////////////////////////////////
3711/// Set total number of bins including under/overflow
3712/// Reallocate bin contents array
3713
3715{
3716 if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2);
3717 fNcells = n;
3719}
3720
3721
3722////////////////////////////////////////////////////////////////////////////////
3723/// Operator =
3724
3726{
3727 if (this != &h2l)
3728 h2l.TH2L::Copy(*this);
3729 return *this;
3730}
3731
3732
3733////////////////////////////////////////////////////////////////////////////////
3734/// Operator *
3735
3737{
3738 TH2L hnew = h1;
3739 hnew.Scale(c1);
3740 hnew.SetDirectory(nullptr);
3741 return hnew;
3742}
3743
3744
3745////////////////////////////////////////////////////////////////////////////////
3746/// Operator +
3747
3748TH2L operator+(TH2L const &h1, TH2L const &h2)
3749{
3750 TH2L hnew = h1;
3751 hnew.Add(&h2,1);
3752 hnew.SetDirectory(nullptr);
3753 return hnew;
3754}
3755
3756
3757////////////////////////////////////////////////////////////////////////////////
3758/// Operator -
3759
3760TH2L operator-(TH2L const &h1, TH2L const &h2)
3761{
3762 TH2L hnew = h1;
3763 hnew.Add(&h2,-1);
3764 hnew.SetDirectory(nullptr);
3765 return hnew;
3766}
3767
3768
3769////////////////////////////////////////////////////////////////////////////////
3770/// Operator *
3771
3772TH2L operator*(TH2L const &h1, TH2L const &h2)
3773{
3774 TH2L hnew = h1;
3775 hnew.Multiply(&h2);
3776 hnew.SetDirectory(nullptr);
3777 return hnew;
3778}
3779
3780
3781////////////////////////////////////////////////////////////////////////////////
3782/// Operator /
3783
3784TH2L operator/(TH2L const &h1, TH2L const &h2)
3785{
3786 TH2L hnew = h1;
3787 hnew.Divide(&h2);
3788 hnew.SetDirectory(nullptr);
3789 return hnew;
3790}
3791
3792
3793//______________________________________________________________________________
3794// TH2F methods
3795// TH2F a 2-D histogram with four bytes per cell (float). Maximum precision 7 digits, maximum integer bin content = +/-16777216
3796//______________________________________________________________________________
3797
3798
3799
3800////////////////////////////////////////////////////////////////////////////////
3801/// Constructor.
3802
3804{
3805 SetBinsLength(9);
3806 if (fgDefaultSumw2) Sumw2();
3807}
3808
3809
3810////////////////////////////////////////////////////////////////////////////////
3811/// Destructor.
3812
3814{
3815}
3816
3817
3818////////////////////////////////////////////////////////////////////////////////
3819/// Constructor
3820/// (see TH2::TH2 for explanation of parameters)
3821
3822TH2F::TH2F(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3823 ,Int_t nbinsy,Double_t ylow,Double_t yup)
3824 :TH2(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup)
3825{
3827 if (fgDefaultSumw2) Sumw2();
3828
3829 if (xlow >= xup || ylow >= yup) SetBuffer(fgBufferSize);
3830}
3831
3832
3833////////////////////////////////////////////////////////////////////////////////
3834/// Constructor
3835/// (see TH2::TH2 for explanation of parameters)
3836
3837TH2F::TH2F(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
3838 ,Int_t nbinsy,Double_t ylow,Double_t yup)
3839 :TH2(name,title,nbinsx,xbins,nbinsy,ylow,yup)
3840{
3842 if (fgDefaultSumw2) Sumw2();
3843}
3844
3845
3846////////////////////////////////////////////////////////////////////////////////
3847/// Constructor
3848/// (see TH2::TH2 for explanation of parameters)
3849
3850TH2F::TH2F(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
3851 ,Int_t nbinsy,const Double_t *ybins)
3852 :TH2(name,title,nbinsx,xlow,xup,nbinsy,ybins)
3853{
3855 if (fgDefaultSumw2) Sumw2();
3856}
3857
3858
3859////////////////////////////////////////////////////////////////////////////////
3860/// Constructor
3861/// (see TH2::TH2 for explanation of parameters)
3862
3863TH2F::TH2F(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
3864 ,Int_t nbinsy,const Double_t *ybins)
3865 :TH2(name,title,nbinsx,xbins,nbinsy,ybins)
3866{
3868 if (fgDefaultSumw2) Sumw2();
3869}
3870
3871
3872////////////////////////////////////////////////////////////////////////////////
3873/// Constructor
3874/// (see TH2::TH2 for explanation of parameters)
3875
3876TH2F::TH2F(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
3877 ,Int_t nbinsy,const Float_t *ybins)
3878 :TH2(name,title,nbinsx,xbins,nbinsy,ybins)
3879{
3881 if (fgDefaultSumw2) Sumw2();
3882}
3883
3884
3885////////////////////////////////////////////////////////////////////////////////
3886/// Constructor.
3887/// Construct a TH2F from a TMatrixFBase
3888
3890:TH2("TMatrixFBase","",m.GetNcols(),m.GetColLwb(),1+m.GetColUpb(),m.GetNrows(),m.GetRowLwb(),1+m.GetRowUpb())
3891{
3893 Int_t ilow = m.GetRowLwb();
3894 Int_t iup = m.GetRowUpb();
3895 Int_t jlow = m.GetColLwb();
3896 Int_t jup = m.GetColUpb();
3897 for (Int_t i=ilow;i<=iup;i++) {
3898 for (Int_t j=jlow;j<=jup;j++) {
3899 SetBinContent(j-jlow+1,i-ilow+1,m(i,j));
3900 }
3901 }
3902}
3903
3904
3905////////////////////////////////////////////////////////////////////////////////
3906/// Copy constructor.
3907/// The list of functions is not copied. (Use Clone() if needed)
3908
3910{
3911 h2f.TH2F::Copy(*this);
3912}
3913
3914
3915////////////////////////////////////////////////////////////////////////////////
3916/// Copy.
3917
3919{
3921}
3922
3923
3924////////////////////////////////////////////////////////////////////////////////
3925/// Reset this histogram: contents, errors, etc.
3926
3928{
3931}
3932
3933
3934////////////////////////////////////////////////////////////////////////////////
3935/// Set total number of bins including under/overflow
3936/// Reallocate bin contents array
3937
3939{
3940 if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2);
3941 fNcells = n;
3942 TArrayF::Set(n);
3943}
3944
3945
3946////////////////////////////////////////////////////////////////////////////////
3947/// Stream an object of class TH2F.
3948
3950{
3951 if (R__b.IsReading()) {
3952 UInt_t R__s, R__c;
3953 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
3954 if (R__v > 2) {
3955 R__b.ReadClassBuffer(TH2F::Class(), this, R__v, R__s, R__c);
3956 return;
3957 }
3958 //====process old versions before automatic schema evolution
3959 if (R__v < 2) {
3960 R__b.ReadVersion();
3963 R__b.ReadVersion();
3964 R__b >> fScalefactor;
3965 R__b >> fTsumwy;
3966 R__b >> fTsumwy2;
3967 R__b >> fTsumwxy;
3968 } else {
3971 R__b.CheckByteCount(R__s, R__c, TH2F::IsA());
3972 }
3973 //====end of old versions
3974
3975 } else {
3976 R__b.WriteClassBuffer(TH2F::Class(),this);
3977 }
3978}
3979
3980
3981////////////////////////////////////////////////////////////////////////////////
3982/// Operator =
3983
3985{
3986 if (this != &h2f)
3987 h2f.TH2F::Copy(*this);
3988 return *this;
3989}
3990
3991
3992////////////////////////////////////////////////////////////////////////////////
3993/// Operator *
3994
3996{
3997 TH2F hnew = h1;
3998 hnew.Scale(c1);
3999 hnew.SetDirectory(nullptr);
4000 return hnew;
4001}
4002
4003
4004////////////////////////////////////////////////////////////////////////////////
4005/// Operator *
4006
4008{
4009 TH2F hnew = h1;
4010 hnew.Scale(c1);
4011 hnew.SetDirectory(nullptr);
4012 return hnew;
4013}
4014
4015
4016////////////////////////////////////////////////////////////////////////////////
4017/// Operator +
4018
4019TH2F operator+(TH2F const &h1, TH2F const &h2)
4020{
4021 TH2F hnew = h1;
4022 hnew.Add(&h2,1);
4023 hnew.SetDirectory(nullptr);
4024 return hnew;
4025}
4026
4027
4028////////////////////////////////////////////////////////////////////////////////
4029/// Operator -
4030
4031TH2F operator-(TH2F const &h1, TH2F const &h2)
4032{
4033 TH2F hnew = h1;
4034 hnew.Add(&h2,-1);
4035 hnew.SetDirectory(nullptr);
4036 return hnew;
4037}
4038
4039
4040////////////////////////////////////////////////////////////////////////////////
4041/// Operator *
4042
4043TH2F operator*(TH2F const &h1, TH2F const &h2)
4044{
4045 TH2F hnew = h1;
4046 hnew.Multiply(&h2);
4047 hnew.SetDirectory(nullptr);
4048 return hnew;
4049}
4050
4051
4052////////////////////////////////////////////////////////////////////////////////
4053/// Operator /
4054
4055TH2F operator/(TH2F const &h1, TH2F const &h2)
4056{
4057 TH2F hnew = h1;
4058 hnew.Divide(&h2);
4059 hnew.SetDirectory(nullptr);
4060 return hnew;
4061}
4062
4063
4064//______________________________________________________________________________
4065// TH2D methods
4066// TH2D a 2-D histogram with eight bytes per cell (double). Maximum precision 14 digits, maximum integer bin content = +/-9007199254740992
4067//______________________________________________________________________________
4068
4069
4070
4071////////////////////////////////////////////////////////////////////////////////
4072/// Constructor.
4073
4075{
4076 SetBinsLength(9);
4077 if (fgDefaultSumw2) Sumw2();
4078}
4079
4080
4081////////////////////////////////////////////////////////////////////////////////
4082/// Destructor.
4083
4085{
4086}
4087
4088
4089////////////////////////////////////////////////////////////////////////////////
4090/// Constructor
4091/// (see TH2::TH2 for explanation of parameters)
4092
4093TH2D::TH2D(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
4094 ,Int_t nbinsy,Double_t ylow,Double_t yup)
4095 :TH2(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup)
4096{
4098 if (fgDefaultSumw2) Sumw2();
4099
4100 if (xlow >= xup || ylow >= yup) SetBuffer(fgBufferSize);
4101}
4102
4103
4104////////////////////////////////////////////////////////////////////////////////
4105/// Constructor
4106/// (see TH2::TH2 for explanation of parameters)
4107
4108TH2D::TH2D(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
4109 ,Int_t nbinsy,Double_t ylow,Double_t yup)
4110 :TH2(name,title,nbinsx,xbins,nbinsy,ylow,yup)
4111{
4113 if (fgDefaultSumw2) Sumw2();
4114}
4115
4116
4117////////////////////////////////////////////////////////////////////////////////
4118/// Constructor
4119/// (see TH2::TH2 for explanation of parameters)
4120
4121TH2D::TH2D(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
4122 ,Int_t nbinsy,const Double_t *ybins)
4123 :TH2(name,title,nbinsx,xlow,xup,nbinsy,ybins)
4124{
4126 if (fgDefaultSumw2) Sumw2();
4127}
4128
4129
4130////////////////////////////////////////////////////////////////////////////////
4131/// Constructor
4132/// (see TH2::TH2 for explanation of parameters)
4133
4134TH2D::TH2D(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
4135 ,Int_t nbinsy,const Double_t *ybins)
4136 :TH2(name,title,nbinsx,xbins,nbinsy,ybins)
4137{
4139 if (fgDefaultSumw2) Sumw2();
4140}
4141
4142
4143////////////////////////////////////////////////////////////////////////////////
4144/// Constructor
4145/// (see TH2::TH2 for explanation of parameters)
4146
4147TH2D::TH2D(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins
4148 ,Int_t nbinsy,const Float_t *ybins)
4149 :TH2(name,title,nbinsx,xbins,nbinsy,ybins)
4150{
4152 if (fgDefaultSumw2) Sumw2();
4153}
4154
4155
4156////////////////////////////////////////////////////////////////////////////////
4157/// Constructor
4158/// Construct a 2-D histogram from a TMatrixDBase
4159
4161:TH2("TMatrixDBase","",m.GetNcols(),m.GetColLwb(),1+m.GetColUpb(),m.GetNrows(),m.GetRowLwb(),1+m.GetRowUpb())
4162{
4164 Int_t ilow = m.GetRowLwb();
4165 Int_t iup = m.GetRowUpb();
4166 Int_t jlow = m.GetColLwb();
4167 Int_t jup = m.GetColUpb();
4168 for (Int_t i=ilow;i<=iup;i++) {
4169 for (Int_t j=jlow;j<=jup;j++) {
4170 SetBinContent(j-jlow+1,i-ilow+1,m(i,j));
4171 }
4172 }
4173 if (fgDefaultSumw2) Sumw2();
4174}
4175
4176
4177////////////////////////////////////////////////////////////////////////////////
4178/// Copy constructor.
4179/// The list of functions is not copied. (Use Clone() if needed)
4180
4182{
4183 // intentionally call virtual Copy method to warn if TProfile2D is copied
4184 h2d.Copy(*this);
4185}
4186
4187
4188////////////////////////////////////////////////////////////////////////////////
4189/// Copy.
4190
4192{
4194}
4195
4196
4197////////////////////////////////////////////////////////////////////////////////
4198/// Reset this histogram: contents, errors, etc.
4199
4201{
4204}
4205
4206
4207////////////////////////////////////////////////////////////////////////////////
4208/// Set total number of bins including under/overflow
4209/// Reallocate bin contents array
4210
4212{
4213 if (n < 0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2);
4214 fNcells = n;
4215 TArrayD::Set(n);
4216}
4217
4218
4219////////////////////////////////////////////////////////////////////////////////
4220/// Stream an object of class TH2D.
4221
4223{
4224 if (R__b.IsReading()) {
4225 UInt_t R__s, R__c;
4226 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
4227 if (R__v > 2) {
4228 R__b.ReadClassBuffer(TH2D::Class(), this, R__v, R__s, R__c);
4229 return;
4230 }
4231 //====process old versions before automatic schema evolution
4232 if (R__v < 2) {
4233 R__b.ReadVersion();
4236 R__b.ReadVersion();
4237 R__b >> fScalefactor;
4238 R__b >> fTsumwy;
4239 R__b >> fTsumwy2;
4240 R__b >> fTsumwxy;
4241 } else {
4244 R__b.CheckByteCount(R__s, R__c, TH2D::IsA());
4245 }
4246 //====end of old versions
4247
4248 } else {
4249 R__b.WriteClassBuffer(TH2D::Class(),this);
4250 }
4251}
4252
4253
4254////////////////////////////////////////////////////////////////////////////////
4255/// Operator =
4256
4258{
4259 // intentionally call virtual Copy method to warn if TProfile2D is copied
4260 if (this != &h2d)
4261 h2d.Copy(*this);
4262 return *this;
4263}
4264
4265
4266
4267////////////////////////////////////////////////////////////////////////////////
4268/// Operator *
4269
4271{
4272 TH2D hnew = h2d;
4273 hnew.Scale(c1);
4274 hnew.SetDirectory(nullptr);
4275 return hnew;
4276}
4277
4278
4279////////////////////////////////////////////////////////////////////////////////
4280/// Operator +
4281
4282TH2D operator+(TH2D const &h1, TH2D const &h2)
4283{
4284 TH2D hnew = h1;
4285 hnew.Add(&h2,1);
4286 hnew.SetDirectory(nullptr);
4287 return hnew;
4288}
4289
4290
4291////////////////////////////////////////////////////////////////////////////////
4292/// Operator -
4293
4294TH2D operator-(TH2D const &h1, TH2D const &h2)
4295{
4296 TH2D hnew = h1;
4297 hnew.Add(&h2,-1);
4298 hnew.SetDirectory(nullptr);
4299 return hnew;
4300}
4301
4302
4303////////////////////////////////////////////////////////////////////////////////
4304/// Operator *
4305
4306TH2D operator*(TH2D const &h1, TH2D const &h2)
4307{
4308 TH2D hnew = h1;
4309 hnew.Multiply(&h2);
4310 hnew.SetDirectory(nullptr);
4311 return hnew;
4312}
4313
4314
4315////////////////////////////////////////////////////////////////////////////////
4316/// Operator /
4317
4318TH2D operator/(TH2D const &h1, TH2D const &h2)
4319{
4320 TH2D hnew = h1;
4321 hnew.Divide(&h2);
4322 hnew.SetDirectory(nullptr);
4323 return hnew;
4324}
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
#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:96
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
short Color_t
Color number (short)
Definition RtypesCore.h:99
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
char Char_t
Character 1 byte (char)
Definition RtypesCore.h:51
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:53
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gDirectory
Definition TDirectory.h:385
Option_t Option_t option
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
char name[80]
Definition TGX11.cxx:110
TH2C operator+(TH2C const &h1, TH2C const &h2)
Operator +.
Definition TH2.cxx:3029
TH2C operator*(Float_t c1, TH2C const &h1)
Operator *.
Definition TH2.cxx:3017
TH2C operator/(TH2C const &h1, TH2C const &h2)
Operator /.
Definition TH2.cxx:3065
TH2C operator-(TH2C const &h1, TH2C const &h2)
Operator -.
Definition TH2.cxx:3041
float xmin
int nentries
float ymin
float xmax
float ymax
#define gROOT
Definition TROOT.h:411
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
#define gPad
#define snprintf
Definition civetweb.c:1579
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
Stat_t GetSum() const
Definition TArrayD.h:46
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 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:31
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:38
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:35
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:42
virtual Style_t GetMarkerStyle() const
Return the marker style.
Definition TAttMarker.h:33
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:39
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition TAttMarker.h:32
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:41
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:875
Bool_t IsAlphanumeric() const
Definition TAxis.h:90
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition TAxis.cxx:481
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:292
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition TAxis.cxx:521
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition TAxis.cxx:783
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x
Definition TAxis.cxx:421
Int_t GetLast() const
Return last bin on the axis i.e.
Definition TAxis.cxx:472
virtual void ImportAttributes(const TAxis *axis)
Copy axis attributes to this.
Definition TAxis.cxx:684
Double_t GetXmin() const
Definition TAxis.h:141
Int_t GetNbins() const
Definition TAxis.h:127
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
Definition TAxis.cxx:545
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition TAxis.cxx:531
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition TAxis.cxx:461
Buffer base class used for serializing objects.
Definition TBuffer.h:43
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:1611
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
Definition TF1.cxx:1957
Double_t GetChisquare() const
Return the Chisquare after fitting. See ROOT::Fit::FitResult::Chi2()
Definition TF1.h:424
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Definition TF1.cxx:3559
virtual Int_t GetNpar() const
Definition TF1.h:461
virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel=1.e-12)
IntegralOneDim or analytical integral.
Definition TF1.cxx:2556
virtual Int_t GetNumberFitPoints() const
Definition TF1.h:483
virtual Double_t * GetParameters() const
Definition TF1.h:500
virtual void GetRange(Double_t *xmin, Double_t *xmax) const
Return range of a generic N-D function.
Definition TF1.cxx:2306
virtual const char * GetParName(Int_t ipar) const
Definition TF1.h:509
virtual void SetParameters(const Double_t *params)
Definition TF1.h:633
virtual Double_t GetParameter(Int_t ipar) const
Definition TF1.h:492
A 2-Dim function with parameters.
Definition TF2.h:29
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:927
static TClass * Class()
void Reset(Option_t *option="") override
Reset.
Definition TH1.cxx:10311
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
Double_t * fBuffer
[fBufferSize] entry buffer
Definition TH1.h:169
virtual Double_t GetEffectiveEntries() const
Number of effective entries of the histogram.
Definition TH1.cxx:4425
@ kXaxis
Definition TH1.h:123
@ kYaxis
Definition TH1.h:124
Int_t fNcells
Number of bins(1D), cells (2D) +U/Overflows.
Definition TH1.h:150
void Copy(TObject &hnew) const override
Copy this histogram structure to newth1.
Definition TH1.cxx:2642
Double_t fTsumw
Total Sum of weights.
Definition TH1.h:157
Double_t fTsumw2
Total Sum of squares of weights.
Definition TH1.h:158
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:8005
Double_t fTsumwx2
Total Sum of weight*X*X.
Definition TH1.h:160
virtual Double_t GetStdDev(Int_t axis=1) const
Returns the Standard Deviation (Sigma).
Definition TH1.cxx:7630
virtual Int_t GetNbinsY() const
Definition TH1.h:543
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition TH1.cxx:9088
virtual Double_t GetMean(Int_t axis=1) const
For axis = 1,2 or 3 returns the mean value of the histogram along X,Y or Z axis.
Definition TH1.cxx:7558
virtual Int_t GetDimension() const
Definition TH1.h:528
void Streamer(TBuffer &) override
Stream a class object.
Definition TH1.cxx:6968
@ kIsNotW
Histogram is forced to be not weighted even when the histogram is filled with weighted.
Definition TH1.h:411
virtual Bool_t CanExtendAllAxes() const
Returns true if all axes are extendable.
Definition TH1.cxx:6671
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
Definition TH1.cxx:7138
TAxis * GetXaxis()
Definition TH1.h:572
virtual Int_t GetNcells() const
Definition TH1.h:545
virtual void PutStats(Double_t *stats)
Replace current statistics with the values in array stats.
Definition TH1.cxx:7907
TVirtualHistPainter * GetPainter(Option_t *option="")
Return pointer to painter.
Definition TH1.cxx:4488
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:4963
virtual Int_t GetNbinsX() const
Definition TH1.h:542
Int_t fBufferSize
fBuffer size
Definition TH1.h:168
Int_t fDimension
! Histogram dimension (1, 2 or 3 dim)
Definition TH1.h:171
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:9231
static Int_t fgBufferSize
! Default buffer size for automatic histograms
Definition TH1.h:176
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3315
TAxis * GetYaxis()
Definition TH1.h:573
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3037
virtual Double_t GetBinErrorSqUnchecked(Int_t bin) const
Definition TH1.h:706
virtual void SetBuffer(Int_t bufsize, Option_t *option="")
Set the maximum number of entries to be kept in the buffer.
Definition TH1.cxx:8486
UInt_t GetAxisLabelStatus() const
Internal function used in TH1::Fill to see which axis is full alphanumeric, i.e.
Definition TH1.cxx:6710
Double_t * fIntegral
! Integral of bins used by GetRandom
Definition TH1.h:172
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:9247
virtual Double_t GetBinLowEdge(Int_t bin) const
Return bin lower edge for 1D histogram.
Definition TH1.cxx:9177
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 Paint(Option_t *option="") override
Control routine to paint any kind of histograms.
Definition TH1.cxx:6241
virtual void ResetStats()
Reset the statistics including the number of entries and replace with values calculated from bin cont...
Definition TH1.cxx:7925
@ kNstat
Size of statistics data (up to TProfile3D)
Definition TH1.h:423
Double_t fEntries
Number of entries.
Definition TH1.h:156
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5063
TAxis fXaxis
X axis descriptor.
Definition TH1.h:151
virtual void ExtendAxis(Double_t x, TAxis *axis)
Histogram is resized along axis such that x is in the axis range.
Definition TH1.cxx:6539
TArrayD fSumw2
Array of sum of squares of weights.
Definition TH1.h:165
virtual Int_t GetSumw2N() const
Definition TH1.h:563
Bool_t GetStatOverflowsBehaviour() const
Definition TH1.h:392
virtual Int_t GetQuantiles(Int_t n, Double_t *xp, const Double_t *p=nullptr)
Compute Quantiles for this histogram.
Definition TH1.cxx:4592
TObject * Clone(const char *newname="") const override
Make a complete copy of the underlying object.
Definition TH1.cxx:2723
TAxis fYaxis
Y axis descriptor.
Definition TH1.h:152
TVirtualHistPainter * fPainter
! Pointer to histogram painter
Definition TH1.h:173
virtual void SetBins(Int_t nx, Double_t xmin, Double_t xmax)
Redefine x axis parameters.
Definition TH1.cxx:8795
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition TH1.cxx:9048
virtual void SetEntries(Double_t n)
Definition TH1.h:640
static Bool_t fgDefaultSumw2
! Flag to call TH1::Sumw2 automatically at histogram creation time
Definition TH1.h:179
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:159
virtual Double_t ComputeIntegral(Bool_t onlyPositive=false)
Compute integral (normalized cumulative sum of bins) w/o under/overflows The result is stored in fInt...
Definition TH1.cxx:2508
2-D histogram with a byte per channel (see TH1 documentation)
Definition TH2.h:143
void Reset(Option_t *option="") override
Reset this histogram: contents, errors, etc.
Definition TH2.cxx:2949
static TClass * Class()
TClass * IsA() const override
Definition TH2.h:179
void Streamer(TBuffer &) override
Stream an object of class TH2C.
Definition TH2.cxx:2971
void AddBinContent(Int_t bin) override
Increment bin content by 1.
Definition TH2.cxx:2917
TH2C()
Constructor.
Definition TH2.cxx:2823
TH2C & operator=(const TH2C &h1)
Operator =.
Definition TH2.cxx:3006
~TH2C() override
Destructor.
Definition TH2.cxx:2833
void Copy(TObject &hnew) const override
Copy.
Definition TH2.cxx:2940
void SetBinsLength(Int_t n=-1) override
Set total number of bins including under/overflow Reallocate bin contents array.
Definition TH2.cxx:2960
2-D histogram with a double per channel (see TH1 documentation)
Definition TH2.h:356
void Streamer(TBuffer &) override
Stream an object of class TH2D.
Definition TH2.cxx:4222
static TClass * Class()
TClass * IsA() const override
Definition TH2.h:398
void SetBinsLength(Int_t n=-1) override
Set total number of bins including under/overflow Reallocate bin contents array.
Definition TH2.cxx:4211
~TH2D() override
Destructor.
Definition TH2.cxx:4084
void Copy(TObject &hnew) const override
Copy.
Definition TH2.cxx:4191
TH2D()
Constructor.
Definition TH2.cxx:4074
TH2D & operator=(const TH2D &h1)
Operator =.
Definition TH2.cxx:4257
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:307
TH2F()
Constructor.
Definition TH2.cxx:3803
TClass * IsA() const override
Definition TH2.h:350
TH2F & operator=(const TH2F &h1)
Operator =.
Definition TH2.cxx:3984
~TH2F() override
Destructor.
Definition TH2.cxx:3813
void Copy(TObject &hnew) const override
Copy.
Definition TH2.cxx:3918
static TClass * Class()
void Streamer(TBuffer &) override
Stream an object of class TH2F.
Definition TH2.cxx:3949
void SetBinsLength(Int_t n=-1) override
Set total number of bins including under/overflow Reallocate bin contents array.
Definition TH2.cxx:3938
2-D histogram with an int per channel (see TH1 documentation)
Definition TH2.h:227
TH2I()
Constructor.
Definition TH2.cxx:3347
void Copy(TObject &hnew) const override
Copy.
Definition TH2.cxx:3466
void AddBinContent(Int_t bin) override
Increment bin content by 1.
Definition TH2.cxx:3443
~TH2I() override
Destructor.
Definition TH2.cxx:3357
TH2I & operator=(const TH2I &h1)
Operator =.
Definition TH2.cxx:3497
void SetBinsLength(Int_t n=-1) override
Set total number of bins including under/overflow Reallocate bin contents array.
Definition TH2.cxx:3486
2-D histogram with a long64 per channel (see TH1 documentation)
Definition TH2.h:268
TH2L & operator=(const TH2L &h1)
Operator =.
Definition TH2.cxx:3725
void SetBinsLength(Int_t n=-1) override
Set total number of bins including under/overflow Reallocate bin contents array.
Definition TH2.cxx:3714
~TH2L() override
Destructor.
Definition TH2.cxx:3585
void Copy(TObject &hnew) const override
Copy.
Definition TH2.cxx:3694
TH2L()
Constructor.
Definition TH2.cxx:3575
void AddBinContent(Int_t bin) override
Increment bin content by 1.
Definition TH2.cxx:3671
2-D histogram with a short per channel (see TH1 documentation)
Definition TH2.h:185
void AddBinContent(Int_t bin) override
Increment bin content by 1.
Definition TH2.cxx:3180
~TH2S() override
Destructor.
Definition TH2.cxx:3094
static TClass * Class()
TH2S & operator=(const TH2S &h1)
Operator =.
Definition TH2.cxx:3269
void Copy(TObject &hnew) const override
Copy.
Definition TH2.cxx:3203
TH2S()
Constructor.
Definition TH2.cxx:3084
void Streamer(TBuffer &) override
Stream an object of class TH2S.
Definition TH2.cxx:3234
void SetBinsLength(Int_t n=-1) override
Set total number of bins including under/overflow Reallocate bin contents array.
Definition TH2.cxx:3223
TClass * IsA() const override
Definition TH2.h:221
Service class for 2-D histogram classes.
Definition TH2.h:30
TH1D * ProjectionY(const char *name="_py", Int_t firstxbin=0, Int_t lastxbin=-1, Option_t *option="") const
Project a 2-D histogram into a 1-D histogram along Y.
Definition TH2.cxx:2436
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 TH2.cxx:1214
Int_t ShowPeaks(Double_t sigma=2, Option_t *option="", Double_t threshold=0.05) override
Interface to TSpectrum2::Search the function finds peaks in this histogram where the width is > sigma...
Definition TH2.cxx:2655
virtual Double_t GetCorrelationFactor(Int_t axis1=1, Int_t axis2=2) const
Return correlation factor between axis1 and axis2.
Definition TH2.cxx:1105
void FillRandom(TF1 *f1, Int_t ntimes=5000, TRandom *rng=nullptr) override
Fill histogram following distribution in function fname.
Definition TH2.cxx:677
virtual TProfile * DoProfile(bool onX, const char *name, Int_t firstbin, Int_t lastbin, Option_t *option) const
Definition TH2.cxx:1840
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 TH2.cxx:1430
virtual void FitSlicesY(TF1 *f1=nullptr, Int_t firstxbin=0, Int_t lastxbin=-1, Int_t cut=0, Option_t *option="QNR", TObjArray *arr=nullptr)
Project slices along Y in case of a 2-D histogram, then fit each slice with function f1 and make a hi...
Definition TH2.cxx:1041
virtual Double_t GetBinWithContent2(Double_t c, Int_t &binx, Int_t &biny, Int_t firstxbin=1, Int_t lastxbin=-1, Int_t firstybin=1, Int_t lastybin=-1, Double_t maxdiff=0) const
compute first cell (binx,biny) in the range [firstxbin,lastxbin][firstybin,lastybin] for which diff =...
Definition TH2.cxx:1077
TProfile * ProfileX(const char *name="_pfx", Int_t firstybin=1, Int_t lastybin=-1, Option_t *option="") const
Project a 2-D histogram into a profile histogram along X.
Definition TH2.cxx:2069
TH2 * Rebin(Int_t ngroup=2, const char *newname="", const Double_t *xbins=nullptr) override
Override TH1::Rebin as TH2::RebinX Rebinning in variable binning as for TH1 is not allowed If a non-n...
Definition TH2.cxx:1623
void FillN(Int_t, const Double_t *, const Double_t *, Int_t) override
Fill this histogram with an array x and weights w.
Definition TH2.h:87
TH1D * QuantilesY(Double_t prob=0.5, const char *name="_qy") const
Compute the Y distribution of quantiles in the other variable X name is the name of the returned hist...
Definition TH2.cxx:2478
void AddBinContent(Int_t binx, Int_t biny)
Increment 2D bin content by 1.
Definition TH2.h:76
TProfile * ProfileY(const char *name="_pfy", Int_t firstxbin=1, Int_t lastxbin=-1, Option_t *option="") const
Project a 2-D histogram into a profile histogram along Y.
Definition TH2.cxx:2119
void Copy(TObject &hnew) const override
Copy.
Definition TH2.cxx:343
virtual TH1D * DoQuantiles(bool onX, const char *name, Double_t prob) const
Implementation of quantiles for x or y.
Definition TH2.cxx:2487
Double_t fTsumwxy
Total Sum of weight*X*Y.
Definition TH2.h:36
void SetBinContent(Int_t bin, Double_t content) override
Set bin content.
Definition TH2.cxx:2576
Int_t BufferEmpty(Int_t action=0) override
Fill histogram with all entries in the buffer.
Definition TH2.cxx:241
virtual void DoFitSlices(bool onX, TF1 *f1, Int_t firstbin, Int_t lastbin, Int_t cut, Option_t *option, TObjArray *arr)
Definition TH2.cxx:774
TH1D * QuantilesX(Double_t prob=0.5, const char *name="_qx") const
Compute the X distribution of quantiles in the other variable Y name is the name of the returned hist...
Definition TH2.cxx:2465
virtual void SetShowProjectionY(Int_t nbins=1)
When the mouse is moved in a pad containing a 2-d view of this histogram a second canvas shows the pr...
Definition TH2.cxx:2610
TClass * IsA() const override
Definition TH2.h:137
void Reset(Option_t *option="") override
Reset this histogram: contents, errors, etc.
Definition TH2.cxx:2560
Double_t fScalefactor
Scale factor.
Definition TH2.h:33
virtual TH1D * DoProjection(bool onX, const char *name, Int_t firstbin, Int_t lastbin, Option_t *option) const
Internal (protected) method for performing projection on the X or Y axis called by ProjectionX or Pro...
Definition TH2.cxx:2129
TH2 * RebinX(Int_t ngroup=2, const char *newname="") override
Rebin only the X axis see Rebin2D.
Definition TH2.cxx:1602
Double_t fTsumwy2
Total Sum of weight*Y*Y.
Definition TH2.h:35
virtual void GetRandom2(Double_t &x, Double_t &y, TRandom *rng=nullptr)
Return 2 random numbers along axis x and y distributed according to the cell-contents of this 2-D his...
Definition TH2.cxx:1160
virtual Double_t GetCovariance(Int_t axis1=1, Int_t axis2=2) const
Return covariance between axis1 and axis2.
Definition TH2.cxx:1123
Int_t GetBin(Int_t binx, Int_t biny, Int_t binz=0) const override
Return Global bin number corresponding to binx,y,z.
Definition TH2.cxx:1046
TH1D * ProjectionX(const char *name="_px", Int_t firstybin=0, Int_t lastybin=-1, Option_t *option="") const
Project a 2-D histogram into a 1-D histogram along X.
Definition TH2.cxx:2396
void Smooth(Int_t ntimes=1, Option_t *option="") override
Smooth bin contents of this 2-d histogram using kernel algorithms similar to the ones used in the ras...
Definition TH2.cxx:2687
~TH2() override
Destructor.
Definition TH2.cxx:229
Double_t GetBinContent(Int_t binx, Int_t biny) const override
Definition TH2.h:97
virtual Double_t IntegralAndError(Int_t binx1, Int_t binx2, Int_t biny1, Int_t biny2, Double_t &err, Option_t *option="") const
Return integral of bin contents in range [firstxbin,lastxbin],[firstybin,lastybin] for a 2-D histogra...
Definition TH2.cxx:1305
Double_t fTsumwy
Total Sum of weight*Y.
Definition TH2.h:34
TH2()
2-D histogram default constructor.
Definition TH2.cxx:72
Double_t Interpolate(Double_t x) const override
illegal for a TH2
Definition TH2.cxx:1313
TH1 * ShowBackground(Int_t niter=20, Option_t *option="same") override
This function calculates the background spectrum in this histogram.
Definition TH2.cxx:2639
virtual void SetShowProjectionX(Int_t nbins=1)
When the mouse is moved in a pad containing a 2-d view of this histogram a second canvas shows the pr...
Definition TH2.cxx:2594
void Streamer(TBuffer &) override
Stream an object of class TH2.
Definition TH2.cxx:2790
Int_t Fill(Double_t) override
Invalid Fill method.
Definition TH2.cxx:356
static TClass * Class()
virtual TH2 * Rebin2D(Int_t nxgroup=2, Int_t nygroup=2, const char *newname="")
Rebin this histogram grouping nxgroup/nygroup bins along the xaxis/yaxis together.
Definition TH2.cxx:1658
virtual void FitSlicesX(TF1 *f1=nullptr, Int_t firstybin=0, Int_t lastybin=-1, Int_t cut=0, Option_t *option="QNR", TObjArray *arr=nullptr)
Project slices along X in case of a 2-D histogram, then fit each slice with function f1 and make a hi...
Definition TH2.cxx:976
virtual Int_t BufferFill(Double_t x, Double_t y, Double_t w)
accumulate arguments in buffer.
Definition TH2.cxx:315
virtual void SetShowProjectionXY(Int_t nbinsY=1, Int_t nbinsX=1)
When the mouse is moved in a pad containing a 2-d view of this histogram two canvases show the projec...
Definition TH2.cxx:2627
Double_t Integral(Option_t *option="") const override
Return integral of bin contents.
Definition TH2.cxx:1277
void PutStats(Double_t *stats) override
Replace current statistics with the values in array stats.
Definition TH2.cxx:2445
virtual TH2 * RebinY(Int_t ngroup=2, const char *newname="")
Rebin only the Y axis see Rebin2D.
Definition TH2.cxx:1612
static THLimitsFinder * GetLimitsFinder()
Return pointer to the current finder.
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
TMatrixTBase.
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
An array of TObjects.
Definition TObjArray.h:31
Collectable string class.
Definition TObjString.h:28
Mother of all ROOT objects.
Definition TObject.h:41
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:202
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:864
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1045
Profile Histogram.
Definition TProfile.h:32
static TClass * Class()
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom.cxx:558
Basic string class.
Definition TString.h:138
void ToLower()
Change string to lower-case.
Definition TString.cxx:1189
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:545
const char * Data() const
Definition TString.h:384
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:712
void ToUpper()
Change string to upper case.
Definition TString.cxx:1202
TString & Remove(Ssiz_t pos)
Definition TString.h:693
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:2384
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:640
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:659
virtual void SetShowProjection(const char *option, Int_t nbins)=0
virtual Int_t MakeCuts(char *cutsopt)=0
virtual Bool_t IsInside(Int_t x, Int_t y)=0
virtual void SetShowProjectionXY(const char *option, Int_t nbinsY, Int_t nbinsX)=0
small helper class to store/restore gPad context in TPad methods
Definition TVirtualPad.h:61
const Double_t sigma
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
Double_t Gaus(Double_t x, Double_t mean=0, Double_t sigma=1, Bool_t norm=kFALSE)
Calculates a gaussian function with mean and sigma.
Definition TMath.cxx:471
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:251
Double_t Prob(Double_t chi2, Int_t ndf)
Computation of the probability for a certain Chi-squared (chi2) and number of degrees of freedom (ndf...
Definition TMath.cxx:637
Double_t QuietNaN()
Returns a quiet NaN as defined by IEEE 754.
Definition TMath.h:913
Double_t Floor(Double_t x)
Rounds x downward, returning the largest integral value that is not greater than x.
Definition TMath.h:691
Double_t Log(Double_t x)
Returns the natural logarithm of x.
Definition TMath.h:767
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673
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:348
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:124
TMarker m
Definition textangle.C:8