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