1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpRowSegment.cxx,v 1.10 2006/05/24 13:58:46 ivana Exp $
20 // Class AliMpRowSegment
21 // ---------------------
22 // Class describing a row segment composed of the
23 // the identic motifs.
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 #include "AliMpRowSegment.h"
29 #include "AliMpVMotif.h"
30 #include "AliMpMotifType.h"
31 #include "AliMpMotifTypePadIterator.h"
32 #include "AliMpMotifMap.h"
33 #include "AliMpMotifPosition.h"
34 #include "AliMpConstants.h"
37 #include <Riostream.h>
40 ClassImp(AliMpRowSegment)
43 //_____________________________________________________________________________
44 AliMpRowSegment::AliMpRowSegment(AliMpRow* row, AliMpVMotif* motif,
45 AliMpIntPair padOffset,
47 Int_t motifPositionId, Int_t motifPositionDId)
49 fNofMotifs(nofMotifs),
50 fPadOffset(padOffset),
54 fMotifPositionId(motifPositionId),
55 fMotifPositionDId(motifPositionDId)
57 /// Standard constructor
59 // Keep pad offset in the low indices limits
60 SetLowIndicesLimit(padOffset);
63 //_____________________________________________________________________________
64 AliMpRowSegment::AliMpRowSegment()
67 fPadOffset(AliMpIntPair()),
74 /// Default constructor
77 //_____________________________________________________________________________
78 AliMpRowSegment::~AliMpRowSegment()
87 //_____________________________________________________________________________
88 Double_t AliMpRowSegment::FirstMotifCenterX() const
90 /// Return the x coordinate of the first motif center
91 /// in the global coordinate system.
96 //_____________________________________________________________________________
97 Double_t AliMpRowSegment::LastMotifCenterX() const
99 /// Return the x coordinate of the last motif center
100 /// in the global coordinate system.
102 return fOffset.X() + 2.*(fNofMotifs-1)*fMotif->Dimensions().X();
105 //_____________________________________________________________________________
106 Double_t AliMpRowSegment::MotifCenterX(Int_t motifPositionId) const
108 /// Return the x coordinate of the motif specified with
109 /// the given position identifier.
111 // Check if x is in the row segment range
112 if (! HasMotifPosition(motifPositionId)) {
113 AliErrorStream() << "Outside row segment region" << endl;
117 // Find the position number in the segment
118 Int_t num = (motifPositionId - fMotifPositionId) * fMotifPositionDId;
120 return fOffset.X() + num*(fMotif->Dimensions().X() * 2.0);
123 //_____________________________________________________________________________
124 Double_t AliMpRowSegment::MotifCenterY(Int_t motifPositionId) const
126 /// Return the y coordinate of the motif specified with
127 /// the given position identifier.
129 // Check if x is in the row segment range
130 if (! HasMotifPosition(motifPositionId)) {
131 AliErrorStream() << "Outside row segment region" << endl;
135 return GetRow()->Position().Y() + fOffset.Y();
138 //_____________________________________________________________________________
139 Bool_t AliMpRowSegment::IsInside(const TVector2& position, Bool_t warn) const
141 /// Check if the position is inside some motif of this row segment.
143 Double_t minY = GetRow()->Position().Y() + fOffset.Y() - fMotif->Dimensions().Y();
144 Double_t maxY = GetRow()->Position().Y() + fOffset.Y() + fMotif->Dimensions().Y();
146 if ( position.X() < LeftBorderX() || position.X() > RightBorderX() ||
147 position.Y() < minY || position.Y() > maxY ) {
150 AliWarningStream() << "Outside row segment region" << endl;
161 //_____________________________________________________________________________
162 Double_t AliMpRowSegment::LeftBorderX() const
164 /// Return the x coordinate of the left row segment border
165 /// in the global coordinate system.
167 return FirstMotifCenterX() - fMotif->Dimensions().X();
170 //_____________________________________________________________________________
171 Double_t AliMpRowSegment::RightBorderX() const
173 /// Return the x coordinate of the right row segment border
174 /// in the global coordinate system.
176 return LastMotifCenterX() + fMotif->Dimensions().X();
179 //_____________________________________________________________________________
180 Double_t AliMpRowSegment::HalfSizeY() const
182 /// Return the size in y of this row segment.
184 return fMotif->Dimensions().Y() + fOffset.Y();
187 //_____________________________________________________________________________
188 AliMpVMotif* AliMpRowSegment::FindMotif(const TVector2& position) const
190 /// Return the motif of this row;
192 if (IsInside(position, false))
198 //_____________________________________________________________________________
199 Int_t AliMpRowSegment::FindMotifPositionId(const TVector2& position) const
201 /// Return the motif position identified for the given
202 /// geometric position.
204 if (!IsInside(position, false)) return 0;
206 // Find the position number in the segment
208 = Int_t((position.X() - LeftBorderX()) / (fMotif->Dimensions().X() * 2.0));
210 // Calculate the position Id
211 return fMotifPositionId + num*fMotifPositionDId;
214 //_____________________________________________________________________________
215 Bool_t AliMpRowSegment::HasMotifPosition(Int_t motifPositionId) const
217 /// Return true if the motif specified with the given position identifier
218 /// is in this segment.
220 Int_t minId = TMath::Min(fMotifPositionId,
221 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
222 Int_t maxId = TMath::Max(fMotifPositionId,
223 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
225 if (motifPositionId >= minId && motifPositionId <= maxId) {
232 //_____________________________________________________________________________
233 TVector2 AliMpRowSegment::MotifCenter(Int_t motifPositionId) const
235 /// Return the coordinates of the motif specified with
236 /// the given position identifier.
238 return TVector2(MotifCenterX(motifPositionId), MotifCenterY(motifPositionId));
241 //_____________________________________________________________________________
242 TVector2 AliMpRowSegment::Position() const
244 /// Return the position of the row segment centre.
246 Double_t x = (LeftBorderX() + RightBorderX())/2.;
247 Double_t y = GetRow()->Position().Y();
249 return TVector2(x, y);
253 //_____________________________________________________________________________
254 TVector2 AliMpRowSegment::Dimensions() const
256 /// Return the halflengths of the row segment in x, y.
259 Double_t x = (RightBorderX() - LeftBorderX())/2.;
260 Double_t y = GetRow()->Dimensions().Y();
262 return TVector2(x, y);
265 //_____________________________________________________________________________
266 void AliMpRowSegment::SetOffset(const TVector2& offset)
268 /// Calculate offset from given offset and
269 /// stored offset in pads.
271 AliMpMotifTypePadIterator iter(fMotif->GetMotifType());
273 AliMpIntPair localPos = iter.CurrentItem().GetIndices();
277 + 2.*fPadOffset.GetFirst() * fMotif->GetPadDimensions(localPos).X()
278 + fMotif->Dimensions().X();
282 + fPadOffset.GetSecond() * fMotif->GetPadDimensions(localPos).Y();
284 fOffset = TVector2(offsetX, offsetY);
287 #include <Riostream.h>
288 //_____________________________________________________________________________
289 void AliMpRowSegment::SetGlobalIndices(AliMpRow* /*rowBefore*/)
291 /// Set global indices limits.
293 // The low/high indices limits has to be taken as the highest/lowest from all
297 Int_t ixh = AliMpConstants::StartPadIndex();
298 Int_t iyh = AliMpConstants::StartPadIndex();
300 for (Int_t i=0; i<GetNofMotifs(); i++) {
302 AliMpMotifPosition* mPos
303 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
305 // Check if the motif positions has the limits set
306 if ( !mPos->HasValidIndices() )
307 Fatal("SetGlobalIndices",
308 "Indices of motif positions have to be set first.");
310 if ( mPos->GetLowIndicesLimit().GetFirst() < ixl )
311 ixl = mPos->GetLowIndicesLimit().GetFirst();
313 if ( mPos->GetLowIndicesLimit().GetSecond() < iyl )
314 iyl = mPos->GetLowIndicesLimit().GetSecond();
316 if ( mPos->GetHighIndicesLimit().GetFirst() > ixh )
317 ixh = mPos->GetHighIndicesLimit().GetFirst();
319 if ( mPos->GetHighIndicesLimit().GetSecond() > iyh )
320 iyh = mPos->GetHighIndicesLimit().GetSecond();
323 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
324 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));
327 //_____________________________________________________________________________
328 Int_t AliMpRowSegment::SetIndicesToMotifPosition(Int_t i,
329 const AliMpIntPair& indices)
331 /// Set global indices to i-th motif position and returns next index
334 // Get motif position
335 AliMpMotifPosition* motifPosition
336 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
339 AliMpIntPair low = indices + AliMpIntPair(0, GetLowIndicesLimit().GetSecond());
340 motifPosition->SetLowIndicesLimit(low);
343 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
345 = motifPosition->GetLowIndicesLimit()
346 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
347 motifPosition->SetHighIndicesLimit(high);
349 // Return next index in x
350 return high.GetFirst()+1;
351 // return motifType->GetNofPadsX();
355 //_____________________________________________________________________________
356 AliMpRow* AliMpRowSegment::GetRow() const
358 /// Return the row.which this row segment belongs to.
363 //_____________________________________________________________________________
364 Int_t AliMpRowSegment::GetNofMotifs() const
366 /// Return number of motifs in this this row segment.
371 //_____________________________________________________________________________
372 Int_t AliMpRowSegment::GetMotifPositionId(Int_t i) const
374 /// Return number of motifs in this this row segment.
376 return fMotifPositionId + i*fMotifPositionDId;
379 //_____________________________________________________________________________
380 AliMpVMotif* AliMpRowSegment::GetMotif(Int_t /*i*/) const
382 /// Return the motif of this row segment.