Line data Source code
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 :
16 : // $Id$
17 :
18 : /// \class AliMUONSegment
19 : ///
20 : /// A basic line segment, to be used in contour making algorithms.
21 : ///
22 : /// In particular, this class defines what a left or right edge is.
23 : ///
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.
28 : ///
29 : /// \author Laurent Aphecetche, Subatech
30 : ///
31 :
32 : #include "AliMUONSegment.h"
33 :
34 : #include "TMath.h"
35 : #include "Riostream.h"
36 : #include "AliMpConstants.h"
37 :
38 : using std::cout;
39 : using std::endl;
40 : /// \cond CLASSIMP
41 12 : ClassImp(AliMUONSegment)
42 : /// \endcond
43 :
44 12 : const Double_t AliMUONSegment::fgkPrecision(AliMpConstants::LengthTolerance());
45 :
46 : //_____________________________________________________________________________
47 : AliMUONSegment::AliMUONSegment() :
48 0 : TObject(),
49 0 : fStartX(), fStartY(), fEndX(), fEndY(), fSmallerY(), fIsHorizontal(), fIsVertical(),
50 0 : fIsLeftEdge(), fIsRightEdge(), fIsAPoint(kTRUE)
51 0 : {
52 : /// Ctor
53 0 : Set(fStartX,fStartY,fEndX,fEndY);
54 0 : }
55 :
56 : //_____________________________________________________________________________
57 : AliMUONSegment::AliMUONSegment(Double_t xstart, Double_t ystart, Double_t xend, Double_t yend)
58 0 : : TObject(),
59 0 : fStartX(xstart), fStartY(ystart), fEndX(xend), fEndY(yend), fSmallerY(), fIsHorizontal(), fIsVertical(),
60 0 : fIsLeftEdge(), fIsRightEdge(), fIsAPoint(kTRUE)
61 0 : {
62 : /// Ctor
63 0 : Set(xstart,ystart,xend,yend);
64 0 : }
65 :
66 : //_____________________________________________________________________________
67 : Bool_t
68 : AliMUONSegment::AreEqual(double a, double b)
69 : {
70 : /// Whether the two floats are equal within the given precision
71 0 : return (TMath::Abs(b-a) < fgkPrecision);
72 : }
73 :
74 : //_____________________________________________________________________________
75 : Int_t
76 : AliMUONSegment::Compare(const TObject* obj) const
77 : {
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 !
82 :
83 0 : const AliMUONSegment* rhs = static_cast<const AliMUONSegment*>(obj);
84 :
85 0 : if ( AreEqual(StartX(),rhs->StartX()) )
86 : {
87 0 : if ( IsLeftEdge() && rhs->IsRightEdge() ) return -1;
88 0 : if ( IsRightEdge() && rhs->IsLeftEdge() ) return 1;
89 0 : if ( SmallerY() < rhs->SmallerY() ) return -1;
90 0 : if ( SmallerY() > rhs->SmallerY() ) return 1;
91 0 : return 0;
92 : }
93 0 : else if ( StartX() < rhs->StartX() )
94 : {
95 0 : return -1;
96 : }
97 : else //if ( StartX() > rhs->StartX() )
98 : {
99 0 : return 1;
100 : }
101 0 : }
102 :
103 : //_____________________________________________________________________________
104 : double AliMUONSegment::Top() const
105 : {
106 : /// Max Y of the segment
107 0 : return TMath::Max(fStartY,fEndY);
108 : }
109 :
110 : //_____________________________________________________________________________
111 : double AliMUONSegment::Distance() const
112 : {
113 : /// Length of the segment
114 0 : return TMath::Sqrt((fStartX-fEndX)*(fStartX-fEndX) +
115 0 : (fStartY-fEndY)*(fStartY-fEndY));
116 : }
117 :
118 : //_____________________________________________________________________________
119 : void AliMUONSegment::Print(Option_t*) const
120 : {
121 : /// Printout
122 0 : cout << AsString() << endl;
123 0 : }
124 :
125 : //_____________________________________________________________________________
126 : const char* AliMUONSegment::AsString() const
127 : {
128 : /// Return a string representation of this object
129 0 : return Form("[ (%10.5f,%10.5f) -> (%10.5f,%10.5f) %s ] (d=%e)",fStartX,fStartY,fEndX,fEndY,
130 0 : IsLeftEdge() ? "L" : ( IsRightEdge() ? "R" : ( IsHorizontal() ? "H" : "" )),
131 0 : Distance() );
132 : }
133 :
134 : //_____________________________________________________________________________
135 : void
136 : AliMUONSegment::Set(Double_t xstart, Double_t ystart, Double_t xend, Double_t yend)
137 : {
138 : /// Set start and end point, and (re)compute internal values
139 0 : fStartX = xstart;
140 0 : fEndX = xend;
141 0 : fStartY = ystart;
142 0 : fEndY = yend;
143 0 : fSmallerY = TMath::Min(fStartY,fEndY);
144 0 : fIsHorizontal = AreEqual(fStartY,fEndY);
145 0 : fIsVertical = AreEqual(fStartX,fEndX);
146 0 : fIsLeftEdge = fIsVertical && ( fStartY > fEndY );
147 0 : fIsRightEdge = fIsVertical && ( fStartY < fEndY );
148 0 : fIsAPoint = ( Distance() < fgkPrecision );
149 0 : }
150 :
|