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.5 2005/08/26 15:43:36 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
28 #include <Riostream.h>
30 #include "AliMpRowSegmentRSpecial.h"
32 #include "AliMpPadRow.h"
33 #include "AliMpVPadRowSegment.h"
34 #include "AliMpMotif.h"
35 #include "AliMpMotifType.h"
36 #include "AliMpMotifMap.h"
37 #include "AliMpMotifPosition.h"
38 #include "AliMpConstants.h"
40 ClassImp(AliMpRowSegmentRSpecial)
42 //______________________________________________________________________________
43 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial(AliMpRow* row, Double_t offsetX)
44 : AliMpVRowSegmentSpecial(row, offsetX)
46 /// Standard constructor
49 //______________________________________________________________________________
50 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial()
51 : AliMpVRowSegmentSpecial()
53 /// Default constructor
56 //______________________________________________________________________________
57 AliMpRowSegmentRSpecial::~AliMpRowSegmentRSpecial()
66 //______________________________________________________________________________
68 AliMpRowSegmentRSpecial::FindMostLeftPadRowSegment(Int_t motifPositionId) const
70 /// Find the most left pad row segment with this motifPositionId.
72 AliMpVPadRowSegment* found = 0;
74 for (Int_t i=0; i<GetNofPadRows(); i++) {
75 AliMpPadRow* padRow = GetPadRow(i);
77 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
78 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
80 if ( padRowSegment->GetMotifPositionId() == motifPositionId &&
81 (!found || padRowSegment->LeftBorderX() < found->LeftBorderX()))
83 found = padRowSegment;
90 //______________________________________________________________________________
91 void AliMpRowSegmentRSpecial::SetGlobalIndicesLow()
93 /// Set global low indices
95 // Last normal row segment in the row
96 // (preceding this special row segment)
97 AliMpVRowSegment* rowSegment
98 = GetRow()->GetRowSegment(GetRow()->GetNofRowSegments()-2);
100 // Set low indices limit to continue indices of the
101 // preceding row segment
102 Int_t ix = rowSegment->GetHighIndicesLimit().GetFirst() + 1;
103 Int_t iy = rowSegment->GetLowIndicesLimit().GetSecond();
105 SetLowIndicesLimit(AliMpIntPair(ix, iy));
112 //______________________________________________________________________________
113 TVector2 AliMpRowSegmentRSpecial::MotifCenterSlow(Int_t motifPositionId) const
115 /// Return the coordinates of the motif specified with
116 /// the given position identifier. \n
117 /// !! Applicable only for motifs that have their most down pad in
118 /// this row segment.
120 // Find the first (left, down) pad row segment with this motifPositionId.
121 AliMpVPadRowSegment* downPadRowSegment
122 = FindPadRowSegment(motifPositionId);
123 AliMpVPadRowSegment* leftPadRowSegment
124 = FindMostLeftPadRowSegment(motifPositionId);
126 // Check if the motifPositionId is present
127 if (!downPadRowSegment || !leftPadRowSegment) {
128 Error("MotifCenter", "Outside row segment region");
132 // Check if both pad row segments have the same motif
133 if (downPadRowSegment->GetMotif() != leftPadRowSegment->GetMotif()) {
134 Fatal("MotifCenter", "Outside row segment region");
138 // Get position of found row segment
139 Double_t x = leftPadRowSegment->LeftBorderX();
140 Double_t y = GetRow()->LowBorderY() ;
142 for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
143 y += GetPadRow(i)->HalfSizeY()*2.;
145 // Add motifs dimensions
146 x += downPadRowSegment->GetMotif()->Dimensions().X();
147 y += downPadRowSegment->GetMotif()->Dimensions().Y();
149 return TVector2(x, y);
156 //______________________________________________________________________________
157 Double_t AliMpRowSegmentRSpecial::LeftBorderX() const
159 /// Return the x coordinate of the left row segment border
160 /// in the global coordinate system.
162 // The right edge of the last normal segment
163 Double_t sameBorder = GetOffsetX();
166 Double_t leftBorder = DBL_MAX;
167 for (Int_t i=0; i<GetNofPadRows(); i++) {
168 AliMpPadRow* padRow = GetPadRow(i);
169 Double_t border = padRow->GetPadRowSegment(0)->LeftBorderX();
170 if (border < leftBorder) leftBorder = border;
173 if (TMath::Abs(sameBorder - leftBorder) > 1.e-04) {
174 Error("LeftBorderX", "WrongBorder");
182 //______________________________________________________________________________
183 Double_t AliMpRowSegmentRSpecial::RightBorderX() const
185 /// Return the x coordinate of the right row segment border
186 /// in the global coordinate system.
188 Double_t rightBorder = -DBL_MAX;
189 for (Int_t i=0; i<GetNofPadRows(); i++) {
190 AliMpPadRow* padRow = GetPadRow(i);
192 = padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)
195 if (border > rightBorder) rightBorder = border;
201 //______________________________________________________________________________
202 TVector2 AliMpRowSegmentRSpecial::Position() const
204 /// Return the position of the row segment centre.
205 /// The centre is defined as the centre of the rectangular
206 /// row segment envelope.
208 // The right edge of the last normal segment
209 Double_t x = GetOffsetX() + Dimensions().X();
210 Double_t y = GetRow()->Position().Y();
212 return TVector2(x, y);
215 //______________________________________________________________________________
216 Int_t AliMpRowSegmentRSpecial::SetIndicesToMotifPosition(Int_t i,
217 const AliMpIntPair& indices)
219 /// Set global indices to i-th motif position and returns next index in x.
221 // Update low indices limit for this row segment
222 SetGlobalIndicesLow();
224 // Check for consistence
225 if (GetLowIndicesLimit().GetFirst() != indices.GetFirst())
226 Fatal("SetIndicesToMotifPosition", "Inconsistent indices");
228 // Get motif position
229 AliMpMotifPosition* motifPosition
230 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
232 // Set limits only once
233 if ( motifPosition->GetHighIndicesLimit().IsValid() )
234 return indices.GetFirst();;
238 Int_t ixl = GetLowIndicesLimit().GetFirst();
239 Int_t iyl = GetLowIndicesLimit().GetSecond();
241 // Find the most down pad row segment with this motifPositionId.
242 AliMpVPadRowSegment* padRowSegment = FindPadRowSegment(GetMotifPositionId(i));
243 Int_t padRowID = padRowSegment->GetPadRow()->GetID();
246 // Add pads offset of this motif position in the row segment
247 for (Int_t im=0; im<i; im++) {
248 AliMpVPadRowSegment* rs = GetPadRow(padRowID)->GetPadRowSegment(im);
249 if ( rs->GetMotifPositionId() == GetMotifPositionId(i) ) break;
250 ixl += rs->GetNofPads();
252 motifPosition->SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
256 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
258 = motifPosition->GetLowIndicesLimit()
259 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
260 motifPosition->SetHighIndicesLimit(high);
262 // No increment index needed (this is always the last element)
263 return indices.GetFirst();
266 //______________________________________________________________________________
267 void AliMpRowSegmentRSpecial::SetGlobalIndices(AliMpRow* rowBefore)
269 /// Set indices limits.
270 /// The limits are defined as the limits of the smallest rectangle which
271 /// includes all pads of this special row segment.
273 // Get first motif position
274 AliMpMotifPosition* firstMotifPosition
275 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(0));
278 Int_t ixl = firstMotifPosition->GetLowIndicesLimit().GetFirst();
279 // We have to take the motif position limit
280 // as it can overlap over more rows and the indices
281 // of the right border of the precedent normal segment
282 // differ from one row to another
285 Int_t ixh = ixl + MaxNofPadsInRow() - 1;
288 Int_t iyl = AliMpConstants::StartPadIndex();
290 //if (constPadSizeDirection == kY) {
291 iyl = rowBefore->GetHighIndicesLimit().GetSecond()+1;
295 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ixl);
296 AliMpMotifPosition* motPos = rowBefore->FindMotifPosition(seg, ixl);
298 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
299 iyl = motPos->GetHighIndicesLimit().GetSecond()+1;
305 Int_t iyh = iyl + GetNofPadRows() - 1;
307 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
308 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));