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