]>
Commit | Line | Data |
---|---|---|
5f91c9e8 | 1 | // $Id$ |
2 | // Category: sector | |
3 | // | |
4 | // Class AliMpRowSegment | |
5 | // --------------------- | |
6 | // Class describing a row segment composed of the | |
7 | // the identic motifs. | |
8 | // | |
9 | // Authors: David Guez, Ivana Hrivnacova; IPN Orsay | |
10 | ||
11 | #include <TError.h> | |
12 | #include <TMath.h> | |
13 | ||
14 | #include "AliMpRowSegment.h" | |
15 | #include "AliMpRow.h" | |
16 | #include "AliMpVMotif.h" | |
17 | #include "AliMpMotifType.h" | |
18 | #include "AliMpMotifTypePadIterator.h" | |
19 | #include "AliMpMotifMap.h" | |
20 | #include "AliMpMotifPosition.h" | |
21 | ||
22 | ClassImp(AliMpRowSegment) | |
23 | ||
24 | //_____________________________________________________________________________ | |
25 | AliMpRowSegment::AliMpRowSegment(AliMpRow* row, AliMpVMotif* motif, | |
26 | AliMpIntPair padOffset, | |
27 | Int_t nofMotifs, | |
28 | Int_t motifPositionId, Int_t motifPositionDId) | |
29 | : AliMpVRowSegment(), | |
30 | fNofMotifs(nofMotifs), | |
31 | fPadOffset(padOffset), | |
32 | fOffset(TVector2()), | |
33 | fRow(row), | |
34 | fMotif(motif), | |
35 | fMotifPositionId(motifPositionId), | |
36 | fMotifPositionDId(motifPositionDId) | |
37 | { | |
38 | // | |
39 | // Keep pad offset in the low indices limits | |
40 | SetLowIndicesLimit(padOffset); | |
41 | } | |
42 | ||
43 | //_____________________________________________________________________________ | |
44 | AliMpRowSegment::AliMpRowSegment() | |
45 | : AliMpVRowSegment(), | |
46 | fNofMotifs(0), | |
47 | fPadOffset(AliMpIntPair()), | |
48 | fOffset(TVector2()), | |
49 | fRow(0), | |
50 | fMotif(0), | |
51 | fMotifPositionId(0), | |
52 | fMotifPositionDId(0) | |
53 | { | |
54 | // | |
55 | } | |
56 | ||
57 | //_____________________________________________________________________________ | |
58 | AliMpRowSegment::~AliMpRowSegment() { | |
59 | // | |
60 | } | |
61 | ||
62 | // | |
63 | // private methods | |
64 | // | |
65 | ||
66 | //_____________________________________________________________________________ | |
67 | Double_t AliMpRowSegment::FirstMotifCenterX() const | |
68 | { | |
69 | // Returns the x coordinate of the first motif center | |
70 | // in global coordinate system. | |
71 | // --- | |
72 | ||
73 | return fOffset.X(); | |
74 | } | |
75 | ||
76 | //_____________________________________________________________________________ | |
77 | Double_t AliMpRowSegment::LastMotifCenterX() const | |
78 | { | |
79 | // Returns the x coordinate of the last motif center | |
80 | // in global coordinate system. | |
81 | // --- | |
82 | ||
83 | return fOffset.X() + 2.*(fNofMotifs-1)*fMotif->Dimensions().X(); | |
84 | } | |
85 | ||
86 | //_____________________________________________________________________________ | |
87 | Double_t AliMpRowSegment::MotifCenterX(Int_t motifPositionId) const | |
88 | { | |
89 | // Returns the x coordinate of the motif specified with | |
90 | // the given position identifier. | |
91 | // --- | |
92 | ||
93 | // Check if x is in the row segment range | |
94 | if (! HasMotifPosition(motifPositionId)) { | |
95 | Error("MotifCenterX", "Outside row segment region"); | |
96 | return 0; | |
97 | } | |
98 | ||
99 | // Find the position number in the segment | |
100 | Int_t num = (motifPositionId - fMotifPositionId) * fMotifPositionDId; | |
101 | ||
102 | return fOffset.X() + num*(fMotif->Dimensions().X() * 2.0); | |
103 | } | |
104 | ||
105 | //_____________________________________________________________________________ | |
106 | Double_t AliMpRowSegment::MotifCenterY(Int_t motifPositionId) const | |
107 | { | |
108 | // Returns the y coordinate of the motif specified with | |
109 | // the given position identifier. | |
110 | // --- | |
111 | ||
112 | // Check if x is in the row segment range | |
113 | if (! HasMotifPosition(motifPositionId)) { | |
114 | Error("MotifCenterY", "Outside row segment region"); | |
115 | return 0; | |
116 | } | |
117 | ||
118 | return GetRow()->Position().Y() + fOffset.Y(); | |
119 | } | |
120 | ||
121 | //_____________________________________________________________________________ | |
122 | Bool_t AliMpRowSegment::IsInside(const TVector2& position, Bool_t warn) const | |
123 | { | |
124 | // Checks if the position is inside some motif of this row segment. | |
125 | // --- | |
126 | ||
127 | Double_t minY = GetRow()->Position().Y() + fOffset.Y() - fMotif->Dimensions().Y(); | |
128 | Double_t maxY = GetRow()->Position().Y() + fOffset.Y() + fMotif->Dimensions().Y(); | |
129 | ||
130 | if ( position.X() < LeftBorderX() || position.X() > RightBorderX() || | |
131 | position.Y() < minY || position.Y() > maxY ) { | |
132 | ||
133 | if (warn) Error("MotifPositionId", "Outside row segment region"); | |
134 | return false; | |
135 | } | |
136 | else | |
137 | return true; | |
138 | } | |
139 | ||
140 | // | |
141 | // public methods | |
142 | // | |
143 | ||
144 | //_____________________________________________________________________________ | |
145 | Double_t AliMpRowSegment::LeftBorderX() const | |
146 | { | |
147 | // Returns the x coordinate of the left row segment border | |
148 | // in global coordinate system. | |
149 | // --- | |
150 | ||
151 | return FirstMotifCenterX() - fMotif->Dimensions().X(); | |
152 | } | |
153 | ||
154 | //_____________________________________________________________________________ | |
155 | Double_t AliMpRowSegment::RightBorderX() const | |
156 | { | |
157 | // Returns the x coordinate of the right row segment border | |
158 | // in global coordinate system. | |
159 | // --- | |
160 | ||
161 | return LastMotifCenterX() + fMotif->Dimensions().X(); | |
162 | } | |
163 | ||
164 | //_____________________________________________________________________________ | |
165 | Double_t AliMpRowSegment::HalfSizeY() const | |
166 | { | |
167 | // Returns the size in y of this row segment. | |
168 | // --- | |
169 | ||
170 | return fMotif->Dimensions().Y() + fOffset.Y(); | |
171 | } | |
172 | ||
173 | //_____________________________________________________________________________ | |
174 | AliMpVMotif* AliMpRowSegment::FindMotif(const TVector2& position) const | |
175 | { | |
176 | // Returns the motif of this row; | |
177 | // --- | |
178 | ||
179 | if (IsInside(position, false)) | |
180 | return fMotif; | |
181 | else | |
182 | return 0; | |
183 | } | |
184 | ||
185 | //_____________________________________________________________________________ | |
186 | Int_t AliMpRowSegment::FindMotifPositionId(const TVector2& position) const | |
187 | { | |
188 | // Returns the motif position identified for the given | |
189 | // geometric position. | |
190 | // --- | |
191 | ||
192 | if (!IsInside(position, false)) return 0; | |
193 | ||
194 | // Find the position number in the segment | |
195 | Int_t num | |
196 | = Int_t((position.X() - LeftBorderX()) / (fMotif->Dimensions().X() * 2.0)); | |
197 | ||
198 | // Calculate the position Id | |
199 | return fMotifPositionId + num*fMotifPositionDId; | |
200 | } | |
201 | ||
202 | //_____________________________________________________________________________ | |
203 | Bool_t AliMpRowSegment::HasMotifPosition(Int_t motifPositionId) const | |
204 | { | |
205 | // Returns true if the motif specified with the given position identifier | |
206 | // is in this segment. | |
207 | // --- | |
208 | ||
209 | Int_t minId = TMath::Min(fMotifPositionId, | |
210 | fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId); | |
211 | Int_t maxId = TMath::Max(fMotifPositionId, | |
212 | fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId); | |
213 | ||
214 | if (motifPositionId >= minId && motifPositionId <= maxId) { | |
215 | return true; | |
216 | } | |
217 | else | |
218 | return false; | |
219 | } | |
220 | ||
221 | //_____________________________________________________________________________ | |
222 | TVector2 AliMpRowSegment::MotifCenter(Int_t motifPositionId) const | |
223 | { | |
224 | // Returns the coordinates of the motif specified with | |
225 | // the given position identifier. | |
226 | // --- | |
227 | ||
228 | return TVector2(MotifCenterX(motifPositionId), MotifCenterY(motifPositionId)); | |
229 | } | |
230 | ||
231 | //_____________________________________________________________________________ | |
232 | TVector2 AliMpRowSegment::Position() const | |
233 | { | |
234 | // Returns the position of the row segment centre. | |
235 | // --- | |
236 | ||
237 | Double_t x = (LeftBorderX() + RightBorderX())/2.; | |
238 | Double_t y = GetRow()->Position().Y(); | |
239 | ||
240 | return TVector2(x, y); | |
241 | } | |
242 | ||
243 | ||
244 | //_____________________________________________________________________________ | |
245 | TVector2 AliMpRowSegment::Dimensions() const | |
246 | { | |
247 | // Returns the halflengths of the row segment in x, y. | |
248 | // --- | |
249 | ||
250 | Double_t x = (RightBorderX() - LeftBorderX())/2.; | |
251 | Double_t y = GetRow()->Dimensions().Y(); | |
252 | ||
253 | return TVector2(x, y); | |
254 | } | |
255 | ||
256 | //_____________________________________________________________________________ | |
257 | void AliMpRowSegment::SetOffset(const TVector2& offset) | |
258 | { | |
259 | // Calculates offset from given offset and | |
260 | // stored offset in pads. | |
261 | // --- | |
262 | ||
263 | AliMpMotifTypePadIterator iter(fMotif->GetMotifType()); | |
264 | iter.First(); | |
265 | AliMpIntPair localPos = iter.CurrentItem().GetIndices(); | |
266 | ||
267 | Double_t offsetX | |
268 | = offset.X() | |
269 | + 2.*fPadOffset.GetFirst() * fMotif->GetPadDimensions(localPos).X() | |
270 | + fMotif->Dimensions().X(); | |
271 | ||
272 | Double_t offsetY | |
273 | = offset.Y() | |
274 | + fPadOffset.GetSecond() * fMotif->GetPadDimensions(localPos).Y(); | |
275 | ||
276 | fOffset = TVector2(offsetX, offsetY); | |
277 | } | |
278 | ||
279 | //_____________________________________________________________________________ | |
280 | void AliMpRowSegment::SetGlobalIndices() | |
281 | { | |
282 | // Sets indices limits. | |
283 | // --- | |
284 | ||
285 | AliMpMotifPosition* firstPos | |
286 | = GetRow()->GetMotifMap() | |
287 | ->FindMotifPosition(GetMotifPositionId(0)); | |
288 | ||
289 | AliMpMotifPosition* lastPos | |
290 | = GetRow()->GetMotifMap() | |
291 | ->FindMotifPosition(GetMotifPositionId(GetNofMotifs()-1)); | |
292 | ||
293 | // Check if the motif positions has the limits set | |
294 | if ( !firstPos->HasValidIndices() || !lastPos->HasValidIndices()) | |
295 | Fatal("SetGlobalIndices", "Indices of motif positions have to be set first."); | |
296 | ||
297 | SetLowIndicesLimit(firstPos->GetLowIndicesLimit()); | |
298 | SetHighIndicesLimit(lastPos->GetHighIndicesLimit()); | |
299 | } | |
300 | ||
301 | //_____________________________________________________________________________ | |
302 | Int_t AliMpRowSegment::SetIndicesToMotifPosition(Int_t i, AliMpIntPair indices) | |
303 | { | |
304 | // Sets global indices to i-th motif position and returns next index | |
305 | // in x. | |
306 | // --- | |
307 | ||
308 | // Get motif position | |
309 | AliMpMotifPosition* motifPosition | |
310 | = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i)); | |
311 | ||
312 | // Low limit | |
313 | AliMpIntPair low = indices + AliMpIntPair(0, GetLowIndicesLimit().GetSecond()); | |
314 | motifPosition->SetLowIndicesLimit(low); | |
315 | ||
316 | // High limit | |
317 | AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType(); | |
318 | AliMpIntPair high | |
319 | = motifPosition->GetLowIndicesLimit() | |
320 | + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1); | |
321 | motifPosition->SetHighIndicesLimit(high); | |
322 | ||
323 | // Return next index in x | |
324 | return high.GetFirst()+1; | |
325 | // return motifType->GetNofPadsX(); | |
326 | } | |
327 | ||
328 | ||
329 | //_____________________________________________________________________________ | |
330 | AliMpRow* AliMpRowSegment::GetRow() const | |
331 | { | |
332 | // Returns the row.which this row segment belongs to. | |
333 | // --- | |
334 | ||
335 | return fRow; | |
336 | } | |
337 | ||
338 | //_____________________________________________________________________________ | |
339 | Int_t AliMpRowSegment::GetNofMotifs() const | |
340 | { | |
341 | // Returns number of motifs in this this row segment. | |
342 | // --- | |
343 | ||
344 | return fNofMotifs; | |
345 | } | |
346 | ||
347 | //_____________________________________________________________________________ | |
348 | Int_t AliMpRowSegment::GetMotifPositionId(Int_t i) const | |
349 | { | |
350 | // Returns number of motifs in this this row segment. | |
351 | // --- | |
352 | ||
353 | return fMotifPositionId + i*fMotifPositionDId; | |
354 | } | |
355 | ||
356 | //_____________________________________________________________________________ | |
357 | AliMpVMotif* AliMpRowSegment::GetMotif(Int_t i) const | |
358 | { | |
359 | // Returns the motif of this row segment. | |
360 | // --- | |
361 | ||
362 | return fMotif; | |
363 | } |