New LinkDef (cmake)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotif.cxx
CommitLineData
dee1d5f1 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
5f91c9e8 16// $Id$
13985652 17// $MpId: AliMpMotif.cxx,v 1.8 2006/05/24 13:58:41 ivana Exp $
5f91c9e8 18// Category: motif
3d1463c8 19
20//-----------------------------------------------------------------------------
5f91c9e8 21// Class AliMpMotif
22// ----------------
23// Class that defines a motif with its unique ID
24// and the motif type.
dbe945cc 25// Included in AliRoot: 2003/05/02
5f91c9e8 26// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
3d1463c8 27//-----------------------------------------------------------------------------
5f91c9e8 28
29#include "AliMpMotif.h"
081259f6 30
31#include "AliMpConstants.h"
168e9c4d 32#include "AliMpEncodePair.h"
081259f6 33#include "AliMpMotifType.h"
5f91c9e8 34
13985652 35/// \cond CLASSIMP
5f91c9e8 36ClassImp(AliMpMotif)
13985652 37/// \endcond
5f91c9e8 38
39//_____________________________________________________________________________
40AliMpMotif::AliMpMotif()
41 : AliMpVMotif(),
42 fPadDimensions(TVector2(0.,0.))
43{
dee1d5f1 44 /// Default constructor
5f91c9e8 45}
46
47//_____________________________________________________________________________
48AliMpMotif::AliMpMotif(const TString &id, AliMpMotifType *motifType,
49 const TVector2& padDimension)
50 : AliMpVMotif(id,motifType),
51 fPadDimensions(padDimension)
52{
dee1d5f1 53 /// Standard constructor. \n
54 /// The dimension in a given direction is calculated by
55 /// multiplying the total dimension by the number of pads
5f91c9e8 56
57}
2998a151 58//_____________________________________________________________________________
59AliMpMotif::~AliMpMotif()
60{
dee1d5f1 61 /// Destructor
2998a151 62}
63
5f91c9e8 64
65//_____________________________________________________________________________
168e9c4d 66TVector2 AliMpMotif::GetPadDimensionsByIndices(MpPair_t localIndices) const
5f91c9e8 67{
dee1d5f1 68 /// Give the dimension of the specified pad in the motif
5f91c9e8 69
168e9c4d 70 if ( GetMotifType()->HasPadByLocalIndices(localIndices) )
5f91c9e8 71 return fPadDimensions;
72 else {
168e9c4d 73 Warning("GetPadDimensionsByIndices","indices outside range");
5f91c9e8 74 return TVector2(0.,0.);
75 }
76}
77
78//_____________________________________________________________________________
168e9c4d 79TVector2 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//_____________________________________________________________________________
5f91c9e8 87TVector2 AliMpMotif::Dimensions() const
88{
dee1d5f1 89 /// Give the dimension of the motif
5f91c9e8 90
91 return TVector2(GetMotifType()->GetNofPadsX()*fPadDimensions.X(),
92 GetMotifType()->GetNofPadsY()*fPadDimensions.Y());
93}
94
95//_____________________________________________________________________________
168e9c4d 96TVector2 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//_____________________________________________________________________________
106TVector2 AliMpMotif::PadPositionLocal(Int_t ixLocal, Int_t iyLocal) const
5f91c9e8 107{
dee1d5f1 108 /// Give the local position of the pad number (ix,iy)
109 /// (0,0 is the center of the motif)
5f91c9e8 110
111 TVector2 dim=Dimensions();
168e9c4d 112 return TVector2((2.*ixLocal+1.)*fPadDimensions.X()-dim.X(),
113 (2.*iyLocal+1.)*fPadDimensions.Y()-dim.Y());
5f91c9e8 114}
115
116//_____________________________________________________________________________
168e9c4d 117MpPair_t AliMpMotif::PadIndicesLocal(const TVector2& localPos) const
5f91c9e8 118{
dee1d5f1 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
5f91c9e8 122
6926db95 123 TVector2 lowerLeft(localPos);
124
125 lowerLeft += Dimensions();
dee1d5f1 126
081259f6 127 if ( lowerLeft.X() < - AliMpConstants::LengthTolerance() ||
128 lowerLeft.Y() < - AliMpConstants::LengthTolerance() )
dee1d5f1 129 {
168e9c4d 130 return -1;
dee1d5f1 131 }
132
5f91c9e8 133 Int_t ix = (Int_t)(lowerLeft.X()/(2.*fPadDimensions.X()));
134 Int_t iy = (Int_t)(lowerLeft.Y()/(2.*fPadDimensions.Y()));
135
168e9c4d 136 if ( ! GetMotifType()->FindConnectionByLocalIndices(ix,iy) )
081259f6 137 {
168e9c4d 138 return -1;
5f91c9e8 139 }
168e9c4d 140
141 return AliMp::Pair(ix,iy);
5f91c9e8 142}