]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotif.cxx
Replacement of AliMpIntPair object with algoritmic
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotif.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 // $Id$
17 // $MpId: AliMpMotif.cxx,v 1.8 2006/05/24 13:58:41 ivana Exp $
18 // Category: motif
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpMotif
22 // ----------------
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 //-----------------------------------------------------------------------------
28
29 #include "AliMpMotif.h"
30
31 #include "AliMpConstants.h"
32 #include "AliMpEncodePair.h"
33 #include "AliMpMotifType.h"
34
35 /// \cond CLASSIMP
36 ClassImp(AliMpMotif)
37 /// \endcond
38
39 //_____________________________________________________________________________
40 AliMpMotif::AliMpMotif()
41   : AliMpVMotif(),
42     fPadDimensions(TVector2(0.,0.))
43 {
44   /// Default constructor
45 }
46
47 //_____________________________________________________________________________
48 AliMpMotif::AliMpMotif(const TString &id, AliMpMotifType *motifType,
49                        const TVector2& padDimension)
50   : AliMpVMotif(id,motifType),
51     fPadDimensions(padDimension)
52 {
53   /// Standard constructor.                                                \n
54   /// The dimension in a given direction is calculated by
55   /// multiplying the total dimension by the number of pads
56
57 }
58 //_____________________________________________________________________________
59 AliMpMotif::~AliMpMotif()
60 {
61   /// Destructor
62 }
63
64
65 //_____________________________________________________________________________
66 TVector2 AliMpMotif::GetPadDimensionsByIndices(MpPair_t localIndices) const
67 {
68   /// Give the dimension of the specified pad in the motif
69
70   if ( GetMotifType()->HasPadByLocalIndices(localIndices) )
71     return fPadDimensions;
72   else {
73     Warning("GetPadDimensionsByIndices","indices outside range");
74     return TVector2(0.,0.);
75   }
76 }
77
78 //_____________________________________________________________________________
79 TVector2 AliMpMotif::GetPadDimensionsByIndices(Int_t ixLocal, Int_t iyLocal) const
80 {
81   /// Give the dimension of the specified pad in the motif
82
83   return GetPadDimensionsByIndices(AliMp::Pair(ixLocal, iyLocal));
84 }
85
86 //_____________________________________________________________________________
87 TVector2 AliMpMotif::Dimensions() const
88 {
89   /// Give the dimension of the motif
90
91   return TVector2(GetMotifType()->GetNofPadsX()*fPadDimensions.X(),
92                 GetMotifType()->GetNofPadsY()*fPadDimensions.Y());
93 }
94
95 //_____________________________________________________________________________
96 TVector2 AliMpMotif::PadPositionLocal(MpPair_t localIndices) const 
97 {
98   /// Give the local position of the pad number (ix,iy)
99   /// (0,0 is the center of the motif)
100
101   return PadPositionLocal(AliMp::PairFirst(localIndices), 
102                           AliMp::PairSecond(localIndices));
103 }
104
105 //_____________________________________________________________________________
106 TVector2 AliMpMotif::PadPositionLocal(Int_t ixLocal, Int_t iyLocal) const 
107 {
108   /// Give the local position of the pad number (ix,iy)
109   /// (0,0 is the center of the motif)
110
111   TVector2 dim=Dimensions();
112   return TVector2((2.*ixLocal+1.)*fPadDimensions.X()-dim.X(),
113                   (2.*iyLocal+1.)*fPadDimensions.Y()-dim.Y());
114 }
115
116 //_____________________________________________________________________________
117 MpPair_t AliMpMotif::PadIndicesLocal(const TVector2& localPos) const
118 {
119   /// Return the pad indices from a given local position
120   /// or (-1,-1) if this position doesn't correspond to any valid
121   /// connection
122
123   TVector2 lowerLeft(localPos);
124   
125   lowerLeft += Dimensions();
126
127   if ( lowerLeft.X() < - AliMpConstants::LengthTolerance() || 
128        lowerLeft.Y() < - AliMpConstants::LengthTolerance() ) 
129     {
130       return -1;
131     }
132
133   Int_t ix = (Int_t)(lowerLeft.X()/(2.*fPadDimensions.X()));
134   Int_t iy = (Int_t)(lowerLeft.Y()/(2.*fPadDimensions.Y()));
135   
136   if ( ! GetMotifType()->FindConnectionByLocalIndices(ix,iy) )
137   {
138     return -1;
139   }
140   
141   return AliMp::Pair(ix,iy);
142 }