ROOT  6.06/09
Reference Guide
TH2Poly.h
Go to the documentation of this file.
1 // @(#)root/hist:$Id$
2 // Author: Olivier Couet, Deniz Gunceler
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_TH2Poly
13 #define ROOT_TH2Poly
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TH2Poly //
18 // //
19 // 2-Dim histogram with polygon bins //
20 // //
21 //////////////////////////////////////////////////////////////////////////
22 
23 #ifndef ROOT_TH2
24 #include "TH2.h"
25 #endif
26 
27 #include "TList.h"
28 
29 class TH2PolyBin: public TObject{
30 
31 public:
32  TH2PolyBin();
33  TH2PolyBin(TObject *poly, Int_t bin_number);
34  virtual ~TH2PolyBin();
35 
36  void ClearContent(){fContent = 0;}
37  void Fill(Double_t w) {fContent = fContent+w; SetChanged(true);}
38  Double_t GetArea();
39  Double_t GetContent() const{return fContent;}
40  Bool_t GetChanged() const{return fChanged;}
41  Int_t GetBinNumber() const {return fNumber;}
42  TObject *GetPolygon() const {return fPoly;}
43  Double_t GetXMax();
44  Double_t GetXMin();
45  Double_t GetYMax();
46  Double_t GetYMin();
48  void SetChanged(Bool_t flag){fChanged = flag;}
49  void SetContent(Double_t content){fContent = content; SetChanged(true);}
50 
51 protected:
52  Bool_t fChanged; //For the 3D Painter
53  Int_t fNumber; //Bin number of the bin in TH2Poly
54  TObject *fPoly; //Object holding the polygon definition
55  Double_t fArea; //Bin area
56  Double_t fContent; //Bin content
57  Double_t fXmin; //X minimum value
58  Double_t fYmin; //Y minimum value
59  Double_t fXmax; //X maximum value
60  Double_t fYmax; //Y maximum value
61 
62  ClassDef(TH2PolyBin,1) //2-Dim polygon bins
63 };
64 
65 class TList;
66 class TGraph;
67 class TMultiGraph;
68 class TPad;
69 
70 class TH2Poly : public TH2 {
71 
72 public:
73  TH2Poly();
74  TH2Poly(const char *name,const char *title, Double_t xlow, Double_t xup, Double_t ylow, Double_t yup);
75  TH2Poly(const char *name,const char *title, Int_t nX, Double_t xlow, Double_t xup, Int_t nY, Double_t ylow, Double_t yup);
76  virtual ~TH2Poly();
77 
78  Int_t AddBin(TObject *poly);
79  Int_t AddBin(Int_t n, const Double_t *x, const Double_t *y);
81  virtual Bool_t Add(const TH1 *h1, Double_t c1);
82  virtual Bool_t Add(const TH1 *h1, const TH1 *h2, Double_t c1=1, Double_t c2=1);
83  virtual Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="");
84  void ClearBinContents(); // Clears the content of all bins
85  TObject *Clone(const char* newname = "") const;
86  void ChangePartition(Int_t n, Int_t m); // Sets the number of partition cells to another value
89  Int_t Fill(const char* name, Double_t w);
90  void FillN(Int_t ntimes, const Double_t* x, const Double_t* y, const Double_t* w, Int_t stride = 1);
91  Int_t Fill(Double_t){return -1;} //MayNotUse
92  Int_t Fill(Double_t , const char *, Double_t){return -1;} //MayNotUse
93  Int_t Fill(const char *, Double_t , Double_t ){return -1;} //MayNotUse
94  Int_t Fill(const char *, const char *, Double_t ){return -1;} //MayNotUse
95  void FillN(Int_t, const Double_t*, const Double_t*, Int_t){return;} //MayNotUse
96  Int_t FindBin(Double_t x, Double_t y, Double_t z = 0);
97  TList *GetBins(){return fBins;} // Returns the TList of all bins in the histogram
98  Double_t GetBinContent(Int_t bin) const;
99  Double_t GetBinContent(Int_t, Int_t) const {return 0;} //MayNotUse
100  Double_t GetBinContent(Int_t, Int_t, Int_t) const {return 0;} //MayNotUse
102  Double_t GetBinError(Int_t bin) const;
103  Double_t GetBinError(Int_t , Int_t) const {return 0;} //MayNotUse
104  Double_t GetBinError(Int_t , Int_t , Int_t) const {return 0;} //MayNotUse
105  const char *GetBinName(Int_t bin) const;
106  const char *GetBinTitle(Int_t bin) const;
107  Bool_t GetFloat(){return fFloat;}
108  Double_t GetMaximum() const;
109  Double_t GetMaximum(Double_t maxval) const;
110  Double_t GetMinimum() const;
111  Double_t GetMinimum(Double_t minval) const;
113  Int_t GetNumberOfBins() const{return fNcells;}
114  void Honeycomb(Double_t xstart, Double_t ystart, Double_t a, Int_t k, Int_t s); // Bins the histogram using a honeycomb structure
115  Double_t Integral(Option_t* option = "") const;
116  Double_t Integral(Int_t, Int_t, const Option_t*) const{return 0;} //MayNotUse
117  Double_t Integral(Int_t, Int_t, Int_t, Int_t, const Option_t*) const{return 0;} //MayNotUse
118  Double_t Integral(Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, const Option_t*) const{return 0;} //MayNotUse
120  void Reset(Option_t *option);
121  void SavePrimitive(std::ostream& out, Option_t* option = "");
122  virtual void Scale(Double_t c1 = 1, Option_t* option = "");
123  void SetBinContent(Int_t bin, Double_t content);
124  void SetBinContent(Int_t, Int_t, Double_t){return;} //MayNotUse
125  void SetBinContent(Int_t, Int_t, Int_t, Double_t){return;} //MayNotUse
127  void SetFloat(Bool_t flag = true);
128  void SetNewBinAdded(Bool_t flag){fNewBinAdded = flag;}
129 
130 protected:
131  TList *fBins; //List of bins. The list owns the contained objects
132  Double_t fOverflow[9]; //Overflow bins
133  Int_t fCellX; //Number of partition cells in the x-direction of the histogram
134  Int_t fCellY; //Number of partition cells in the y-direction of the histogram
135  Int_t fNCells; //Number of partition cells: fCellX*fCellY
136  TList *fCells; //[fNCells] The array of TLists that store the bins that intersect with each cell. List do not own the contained objects
137  Double_t fStepX, fStepY; //Dimensions of a partition cell
138  Bool_t *fIsEmpty; //[fNCells] The array that returns true if the cell at the given coordinate is empty
139  Bool_t *fCompletelyInside; //[fNCells] The array that returns true if the cell at the given coordinate is completely inside a bin
140  Bool_t fFloat; //When set to kTRUE, allows the histogram to expand if a bin outside the limits is added.
141  Bool_t fNewBinAdded; //!For the 3D Painter
142  Bool_t fBinContentChanged; //!For the 3D Painter
143 
144  void AddBinToPartition(TH2PolyBin *bin); // Adds the input bin into the partition matrix
145  void Initialize(Double_t xlow, Double_t xup, Double_t ylow, Double_t yup, Int_t n, Int_t m);
146  Bool_t IsIntersecting(TH2PolyBin *bin, Double_t xclipl, Double_t xclipr, Double_t yclipb, Double_t yclipt);
147  Bool_t IsIntersectingPolygon(Int_t bn, Double_t *x, Double_t *y, Double_t xclipl, Double_t xclipr, Double_t yclipb, Double_t yclipt);
148  // needed by TH1 - no need to have a separate implementation
149  virtual Double_t RetrieveBinContent(Int_t bin) const { return GetBinContent(bin); }
150  virtual void UpdateBinContent(Int_t bin, Double_t content) { return SetBinContent(bin,content); }
151 
152  ClassDef(TH2Poly,1) //2-Dim histogram with polygon bins
153 };
154 
155 #endif
Double_t Integral(Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, const Option_t *) const
Definition: TH2Poly.h:118
Bool_t fBinContentChanged
For the 3D Painter.
Definition: TH2Poly.h:142
Int_t FindBin(Double_t x, Double_t y, Double_t z=0)
Returns the bin number of the bin at the given coordinate.
Definition: TH2Poly.cxx:521
Double_t GetBinContent(Int_t bin) const
Returns the content of the input bin For the overflow/underflow/sea bins: -1 | -2 | -3 ---+----+---- ...
Definition: TH2Poly.cxx:717
long long Long64_t
Definition: RtypesCore.h:69
Bool_t * fCompletelyInside
Definition: TH2Poly.h:139
const char Option_t
Definition: RtypesCore.h:62
Double_t fStepX
Definition: TH2Poly.h:137
Double_t GetBinError(Int_t bin) const
Returns the value of error associated to bin number bin.
Definition: TH2Poly.cxx:730
TCanvas * c1
Definition: legend1.C:2
void ChangePartition(Int_t n, Int_t m)
Changes the number of partition cells in the histogram.
Definition: TH2Poly.cxx:416
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
Definition: TH2Poly.cxx:1183
Long64_t Merge(TCollection *)
TH2Poly cannot be merged.
Definition: TH2Poly.cxx:1114
void SetChanged(Bool_t flag)
Definition: TH2Poly.h:48
Int_t GetNumberOfBins() const
Definition: TH2Poly.h:113
A TMultiGraph is a collection of TGraph (or derived) objects.
Definition: TMultiGraph.h:37
void Initialize(Double_t xlow, Double_t xup, Double_t ylow, Double_t yup, Int_t n, Int_t m)
Initializes the TH2Poly object. This method is called by the constructor.
Definition: TH2Poly.cxx:910
Double_t fOverflow[9]
Definition: TH2Poly.h:132
Double_t GetBinError(Int_t, Int_t, Int_t) const
Definition: TH2Poly.h:104
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
virtual Bool_t Add(const TH1 *h1, Double_t c1)
Performs the operation: this = this + c1*h1.
Definition: TH2Poly.cxx:276
Double_t fXmax
Definition: TH2Poly.h:59
const char * GetBinName(Int_t bin) const
Returns the bin name.
Definition: TH2Poly.cxx:746
void SetBinContentChanged(Bool_t flag)
Definition: TH2Poly.h:126
TObject * Clone(const char *newname="") const
Make a complete copy of the underlying object.
Definition: TH2Poly.cxx:455
Helper class to represent a bin in the TH2Poly histogram.
Definition: TH2Poly.h:29
Bool_t GetNewBinAdded() const
Definition: TH2Poly.h:112
void AddBinToPartition(TH2PolyBin *bin)
For the 3D Painter.
Definition: TH2Poly.cxx:344
Bool_t GetChanged() const
Definition: TH2Poly.h:40
Bool_t * fIsEmpty
Definition: TH2Poly.h:138
Int_t fCellX
Definition: TH2Poly.h:133
Double_t GetBinError(Int_t, Int_t) const
Definition: TH2Poly.h:103
Double_t GetMaximum() const
Returns the maximum value of the histogram.
Definition: TH2Poly.cxx:766
static const double x2[5]
TList * fCells
Definition: TH2Poly.h:136
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
Int_t Fill(Double_t, const char *, Double_t)
Increment cell defined by x,namey by a weight w.
Definition: TH2Poly.h:92
Int_t AddBin(TObject *poly)
Adds a new bin to the histogram.
Definition: TH2Poly.cxx:202
Bool_t IsIntersecting(TH2PolyBin *bin, Double_t xclipl, Double_t xclipr, Double_t yclipb, Double_t yclipt)
Returns kTRUE if the input bin is intersecting with the input rectangle (xclipl, xclipr, yclipb, yclipt)
Definition: TH2Poly.cxx:960
virtual ~TH2Poly()
Destructor.
Definition: TH2Poly.cxx:187
ClassDef(TAttLine, 2)
Double_t GetXMax()
Returns the maximum value for the x coordinates of the bin.
Definition: TH2Poly.cxx:1292
Double_t GetYMin()
Returns the minimum value for the y coordinates of the bin.
Definition: TH2Poly.cxx:1400
void SetBinContent(Int_t, Int_t, Int_t, Double_t)
Definition: TH2Poly.h:125
Double_t GetYMax()
Returns the maximum value for the y coordinates of the bin.
Definition: TH2Poly.cxx:1364
TH1F * h1
Definition: legend1.C:5
void SetContent(Double_t content)
Definition: TH2Poly.h:49
char * out
Definition: TBase64.cxx:29
TObject * fPoly
Definition: TH2Poly.h:54
void SetBinContent(Int_t, Int_t, Double_t)
Definition: TH2Poly.h:124
Bool_t fFloat
Definition: TH2Poly.h:140
A doubly linked list.
Definition: TList.h:47
Bool_t GetBinContentChanged() const
Definition: TH2Poly.h:101
Int_t fNumber
Definition: TH2Poly.h:53
virtual Double_t RetrieveBinContent(Int_t bin) const
Definition: TH2Poly.h:149
TList * GetBins()
Definition: TH2Poly.h:97
Int_t fCellY
Definition: TH2Poly.h:134
Service class for 2-Dim histogram classes.
Definition: TH2.h:36
void SetBinContent(Int_t bin, Double_t content)
Sets the contents of the input bin to the input content Negative values between -1 and -9 are for the...
Definition: TH2Poly.cxx:1194
virtual ~TH2PolyBin()
Destructor.
Definition: TH2Poly.cxx:1254
Collection abstract base class.
Definition: TCollection.h:48
The most important graphics class in the ROOT system.
Definition: TPad.h:46
TMarker * m
Definition: textangle.C:8
Double_t fArea
Definition: TH2Poly.h:55
const char * GetBinTitle(Int_t bin) const
Returns the bin title.
Definition: TH2Poly.cxx:756
Double_t Integral(Int_t, Int_t, const Option_t *) const
Definition: TH2Poly.h:116
Bool_t GetFloat()
Definition: TH2Poly.h:107
Int_t fNCells
Definition: TH2Poly.h:135
void SetFloat(Bool_t flag=true)
When set to kTRUE, allows the histogram to expand if a bin outside the limits is added.
Definition: TH2Poly.cxx:1208
TObject * GetPolygon() const
Definition: TH2Poly.h:42
Double_t GetContent() const
Definition: TH2Poly.h:39
TList * fBins
Definition: TH2Poly.h:131
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: TH2Poly.h:150
Double_t GetBinContent(Int_t, Int_t, Int_t) const
Definition: TH2Poly.h:100
Int_t Fill(const char *, Double_t, Double_t)
Increment cell defined by namex,y by a weight w.
Definition: TH2Poly.h:93
return c2
Definition: legend2.C:14
static const double x1[5]
Double_t GetBinContent(Int_t, Int_t) const
Definition: TH2Poly.h:99
double Double_t
Definition: RtypesCore.h:55
Double_t fXmin
Definition: TH2Poly.h:57
Double_t Integral(Option_t *option="") const
Returns the integral of bin contents.
Definition: TH2Poly.cxx:681
Double_t y[n]
Definition: legend1.C:17
Bool_t fNewBinAdded
Definition: TH2Poly.h:141
Double_t fYmin
Definition: TH2Poly.h:58
The TH1 histogram class.
Definition: TH1.h:80
void Honeycomb(Double_t xstart, Double_t ystart, Double_t a, Int_t k, Int_t s)
Bins the histogram using a honeycomb structure.
Definition: TH2Poly.cxx:862
void ClearContent()
Definition: TH2Poly.h:36
void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TH2Poly.cxx:1123
#define name(a, b)
Definition: linkTestLib0.cpp:5
void ClearBinContents()
Clears the contents of all bins in the histogram.
Definition: TH2Poly.cxx:467
Mother of all ROOT objects.
Definition: TObject.h:58
void FillN(Int_t, const Double_t *, const Double_t *, Int_t)
Fill this histogram with an array x and weights w.
Definition: TH2Poly.h:95
Double_t Integral(Int_t, Int_t, Int_t, Int_t, const Option_t *) const
Definition: TH2Poly.h:117
void Reset(Option_t *option)
Reset this histogram: contents, errors, etc.
Definition: TH2Poly.cxx:491
1-Dim function class
Definition: TF1.h:149
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
Double_t GetArea()
Returns the area of the bin.
Definition: TH2Poly.cxx:1262
Int_t GetBinNumber() const
Definition: TH2Poly.h:41
Double_t fStepY
Definition: TH2Poly.h:137
void Fill(Double_t w)
Definition: TH2Poly.h:37
Int_t Fill(const char *, const char *, Double_t)
Increment cell defined by namex,namey by a weight w.
Definition: TH2Poly.h:94
Bool_t IsInside(Double_t x, Double_t y) const
Return "true" if the point (x,y) is inside the bin.
Definition: TH2Poly.cxx:1436
Double_t GetMinimum() const
Returns the minimum value of the histogram.
Definition: TH2Poly.cxx:814
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2Poly.h:91
Double_t GetXMin()
Returns the minimum value for the x coordinates of the bin.
Definition: TH2Poly.cxx:1328
Double_t fContent
Definition: TH2Poly.h:56
Bool_t IsIntersectingPolygon(Int_t bn, Double_t *x, Double_t *y, Double_t xclipl, Double_t xclipr, Double_t yclipb, Double_t yclipt)
Returns kTRUE if the input polygon (bn, x, y) is intersecting with the input rectangle (xclipl...
Definition: TH2Poly.cxx:1001
Double_t fYmax
Definition: TH2Poly.h:60
Bool_t fChanged
Definition: TH2Poly.h:52
const Int_t n
Definition: legend1.C:16
void FillN(Int_t ntimes, const Double_t *x, const Double_t *y, const Double_t *w, Int_t stride=1)
Fills a 2-D histogram with an array of values and weights.
Definition: TH2Poly.cxx:667
Int_t Fill(Double_t x, Double_t y)
Increment the bin containing (x,y) by 1.
Definition: TH2Poly.cxx:564
2D Histogram with Polygonal Bins
Definition: TH2Poly.h:70
void SetNewBinAdded(Bool_t flag)
Definition: TH2Poly.h:128
TH2PolyBin()
Default constructor.
Definition: TH2Poly.cxx:1222
Int_t fNcells
Definition: TH1.h:101