Logo ROOT   6.10/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 #include "TH2.h"
24 
25 class TH2PolyBin: public TObject{
26 
27 public:
28  TH2PolyBin();
29  TH2PolyBin(TObject *poly, Int_t bin_number);
30  virtual ~TH2PolyBin();
31 
32  void ClearContent(){fContent = 0;}
33  void Fill(Double_t w) {fContent = fContent+w; SetChanged(true);}
34  Double_t GetArea();
35  Double_t GetContent() const{return fContent;}
36  Bool_t GetChanged() const{return fChanged;}
37  Int_t GetBinNumber() const {return fNumber;}
38  TObject *GetPolygon() const {return fPoly;}
39  Double_t GetXMax();
40  Double_t GetXMin();
41  Double_t GetYMax();
42  Double_t GetYMin();
44  void SetChanged(Bool_t flag){fChanged = flag;}
45  void SetContent(Double_t content){fContent = content; SetChanged(true);}
46 
47 protected:
48  Bool_t fChanged; //For the 3D Painter
49  Int_t fNumber; //Bin number of the bin in TH2Poly
50  TObject *fPoly; //Object holding the polygon definition
51  Double_t fArea; //Bin area
52  Double_t fContent; //Bin content
53  Double_t fXmin; //X minimum value
54  Double_t fYmin; //Y minimum value
55  Double_t fXmax; //X maximum value
56  Double_t fYmax; //Y maximum value
57 
58  ClassDef(TH2PolyBin,1) //2-Dim polygon bins
59 };
60 
61 class TList;
62 class TGraph;
63 class TMultiGraph;
64 class TPad;
65 
66 class TH2Poly : public TH2 {
67 
68 public:
69  TH2Poly();
70  TH2Poly(const char *name,const char *title, Double_t xlow, Double_t xup, Double_t ylow, Double_t yup);
71  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);
72  virtual ~TH2Poly();
73 
74  virtual TH2PolyBin *CreateBin(TObject *poly);
75  virtual Int_t AddBin(TObject *poly);
76  Int_t AddBin(Int_t n, const Double_t *x, const Double_t *y);
77  Int_t AddBin(Double_t x1, Double_t y1, Double_t x2, Double_t y2);
78  virtual Bool_t Add(const TH1 *h1, Double_t c1);
79  virtual Bool_t Add(const TH1 *h1, const TH1 *h2, Double_t c1=1, Double_t c2=1);
80  virtual Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="");
81  void ClearBinContents(); // Clears the content of all bins
82  TObject *Clone(const char* newname = "") const;
83  void ChangePartition(Int_t n, Int_t m); // Sets the number of partition cells to another value
84  virtual Int_t Fill(Double_t x,Double_t y);
85  virtual Int_t Fill(Double_t x,Double_t y, Double_t w);
86  virtual Int_t Fill(const char* name, Double_t w);
87  void FillN(Int_t ntimes, const Double_t* x, const Double_t* y, const Double_t* w, Int_t stride = 1);
88  Int_t Fill(Double_t){return -1;} //MayNotUse
89  Int_t Fill(Double_t , const char *, Double_t){return -1;} //MayNotUse
90  Int_t Fill(const char *, Double_t , Double_t ){return -1;} //MayNotUse
91  Int_t Fill(const char *, const char *, Double_t ){return -1;} //MayNotUse
92  void FillN(Int_t, const Double_t*, const Double_t*, Int_t){return;} //MayNotUse
93  Int_t FindBin(Double_t x, Double_t y, Double_t z = 0);
94  TList *GetBins(){return fBins;} // Returns the TList of all bins in the histogram
95  virtual Double_t GetBinContent(Int_t bin) const;
96  virtual Double_t GetBinContent(Int_t, Int_t) const {return 0;} //MayNotUse
97  virtual Double_t GetBinContent(Int_t, Int_t, Int_t) const {return 0;} //MayNotUse
98  Bool_t GetBinContentChanged() const{return fBinContentChanged;}
99  virtual Double_t GetBinError(Int_t bin) const;
100  virtual Double_t GetBinError(Int_t , Int_t) const {return 0;} //MayNotUse
101  virtual Double_t GetBinError(Int_t , Int_t , Int_t) const {return 0;} //MayNotUse
102  const char *GetBinName(Int_t bin) const;
103  const char *GetBinTitle(Int_t bin) const;
104  Bool_t GetFloat(){return fFloat;}
105  Double_t GetMaximum() const;
106  Double_t GetMaximum(Double_t maxval) const;
107  Double_t GetMinimum() const;
108  Double_t GetMinimum(Double_t minval) const;
109  Bool_t GetNewBinAdded() const{return fNewBinAdded;}
110  Int_t GetNumberOfBins() const{return fNcells-kNOverflow;}
111  void Honeycomb(Double_t xstart, Double_t ystart, Double_t a, Int_t k, Int_t s); // Bins the histogram using a honeycomb structure
112  Double_t Integral(Option_t* option = "") const;
113  Double_t Integral(Int_t, Int_t, const Option_t*) const{return 0;} //MayNotUse
114  Double_t Integral(Int_t, Int_t, Int_t, Int_t, const Option_t*) const{return 0;} //MayNotUse
115  Double_t Integral(Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, const Option_t*) const{return 0;} //MayNotUse
116  Long64_t Merge(TCollection *);
117  virtual void Reset(Option_t *option);
118  virtual void Scale(Double_t c1 = 1, Option_t* option = "");
119  void SavePrimitive(std::ostream& out, Option_t* option = "");
120  void SetBinContent(Int_t bin, Double_t content);
121  void SetBinContent(Int_t, Int_t, Double_t){return;} //MayNotUse
122  void SetBinContent(Int_t, Int_t, Int_t, Double_t){return;} //MayNotUse
123  void SetBinContentChanged(Bool_t flag){fBinContentChanged = flag;}
124  void SetFloat(Bool_t flag = true);
125  void SetNewBinAdded(Bool_t flag){fNewBinAdded = flag;}
126  Bool_t IsInsideBin(Int_t binnr, Double_t x, Double_t y);
127  virtual void GetStats(Double_t *stats) const;
128 
129 
130 protected:
131  enum {
132  kNOverflow = 9 // number of overflows bins
133  };
134  TList *fBins; //List of bins. The list owns the contained objects
135  Double_t fOverflow[kNOverflow]; //Overflow bins
136  Int_t fCellX; //Number of partition cells in the x-direction of the histogram
137  Int_t fCellY; //Number of partition cells in the y-direction of the histogram
138  Int_t fNCells; //Number of partition cells: fCellX*fCellY
139  TList *fCells; //[fNCells] The array of TLists that store the bins that intersect with each cell. List do not own the contained objects
140  Double_t fStepX, fStepY; //Dimensions of a partition cell
141  Bool_t *fIsEmpty; //[fNCells] The array that returns true if the cell at the given coordinate is empty
142  Bool_t *fCompletelyInside; //[fNCells] The array that returns true if the cell at the given coordinate is completely inside a bin
143  Bool_t fFloat; //When set to kTRUE, allows the histogram to expand if a bin outside the limits is added.
144  Bool_t fNewBinAdded; //!For the 3D Painter
145  Bool_t fBinContentChanged; //!For the 3D Painter
146 
147  void AddBinToPartition(TH2PolyBin *bin); // Adds the input bin into the partition matrix
148  void Initialize(Double_t xlow, Double_t xup, Double_t ylow, Double_t yup, Int_t n, Int_t m);
149  Bool_t IsIntersecting(TH2PolyBin *bin, Double_t xclipl, Double_t xclipr, Double_t yclipb, Double_t yclipt);
150  Bool_t IsIntersectingPolygon(Int_t bn, Double_t *x, Double_t *y, Double_t xclipl, Double_t xclipr, Double_t yclipb, Double_t yclipt);
151  // needed by TH1 - no need to have a separate implementation , but internal ibin=0 is first bin.
152  virtual Double_t RetrieveBinContent(Int_t bin) const {
153  return (bin>=kNOverflow) ? GetBinContent(bin-kNOverflow+1) : GetBinContent(-bin-1);
154  }
155  virtual void UpdateBinContent(Int_t bin, Double_t content) {
156  return (bin>=kNOverflow) ? SetBinContent(bin-kNOverflow+1,content) : SetBinContent(-bin-1,content);
157  }
158 
159  ClassDef(TH2Poly,1) //2-Dim histogram with polygon bins
160  };
161 
162 #endif
Bool_t fBinContentChanged
For the 3D Painter.
Definition: TH2Poly.h:145
long long Long64_t
Definition: RtypesCore.h:69
Bool_t * fCompletelyInside
Definition: TH2Poly.h:142
const char Option_t
Definition: RtypesCore.h:62
return c1
Definition: legend1.C:41
Int_t GetBinNumber() const
Definition: TH2Poly.h:37
void SetChanged(Bool_t flag)
Definition: TH2Poly.h:44
A TMultiGraph is a collection of TGraph (or derived) objects.
Definition: TMultiGraph.h:35
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
Double_t fXmax
Definition: TH2Poly.h:55
Bool_t IsInside(Double_t x, Double_t y) const
Return "true" if the point (x,y) is inside the bin.
Definition: TH2Poly.cxx:1509
void SetBinContentChanged(Bool_t flag)
Definition: TH2Poly.h:123
Helper class to represent a bin in the TH2Poly histogram.
Definition: TH2Poly.h:25
Bool_t * fIsEmpty
Definition: TH2Poly.h:141
Int_t fCellX
Definition: TH2Poly.h:136
static const double x2[5]
TList * fCells
Definition: TH2Poly.h:139
Double_t x[n]
Definition: legend1.C:17
Double_t Integral(Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, const Option_t *) const
Definition: TH2Poly.h:115
#define ClassDef(name, id)
Definition: Rtypes.h:297
Bool_t GetChanged() const
Definition: TH2Poly.h:36
Int_t Fill(Double_t, const char *, Double_t)
Increment cell defined by x,namey by a weight w.
Definition: TH2Poly.h:89
Double_t Integral(Int_t, Int_t, const Option_t *) const
Definition: TH2Poly.h:113
Double_t GetXMax()
Returns the maximum value for the x coordinates of the bin.
Definition: TH2Poly.cxx:1365
Double_t GetYMin()
Returns the minimum value for the y coordinates of the bin.
Definition: TH2Poly.cxx:1473
void SetBinContent(Int_t, Int_t, Int_t, Double_t)
Definition: TH2Poly.h:122
Double_t GetYMax()
Returns the maximum value for the y coordinates of the bin.
Definition: TH2Poly.cxx:1437
TH1F * h1
Definition: legend1.C:5
void SetContent(Double_t content)
Definition: TH2Poly.h:45
TObject * fPoly
Definition: TH2Poly.h:50
void SetBinContent(Int_t, Int_t, Double_t)
Definition: TH2Poly.h:121
Bool_t fFloat
Definition: TH2Poly.h:143
A doubly linked list.
Definition: TList.h:43
TObject * GetPolygon() const
Definition: TH2Poly.h:38
Int_t fNumber
Definition: TH2Poly.h:49
TList * GetBins()
Definition: TH2Poly.h:94
Int_t fCellY
Definition: TH2Poly.h:137
Service class for 2-Dim histogram classes.
Definition: TH2.h:30
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176
virtual ~TH2PolyBin()
Destructor.
Definition: TH2Poly.cxx:1327
Double_t GetContent() const
Definition: TH2Poly.h:35
Collection abstract base class.
Definition: TCollection.h:42
Double_t Integral(Int_t, Int_t, Int_t, Int_t, const Option_t *) const
Definition: TH2Poly.h:114
The most important graphics class in the ROOT system.
Definition: TPad.h:29
TMarker * m
Definition: textangle.C:8
Int_t GetNumberOfBins() const
Definition: TH2Poly.h:110
Double_t fArea
Definition: TH2Poly.h:51
Bool_t GetFloat()
Definition: TH2Poly.h:104
Int_t fNCells
Definition: TH2Poly.h:138
void Reset(Detail::TBranchProxy *x)
TList * fBins
Definition: TH2Poly.h:134
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:155
Int_t Fill(const char *, Double_t, Double_t)
Increment cell defined by namex,y by a weight w.
Definition: TH2Poly.h:90
void Add(THist< DIMENSIONS, PRECISION_TO, STAT_TO... > &to, const THist< DIMENSIONS, PRECISION_FROM, STAT_FROM... > &from)
Add two histograms.
Definition: THist.hxx:336
return c2
Definition: legend2.C:14
static const double x1[5]
Bool_t GetNewBinAdded() const
Definition: TH2Poly.h:109
double Double_t
Definition: RtypesCore.h:55
virtual Double_t GetBinError(Int_t, Int_t) const
Definition: TH2Poly.h:100
Double_t fXmin
Definition: TH2Poly.h:53
Double_t y[n]
Definition: legend1.C:17
Bool_t fNewBinAdded
Definition: TH2Poly.h:144
Double_t fYmin
Definition: TH2Poly.h:54
The TH1 histogram class.
Definition: TH1.h:56
void ClearContent()
Definition: TH2Poly.h:32
Mother of all ROOT objects.
Definition: TObject.h:37
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:151
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
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:92
Bool_t GetBinContentChanged() const
Definition: TH2Poly.h:98
1-Dim function class
Definition: TF1.h:150
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
Double_t GetArea()
Returns the area of the bin.
Definition: TH2Poly.cxx:1335
Double_t fStepY
Definition: TH2Poly.h:140
void Fill(Double_t w)
Definition: TH2Poly.h:33
Int_t Fill(const char *, const char *, Double_t)
Increment cell defined by namex,namey by a weight w.
Definition: TH2Poly.h:91
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2Poly.h:88
Double_t GetXMin()
Returns the minimum value for the x coordinates of the bin.
Definition: TH2Poly.cxx:1401
Double_t fContent
Definition: TH2Poly.h:52
virtual Double_t GetBinError(Int_t, Int_t, Int_t) const
Definition: TH2Poly.h:101
Double_t fYmax
Definition: TH2Poly.h:56
Bool_t fChanged
Definition: TH2Poly.h:48
const Int_t n
Definition: legend1.C:16
2D Histogram with Polygonal Bins
Definition: TH2Poly.h:66
void SetNewBinAdded(Bool_t flag)
Definition: TH2Poly.h:125
TH2PolyBin()
Default constructor.
Definition: TH2Poly.cxx:1295
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: TH2Poly.h:152
virtual Double_t GetBinContent(Int_t, Int_t) const
Definition: TH2Poly.h:96
virtual Double_t GetBinContent(Int_t, Int_t, Int_t) const
Definition: TH2Poly.h:97
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:657