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>
46 ClassImp(AliMpRowSegmentRSpecial)
49 //______________________________________________________________________________
50 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial(AliMpRow* row, Double_t offsetX)
51 : AliMpVRowSegmentSpecial(row, offsetX)
53 /// Standard constructor
56 //______________________________________________________________________________
57 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial()
58 : AliMpVRowSegmentSpecial()
60 /// Default constructor
63 //______________________________________________________________________________
64 AliMpRowSegmentRSpecial::~AliMpRowSegmentRSpecial()
73 //______________________________________________________________________________
75 AliMpRowSegmentRSpecial::FindMostLeftPadRowSegment(Int_t motifPositionId) const
77 /// Find the most left pad row segment with this motifPositionId.
79 AliMpVPadRowSegment* found = 0;
81 for (Int_t i=0; i<GetNofPadRows(); i++) {
82 AliMpPadRow* padRow = GetPadRow(i);
84 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
85 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
87 if ( padRowSegment->GetMotifPositionId() == motifPositionId &&
88 (!found || padRowSegment->LeftBorderX() < found->LeftBorderX()))
90 found = padRowSegment;
97 //______________________________________________________________________________
98 void AliMpRowSegmentRSpecial::SetGlobalIndicesLow()
100 /// Set global low indices
102 // Last normal row segment in the row
103 // (preceding this special row segment)
104 AliMpVRowSegment* rowSegment
105 = GetRow()->GetRowSegment(GetRow()->GetNofRowSegments()-2);
107 // Set low indices limit to continue indices of the
108 // preceding row segment
109 Int_t ix = rowSegment->GetHighLimitIx() + 1;
110 Int_t iy = rowSegment->GetLowLimitIy();
112 SetLowIndicesLimit(ix, iy);
119 //______________________________________________________________________________
120 void AliMpRowSegmentRSpecial::MotifCenterSlow(Int_t motifPositionId,
121 Double_t& x, Double_t& y) const
123 /// Fill the coordinates of the motif specified with
124 /// the given position identifier. \n
125 /// !! Applicable only for motifs that have their most down pad in
126 /// this row segment.
128 // Find the first (left, down) pad row segment with this motifPositionId.
129 AliMpVPadRowSegment* downPadRowSegment
130 = FindPadRowSegment(motifPositionId);
131 AliMpVPadRowSegment* leftPadRowSegment
132 = FindMostLeftPadRowSegment(motifPositionId);
134 // Check if the motifPositionId is present
135 if (!downPadRowSegment || !leftPadRowSegment) {
136 AliErrorStream() << "Outside row segment region" << endl;
140 // Check if both pad row segments have the same motif
141 if (downPadRowSegment->GetMotif() != leftPadRowSegment->GetMotif()) {
142 AliFatal("Outside row segment region");
146 // Get position of found row segment
147 x = leftPadRowSegment->LeftBorderX();
148 y = GetRow()->LowBorderY() ;
150 for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
151 y += GetPadRow(i)->HalfSizeY()*2.;
153 // Add motifs dimensions
154 x += downPadRowSegment->GetMotif()->DimensionX();
155 y += downPadRowSegment->GetMotif()->DimensionY();
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 Double_t AliMpRowSegmentRSpecial::GetPositionX() const
210 /// Return the x 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 return GetOffsetX() + GetDimensionX();
218 //______________________________________________________________________________
219 Double_t AliMpRowSegmentRSpecial::GetPositionY() const
221 /// Return the y position of the row segment centre.
222 /// The centre is defined as the centre of the rectangular
223 /// row segment envelope.
225 // The right edge of the last normal segment
226 return GetRow()->GetPositionY();
229 //______________________________________________________________________________
230 Int_t AliMpRowSegmentRSpecial::SetIndicesToMotifPosition(Int_t i, MpPair_t indices)
232 /// Set global indices to i-th motif position and returns next index in x.
234 // Update low indices limit for this row segment
235 SetGlobalIndicesLow();
237 // Check for consistence
238 if ( GetLowLimitIx() != AliMp::PairFirst(indices) )
239 AliFatal("Inconsistent indices");
241 // Get motif position
242 AliMpMotifPosition* motifPosition
243 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
245 // Set limits only once
246 if ( motifPosition->IsHighLimitValid() )
247 return AliMp::PairFirst(indices);
251 Int_t ixl = GetLowLimitIx();
252 Int_t iyl = GetLowLimitIy();
254 // Find the most down pad row segment with this motifPositionId.
255 AliMpVPadRowSegment* padRowSegment = FindPadRowSegment(GetMotifPositionId(i));
256 Int_t padRowID = padRowSegment->GetPadRow()->GetID();
259 // Add pads offset of this motif position in the row segment
260 for ( Int_t im=0; im<i; im++ ) {
261 AliMpVPadRowSegment* rs = GetPadRow(padRowID)->GetPadRowSegment(im);
262 if ( rs->GetMotifPositionId() == GetMotifPositionId(i) ) break;
263 ixl += rs->GetNofPads();
265 motifPosition->SetLowIndicesLimit(ixl, iyl);
269 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
271 = motifPosition->GetLowIndicesLimit()
272 + AliMp::Pair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
273 motifPosition->SetHighIndicesLimit(high);
275 // No increment index needed (this is always the last element)
276 return AliMp::PairFirst(indices);
279 //______________________________________________________________________________
280 void AliMpRowSegmentRSpecial::SetGlobalIndices(AliMpRow* rowBefore)
282 /// Set indices limits.
283 /// The limits are defined as the limits of the smallest rectangle which
284 /// includes all pads of this special row segment.
286 // Get first motif position
287 AliMpMotifPosition* firstMotifPosition
288 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(0));
291 Int_t ixl = firstMotifPosition->GetLowLimitIx();
292 // We have to take the motif position limit
293 // as it can overlap over more rows and the indices
294 // of the right border of the precedent normal segment
295 // differ from one row to another
298 Int_t ixh = ixl + MaxNofPadsInRow() - 1;
301 Int_t iyl = AliMpConstants::StartPadIndex();
303 //if (constPadSizeDirection == kY) {
304 iyl = rowBefore->GetHighLimitIy()+1;
308 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ixl);
309 AliMpMotifPosition* motPos = rowBefore->FindMotifPosition(seg, ixl);
311 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
312 iyl = motPos->GetHighLimitIy()+1;
318 Int_t iyh = iyl + GetNofPadRows() - 1;
320 SetLowIndicesLimit(ixl, iyl);
321 SetHighIndicesLimit(ixh, iyh);