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"
41 ClassImp(AliMUONSegment)
44 const Double_t AliMUONSegment::fgkPrecision(AliMpConstants::LengthTolerance());
46 //_____________________________________________________________________________
47 AliMUONSegment::AliMUONSegment() :
49 fStartX(), fStartY(), fEndX(), fEndY(), fSmallerY(), fIsHorizontal(), fIsVertical(),
50 fIsLeftEdge(), fIsRightEdge(), fIsAPoint(kTRUE)
53 Set(fStartX,fStartY,fEndX,fEndY);
56 //_____________________________________________________________________________
57 AliMUONSegment::AliMUONSegment(Double_t xstart, Double_t ystart, Double_t xend, Double_t yend)
59 fStartX(xstart), fStartY(ystart), fEndX(xend), fEndY(yend), fSmallerY(), fIsHorizontal(), fIsVertical(),
60 fIsLeftEdge(), fIsRightEdge(), fIsAPoint(kTRUE)
63 Set(xstart,ystart,xend,yend);
66 //_____________________________________________________________________________
68 AliMUONSegment::AreEqual(double a, double b)
70 /// Whether the two floats are equal within the given precision
71 return (TMath::Abs(b-a) < fgkPrecision);
74 //_____________________________________________________________________________
76 AliMUONSegment::Compare(const TObject* obj) const
78 /// Compare method, which sort segments in ascending x order
79 /// if same x, insure that left edges are before right edges
80 /// within same x, order by increasing bottommost y
81 /// Mind your steps ! This method is critical to the contour merging algorithm !
83 const AliMUONSegment* rhs = static_cast<const AliMUONSegment*>(obj);
85 if ( AreEqual(StartX(),rhs->StartX()) )
87 if ( IsLeftEdge() && rhs->IsRightEdge() ) return -1;
88 if ( IsRightEdge() && rhs->IsLeftEdge() ) return 1;
89 if ( SmallerY() < rhs->SmallerY() ) return -1;
90 if ( SmallerY() > rhs->SmallerY() ) return 1;
93 else if ( StartX() < rhs->StartX() )
97 else //if ( StartX() > rhs->StartX() )
103 //_____________________________________________________________________________
104 double AliMUONSegment::Top() const
106 /// Max Y of the segment
107 return TMath::Max(fStartY,fEndY);
110 //_____________________________________________________________________________
111 double AliMUONSegment::Distance() const
113 /// Length of the segment
114 return TMath::Sqrt((fStartX-fEndX)*(fStartX-fEndX) +
115 (fStartY-fEndY)*(fStartY-fEndY));
118 //_____________________________________________________________________________
119 void AliMUONSegment::Print(Option_t*) const
122 cout << AsString() << endl;
125 //_____________________________________________________________________________
126 const char* AliMUONSegment::AsString() const
128 /// Return a string representation of this object
129 return Form("[ (%10.5f,%10.5f) -> (%10.5f,%10.5f) %s ] (d=%e)",fStartX,fStartY,fEndX,fEndY,
130 IsLeftEdge() ? "L" : ( IsRightEdge() ? "R" : ( IsHorizontal() ? "H" : "" )),
134 //_____________________________________________________________________________
136 AliMUONSegment::Set(Double_t xstart, Double_t ystart, Double_t xend, Double_t yend)
138 /// Set start and end point, and (re)compute internal values
143 fSmallerY = TMath::Min(fStartY,fEndY);
144 fIsHorizontal = AreEqual(fStartY,fEndY);
145 fIsVertical = AreEqual(fStartX,fEndX);
146 fIsLeftEdge = fIsVertical && ( fStartY > fEndY );
147 fIsRightEdge = fIsVertical && ( fStartY < fEndY );
148 fIsAPoint = ( Distance() < fgkPrecision );