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