]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpArea.cxx
Fix floating exception bug which can appear in few specific cases.
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpArea.cxx
index 3ae92ab4459191a7402899fc7366d12d94f9dc46..b9887ab3c5d7589f466553bf6a69288e142aeb74 100755 (executable)
@@ -1,29 +1,61 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
 // $Id$
+// $MpId: AliMpArea.cxx,v 1.8 2006/05/24 13:58:29 ivana Exp $
 // Category: basic
-//
+
+//-----------------------------------------------------------------------------
 // Class AliMpArea
 // ----------------
 // Class that defines a rectangle area positioned in plane..
-//
+// Included in AliRoot: 2003/05/02
 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
-
-#include <Riostream.h>
+//-----------------------------------------------------------------------------
 
 #include "AliMpArea.h"
 
-ClassImp(AliMpArea)
+#include "AliLog.h"
+#include "AliMpConstants.h"
 
+#include <Riostream.h>
+
+/// \cond CLASSIMP
+ClassImp(AliMpArea)
+/// \endcond
 
 //_____________________________________________________________________________
-AliMpArea::AliMpArea(const TVector2& position, const TVector2& dimensions)
+AliMpArea::AliMpArea(Double_t x, Double_t y, 
+                     Double_t dx, Double_t dy)
   : TObject(),
-    fPosition(position),
-    fDimensions(dimensions),
-    fValidity(true) {
-//
+    fPositionX(x),
+    fPositionY(y),
+    fDimensionX(dx),
+    fDimensionY(dy),
+    fValidity(true) 
+{
+/// Standard constructor
+
   // Check dimensions
-  if (fDimensions.X() <= 0. || fDimensions.Y() <=0.) {
-    fDimensions = TVector2();
+  if (  fDimensionX < - AliMpConstants::LengthTolerance() || 
+        fDimensionY < - AliMpConstants::LengthTolerance() || 
+      ( fDimensionX < AliMpConstants::LengthTolerance() && 
+        fDimensionY < AliMpConstants::LengthTolerance() ) )
+  {
+    fDimensionX = 0.;
+    fDimensionY = 0.;
     fValidity = false;
   }  
 }
@@ -31,23 +63,31 @@ AliMpArea::AliMpArea(const TVector2& position, const TVector2& dimensions)
 //_____________________________________________________________________________
 AliMpArea::AliMpArea()
   : TObject(),
-    fPosition(TVector2()),
-    fDimensions(TVector2()), 
-    fValidity(false) {
-//
+    fPositionX(0.),
+    fPositionY(0.),
+    fDimensionX(0.),
+    fDimensionY(0.),
+    fValidity(false) 
+{
+/// Default constructor
 }
 
 //_____________________________________________________________________________
 AliMpArea::AliMpArea(const AliMpArea& rhs):
   TObject(rhs),
-  fPosition(rhs.fPosition),
-  fDimensions(rhs.fDimensions) {
-//
+  fPositionX(rhs.fPositionX),
+  fPositionY(rhs.fPositionY),
+  fDimensionX(rhs.fDimensionX), 
+  fDimensionY(rhs.fDimensionY), 
+  fValidity(rhs.fValidity) 
+{
+/// Copy constructor
 }
 
 //_____________________________________________________________________________
-AliMpArea::~AliMpArea() {
-//
+AliMpArea::~AliMpArea() 
+{
+/// Destructor
 }
 
 //
@@ -57,16 +97,18 @@ AliMpArea::~AliMpArea() {
 //______________________________________________________________________________
 AliMpArea& AliMpArea::operator = (const AliMpArea& right)
 {
-// Assignement operator
+/// Assignment operator
 
-  // check assignement to self
+  // check assignment to self
   if (this == &right) return *this;
 
-  // base class assignement
+  // base class assignment
   TObject::operator=(right);
 
-  fPosition = right.fPosition;
-  fDimensions = right.fDimensions;
+  fPositionX = right.fPositionX;
+  fPositionY = right.fPositionY;
+  fDimensionX = right.fDimensionX;
+  fDimensionY = right.fDimensionY;
   fValidity = right.fValidity;
 
   return *this;
@@ -79,83 +121,175 @@ AliMpArea& AliMpArea::operator = (const AliMpArea& right)
 //_____________________________________________________________________________
 Double_t AliMpArea::LeftBorder() const
 {
-// Returns the position of the left edge.
-// --
+/// Return the position of the left edge.
 
-  return fPosition.X() - fDimensions.X();
+  return fPositionX - fDimensionX;
 }
 
 //_____________________________________________________________________________
 Double_t AliMpArea::RightBorder() const
 {
-// Returns the position of right edge.
-// --
+/// Return the position of right edge.
 
-  return fPosition.X() + fDimensions.X();
+  return fPositionX + fDimensionX;
 }
 
 //_____________________________________________________________________________
 Double_t AliMpArea::UpBorder() const
 {
-// Returns the position of the up edge.
-// --
+/// Return the position of the up edge.
 
-  return fPosition.Y() + fDimensions.Y();
+  return fPositionY + fDimensionY;
 }
 
 //_____________________________________________________________________________
 Double_t AliMpArea::DownBorder() const
 {
-// Returns the position of the down edge.
-// --
+/// Return the position of the down edge.
 
-  return fPosition.Y() - fDimensions.Y();
+  return fPositionY - fDimensionY;
 }
 
 //_____________________________________________________________________________
-TVector2 AliMpArea::LeftDownCorner() const
+void AliMpArea::LeftDownCorner(Double_t& x, Double_t& y) const
+{
+/// Return position of the left down corner.
+
+  x = LeftBorder();
+  y = DownBorder();
+}  
+
+//_____________________________________________________________________________
+void AliMpArea::LeftUpCorner(Double_t& x, Double_t& y) const
 {
-// Returns position of the left down corner.
-// --
+/// Return position of the left up corner.
 
-  return TVector2(LeftBorder(), DownBorder());
+  x = LeftBorder();
+  y = UpBorder();
 }  
 
 //_____________________________________________________________________________
-TVector2 AliMpArea::LeftUpCorner() const
+void AliMpArea::RightDownCorner(Double_t& x, Double_t& y) const
 {
-// Returns position of the left up corner.
-// --
+/// Return position of the right down corner.
 
-  return TVector2(LeftBorder(), UpBorder());
+  x = RightBorder();
+  y = DownBorder();
 }  
 
+
 //_____________________________________________________________________________
-TVector2 AliMpArea::RightDownCorner() const
+void AliMpArea::RightUpCorner(Double_t& x, Double_t& y) const
 {
-// Returns position of the right down corner.
-// --
+/// Return position of the right up corner.
 
-  return TVector2(RightBorder(), DownBorder());
+  x = RightBorder();
+  y = UpBorder();
 }  
 
+//_____________________________________________________________________________
+Bool_t AliMpArea::Contains(const AliMpArea& area) const
+{
+/// Whether area is contained within this
+  
+//  return
+//    ( area.LeftBorder() > LeftBorder() - AliMpConstants::LengthTolerance() &&
+//      area.RightBorder() < RightBorder() +  AliMpConstants::LengthTolerance() &&
+//      area.DownBorder() > DownBorder() - AliMpConstants::LengthTolerance() &&
+//      area.UpBorder() < UpBorder() + AliMpConstants::LengthTolerance() );
+
+  if ( area.LeftBorder() < LeftBorder() ||
+       area.RightBorder() > RightBorder() ||
+       area.DownBorder() < DownBorder() ||
+       area.UpBorder() > UpBorder() ) 
+  {
+    return kFALSE;
+  }
+  else
+  {
+    return kTRUE;
+  }
+}
+
+//_____________________________________________________________________________
+AliMpArea AliMpArea::Intersect(const AliMpArea& area) const
+{ 
+/// Return the common part of area and this
+
+  Double_t xmin = TMath::Max(area.LeftBorder(),LeftBorder());
+  Double_t xmax = TMath::Min(area.RightBorder(),RightBorder());
+  Double_t ymin = TMath::Max(area.DownBorder(),DownBorder());
+  Double_t ymax = TMath::Min(area.UpBorder(),UpBorder());
+
+  return AliMpArea( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ,
+                    (xmax-xmin)/2.0, (ymax-ymin)/2.0 );
+}
+
+//_____________________________________________________________________________
+Bool_t AliMpArea::Overlap(const AliMpArea& area) const
+{
+/// Return true if this overlaps with given area
+
+  if ( LeftBorder() > area.RightBorder() - AliMpConstants::LengthTolerance() ||
+       RightBorder() < area.LeftBorder() + AliMpConstants::LengthTolerance() )
+  {
+    return kFALSE;
+  }
+
+  if ( DownBorder() > area.UpBorder() - AliMpConstants::LengthTolerance() ||
+       UpBorder() < area.DownBorder() + AliMpConstants::LengthTolerance() )
+  {
+    return kFALSE;
+  }
+  return kTRUE;
+  
+}
 
 //_____________________________________________________________________________
-TVector2 AliMpArea::RightUpCorner() const
+void
+AliMpArea::Print(Option_t* opt) const
 {
-// Returns position of the right up corner.
-// --
+/// Printing
+/// When option is set to B (borders), the area boreders will be printed 
+/// instead of default parameters
+
+  
+  if ( opt[0] == 'B' ) {
+    cout << "Area x-borders: (" 
+         << LeftBorder() << ", " << RightBorder() << ") " 
+        << " y-borders: (" 
+         << DownBorder() << ", " << UpBorder() << ") " 
+        << endl;
+    return;
+
+  }       
 
-  return TVector2(RightBorder(), UpBorder());
+  cout << (*this) << endl;
+}
+
+//_____________________________________________________________________________
+void      
+AliMpArea::GetParameters(Double_t& x, Double_t& y,
+                         Double_t& dx, Double_t& dy) const
+{
+/// Fill the parameters: x, y position and dimensions
+                         
+  x = fPositionX;
+  y = fPositionY;
+  dx = fDimensionX;
+  dy = fDimensionY;
 }  
 
 //_____________________________________________________________________________
 ostream& operator<< (ostream &stream,const AliMpArea& area)
 {
+/// Output streaming
+
   stream << "Area: position: (" 
-         << area.Position().X() << ", " << area.Position().Y() << ") " 
+         << area.GetPositionX() << ", " << area.GetPositionY() << ") " 
         << " dimensions: (" 
-         << area.Dimensions().X() << ", " << area.Dimensions().Y() << ") " 
+         << area.GetDimensionX() << ", " << area.GetDimensionY() << ") " 
+  << " valid: " << (area.IsValid()==true ? "YES":"NO")
         << endl;
   return stream;
 }