]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpTransformer.cxx
new class AliMUONLoader
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpTransformer.cxx
CommitLineData
5f91c9e8 1// $Id$
2// Category: basic
3//
4// Class AliMpTransformer
5// ------------------------
6// Class contains definition of transformation and
7// provides functions for transforming pads.
8//
9// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
10
11#include "AliMpTransformer.h"
12
13ClassImp(AliMpTransformer)
14
15///_____________________________________________________________________________
16AliMpTransformer::AliMpTransformer(const TVector2& offset,
17 const AliMpIntPair& scale)
18 : TObject(),
19 fOffset(offset),
20 fScale(scale)
21{
22//
23}
24
25///_____________________________________________________________________________
26AliMpTransformer::AliMpTransformer()
27 : TObject(),
28 fOffset(TVector2()),
29 fScale(AliMpIntPair(1,1))
30{
31//
32}
33
34//_____________________________________________________________________________
35AliMpTransformer::~AliMpTransformer() {
36//
37}
38
39//
40// private methods
41//
42
43//_____________________________________________________________________________
44void AliMpTransformer::CutInterval(Double_t x1, Double_t x2, Double_t x0,
45 Double_t s, Double_t& pos, Double_t& dx) const
46{
47// Cuts the interval <x1,x2> into <x1', x2'>
48// by position x0 in direction of s*x.
49// Returns the centre of the new interval (pos) and its half size.
50// ---
51
52 // Transform values
53
54 Double_t sx0 = s * x0;
55 Double_t sx1 = s * x1;
56 Double_t sx2 = s * x2;
57
58 if (s < 0) {
59 // when inversion, replace x1 and x2
60 Double_t tmp = sx1;
61 sx1 = sx2;
62 sx2 = tmp;
63 }
64
65 if (sx0 > sx2) {
66 // the interval outside region
67 pos = 0.;
68 dx = -1.;
69 }
70 else if (sx0 > sx1) {
71 // x0 cuts the interval
72 dx = (sx2 - sx0)/2.;
73 pos = s * (sx0 + dx);
74 }
75 else {
76 // the interval inside region
77 dx = (sx2 - sx1)/2.;
78 pos = s * ((sx2 + sx1)/2.);
79 }
80}
81
82//
83// public methods
84//
85
86//_____________________________________________________________________________
87AliMpIntPair AliMpTransformer::Scale(const AliMpIntPair& pair) const
88{
89// Returns the pair with values scaled by the given scale.
90// ---
91
92 return pair * fScale;
93}
94
95//_____________________________________________________________________________
96TVector2 AliMpTransformer::Scale(const TVector2& vector) const
97{
98// Returns vector with values scaled by the given scale.
99// ---
100
101 return TVector2(vector.X()*fScale.GetFirst(), vector.Y()*fScale.GetSecond());
102}
103
104//_____________________________________________________________________________
105AliMpIntPair AliMpTransformer::ScaleLocation(const AliMpIntPair& orig) const
106{
107// Returns location with values scaled by the given scale.
108// ---
109
110 return AliMpIntPair(orig.GetFirst() * fScale.GetSecond(), orig.GetSecond(),
111 orig.IsValid());
112}
113
114//_____________________________________________________________________________
115AliMpPad AliMpTransformer::Scale(const AliMpPad& pad) const
116{
117// Returns pad with indices scaled by the given scale.
118// ---
119
120 return AliMpPad(ScaleLocation(pad.GetLocation()),
121 Scale(pad.GetIndices()),
122 Scale(pad.Position()),
123 pad.Dimensions(),
124 pad.IsValid());
125}
126
127//_____________________________________________________________________________
128TVector2 AliMpTransformer::Transform(const TVector2& vector) const
129{
130// Transforms given vector with scale and corresponding translation
131// from sector (local) to plane (global).
132// ---
133
134 return Scale(vector) + fOffset;
135}
136
137//_____________________________________________________________________________
138TVector2 AliMpTransformer::ITransform(const TVector2& vector) const
139{
140// Transforms given vector with scale and corresponding translation
141// from plane (global) to sector (local).
142// ---
143
144 return Scale(vector - fOffset);
145}
146
147//_____________________________________________________________________________
148AliMpPad AliMpTransformer::Transform(const AliMpPad& pad) const
149{
150// Returns pad with characteristics transformed with given scale and
151// corresponding translation from sector (local) to plane (global).
152// ---
153
154 return AliMpPad(ScaleLocation(pad.GetLocation()),
155 Scale(pad.GetIndices()),
156 Transform(pad.Position()),
157 pad.Dimensions(),
158 pad.IsValid());
159}
160
161
162//_____________________________________________________________________________
163AliMpPad AliMpTransformer::ITransform(const AliMpPad& pad) const
164{
165// Returns pad with characteristics transformed with given scale and
166// corresponding translation from plane (global) to sector (local).
167// ---
168
169 return AliMpPad(ScaleLocation(pad.GetLocation()),
170 Scale(pad.GetIndices()),
171 ITransform(pad.Position()),
172 pad.Dimensions(),
173 pad.IsValid());
174}
175
176//_____________________________________________________________________________
177AliMpArea AliMpTransformer::CutArea(const AliMpArea& area) const
178{
179// Cuts the area with its offset in the quadrant defined by scale
180// and transforms its position into its local system.
181// ---
182
183 Double_t posx, dx;
184 CutInterval(area.LeftBorder(), area.RightBorder(), fOffset.X(),
185 fScale.GetFirst(), posx, dx);
186
187 Double_t posy, dy;
188 CutInterval(area.DownBorder(), area.UpBorder(), fOffset.Y(),
189 fScale.GetSecond(), posy, dy);
190
191 return AliMpArea(ITransform(TVector2(posx, posy)), TVector2(dx, dy));
192}