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