New macro to keep track of timing performances of the segmentation methods (Laurent)
[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(const TVector2& position, const TVector2& dimensions)
41   : TObject(),
42     fPosition(position),
43     fDimensions(dimensions),
44     fValidity(true) 
45 {
46 /// Standard constructor
47
48   // Check dimensions
49   if (  fDimensions.X() < - AliMpConstants::LengthTolerance() || 
50         fDimensions.Y() < - AliMpConstants::LengthTolerance() || 
51       ( fDimensions.X() < AliMpConstants::LengthTolerance() && 
52         fDimensions.Y() < AliMpConstants::LengthTolerance() ) )
53   {
54     fDimensions = TVector2();
55     fValidity = false;
56   }  
57 }
58
59 //_____________________________________________________________________________
60 AliMpArea::AliMpArea()
61   : TObject(),
62     fPosition(TVector2()),
63     fDimensions(TVector2()), 
64     fValidity(false) 
65 {
66 /// Default constructor
67 }
68
69 //_____________________________________________________________________________
70 AliMpArea::AliMpArea(const AliMpArea& rhs):
71   TObject(rhs),
72   fPosition(rhs.fPosition),
73   fDimensions(rhs.fDimensions), 
74   fValidity(rhs.fValidity) 
75 {
76 /// Copy constructor
77 }
78
79 //_____________________________________________________________________________
80 AliMpArea::~AliMpArea() 
81 {
82 /// Destructor
83 }
84
85 //
86 // operators
87 //
88
89 //______________________________________________________________________________
90 AliMpArea& AliMpArea::operator = (const AliMpArea& right)
91 {
92 /// Assignment operator
93
94   // check assignment to self
95   if (this == &right) return *this;
96
97   // base class assignment
98   TObject::operator=(right);
99
100   fPosition = right.fPosition;
101   fDimensions = right.fDimensions;
102   fValidity = right.fValidity;
103
104   return *this;
105
106
107 //
108 // public methods
109 //
110
111 //_____________________________________________________________________________
112 Double_t AliMpArea::LeftBorder() const
113 {
114 /// Return the position of the left edge.
115
116   return fPosition.X() - fDimensions.X();
117 }
118
119 //_____________________________________________________________________________
120 Double_t AliMpArea::RightBorder() const
121 {
122 /// Return the position of right edge.
123
124   return fPosition.X() + fDimensions.X();
125 }
126
127 //_____________________________________________________________________________
128 Double_t AliMpArea::UpBorder() const
129 {
130 /// Return the position of the up edge.
131
132   return fPosition.Y() + fDimensions.Y();
133 }
134
135 //_____________________________________________________________________________
136 Double_t AliMpArea::DownBorder() const
137 {
138 /// Return the position of the down edge.
139
140   return fPosition.Y() - fDimensions.Y();
141 }
142
143 //_____________________________________________________________________________
144 TVector2 AliMpArea::LeftDownCorner() const
145 {
146 /// Return position of the left down corner.
147
148   return TVector2(LeftBorder(), DownBorder());
149 }  
150
151 //_____________________________________________________________________________
152 TVector2 AliMpArea::LeftUpCorner() const
153 {
154 /// Return position of the left up corner.
155
156   return TVector2(LeftBorder(), UpBorder());
157 }  
158
159 //_____________________________________________________________________________
160 TVector2 AliMpArea::RightDownCorner() const
161 {
162 /// Return position of the right down corner.
163
164   return TVector2(RightBorder(), DownBorder());
165 }  
166
167
168 //_____________________________________________________________________________
169 TVector2 AliMpArea::RightUpCorner() const
170 {
171 /// Return position of the right up corner.
172
173   return TVector2(RightBorder(), UpBorder());
174 }  
175
176 //_____________________________________________________________________________
177 Bool_t AliMpArea::Contains(const AliMpArea& area) const
178 {
179 /// Whether area is contained within this
180   
181 //  return
182 //    ( area.LeftBorder() > LeftBorder() - AliMpConstants::LengthTolerance() &&
183 //      area.RightBorder() < RightBorder() +  AliMpConstants::LengthTolerance() &&
184 //      area.DownBorder() > DownBorder() - AliMpConstants::LengthTolerance() &&
185 //      area.UpBorder() < UpBorder() + AliMpConstants::LengthTolerance() );
186
187   if ( area.LeftBorder() < LeftBorder() ||
188        area.RightBorder() > RightBorder() ||
189        area.DownBorder() < DownBorder() ||
190        area.UpBorder() > UpBorder() ) 
191   {
192     return kFALSE;
193   }
194   else
195   {
196     return kTRUE;
197   }
198 }
199
200 //_____________________________________________________________________________
201 AliMpArea AliMpArea::Intersect(const AliMpArea& area) const
202
203 /// Return the common part of area and this
204
205   Double_t xmin = TMath::Max(area.LeftBorder(),LeftBorder());
206   Double_t xmax = TMath::Min(area.RightBorder(),RightBorder());
207   Double_t ymin = TMath::Max(area.DownBorder(),DownBorder());
208   Double_t ymax = TMath::Min(area.UpBorder(),UpBorder());
209
210   return AliMpArea( TVector2( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ),
211                     TVector2( (xmax-xmin)/2.0, (ymax-ymin)/2.0 ) );
212 }
213
214 //_____________________________________________________________________________
215 Bool_t AliMpArea::Overlap(const AliMpArea& area) const
216 {
217 /// Return true if this overlaps with given area
218
219   if ( LeftBorder() > area.RightBorder() - AliMpConstants::LengthTolerance() ||
220        RightBorder() < area.LeftBorder() + AliMpConstants::LengthTolerance() )
221   {
222     return kFALSE;
223   }
224
225   if ( DownBorder() > area.UpBorder() - AliMpConstants::LengthTolerance() ||
226        UpBorder() < area.DownBorder() + AliMpConstants::LengthTolerance() )
227   {
228     return kFALSE;
229   }
230   return kTRUE;
231   
232 }
233
234 //_____________________________________________________________________________
235 void
236 AliMpArea::Print(Option_t* opt) const
237 {
238 /// Printing
239 /// When option is set to B (borders), the area boreders will be printed 
240 /// instead of default parameters
241
242   
243   if ( opt[0] == 'B' ) {
244     cout << "Area x-borders: (" 
245          << LeftBorder() << ", " << RightBorder() << ") " 
246          << " y-borders: (" 
247          << DownBorder() << ", " << UpBorder() << ") " 
248          << endl;
249     return;
250
251   }       
252
253   cout << (*this) << endl;
254 }
255
256 //_____________________________________________________________________________
257 ostream& operator<< (ostream &stream,const AliMpArea& area)
258 {
259 /// Output streaming
260
261   stream << "Area: position: (" 
262          << area.Position().X() << ", " << area.Position().Y() << ") " 
263          << " dimensions: (" 
264          << area.Dimensions().X() << ", " << area.Dimensions().Y() << ") " 
265   << " valid: " << (area.IsValid()==true ? "YES":"NO")
266          << endl;
267   return stream;
268 }
269