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