]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpArea.cxx
Adding a couple of methods used by combined tracking (Laurent)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpArea.cxx
index d221853a0912c2f1613e5613f6ab555febf4dbf8..66e8734eb0335b435a12cd3a0e2d311588f3ff1c 100755 (executable)
  **************************************************************************/
 
 // $Id$
-// $MpId: AliMpArea.cxx,v 1.6 2005/08/26 15:43:36 ivana Exp $
+// $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)
@@ -40,8 +46,11 @@ AliMpArea::AliMpArea(const TVector2& position, const TVector2& dimensions)
 /// Standard constructor
 
   // Check dimensions
-  if (  fDimensions.X() < 0. || fDimensions.Y() < 0. ||
-      ( fDimensions.X() == 0 && fDimensions.Y() == 0.0 ) ) {
+  if (  fDimensions.X() < - AliMpConstants::LengthTolerance() || 
+        fDimensions.Y() < - AliMpConstants::LengthTolerance() || 
+      ( fDimensions.X() < AliMpConstants::LengthTolerance() && 
+        fDimensions.Y() < AliMpConstants::LengthTolerance() ) )
+  {
     fDimensions = TVector2();
     fValidity = false;
   }  
@@ -61,7 +70,8 @@ AliMpArea::AliMpArea()
 AliMpArea::AliMpArea(const AliMpArea& rhs):
   TObject(rhs),
   fPosition(rhs.fPosition),
-  fDimensions(rhs.fDimensions) 
+  fDimensions(rhs.fDimensions), 
+  fValidity(rhs.fValidity) 
 {
 /// Copy constructor
 }
@@ -163,6 +173,73 @@ TVector2 AliMpArea::RightUpCorner() const
   return TVector2(RightBorder(), 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( TVector2( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ),
+                    TVector2( (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;
+  
+}
+
+//_____________________________________________________________________________
+void
+AliMpArea::Print(Option_t*) const
+{
+/// Printing
+
+  cout << (*this) << endl;
+}
+
 //_____________________________________________________________________________
 ostream& operator<< (ostream &stream,const AliMpArea& area)
 {
@@ -172,6 +249,7 @@ ostream& operator<< (ostream &stream,const AliMpArea& area)
          << area.Position().X() << ", " << area.Position().Y() << ") " 
         << " dimensions: (" 
          << area.Dimensions().X() << ", " << area.Dimensions().Y() << ") " 
+  << " valid: " << (area.IsValid()==true ? "YES":"NO")
         << endl;
   return stream;
 }