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 AliMUONNode
19 : ///
20 : /// A node of a segment tree
21 : ///
22 : /// For the details of the meaning of cardinality and potent data
23 : /// members, please see Diane L. Souvaine and Iliana Bjorling-Sachs,
24 : /// Proceedings of the IEEE, Vol. 80, No. 9, September 1992, p. 1449
25 : ///
26 : ///
27 : /// \author Laurent Aphecetche, Subatech
28 :
29 : #include "AliMUONNode.h"
30 :
31 : #include "AliLog.h"
32 : #include "AliMUONSegment.h"
33 : #include "Riostream.h"
34 : #include "TMath.h"
35 : #include "TObjArray.h"
36 : #include "TString.h"
37 :
38 : using std::cout;
39 : using std::endl;
40 : ///\cond CLASSIMP
41 12 : ClassImp(AliMUONNode)
42 : ///\endcond
43 :
44 : //_____________________________________________________________________________
45 0 : AliMUONNode::AliMUONNode(Double_t a, Double_t b, Double_t midpoint)
46 0 : : fLeftNode(0x0), fRightNode(0x0), fMin(a), fMax(b), fMidPoint(midpoint), fC(0), fP(0)
47 0 : {
48 : /// ctor
49 0 : }
50 :
51 : //_____________________________________________________________________________
52 : AliMUONNode::~AliMUONNode()
53 0 : {
54 : /// dtor
55 0 : delete fLeftNode;
56 0 : delete fRightNode;
57 0 : }
58 :
59 : //_____________________________________________________________________________
60 : void
61 : AliMUONNode::Print(const char* opt) const
62 : {
63 : /// Printout
64 0 : cout << opt << Form("[%7.2f,%7.2f]",fMin,fMax);
65 0 : if ( !TMath::IsNaN(fMidPoint) ) cout << Form(" (%7.2f)",fMidPoint);
66 0 : cout << endl;
67 :
68 0 : TString sopt(opt);
69 0 : sopt += " ";
70 :
71 0 : if ( fLeftNode )
72 : {
73 0 : fLeftNode->Print(sopt.Data());
74 : }
75 0 : if ( fRightNode )
76 : {
77 0 : fRightNode->Print(sopt.Data());
78 : }
79 0 : }
80 :
81 : //_____________________________________________________________________________
82 : void
83 : AliMUONNode::Contribution(Double_t b, Double_t e, TObjArray& stack)
84 : {
85 : /// Contribution of an edge (b,e) to the final contour
86 0 : if ( fMax < fMin )
87 : {
88 0 : AliError(Form("fMax(%10.5f) < fMin(%10.5f",fMax,fMin));
89 0 : }
90 :
91 0 : if ( fC == 0 )
92 : {
93 0 : if ( IsFullyContained(b,e) && fP == 0 )
94 : {
95 0 : AliMUONSegment* back = static_cast<AliMUONSegment*>(stack.Last());
96 :
97 0 : if ( back && AliMUONSegment::AreEqual(back->EndY(),fMin) )
98 : {
99 : // merge to existing segment
100 0 : Double_t y(back->StartY());
101 0 : back->Set(0.0,y,0.0,fMax);
102 0 : }
103 : else
104 : {
105 : // add a new segment
106 0 : stack.Add(new AliMUONSegment(0.0,fMin,0.0,fMax));
107 : }
108 0 : }
109 : else
110 : {
111 0 : if ( b < fMidPoint )
112 : {
113 0 : fLeftNode->Contribution(b,e,stack);
114 0 : }
115 0 : if ( fMidPoint < e )
116 : {
117 0 : fRightNode->Contribution(b,e,stack);
118 0 : }
119 : }
120 : }
121 0 : }
122 :
123 : //_____________________________________________________________________________
124 : Bool_t
125 : AliMUONNode::IsFullyContained(Double_t b, Double_t e) const
126 : {
127 : /// Whether this node's interval is fully contained into [b,e]
128 :
129 0 : return ( ( b < fMin || AliMUONSegment::AreEqual(b,fMin) ) && ( fMax < e || AliMUONSegment::AreEqual(e,fMax)) );
130 : }
131 :
132 : //_____________________________________________________________________________
133 : void
134 : AliMUONNode::InsertInterval(Double_t b, Double_t e, TObjArray& stack)
135 : {
136 : /// Insert an interval
137 0 : if ( IsFullyContained(b,e) )
138 : {
139 0 : C(1);
140 0 : }
141 : else
142 : {
143 0 : if ( b < fMidPoint )
144 : {
145 0 : fLeftNode->InsertInterval(b,e,stack);
146 0 : }
147 0 : if ( fMidPoint < e )
148 : {
149 0 : fRightNode->InsertInterval(b,e,stack);
150 0 : }
151 : }
152 0 : Update();
153 0 : }
154 :
155 : //_____________________________________________________________________________
156 : void
157 : AliMUONNode::DeleteInterval(Double_t b, Double_t e, TObjArray& stack)
158 : {
159 : /// Delete an interval
160 0 : if ( IsFullyContained(b,e) )
161 : {
162 0 : C(-1);
163 0 : }
164 : else
165 : {
166 0 : if ( fC > 0 ) Demote();
167 0 : if ( b < fMidPoint )
168 : {
169 0 : fLeftNode->DeleteInterval(b,e,stack);
170 0 : }
171 :
172 0 : if ( fMidPoint < e )
173 : {
174 0 : fRightNode->DeleteInterval(b,e,stack);
175 0 : }
176 : }
177 0 : Update();
178 0 : }
179 :
180 : //_____________________________________________________________________________
181 : void
182 : AliMUONNode::Update()
183 : {
184 : /// Update internal values
185 0 : if ( !fLeftNode )
186 : {
187 0 : fP = 0;
188 0 : }
189 : else
190 : {
191 0 : if (fLeftNode->C() > 0 && fRightNode->C() > 0 )
192 : {
193 0 : Promote();
194 0 : }
195 0 : if (fLeftNode->C()==0 && fRightNode->C()==0 && fLeftNode->P()==0 && fRightNode->P()==0 )
196 : {
197 0 : fP = 0;
198 0 : }
199 : else
200 : {
201 0 : fP = 1;
202 : }
203 : }
204 0 : }
205 :
206 : //_____________________________________________________________________________
207 : void
208 : AliMUONNode::Promote()
209 : {
210 : /// Promote node
211 0 : fLeftNode->C(-1);
212 0 : fRightNode->C(-1);
213 0 : C(+1);
214 0 : }
215 :
216 : //_____________________________________________________________________________
217 : void
218 : AliMUONNode::Demote()
219 : {
220 : /// Demote node
221 0 : fLeftNode->C(+1);
222 0 : fRightNode->C(+1);
223 0 : C(-1);
224 0 : fP = 1;
225 0 : }
226 :
|