1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 /// \class AliMUONSegment
20 /// A basic line segment, to be used in contour making algorithms.
22 /// In particular, this class defines what a left or right edge is.
24 /// Also, please note that, due to the way Root collections are sorted (relying
25 /// on TObject::Compare method), the way the AliMUONSegment::Compare method
26 /// is implemented below is really important when it comes to understand
27 /// contour making algorithm. Keep that in mind.
29 /// \author Laurent Aphecetche, Subatech
32 #include "AliMUONSegment.h"
35 #include "Riostream.h"
36 #include "AliMpConstants.h"
39 ClassImp(AliMUONSegment)
42 const Double_t AliMUONSegment::fgkPrecision(AliMpConstants::LengthTolerance());
44 //_____________________________________________________________________________
45 AliMUONSegment::AliMUONSegment() :
47 fStartX(), fStartY(), fEndX(), fEndY(), fSmallerY(), fIsHorizontal(), fIsVertical(),
48 fIsLeftEdge(), fIsRightEdge(), fIsAPoint(kTRUE)
51 Set(fStartX,fStartY,fEndX,fEndY);
54 //_____________________________________________________________________________
55 AliMUONSegment::AliMUONSegment(Double_t xstart, Double_t ystart, Double_t xend, Double_t yend)
57 fStartX(xstart), fStartY(ystart), fEndX(xend), fEndY(yend), fSmallerY(), fIsHorizontal(), fIsVertical(),
58 fIsLeftEdge(), fIsRightEdge(), fIsAPoint(kTRUE)
61 Set(xstart,ystart,xend,yend);
64 //_____________________________________________________________________________
66 AliMUONSegment::AreEqual(double a, double b)
68 /// Whether the two floats are equal within the given precision
69 return (TMath::Abs(b-a) < fgkPrecision);
72 //_____________________________________________________________________________
74 AliMUONSegment::Compare(const TObject* obj) const
76 /// Compare method, which sort segments in ascending x order
77 /// if same x, insure that left edges are before right edges
78 /// within same x, order by increasing bottommost y
79 /// Mind your steps ! This method is critical to the contour merging algorithm !
81 const AliMUONSegment* rhs = static_cast<const AliMUONSegment*>(obj);
83 if ( AreEqual(StartX(),rhs->StartX()) )
85 if ( IsLeftEdge() && rhs->IsRightEdge() ) return -1;
86 if ( IsRightEdge() && rhs->IsLeftEdge() ) return 1;
87 if ( SmallerY() < rhs->SmallerY() ) return -1;
88 if ( SmallerY() > rhs->SmallerY() ) return 1;
91 else if ( StartX() < rhs->StartX() )
95 else //if ( StartX() > rhs->StartX() )
101 //_____________________________________________________________________________
102 double AliMUONSegment::Top() const
104 /// Max Y of the segment
105 return TMath::Max(fStartY,fEndY);
108 //_____________________________________________________________________________
109 double AliMUONSegment::Distance() const
111 /// Length of the segment
112 return TMath::Sqrt((fStartX-fEndX)*(fStartX-fEndX) +
113 (fStartY-fEndY)*(fStartY-fEndY));
116 //_____________________________________________________________________________
117 void AliMUONSegment::Print(Option_t*) const
120 cout << AsString() << endl;
123 //_____________________________________________________________________________
124 const char* AliMUONSegment::AsString() const
126 /// Return a string representation of this object
127 return Form("[ (%10.5f,%10.5f) -> (%10.5f,%10.5f) %s ] (d=%e)",fStartX,fStartY,fEndX,fEndY,
128 IsLeftEdge() ? "L" : ( IsRightEdge() ? "R" : ( IsHorizontal() ? "H" : "" )),
132 //_____________________________________________________________________________
134 AliMUONSegment::Set(Double_t xstart, Double_t ystart, Double_t xend, Double_t yend)
136 /// Set start and end point, and (re)compute internal values
141 fSmallerY = TMath::Min(fStartY,fEndY);
142 fIsHorizontal = AreEqual(fStartY,fEndY);
143 fIsVertical = AreEqual(fStartX,fEndX);
144 fIsLeftEdge = fIsVertical && ( fStartY > fEndY );
145 fIsRightEdge = fIsVertical && ( fStartY < fEndY );
146 fIsAPoint = ( Distance() < fgkPrecision );