]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpRowSegment.cxx
mapping/AliMpPlaneSegmentation.cxx
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpRowSegment.cxx
CommitLineData
5f91c9e8 1// $Id$
2// Category: sector
3//
4// Class AliMpRowSegment
5// ---------------------
6// Class describing a row segment composed of the
7// the identic motifs.
dbe945cc 8// Included in AliRoot: 2003/05/02
5f91c9e8 9// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
10
11#include <TError.h>
12#include <TMath.h>
13
14#include "AliMpRowSegment.h"
15#include "AliMpRow.h"
16#include "AliMpVMotif.h"
17#include "AliMpMotifType.h"
18#include "AliMpMotifTypePadIterator.h"
19#include "AliMpMotifMap.h"
20#include "AliMpMotifPosition.h"
580c28fd 21#include "AliMpConstants.h"
5f91c9e8 22
23ClassImp(AliMpRowSegment)
24
25//_____________________________________________________________________________
26AliMpRowSegment::AliMpRowSegment(AliMpRow* row, AliMpVMotif* motif,
27 AliMpIntPair padOffset,
28 Int_t nofMotifs,
29 Int_t motifPositionId, Int_t motifPositionDId)
30 : AliMpVRowSegment(),
31 fNofMotifs(nofMotifs),
32 fPadOffset(padOffset),
33 fOffset(TVector2()),
34 fRow(row),
35 fMotif(motif),
36 fMotifPositionId(motifPositionId),
37 fMotifPositionDId(motifPositionDId)
38{
39//
40 // Keep pad offset in the low indices limits
41 SetLowIndicesLimit(padOffset);
42}
43
44//_____________________________________________________________________________
45AliMpRowSegment::AliMpRowSegment()
46 : AliMpVRowSegment(),
47 fNofMotifs(0),
48 fPadOffset(AliMpIntPair()),
49 fOffset(TVector2()),
50 fRow(0),
51 fMotif(0),
52 fMotifPositionId(0),
53 fMotifPositionDId(0)
54{
55//
56}
57
fb1bf5c0 58//_____________________________________________________________________________
59AliMpRowSegment::AliMpRowSegment(const AliMpRowSegment& right)
60 : AliMpVRowSegment(right) {
61//
62 Fatal("AliMpRowSegment", "Copy constructor not provided.");
63}
64
5f91c9e8 65//_____________________________________________________________________________
66AliMpRowSegment::~AliMpRowSegment() {
67//
68}
69
fb1bf5c0 70//
71// operators
72//
73
74//_____________________________________________________________________________
75AliMpRowSegment& AliMpRowSegment::operator=(const AliMpRowSegment& right)
76{
77 // check assignement to self
78 if (this == &right) return *this;
79
80 Fatal("operator =", "Assignement operator not provided.");
81
82 return *this;
83}
84
5f91c9e8 85//
86// private methods
87//
88
89//_____________________________________________________________________________
90Double_t AliMpRowSegment::FirstMotifCenterX() const
91{
92// Returns the x coordinate of the first motif center
93// in global coordinate system.
94// ---
95
96 return fOffset.X();
97}
98
99//_____________________________________________________________________________
100Double_t AliMpRowSegment::LastMotifCenterX() const
101{
102// Returns the x coordinate of the last motif center
103// in global coordinate system.
104// ---
105
106 return fOffset.X() + 2.*(fNofMotifs-1)*fMotif->Dimensions().X();
107}
108
109//_____________________________________________________________________________
110Double_t AliMpRowSegment::MotifCenterX(Int_t motifPositionId) const
111{
112// Returns the x coordinate of the motif specified with
113// the given position identifier.
114// ---
115
116 // Check if x is in the row segment range
117 if (! HasMotifPosition(motifPositionId)) {
118 Error("MotifCenterX", "Outside row segment region");
119 return 0;
120 }
121
122 // Find the position number in the segment
123 Int_t num = (motifPositionId - fMotifPositionId) * fMotifPositionDId;
124
125 return fOffset.X() + num*(fMotif->Dimensions().X() * 2.0);
126}
127
128//_____________________________________________________________________________
129Double_t AliMpRowSegment::MotifCenterY(Int_t motifPositionId) const
130{
131// Returns the y coordinate of the motif specified with
132// the given position identifier.
133// ---
134
135 // Check if x is in the row segment range
136 if (! HasMotifPosition(motifPositionId)) {
137 Error("MotifCenterY", "Outside row segment region");
138 return 0;
139 }
140
141 return GetRow()->Position().Y() + fOffset.Y();
142}
143
144//_____________________________________________________________________________
145Bool_t AliMpRowSegment::IsInside(const TVector2& position, Bool_t warn) const
146{
147// Checks if the position is inside some motif of this row segment.
148// ---
149
150 Double_t minY = GetRow()->Position().Y() + fOffset.Y() - fMotif->Dimensions().Y();
151 Double_t maxY = GetRow()->Position().Y() + fOffset.Y() + fMotif->Dimensions().Y();
152
153 if ( position.X() < LeftBorderX() || position.X() > RightBorderX() ||
154 position.Y() < minY || position.Y() > maxY ) {
155
156 if (warn) Error("MotifPositionId", "Outside row segment region");
157 return false;
158 }
159 else
160 return true;
161}
162
163//
164// public methods
165//
166
167//_____________________________________________________________________________
168Double_t AliMpRowSegment::LeftBorderX() const
169{
170// Returns the x coordinate of the left row segment border
171// in global coordinate system.
172// ---
173
174 return FirstMotifCenterX() - fMotif->Dimensions().X();
175}
176
177//_____________________________________________________________________________
178Double_t AliMpRowSegment::RightBorderX() const
179{
180// Returns the x coordinate of the right row segment border
181// in global coordinate system.
182// ---
183
184 return LastMotifCenterX() + fMotif->Dimensions().X();
185}
186
187//_____________________________________________________________________________
188Double_t AliMpRowSegment::HalfSizeY() const
189{
190// Returns the size in y of this row segment.
191// ---
192
193 return fMotif->Dimensions().Y() + fOffset.Y();
194}
195
196//_____________________________________________________________________________
197AliMpVMotif* AliMpRowSegment::FindMotif(const TVector2& position) const
198{
199// Returns the motif of this row;
200// ---
201
202 if (IsInside(position, false))
203 return fMotif;
204 else
205 return 0;
206}
207
208//_____________________________________________________________________________
209Int_t AliMpRowSegment::FindMotifPositionId(const TVector2& position) const
210{
211// Returns the motif position identified for the given
212// geometric position.
213// ---
214
215 if (!IsInside(position, false)) return 0;
216
217 // Find the position number in the segment
218 Int_t num
219 = Int_t((position.X() - LeftBorderX()) / (fMotif->Dimensions().X() * 2.0));
220
221 // Calculate the position Id
222 return fMotifPositionId + num*fMotifPositionDId;
223}
224
225//_____________________________________________________________________________
226Bool_t AliMpRowSegment::HasMotifPosition(Int_t motifPositionId) const
227{
228// Returns true if the motif specified with the given position identifier
229// is in this segment.
230// ---
231
232 Int_t minId = TMath::Min(fMotifPositionId,
233 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
234 Int_t maxId = TMath::Max(fMotifPositionId,
235 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
236
237 if (motifPositionId >= minId && motifPositionId <= maxId) {
238 return true;
239 }
240 else
241 return false;
242}
243
244//_____________________________________________________________________________
245TVector2 AliMpRowSegment::MotifCenter(Int_t motifPositionId) const
246{
247// Returns the coordinates of the motif specified with
248// the given position identifier.
249// ---
250
251 return TVector2(MotifCenterX(motifPositionId), MotifCenterY(motifPositionId));
252}
253
254//_____________________________________________________________________________
255TVector2 AliMpRowSegment::Position() const
256{
257// Returns the position of the row segment centre.
258// ---
259
260 Double_t x = (LeftBorderX() + RightBorderX())/2.;
261 Double_t y = GetRow()->Position().Y();
262
263 return TVector2(x, y);
264}
265
266
267//_____________________________________________________________________________
268TVector2 AliMpRowSegment::Dimensions() const
269{
270// Returns the halflengths of the row segment in x, y.
271// ---
272
273 Double_t x = (RightBorderX() - LeftBorderX())/2.;
274 Double_t y = GetRow()->Dimensions().Y();
275
276 return TVector2(x, y);
277}
278
279//_____________________________________________________________________________
280void AliMpRowSegment::SetOffset(const TVector2& offset)
281{
282// Calculates offset from given offset and
283// stored offset in pads.
284// ---
285
286 AliMpMotifTypePadIterator iter(fMotif->GetMotifType());
287 iter.First();
288 AliMpIntPair localPos = iter.CurrentItem().GetIndices();
289
290 Double_t offsetX
291 = offset.X()
292 + 2.*fPadOffset.GetFirst() * fMotif->GetPadDimensions(localPos).X()
293 + fMotif->Dimensions().X();
294
295 Double_t offsetY
296 = offset.Y()
297 + fPadOffset.GetSecond() * fMotif->GetPadDimensions(localPos).Y();
298
299 fOffset = TVector2(offsetX, offsetY);
300}
301
580c28fd 302#include <Riostream.h>
5f91c9e8 303//_____________________________________________________________________________
580c28fd 304void AliMpRowSegment::SetGlobalIndices(AliMpRow* /*rowBefore*/)
5f91c9e8 305{
306// Sets indices limits.
307// ---
308
580c28fd 309 // The low/high indices limits has to be taken as the highest/lowest from all
310 // motif positions
311 Int_t ixl = 9999;
312 Int_t iyl = 9999;
313 Int_t ixh = AliMpConstants::StartPadIndex();
314 Int_t iyh = AliMpConstants::StartPadIndex();
315
316 for (Int_t i=0; i<GetNofMotifs(); i++) {
317
318 AliMpMotifPosition* mPos
319 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
320
321 // Check if the motif positions has the limits set
322 if ( !mPos->HasValidIndices() )
323 Fatal("SetGlobalIndices",
324 "Indices of motif positions have to be set first.");
5f91c9e8 325
580c28fd 326 if ( mPos->GetLowIndicesLimit().GetFirst() < ixl )
327 ixl = mPos->GetLowIndicesLimit().GetFirst();
328
329 if ( mPos->GetLowIndicesLimit().GetSecond() < iyl )
330 iyl = mPos->GetLowIndicesLimit().GetSecond();
331
332 if ( mPos->GetHighIndicesLimit().GetFirst() > ixh )
333 ixh = mPos->GetHighIndicesLimit().GetFirst();
334
335 if ( mPos->GetHighIndicesLimit().GetSecond() > iyh )
336 iyh = mPos->GetHighIndicesLimit().GetSecond();
337 }
338
339 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
340 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));
5f91c9e8 341}
342
343//_____________________________________________________________________________
ffb47139 344Int_t AliMpRowSegment::SetIndicesToMotifPosition(Int_t i,
345 const AliMpIntPair& indices)
5f91c9e8 346{
347// Sets global indices to i-th motif position and returns next index
348// in x.
349// ---
350
351 // Get motif position
352 AliMpMotifPosition* motifPosition
353 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
354
355 // Low limit
356 AliMpIntPair low = indices + AliMpIntPair(0, GetLowIndicesLimit().GetSecond());
357 motifPosition->SetLowIndicesLimit(low);
358
359 // High limit
360 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
361 AliMpIntPair high
362 = motifPosition->GetLowIndicesLimit()
363 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
364 motifPosition->SetHighIndicesLimit(high);
365
366 // Return next index in x
367 return high.GetFirst()+1;
368 // return motifType->GetNofPadsX();
369}
370
371
372//_____________________________________________________________________________
373AliMpRow* AliMpRowSegment::GetRow() const
374{
375// Returns the row.which this row segment belongs to.
376// ---
377
378 return fRow;
379}
380
381//_____________________________________________________________________________
382Int_t AliMpRowSegment::GetNofMotifs() const
383{
384// Returns number of motifs in this this row segment.
385// ---
386
387 return fNofMotifs;
388}
389
390//_____________________________________________________________________________
391Int_t AliMpRowSegment::GetMotifPositionId(Int_t i) const
392{
393// Returns number of motifs in this this row segment.
394// ---
395
396 return fMotifPositionId + i*fMotifPositionDId;
397}
398
399//_____________________________________________________________________________
ffb47139 400AliMpVMotif* AliMpRowSegment::GetMotif(Int_t /*i*/) const
5f91c9e8 401{
402// Returns the motif of this row segment.
403// ---
404
405 return fMotif;
406}