Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TProfile2D.h
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Rene Brun 16/04/2000
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#ifndef ROOT_TProfile2D
13#define ROOT_TProfile2D
14
15
16//////////////////////////////////////////////////////////////////////////
17// //
18// TProfile2D //
19// //
20// Profile2D histogram class. //
21// //
22//////////////////////////////////////////////////////////////////////////
23
24#include "TH2.h"
25#include "TProfile.h"
26
27class TProfile2D : public TH2D {
28
29public:
30 friend class TProfileHelper;
31 friend class TH1Merger;
32
33protected:
34 TArrayD fBinEntries; ///< Number of entries per bin
35 EErrorType fErrorMode; ///< Option to compute errors
36 Double_t fZmin; ///< Lower limit in Z (if set)
37 Double_t fZmax; ///< Upper limit in Z (if set)
38 Bool_t fScaling; ///<! True when TProfile2D::Scale is called
39 Double_t fTsumwz; ///< Total Sum of weight*Z
40 Double_t fTsumwz2; ///< Total Sum of weight*Z*Z
41 TArrayD fBinSumw2; ///< Array of sum of squares of weights per bin
42 static Bool_t fgApproximate; ///< Bin error approximation option
43
44 Int_t BufferFill(Double_t, Double_t) override {return -2;} //may not use
45 Int_t BufferFill(Double_t, Double_t, Double_t) override {return -2;} //may not use
47
48 // helper methods for the Merge unification in TProfileHelper
49 void SetBins(const Int_t* nbins, const Double_t* range) { SetBins(nbins[0], range[0], range[1],
50 nbins[1], range[2], range[3]); };
51 Int_t Fill(const Double_t* v) { return Fill(v[0], v[1], v[2], v[3]); };
52
53 TProfile *DoProfile(bool onX, const char *name, Int_t firstbin, Int_t lastbin, Option_t *option) const override;
54
55 using TH2::Fill;
56 Int_t Fill(Double_t, Double_t) override {return TH2::Fill(0); } //MayNotUse
57
58 Double_t RetrieveBinContent(Int_t bin) const override { return (fBinEntries.fArray[bin] > 0) ? fArray[bin]/fBinEntries.fArray[bin] : 0; }
59 //virtual void UpdateBinContent(Int_t bin, Double_t content);
60 Double_t GetBinErrorSqUnchecked(Int_t bin) const override { Double_t err = GetBinError(bin); return err*err; }
61
62private:
64 Double_t *GetB2() {return fBinSumw2.fN ? &fBinSumw2.fArray[0] : nullptr; }
65 Double_t *GetW() {return &fArray[0];}
66 Double_t *GetW2() {return &fSumw2.fArray[0];}
67 void SetBins(Int_t, Double_t, Double_t) override
68 { MayNotUse("SetBins(Int_t, Double_t, Double_t"); }
69 void SetBins(Int_t, const Double_t*) override
70 { MayNotUse("SetBins(Int_t, const Double_t*"); }
72 { MayNotUse("SetBins(Int_t, Double_t, Double_t, Int_t, Double_t, Double_t, Int_t, Double_t, Double_t"); }
73 void SetBins(Int_t, const Double_t *, Int_t, const Double_t *, Int_t, const Double_t *) override
74 { MayNotUse("SetBins(Int_t, const Double_t*, Int_t, const Double_t*, Int_t, const Double_t*"); }
75
76public:
77 TProfile2D();
78 TProfile2D(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
79 ,Int_t nbinsy,Double_t ylow,Double_t yup
80 ,Double_t zlow, Double_t zup,Option_t *option="");
81 TProfile2D(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
82 ,Int_t nbinsy,Double_t ylow,Double_t yup,Option_t *option="");
83 TProfile2D(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
84 ,Int_t nbinsy,Double_t ylow,Double_t yup,Option_t *option="");
85 TProfile2D(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup
86 ,Int_t nbinsy,const Double_t *ybins,Option_t *option="");
87 TProfile2D(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins
88 ,Int_t nbinsy,const Double_t *ybins,Option_t *option="");
89 TProfile2D(const TProfile2D &profile);
90 TProfile2D &operator=(const TProfile2D &profile);
91 ~TProfile2D() override;
92 Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="") override;
93 Bool_t Add(const TH1 *h1, Double_t c1=1) override;
94 Bool_t Add(const TH1 *h1, const TH1 *h2, Double_t c1=1, Double_t c2=1) override; // *MENU*
95 static void Approximate(Bool_t approx=kTRUE);
96 void BuildOptions(Double_t zmin, Double_t zmax, Option_t *option);
97 Int_t BufferEmpty(Int_t action=0) override;
98 void Copy(TObject &hnew) const override;
99 Bool_t Divide(TF1 *h1, Double_t c1=1) override;
100 Bool_t Divide(const TH1 *h1) override;
101 Bool_t Divide(const TH1 *h1, const TH1 *h2, Double_t c1=1, Double_t c2=1, Option_t *option="") override; // *MENU*
102 void ExtendAxis(Double_t x, TAxis *axis) override;
103 Int_t Fill(Double_t x, Double_t y, Double_t z) override;
104 // Don't use a default w=1.0 in the Fill functions, but instead declare
105 // inlined no-weight overloads to correctly override TH2 methods.
106 virtual Int_t Fill(Double_t x, const char *namey, Double_t z, Double_t w);
107 virtual Int_t Fill(const char *namex, Double_t y, Double_t z, Double_t w);
108 virtual Int_t Fill(const char *namex, const char *namey, Double_t z, Double_t w);
110 inline Int_t Fill(Double_t x, const char *namey, Double_t z) override { return Fill(x, namey, z, 1.0); }
111 inline Int_t Fill(const char *namex, Double_t y, Double_t z) override { return Fill(namex, y, z, 1.0); }
112 inline Int_t Fill(const char *namex, const char *namey, Double_t z) override { return Fill(namex, namey, z, 1.0); }
113 Double_t GetBinContent(Int_t bin) const override;
114 Double_t GetBinContent(Int_t binx, Int_t biny) const override {return GetBinContent(GetBin(binx,biny));}
115 Double_t GetBinContent(Int_t binx, Int_t biny, Int_t) const override {return GetBinContent(GetBin(binx,biny));}
116 Double_t GetBinError(Int_t bin) const override;
117 Double_t GetBinError(Int_t binx, Int_t biny) const override {return GetBinError(GetBin(binx,biny));}
118 Double_t GetBinError(Int_t binx, Int_t biny, Int_t) const override {return GetBinError(GetBin(binx,biny));}
119 virtual Double_t GetBinEntries(Int_t bin) const;
121 virtual TArrayD *GetBinSumw2() {return &fBinSumw2;}
122 virtual const TArrayD *GetBinSumw2() const {return &fBinSumw2;}
123 Option_t *GetErrorOption() const;
124 void GetStats(Double_t *stats) const override;
125 virtual Double_t GetZmin() const {return fZmin;}
126 virtual Double_t GetZmax() const {return fZmax;}
127 void LabelsDeflate(Option_t *axis="X") override;
128 void LabelsInflate(Option_t *axis="X") override;
129 void LabelsOption(Option_t *option="h", Option_t *axis="X") override;
130 Long64_t Merge(TCollection *list) override;
131 Bool_t Multiply(TF1 *h1, Double_t c1=1) override;
132 Bool_t Multiply(const TH1 *h1) override;
133 Bool_t Multiply(const TH1 *h1, const TH1 *h2, Double_t c1=1, Double_t c2=1, Option_t *option="") override; // *MENU*
134 TH2D *ProjectionXY(const char *name="_pxy", Option_t *option="e") const;
135 TProfile *ProfileX(const char *name="_pfx", Int_t firstybin=0, Int_t lastybin=-1, Option_t *option="") const; // *MENU*
136 TProfile *ProfileY(const char *name="_pfy", Int_t firstxbin=0, Int_t lastxbin=-1, Option_t *option="") const; // *MENU*
137 void PutStats(Double_t *stats) override;
138 void Reset(Option_t *option="") override;
139 TProfile2D *Rebin2D(Int_t nxgroup=2, Int_t nygroup=2, const char *newname="") override;
140 TProfile2D *RebinX(Int_t ngroup=2, const char *newname="") override;
141 TProfile2D *RebinY(Int_t ngroup=2, const char *newname="") override;
142 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
143 void Scale(Double_t c1=1, Option_t *option="") override;
144 virtual void SetBinEntries(Int_t bin, Double_t w);
145 void SetBins(Int_t nbinsx, Double_t xmin, Double_t xmax, Int_t nbinsy, Double_t ymin, Double_t ymax) override;
146 void SetBins(Int_t nx, const Double_t *xBins, Int_t ny, const Double_t *yBins) override;
147 void SetBinsLength(Int_t n=-1) override;
148 void SetBuffer(Int_t buffersize, Option_t *option="") override;
149 virtual void SetErrorOption(Option_t *option=""); // *MENU*
150 void Sumw2(Bool_t flag = kTRUE) override;
152
153 ClassDefOverride(TProfile2D,8) //Profile2D histogram class
154};
155
156#endif
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
long long Long64_t
Definition RtypesCore.h:69
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
void MayNotUse(const char *method)
This function can be used in classes that should override a certain function, but in the inherited cl...
Definition TError.cxx:168
Option_t Option_t option
char name[80]
Definition TGX11.cxx:110
float xmin
float ymin
float xmax
float ymax
EErrorType
Definition TProfile.h:28
Array of doubles (64 bits per element).
Definition TArrayD.h:27
Double_t * fArray
Definition TArrayD.h:30
void Reset()
Definition TArrayD.h:47
Int_t fN
Definition TArray.h:38
Int_t GetSize() const
Definition TArray.h:47
Class to manage histogram axis.
Definition TAxis.h:31
Collection abstract base class.
Definition TCollection.h:65
1-Dim function class
Definition TF1.h:233
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
TArrayD fSumw2
Array of sum of squares of weights.
Definition TH1.h:104
2-D histogram with a double per channel (see TH1 documentation)
Definition TH2.h:357
Int_t GetBin(Int_t binx, Int_t biny, Int_t binz=0) const override
Return Global bin number corresponding to binx,y,z.
Definition TH2.cxx:1086
Int_t Fill(Double_t) override
Invalid Fill method.
Definition TH2.cxx:393
Mother of all ROOT objects.
Definition TObject.h:41
Profile2D histograms are used to display the mean value of Z and its error for each cell in X,...
Definition TProfile2D.h:27
Long64_t Merge(TCollection *list) override
Merge all histograms in the collection in this histogram.
void SetBins(Int_t, Double_t, Double_t) override
Redefine x axis parameters.
Definition TProfile2D.h:67
void PutStats(Double_t *stats) override
Replace current statistics with the values in array stats.
Int_t BufferFill(Double_t, Double_t) override
accumulate arguments in buffer.
Definition TProfile2D.h:44
Double_t fTsumwz
Total Sum of weight*Z.
Definition TProfile2D.h:39
Int_t Fill(const Double_t *v)
Definition TProfile2D.h:51
TH2D * ProjectionXY(const char *name="_pxy", Option_t *option="e") const
Project this profile2D into a 2-D histogram along X,Y.
Bool_t Multiply(TF1 *h1, Double_t c1=1) override
Performs the operation: this = this*c1*f1.
void LabelsDeflate(Option_t *axis="X") override
Reduce the number of bins for this axis to the number of bins having a label.
Double_t GetBinError(Int_t bin) const override
Return bin error of a Profile2D histogram.
Double_t GetBinContent(Int_t binx, Int_t biny, Int_t) const override
Definition TProfile2D.h:115
static void Approximate(Bool_t approx=kTRUE)
Static function, set the fgApproximate flag.
virtual const TArrayD * GetBinSumw2() const
Definition TProfile2D.h:122
EErrorType fErrorMode
Option to compute errors.
Definition TProfile2D.h:35
Double_t fZmin
Lower limit in Z (if set)
Definition TProfile2D.h:36
TProfile2D * RebinX(Int_t ngroup=2, const char *newname="") override
Rebin only the X axis.
Int_t Fill(const char *namex, const char *namey, Double_t z) override
Increment cell defined by namex,namey by a weight w.
Definition TProfile2D.h:112
Double_t * GetW2()
Definition TProfile2D.h:66
Int_t BufferFill(Double_t, Double_t, Double_t) override
accumulate arguments in buffer.
Definition TProfile2D.h:45
Double_t GetBinError(Int_t binx, Int_t biny) const override
Definition TProfile2D.h:117
void SetBins(Int_t, const Double_t *) override
Redefine x axis parameters with variable bin sizes.
Definition TProfile2D.h:69
Int_t Fill(const char *namex, Double_t y, Double_t z) override
Increment cell defined by namex,y by a weight w.
Definition TProfile2D.h:111
Bool_t fScaling
! True when TProfile2D::Scale is called
Definition TProfile2D.h:38
virtual Double_t GetBinEffectiveEntries(Int_t bin)
Return bin effective entries for a weighted filled Profile histogram.
Option_t * GetErrorOption() const
Return option to compute profile2D errors.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
TArrayD fBinSumw2
Array of sum of squares of weights per bin.
Definition TProfile2D.h:41
Double_t GetBinContent(Int_t binx, Int_t biny) const override
Definition TProfile2D.h:114
Double_t * GetB2()
Definition TProfile2D.h:64
void ExtendAxis(Double_t x, TAxis *axis) override
Profile histogram is resized along axis such that x is in the axis range.
TProfile * ProfileY(const char *name="_pfy", Int_t firstxbin=0, Int_t lastxbin=-1, Option_t *option="") const
Project a 2-D histogram into a profile histogram along X.
TProfile2D * RebinY(Int_t ngroup=2, const char *newname="") override
Rebin only the Y axis.
Double_t * GetW()
Definition TProfile2D.h:65
void Scale(Double_t c1=1, Option_t *option="") override
Multiply this profile2D by a constant c1.
virtual void SetBinEntries(Int_t bin, Double_t w)
Set the number of entries in bin.
void Copy(TObject &hnew) const override
Copy a Profile2D histogram to a new profile2D histogram.
TProfile * DoProfile(bool onX, const char *name, Int_t firstbin, Int_t lastbin, Option_t *option) const override
Implementation of ProfileX or ProfileY for a TProfile2D.
TProfile * ProfileX(const char *name="_pfx", Int_t firstybin=0, Int_t lastybin=-1, Option_t *option="") const
Project a 2-D histogram into a profile histogram along X.
void LabelsOption(Option_t *option="h", Option_t *axis="X") override
Set option(s) to draw axis with labels.
TProfile2D()
Default constructor for Profile2D histograms.
Double_t GetBinError(Int_t binx, Int_t biny, Int_t) const override
Definition TProfile2D.h:118
void Sumw2(Bool_t flag=kTRUE) override
Create/Delete structure to store sum of squares of weights per bin.
Int_t Fill(Double_t x, const char *namey, Double_t z) override
Increment cell defined by x,namey by a weight w.
Definition TProfile2D.h:110
Double_t GetBinErrorSqUnchecked(Int_t bin) const override
Definition TProfile2D.h:60
TArrayD fBinEntries
Number of entries per bin.
Definition TProfile2D.h:34
void SetBins(const Int_t *nbins, const Double_t *range)
Definition TProfile2D.h:49
~TProfile2D() override
Default destructor for Profile2D histograms.
static Bool_t fgApproximate
Bin error approximation option.
Definition TProfile2D.h:42
Bool_t Divide(TF1 *h1, Double_t c1=1) override
Performs the operation: this = this/(c1*f1) .
void SetBins(Int_t, const Double_t *, Int_t, const Double_t *, Int_t, const Double_t *) override
Redefine x, y and z axis parameters with variable bin sizes.
Definition TProfile2D.h:73
TProfile2D * Rebin2D(Int_t nxgroup=2, Int_t nygroup=2, const char *newname="") override
Rebin this histogram grouping nxgroup/nygroup bins along the xaxis/yaxis together.
Int_t Fill(Double_t, Double_t) override
Increment cell defined by x,y by 1.
Definition TProfile2D.h:56
Int_t BufferEmpty(Int_t action=0) override
Fill histogram with all entries in the buffer.
void LabelsInflate(Option_t *axis="X") override
Double the number of bins for axis.
void GetStats(Double_t *stats) const override
Fill the array stats from the contents of this profile.
virtual Double_t GetBinEntries(Int_t bin) const
Return bin entries of a Profile2D histogram.
Double_t RetrieveBinContent(Int_t bin) const override
Raw retrieval of bin content on internal data structure see convention for numbering bins in TH1::Get...
Definition TProfile2D.h:58
void SetBins(Int_t, Double_t, Double_t, Int_t, Double_t, Double_t, Int_t, Double_t, Double_t) override
Redefine x, y and z axis parameters.
Definition TProfile2D.h:71
Double_t fZmax
Upper limit in Z (if set)
Definition TProfile2D.h:37
void SetBinsLength(Int_t n=-1) override
Set total number of bins including under/overflow.
void BuildOptions(Double_t zmin, Double_t zmax, Option_t *option)
Set Profile2D histogram structure and options.
Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="") override
Performs the operation: this = this + c1*f1 .
TProfile2D & operator=(const TProfile2D &profile)
void SetBuffer(Int_t buffersize, Option_t *option="") override
Set the buffer size in units of 8 bytes (double).
Double_t fTsumwz2
Total Sum of weight*Z*Z.
Definition TProfile2D.h:40
virtual TArrayD * GetBinSumw2()
Definition TProfile2D.h:121
Double_t GetNumberOfBins()
Definition TProfile2D.h:151
Double_t * GetB()
Definition TProfile2D.h:63
virtual void SetErrorOption(Option_t *option="")
Set option to compute profile2D errors.
virtual Double_t GetZmax() const
Definition TProfile2D.h:126
virtual Double_t GetZmin() const
Definition TProfile2D.h:125
Double_t GetBinContent(Int_t bin) const override
Return bin content of a Profile2D histogram.
Profile Histogram.
Definition TProfile.h:32
Double_t y[n]
Definition legend1.C:17
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TH1F * h1
Definition legend1.C:5
return c2
Definition legend2.C:14