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