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.7 2006/05/24 13:58:46 ivana Exp $
20 //-----------------------------------------------------------------------------
21 // Class AliMpRowSegmentRSpecial
22 // -----------------------------
23 // Class describing a special outer row segment composed of the
25 // Included in AliRoot: 2003/05/02
26 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 //-----------------------------------------------------------------------------
29 #include "AliMpRowSegmentRSpecial.h"
31 #include "AliMpPadRow.h"
32 #include "AliMpVPadRowSegment.h"
33 #include "AliMpMotif.h"
34 #include "AliMpMotifType.h"
35 #include "AliMpMotifMap.h"
36 #include "AliMpMotifPosition.h"
37 #include "AliMpConstants.h"
41 #include <Riostream.h>
45 ClassImp(AliMpRowSegmentRSpecial)
48 //______________________________________________________________________________
49 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial(AliMpRow* row, Double_t offsetX)
50 : AliMpVRowSegmentSpecial(row, offsetX)
52 /// Standard constructor
55 //______________________________________________________________________________
56 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial()
57 : AliMpVRowSegmentSpecial()
59 /// Default constructor
62 //______________________________________________________________________________
63 AliMpRowSegmentRSpecial::~AliMpRowSegmentRSpecial()
72 //______________________________________________________________________________
74 AliMpRowSegmentRSpecial::FindMostLeftPadRowSegment(Int_t motifPositionId) const
76 /// Find the most left pad row segment with this motifPositionId.
78 AliMpVPadRowSegment* found = 0;
80 for (Int_t i=0; i<GetNofPadRows(); i++) {
81 AliMpPadRow* padRow = GetPadRow(i);
83 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
84 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
86 if ( padRowSegment->GetMotifPositionId() == motifPositionId &&
87 (!found || padRowSegment->LeftBorderX() < found->LeftBorderX()))
89 found = padRowSegment;
96 //______________________________________________________________________________
97 void AliMpRowSegmentRSpecial::SetGlobalIndicesLow()
99 /// Set global low indices
101 // Last normal row segment in the row
102 // (preceding this special row segment)
103 AliMpVRowSegment* rowSegment
104 = GetRow()->GetRowSegment(GetRow()->GetNofRowSegments()-2);
106 // Set low indices limit to continue indices of the
107 // preceding row segment
108 Int_t ix = rowSegment->GetHighIndicesLimit().GetFirst() + 1;
109 Int_t iy = rowSegment->GetLowIndicesLimit().GetSecond();
111 SetLowIndicesLimit(AliMpIntPair(ix, iy));
118 //______________________________________________________________________________
119 TVector2 AliMpRowSegmentRSpecial::MotifCenterSlow(Int_t motifPositionId) const
121 /// Return the coordinates of the motif specified with
122 /// the given position identifier. \n
123 /// !! Applicable only for motifs that have their most down pad in
124 /// this row segment.
126 // Find the first (left, down) pad row segment with this motifPositionId.
127 AliMpVPadRowSegment* downPadRowSegment
128 = FindPadRowSegment(motifPositionId);
129 AliMpVPadRowSegment* leftPadRowSegment
130 = FindMostLeftPadRowSegment(motifPositionId);
132 // Check if the motifPositionId is present
133 if (!downPadRowSegment || !leftPadRowSegment) {
134 AliErrorStream() << "Outside row segment region" << endl;
138 // Check if both pad row segments have the same motif
139 if (downPadRowSegment->GetMotif() != leftPadRowSegment->GetMotif()) {
140 AliFatal("Outside row segment region");
144 // Get position of found row segment
145 Double_t x = leftPadRowSegment->LeftBorderX();
146 Double_t y = GetRow()->LowBorderY() ;
148 for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
149 y += GetPadRow(i)->HalfSizeY()*2.;
151 // Add motifs dimensions
152 x += downPadRowSegment->GetMotif()->Dimensions().X();
153 y += downPadRowSegment->GetMotif()->Dimensions().Y();
155 return TVector2(x, y);
162 //______________________________________________________________________________
163 Double_t AliMpRowSegmentRSpecial::LeftBorderX() const
165 /// Return the x coordinate of the left row segment border
166 /// in the global coordinate system.
168 // The right edge of the last normal segment
169 Double_t sameBorder = GetOffsetX();
172 Double_t leftBorder = DBL_MAX;
173 for (Int_t i=0; i<GetNofPadRows(); i++) {
174 AliMpPadRow* padRow = GetPadRow(i);
175 Double_t border = padRow->GetPadRowSegment(0)->LeftBorderX();
176 if (border < leftBorder) leftBorder = border;
179 if (TMath::Abs(sameBorder - leftBorder) > 1.e-04) {
180 AliErrorStream() << "WrongBorder" << endl;;
188 //______________________________________________________________________________
189 Double_t AliMpRowSegmentRSpecial::RightBorderX() const
191 /// Return the x coordinate of the right row segment border
192 /// in the global coordinate system.
194 Double_t rightBorder = -DBL_MAX;
195 for (Int_t i=0; i<GetNofPadRows(); i++) {
196 AliMpPadRow* padRow = GetPadRow(i);
198 = padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)
201 if (border > rightBorder) rightBorder = border;
207 //______________________________________________________________________________
208 TVector2 AliMpRowSegmentRSpecial::Position() const
210 /// Return the position of the row segment centre.
211 /// The centre is defined as the centre of the rectangular
212 /// row segment envelope.
214 // The right edge of the last normal segment
215 Double_t x = GetOffsetX() + Dimensions().X();
216 Double_t y = GetRow()->Position().Y();
218 return TVector2(x, y);
221 //______________________________________________________________________________
222 Int_t AliMpRowSegmentRSpecial::SetIndicesToMotifPosition(Int_t i,
223 const AliMpIntPair& indices)
225 /// Set global indices to i-th motif position and returns next index in x.
227 // Update low indices limit for this row segment
228 SetGlobalIndicesLow();
230 // Check for consistence
231 if (GetLowIndicesLimit().GetFirst() != indices.GetFirst())
232 AliFatal("Inconsistent indices");
234 // Get motif position
235 AliMpMotifPosition* motifPosition
236 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
238 // Set limits only once
239 if ( motifPosition->GetHighIndicesLimit().IsValid() )
240 return indices.GetFirst();;
244 Int_t ixl = GetLowIndicesLimit().GetFirst();
245 Int_t iyl = GetLowIndicesLimit().GetSecond();
247 // Find the most down pad row segment with this motifPositionId.
248 AliMpVPadRowSegment* padRowSegment = FindPadRowSegment(GetMotifPositionId(i));
249 Int_t padRowID = padRowSegment->GetPadRow()->GetID();
252 // Add pads offset of this motif position in the row segment
253 for (Int_t im=0; im<i; im++) {
254 AliMpVPadRowSegment* rs = GetPadRow(padRowID)->GetPadRowSegment(im);
255 if ( rs->GetMotifPositionId() == GetMotifPositionId(i) ) break;
256 ixl += rs->GetNofPads();
258 motifPosition->SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
262 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
264 = motifPosition->GetLowIndicesLimit()
265 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
266 motifPosition->SetHighIndicesLimit(high);
268 // No increment index needed (this is always the last element)
269 return indices.GetFirst();
272 //______________________________________________________________________________
273 void AliMpRowSegmentRSpecial::SetGlobalIndices(AliMpRow* rowBefore)
275 /// Set indices limits.
276 /// The limits are defined as the limits of the smallest rectangle which
277 /// includes all pads of this special row segment.
279 // Get first motif position
280 AliMpMotifPosition* firstMotifPosition
281 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(0));
284 Int_t ixl = firstMotifPosition->GetLowIndicesLimit().GetFirst();
285 // We have to take the motif position limit
286 // as it can overlap over more rows and the indices
287 // of the right border of the precedent normal segment
288 // differ from one row to another
291 Int_t ixh = ixl + MaxNofPadsInRow() - 1;
294 Int_t iyl = AliMpConstants::StartPadIndex();
296 //if (constPadSizeDirection == kY) {
297 iyl = rowBefore->GetHighIndicesLimit().GetSecond()+1;
301 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ixl);
302 AliMpMotifPosition* motPos = rowBefore->FindMotifPosition(seg, ixl);
304 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
305 iyl = motPos->GetHighIndicesLimit().GetSecond()+1;
311 Int_t iyh = iyl + GetNofPadRows() - 1;
313 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
314 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));