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