AliRoot Core  v5-06-30 (35d6c57)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMUONPolygon.cxx
Go to the documentation of this file.
1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15 
16 // $Id$
17 
23 
24 #include "AliMUONPolygon.h"
25 
26 #include "AliLog.h"
27 #include "Riostream.h"
28 #include "TMath.h"
29 
30 using std::cout;
31 using std::endl;
35 
36 //_____________________________________________________________________________
37 AliMUONPolygon::AliMUONPolygon(Int_t nvertices)
38 : TObject(),
39 fN(nvertices),
40 fX(new Double_t[fN]),
41 fY(new Double_t[fN])
42 {
44 }
45 
46 //_____________________________________________________________________________
47 AliMUONPolygon::AliMUONPolygon(Double_t xpos, Double_t ypos, Double_t halfsizex, Double_t halfsizey)
48 : TObject(),
49 fN(5),
50 fX(new Double_t[fN]),
51 fY(new Double_t[fN])
52 {
54 
55 
56  double xmin(xpos-halfsizex);
57  double xmax(xpos+halfsizex);
58  double ymin(ypos-halfsizey);
59  double ymax(ypos+halfsizey);
60 
61  SetVertex(0,xmin,ymin);
62  SetVertex(1,xmax,ymin);
63  SetVertex(2,xmax,ymax);
64  SetVertex(3,xmin,ymax);
65 
66  Close();
67 }
68 
69 
70 //_____________________________________________________________________________
72 {
74  delete[] fX;
75  delete[] fY;
76 }
77 
78 //______________________________________________________________________________
80 : TObject(rhs),
81 fN(rhs.fN),
82 fX(0x0),
83 fY(0x0)
84 {
86 
87  if ( fN > 0 )
88  {
89  fX = new Double_t[fN];
90  fY = new Double_t[fN];
91 
92  for ( Int_t i = 0; i < fN; ++i )
93  {
94  fX[i] = rhs.fX[i];
95  fY[i] = rhs.fY[i];
96  }
97 
98  }
99 
100 }
101 
102 //______________________________________________________________________________
105 {
107  if ( this != &rhs )
108  {
109  static_cast<TObject&>(*this)=rhs;
110 
111  delete[] fX;
112  delete[] fY;
113 
114  fX = 0;
115  fY = 0;
116 
117  fN = rhs.fN;
118 
119  if ( fN > 0 )
120  {
121  fX = new Double_t[fN];
122  fY = new Double_t[fN];
123 
124  for ( Int_t i = 0; i < fN; ++i )
125  {
126  fX[i] = rhs.fX[i];
127  fY[i] = rhs.fY[i];
128  }
129 
130  }
131  }
132  return *this;
133 }
134 
135 //______________________________________________________________________________
136 Bool_t
137 AliMUONPolygon::Contains(Double_t x, Double_t y) const
138 {
140 
141  // Note that the polygon must be a closed polygon (1st and last point
142  // must be identical), which should be the case here.
143 
144  return TMath::IsInside(x,y,fN,fX,fY);
145 }
146 
147 //_____________________________________________________________________________
148 void
150 {
152 
153  SetVertex(fN-1,X(0),Y(0));
154 }
155 
156 //_____________________________________________________________________________
157 void AliMUONPolygon::Print(Option_t*) const
158 {
160  cout << Form("AliMUONPolygon : %3d vertices. Signed Area=%e",NumberOfVertices(),SignedArea()) << endl;
161  for ( Int_t i = 0; i < NumberOfVertices(); ++i )
162  {
163  cout << Form("%10.5f,%10.5f",X(i),Y(i)) << endl;
164  }
165 }
166 
167 //_____________________________________________________________________________
168 Double_t
170 {
174 
175  Double_t area(0.0);
176 
177  for ( Int_t i = 0; i < NumberOfVertices()-1; ++i )
178  {
179  area += X(i)*Y(i+1) - X(i+1)*Y(i);
180  }
181 
182  return area;
183 }
184 
185 //_____________________________________________________________________________
186 void
188 {
190  Double_t* x = new Double_t[fN];
191  Double_t* y = new Double_t[fN];
192 
193  for ( Int_t i = fN-1; i >= 0; --i )
194  {
195  x[i] = X(fN-i-1);
196  y[i] = Y(fN-i-1);
197  }
198 
199  delete[] fX;
200  delete[] fY;
201 
202  fX = x;
203  fY = y;
204 }
205 
206 //_____________________________________________________________________________
207 void
208 AliMUONPolygon::SetVertex(Int_t i, Double_t x, Double_t y)
209 {
211  if ( i >= fN )
212  {
213  AliFatal("Wrong index");
214  }
215  fX[i] = x;
216  fY[i] = y;
217 }
218 
Int_t fN
Number of vertices.
Double_t Y(Int_t i) const
Return the y-coordinate of the i-th vertex.
AliMUONPolygon(Int_t nvertices=5)
Double_t * fX
Vertices x coordinates.
A planar polygon.
Double_t SignedArea() const
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
void Print(Option_t *opt="") const
Int_t NumberOfVertices() const
Get the number of vertices of this polygon.
Double_t X(Int_t i) const
Return the x-coordinate of the i-th vertex.
virtual ~AliMUONPolygon()
void SetVertex(Int_t i, Double_t x, Double_t y)
AliMUONPolygon & operator=(const AliMUONPolygon &rhs)
Double_t * fY
Vertices y coordinates.
Bool_t Contains(Double_t x, Double_t y) const