4 // Class AliMpRowSegmentRSpecial
5 // -----------------------------
6 // Class describing a special outer row segment composed of the
8 // Included in AliRoot: 2003/05/02
9 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
12 #include <Riostream.h>
14 #include "AliMpRowSegmentRSpecial.h"
16 #include "AliMpPadRow.h"
17 #include "AliMpVPadRowSegment.h"
18 #include "AliMpMotif.h"
19 #include "AliMpMotifType.h"
20 #include "AliMpMotifMap.h"
21 #include "AliMpMotifPosition.h"
23 ClassImp(AliMpRowSegmentRSpecial)
25 //______________________________________________________________________________
26 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial(AliMpRow* row, Double_t offsetX)
27 : AliMpVRowSegmentSpecial(row, offsetX)
32 //______________________________________________________________________________
33 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial()
34 : AliMpVRowSegmentSpecial()
39 //______________________________________________________________________________
40 AliMpRowSegmentRSpecial::~AliMpRowSegmentRSpecial()
49 //______________________________________________________________________________
51 AliMpRowSegmentRSpecial::FindMostLeftPadRowSegment(Int_t motifPositionId) const
53 // Find the most left pad row segment with this motifPositionId.
56 AliMpVPadRowSegment* found = 0;
58 for (Int_t i=0; i<GetNofPadRows(); i++) {
59 AliMpPadRow* padRow = GetPadRow(i);
61 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
62 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
64 if ( padRowSegment->GetMotifPositionId() == motifPositionId &&
65 (!found || padRowSegment->LeftBorderX() < found->LeftBorderX()))
67 found = padRowSegment;
74 //______________________________________________________________________________
75 void AliMpRowSegmentRSpecial::SetGlobalIndicesLow()
79 // Last normal row segment in the row
80 // (preceding this special row segment)
81 AliMpVRowSegment* rowSegment
82 = GetRow()->GetRowSegment(GetRow()->GetNofRowSegments()-2);
84 // Set low indices limit to continue indices of the
85 // preceding row segment
86 Int_t ix = rowSegment->GetHighIndicesLimit().GetFirst() + 1;
87 Int_t iy = rowSegment->GetLowIndicesLimit().GetSecond();
89 SetLowIndicesLimit(AliMpIntPair(ix, iy));
96 //______________________________________________________________________________
97 TVector2 AliMpRowSegmentRSpecial::MotifCenterSlow(Int_t motifPositionId) const
99 // Returns the coordinates of the motif specified with
100 // the given position identifier.
101 // !! Applicable only for motifs that have their most down pad in
105 // Find the first (left, down) pad row segment with this motifPositionId.
106 AliMpVPadRowSegment* downPadRowSegment
107 = FindPadRowSegment(motifPositionId);
108 AliMpVPadRowSegment* leftPadRowSegment
109 = FindMostLeftPadRowSegment(motifPositionId);
111 // Check if the motifPositionId is present
112 if (!downPadRowSegment || !leftPadRowSegment) {
113 Error("MotifCenter", "Outside row segment region");
117 // Check if both pad row segments have the same motif
118 if (downPadRowSegment->GetMotif() != leftPadRowSegment->GetMotif()) {
119 Fatal("MotifCenter", "Outside row segment region");
123 // Get position of found row segment
124 Double_t x = leftPadRowSegment->LeftBorderX();
125 Double_t y = GetRow()->LowBorderY() ;
127 for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
128 y += GetPadRow(i)->HalfSizeY()*2.;
130 // Add motifs dimensions
131 x += downPadRowSegment->GetMotif()->Dimensions().X();
132 y += downPadRowSegment->GetMotif()->Dimensions().Y();
134 return TVector2(x, y);
141 //______________________________________________________________________________
142 Double_t AliMpRowSegmentRSpecial::LeftBorderX() const
144 // Returns the x coordinate of the left row segment border
145 // in global coordinate system.
148 // The right edge of the last normal segment
149 Double_t sameBorder = GetOffsetX();
152 Double_t leftBorder = DBL_MAX;
153 for (Int_t i=0; i<GetNofPadRows(); i++) {
154 AliMpPadRow* padRow = GetPadRow(i);
155 Double_t border = padRow->GetPadRowSegment(0)->LeftBorderX();
156 if (border < leftBorder) leftBorder = border;
159 if (TMath::Abs(sameBorder - leftBorder) > 1.e-04) {
160 Error("LeftBorderX", "WrongBorder");
168 //______________________________________________________________________________
169 Double_t AliMpRowSegmentRSpecial::RightBorderX() const
171 // Returns the x coordinate of the right row segment border
172 // in global coordinate system.
175 Double_t rightBorder = -DBL_MAX;
176 for (Int_t i=0; i<GetNofPadRows(); i++) {
177 AliMpPadRow* padRow = GetPadRow(i);
179 = padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)
182 if (border > rightBorder) rightBorder = border;
188 //______________________________________________________________________________
189 TVector2 AliMpRowSegmentRSpecial::Position() const
191 // Returns the position of the row segment centre.
192 // The centre is defined as the centre of the rectangular
193 // row segment envelope.
196 // The right edge of the last normal segment
197 Double_t x = GetOffsetX() + Dimensions().X();
198 Double_t y = GetRow()->Position().Y();
200 return TVector2(x, y);
203 //______________________________________________________________________________
204 Int_t AliMpRowSegmentRSpecial::SetIndicesToMotifPosition(Int_t i,
205 const AliMpIntPair& indices)
207 // Sets global indices to i-th motif position and returns next index in x.
210 // Update low indices limit for this row segment
211 SetGlobalIndicesLow();
213 // Check for consistence
214 if (GetLowIndicesLimit().GetFirst() != indices.GetFirst())
215 Fatal("SetIndicesToMotifPosition", "Inconsistent indices");
217 // Get motif position
218 AliMpMotifPosition* motifPosition
219 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
222 AliMpIntPair low = GetLowIndicesLimit();
224 if (! motifPosition->GetHighIndicesLimit().IsValid()) {
225 motifPosition->SetLowIndicesLimit(low);
228 if (motifPosition->GetLowIndicesLimit().GetFirst() > low.GetFirst())
229 motifPosition->SetLowIndicesLimit(
230 AliMpIntPair(low.GetFirst(),
231 motifPosition->GetLowIndicesLimit().GetSecond()));
233 if (motifPosition->GetLowIndicesLimit().GetSecond() > low.GetSecond())
234 motifPosition->SetLowIndicesLimit(
235 AliMpIntPair(motifPosition->GetLowIndicesLimit().GetFirst(),
240 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
242 = motifPosition->GetLowIndicesLimit()
243 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
244 motifPosition->SetHighIndicesLimit(high);
246 // No increment index needed (this is always the last element)
247 return indices.GetFirst();