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"
37 #include <Riostream.h>
43 //_____________________________________________________________________________
44 AliMpRow::AliMpRow(Int_t id, AliMpMotifMap* motifMap)
51 /// Standard constructor
54 //_____________________________________________________________________________
62 /// Default constructor
65 //_____________________________________________________________________________
71 for (Int_t i=0; i<GetNofRowSegments(); i++)
84 //_____________________________________________________________________________
85 AliMpVRowSegment* AliMpRow::FindRowSegment(Int_t ix) const
87 /// Find first normal row segment with low indices limit >= ix.
89 for (Int_t i=0; i<GetNofRowSegments(); i++) {
90 AliMpVRowSegment* segment = GetRowSegment(i);
92 if (!dynamic_cast<AliMpVRowSegmentSpecial*>(segment) &&
93 segment->GetHighIndicesLimit().GetFirst() >= ix)
101 //_____________________________________________________________________________
103 AliMpRow::FindMotifPosition(AliMpVRowSegment* segment, Int_t ix) const
105 /// Find first motif position in the specified row segment
106 /// with high indices limit >= ix.
108 if (!segment) return 0;
110 for (Int_t i=0; i<segment->GetNofMotifs(); i++){
111 AliMpMotifPosition* motifPosition
112 = GetMotifMap()->FindMotifPosition(segment->GetMotifPositionId(i));
115 Fatal("FindMotifPosition", "Not found.");
119 if (motifPosition->GetHighIndicesLimit().GetFirst()>=ix)
120 return motifPosition;
127 //_____________________________________________________________________________
128 void AliMpRow::SetHighIndicesLimits(Int_t iy)
130 /// Set the global indices high limit to its row segments,
131 /// motif positions with a given value.
132 /// Keep ix unmodified.
134 for (Int_t j=0; j<GetNofRowSegments(); j++) {
135 AliMpVRowSegment* rowSegment = GetRowSegment(j);
137 ->SetHighIndicesLimit(
138 AliMpIntPair(rowSegment->GetHighIndicesLimit().GetFirst(),iy));
140 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
142 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
143 AliMpMotifPosition* motifPosition
144 = GetMotifMap()->FindMotifPosition(motifPositionId);
147 ->SetHighIndicesLimit(
148 AliMpIntPair(motifPosition->GetHighIndicesLimit().GetFirst(), iy));
154 //_____________________________________________________________________________
155 void AliMpRow::CheckEmpty() const
157 /// Give a fatal if the row is empty.
159 if (GetNofRowSegments() == 0)
160 Fatal("CheckEmpty", "Empty row");
167 //_____________________________________________________________________________
168 void AliMpRow::AddRowSegment(AliMpVRowSegment* rowSegment)
170 /// Add row segment at the end.
173 fSegments.push_back(rowSegment);
177 fSegments.Add(rowSegment);
181 //_____________________________________________________________________________
182 void AliMpRow::AddRowSegmentInFront(AliMpVRowSegment* rowSegment)
184 /// Insert row segment in the first vector position.
187 fSegments.insert(fSegments.begin(), rowSegment);
191 fSegments.AddFirst(rowSegment);
195 //_____________________________________________________________________________
196 AliMpVRowSegment* AliMpRow::FindRowSegment(Double_t x) const
198 /// Find the row segment for the specified x position;
199 /// return 0 if no row segment is found.
201 for (Int_t i=0; i<GetNofRowSegments(); i++) {
204 AliMpVRowSegment* rs = fSegments[i];
207 AliMpVRowSegment* rs = (AliMpVRowSegment*)fSegments.At(i);
210 if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
217 //_____________________________________________________________________________
218 Double_t AliMpRow::LowBorderY() const
220 /// Return the lowest row offset (the Y coordinate of the position of the
221 /// low border of motif).
225 return fOffsetY - GetRowSegment(0)->HalfSizeY();
228 //_____________________________________________________________________________
229 Double_t AliMpRow::UpperBorderY() const
231 /// Return the uppermost row offset (the Y coordinate of the position of the
232 /// upper border of motif).
236 return fOffsetY + GetRowSegment(0)->HalfSizeY();
239 //_____________________________________________________________________________
240 AliMpVPadIterator* AliMpRow::CreateIterator() const
242 /// Iterator is not implemented.
244 Fatal("CreateIterator", "Iterator is not implemented.");
249 //_____________________________________________________________________________
250 void AliMpRow::SetMotifPositions()
252 /// Create motif positions objects and fills them in the motif map.
256 for (Int_t j=0; j<GetNofRowSegments(); j++) {
257 AliMpVRowSegment* rowSegment = GetRowSegment(j);
259 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
261 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
262 AliMpVMotif* motif = rowSegment->GetMotif(k);
263 TVector2 position = rowSegment->MotifCenter(motifPositionId);
265 AliMpMotifPosition* motifPosition
266 = new AliMpMotifPosition(motifPositionId, motif, position);
267 // set the initial value to of HighIndicesLimit() Invalid()
268 // (this is used for calculation of indices in case of
269 // special row segments)
270 motifPosition->SetHighIndicesLimit(AliMpIntPair::Invalid());
272 //Bool_t warn = (rowSegment->GetNofMotifs()==1);
274 if (dynamic_cast<AliMpVRowSegmentSpecial*>(rowSegment)) warn = false;
275 // supress warnings for special row segments
276 // which motifs can overlap the row borders
278 Bool_t added = GetMotifMap()->AddMotifPosition(motifPosition, warn);
280 if (!added) delete motifPosition;
285 //_____________________________________________________________________________
286 void AliMpRow::SetGlobalIndices(AliMpDirection constPadSizeDirection,
289 /// Set the global indices limits to its row segments, motif positions
292 Int_t ix = AliMpConstants::StartPadIndex();
293 Int_t iy = AliMpConstants::StartPadIndex();
295 for (Int_t j=0; j<GetNofRowSegments(); j++) {
296 AliMpVRowSegment* rowSegment = GetRowSegment(j);
298 ix += rowSegment->GetLowIndicesLimit().GetFirst();
300 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
302 // Find the y index value of the low edge
304 if (constPadSizeDirection == kY) {
305 iy = rowBefore->GetHighIndicesLimit().GetSecond()+1;
308 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ix);
309 AliMpMotifPosition* motPos = FindMotifPosition(seg, ix);
310 if (!dynamic_cast<AliMpRowSegmentRSpecial*>(rowSegment)) {
312 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
314 iy = motPos->GetHighIndicesLimit().GetSecond()+1;
319 // Set (ix, iy) to k-th motif position and update ix
320 ix = rowSegment->SetIndicesToMotifPosition(k, AliMpIntPair(ix, iy));
322 rowSegment->SetGlobalIndices(rowBefore);
325 // The low/high indices limits has to be taken as the highest/lowest from all
329 Int_t ixh = AliMpConstants::StartPadIndex();
330 Int_t iyh = AliMpConstants::StartPadIndex();
332 for (Int_t i=0; i<GetNofRowSegments(); i++) {
334 AliMpVRowSegment* rowSegment = GetRowSegment(i);
336 if ( rowSegment->GetLowIndicesLimit().GetFirst() < ixl )
337 ixl = rowSegment->GetLowIndicesLimit().GetFirst();
339 if ( rowSegment->GetLowIndicesLimit().GetSecond() < iyl )
340 iyl = rowSegment->GetLowIndicesLimit().GetSecond();
342 if ( rowSegment->GetHighIndicesLimit().GetFirst() > ixh )
343 ixh = rowSegment->GetHighIndicesLimit().GetFirst();
345 if ( rowSegment->GetHighIndicesLimit().GetSecond() > iyh )
346 iyh = rowSegment->GetHighIndicesLimit().GetSecond();
349 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
350 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));
353 //_____________________________________________________________________________
354 TVector2 AliMpRow::Position() const
356 /// Return the position of the row centre.
358 Double_t x = (GetRowSegment(0)->LeftBorderX() +
359 GetRowSegment(GetNofRowSegments()-1)->RightBorderX())/2.;
361 Double_t y = fOffsetY;
363 return TVector2(x, y);
366 //_____________________________________________________________________________
367 TVector2 AliMpRow::Dimensions() const
369 /// Return the maximum halflengths of the row in x, y.
371 Double_t x = (GetRowSegment(GetNofRowSegments()-1)->RightBorderX() -
372 GetRowSegment(0)->LeftBorderX())/2.;
374 Double_t y = GetRowSegment(0)->HalfSizeY();
376 return TVector2(x, y);
379 //_____________________________________________________________________________
380 void AliMpRow::SetRowSegmentOffsets(const TVector2& offset)
382 /// Set the row segments offsets in X .
386 AliMpVRowSegment* previous = 0;
388 for (Int_t j=0; j<GetNofRowSegments(); j++) {
389 AliMpVRowSegment* rowSegment = GetRowSegment(j);
393 offsetX = previous->RightBorderX();
395 offsetX = offset.X();
397 rowSegment->SetOffset(TVector2(offsetX, 0.));
398 previous = rowSegment;
403 //_____________________________________________________________________________
404 Double_t AliMpRow::SetOffsetY(Double_t offsetY)
406 /// Set the row offset (the Y coordinate of the position of the
407 /// center of motif) and returns the offset of the top border.
411 AliMpVRowSegment* first = GetRowSegment(0);
412 Double_t rowSizeY = first->HalfSizeY();
414 // Check if all next row segments have motif of
415 // the same size in y
416 for (Int_t i=1; i<GetNofRowSegments(); i++) {
417 Double_t sizeY = GetRowSegment(i)->HalfSizeY();
419 if (TMath::Abs(sizeY - rowSizeY) >= AliMpConstants::LengthTolerance()) {
420 Fatal("SetOffsetY", "Motif with different Y size in one row");
425 offsetY += rowSizeY ;
429 return offsetY += rowSizeY;
432 //_____________________________________________________________________________
433 Int_t AliMpRow::GetNofRowSegments() const
435 /// Return number of row segments.
438 return fSegments.size();
442 return fSegments.GetSize();
446 //_____________________________________________________________________________
447 AliMpVRowSegment* AliMpRow::GetRowSegment(Int_t i) const
449 /// Return i-th row segment.
451 if (i<0 || i>=GetNofRowSegments()) {
452 AliWarningStream() << "Index outside range" << endl;
461 return (AliMpVRowSegment*)fSegments.At(i);