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.8 2006/03/17 11:38:43 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"
37 #include <Riostream.h>
41 //_____________________________________________________________________________
42 AliMpRow::AliMpRow(Int_t id, AliMpMotifMap* motifMap)
49 /// Standard constructor
52 //_____________________________________________________________________________
60 /// Default constructor
63 //_____________________________________________________________________________
64 AliMpRow::AliMpRow(const AliMpRow& right)
65 : AliMpVIndexed(right)
67 /// Protected copy constructor (not provided)
69 Fatal("AliMpRow", "Copy constructor not provided.");
72 //_____________________________________________________________________________
78 for (Int_t i=0; i<GetNofRowSegments(); i++)
91 //_____________________________________________________________________________
92 AliMpRow& AliMpRow::operator=(const AliMpRow& right)
94 /// Protected assignment operator (not provided)
96 // check assignment to self
97 if (this == &right) return *this;
99 Fatal("operator =", "Assignment operator not provided.");
108 //_____________________________________________________________________________
109 AliMpVRowSegment* AliMpRow::FindRowSegment(Int_t ix) const
111 /// Find first normal row segment with low indices limit >= ix.
113 for (Int_t i=0; i<GetNofRowSegments(); i++) {
114 AliMpVRowSegment* segment = GetRowSegment(i);
116 if (!dynamic_cast<AliMpVRowSegmentSpecial*>(segment) &&
117 segment->GetHighIndicesLimit().GetFirst() >= ix)
125 //_____________________________________________________________________________
127 AliMpRow::FindMotifPosition(AliMpVRowSegment* segment, Int_t ix) const
129 /// Find first motif position in the specified row segment
130 /// with high indices limit >= ix.
132 if (!segment) return 0;
134 for (Int_t i=0; i<segment->GetNofMotifs(); i++){
135 AliMpMotifPosition* motifPosition
136 = GetMotifMap()->FindMotifPosition(segment->GetMotifPositionId(i));
139 Fatal("FindMotifPosition", "Not found.");
143 if (motifPosition->GetHighIndicesLimit().GetFirst()>=ix)
144 return motifPosition;
151 //_____________________________________________________________________________
152 void AliMpRow::SetHighIndicesLimits(Int_t iy)
154 /// Set the global indices high limit to its row segments,
155 /// motif positions with a given value.
156 /// Keep ix unmodified.
158 for (Int_t j=0; j<GetNofRowSegments(); j++) {
159 AliMpVRowSegment* rowSegment = GetRowSegment(j);
161 ->SetHighIndicesLimit(
162 AliMpIntPair(rowSegment->GetHighIndicesLimit().GetFirst(),iy));
164 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
166 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
167 AliMpMotifPosition* motifPosition
168 = GetMotifMap()->FindMotifPosition(motifPositionId);
171 ->SetHighIndicesLimit(
172 AliMpIntPair(motifPosition->GetHighIndicesLimit().GetFirst(), iy));
178 //_____________________________________________________________________________
179 void AliMpRow::CheckEmpty() const
181 /// Give a fatal if the row is empty.
183 if (GetNofRowSegments() == 0)
184 Fatal("CheckEmpty", "Empty row");
191 //_____________________________________________________________________________
192 void AliMpRow::AddRowSegment(AliMpVRowSegment* rowSegment)
194 /// Add row segment at the end.
197 fSegments.push_back(rowSegment);
201 fSegments.Add(rowSegment);
205 //_____________________________________________________________________________
206 void AliMpRow::AddRowSegmentInFront(AliMpVRowSegment* rowSegment)
208 /// Insert row segment in the first vector position.
211 fSegments.insert(fSegments.begin(), rowSegment);
215 fSegments.AddFirst(rowSegment);
219 //_____________________________________________________________________________
220 AliMpVRowSegment* AliMpRow::FindRowSegment(Double_t x) const
222 /// Find the row segment for the specified x position;
223 /// return 0 if no row segment is found.
225 for (Int_t i=0; i<GetNofRowSegments(); i++) {
228 AliMpVRowSegment* rs = fSegments[i];
231 AliMpVRowSegment* rs = (AliMpVRowSegment*)fSegments.At(i);
234 if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
241 //_____________________________________________________________________________
242 Double_t AliMpRow::LowBorderY() const
244 /// Return the lowest row offset (the Y coordinate of the position of the
245 /// low border of motif).
249 return fOffsetY - GetRowSegment(0)->HalfSizeY();
252 //_____________________________________________________________________________
253 Double_t AliMpRow::UpperBorderY() const
255 /// Return the uppermost row offset (the Y coordinate of the position of the
256 /// upper border of motif).
260 return fOffsetY + GetRowSegment(0)->HalfSizeY();
263 //_____________________________________________________________________________
264 AliMpVPadIterator* AliMpRow::CreateIterator() const
266 /// Iterator is not implemented.
268 Fatal("CreateIterator", "Iterator is not implemented.");
273 //_____________________________________________________________________________
274 void AliMpRow::SetMotifPositions()
276 /// Create motif positions objects and fills them in the motif map.
280 for (Int_t j=0; j<GetNofRowSegments(); j++) {
281 AliMpVRowSegment* rowSegment = GetRowSegment(j);
283 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
285 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
286 AliMpVMotif* motif = rowSegment->GetMotif(k);
287 TVector2 position = rowSegment->MotifCenter(motifPositionId);
289 AliMpMotifPosition* motifPosition
290 = new AliMpMotifPosition(motifPositionId, motif, position);
291 // set the initial value to of HighIndicesLimit() Invalid()
292 // (this is used for calculation of indices in case of
293 // special row segments)
294 motifPosition->SetHighIndicesLimit(AliMpIntPair::Invalid());
296 //Bool_t warn = (rowSegment->GetNofMotifs()==1);
298 if (dynamic_cast<AliMpVRowSegmentSpecial*>(rowSegment)) warn = false;
299 // supress warnings for special row segments
300 // which motifs can overlap the row borders
302 Bool_t added = GetMotifMap()->AddMotifPosition(motifPosition, warn);
304 if (!added) delete motifPosition;
309 //_____________________________________________________________________________
310 void AliMpRow::SetGlobalIndices(AliMpDirection constPadSizeDirection,
313 /// Set the global indices limits to its row segments, motif positions
316 Int_t ix = AliMpConstants::StartPadIndex();
317 Int_t iy = AliMpConstants::StartPadIndex();
319 for (Int_t j=0; j<GetNofRowSegments(); j++) {
320 AliMpVRowSegment* rowSegment = GetRowSegment(j);
322 ix += rowSegment->GetLowIndicesLimit().GetFirst();
324 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
326 // Find the y index value of the low edge
328 if (constPadSizeDirection == kY) {
329 iy = rowBefore->GetHighIndicesLimit().GetSecond()+1;
332 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ix);
333 AliMpMotifPosition* motPos = FindMotifPosition(seg, ix);
334 if (!dynamic_cast<AliMpRowSegmentRSpecial*>(rowSegment)) {
336 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
338 iy = motPos->GetHighIndicesLimit().GetSecond()+1;
343 // Set (ix, iy) to k-th motif position and update ix
344 ix = rowSegment->SetIndicesToMotifPosition(k, AliMpIntPair(ix, iy));
346 rowSegment->SetGlobalIndices(rowBefore);
349 // The low/high indices limits has to be taken as the highest/lowest from all
353 Int_t ixh = AliMpConstants::StartPadIndex();
354 Int_t iyh = AliMpConstants::StartPadIndex();
356 for (Int_t i=0; i<GetNofRowSegments(); i++) {
358 AliMpVRowSegment* rowSegment = GetRowSegment(i);
360 if ( rowSegment->GetLowIndicesLimit().GetFirst() < ixl )
361 ixl = rowSegment->GetLowIndicesLimit().GetFirst();
363 if ( rowSegment->GetLowIndicesLimit().GetSecond() < iyl )
364 iyl = rowSegment->GetLowIndicesLimit().GetSecond();
366 if ( rowSegment->GetHighIndicesLimit().GetFirst() > ixh )
367 ixh = rowSegment->GetHighIndicesLimit().GetFirst();
369 if ( rowSegment->GetHighIndicesLimit().GetSecond() > iyh )
370 iyh = rowSegment->GetHighIndicesLimit().GetSecond();
373 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
374 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));
377 //_____________________________________________________________________________
378 TVector2 AliMpRow::Position() const
380 /// Return the position of the row centre.
382 Double_t x = (GetRowSegment(0)->LeftBorderX() +
383 GetRowSegment(GetNofRowSegments()-1)->RightBorderX())/2.;
385 Double_t y = fOffsetY;
387 return TVector2(x, y);
390 //_____________________________________________________________________________
391 TVector2 AliMpRow::Dimensions() const
393 /// Return the maximum halflengths of the row in x, y.
395 Double_t x = (GetRowSegment(GetNofRowSegments()-1)->RightBorderX() -
396 GetRowSegment(0)->LeftBorderX())/2.;
398 Double_t y = GetRowSegment(0)->HalfSizeY();
400 return TVector2(x, y);
403 //_____________________________________________________________________________
404 void AliMpRow::SetRowSegmentOffsets(const TVector2& offset)
406 /// Set the row segments offsets in X .
410 AliMpVRowSegment* previous = 0;
412 for (Int_t j=0; j<GetNofRowSegments(); j++) {
413 AliMpVRowSegment* rowSegment = GetRowSegment(j);
417 offsetX = previous->RightBorderX();
419 offsetX = offset.X();
421 rowSegment->SetOffset(TVector2(offsetX, 0.));
422 previous = rowSegment;
427 //_____________________________________________________________________________
428 Double_t AliMpRow::SetOffsetY(Double_t offsetY)
430 /// Set the row offset (the Y coordinate of the position of the
431 /// center of motif) and returns the offset of the top border.
435 AliMpVRowSegment* first = GetRowSegment(0);
436 Double_t rowSizeY = first->HalfSizeY();
438 // Check if all next row segments have motif of
439 // the same size in y
440 for (Int_t i=1; i<GetNofRowSegments(); i++) {
441 Double_t sizeY = GetRowSegment(i)->HalfSizeY();
443 if (TMath::Abs(sizeY - rowSizeY) >= AliMpConstants::LengthTolerance()) {
444 Fatal("SetOffsetY", "Motif with different Y size in one row");
449 offsetY += rowSizeY ;
453 return offsetY += rowSizeY;
456 //_____________________________________________________________________________
457 Int_t AliMpRow::GetNofRowSegments() const
459 /// Return number of row segments.
462 return fSegments.size();
466 return fSegments.GetSize();
470 //_____________________________________________________________________________
471 AliMpVRowSegment* AliMpRow::GetRowSegment(Int_t i) const
473 /// Return i-th row segment.
475 if (i<0 || i>=GetNofRowSegments()) {
476 AliWarningStream() << "Index outside range" << endl;
485 return (AliMpVRowSegment*)fSegments.At(i);