]>
Commit | Line | Data |
---|---|---|
dee1d5f1 | 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 | ||
5f91c9e8 | 16 | // $Id$ |
13985652 | 17 | // $MpId: AliMpRow.cxx,v 1.9 2006/05/24 13:58:46 ivana Exp $ |
5f91c9e8 | 18 | // Category: sector |
3d1463c8 | 19 | |
20 | //----------------------------------------------------------------------------- | |
5f91c9e8 | 21 | // Class AliMpRow |
22 | // -------------- | |
23 | // Class describing a row composed of the row segments. | |
dbe945cc | 24 | // Included in AliRoot: 2003/05/02 |
5f91c9e8 | 25 | // Authors: David Guez, Ivana Hrivnacova; IPN Orsay |
3d1463c8 | 26 | //----------------------------------------------------------------------------- |
5f91c9e8 | 27 | |
5f91c9e8 | 28 | #include "AliMpRow.h" |
29 | #include "AliMpVRowSegment.h" | |
348e0500 | 30 | #include "AliMpVRowSegmentSpecial.h" |
31 | #include "AliMpRowSegmentRSpecial.h" | |
5f91c9e8 | 32 | #include "AliMpVMotif.h" |
33 | #include "AliMpMotifType.h" | |
34 | #include "AliMpMotifPosition.h" | |
35 | #include "AliMpMotifMap.h" | |
36 | #include "AliMpConstants.h" | |
37 | ||
cddd101e | 38 | #include "AliLog.h" |
39 | ||
2c605e66 | 40 | #include <TMath.h> |
41 | #include <Riostream.h> | |
42 | ||
13985652 | 43 | /// \cond CLASSIMP |
5f91c9e8 | 44 | ClassImp(AliMpRow) |
13985652 | 45 | /// \endcond |
5f91c9e8 | 46 | |
47 | //_____________________________________________________________________________ | |
48 | AliMpRow::AliMpRow(Int_t id, AliMpMotifMap* motifMap) | |
49 | : AliMpVIndexed(), | |
50 | fID(id), | |
51 | fOffsetY(0.), | |
52 | fSegments(), | |
53 | fMotifMap(motifMap) | |
54 | { | |
dee1d5f1 | 55 | /// Standard constructor |
5f91c9e8 | 56 | } |
57 | ||
58 | //_____________________________________________________________________________ | |
59 | AliMpRow::AliMpRow() | |
60 | : AliMpVIndexed(), | |
61 | fID(0), | |
62 | fOffsetY(0.), | |
63 | fSegments(), | |
64 | fMotifMap(0) | |
65 | { | |
dee1d5f1 | 66 | /// Default constructor |
5f91c9e8 | 67 | } |
68 | ||
69 | //_____________________________________________________________________________ | |
dee1d5f1 | 70 | AliMpRow::~AliMpRow() |
71 | { | |
72 | /// Destructor | |
5f91c9e8 | 73 | |
f79c58a5 | 74 | fSegments.Delete(); |
5f91c9e8 | 75 | } |
76 | ||
77 | // | |
78 | // private methods | |
79 | // | |
80 | ||
81 | //_____________________________________________________________________________ | |
82 | AliMpVRowSegment* AliMpRow::FindRowSegment(Int_t ix) const | |
83 | { | |
dee1d5f1 | 84 | /// Find first normal row segment with low indices limit >= ix. |
5f91c9e8 | 85 | |
86 | for (Int_t i=0; i<GetNofRowSegments(); i++) { | |
87 | AliMpVRowSegment* segment = GetRowSegment(i); | |
88 | ||
348e0500 | 89 | if (!dynamic_cast<AliMpVRowSegmentSpecial*>(segment) && |
5f91c9e8 | 90 | segment->GetHighIndicesLimit().GetFirst() >= ix) |
91 | ||
92 | return segment; | |
93 | } | |
348e0500 | 94 | |
5f91c9e8 | 95 | return 0; |
96 | } | |
97 | ||
98 | //_____________________________________________________________________________ | |
99 | AliMpMotifPosition* | |
100 | AliMpRow::FindMotifPosition(AliMpVRowSegment* segment, Int_t ix) const | |
101 | { | |
dee1d5f1 | 102 | /// Find first motif position in the specified row segment |
103 | /// with high indices limit >= ix. | |
5f91c9e8 | 104 | |
105 | if (!segment) return 0; | |
106 | ||
107 | for (Int_t i=0; i<segment->GetNofMotifs(); i++){ | |
108 | AliMpMotifPosition* motifPosition | |
109 | = GetMotifMap()->FindMotifPosition(segment->GetMotifPositionId(i)); | |
110 | ||
111 | if(!motifPosition) { | |
112 | Fatal("FindMotifPosition", "Not found."); | |
113 | return 0; | |
114 | } | |
115 | ||
116 | if (motifPosition->GetHighIndicesLimit().GetFirst()>=ix) | |
117 | return motifPosition; | |
118 | } | |
119 | ||
120 | return 0; | |
121 | } | |
122 | ||
123 | ||
124 | //_____________________________________________________________________________ | |
125 | void AliMpRow::SetHighIndicesLimits(Int_t iy) | |
126 | { | |
dee1d5f1 | 127 | /// Set the global indices high limit to its row segments, |
128 | /// motif positions with a given value. | |
129 | /// Keep ix unmodified. | |
5f91c9e8 | 130 | |
131 | for (Int_t j=0; j<GetNofRowSegments(); j++) { | |
132 | AliMpVRowSegment* rowSegment = GetRowSegment(j); | |
133 | rowSegment | |
134 | ->SetHighIndicesLimit( | |
135 | AliMpIntPair(rowSegment->GetHighIndicesLimit().GetFirst(),iy)); | |
136 | ||
137 | for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) { | |
138 | ||
139 | Int_t motifPositionId = rowSegment->GetMotifPositionId(k); | |
140 | AliMpMotifPosition* motifPosition | |
141 | = GetMotifMap()->FindMotifPosition(motifPositionId); | |
142 | ||
143 | motifPosition | |
144 | ->SetHighIndicesLimit( | |
145 | AliMpIntPair(motifPosition->GetHighIndicesLimit().GetFirst(), iy)); | |
146 | ||
147 | } | |
148 | } | |
149 | } | |
150 | ||
151 | //_____________________________________________________________________________ | |
152 | void AliMpRow::CheckEmpty() const | |
153 | { | |
dee1d5f1 | 154 | /// Give a fatal if the row is empty. |
5f91c9e8 | 155 | |
156 | if (GetNofRowSegments() == 0) | |
157 | Fatal("CheckEmpty", "Empty row"); | |
158 | } | |
159 | ||
160 | // | |
161 | // public methods | |
162 | // | |
163 | ||
164 | //_____________________________________________________________________________ | |
165 | void AliMpRow::AddRowSegment(AliMpVRowSegment* rowSegment) | |
166 | { | |
dee1d5f1 | 167 | /// Add row segment at the end. |
5f91c9e8 | 168 | |
f79c58a5 | 169 | fSegments.Add(rowSegment); |
5f91c9e8 | 170 | } |
171 | ||
172 | //_____________________________________________________________________________ | |
173 | void AliMpRow::AddRowSegmentInFront(AliMpVRowSegment* rowSegment) | |
174 | { | |
dee1d5f1 | 175 | /// Insert row segment in the first vector position. |
5f91c9e8 | 176 | |
f79c58a5 | 177 | fSegments.AddFirst(rowSegment); |
5f91c9e8 | 178 | } |
179 | ||
180 | //_____________________________________________________________________________ | |
181 | AliMpVRowSegment* AliMpRow::FindRowSegment(Double_t x) const | |
182 | { | |
dee1d5f1 | 183 | /// Find the row segment for the specified x position; |
184 | /// return 0 if no row segment is found. | |
5f91c9e8 | 185 | |
186 | for (Int_t i=0; i<GetNofRowSegments(); i++) { | |
f79c58a5 | 187 | |
f79c58a5 | 188 | AliMpVRowSegment* rs = (AliMpVRowSegment*)fSegments.At(i); |
f79c58a5 | 189 | |
5f91c9e8 | 190 | if (x >= rs->LeftBorderX() && x <= rs->RightBorderX()) |
191 | return rs; | |
192 | } | |
193 | ||
194 | return 0; | |
195 | } | |
196 | ||
197 | //_____________________________________________________________________________ | |
198 | Double_t AliMpRow::LowBorderY() const | |
199 | { | |
dee1d5f1 | 200 | /// Return the lowest row offset (the Y coordinate of the position of the |
201 | /// low border of motif). | |
5f91c9e8 | 202 | |
203 | CheckEmpty(); | |
204 | ||
205 | return fOffsetY - GetRowSegment(0)->HalfSizeY(); | |
206 | } | |
207 | ||
208 | //_____________________________________________________________________________ | |
209 | Double_t AliMpRow::UpperBorderY() const | |
210 | { | |
dee1d5f1 | 211 | /// Return the uppermost row offset (the Y coordinate of the position of the |
212 | /// upper border of motif). | |
213 | \ | |
5f91c9e8 | 214 | CheckEmpty(); |
215 | ||
216 | return fOffsetY + GetRowSegment(0)->HalfSizeY(); | |
217 | } | |
218 | ||
219 | //_____________________________________________________________________________ | |
220 | AliMpVPadIterator* AliMpRow::CreateIterator() const | |
221 | { | |
dee1d5f1 | 222 | /// Iterator is not implemented. |
5f91c9e8 | 223 | |
dee1d5f1 | 224 | Fatal("CreateIterator", "Iterator is not implemented."); |
5f91c9e8 | 225 | |
226 | return 0; | |
227 | } | |
228 | ||
229 | //_____________________________________________________________________________ | |
230 | void AliMpRow::SetMotifPositions() | |
231 | { | |
dee1d5f1 | 232 | /// Create motif positions objects and fills them in the motif map. |
5f91c9e8 | 233 | |
234 | CheckEmpty(); | |
235 | ||
236 | for (Int_t j=0; j<GetNofRowSegments(); j++) { | |
237 | AliMpVRowSegment* rowSegment = GetRowSegment(j); | |
238 | ||
239 | for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) { | |
240 | // Get values | |
241 | Int_t motifPositionId = rowSegment->GetMotifPositionId(k); | |
242 | AliMpVMotif* motif = rowSegment->GetMotif(k); | |
243 | TVector2 position = rowSegment->MotifCenter(motifPositionId); | |
244 | ||
245 | AliMpMotifPosition* motifPosition | |
246 | = new AliMpMotifPosition(motifPositionId, motif, position); | |
247 | // set the initial value to of HighIndicesLimit() Invalid() | |
248 | // (this is used for calculation of indices in case of | |
249 | // special row segments) | |
250 | motifPosition->SetHighIndicesLimit(AliMpIntPair::Invalid()); | |
251 | ||
348e0500 | 252 | //Bool_t warn = (rowSegment->GetNofMotifs()==1); |
253 | Bool_t warn = true; | |
254 | if (dynamic_cast<AliMpVRowSegmentSpecial*>(rowSegment)) warn = false; | |
5f91c9e8 | 255 | // supress warnings for special row segments |
256 | // which motifs can overlap the row borders | |
257 | ||
258 | Bool_t added = GetMotifMap()->AddMotifPosition(motifPosition, warn); | |
259 | ||
260 | if (!added) delete motifPosition; | |
261 | } | |
262 | } | |
263 | } | |
264 | ||
265 | //_____________________________________________________________________________ | |
cddd101e | 266 | void AliMpRow::SetGlobalIndices(AliMp::Direction constPadSizeDirection, |
5f91c9e8 | 267 | AliMpRow* rowBefore) |
268 | { | |
dee1d5f1 | 269 | /// Set the global indices limits to its row segments, motif positions |
270 | /// and itself. | |
5f91c9e8 | 271 | |
272 | Int_t ix = AliMpConstants::StartPadIndex(); | |
273 | Int_t iy = AliMpConstants::StartPadIndex(); | |
274 | ||
275 | for (Int_t j=0; j<GetNofRowSegments(); j++) { | |
276 | AliMpVRowSegment* rowSegment = GetRowSegment(j); | |
277 | ||
278 | ix += rowSegment->GetLowIndicesLimit().GetFirst(); | |
279 | ||
280 | for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) { | |
281 | ||
282 | // Find the y index value of the low edge | |
283 | if (rowBefore) { | |
cddd101e | 284 | if (constPadSizeDirection == AliMp::kY) { |
5f91c9e8 | 285 | iy = rowBefore->GetHighIndicesLimit().GetSecond()+1; |
286 | } | |
287 | else { | |
348e0500 | 288 | AliMpVRowSegment* seg = rowBefore->FindRowSegment(ix); |
5f91c9e8 | 289 | AliMpMotifPosition* motPos = FindMotifPosition(seg, ix); |
348e0500 | 290 | if (!dynamic_cast<AliMpRowSegmentRSpecial*>(rowSegment)) { |
291 | if (!motPos) | |
292 | Fatal("SetGlobalIndices", "Motif position in rowBefore not found."); | |
5f91c9e8 | 293 | |
348e0500 | 294 | iy = motPos->GetHighIndicesLimit().GetSecond()+1; |
295 | } | |
5f91c9e8 | 296 | } |
297 | } | |
298 | ||
299 | // Set (ix, iy) to k-th motif position and update ix | |
580c28fd | 300 | ix = rowSegment->SetIndicesToMotifPosition(k, AliMpIntPair(ix, iy)); |
5f91c9e8 | 301 | } |
580c28fd | 302 | rowSegment->SetGlobalIndices(rowBefore); |
5f91c9e8 | 303 | } |
304 | ||
580c28fd | 305 | // The low/high indices limits has to be taken as the highest/lowest from all |
306 | // row segments | |
307 | Int_t ixl = 9999; | |
308 | Int_t iyl = 9999; | |
309 | Int_t ixh = AliMpConstants::StartPadIndex(); | |
310 | Int_t iyh = AliMpConstants::StartPadIndex(); | |
5f91c9e8 | 311 | |
580c28fd | 312 | for (Int_t i=0; i<GetNofRowSegments(); i++) { |
313 | ||
314 | AliMpVRowSegment* rowSegment = GetRowSegment(i); | |
315 | ||
316 | if ( rowSegment->GetLowIndicesLimit().GetFirst() < ixl ) | |
317 | ixl = rowSegment->GetLowIndicesLimit().GetFirst(); | |
318 | ||
319 | if ( rowSegment->GetLowIndicesLimit().GetSecond() < iyl ) | |
320 | iyl = rowSegment->GetLowIndicesLimit().GetSecond(); | |
321 | ||
322 | if ( rowSegment->GetHighIndicesLimit().GetFirst() > ixh ) | |
323 | ixh = rowSegment->GetHighIndicesLimit().GetFirst(); | |
324 | ||
325 | if ( rowSegment->GetHighIndicesLimit().GetSecond() > iyh ) | |
326 | iyh = rowSegment->GetHighIndicesLimit().GetSecond(); | |
327 | } | |
328 | ||
329 | SetLowIndicesLimit(AliMpIntPair(ixl, iyl)); | |
330 | SetHighIndicesLimit(AliMpIntPair(ixh, iyh)); | |
5f91c9e8 | 331 | } |
332 | ||
333 | //_____________________________________________________________________________ | |
334 | TVector2 AliMpRow::Position() const | |
335 | { | |
dee1d5f1 | 336 | /// Return the position of the row centre. |
5f91c9e8 | 337 | |
338 | Double_t x = (GetRowSegment(0)->LeftBorderX() + | |
339 | GetRowSegment(GetNofRowSegments()-1)->RightBorderX())/2.; | |
340 | ||
341 | Double_t y = fOffsetY; | |
342 | ||
343 | return TVector2(x, y); | |
344 | } | |
345 | ||
346 | //_____________________________________________________________________________ | |
347 | TVector2 AliMpRow::Dimensions() const | |
348 | { | |
dee1d5f1 | 349 | /// Return the maximum halflengths of the row in x, y. |
5f91c9e8 | 350 | |
351 | Double_t x = (GetRowSegment(GetNofRowSegments()-1)->RightBorderX() - | |
352 | GetRowSegment(0)->LeftBorderX())/2.; | |
353 | ||
354 | Double_t y = GetRowSegment(0)->HalfSizeY(); | |
355 | ||
356 | return TVector2(x, y); | |
357 | } | |
358 | ||
359 | //_____________________________________________________________________________ | |
360 | void AliMpRow::SetRowSegmentOffsets(const TVector2& offset) | |
361 | { | |
dee1d5f1 | 362 | /// Set the row segments offsets in X . |
5f91c9e8 | 363 | |
364 | CheckEmpty(); | |
365 | ||
366 | AliMpVRowSegment* previous = 0; | |
367 | ||
368 | for (Int_t j=0; j<GetNofRowSegments(); j++) { | |
369 | AliMpVRowSegment* rowSegment = GetRowSegment(j); | |
370 | ||
371 | Double_t offsetX; | |
372 | if (previous) | |
373 | offsetX = previous->RightBorderX(); | |
374 | else | |
375 | offsetX = offset.X(); | |
376 | ||
377 | rowSegment->SetOffset(TVector2(offsetX, 0.)); | |
378 | previous = rowSegment; | |
379 | } | |
380 | } | |
381 | ||
382 | ||
383 | //_____________________________________________________________________________ | |
384 | Double_t AliMpRow::SetOffsetY(Double_t offsetY) | |
385 | { | |
dee1d5f1 | 386 | /// Set the row offset (the Y coordinate of the position of the |
387 | /// center of motif) and returns the offset of the top border. | |
5f91c9e8 | 388 | |
389 | CheckEmpty(); | |
390 | ||
391 | AliMpVRowSegment* first = GetRowSegment(0); | |
392 | Double_t rowSizeY = first->HalfSizeY(); | |
393 | ||
394 | // Check if all next row segments have motif of | |
395 | // the same size in y | |
396 | for (Int_t i=1; i<GetNofRowSegments(); i++) { | |
397 | Double_t sizeY = GetRowSegment(i)->HalfSizeY(); | |
398 | ||
399 | if (TMath::Abs(sizeY - rowSizeY) >= AliMpConstants::LengthTolerance()) { | |
5f91c9e8 | 400 | Fatal("SetOffsetY", "Motif with different Y size in one row"); |
401 | return 0.; | |
402 | } | |
403 | } | |
404 | ||
405 | offsetY += rowSizeY ; | |
406 | ||
407 | fOffsetY = offsetY; | |
408 | ||
409 | return offsetY += rowSizeY; | |
410 | } | |
411 | ||
412 | //_____________________________________________________________________________ | |
413 | Int_t AliMpRow::GetNofRowSegments() const | |
414 | { | |
dee1d5f1 | 415 | /// Return number of row segments. |
5f91c9e8 | 416 | |
f79c58a5 | 417 | return fSegments.GetSize(); |
5f91c9e8 | 418 | } |
419 | ||
420 | //_____________________________________________________________________________ | |
421 | AliMpVRowSegment* AliMpRow::GetRowSegment(Int_t i) const | |
422 | { | |
dee1d5f1 | 423 | /// Return i-th row segment. |
fb1bf5c0 | 424 | |
5f91c9e8 | 425 | if (i<0 || i>=GetNofRowSegments()) { |
2c605e66 | 426 | AliWarningStream() << "Index outside range" << endl; |
5f91c9e8 | 427 | return 0; |
428 | } | |
429 | ||
f79c58a5 | 430 | return (AliMpVRowSegment*)fSegments.At(i); |
5f91c9e8 | 431 | } |
432 |