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