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