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