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"
22 #include "AliMpConstants.h"
24 ClassImp(AliMpRowSegmentRSpecial)
26 //______________________________________________________________________________
27 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial(AliMpRow* row, Double_t offsetX)
28 : AliMpVRowSegmentSpecial(row, offsetX)
33 //______________________________________________________________________________
34 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial()
35 : AliMpVRowSegmentSpecial()
40 //______________________________________________________________________________
41 AliMpRowSegmentRSpecial::~AliMpRowSegmentRSpecial()
50 //______________________________________________________________________________
52 AliMpRowSegmentRSpecial::FindMostLeftPadRowSegment(Int_t motifPositionId) const
54 // Find the most left pad row segment with this motifPositionId.
57 AliMpVPadRowSegment* found = 0;
59 for (Int_t i=0; i<GetNofPadRows(); i++) {
60 AliMpPadRow* padRow = GetPadRow(i);
62 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
63 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
65 if ( padRowSegment->GetMotifPositionId() == motifPositionId &&
66 (!found || padRowSegment->LeftBorderX() < found->LeftBorderX()))
68 found = padRowSegment;
75 //______________________________________________________________________________
76 void AliMpRowSegmentRSpecial::SetGlobalIndicesLow()
80 // Last normal row segment in the row
81 // (preceding this special row segment)
82 AliMpVRowSegment* rowSegment
83 = GetRow()->GetRowSegment(GetRow()->GetNofRowSegments()-2);
85 // Set low indices limit to continue indices of the
86 // preceding row segment
87 Int_t ix = rowSegment->GetHighIndicesLimit().GetFirst() + 1;
88 Int_t iy = rowSegment->GetLowIndicesLimit().GetSecond();
90 SetLowIndicesLimit(AliMpIntPair(ix, iy));
97 //______________________________________________________________________________
98 TVector2 AliMpRowSegmentRSpecial::MotifCenterSlow(Int_t motifPositionId) const
100 // Returns the coordinates of the motif specified with
101 // the given position identifier.
102 // !! Applicable only for motifs that have their most down pad in
106 // Find the first (left, down) pad row segment with this motifPositionId.
107 AliMpVPadRowSegment* downPadRowSegment
108 = FindPadRowSegment(motifPositionId);
109 AliMpVPadRowSegment* leftPadRowSegment
110 = FindMostLeftPadRowSegment(motifPositionId);
112 // Check if the motifPositionId is present
113 if (!downPadRowSegment || !leftPadRowSegment) {
114 Error("MotifCenter", "Outside row segment region");
118 // Check if both pad row segments have the same motif
119 if (downPadRowSegment->GetMotif() != leftPadRowSegment->GetMotif()) {
120 Fatal("MotifCenter", "Outside row segment region");
124 // Get position of found row segment
125 Double_t x = leftPadRowSegment->LeftBorderX();
126 Double_t y = GetRow()->LowBorderY() ;
128 for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
129 y += GetPadRow(i)->HalfSizeY()*2.;
131 // Add motifs dimensions
132 x += downPadRowSegment->GetMotif()->Dimensions().X();
133 y += downPadRowSegment->GetMotif()->Dimensions().Y();
135 return TVector2(x, y);
142 //______________________________________________________________________________
143 Double_t AliMpRowSegmentRSpecial::LeftBorderX() const
145 // Returns the x coordinate of the left row segment border
146 // in global coordinate system.
149 // The right edge of the last normal segment
150 Double_t sameBorder = GetOffsetX();
153 Double_t leftBorder = DBL_MAX;
154 for (Int_t i=0; i<GetNofPadRows(); i++) {
155 AliMpPadRow* padRow = GetPadRow(i);
156 Double_t border = padRow->GetPadRowSegment(0)->LeftBorderX();
157 if (border < leftBorder) leftBorder = border;
160 if (TMath::Abs(sameBorder - leftBorder) > 1.e-04) {
161 Error("LeftBorderX", "WrongBorder");
169 //______________________________________________________________________________
170 Double_t AliMpRowSegmentRSpecial::RightBorderX() const
172 // Returns the x coordinate of the right row segment border
173 // in global coordinate system.
176 Double_t rightBorder = -DBL_MAX;
177 for (Int_t i=0; i<GetNofPadRows(); i++) {
178 AliMpPadRow* padRow = GetPadRow(i);
180 = padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)
183 if (border > rightBorder) rightBorder = border;
189 //______________________________________________________________________________
190 TVector2 AliMpRowSegmentRSpecial::Position() const
192 // Returns the position of the row segment centre.
193 // The centre is defined as the centre of the rectangular
194 // row segment envelope.
197 // The right edge of the last normal segment
198 Double_t x = GetOffsetX() + Dimensions().X();
199 Double_t y = GetRow()->Position().Y();
201 return TVector2(x, y);
204 //______________________________________________________________________________
205 Int_t AliMpRowSegmentRSpecial::SetIndicesToMotifPosition(Int_t i,
206 const AliMpIntPair& indices)
208 // Sets global indices to i-th motif position and returns next index in x.
211 // Update low indices limit for this row segment
212 SetGlobalIndicesLow();
214 // Check for consistence
215 if (GetLowIndicesLimit().GetFirst() != indices.GetFirst())
216 Fatal("SetIndicesToMotifPosition", "Inconsistent indices");
218 // Get motif position
219 AliMpMotifPosition* motifPosition
220 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
222 // Set limits only once
223 if ( motifPosition->GetHighIndicesLimit().IsValid() )
224 return indices.GetFirst();;
228 Int_t ixl = GetLowIndicesLimit().GetFirst();
229 Int_t iyl = GetLowIndicesLimit().GetSecond();
231 // Find the most down pad row segment with this motifPositionId.
232 AliMpVPadRowSegment* padRowSegment = FindPadRowSegment(GetMotifPositionId(i));
233 Int_t padRowID = padRowSegment->GetPadRow()->GetID();
236 // Add pads offset of this motif position in the row segment
237 for (Int_t im=0; im<i; im++) {
238 AliMpVPadRowSegment* rs = GetPadRow(padRowID)->GetPadRowSegment(im);
239 if ( rs->GetMotifPositionId() == GetMotifPositionId(i) ) break;
240 ixl += rs->GetNofPads();
242 motifPosition->SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
246 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
248 = motifPosition->GetLowIndicesLimit()
249 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
250 motifPosition->SetHighIndicesLimit(high);
252 // No increment index needed (this is always the last element)
253 return indices.GetFirst();
256 //______________________________________________________________________________
257 void AliMpRowSegmentRSpecial::SetGlobalIndices(AliMpRow* rowBefore)
259 // Sets indices limits.
260 // The limits are defined as the limits of the smallest rectangle which
261 // includes all pads of this special row segment.
264 // Get first motif position
265 AliMpMotifPosition* firstMotifPosition
266 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(0));
269 Int_t ixl = firstMotifPosition->GetLowIndicesLimit().GetFirst();
270 // We have to take the motif position limit
271 // as it can overlap over more rows and the indices
272 // of the right border of the precedent normal segment
273 // differ from one row to another
276 Int_t ixh = ixl + MaxNofPadsInRow() - 1;
279 Int_t iyl = AliMpConstants::StartPadIndex();
281 //if (constPadSizeDirection == kY) {
282 iyl = rowBefore->GetHighIndicesLimit().GetSecond()+1;
286 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ixl);
287 AliMpMotifPosition* motPos = rowBefore->FindMotifPosition(seg, ixl);
289 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
290 iyl = motPos->GetHighIndicesLimit().GetSecond()+1;
296 Int_t iyh = iyl + GetNofPadRows() - 1;
298 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
299 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));