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