]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpArea.cxx
Replacement of TVector2 object with two doubles
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpArea.cxx
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 // $MpId: AliMpArea.cxx,v 1.8 2006/05/24 13:58:29 ivana Exp $
18 // Category: basic
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpArea
22 // ----------------
23 // Class that defines a rectangle area positioned in plane..
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 //-----------------------------------------------------------------------------
27
28 #include "AliMpArea.h"
29
30 #include "AliLog.h"
31 #include "AliMpConstants.h"
32
33 #include <Riostream.h>
34
35 /// \cond CLASSIMP
36 ClassImp(AliMpArea)
37 /// \endcond
38
39 //_____________________________________________________________________________
40 AliMpArea::AliMpArea(Double_t x, Double_t y, 
41                      Double_t dx, Double_t dy)
42   : TObject(),
43     fPositionX(x),
44     fPositionY(y),
45     fDimensionX(dx),
46     fDimensionY(dy),
47     fValidity(true) 
48 {
49 /// Standard constructor
50
51   // Check dimensions
52   if (  fDimensionX < - AliMpConstants::LengthTolerance() || 
53         fDimensionY < - AliMpConstants::LengthTolerance() || 
54       ( fDimensionX < AliMpConstants::LengthTolerance() && 
55         fDimensionY < AliMpConstants::LengthTolerance() ) )
56   {
57     fDimensionX = 0.;
58     fDimensionY = 0.;
59     fValidity = false;
60   }  
61 }
62
63 //_____________________________________________________________________________
64 AliMpArea::AliMpArea()
65   : TObject(),
66     fPositionX(0.),
67     fPositionY(0.),
68     fDimensionX(0.),
69     fDimensionY(0.),
70     fValidity(false) 
71 {
72 /// Default constructor
73 }
74
75 //_____________________________________________________________________________
76 AliMpArea::AliMpArea(const AliMpArea& rhs):
77   TObject(rhs),
78   fPositionX(rhs.fPositionX),
79   fPositionY(rhs.fPositionY),
80   fDimensionX(rhs.fDimensionX), 
81   fDimensionY(rhs.fDimensionY), 
82   fValidity(rhs.fValidity) 
83 {
84 /// Copy constructor
85 }
86
87 //_____________________________________________________________________________
88 AliMpArea::~AliMpArea() 
89 {
90 /// Destructor
91 }
92
93 //
94 // operators
95 //
96
97 //______________________________________________________________________________
98 AliMpArea& AliMpArea::operator = (const AliMpArea& right)
99 {
100 /// Assignment operator
101
102   // check assignment to self
103   if (this == &right) return *this;
104
105   // base class assignment
106   TObject::operator=(right);
107
108   fPositionX = right.fPositionX;
109   fPositionY = right.fPositionY;
110   fDimensionX = right.fDimensionX;
111   fDimensionY = right.fDimensionY;
112   fValidity = right.fValidity;
113
114   return *this;
115
116
117 //
118 // public methods
119 //
120
121 //_____________________________________________________________________________
122 Double_t AliMpArea::LeftBorder() const
123 {
124 /// Return the position of the left edge.
125
126   return fPositionX - fDimensionX;
127 }
128
129 //_____________________________________________________________________________
130 Double_t AliMpArea::RightBorder() const
131 {
132 /// Return the position of right edge.
133
134   return fPositionX + fDimensionX;
135 }
136
137 //_____________________________________________________________________________
138 Double_t AliMpArea::UpBorder() const
139 {
140 /// Return the position of the up edge.
141
142   return fPositionY + fDimensionY;
143 }
144
145 //_____________________________________________________________________________
146 Double_t AliMpArea::DownBorder() const
147 {
148 /// Return the position of the down edge.
149
150   return fPositionY - fDimensionY;
151 }
152
153 //_____________________________________________________________________________
154 void AliMpArea::LeftDownCorner(Double_t& x, Double_t& y) const
155 {
156 /// Return position of the left down corner.
157
158   x = LeftBorder();
159   y = DownBorder();
160 }  
161
162 //_____________________________________________________________________________
163 void AliMpArea::LeftUpCorner(Double_t& x, Double_t& y) const
164 {
165 /// Return position of the left up corner.
166
167   x = LeftBorder();
168   y = UpBorder();
169 }  
170
171 //_____________________________________________________________________________
172 void AliMpArea::RightDownCorner(Double_t& x, Double_t& y) const
173 {
174 /// Return position of the right down corner.
175
176   x = RightBorder();
177   y = DownBorder();
178 }  
179
180
181 //_____________________________________________________________________________
182 void AliMpArea::RightUpCorner(Double_t& x, Double_t& y) const
183 {
184 /// Return position of the right up corner.
185
186   x = RightBorder();
187   y = UpBorder();
188 }  
189
190 //_____________________________________________________________________________
191 Bool_t AliMpArea::Contains(const AliMpArea& area) const
192 {
193 /// Whether area is contained within this
194   
195 //  return
196 //    ( area.LeftBorder() > LeftBorder() - AliMpConstants::LengthTolerance() &&
197 //      area.RightBorder() < RightBorder() +  AliMpConstants::LengthTolerance() &&
198 //      area.DownBorder() > DownBorder() - AliMpConstants::LengthTolerance() &&
199 //      area.UpBorder() < UpBorder() + AliMpConstants::LengthTolerance() );
200
201   if ( area.LeftBorder() < LeftBorder() ||
202        area.RightBorder() > RightBorder() ||
203        area.DownBorder() < DownBorder() ||
204        area.UpBorder() > UpBorder() ) 
205   {
206     return kFALSE;
207   }
208   else
209   {
210     return kTRUE;
211   }
212 }
213
214 //_____________________________________________________________________________
215 AliMpArea AliMpArea::Intersect(const AliMpArea& area) const
216
217 /// Return the common part of area and this
218
219   Double_t xmin = TMath::Max(area.LeftBorder(),LeftBorder());
220   Double_t xmax = TMath::Min(area.RightBorder(),RightBorder());
221   Double_t ymin = TMath::Max(area.DownBorder(),DownBorder());
222   Double_t ymax = TMath::Min(area.UpBorder(),UpBorder());
223
224   return AliMpArea( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ,
225                     (xmax-xmin)/2.0, (ymax-ymin)/2.0 );
226 }
227
228 //_____________________________________________________________________________
229 Bool_t AliMpArea::Overlap(const AliMpArea& area) const
230 {
231 /// Return true if this overlaps with given area
232
233   if ( LeftBorder() > area.RightBorder() - AliMpConstants::LengthTolerance() ||
234        RightBorder() < area.LeftBorder() + AliMpConstants::LengthTolerance() )
235   {
236     return kFALSE;
237   }
238
239   if ( DownBorder() > area.UpBorder() - AliMpConstants::LengthTolerance() ||
240        UpBorder() < area.DownBorder() + AliMpConstants::LengthTolerance() )
241   {
242     return kFALSE;
243   }
244   return kTRUE;
245   
246 }
247
248 //_____________________________________________________________________________
249 void
250 AliMpArea::Print(Option_t* opt) const
251 {
252 /// Printing
253 /// When option is set to B (borders), the area boreders will be printed 
254 /// instead of default parameters
255
256   
257   if ( opt[0] == 'B' ) {
258     cout << "Area x-borders: (" 
259          << LeftBorder() << ", " << RightBorder() << ") " 
260          << " y-borders: (" 
261          << DownBorder() << ", " << UpBorder() << ") " 
262          << endl;
263     return;
264
265   }       
266
267   cout << (*this) << endl;
268 }
269
270 //_____________________________________________________________________________
271 void      
272 AliMpArea::GetParameters(Double_t& x, Double_t& y,
273                          Double_t& dx, Double_t& dy) const
274 {                         
275   x = fPositionX;
276   y = fPositionY;
277   dx = fDimensionX;
278   dy = fDimensionY;
279 }  
280
281 //_____________________________________________________________________________
282 ostream& operator<< (ostream &stream,const AliMpArea& area)
283 {
284 /// Output streaming
285
286   stream << "Area: position: (" 
287          << area.GetPositionX() << ", " << area.GetPositionY() << ") " 
288          << " dimensions: (" 
289          << area.GetDimensionX() << ", " << area.GetDimensionY() << ") " 
290   << " valid: " << (area.IsValid()==true ? "YES":"NO")
291          << endl;
292   return stream;
293 }
294