6 // Class describing a row composed of the row segments.
8 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
10 #include <Riostream.h>
15 #include "AliMpVRowSegment.h"
16 #include "AliMpRowSegmentSpecial.h"
17 #include "AliMpVMotif.h"
18 #include "AliMpMotifType.h"
19 #include "AliMpMotifPosition.h"
20 #include "AliMpMotifMap.h"
21 #include "AliMpConstants.h"
25 //_____________________________________________________________________________
26 AliMpRow::AliMpRow(Int_t id, AliMpMotifMap* motifMap)
36 //_____________________________________________________________________________
47 //_____________________________________________________________________________
48 AliMpRow::~AliMpRow() {
51 for (Int_t i=0; i<GetNofRowSegments(); i++)
59 //_____________________________________________________________________________
60 AliMpVRowSegment* AliMpRow::FindRowSegment(Int_t ix) const
62 // Finds first normal row segment with low indices limit >= ix.
65 for (Int_t i=0; i<GetNofRowSegments(); i++) {
66 AliMpVRowSegment* segment = GetRowSegment(i);
68 if (!dynamic_cast<AliMpRowSegmentSpecial*>(segment) &&
69 segment->GetHighIndicesLimit().GetFirst() >= ix)
77 //_____________________________________________________________________________
79 AliMpRow::FindMotifPosition(AliMpVRowSegment* segment, Int_t ix) const
81 // Finds first motif position in the specified row segment
82 // with high indices limit >= ix.
85 if (!segment) return 0;
87 for (Int_t i=0; i<segment->GetNofMotifs(); i++){
88 AliMpMotifPosition* motifPosition
89 = GetMotifMap()->FindMotifPosition(segment->GetMotifPositionId(i));
92 Fatal("FindMotifPosition", "Not found.");
96 if (motifPosition->GetHighIndicesLimit().GetFirst()>=ix)
104 //_____________________________________________________________________________
105 void AliMpRow::SetHighIndicesLimits(Int_t iy)
107 // Sets the global indices high limit to its row segments,
108 // motif positions with a given value.
109 // Keeps ix unmodified.
112 for (Int_t j=0; j<GetNofRowSegments(); j++) {
113 AliMpVRowSegment* rowSegment = GetRowSegment(j);
115 ->SetHighIndicesLimit(
116 AliMpIntPair(rowSegment->GetHighIndicesLimit().GetFirst(),iy));
118 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
120 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
121 AliMpMotifPosition* motifPosition
122 = GetMotifMap()->FindMotifPosition(motifPositionId);
125 ->SetHighIndicesLimit(
126 AliMpIntPair(motifPosition->GetHighIndicesLimit().GetFirst(), iy));
132 //_____________________________________________________________________________
133 void AliMpRow::CheckEmpty() const
135 // Give a fatal if row is empty.
138 if (GetNofRowSegments() == 0)
139 Fatal("CheckEmpty", "Empty row");
146 //_____________________________________________________________________________
147 void AliMpRow::AddRowSegment(AliMpVRowSegment* rowSegment)
149 // Adds row segment at the end.
152 fSegments.push_back(rowSegment);
155 //_____________________________________________________________________________
156 void AliMpRow::AddRowSegmentInFront(AliMpVRowSegment* rowSegment)
158 // Inserts row segment in the first vector position.
161 fSegments.insert(fSegments.begin(), rowSegment);
164 //_____________________________________________________________________________
165 AliMpVRowSegment* AliMpRow::FindRowSegment(Double_t x) const
167 // Finds the row segment for the specified x position;
168 // returns 0 if no row segment is found.
171 for (Int_t i=0; i<GetNofRowSegments(); i++) {
172 AliMpVRowSegment* rs = fSegments[i];
173 if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
180 //_____________________________________________________________________________
181 Double_t AliMpRow::LowBorderY() const
183 // Returns the lowest row offset (the Y coordinate of the position of the
184 // low border of motif).
189 return fOffsetY - GetRowSegment(0)->HalfSizeY();
192 //_____________________________________________________________________________
193 Double_t AliMpRow::UpperBorderY() const
195 // Returns the uppermost row offset (the Y coordinate of the position of the
196 // upper border of motif).
201 return fOffsetY + GetRowSegment(0)->HalfSizeY();
204 //_____________________________________________________________________________
205 AliMpVPadIterator* AliMpRow::CreateIterator() const
207 // Iterator is not yet implemented.
210 Fatal("CreateIterator", "Iterator is not yet implemented.");
215 //_____________________________________________________________________________
216 void AliMpRow::SetMotifPositions()
218 // Creates motif positions objects and fills them in the motif map.
223 for (Int_t j=0; j<GetNofRowSegments(); j++) {
224 AliMpVRowSegment* rowSegment = GetRowSegment(j);
226 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
228 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
229 AliMpVMotif* motif = rowSegment->GetMotif(k);
230 TVector2 position = rowSegment->MotifCenter(motifPositionId);
232 AliMpMotifPosition* motifPosition
233 = new AliMpMotifPosition(motifPositionId, motif, position);
234 // set the initial value to of HighIndicesLimit() Invalid()
235 // (this is used for calculation of indices in case of
236 // special row segments)
237 motifPosition->SetHighIndicesLimit(AliMpIntPair::Invalid());
239 Bool_t warn = (rowSegment->GetNofMotifs()==1);
240 // supress warnings for special row segments
241 // which motifs can overlap the row borders
243 Bool_t added = GetMotifMap()->AddMotifPosition(motifPosition, warn);
245 if (!added) delete motifPosition;
250 //_____________________________________________________________________________
251 void AliMpRow::SetGlobalIndices(AliMpDirection constPadSizeDirection,
254 // Sets the global indices limits to its row segments,
258 Int_t ix = AliMpConstants::StartPadIndex();
259 Int_t iy = AliMpConstants::StartPadIndex();
261 for (Int_t j=0; j<GetNofRowSegments(); j++) {
262 AliMpVRowSegment* rowSegment = GetRowSegment(j);
264 ix += rowSegment->GetLowIndicesLimit().GetFirst();
266 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
268 // Find the y index value of the low edge
270 if (constPadSizeDirection == kY) {
271 iy = rowBefore->GetHighIndicesLimit().GetSecond()+1;
274 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ix);
275 AliMpMotifPosition* motPos = FindMotifPosition(seg, ix);
277 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
279 iy = motPos->GetHighIndicesLimit().GetSecond()+1;
283 // Set (ix, iy) to k-th motif position and update ix
284 ix = rowSegment->SetIndicesToMotifPosition(k, AliMpIntPair(ix, iy));
286 rowSegment->SetGlobalIndices();
289 SetLowIndicesLimit(GetRowSegment(0)->GetLowIndicesLimit());
290 SetHighIndicesLimit(GetRowSegment(GetNofRowSegments()-1)->GetHighIndicesLimit());
295 //_____________________________________________________________________________
296 TVector2 AliMpRow::Position() const
298 // Returns the position of the row centre.
301 Double_t x = (GetRowSegment(0)->LeftBorderX() +
302 GetRowSegment(GetNofRowSegments()-1)->RightBorderX())/2.;
304 Double_t y = fOffsetY;
306 return TVector2(x, y);
309 //_____________________________________________________________________________
310 TVector2 AliMpRow::Dimensions() const
312 // Returns the maximum halflengths of the row in x, y.
315 Double_t x = (GetRowSegment(GetNofRowSegments()-1)->RightBorderX() -
316 GetRowSegment(0)->LeftBorderX())/2.;
318 Double_t y = GetRowSegment(0)->HalfSizeY();
320 return TVector2(x, y);
323 //_____________________________________________________________________________
324 void AliMpRow::SetRowSegmentOffsets(const TVector2& offset)
326 // Sets the row segments offsets in X .
331 AliMpVRowSegment* previous = 0;
333 for (Int_t j=0; j<GetNofRowSegments(); j++) {
334 AliMpVRowSegment* rowSegment = GetRowSegment(j);
338 offsetX = previous->RightBorderX();
340 offsetX = offset.X();
342 rowSegment->SetOffset(TVector2(offsetX, 0.));
343 previous = rowSegment;
348 //_____________________________________________________________________________
349 Double_t AliMpRow::SetOffsetY(Double_t offsetY)
351 // Sets the row offset (the Y coordinate of the position of the
352 // center of motif) and returns the offset of the top border.
357 AliMpVRowSegment* first = GetRowSegment(0);
358 Double_t rowSizeY = first->HalfSizeY();
360 // Check if all next row segments have motif of
361 // the same size in y
362 for (Int_t i=1; i<GetNofRowSegments(); i++) {
363 Double_t sizeY = GetRowSegment(i)->HalfSizeY();
365 if (TMath::Abs(sizeY - rowSizeY) >= AliMpConstants::LengthTolerance()) {
366 cout << GetID() << "th row " << i << "th segment "
367 << sizeY << " " << rowSizeY << endl;
368 Fatal("SetOffsetY", "Motif with different Y size in one row");
373 offsetY += rowSizeY ;
377 return offsetY += rowSizeY;
380 //_____________________________________________________________________________
381 Int_t AliMpRow::GetNofRowSegments() const
383 // Returns number of row segments.
385 return fSegments.size();
388 //_____________________________________________________________________________
389 AliMpVRowSegment* AliMpRow::GetRowSegment(Int_t i) const
391 if (i<0 || i>=GetNofRowSegments()) {
392 Warning("GetRowSegment", "Index outside range");