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: AliMpRowSegmentRSpecial.cxx,v 1.6 2006/03/17 11:38:43 ivana Exp $
20 // Class AliMpRowSegmentRSpecial
21 // -----------------------------
22 // Class describing a special outer row segment composed of the
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 #include "AliMpRowSegmentRSpecial.h"
29 #include "AliMpPadRow.h"
30 #include "AliMpVPadRowSegment.h"
31 #include "AliMpMotif.h"
32 #include "AliMpMotifType.h"
33 #include "AliMpMotifMap.h"
34 #include "AliMpMotifPosition.h"
35 #include "AliMpConstants.h"
37 #include <Riostream.h>
39 ClassImp(AliMpRowSegmentRSpecial)
41 //______________________________________________________________________________
42 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial(AliMpRow* row, Double_t offsetX)
43 : AliMpVRowSegmentSpecial(row, offsetX)
45 /// Standard constructor
48 //______________________________________________________________________________
49 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial()
50 : AliMpVRowSegmentSpecial()
52 /// Default constructor
55 //______________________________________________________________________________
56 AliMpRowSegmentRSpecial::~AliMpRowSegmentRSpecial()
65 //______________________________________________________________________________
67 AliMpRowSegmentRSpecial::FindMostLeftPadRowSegment(Int_t motifPositionId) const
69 /// Find the most left pad row segment with this motifPositionId.
71 AliMpVPadRowSegment* found = 0;
73 for (Int_t i=0; i<GetNofPadRows(); i++) {
74 AliMpPadRow* padRow = GetPadRow(i);
76 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
77 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
79 if ( padRowSegment->GetMotifPositionId() == motifPositionId &&
80 (!found || padRowSegment->LeftBorderX() < found->LeftBorderX()))
82 found = padRowSegment;
89 //______________________________________________________________________________
90 void AliMpRowSegmentRSpecial::SetGlobalIndicesLow()
92 /// Set global low indices
94 // Last normal row segment in the row
95 // (preceding this special row segment)
96 AliMpVRowSegment* rowSegment
97 = GetRow()->GetRowSegment(GetRow()->GetNofRowSegments()-2);
99 // Set low indices limit to continue indices of the
100 // preceding row segment
101 Int_t ix = rowSegment->GetHighIndicesLimit().GetFirst() + 1;
102 Int_t iy = rowSegment->GetLowIndicesLimit().GetSecond();
104 SetLowIndicesLimit(AliMpIntPair(ix, iy));
111 //______________________________________________________________________________
112 TVector2 AliMpRowSegmentRSpecial::MotifCenterSlow(Int_t motifPositionId) const
114 /// Return the coordinates of the motif specified with
115 /// the given position identifier. \n
116 /// !! Applicable only for motifs that have their most down pad in
117 /// this row segment.
119 // Find the first (left, down) pad row segment with this motifPositionId.
120 AliMpVPadRowSegment* downPadRowSegment
121 = FindPadRowSegment(motifPositionId);
122 AliMpVPadRowSegment* leftPadRowSegment
123 = FindMostLeftPadRowSegment(motifPositionId);
125 // Check if the motifPositionId is present
126 if (!downPadRowSegment || !leftPadRowSegment) {
127 AliErrorStream() << "Outside row segment region" << endl;
131 // Check if both pad row segments have the same motif
132 if (downPadRowSegment->GetMotif() != leftPadRowSegment->GetMotif()) {
133 AliFatal("Outside row segment region");
137 // Get position of found row segment
138 Double_t x = leftPadRowSegment->LeftBorderX();
139 Double_t y = GetRow()->LowBorderY() ;
141 for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
142 y += GetPadRow(i)->HalfSizeY()*2.;
144 // Add motifs dimensions
145 x += downPadRowSegment->GetMotif()->Dimensions().X();
146 y += downPadRowSegment->GetMotif()->Dimensions().Y();
148 return TVector2(x, y);
155 //______________________________________________________________________________
156 Double_t AliMpRowSegmentRSpecial::LeftBorderX() const
158 /// Return the x coordinate of the left row segment border
159 /// in the global coordinate system.
161 // The right edge of the last normal segment
162 Double_t sameBorder = GetOffsetX();
165 Double_t leftBorder = DBL_MAX;
166 for (Int_t i=0; i<GetNofPadRows(); i++) {
167 AliMpPadRow* padRow = GetPadRow(i);
168 Double_t border = padRow->GetPadRowSegment(0)->LeftBorderX();
169 if (border < leftBorder) leftBorder = border;
172 if (TMath::Abs(sameBorder - leftBorder) > 1.e-04) {
173 AliErrorStream() << "WrongBorder" << endl;;
181 //______________________________________________________________________________
182 Double_t AliMpRowSegmentRSpecial::RightBorderX() const
184 /// Return the x coordinate of the right row segment border
185 /// in the global coordinate system.
187 Double_t rightBorder = -DBL_MAX;
188 for (Int_t i=0; i<GetNofPadRows(); i++) {
189 AliMpPadRow* padRow = GetPadRow(i);
191 = padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)
194 if (border > rightBorder) rightBorder = border;
200 //______________________________________________________________________________
201 TVector2 AliMpRowSegmentRSpecial::Position() const
203 /// Return the position of the row segment centre.
204 /// The centre is defined as the centre of the rectangular
205 /// row segment envelope.
207 // The right edge of the last normal segment
208 Double_t x = GetOffsetX() + Dimensions().X();
209 Double_t y = GetRow()->Position().Y();
211 return TVector2(x, y);
214 //______________________________________________________________________________
215 Int_t AliMpRowSegmentRSpecial::SetIndicesToMotifPosition(Int_t i,
216 const AliMpIntPair& indices)
218 /// Set global indices to i-th motif position and returns next index in x.
220 // Update low indices limit for this row segment
221 SetGlobalIndicesLow();
223 // Check for consistence
224 if (GetLowIndicesLimit().GetFirst() != indices.GetFirst())
225 Fatal("SetIndicesToMotifPosition", "Inconsistent indices");
227 // Get motif position
228 AliMpMotifPosition* motifPosition
229 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
231 // Set limits only once
232 if ( motifPosition->GetHighIndicesLimit().IsValid() )
233 return indices.GetFirst();;
237 Int_t ixl = GetLowIndicesLimit().GetFirst();
238 Int_t iyl = GetLowIndicesLimit().GetSecond();
240 // Find the most down pad row segment with this motifPositionId.
241 AliMpVPadRowSegment* padRowSegment = FindPadRowSegment(GetMotifPositionId(i));
242 Int_t padRowID = padRowSegment->GetPadRow()->GetID();
245 // Add pads offset of this motif position in the row segment
246 for (Int_t im=0; im<i; im++) {
247 AliMpVPadRowSegment* rs = GetPadRow(padRowID)->GetPadRowSegment(im);
248 if ( rs->GetMotifPositionId() == GetMotifPositionId(i) ) break;
249 ixl += rs->GetNofPads();
251 motifPosition->SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
255 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
257 = motifPosition->GetLowIndicesLimit()
258 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
259 motifPosition->SetHighIndicesLimit(high);
261 // No increment index needed (this is always the last element)
262 return indices.GetFirst();
265 //______________________________________________________________________________
266 void AliMpRowSegmentRSpecial::SetGlobalIndices(AliMpRow* rowBefore)
268 /// Set indices limits.
269 /// The limits are defined as the limits of the smallest rectangle which
270 /// includes all pads of this special row segment.
272 // Get first motif position
273 AliMpMotifPosition* firstMotifPosition
274 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(0));
277 Int_t ixl = firstMotifPosition->GetLowIndicesLimit().GetFirst();
278 // We have to take the motif position limit
279 // as it can overlap over more rows and the indices
280 // of the right border of the precedent normal segment
281 // differ from one row to another
284 Int_t ixh = ixl + MaxNofPadsInRow() - 1;
287 Int_t iyl = AliMpConstants::StartPadIndex();
289 //if (constPadSizeDirection == kY) {
290 iyl = rowBefore->GetHighIndicesLimit().GetSecond()+1;
294 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ixl);
295 AliMpMotifPosition* motPos = rowBefore->FindMotifPosition(seg, ixl);
297 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
298 iyl = motPos->GetHighIndicesLimit().GetSecond()+1;
304 Int_t iyh = iyl + GetNofPadRows() - 1;
306 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
307 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));