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