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: AliMpMotif.cxx,v 1.8 2006/05/24 13:58:41 ivana Exp $
20 //-----------------------------------------------------------------------------
23 // Class that defines a motif with its unique ID
24 // and the motif type.
25 // Included in AliRoot: 2003/05/02
26 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 //-----------------------------------------------------------------------------
29 #include "AliMpMotif.h"
31 #include "AliMpConstants.h"
32 #include "AliMpIntPair.h"
33 #include "AliMpMotifType.h"
39 //_____________________________________________________________________________
40 AliMpMotif::AliMpMotif()
42 fPadDimensions(TVector2(0.,0.))
44 /// Default constructor
47 //_____________________________________________________________________________
48 AliMpMotif::AliMpMotif(const TString &id, AliMpMotifType *motifType,
49 const TVector2& padDimension)
50 : AliMpVMotif(id,motifType),
51 fPadDimensions(padDimension)
53 /// Standard constructor. \n
54 /// The dimension in a given direction is calculated by
55 /// multiplying the total dimension by the number of pads
58 //_____________________________________________________________________________
59 AliMpMotif::~AliMpMotif()
65 //_____________________________________________________________________________
66 TVector2 AliMpMotif::GetPadDimensions(const AliMpIntPair& localIndices) const
68 /// Give the dimension of the specified pad in the motif
70 if (GetMotifType()->HasPad(localIndices))
71 return fPadDimensions;
73 Warning("GetPadDimensions","indices outside range");
74 return TVector2(0.,0.);
78 //_____________________________________________________________________________
79 TVector2 AliMpMotif::Dimensions() const
81 /// Give the dimension of the motif
83 return TVector2(GetMotifType()->GetNofPadsX()*fPadDimensions.X(),
84 GetMotifType()->GetNofPadsY()*fPadDimensions.Y());
87 //_____________________________________________________________________________
88 TVector2 AliMpMotif::PadPositionLocal(const AliMpIntPair& localIndices) const
90 /// Give the local position of the pad number (ix,iy)
91 /// (0,0 is the center of the motif)
93 TVector2 dim=Dimensions();
94 return TVector2((2.*localIndices.GetFirst()+1.)*fPadDimensions.X()-dim.X(),
95 (2.*localIndices.GetSecond()+1.)*fPadDimensions.Y()-dim.Y());
98 //_____________________________________________________________________________
99 AliMpIntPair AliMpMotif::PadIndicesLocal(const TVector2& localPos) const
101 /// Return the pad indices from a given local position
102 /// or (-1,-1) if this position doesn't correspond to any valid
105 TVector2 lowerLeft(localPos);
107 lowerLeft += Dimensions();
109 if ( lowerLeft.X() < - AliMpConstants::LengthTolerance() ||
110 lowerLeft.Y() < - AliMpConstants::LengthTolerance() )
112 return AliMpIntPair::Invalid();
115 Int_t ix = (Int_t)(lowerLeft.X()/(2.*fPadDimensions.X()));
116 Int_t iy = (Int_t)(lowerLeft.Y()/(2.*fPadDimensions.Y()));
118 if (!GetMotifType()->FindConnectionByLocalIndices(AliMpIntPair(ix,iy)))
120 return AliMpIntPair::Invalid();
122 return AliMpIntPair(ix,iy);