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 $
20 //-----------------------------------------------------------------------------
23 // Class describing a row composed of the row segments.
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 //-----------------------------------------------------------------------------
29 #include "AliMpVRowSegment.h"
30 #include "AliMpVRowSegmentSpecial.h"
31 #include "AliMpRowSegmentRSpecial.h"
32 #include "AliMpVMotif.h"
33 #include "AliMpMotifType.h"
34 #include "AliMpMotifPosition.h"
35 #include "AliMpMotifMap.h"
36 #include "AliMpConstants.h"
41 #include <Riostream.h>
47 //_____________________________________________________________________________
48 AliMpRow::AliMpRow(Int_t id, AliMpMotifMap* motifMap)
55 /// Standard constructor
58 //_____________________________________________________________________________
66 /// Default constructor
69 //_____________________________________________________________________________
75 for (Int_t i=0; i<GetNofRowSegments(); i++)
88 //_____________________________________________________________________________
89 AliMpVRowSegment* AliMpRow::FindRowSegment(Int_t ix) const
91 /// Find first normal row segment with low indices limit >= ix.
93 for (Int_t i=0; i<GetNofRowSegments(); i++) {
94 AliMpVRowSegment* segment = GetRowSegment(i);
96 if (!dynamic_cast<AliMpVRowSegmentSpecial*>(segment) &&
97 segment->GetHighIndicesLimit().GetFirst() >= ix)
105 //_____________________________________________________________________________
107 AliMpRow::FindMotifPosition(AliMpVRowSegment* segment, Int_t ix) const
109 /// Find first motif position in the specified row segment
110 /// with high indices limit >= ix.
112 if (!segment) return 0;
114 for (Int_t i=0; i<segment->GetNofMotifs(); i++){
115 AliMpMotifPosition* motifPosition
116 = GetMotifMap()->FindMotifPosition(segment->GetMotifPositionId(i));
119 Fatal("FindMotifPosition", "Not found.");
123 if (motifPosition->GetHighIndicesLimit().GetFirst()>=ix)
124 return motifPosition;
131 //_____________________________________________________________________________
132 void AliMpRow::SetHighIndicesLimits(Int_t iy)
134 /// Set the global indices high limit to its row segments,
135 /// motif positions with a given value.
136 /// Keep ix unmodified.
138 for (Int_t j=0; j<GetNofRowSegments(); j++) {
139 AliMpVRowSegment* rowSegment = GetRowSegment(j);
141 ->SetHighIndicesLimit(
142 AliMpIntPair(rowSegment->GetHighIndicesLimit().GetFirst(),iy));
144 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
146 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
147 AliMpMotifPosition* motifPosition
148 = GetMotifMap()->FindMotifPosition(motifPositionId);
151 ->SetHighIndicesLimit(
152 AliMpIntPair(motifPosition->GetHighIndicesLimit().GetFirst(), iy));
158 //_____________________________________________________________________________
159 void AliMpRow::CheckEmpty() const
161 /// Give a fatal if the row is empty.
163 if (GetNofRowSegments() == 0)
164 Fatal("CheckEmpty", "Empty row");
171 //_____________________________________________________________________________
172 void AliMpRow::AddRowSegment(AliMpVRowSegment* rowSegment)
174 /// Add row segment at the end.
177 fSegments.push_back(rowSegment);
181 fSegments.Add(rowSegment);
185 //_____________________________________________________________________________
186 void AliMpRow::AddRowSegmentInFront(AliMpVRowSegment* rowSegment)
188 /// Insert row segment in the first vector position.
191 fSegments.insert(fSegments.begin(), rowSegment);
195 fSegments.AddFirst(rowSegment);
199 //_____________________________________________________________________________
200 AliMpVRowSegment* AliMpRow::FindRowSegment(Double_t x) const
202 /// Find the row segment for the specified x position;
203 /// return 0 if no row segment is found.
205 for (Int_t i=0; i<GetNofRowSegments(); i++) {
208 AliMpVRowSegment* rs = fSegments[i];
211 AliMpVRowSegment* rs = (AliMpVRowSegment*)fSegments.At(i);
214 if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
221 //_____________________________________________________________________________
222 Double_t AliMpRow::LowBorderY() const
224 /// Return the lowest row offset (the Y coordinate of the position of the
225 /// low border of motif).
229 return fOffsetY - GetRowSegment(0)->HalfSizeY();
232 //_____________________________________________________________________________
233 Double_t AliMpRow::UpperBorderY() const
235 /// Return the uppermost row offset (the Y coordinate of the position of the
236 /// upper border of motif).
240 return fOffsetY + GetRowSegment(0)->HalfSizeY();
243 //_____________________________________________________________________________
244 AliMpVPadIterator* AliMpRow::CreateIterator() const
246 /// Iterator is not implemented.
248 Fatal("CreateIterator", "Iterator is not implemented.");
253 //_____________________________________________________________________________
254 void AliMpRow::SetMotifPositions()
256 /// Create motif positions objects and fills them in the motif map.
260 for (Int_t j=0; j<GetNofRowSegments(); j++) {
261 AliMpVRowSegment* rowSegment = GetRowSegment(j);
263 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
265 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
266 AliMpVMotif* motif = rowSegment->GetMotif(k);
267 TVector2 position = rowSegment->MotifCenter(motifPositionId);
269 AliMpMotifPosition* motifPosition
270 = new AliMpMotifPosition(motifPositionId, motif, position);
271 // set the initial value to of HighIndicesLimit() Invalid()
272 // (this is used for calculation of indices in case of
273 // special row segments)
274 motifPosition->SetHighIndicesLimit(AliMpIntPair::Invalid());
276 //Bool_t warn = (rowSegment->GetNofMotifs()==1);
278 if (dynamic_cast<AliMpVRowSegmentSpecial*>(rowSegment)) warn = false;
279 // supress warnings for special row segments
280 // which motifs can overlap the row borders
282 Bool_t added = GetMotifMap()->AddMotifPosition(motifPosition, warn);
284 if (!added) delete motifPosition;
289 //_____________________________________________________________________________
290 void AliMpRow::SetGlobalIndices(AliMp::Direction constPadSizeDirection,
293 /// Set the global indices limits to its row segments, motif positions
296 Int_t ix = AliMpConstants::StartPadIndex();
297 Int_t iy = AliMpConstants::StartPadIndex();
299 for (Int_t j=0; j<GetNofRowSegments(); j++) {
300 AliMpVRowSegment* rowSegment = GetRowSegment(j);
302 ix += rowSegment->GetLowIndicesLimit().GetFirst();
304 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
306 // Find the y index value of the low edge
308 if (constPadSizeDirection == AliMp::kY) {
309 iy = rowBefore->GetHighIndicesLimit().GetSecond()+1;
312 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ix);
313 AliMpMotifPosition* motPos = FindMotifPosition(seg, ix);
314 if (!dynamic_cast<AliMpRowSegmentRSpecial*>(rowSegment)) {
316 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
318 iy = motPos->GetHighIndicesLimit().GetSecond()+1;
323 // Set (ix, iy) to k-th motif position and update ix
324 ix = rowSegment->SetIndicesToMotifPosition(k, AliMpIntPair(ix, iy));
326 rowSegment->SetGlobalIndices(rowBefore);
329 // The low/high indices limits has to be taken as the highest/lowest from all
333 Int_t ixh = AliMpConstants::StartPadIndex();
334 Int_t iyh = AliMpConstants::StartPadIndex();
336 for (Int_t i=0; i<GetNofRowSegments(); i++) {
338 AliMpVRowSegment* rowSegment = GetRowSegment(i);
340 if ( rowSegment->GetLowIndicesLimit().GetFirst() < ixl )
341 ixl = rowSegment->GetLowIndicesLimit().GetFirst();
343 if ( rowSegment->GetLowIndicesLimit().GetSecond() < iyl )
344 iyl = rowSegment->GetLowIndicesLimit().GetSecond();
346 if ( rowSegment->GetHighIndicesLimit().GetFirst() > ixh )
347 ixh = rowSegment->GetHighIndicesLimit().GetFirst();
349 if ( rowSegment->GetHighIndicesLimit().GetSecond() > iyh )
350 iyh = rowSegment->GetHighIndicesLimit().GetSecond();
353 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
354 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));
357 //_____________________________________________________________________________
358 TVector2 AliMpRow::Position() const
360 /// Return the position of the row centre.
362 Double_t x = (GetRowSegment(0)->LeftBorderX() +
363 GetRowSegment(GetNofRowSegments()-1)->RightBorderX())/2.;
365 Double_t y = fOffsetY;
367 return TVector2(x, y);
370 //_____________________________________________________________________________
371 TVector2 AliMpRow::Dimensions() const
373 /// Return the maximum halflengths of the row in x, y.
375 Double_t x = (GetRowSegment(GetNofRowSegments()-1)->RightBorderX() -
376 GetRowSegment(0)->LeftBorderX())/2.;
378 Double_t y = GetRowSegment(0)->HalfSizeY();
380 return TVector2(x, y);
383 //_____________________________________________________________________________
384 void AliMpRow::SetRowSegmentOffsets(const TVector2& offset)
386 /// Set the row segments offsets in X .
390 AliMpVRowSegment* previous = 0;
392 for (Int_t j=0; j<GetNofRowSegments(); j++) {
393 AliMpVRowSegment* rowSegment = GetRowSegment(j);
397 offsetX = previous->RightBorderX();
399 offsetX = offset.X();
401 rowSegment->SetOffset(TVector2(offsetX, 0.));
402 previous = rowSegment;
407 //_____________________________________________________________________________
408 Double_t AliMpRow::SetOffsetY(Double_t offsetY)
410 /// Set the row offset (the Y coordinate of the position of the
411 /// center of motif) and returns the offset of the top border.
415 AliMpVRowSegment* first = GetRowSegment(0);
416 Double_t rowSizeY = first->HalfSizeY();
418 // Check if all next row segments have motif of
419 // the same size in y
420 for (Int_t i=1; i<GetNofRowSegments(); i++) {
421 Double_t sizeY = GetRowSegment(i)->HalfSizeY();
423 if (TMath::Abs(sizeY - rowSizeY) >= AliMpConstants::LengthTolerance()) {
424 Fatal("SetOffsetY", "Motif with different Y size in one row");
429 offsetY += rowSizeY ;
433 return offsetY += rowSizeY;
436 //_____________________________________________________________________________
437 Int_t AliMpRow::GetNofRowSegments() const
439 /// Return number of row segments.
442 return fSegments.size();
446 return fSegments.GetSize();
450 //_____________________________________________________________________________
451 AliMpVRowSegment* AliMpRow::GetRowSegment(Int_t i) const
453 /// Return i-th row segment.
455 if (i<0 || i>=GetNofRowSegments()) {
456 AliWarningStream() << "Index outside range" << endl;
465 return (AliMpVRowSegment*)fSegments.At(i);