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