4 // Class AliMpRowSegmentSpecial
5 // ----------------------------
6 // Class describing a special row segment composed of the
9 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
13 #include "AliMpRowSegmentSpecial.h"
15 #include "AliMpPadRow.h"
16 #include "AliMpPadRowSegment.h"
17 #include "AliMpMotif.h"
18 #include "AliMpMotifType.h"
19 #include "AliMpMotifMap.h"
20 #include "AliMpMotifPosition.h"
21 #include "AliMpConstants.h"
23 ClassImp(AliMpRowSegmentSpecial)
25 //______________________________________________________________________________
26 AliMpRowSegmentSpecial::AliMpRowSegmentSpecial(AliMpRow* row, Double_t offsetX)
37 //______________________________________________________________________________
38 AliMpRowSegmentSpecial::AliMpRowSegmentSpecial()
49 //______________________________________________________________________________
50 AliMpRowSegmentSpecial::~AliMpRowSegmentSpecial()
53 for (Int_t i=0; i<GetNofPadRows(); i++)
61 //______________________________________________________________________________
62 Int_t AliMpRowSegmentSpecial::GetNofPadRows() const
64 // Returns number of pad rows.
67 return fPadRows.size();
70 //______________________________________________________________________________
71 AliMpPadRow* AliMpRowSegmentSpecial::GetPadRow(Int_t i) const
73 // Returns number of pad rows.
79 //______________________________________________________________________________
80 Int_t AliMpRowSegmentSpecial::MaxNofPadsInRow() const
82 // Returns the maximum number of pads in this row segment along the X direction
87 for (Int_t i=0; i<GetNofPadRows(); i++){
88 Int_t nofPads = GetPadRow(i)->GetNofPads();
91 if (nofPads > maxNofPads) maxNofPads = nofPads;
97 //______________________________________________________________________________
98 AliMpPadRow* AliMpRowSegmentSpecial::FindPadRow(Double_t y) const
100 // Finds the pad row in the given y coordinate.
103 Double_t lowBorder = fRow->LowBorderY();
104 Double_t highBorder = fRow->LowBorderY();
106 for (Int_t i=0; i<GetNofPadRows(); i++) {
108 AliMpPadRow* padRow = GetPadRow(i);
109 highBorder += 2.*padRow->HalfSizeY();
111 if ( y >= lowBorder && y <= highBorder)
114 lowBorder = highBorder;
120 //______________________________________________________________________________
122 AliMpRowSegmentSpecial::FindPadRowSegment(Int_t motifPositionId) const
124 // Find the most down pad row segment with this motifPositionId.
127 for (Int_t i=0; i<GetNofPadRows(); i++) {
128 AliMpPadRow* padRow = GetPadRow(i);
130 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
131 AliMpPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
133 if (padRowSegment->GetMotifPositionId() == motifPositionId)
134 return padRowSegment;
140 //______________________________________________________________________________
142 AliMpRowSegmentSpecial::FindMostRightPadRowSegment(Int_t motifPositionId) const
144 // Find the most left pad row segment with this motifPositionId.
147 AliMpPadRowSegment* found = 0;
149 for (Int_t i=0; i<GetNofPadRows(); i++) {
150 AliMpPadRow* padRow = GetPadRow(i);
152 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
153 AliMpPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
155 if ( padRowSegment->GetMotifPositionId() == motifPositionId &&
156 (!found || padRowSegment->RightBorderX() > found->RightBorderX()))
158 found = padRowSegment;
165 //______________________________________________________________________________
167 AliMpRowSegmentSpecial::FindRelativeLowIndicesOf(Int_t motifPositionId) const
169 // Returns the lowest pad indices where the motif of the given position ID
170 // exists in this segment.
173 AliMpIntPair ans(0,1000);
174 AliMpIntPair ans0 = ans;
177 for (Int_t i=0; i<GetNofPadRows(); i++) {
178 AliMpPadRow* padRow = GetPadRow(i);
181 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
182 AliMpPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
183 nofPadsX += padRowSegment->GetNofPads();
184 if (padRowSegment->GetMotifPositionId() == motifPositionId) {
185 if (ans.GetFirst() < nofPadsX) ans.SetFirst(nofPadsX);
186 if (ans.GetSecond()>i) ans.SetSecond(i);
187 // ans.First = max (nof pads of this pos ID)
188 // ans.Second = min of pad row number
191 if (nofPadsX > maxNofPadsX) maxNofPadsX = nofPadsX;
193 if (ans == ans0) return AliMpIntPair::Invalid();
195 return AliMpIntPair(maxNofPadsX-ans.GetFirst(), ans.GetSecond());
198 //______________________________________________________________________________
199 TVector2 AliMpRowSegmentSpecial::MotifCenterSlow(Int_t motifPositionId) const
201 // Returns the coordinates of the motif specified with
202 // the given position identifier.
203 // !! Applicable only for motifs that have their most down pad in
207 // Find the first (left, down) pad row segment with this motifPositionId.
208 AliMpPadRowSegment* downPadRowSegment
209 = FindPadRowSegment(motifPositionId);
210 AliMpPadRowSegment* rightPadRowSegment
211 = FindMostRightPadRowSegment(motifPositionId);
213 // Check if the motifPositionId is present
214 if (!downPadRowSegment || !rightPadRowSegment) {
215 Error("MotifCenter", "Outside row segment region");
219 // Check if both pad row segments have the same motif
220 if (downPadRowSegment->GetMotif() != rightPadRowSegment->GetMotif()) {
221 Fatal("MotifCenter", "Outside row segment region");
225 // Get position of found row segment
226 Double_t x = rightPadRowSegment->RightBorderX();
227 Double_t y = fRow->LowBorderY() ;
229 for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
230 y += GetPadRow(i)->HalfSizeY()*2.;
232 // Add motifs dimensions
233 x -= downPadRowSegment->GetMotif()->Dimensions().X();
234 y += downPadRowSegment->GetMotif()->Dimensions().Y();
236 return TVector2(x, y);
239 //______________________________________________________________________________
240 Bool_t AliMpRowSegmentSpecial::HasMotif(const AliMpVMotif* motif) const
242 // Returns true if the specified motif is already in fMotifs vector,
243 // returns false otherwise.
246 for (UInt_t i=0; i<fMotifs.size(); i++)
247 if (fMotifs[i] == motif) return true;
256 //______________________________________________________________________________
257 void AliMpRowSegmentSpecial::AddPadRow(AliMpPadRow* padRow)
262 padRow->SetID(GetNofPadRows());
263 padRow->SetOffsetX(fOffsetX);
265 fPadRows.push_back(padRow);
268 //______________________________________________________________________________
269 void AliMpRowSegmentSpecial::UpdateMotifVector()
271 // Add motifs associated with the pad row segments in the specified
272 // pad row in the fMotifs vector.
275 for (Int_t i=0; i<GetNofPadRows(); i++) {
276 AliMpPadRow* padRow = GetPadRow(i);
278 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
279 AliMpVMotif* motif = padRow->GetPadRowSegment(j)->GetMotif();
281 if (!HasMotif(motif)) {
282 fMotifs.push_back(motif);
283 fMotifPositionIds.push_back(
284 padRow->GetPadRowSegment(j)->GetMotifPositionId());
290 //______________________________________________________________________________
291 void AliMpRowSegmentSpecial::UpdatePadsOffset()
293 // Sets low indices limit to the pad offset calculated
294 // from the neighbour normal segment.
297 // Get the neighbour row segment
298 // (the first normal segment)
299 AliMpVRowSegment* neighbour = fRow->GetRowSegment(1);
301 // Get the the pads offset of the neighbour row segment
302 // (the first normal segment)
303 AliMpIntPair offset = neighbour->GetLowIndicesLimit();
305 // Find max nof pads in a row
306 Int_t maxNofPads = MaxNofPadsInRow();
309 SetLowIndicesLimit(offset - AliMpIntPair(maxNofPads, 0));
311 // Reset limits in the neighbour row segment
312 // (pad offset is now included in the special segment)
313 neighbour->SetLowIndicesLimit(
314 AliMpIntPair(0, neighbour->GetLowIndicesLimit().GetSecond()));
317 //______________________________________________________________________________
318 Double_t AliMpRowSegmentSpecial::LeftBorderX() const
320 // Returns the x coordinate of the left row segment border
321 // in global coordinate system.
324 Double_t leftBorder = DBL_MAX;
325 for (Int_t i=0; i<GetNofPadRows(); i++) {
326 AliMpPadRow* padRow = GetPadRow(i);
328 = padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX();
330 if (border < leftBorder) leftBorder = border;
336 //______________________________________________________________________________
337 Double_t AliMpRowSegmentSpecial::RightBorderX() const
339 // Returns the x coordinate of the right row segment border
340 // in global coordinate system.
343 Double_t sameBorder = fOffsetX;
346 Double_t rightBorder = -DBL_MAX;
347 for (Int_t i=0; i<GetNofPadRows(); i++) {
348 AliMpPadRow* padRow = GetPadRow(i);
349 Double_t border = padRow->GetPadRowSegment(0)->RightBorderX();
350 if (border > rightBorder) rightBorder = border;
353 if (TMath::Abs(fOffsetX - rightBorder) > 1.e-04) {
354 Error("RightBorderX", "WrongBorder");
361 //______________________________________________________________________________
362 Double_t AliMpRowSegmentSpecial::HalfSizeY() const
364 // Returns the size in y of this row segment.
367 Double_t halfSizeY = 0.;
368 for (Int_t i=0; i<GetNofPadRows(); i++) {
369 halfSizeY += GetPadRow(i)->HalfSizeY();
375 //______________________________________________________________________________
376 AliMpVMotif* AliMpRowSegmentSpecial::FindMotif(const TVector2& position) const
378 // Returns the motif of this row;
382 = FindPadRow(position.Y());
384 if (!padRow) return 0;
386 AliMpPadRowSegment* padRowSegment
387 = padRow->FindPadRowSegment(position.X());
389 if (!padRowSegment) return 0;
391 return padRowSegment->GetMotif();
394 //______________________________________________________________________________
395 Int_t AliMpRowSegmentSpecial::FindMotifPositionId(const TVector2& position) const
397 // Returns the motif position identified for the given
398 // geometric position.
402 = FindPadRow(position.Y());
404 if (!padRow) return 0;
406 AliMpPadRowSegment* padRowSegment
407 = padRow->FindPadRowSegment(position.X());
409 if (!padRowSegment) return 0;
411 return padRowSegment->GetMotifPositionId();
414 //______________________________________________________________________________
415 Bool_t AliMpRowSegmentSpecial::HasMotifPosition(Int_t motifPositionId) const
417 // Returns true if the motif specified with the given position identifier
418 // is in this segment.
421 if (FindPadRowSegment(motifPositionId))
427 //______________________________________________________________________________
428 TVector2 AliMpRowSegmentSpecial::MotifCenter(Int_t motifPositionId) const
430 // Returns the coordinates of the motif specified with
431 // the given position identifier.
434 // Try to get the motif position from the motif map first
435 AliMpMotifPosition* motifPosition
436 = GetRow()->GetMotifMap()->FindMotifPosition(motifPositionId);
437 if (motifPosition) return motifPosition->Position();
439 // Use slow method otherwise
440 return MotifCenterSlow(motifPositionId);
443 //______________________________________________________________________________
444 TVector2 AliMpRowSegmentSpecial::Position() const
446 // Returns the position of the row segment centre.
447 // The centre is defined as the centre of the rectangular
448 // row segment envelope.
451 Double_t x = fOffsetX - Dimensions().X();
452 Double_t y = fRow->Position().Y();
454 return TVector2(x, y);
458 //______________________________________________________________________________
459 TVector2 AliMpRowSegmentSpecial::Dimensions() const
461 // Returns the halflengths in x, y of the row segment rectangular envelope.
466 for (Int_t i=0; i<GetNofPadRows(); i++) {
467 AliMpPadRow* padRow = GetPadRow(i);
469 // Add all pad rows y halfsizes
470 y += padRow->HalfSizeY();
472 // Find the biggest pad rows x halfsize
474 = (padRow->GetPadRowSegment(0)->RightBorderX() -
475 padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX())/2.;
479 return TVector2(x, y);
482 //______________________________________________________________________________
483 void AliMpRowSegmentSpecial::SetGlobalIndices()
485 // Sets indices limits.
488 AliMpMotifPosition* firstPos = 0;
489 AliMpMotifPosition* lastPos = 0;
491 for (Int_t i=0;i<GetNofMotifs();i++) {
492 AliMpMotifPosition* mPos
493 = GetRow()->GetMotifMap()
494 ->FindMotifPosition(GetMotifPositionId(i));
497 mPos->GetLowIndicesLimit().GetFirst()
498 < firstPos->GetLowIndicesLimit().GetFirst())
502 mPos->GetHighIndicesLimit().GetFirst()
503 >lastPos->GetHighIndicesLimit().GetFirst())
507 // Check if the motif positions has the limits set
508 if ( !firstPos->HasValidIndices() || !lastPos->HasValidIndices())
509 Fatal("SetGlobalIndices", "Indices of motif positions have to be set first.");
511 SetLowIndicesLimit(firstPos->GetLowIndicesLimit());
512 SetHighIndicesLimit(lastPos->GetHighIndicesLimit());
515 //______________________________________________________________________________
516 Int_t AliMpRowSegmentSpecial::SetIndicesToMotifPosition(
517 Int_t i, AliMpIntPair indices)
519 // Sets global indices to i-th motif position and returns next index in x.
522 // Get motif position
523 AliMpMotifPosition* motifPosition
524 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
528 = AliMpIntPair(GetLowIndicesLimit().GetFirst() + AliMpConstants::StartPadIndex(),
530 + FindRelativeLowIndicesOf(GetMotifPositionId(i));
532 if (! motifPosition->GetHighIndicesLimit().IsValid()) {
533 motifPosition->SetLowIndicesLimit(low);
536 if (motifPosition->GetLowIndicesLimit().GetFirst() > low.GetFirst())
537 motifPosition->SetLowIndicesLimit(
538 AliMpIntPair(low.GetFirst(),
539 motifPosition->GetLowIndicesLimit().GetSecond()));
541 if (motifPosition->GetLowIndicesLimit().GetSecond() > low.GetSecond())
542 motifPosition->SetLowIndicesLimit(
543 AliMpIntPair(motifPosition->GetLowIndicesLimit().GetFirst(),
548 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
550 = motifPosition->GetLowIndicesLimit()
551 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
552 motifPosition->SetHighIndicesLimit(high);
554 // Increment index only if last motif position is processed
555 if (i != GetNofMotifs()-1)
556 return indices.GetFirst();
559 return indices.GetFirst() + MaxNofPadsInRow();
560 //return MaxNofPadsInRow();
563 //______________________________________________________________________________
564 AliMpRow* AliMpRowSegmentSpecial::GetRow() const
566 // Returns the row.which this row segment belongs to.
572 //______________________________________________________________________________
573 Int_t AliMpRowSegmentSpecial::GetNofMotifs() const
575 // Returns the number of different motifs present in this row segment.
578 return fMotifs.size();
581 //______________________________________________________________________________
582 AliMpVMotif* AliMpRowSegmentSpecial::GetMotif(Int_t i) const
584 // Returns the i-th motif present in this row segment.
590 //______________________________________________________________________________
591 Int_t AliMpRowSegmentSpecial::GetMotifPositionId(Int_t i) const
593 // Returns the i-th motif position Id present in this row segment.
596 return fMotifPositionIds[i];