]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/MUONmapping/AliMpArea.cxx
Fixes for object target dependencies
[u/mrichter/AliRoot.git] / MUON / MUONmapping / AliMpArea.cxx
CommitLineData
dee1d5f1 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
5f91c9e8 16// $Id$
13985652 17// $MpId: AliMpArea.cxx,v 1.8 2006/05/24 13:58:29 ivana Exp $
5f91c9e8 18// Category: basic
3d1463c8 19
20//-----------------------------------------------------------------------------
5f91c9e8 21// Class AliMpArea
22// ----------------
23// Class that defines a rectangle area positioned in plane..
3ffe1a93 24// Included in AliRoot: 2003/05/02
5f91c9e8 25// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
3d1463c8 26//-----------------------------------------------------------------------------
5f91c9e8 27
5f91c9e8 28#include "AliMpArea.h"
94f2b22c 29
30#include "AliLog.h"
52dd0c39 31#include "AliMpConstants.h"
5f91c9e8 32
2c605e66 33#include <Riostream.h>
34
b80faac0 35using std::cout;
36using std::endl;
13985652 37/// \cond CLASSIMP
5f91c9e8 38ClassImp(AliMpArea)
13985652 39/// \endcond
5f91c9e8 40
41//_____________________________________________________________________________
6e97fbb8 42AliMpArea::AliMpArea(Double_t x, Double_t y,
43 Double_t dx, Double_t dy)
5f91c9e8 44 : TObject(),
6e97fbb8 45 fPositionX(x),
46 fPositionY(y),
47 fDimensionX(dx),
48 fDimensionY(dy),
dee1d5f1 49 fValidity(true)
50{
51/// Standard constructor
52
5f91c9e8 53 // Check dimensions
6e97fbb8 54 if ( fDimensionX < - AliMpConstants::LengthTolerance() ||
55 fDimensionY < - AliMpConstants::LengthTolerance() ||
56 ( fDimensionX < AliMpConstants::LengthTolerance() &&
57 fDimensionY < AliMpConstants::LengthTolerance() ) )
52dd0c39 58 {
6e97fbb8 59 fDimensionX = 0.;
60 fDimensionY = 0.;
5f91c9e8 61 fValidity = false;
62 }
63}
64
65//_____________________________________________________________________________
66AliMpArea::AliMpArea()
67 : TObject(),
6e97fbb8 68 fPositionX(0.),
69 fPositionY(0.),
70 fDimensionX(0.),
71 fDimensionY(0.),
dee1d5f1 72 fValidity(false)
73{
74/// Default constructor
5f91c9e8 75}
76
77//_____________________________________________________________________________
78AliMpArea::AliMpArea(const AliMpArea& rhs):
79 TObject(rhs),
6e97fbb8 80 fPositionX(rhs.fPositionX),
81 fPositionY(rhs.fPositionY),
82 fDimensionX(rhs.fDimensionX),
83 fDimensionY(rhs.fDimensionY),
0471c97b 84 fValidity(rhs.fValidity)
dee1d5f1 85{
86/// Copy constructor
5f91c9e8 87}
88
89//_____________________________________________________________________________
dee1d5f1 90AliMpArea::~AliMpArea()
91{
92/// Destructor
5f91c9e8 93}
94
95//
96// operators
97//
98
99//______________________________________________________________________________
100AliMpArea& AliMpArea::operator = (const AliMpArea& right)
101{
dee1d5f1 102/// Assignment operator
5f91c9e8 103
dee1d5f1 104 // check assignment to self
5f91c9e8 105 if (this == &right) return *this;
106
dee1d5f1 107 // base class assignment
5f91c9e8 108 TObject::operator=(right);
109
6e97fbb8 110 fPositionX = right.fPositionX;
111 fPositionY = right.fPositionY;
112 fDimensionX = right.fDimensionX;
113 fDimensionY = right.fDimensionY;
5f91c9e8 114 fValidity = right.fValidity;
115
116 return *this;
117}
118
119//
120// public methods
121//
122
123//_____________________________________________________________________________
124Double_t AliMpArea::LeftBorder() const
125{
dee1d5f1 126/// Return the position of the left edge.
5f91c9e8 127
6e97fbb8 128 return fPositionX - fDimensionX;
5f91c9e8 129}
130
131//_____________________________________________________________________________
132Double_t AliMpArea::RightBorder() const
133{
dee1d5f1 134/// Return the position of right edge.
5f91c9e8 135
6e97fbb8 136 return fPositionX + fDimensionX;
5f91c9e8 137}
138
139//_____________________________________________________________________________
140Double_t AliMpArea::UpBorder() const
141{
dee1d5f1 142/// Return the position of the up edge.
5f91c9e8 143
6e97fbb8 144 return fPositionY + fDimensionY;
5f91c9e8 145}
146
147//_____________________________________________________________________________
148Double_t AliMpArea::DownBorder() const
149{
dee1d5f1 150/// Return the position of the down edge.
5f91c9e8 151
6e97fbb8 152 return fPositionY - fDimensionY;
5f91c9e8 153}
154
155//_____________________________________________________________________________
6e97fbb8 156void AliMpArea::LeftDownCorner(Double_t& x, Double_t& y) const
5f91c9e8 157{
dee1d5f1 158/// Return position of the left down corner.
5f91c9e8 159
6e97fbb8 160 x = LeftBorder();
161 y = DownBorder();
5f91c9e8 162}
163
164//_____________________________________________________________________________
6e97fbb8 165void AliMpArea::LeftUpCorner(Double_t& x, Double_t& y) const
5f91c9e8 166{
dee1d5f1 167/// Return position of the left up corner.
5f91c9e8 168
6e97fbb8 169 x = LeftBorder();
170 y = UpBorder();
5f91c9e8 171}
172
173//_____________________________________________________________________________
6e97fbb8 174void AliMpArea::RightDownCorner(Double_t& x, Double_t& y) const
5f91c9e8 175{
dee1d5f1 176/// Return position of the right down corner.
5f91c9e8 177
6e97fbb8 178 x = RightBorder();
179 y = DownBorder();
5f91c9e8 180}
181
182
183//_____________________________________________________________________________
6e97fbb8 184void AliMpArea::RightUpCorner(Double_t& x, Double_t& y) const
5f91c9e8 185{
dee1d5f1 186/// Return position of the right up corner.
5f91c9e8 187
6e97fbb8 188 x = RightBorder();
189 y = UpBorder();
5f91c9e8 190}
191
94f2b22c 192//_____________________________________________________________________________
193Bool_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//_____________________________________________________________________________
217AliMpArea 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
6e97fbb8 226 return AliMpArea( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ,
227 (xmax-xmin)/2.0, (ymax-ymin)/2.0 );
94f2b22c 228}
229
230//_____________________________________________________________________________
231Bool_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
52dd0c39 250//_____________________________________________________________________________
251void
ce5605e9 252AliMpArea::Print(Option_t* opt) const
52dd0c39 253{
71a2d3aa 254/// Printing
ce5605e9 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 }
71a2d3aa 268
52dd0c39 269 cout << (*this) << endl;
270}
271
6e97fbb8 272//_____________________________________________________________________________
273void
274AliMpArea::GetParameters(Double_t& x, Double_t& y,
275 Double_t& dx, Double_t& dy) const
cddcc1f3 276{
277/// Fill the parameters: x, y position and dimensions
278
6e97fbb8 279 x = fPositionX;
280 y = fPositionY;
281 dx = fDimensionX;
282 dy = fDimensionY;
283}
284
5f91c9e8 285//_____________________________________________________________________________
286ostream& operator<< (ostream &stream,const AliMpArea& area)
287{
dee1d5f1 288/// Output streaming
289
5f91c9e8 290 stream << "Area: position: ("
6e97fbb8 291 << area.GetPositionX() << ", " << area.GetPositionY() << ") "
5f91c9e8 292 << " dimensions: ("
6e97fbb8 293 << area.GetDimensionX() << ", " << area.GetDimensionY() << ") "
52dd0c39 294 << " valid: " << (area.IsValid()==true ? "YES":"NO")
5f91c9e8 295 << endl;
296 return stream;
297}
298