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