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"
47 ClassImp(AliMpRowSegmentLSpecial)
50 //______________________________________________________________________________
51 AliMpRowSegmentLSpecial::AliMpRowSegmentLSpecial(AliMpRow* row, Double_t offsetX)
52 : AliMpVRowSegmentSpecial(row, offsetX)
54 /// Standard constructor
57 //______________________________________________________________________________
58 AliMpRowSegmentLSpecial::AliMpRowSegmentLSpecial()
59 : AliMpVRowSegmentSpecial()
61 /// Default constructor
64 //______________________________________________________________________________
65 AliMpRowSegmentLSpecial::~AliMpRowSegmentLSpecial()
74 //______________________________________________________________________________
76 AliMpRowSegmentLSpecial::FindMostRightPadRowSegment(Int_t motifPositionId) const
78 /// Find the most right pad row segment with this motifPositionId.
80 AliMpVPadRowSegment* found = 0;
82 for (Int_t i=0; i<GetNofPadRows(); i++) {
83 AliMpPadRow* padRow = GetPadRow(i);
85 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
86 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
88 if ( padRowSegment->GetMotifPositionId() == motifPositionId &&
89 (!found || padRowSegment->RightBorderX() > found->RightBorderX()))
91 found = padRowSegment;
102 //______________________________________________________________________________
103 void AliMpRowSegmentLSpecial::MotifCenterSlow(Int_t motifPositionId,
104 Double_t& x, Double_t& y) const
106 /// Fill the coordinates of the motif specified with
107 /// the given position identifier. \n
108 /// !! Applicable only for motifs that have their most down pad in
109 /// this row segment.
111 // Find the first (left, down) pad row segment with this motifPositionId.
112 AliMpVPadRowSegment* downPadRowSegment
113 = FindPadRowSegment(motifPositionId);
114 AliMpVPadRowSegment* rightPadRowSegment
115 = FindMostRightPadRowSegment(motifPositionId);
117 // Check if the motifPositionId is present
118 if (!downPadRowSegment || !rightPadRowSegment) {
119 AliErrorStream() << "Outside row segment region" << endl;
123 // Check if both pad row segments have the same motif
124 if (downPadRowSegment->GetMotif() != rightPadRowSegment->GetMotif()) {
125 AliFatal("Outside row segment region");
129 // Get position of found row segment
130 x = rightPadRowSegment->RightBorderX();
131 y = GetRow()->LowBorderY() ;
133 for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
134 y += GetPadRow(i)->HalfSizeY()*2.;
136 // Add motifs dimensions
137 x -= downPadRowSegment->GetMotif()->DimensionX();
138 y += downPadRowSegment->GetMotif()->DimensionY();
145 //______________________________________________________________________________
146 void AliMpRowSegmentLSpecial::UpdatePadsOffset()
148 /// Set low indices limit to the pad offset calculated
149 /// from the neighbour normal segment.
151 // Get the neighbour row segment
152 // (the first normal segment)
153 AliMpVRowSegment* neighbour = GetRow()->GetRowSegment(1);
155 // Get the the pads offset of the neighbour row segment
156 // (the first normal segment)
157 MpPair_t offset = neighbour->GetLowIndicesLimit();
159 // Find max nof pads in a row
160 Int_t maxNofPads = MaxNofPadsInRow();
163 SetLowIndicesLimit(offset - AliMp::Pair(maxNofPads, 0));
165 // Reset limits in the neighbour row segment
166 // (pad offset is now included in the special segment)
167 neighbour->SetLowIndicesLimit(0, neighbour->GetLowLimitIy());
170 //______________________________________________________________________________
171 Double_t AliMpRowSegmentLSpecial::LeftBorderX() const
173 /// Return the x coordinate of the left row segment border
174 /// in the global coordinate system.
176 Double_t leftBorder = DBL_MAX;
177 for (Int_t i=0; i<GetNofPadRows(); i++) {
178 AliMpPadRow* padRow = GetPadRow(i);
180 = padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX();
182 if (border < leftBorder) leftBorder = border;
188 //______________________________________________________________________________
189 Double_t AliMpRowSegmentLSpecial::RightBorderX() const
191 /// Returns the x coordinate of the right row segment border
192 /// in the global coordinate system.
194 Double_t sameBorder = GetOffsetX();
197 Double_t rightBorder = -DBL_MAX;
198 for (Int_t i=0; i<GetNofPadRows(); i++) {
199 AliMpPadRow* padRow = GetPadRow(i);
200 Double_t border = padRow->GetPadRowSegment(0)->RightBorderX();
201 if (border > rightBorder) rightBorder = border;
204 if (TMath::Abs(GetOffsetX() - rightBorder) > 1.e-04) {
205 AliErrorStream() << "WrongBorder" << endl;
212 //______________________________________________________________________________
213 Double_t AliMpRowSegmentLSpecial::GetPositionX() const
215 /// Return the x position of the row segment centre.
216 /// The centre is defined as the centre of the rectangular
217 /// row segment envelope.
219 return GetOffsetX() - GetDimensionX();
222 //______________________________________________________________________________
223 Double_t AliMpRowSegmentLSpecial::GetPositionY() const
225 /// Return the y position of the row segment centre.
226 /// The centre is defined as the centre of the rectangular
227 /// row segment envelope.
229 return GetRow()->GetPositionY();
232 #include <Riostream.h>
233 //______________________________________________________________________________
234 Int_t AliMpRowSegmentLSpecial::SetIndicesToMotifPosition(Int_t i, MpPair_t indices)
236 /// Set global indices to i-th motif position and returns next index in x.
238 // Get motif position
239 AliMpMotifPosition* motifPosition
240 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
244 = AliMp::Pair(GetLowLimitIx() + AliMpConstants::StartPadIndex(),
245 AliMp::PairSecond(indices))
246 + FindRelativeLowIndicesOf(GetMotifPositionId(i));
248 if (! motifPosition->IsHighLimitValid()) {
249 motifPosition->SetLowIndicesLimit(low);
252 if ( motifPosition->GetLowLimitIx() > AliMp::PairFirst(low) )
253 motifPosition->SetLowIndicesLimit(
254 AliMp::PairFirst(low),
255 motifPosition->GetLowLimitIy());
257 if ( motifPosition->GetLowLimitIy() > AliMp::PairSecond(low) )
258 motifPosition->SetLowIndicesLimit(
259 motifPosition->GetLowLimitIx(),
260 AliMp::PairSecond(low) );
264 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
266 = motifPosition->GetLowIndicesLimit()
267 + AliMp::Pair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
269 motifPosition->SetHighIndicesLimit(high);
271 // Increment index only if last motif position is processed
272 if ( i != GetNofMotifs()-1 )
273 return AliMp::PairFirst(indices);
276 return AliMp::PairFirst(indices) + MaxNofPadsInRow();
277 //return MaxNofPadsInRow();
279 //______________________________________________________________________________
280 void AliMpRowSegmentLSpecial::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.
287 Int_t ixl = GetLowLimitIx() + AliMpConstants::StartPadIndex();
288 // the pads offset was already defined by Reader
291 Int_t ixh = ixl + MaxNofPadsInRow() - 1;
294 Int_t iyl = AliMpConstants::StartPadIndex();
296 //if (constPadSizeDirection == kY) {
297 iyl = rowBefore->GetHighLimitIy()+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->GetHighLimitIy()+1;
311 Int_t iyh = iyl + GetNofPadRows() - 1;
313 SetLowIndicesLimit(ixl, iyl);
314 SetHighIndicesLimit(ixh, iyh);