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->GetHighLimitIx() + 1;
109 Int_t iy = rowSegment->GetLowLimitIy();
111 SetLowIndicesLimit(ix, iy);
118 //______________________________________________________________________________
119 void AliMpRowSegmentRSpecial::MotifCenterSlow(Int_t motifPositionId,
120 Double_t& x, Double_t& y) const
122 /// Fill the coordinates of the motif specified with
123 /// the given position identifier. \n
124 /// !! Applicable only for motifs that have their most down pad in
125 /// this row segment.
127 // Find the first (left, down) pad row segment with this motifPositionId.
128 AliMpVPadRowSegment* downPadRowSegment
129 = FindPadRowSegment(motifPositionId);
130 AliMpVPadRowSegment* leftPadRowSegment
131 = FindMostLeftPadRowSegment(motifPositionId);
133 // Check if the motifPositionId is present
134 if (!downPadRowSegment || !leftPadRowSegment) {
135 AliErrorStream() << "Outside row segment region" << endl;
139 // Check if both pad row segments have the same motif
140 if (downPadRowSegment->GetMotif() != leftPadRowSegment->GetMotif()) {
141 AliFatal("Outside row segment region");
145 // Get position of found row segment
146 x = leftPadRowSegment->LeftBorderX();
147 y = GetRow()->LowBorderY() ;
149 for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
150 y += GetPadRow(i)->HalfSizeY()*2.;
152 // Add motifs dimensions
153 x += downPadRowSegment->GetMotif()->DimensionX();
154 y += downPadRowSegment->GetMotif()->DimensionY();
161 //______________________________________________________________________________
162 Double_t AliMpRowSegmentRSpecial::LeftBorderX() const
164 /// Return the x coordinate of the left row segment border
165 /// in the global coordinate system.
167 // The right edge of the last normal segment
168 Double_t sameBorder = GetOffsetX();
171 Double_t leftBorder = DBL_MAX;
172 for (Int_t i=0; i<GetNofPadRows(); i++) {
173 AliMpPadRow* padRow = GetPadRow(i);
174 Double_t border = padRow->GetPadRowSegment(0)->LeftBorderX();
175 if (border < leftBorder) leftBorder = border;
178 if (TMath::Abs(sameBorder - leftBorder) > 1.e-04) {
179 AliErrorStream() << "WrongBorder" << endl;;
187 //______________________________________________________________________________
188 Double_t AliMpRowSegmentRSpecial::RightBorderX() const
190 /// Return the x coordinate of the right row segment border
191 /// in the global coordinate system.
193 Double_t rightBorder = -DBL_MAX;
194 for (Int_t i=0; i<GetNofPadRows(); i++) {
195 AliMpPadRow* padRow = GetPadRow(i);
197 = padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)
200 if (border > rightBorder) rightBorder = border;
206 //______________________________________________________________________________
207 Double_t AliMpRowSegmentRSpecial::GetPositionX() const
209 /// Return the x position of the row segment centre.
210 /// The centre is defined as the centre of the rectangular
211 /// row segment envelope.
213 // The right edge of the last normal segment
214 return GetOffsetX() + GetDimensionX();
217 //______________________________________________________________________________
218 Double_t AliMpRowSegmentRSpecial::GetPositionY() const
220 /// Return the y position of the row segment centre.
221 /// The centre is defined as the centre of the rectangular
222 /// row segment envelope.
224 // The right edge of the last normal segment
225 return GetRow()->GetPositionY();
228 //______________________________________________________________________________
229 Int_t AliMpRowSegmentRSpecial::SetIndicesToMotifPosition(Int_t i, MpPair_t indices)
231 /// Set global indices to i-th motif position and returns next index in x.
233 // Update low indices limit for this row segment
234 SetGlobalIndicesLow();
236 // Check for consistence
237 if ( GetLowLimitIx() != AliMp::PairFirst(indices) )
238 AliFatal("Inconsistent indices");
240 // Get motif position
241 AliMpMotifPosition* motifPosition
242 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
244 // Set limits only once
245 if ( motifPosition->IsHighLimitValid() )
246 return AliMp::PairFirst(indices);
250 Int_t ixl = GetLowLimitIx();
251 Int_t iyl = GetLowLimitIy();
253 // Find the most down pad row segment with this motifPositionId.
254 AliMpVPadRowSegment* padRowSegment = FindPadRowSegment(GetMotifPositionId(i));
255 Int_t padRowID = padRowSegment->GetPadRow()->GetID();
258 // Add pads offset of this motif position in the row segment
259 for ( Int_t im=0; im<i; im++ ) {
260 AliMpVPadRowSegment* rs = GetPadRow(padRowID)->GetPadRowSegment(im);
261 if ( rs->GetMotifPositionId() == GetMotifPositionId(i) ) break;
262 ixl += rs->GetNofPads();
264 motifPosition->SetLowIndicesLimit(ixl, iyl);
268 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
270 = motifPosition->GetLowIndicesLimit()
271 + AliMp::Pair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
272 motifPosition->SetHighIndicesLimit(high);
274 // No increment index needed (this is always the last element)
275 return AliMp::PairFirst(indices);
278 //______________________________________________________________________________
279 void AliMpRowSegmentRSpecial::SetGlobalIndices(AliMpRow* rowBefore)
281 /// Set indices limits.
282 /// The limits are defined as the limits of the smallest rectangle which
283 /// includes all pads of this special row segment.
285 // Get first motif position
286 AliMpMotifPosition* firstMotifPosition
287 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(0));
290 Int_t ixl = firstMotifPosition->GetLowLimitIx();
291 // We have to take the motif position limit
292 // as it can overlap over more rows and the indices
293 // of the right border of the precedent normal segment
294 // differ from one row to another
297 Int_t ixh = ixl + MaxNofPadsInRow() - 1;
300 Int_t iyl = AliMpConstants::StartPadIndex();
302 //if (constPadSizeDirection == kY) {
303 iyl = rowBefore->GetHighLimitIy()+1;
307 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ixl);
308 AliMpMotifPosition* motPos = rowBefore->FindMotifPosition(seg, ixl);
310 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
311 iyl = motPos->GetHighLimitIy()+1;
317 Int_t iyh = iyl + GetNofPadRows() - 1;
319 SetLowIndicesLimit(ixl, iyl);
320 SetHighIndicesLimit(ixh, iyh);