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