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: AliMpRowSegment.cxx,v 1.10 2006/05/24 13:58:46 ivana Exp $
20 //-----------------------------------------------------------------------------
21 // Class AliMpRowSegment
22 // ---------------------
23 // Class describing a row segment composed of the
24 // the identic motifs.
25 // Included in AliRoot: 2003/05/02
26 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 //-----------------------------------------------------------------------------
29 #include "AliMpRowSegment.h"
31 #include "AliMpVMotif.h"
32 #include "AliMpMotifType.h"
33 #include "AliMpMotifTypePadIterator.h"
34 #include "AliMpMotifMap.h"
35 #include "AliMpMotifPosition.h"
36 #include "AliMpConstants.h"
37 #include "AliMpEncodePair.h"
42 #include <Riostream.h>
45 ClassImp(AliMpRowSegment)
48 //_____________________________________________________________________________
49 AliMpRowSegment::AliMpRowSegment(AliMpRow* row, AliMpVMotif* motif,
50 Int_t padOffsetX, Int_t padOffsetY,
52 Int_t motifPositionId, Int_t motifPositionDId)
54 fNofMotifs(nofMotifs),
55 fLPadOffset(AliMp::Pair(padOffsetX,padOffsetY)),
60 fMotifPositionId(motifPositionId),
61 fMotifPositionDId(motifPositionDId)
63 /// Standard constructor
65 // Keep pad offset in the low indices limits
66 SetLowIndicesLimit(fLPadOffset);
69 //_____________________________________________________________________________
70 AliMpRowSegment::AliMpRowSegment()
81 /// Default constructor
84 //_____________________________________________________________________________
85 AliMpRowSegment::~AliMpRowSegment()
94 //_____________________________________________________________________________
95 Double_t AliMpRowSegment::FirstMotifCenterX() const
97 /// Return the x coordinate of the first motif center
98 /// in the global coordinate system.
103 //_____________________________________________________________________________
104 Double_t AliMpRowSegment::LastMotifCenterX() const
106 /// Return the x coordinate of the last motif center
107 /// in the global coordinate system.
109 return fOffsetX + 2.*(fNofMotifs-1)*fMotif->DimensionX();
112 //_____________________________________________________________________________
113 Double_t AliMpRowSegment::MotifCenterX(Int_t motifPositionId) const
115 /// Return the x coordinate of the motif specified with
116 /// the given position identifier.
118 // Check if x is in the row segment range
119 if (! HasMotifPosition(motifPositionId)) {
120 AliErrorStream() << "Outside row segment region" << endl;
124 // Find the position number in the segment
125 Int_t num = (motifPositionId - fMotifPositionId) * fMotifPositionDId;
127 return fOffsetX + num*(fMotif->DimensionX() * 2.0);
130 //_____________________________________________________________________________
131 Double_t AliMpRowSegment::MotifCenterY(Int_t motifPositionId) const
133 /// Return the y coordinate of the motif specified with
134 /// the given position identifier.
136 // Check if x is in the row segment range
137 if (! HasMotifPosition(motifPositionId)) {
138 AliErrorStream() << "Outside row segment region" << endl;
142 return GetRow()->GetPositionY() + fOffsetY;
145 //_____________________________________________________________________________
146 Bool_t AliMpRowSegment::IsInside(Double_t x, Double_t y, Bool_t warn) const
148 /// Check if the position is inside some motif of this row segment.
150 Double_t minY = GetRow()->GetPositionY() + fOffsetY - fMotif->DimensionY();
151 Double_t maxY = GetRow()->GetPositionY() + fOffsetY + fMotif->DimensionY();
153 if ( x < LeftBorderX() || x > RightBorderX() ||
154 y < minY || y > maxY ) {
157 AliWarningStream() << "Outside row segment region" << endl;
168 //_____________________________________________________________________________
169 Double_t AliMpRowSegment::LeftBorderX() const
171 /// Return the x coordinate of the left row segment border
172 /// in the global coordinate system.
174 return FirstMotifCenterX() - fMotif->DimensionX();
177 //_____________________________________________________________________________
178 Double_t AliMpRowSegment::RightBorderX() const
180 /// Return the x coordinate of the right row segment border
181 /// in the global coordinate system.
183 return LastMotifCenterX() + fMotif->DimensionX();
186 //_____________________________________________________________________________
187 Double_t AliMpRowSegment::HalfSizeY() const
189 /// Return the size in y of this row segment.
191 return fMotif->DimensionY() + fOffsetY;
194 //_____________________________________________________________________________
195 AliMpVMotif* AliMpRowSegment::FindMotif(Double_t x, Double_t y) const
197 /// Return the motif of this row;
199 if ( IsInside(x, y, false) )
205 //_____________________________________________________________________________
206 Int_t AliMpRowSegment::FindMotifPositionId(Double_t x, Double_t y) const
208 /// Return the motif position identified for the given
209 /// geometric position.
211 if ( ! IsInside(x, y, false) ) return 0;
213 // Find the position number in the segment
215 = Int_t((x - LeftBorderX()) / (fMotif->DimensionX() * 2.0));
217 // Calculate the position Id
218 return fMotifPositionId + num*fMotifPositionDId;
221 //_____________________________________________________________________________
222 Bool_t AliMpRowSegment::HasMotifPosition(Int_t motifPositionId) const
224 /// Return true if the motif specified with the given position identifier
225 /// is in this segment.
227 Int_t minId = TMath::Min(fMotifPositionId,
228 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
229 Int_t maxId = TMath::Max(fMotifPositionId,
230 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
232 if (motifPositionId >= minId && motifPositionId <= maxId) {
239 //_____________________________________________________________________________
240 void AliMpRowSegment::MotifCenter(Int_t motifPositionId,
241 Double_t& x, Double_t& y) const
243 /// Return the coordinates of the motif specified with
244 /// the given position identifier.
246 x = MotifCenterX(motifPositionId);
247 y = MotifCenterY(motifPositionId);
250 //_____________________________________________________________________________
251 Double_t AliMpRowSegment::GetPositionX() const
253 /// Return the x position of the row segment centre.
255 return (LeftBorderX() + RightBorderX())/2.;
258 //_____________________________________________________________________________
259 Double_t AliMpRowSegment::GetPositionY() const
261 /// Return the y position of the row segment centre.
263 return GetRow()->GetPositionY();
266 //_____________________________________________________________________________
267 Double_t AliMpRowSegment::GetDimensionX() const
269 /// Return the halflengths of the row segment in x, y.
272 return (RightBorderX() - LeftBorderX())/2.;
275 //_____________________________________________________________________________
276 Double_t AliMpRowSegment::GetDimensionY() const
278 /// Return the halflengths of the row segment in x, y.
281 return GetRow()->GetDimensionY();
284 //_____________________________________________________________________________
285 void AliMpRowSegment::SetOffset(Double_t x, Double_t y)
287 /// Calculate offset from given offset and
288 /// stored offset in pads.
290 AliMpMotifTypePadIterator iter(fMotif->GetMotifType());
293 Int_t ix = iter.CurrentItem().GetIx();
294 Int_t iy = iter.CurrentItem().GetIy();
297 fMotif->GetPadDimensionsByIndices(ix, iy, dx, dy);
300 = x + 2.*AliMp::PairFirst(fLPadOffset) * dx + fMotif->DimensionX();
303 = y + AliMp::PairSecond(fLPadOffset) * dy;
306 //_____________________________________________________________________________
307 void AliMpRowSegment::SetGlobalIndices(AliMpRow* /*rowBefore*/)
309 /// Set global indices limits.
311 // The low/high indices limits has to be taken as the highest/lowest from all
315 Int_t ixh = AliMpConstants::StartPadIndex();
316 Int_t iyh = AliMpConstants::StartPadIndex();
318 for (Int_t i=0; i<GetNofMotifs(); i++) {
320 AliMpMotifPosition* mPos
321 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
323 // Check if the motif positions has the limits set
324 if ( !mPos->HasValidIndices() )
325 Fatal("SetGlobalIndices",
326 "Indices of motif positions have to be set first.");
328 if ( mPos->GetLowLimitIx() < ixl )
329 ixl = mPos->GetLowLimitIx();
331 if ( mPos->GetLowLimitIy() < iyl )
332 iyl = mPos->GetLowLimitIy();
334 if ( mPos->GetHighLimitIx() > ixh )
335 ixh = mPos->GetHighLimitIx();
337 if ( mPos->GetHighLimitIy() > iyh )
338 iyh = mPos->GetHighLimitIy();
341 SetLowIndicesLimit(ixl, iyl);
342 SetHighIndicesLimit(ixh, iyh);
345 //_____________________________________________________________________________
346 Int_t AliMpRowSegment::SetIndicesToMotifPosition(Int_t i, MpPair_t indices)
348 /// Set global indices to i-th motif position and returns next index
351 // Get motif position
352 AliMpMotifPosition* motifPosition
353 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
356 MpPair_t low = indices + AliMp::Pair(0, GetLowLimitIy());
357 motifPosition->SetLowIndicesLimit(low);
360 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
362 = motifPosition->GetLowIndicesLimit()
363 + AliMp::Pair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
364 motifPosition->SetHighIndicesLimit(high);
366 // Return next index in x
367 return AliMp::PairFirst(high)+1;
368 // return motifType->GetNofPadsX();
372 //_____________________________________________________________________________
373 AliMpRow* AliMpRowSegment::GetRow() const
375 /// Return the row.which this row segment belongs to.
380 //_____________________________________________________________________________
381 Int_t AliMpRowSegment::GetNofMotifs() const
383 /// Return number of motifs in this this row segment.
388 //_____________________________________________________________________________
389 Int_t AliMpRowSegment::GetMotifPositionId(Int_t i) const
391 /// Return number of motifs in this this row segment.
393 return fMotifPositionId + i*fMotifPositionDId;
396 //_____________________________________________________________________________
397 AliMpVMotif* AliMpRowSegment::GetMotif(Int_t /*i*/) const
399 /// Return the motif of this row segment.