1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpRow.cxx,v 1.9 2006/05/24 13:58:46 ivana Exp $
22 // Class describing a row composed of the row segments.
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 #include "AliMpVRowSegment.h"
28 #include "AliMpVRowSegmentSpecial.h"
29 #include "AliMpRowSegmentRSpecial.h"
30 #include "AliMpVMotif.h"
31 #include "AliMpMotifType.h"
32 #include "AliMpMotifPosition.h"
33 #include "AliMpMotifMap.h"
34 #include "AliMpConstants.h"
39 #include <Riostream.h>
45 //_____________________________________________________________________________
46 AliMpRow::AliMpRow(Int_t id, AliMpMotifMap* motifMap)
53 /// Standard constructor
56 //_____________________________________________________________________________
64 /// Default constructor
67 //_____________________________________________________________________________
73 for (Int_t i=0; i<GetNofRowSegments(); i++)
86 //_____________________________________________________________________________
87 AliMpVRowSegment* AliMpRow::FindRowSegment(Int_t ix) const
89 /// Find first normal row segment with low indices limit >= ix.
91 for (Int_t i=0; i<GetNofRowSegments(); i++) {
92 AliMpVRowSegment* segment = GetRowSegment(i);
94 if (!dynamic_cast<AliMpVRowSegmentSpecial*>(segment) &&
95 segment->GetHighIndicesLimit().GetFirst() >= ix)
103 //_____________________________________________________________________________
105 AliMpRow::FindMotifPosition(AliMpVRowSegment* segment, Int_t ix) const
107 /// Find first motif position in the specified row segment
108 /// with high indices limit >= ix.
110 if (!segment) return 0;
112 for (Int_t i=0; i<segment->GetNofMotifs(); i++){
113 AliMpMotifPosition* motifPosition
114 = GetMotifMap()->FindMotifPosition(segment->GetMotifPositionId(i));
117 Fatal("FindMotifPosition", "Not found.");
121 if (motifPosition->GetHighIndicesLimit().GetFirst()>=ix)
122 return motifPosition;
129 //_____________________________________________________________________________
130 void AliMpRow::SetHighIndicesLimits(Int_t iy)
132 /// Set the global indices high limit to its row segments,
133 /// motif positions with a given value.
134 /// Keep ix unmodified.
136 for (Int_t j=0; j<GetNofRowSegments(); j++) {
137 AliMpVRowSegment* rowSegment = GetRowSegment(j);
139 ->SetHighIndicesLimit(
140 AliMpIntPair(rowSegment->GetHighIndicesLimit().GetFirst(),iy));
142 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
144 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
145 AliMpMotifPosition* motifPosition
146 = GetMotifMap()->FindMotifPosition(motifPositionId);
149 ->SetHighIndicesLimit(
150 AliMpIntPair(motifPosition->GetHighIndicesLimit().GetFirst(), iy));
156 //_____________________________________________________________________________
157 void AliMpRow::CheckEmpty() const
159 /// Give a fatal if the row is empty.
161 if (GetNofRowSegments() == 0)
162 Fatal("CheckEmpty", "Empty row");
169 //_____________________________________________________________________________
170 void AliMpRow::AddRowSegment(AliMpVRowSegment* rowSegment)
172 /// Add row segment at the end.
175 fSegments.push_back(rowSegment);
179 fSegments.Add(rowSegment);
183 //_____________________________________________________________________________
184 void AliMpRow::AddRowSegmentInFront(AliMpVRowSegment* rowSegment)
186 /// Insert row segment in the first vector position.
189 fSegments.insert(fSegments.begin(), rowSegment);
193 fSegments.AddFirst(rowSegment);
197 //_____________________________________________________________________________
198 AliMpVRowSegment* AliMpRow::FindRowSegment(Double_t x) const
200 /// Find the row segment for the specified x position;
201 /// return 0 if no row segment is found.
203 for (Int_t i=0; i<GetNofRowSegments(); i++) {
206 AliMpVRowSegment* rs = fSegments[i];
209 AliMpVRowSegment* rs = (AliMpVRowSegment*)fSegments.At(i);
212 if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
219 //_____________________________________________________________________________
220 Double_t AliMpRow::LowBorderY() const
222 /// Return the lowest row offset (the Y coordinate of the position of the
223 /// low border of motif).
227 return fOffsetY - GetRowSegment(0)->HalfSizeY();
230 //_____________________________________________________________________________
231 Double_t AliMpRow::UpperBorderY() const
233 /// Return the uppermost row offset (the Y coordinate of the position of the
234 /// upper border of motif).
238 return fOffsetY + GetRowSegment(0)->HalfSizeY();
241 //_____________________________________________________________________________
242 AliMpVPadIterator* AliMpRow::CreateIterator() const
244 /// Iterator is not implemented.
246 Fatal("CreateIterator", "Iterator is not implemented.");
251 //_____________________________________________________________________________
252 void AliMpRow::SetMotifPositions()
254 /// Create motif positions objects and fills them in the motif map.
258 for (Int_t j=0; j<GetNofRowSegments(); j++) {
259 AliMpVRowSegment* rowSegment = GetRowSegment(j);
261 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
263 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
264 AliMpVMotif* motif = rowSegment->GetMotif(k);
265 TVector2 position = rowSegment->MotifCenter(motifPositionId);
267 AliMpMotifPosition* motifPosition
268 = new AliMpMotifPosition(motifPositionId, motif, position);
269 // set the initial value to of HighIndicesLimit() Invalid()
270 // (this is used for calculation of indices in case of
271 // special row segments)
272 motifPosition->SetHighIndicesLimit(AliMpIntPair::Invalid());
274 //Bool_t warn = (rowSegment->GetNofMotifs()==1);
276 if (dynamic_cast<AliMpVRowSegmentSpecial*>(rowSegment)) warn = false;
277 // supress warnings for special row segments
278 // which motifs can overlap the row borders
280 Bool_t added = GetMotifMap()->AddMotifPosition(motifPosition, warn);
282 if (!added) delete motifPosition;
287 //_____________________________________________________________________________
288 void AliMpRow::SetGlobalIndices(AliMp::Direction constPadSizeDirection,
291 /// Set the global indices limits to its row segments, motif positions
294 Int_t ix = AliMpConstants::StartPadIndex();
295 Int_t iy = AliMpConstants::StartPadIndex();
297 for (Int_t j=0; j<GetNofRowSegments(); j++) {
298 AliMpVRowSegment* rowSegment = GetRowSegment(j);
300 ix += rowSegment->GetLowIndicesLimit().GetFirst();
302 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
304 // Find the y index value of the low edge
306 if (constPadSizeDirection == AliMp::kY) {
307 iy = rowBefore->GetHighIndicesLimit().GetSecond()+1;
310 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ix);
311 AliMpMotifPosition* motPos = FindMotifPosition(seg, ix);
312 if (!dynamic_cast<AliMpRowSegmentRSpecial*>(rowSegment)) {
314 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
316 iy = motPos->GetHighIndicesLimit().GetSecond()+1;
321 // Set (ix, iy) to k-th motif position and update ix
322 ix = rowSegment->SetIndicesToMotifPosition(k, AliMpIntPair(ix, iy));
324 rowSegment->SetGlobalIndices(rowBefore);
327 // The low/high indices limits has to be taken as the highest/lowest from all
331 Int_t ixh = AliMpConstants::StartPadIndex();
332 Int_t iyh = AliMpConstants::StartPadIndex();
334 for (Int_t i=0; i<GetNofRowSegments(); i++) {
336 AliMpVRowSegment* rowSegment = GetRowSegment(i);
338 if ( rowSegment->GetLowIndicesLimit().GetFirst() < ixl )
339 ixl = rowSegment->GetLowIndicesLimit().GetFirst();
341 if ( rowSegment->GetLowIndicesLimit().GetSecond() < iyl )
342 iyl = rowSegment->GetLowIndicesLimit().GetSecond();
344 if ( rowSegment->GetHighIndicesLimit().GetFirst() > ixh )
345 ixh = rowSegment->GetHighIndicesLimit().GetFirst();
347 if ( rowSegment->GetHighIndicesLimit().GetSecond() > iyh )
348 iyh = rowSegment->GetHighIndicesLimit().GetSecond();
351 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
352 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));
355 //_____________________________________________________________________________
356 TVector2 AliMpRow::Position() const
358 /// Return the position of the row centre.
360 Double_t x = (GetRowSegment(0)->LeftBorderX() +
361 GetRowSegment(GetNofRowSegments()-1)->RightBorderX())/2.;
363 Double_t y = fOffsetY;
365 return TVector2(x, y);
368 //_____________________________________________________________________________
369 TVector2 AliMpRow::Dimensions() const
371 /// Return the maximum halflengths of the row in x, y.
373 Double_t x = (GetRowSegment(GetNofRowSegments()-1)->RightBorderX() -
374 GetRowSegment(0)->LeftBorderX())/2.;
376 Double_t y = GetRowSegment(0)->HalfSizeY();
378 return TVector2(x, y);
381 //_____________________________________________________________________________
382 void AliMpRow::SetRowSegmentOffsets(const TVector2& offset)
384 /// Set the row segments offsets in X .
388 AliMpVRowSegment* previous = 0;
390 for (Int_t j=0; j<GetNofRowSegments(); j++) {
391 AliMpVRowSegment* rowSegment = GetRowSegment(j);
395 offsetX = previous->RightBorderX();
397 offsetX = offset.X();
399 rowSegment->SetOffset(TVector2(offsetX, 0.));
400 previous = rowSegment;
405 //_____________________________________________________________________________
406 Double_t AliMpRow::SetOffsetY(Double_t offsetY)
408 /// Set the row offset (the Y coordinate of the position of the
409 /// center of motif) and returns the offset of the top border.
413 AliMpVRowSegment* first = GetRowSegment(0);
414 Double_t rowSizeY = first->HalfSizeY();
416 // Check if all next row segments have motif of
417 // the same size in y
418 for (Int_t i=1; i<GetNofRowSegments(); i++) {
419 Double_t sizeY = GetRowSegment(i)->HalfSizeY();
421 if (TMath::Abs(sizeY - rowSizeY) >= AliMpConstants::LengthTolerance()) {
422 Fatal("SetOffsetY", "Motif with different Y size in one row");
427 offsetY += rowSizeY ;
431 return offsetY += rowSizeY;
434 //_____________________________________________________________________________
435 Int_t AliMpRow::GetNofRowSegments() const
437 /// Return number of row segments.
440 return fSegments.size();
444 return fSegments.GetSize();
448 //_____________________________________________________________________________
449 AliMpVRowSegment* AliMpRow::GetRowSegment(Int_t i) const
451 /// Return i-th row segment.
453 if (i<0 || i>=GetNofRowSegments()) {
454 AliWarningStream() << "Index outside range" << endl;
463 return (AliMpVRowSegment*)fSegments.At(i);