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: AliMpRowSegmentLSpecial.cxx,v 1.7 2006/05/24 13:58:46 ivana Exp $
20 //-----------------------------------------------------------------------------
21 // Class AliMpRowSegmentLSpecial
22 // -----------------------------
23 // Class describing a special inner row segment composed of the
25 // Included in AliRoot: 2003/05/02
26 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 //-----------------------------------------------------------------------------
29 #include <Riostream.h>
32 #include "AliMpRowSegmentLSpecial.h"
34 #include "AliMpPadRow.h"
35 #include "AliMpVPadRowSegment.h"
36 #include "AliMpMotif.h"
37 #include "AliMpMotifType.h"
38 #include "AliMpMotifMap.h"
39 #include "AliMpMotifPosition.h"
40 #include "AliMpConstants.h"
41 #include "AliMpEncodePair.h"
46 ClassImp(AliMpRowSegmentLSpecial)
49 //______________________________________________________________________________
50 AliMpRowSegmentLSpecial::AliMpRowSegmentLSpecial(AliMpRow* row, Double_t offsetX)
51 : AliMpVRowSegmentSpecial(row, offsetX)
53 /// Standard constructor
56 //______________________________________________________________________________
57 AliMpRowSegmentLSpecial::AliMpRowSegmentLSpecial()
58 : AliMpVRowSegmentSpecial()
60 /// Default constructor
63 //______________________________________________________________________________
64 AliMpRowSegmentLSpecial::~AliMpRowSegmentLSpecial()
73 //______________________________________________________________________________
75 AliMpRowSegmentLSpecial::FindMostRightPadRowSegment(Int_t motifPositionId) const
77 /// Find the most right 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->RightBorderX() > found->RightBorderX()))
90 found = padRowSegment;
101 //______________________________________________________________________________
102 void AliMpRowSegmentLSpecial::MotifCenterSlow(Int_t motifPositionId,
103 Double_t& x, Double_t& y) const
105 /// Fill the coordinates of the motif specified with
106 /// the given position identifier. \n
107 /// !! Applicable only for motifs that have their most down pad in
108 /// this row segment.
110 // Find the first (left, down) pad row segment with this motifPositionId.
111 AliMpVPadRowSegment* downPadRowSegment
112 = FindPadRowSegment(motifPositionId);
113 AliMpVPadRowSegment* rightPadRowSegment
114 = FindMostRightPadRowSegment(motifPositionId);
116 // Check if the motifPositionId is present
117 if (!downPadRowSegment || !rightPadRowSegment) {
118 AliErrorStream() << "Outside row segment region" << endl;
122 // Check if both pad row segments have the same motif
123 if (downPadRowSegment->GetMotif() != rightPadRowSegment->GetMotif()) {
124 AliFatal("Outside row segment region");
128 // Get position of found row segment
129 x = rightPadRowSegment->RightBorderX();
130 y = GetRow()->LowBorderY() ;
132 for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
133 y += GetPadRow(i)->HalfSizeY()*2.;
135 // Add motifs dimensions
136 x -= downPadRowSegment->GetMotif()->DimensionX();
137 y += downPadRowSegment->GetMotif()->DimensionY();
144 //______________________________________________________________________________
145 void AliMpRowSegmentLSpecial::UpdatePadsOffset()
147 /// Set low indices limit to the pad offset calculated
148 /// from the neighbour normal segment.
150 // Get the neighbour row segment
151 // (the first normal segment)
152 AliMpVRowSegment* neighbour = GetRow()->GetRowSegment(1);
154 // Get the the pads offset of the neighbour row segment
155 // (the first normal segment)
156 MpPair_t offset = neighbour->GetLowIndicesLimit();
158 // Find max nof pads in a row
159 Int_t maxNofPads = MaxNofPadsInRow();
162 SetLowIndicesLimit(offset - AliMp::Pair(maxNofPads, 0));
164 // Reset limits in the neighbour row segment
165 // (pad offset is now included in the special segment)
166 neighbour->SetLowIndicesLimit(0, neighbour->GetLowLimitIy());
169 //______________________________________________________________________________
170 Double_t AliMpRowSegmentLSpecial::LeftBorderX() const
172 /// Return the x coordinate of the left row segment border
173 /// in the global coordinate system.
175 Double_t leftBorder = DBL_MAX;
176 for (Int_t i=0; i<GetNofPadRows(); i++) {
177 AliMpPadRow* padRow = GetPadRow(i);
179 = padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX();
181 if (border < leftBorder) leftBorder = border;
187 //______________________________________________________________________________
188 Double_t AliMpRowSegmentLSpecial::RightBorderX() const
190 /// Returns the x coordinate of the right row segment border
191 /// in the global coordinate system.
193 Double_t sameBorder = GetOffsetX();
196 Double_t rightBorder = -DBL_MAX;
197 for (Int_t i=0; i<GetNofPadRows(); i++) {
198 AliMpPadRow* padRow = GetPadRow(i);
199 Double_t border = padRow->GetPadRowSegment(0)->RightBorderX();
200 if (border > rightBorder) rightBorder = border;
203 if (TMath::Abs(GetOffsetX() - rightBorder) > 1.e-04) {
204 AliErrorStream() << "WrongBorder" << endl;
211 //______________________________________________________________________________
212 Double_t AliMpRowSegmentLSpecial::GetPositionX() const
214 /// Return the x position of the row segment centre.
215 /// The centre is defined as the centre of the rectangular
216 /// row segment envelope.
218 return GetOffsetX() - GetDimensionX();
221 //______________________________________________________________________________
222 Double_t AliMpRowSegmentLSpecial::GetPositionY() const
224 /// Return the y position of the row segment centre.
225 /// The centre is defined as the centre of the rectangular
226 /// row segment envelope.
228 return GetRow()->GetPositionY();
231 #include <Riostream.h>
232 //______________________________________________________________________________
233 Int_t AliMpRowSegmentLSpecial::SetIndicesToMotifPosition(Int_t i, MpPair_t indices)
235 /// Set global indices to i-th motif position and returns next index in x.
237 // Get motif position
238 AliMpMotifPosition* motifPosition
239 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
243 = AliMp::Pair(GetLowLimitIx() + AliMpConstants::StartPadIndex(),
244 AliMp::PairSecond(indices))
245 + FindRelativeLowIndicesOf(GetMotifPositionId(i));
247 if (! motifPosition->IsHighLimitValid()) {
248 motifPosition->SetLowIndicesLimit(low);
251 if ( motifPosition->GetLowLimitIx() > AliMp::PairFirst(low) )
252 motifPosition->SetLowIndicesLimit(
253 AliMp::PairFirst(low),
254 motifPosition->GetLowLimitIy());
256 if ( motifPosition->GetLowLimitIy() > AliMp::PairSecond(low) )
257 motifPosition->SetLowIndicesLimit(
258 motifPosition->GetLowLimitIx(),
259 AliMp::PairSecond(low) );
263 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
265 = motifPosition->GetLowIndicesLimit()
266 + AliMp::Pair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
268 motifPosition->SetHighIndicesLimit(high);
270 // Increment index only if last motif position is processed
271 if ( i != GetNofMotifs()-1 )
272 return AliMp::PairFirst(indices);
275 return AliMp::PairFirst(indices) + MaxNofPadsInRow();
276 //return MaxNofPadsInRow();
278 //______________________________________________________________________________
279 void AliMpRowSegmentLSpecial::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.
286 Int_t ixl = GetLowLimitIx() + AliMpConstants::StartPadIndex();
287 // the pads offset was already defined by Reader
290 Int_t ixh = ixl + MaxNofPadsInRow() - 1;
293 Int_t iyl = AliMpConstants::StartPadIndex();
295 //if (constPadSizeDirection == kY) {
296 iyl = rowBefore->GetHighLimitIy()+1;
300 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ixl);
301 AliMpMotifPosition* motPos = rowBefore->FindMotifPosition(seg, ixl);
303 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
304 iyl = motPos->GetHighLimitIy()+1;
310 Int_t iyh = iyl + GetNofPadRows() - 1;
312 SetLowIndicesLimit(ixl, iyl);
313 SetHighIndicesLimit(ixh, iyh);