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.7 2005/08/26 15:43:36 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
26 #include <Riostream.h>
31 #include "AliMpVRowSegment.h"
32 #include "AliMpVRowSegmentSpecial.h"
33 #include "AliMpRowSegmentRSpecial.h"
34 #include "AliMpVMotif.h"
35 #include "AliMpMotifType.h"
36 #include "AliMpMotifPosition.h"
37 #include "AliMpMotifMap.h"
38 #include "AliMpConstants.h"
42 //_____________________________________________________________________________
43 AliMpRow::AliMpRow(Int_t id, AliMpMotifMap* motifMap)
50 /// Standard constructor
53 //_____________________________________________________________________________
61 /// Default constructor
64 //_____________________________________________________________________________
65 AliMpRow::AliMpRow(const AliMpRow& right)
66 : AliMpVIndexed(right)
68 /// Protected copy constructor (not provided)
70 Fatal("AliMpRow", "Copy constructor not provided.");
73 //_____________________________________________________________________________
79 for (Int_t i=0; i<GetNofRowSegments(); i++)
92 //_____________________________________________________________________________
93 AliMpRow& AliMpRow::operator=(const AliMpRow& right)
95 /// Protected assignment operator (not provided)
97 // check assignment to self
98 if (this == &right) return *this;
100 Fatal("operator =", "Assignment operator not provided.");
109 //_____________________________________________________________________________
110 AliMpVRowSegment* AliMpRow::FindRowSegment(Int_t ix) const
112 /// Find first normal row segment with low indices limit >= ix.
114 for (Int_t i=0; i<GetNofRowSegments(); i++) {
115 AliMpVRowSegment* segment = GetRowSegment(i);
117 if (!dynamic_cast<AliMpVRowSegmentSpecial*>(segment) &&
118 segment->GetHighIndicesLimit().GetFirst() >= ix)
126 //_____________________________________________________________________________
128 AliMpRow::FindMotifPosition(AliMpVRowSegment* segment, Int_t ix) const
130 /// Find first motif position in the specified row segment
131 /// with high indices limit >= ix.
133 if (!segment) return 0;
135 for (Int_t i=0; i<segment->GetNofMotifs(); i++){
136 AliMpMotifPosition* motifPosition
137 = GetMotifMap()->FindMotifPosition(segment->GetMotifPositionId(i));
140 Fatal("FindMotifPosition", "Not found.");
144 if (motifPosition->GetHighIndicesLimit().GetFirst()>=ix)
145 return motifPosition;
152 //_____________________________________________________________________________
153 void AliMpRow::SetHighIndicesLimits(Int_t iy)
155 /// Set the global indices high limit to its row segments,
156 /// motif positions with a given value.
157 /// Keep ix unmodified.
159 for (Int_t j=0; j<GetNofRowSegments(); j++) {
160 AliMpVRowSegment* rowSegment = GetRowSegment(j);
162 ->SetHighIndicesLimit(
163 AliMpIntPair(rowSegment->GetHighIndicesLimit().GetFirst(),iy));
165 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
167 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
168 AliMpMotifPosition* motifPosition
169 = GetMotifMap()->FindMotifPosition(motifPositionId);
172 ->SetHighIndicesLimit(
173 AliMpIntPair(motifPosition->GetHighIndicesLimit().GetFirst(), iy));
179 //_____________________________________________________________________________
180 void AliMpRow::CheckEmpty() const
182 /// Give a fatal if the row is empty.
184 if (GetNofRowSegments() == 0)
185 Fatal("CheckEmpty", "Empty row");
192 //_____________________________________________________________________________
193 void AliMpRow::AddRowSegment(AliMpVRowSegment* rowSegment)
195 /// Add row segment at the end.
198 fSegments.push_back(rowSegment);
202 fSegments.Add(rowSegment);
206 //_____________________________________________________________________________
207 void AliMpRow::AddRowSegmentInFront(AliMpVRowSegment* rowSegment)
209 /// Insert row segment in the first vector position.
212 fSegments.insert(fSegments.begin(), rowSegment);
216 fSegments.AddFirst(rowSegment);
220 //_____________________________________________________________________________
221 AliMpVRowSegment* AliMpRow::FindRowSegment(Double_t x) const
223 /// Find the row segment for the specified x position;
224 /// return 0 if no row segment is found.
226 for (Int_t i=0; i<GetNofRowSegments(); i++) {
229 AliMpVRowSegment* rs = fSegments[i];
232 AliMpVRowSegment* rs = (AliMpVRowSegment*)fSegments.At(i);
235 if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
242 //_____________________________________________________________________________
243 Double_t AliMpRow::LowBorderY() const
245 /// Return the lowest row offset (the Y coordinate of the position of the
246 /// low border of motif).
250 return fOffsetY - GetRowSegment(0)->HalfSizeY();
253 //_____________________________________________________________________________
254 Double_t AliMpRow::UpperBorderY() const
256 /// Return the uppermost row offset (the Y coordinate of the position of the
257 /// upper border of motif).
261 return fOffsetY + GetRowSegment(0)->HalfSizeY();
264 //_____________________________________________________________________________
265 AliMpVPadIterator* AliMpRow::CreateIterator() const
267 /// Iterator is not implemented.
269 Fatal("CreateIterator", "Iterator is not implemented.");
274 //_____________________________________________________________________________
275 void AliMpRow::SetMotifPositions()
277 /// Create motif positions objects and fills them in the motif map.
281 for (Int_t j=0; j<GetNofRowSegments(); j++) {
282 AliMpVRowSegment* rowSegment = GetRowSegment(j);
284 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
286 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
287 AliMpVMotif* motif = rowSegment->GetMotif(k);
288 TVector2 position = rowSegment->MotifCenter(motifPositionId);
290 AliMpMotifPosition* motifPosition
291 = new AliMpMotifPosition(motifPositionId, motif, position);
292 // set the initial value to of HighIndicesLimit() Invalid()
293 // (this is used for calculation of indices in case of
294 // special row segments)
295 motifPosition->SetHighIndicesLimit(AliMpIntPair::Invalid());
297 //Bool_t warn = (rowSegment->GetNofMotifs()==1);
299 if (dynamic_cast<AliMpVRowSegmentSpecial*>(rowSegment)) warn = false;
300 // supress warnings for special row segments
301 // which motifs can overlap the row borders
303 Bool_t added = GetMotifMap()->AddMotifPosition(motifPosition, warn);
305 if (!added) delete motifPosition;
310 //_____________________________________________________________________________
311 void AliMpRow::SetGlobalIndices(AliMpDirection constPadSizeDirection,
314 /// Set the global indices limits to its row segments, motif positions
317 Int_t ix = AliMpConstants::StartPadIndex();
318 Int_t iy = AliMpConstants::StartPadIndex();
320 for (Int_t j=0; j<GetNofRowSegments(); j++) {
321 AliMpVRowSegment* rowSegment = GetRowSegment(j);
323 ix += rowSegment->GetLowIndicesLimit().GetFirst();
325 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
327 // Find the y index value of the low edge
329 if (constPadSizeDirection == kY) {
330 iy = rowBefore->GetHighIndicesLimit().GetSecond()+1;
333 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ix);
334 AliMpMotifPosition* motPos = FindMotifPosition(seg, ix);
335 if (!dynamic_cast<AliMpRowSegmentRSpecial*>(rowSegment)) {
337 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
339 iy = motPos->GetHighIndicesLimit().GetSecond()+1;
344 // Set (ix, iy) to k-th motif position and update ix
345 ix = rowSegment->SetIndicesToMotifPosition(k, AliMpIntPair(ix, iy));
347 rowSegment->SetGlobalIndices(rowBefore);
350 // The low/high indices limits has to be taken as the highest/lowest from all
354 Int_t ixh = AliMpConstants::StartPadIndex();
355 Int_t iyh = AliMpConstants::StartPadIndex();
357 for (Int_t i=0; i<GetNofRowSegments(); i++) {
359 AliMpVRowSegment* rowSegment = GetRowSegment(i);
361 if ( rowSegment->GetLowIndicesLimit().GetFirst() < ixl )
362 ixl = rowSegment->GetLowIndicesLimit().GetFirst();
364 if ( rowSegment->GetLowIndicesLimit().GetSecond() < iyl )
365 iyl = rowSegment->GetLowIndicesLimit().GetSecond();
367 if ( rowSegment->GetHighIndicesLimit().GetFirst() > ixh )
368 ixh = rowSegment->GetHighIndicesLimit().GetFirst();
370 if ( rowSegment->GetHighIndicesLimit().GetSecond() > iyh )
371 iyh = rowSegment->GetHighIndicesLimit().GetSecond();
374 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
375 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));
378 //_____________________________________________________________________________
379 TVector2 AliMpRow::Position() const
381 /// Return the position of the row centre.
383 Double_t x = (GetRowSegment(0)->LeftBorderX() +
384 GetRowSegment(GetNofRowSegments()-1)->RightBorderX())/2.;
386 Double_t y = fOffsetY;
388 return TVector2(x, y);
391 //_____________________________________________________________________________
392 TVector2 AliMpRow::Dimensions() const
394 /// Return the maximum halflengths of the row in x, y.
396 Double_t x = (GetRowSegment(GetNofRowSegments()-1)->RightBorderX() -
397 GetRowSegment(0)->LeftBorderX())/2.;
399 Double_t y = GetRowSegment(0)->HalfSizeY();
401 return TVector2(x, y);
404 //_____________________________________________________________________________
405 void AliMpRow::SetRowSegmentOffsets(const TVector2& offset)
407 /// Set the row segments offsets in X .
411 AliMpVRowSegment* previous = 0;
413 for (Int_t j=0; j<GetNofRowSegments(); j++) {
414 AliMpVRowSegment* rowSegment = GetRowSegment(j);
418 offsetX = previous->RightBorderX();
420 offsetX = offset.X();
422 rowSegment->SetOffset(TVector2(offsetX, 0.));
423 previous = rowSegment;
428 //_____________________________________________________________________________
429 Double_t AliMpRow::SetOffsetY(Double_t offsetY)
431 /// Set the row offset (the Y coordinate of the position of the
432 /// center of motif) and returns the offset of the top border.
436 AliMpVRowSegment* first = GetRowSegment(0);
437 Double_t rowSizeY = first->HalfSizeY();
439 // Check if all next row segments have motif of
440 // the same size in y
441 for (Int_t i=1; i<GetNofRowSegments(); i++) {
442 Double_t sizeY = GetRowSegment(i)->HalfSizeY();
444 if (TMath::Abs(sizeY - rowSizeY) >= AliMpConstants::LengthTolerance()) {
445 //cout << GetID() << "th row " << i << "th segment "
446 // << sizeY << " " << rowSizeY << endl;
447 Fatal("SetOffsetY", "Motif with different Y size in one row");
452 offsetY += rowSizeY ;
456 return offsetY += rowSizeY;
459 //_____________________________________________________________________________
460 Int_t AliMpRow::GetNofRowSegments() const
462 /// Return number of row segments.
465 return fSegments.size();
469 return fSegments.GetSize();
473 //_____________________________________________________________________________
474 AliMpVRowSegment* AliMpRow::GetRowSegment(Int_t i) const
476 /// Return i-th row segment.
478 if (i<0 || i>=GetNofRowSegments()) {
479 Warning("GetRowSegment", "Index outside range");
488 return (AliMpVRowSegment*)fSegments.At(i);