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>
46 ClassImp(AliMpRowSegment)
49 //_____________________________________________________________________________
50 AliMpRowSegment::AliMpRowSegment(AliMpRow* row, AliMpVMotif* motif,
51 Int_t padOffsetX, Int_t padOffsetY,
53 Int_t motifPositionId, Int_t motifPositionDId)
55 fNofMotifs(nofMotifs),
56 fLPadOffset(AliMp::Pair(padOffsetX,padOffsetY)),
61 fMotifPositionId(motifPositionId),
62 fMotifPositionDId(motifPositionDId)
64 /// Standard constructor
66 // Keep pad offset in the low indices limits
67 SetLowIndicesLimit(fLPadOffset);
70 //_____________________________________________________________________________
71 AliMpRowSegment::AliMpRowSegment()
82 /// Default constructor
85 //_____________________________________________________________________________
86 AliMpRowSegment::~AliMpRowSegment()
95 //_____________________________________________________________________________
96 Double_t AliMpRowSegment::FirstMotifCenterX() const
98 /// Return the x coordinate of the first motif center
99 /// in the global coordinate system.
104 //_____________________________________________________________________________
105 Double_t AliMpRowSegment::LastMotifCenterX() const
107 /// Return the x coordinate of the last motif center
108 /// in the global coordinate system.
110 return fOffsetX + 2.*(fNofMotifs-1)*fMotif->DimensionX();
113 //_____________________________________________________________________________
114 Double_t AliMpRowSegment::MotifCenterX(Int_t motifPositionId) const
116 /// Return the x coordinate of the motif specified with
117 /// the given position identifier.
119 // Check if x is in the row segment range
120 if (! HasMotifPosition(motifPositionId)) {
121 AliErrorStream() << "Outside row segment region" << endl;
125 // Find the position number in the segment
126 Int_t num = (motifPositionId - fMotifPositionId) * fMotifPositionDId;
128 return fOffsetX + num*(fMotif->DimensionX() * 2.0);
131 //_____________________________________________________________________________
132 Double_t AliMpRowSegment::MotifCenterY(Int_t motifPositionId) const
134 /// Return the y coordinate of the motif specified with
135 /// the given position identifier.
137 // Check if x is in the row segment range
138 if (! HasMotifPosition(motifPositionId)) {
139 AliErrorStream() << "Outside row segment region" << endl;
143 return GetRow()->GetPositionY() + fOffsetY;
146 //_____________________________________________________________________________
147 Bool_t AliMpRowSegment::IsInside(Double_t x, Double_t y, Bool_t warn) const
149 /// Check if the position is inside some motif of this row segment.
151 Double_t minY = GetRow()->GetPositionY() + fOffsetY - fMotif->DimensionY();
152 Double_t maxY = GetRow()->GetPositionY() + fOffsetY + fMotif->DimensionY();
154 if ( x < LeftBorderX() || x > RightBorderX() ||
155 y < minY || y > maxY ) {
158 AliWarningStream() << "Outside row segment region" << endl;
169 //_____________________________________________________________________________
170 Double_t AliMpRowSegment::LeftBorderX() const
172 /// Return the x coordinate of the left row segment border
173 /// in the global coordinate system.
175 return FirstMotifCenterX() - fMotif->DimensionX();
178 //_____________________________________________________________________________
179 Double_t AliMpRowSegment::RightBorderX() const
181 /// Return the x coordinate of the right row segment border
182 /// in the global coordinate system.
184 return LastMotifCenterX() + fMotif->DimensionX();
187 //_____________________________________________________________________________
188 Double_t AliMpRowSegment::HalfSizeY() const
190 /// Return the size in y of this row segment.
192 return fMotif->DimensionY() + fOffsetY;
195 //_____________________________________________________________________________
196 AliMpVMotif* AliMpRowSegment::FindMotif(Double_t x, Double_t y) const
198 /// Return the motif of this row;
200 if ( IsInside(x, y, false) )
206 //_____________________________________________________________________________
207 Int_t AliMpRowSegment::FindMotifPositionId(Double_t x, Double_t y) const
209 /// Return the motif position identified for the given
210 /// geometric position.
212 if ( ! IsInside(x, y, false) ) return 0;
214 // Find the position number in the segment
216 = Int_t((x - LeftBorderX()) / (fMotif->DimensionX() * 2.0));
218 // Calculate the position Id
219 return fMotifPositionId + num*fMotifPositionDId;
222 //_____________________________________________________________________________
223 Bool_t AliMpRowSegment::HasMotifPosition(Int_t motifPositionId) const
225 /// Return true if the motif specified with the given position identifier
226 /// is in this segment.
228 Int_t minId = TMath::Min(fMotifPositionId,
229 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
230 Int_t maxId = TMath::Max(fMotifPositionId,
231 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
233 if (motifPositionId >= minId && motifPositionId <= maxId) {
240 //_____________________________________________________________________________
241 void AliMpRowSegment::MotifCenter(Int_t motifPositionId,
242 Double_t& x, Double_t& y) const
244 /// Return the coordinates of the motif specified with
245 /// the given position identifier.
247 x = MotifCenterX(motifPositionId);
248 y = MotifCenterY(motifPositionId);
251 //_____________________________________________________________________________
252 Double_t AliMpRowSegment::GetPositionX() const
254 /// Return the x position of the row segment centre.
256 return (LeftBorderX() + RightBorderX())/2.;
259 //_____________________________________________________________________________
260 Double_t AliMpRowSegment::GetPositionY() const
262 /// Return the y position of the row segment centre.
264 return GetRow()->GetPositionY();
267 //_____________________________________________________________________________
268 Double_t AliMpRowSegment::GetDimensionX() const
270 /// Return the halflengths of the row segment in x, y.
273 return (RightBorderX() - LeftBorderX())/2.;
276 //_____________________________________________________________________________
277 Double_t AliMpRowSegment::GetDimensionY() const
279 /// Return the halflengths of the row segment in x, y.
282 return GetRow()->GetDimensionY();
285 //_____________________________________________________________________________
286 void AliMpRowSegment::SetOffset(Double_t x, Double_t y)
288 /// Calculate offset from given offset and
289 /// stored offset in pads.
291 AliMpMotifTypePadIterator iter(fMotif->GetMotifType());
294 Int_t ix = iter.CurrentItem().GetIx();
295 Int_t iy = iter.CurrentItem().GetIy();
298 fMotif->GetPadDimensionsByIndices(ix, iy, dx, dy);
301 = x + 2.*AliMp::PairFirst(fLPadOffset) * dx + fMotif->DimensionX();
304 = y + AliMp::PairSecond(fLPadOffset) * dy;
307 //_____________________________________________________________________________
308 void AliMpRowSegment::SetGlobalIndices(AliMpRow* /*rowBefore*/)
310 /// Set global indices limits.
312 // The low/high indices limits has to be taken as the highest/lowest from all
316 Int_t ixh = AliMpConstants::StartPadIndex();
317 Int_t iyh = AliMpConstants::StartPadIndex();
319 for (Int_t i=0; i<GetNofMotifs(); i++) {
321 AliMpMotifPosition* mPos
322 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
324 // Check if the motif positions has the limits set
325 if ( !mPos->HasValidIndices() )
326 Fatal("SetGlobalIndices",
327 "Indices of motif positions have to be set first.");
329 if ( mPos->GetLowLimitIx() < ixl )
330 ixl = mPos->GetLowLimitIx();
332 if ( mPos->GetLowLimitIy() < iyl )
333 iyl = mPos->GetLowLimitIy();
335 if ( mPos->GetHighLimitIx() > ixh )
336 ixh = mPos->GetHighLimitIx();
338 if ( mPos->GetHighLimitIy() > iyh )
339 iyh = mPos->GetHighLimitIy();
342 SetLowIndicesLimit(ixl, iyl);
343 SetHighIndicesLimit(ixh, iyh);
346 //_____________________________________________________________________________
347 Int_t AliMpRowSegment::SetIndicesToMotifPosition(Int_t i, MpPair_t indices)
349 /// Set global indices to i-th motif position and returns next index
352 // Get motif position
353 AliMpMotifPosition* motifPosition
354 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
357 MpPair_t low = indices + AliMp::Pair(0, GetLowLimitIy());
358 motifPosition->SetLowIndicesLimit(low);
361 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
363 = motifPosition->GetLowIndicesLimit()
364 + AliMp::Pair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
365 motifPosition->SetHighIndicesLimit(high);
367 // Return next index in x
368 return AliMp::PairFirst(high)+1;
369 // return motifType->GetNofPadsX();
373 //_____________________________________________________________________________
374 AliMpRow* AliMpRowSegment::GetRow() const
376 /// Return the row.which this row segment belongs to.
381 //_____________________________________________________________________________
382 Int_t AliMpRowSegment::GetNofMotifs() const
384 /// Return number of motifs in this this row segment.
389 //_____________________________________________________________________________
390 Int_t AliMpRowSegment::GetMotifPositionId(Int_t i) const
392 /// Return number of motifs in this this row segment.
394 return fMotifPositionId + i*fMotifPositionDId;
397 //_____________________________________________________________________________
398 AliMpVMotif* AliMpRowSegment::GetMotif(Int_t /*i*/) const
400 /// Return the motif of this row segment.