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"
39 #include <Riostream.h>
42 ClassImp(AliMpRowSegment)
45 //_____________________________________________________________________________
46 AliMpRowSegment::AliMpRowSegment(AliMpRow* row, AliMpVMotif* motif,
47 AliMpIntPair padOffset,
49 Int_t motifPositionId, Int_t motifPositionDId)
51 fNofMotifs(nofMotifs),
52 fPadOffset(padOffset),
56 fMotifPositionId(motifPositionId),
57 fMotifPositionDId(motifPositionDId)
59 /// Standard constructor
61 // Keep pad offset in the low indices limits
62 SetLowIndicesLimit(padOffset);
65 //_____________________________________________________________________________
66 AliMpRowSegment::AliMpRowSegment()
69 fPadOffset(AliMpIntPair()),
76 /// Default constructor
79 //_____________________________________________________________________________
80 AliMpRowSegment::~AliMpRowSegment()
89 //_____________________________________________________________________________
90 Double_t AliMpRowSegment::FirstMotifCenterX() const
92 /// Return the x coordinate of the first motif center
93 /// in the global coordinate system.
98 //_____________________________________________________________________________
99 Double_t AliMpRowSegment::LastMotifCenterX() const
101 /// Return the x coordinate of the last motif center
102 /// in the global coordinate system.
104 return fOffset.X() + 2.*(fNofMotifs-1)*fMotif->Dimensions().X();
107 //_____________________________________________________________________________
108 Double_t AliMpRowSegment::MotifCenterX(Int_t motifPositionId) const
110 /// Return the x coordinate of the motif specified with
111 /// the given position identifier.
113 // Check if x is in the row segment range
114 if (! HasMotifPosition(motifPositionId)) {
115 AliErrorStream() << "Outside row segment region" << endl;
119 // Find the position number in the segment
120 Int_t num = (motifPositionId - fMotifPositionId) * fMotifPositionDId;
122 return fOffset.X() + num*(fMotif->Dimensions().X() * 2.0);
125 //_____________________________________________________________________________
126 Double_t AliMpRowSegment::MotifCenterY(Int_t motifPositionId) const
128 /// Return the y coordinate of the motif specified with
129 /// the given position identifier.
131 // Check if x is in the row segment range
132 if (! HasMotifPosition(motifPositionId)) {
133 AliErrorStream() << "Outside row segment region" << endl;
137 return GetRow()->Position().Y() + fOffset.Y();
140 //_____________________________________________________________________________
141 Bool_t AliMpRowSegment::IsInside(const TVector2& position, Bool_t warn) const
143 /// Check if the position is inside some motif of this row segment.
145 Double_t minY = GetRow()->Position().Y() + fOffset.Y() - fMotif->Dimensions().Y();
146 Double_t maxY = GetRow()->Position().Y() + fOffset.Y() + fMotif->Dimensions().Y();
148 if ( position.X() < LeftBorderX() || position.X() > RightBorderX() ||
149 position.Y() < minY || position.Y() > maxY ) {
152 AliWarningStream() << "Outside row segment region" << endl;
163 //_____________________________________________________________________________
164 Double_t AliMpRowSegment::LeftBorderX() const
166 /// Return the x coordinate of the left row segment border
167 /// in the global coordinate system.
169 return FirstMotifCenterX() - fMotif->Dimensions().X();
172 //_____________________________________________________________________________
173 Double_t AliMpRowSegment::RightBorderX() const
175 /// Return the x coordinate of the right row segment border
176 /// in the global coordinate system.
178 return LastMotifCenterX() + fMotif->Dimensions().X();
181 //_____________________________________________________________________________
182 Double_t AliMpRowSegment::HalfSizeY() const
184 /// Return the size in y of this row segment.
186 return fMotif->Dimensions().Y() + fOffset.Y();
189 //_____________________________________________________________________________
190 AliMpVMotif* AliMpRowSegment::FindMotif(const TVector2& position) const
192 /// Return the motif of this row;
194 if (IsInside(position, false))
200 //_____________________________________________________________________________
201 Int_t AliMpRowSegment::FindMotifPositionId(const TVector2& position) const
203 /// Return the motif position identified for the given
204 /// geometric position.
206 if (!IsInside(position, false)) return 0;
208 // Find the position number in the segment
210 = Int_t((position.X() - LeftBorderX()) / (fMotif->Dimensions().X() * 2.0));
212 // Calculate the position Id
213 return fMotifPositionId + num*fMotifPositionDId;
216 //_____________________________________________________________________________
217 Bool_t AliMpRowSegment::HasMotifPosition(Int_t motifPositionId) const
219 /// Return true if the motif specified with the given position identifier
220 /// is in this segment.
222 Int_t minId = TMath::Min(fMotifPositionId,
223 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
224 Int_t maxId = TMath::Max(fMotifPositionId,
225 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
227 if (motifPositionId >= minId && motifPositionId <= maxId) {
234 //_____________________________________________________________________________
235 TVector2 AliMpRowSegment::MotifCenter(Int_t motifPositionId) const
237 /// Return the coordinates of the motif specified with
238 /// the given position identifier.
240 return TVector2(MotifCenterX(motifPositionId), MotifCenterY(motifPositionId));
243 //_____________________________________________________________________________
244 TVector2 AliMpRowSegment::Position() const
246 /// Return the position of the row segment centre.
248 Double_t x = (LeftBorderX() + RightBorderX())/2.;
249 Double_t y = GetRow()->Position().Y();
251 return TVector2(x, y);
255 //_____________________________________________________________________________
256 TVector2 AliMpRowSegment::Dimensions() const
258 /// Return the halflengths of the row segment in x, y.
261 Double_t x = (RightBorderX() - LeftBorderX())/2.;
262 Double_t y = GetRow()->Dimensions().Y();
264 return TVector2(x, y);
267 //_____________________________________________________________________________
268 void AliMpRowSegment::SetOffset(const TVector2& offset)
270 /// Calculate offset from given offset and
271 /// stored offset in pads.
273 AliMpMotifTypePadIterator iter(fMotif->GetMotifType());
275 AliMpIntPair localPos = iter.CurrentItem().GetIndices();
279 + 2.*fPadOffset.GetFirst() * fMotif->GetPadDimensions(localPos).X()
280 + fMotif->Dimensions().X();
284 + fPadOffset.GetSecond() * fMotif->GetPadDimensions(localPos).Y();
286 fOffset = TVector2(offsetX, offsetY);
289 #include <Riostream.h>
290 //_____________________________________________________________________________
291 void AliMpRowSegment::SetGlobalIndices(AliMpRow* /*rowBefore*/)
293 /// Set global indices limits.
295 // The low/high indices limits has to be taken as the highest/lowest from all
299 Int_t ixh = AliMpConstants::StartPadIndex();
300 Int_t iyh = AliMpConstants::StartPadIndex();
302 for (Int_t i=0; i<GetNofMotifs(); i++) {
304 AliMpMotifPosition* mPos
305 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
307 // Check if the motif positions has the limits set
308 if ( !mPos->HasValidIndices() )
309 Fatal("SetGlobalIndices",
310 "Indices of motif positions have to be set first.");
312 if ( mPos->GetLowIndicesLimit().GetFirst() < ixl )
313 ixl = mPos->GetLowIndicesLimit().GetFirst();
315 if ( mPos->GetLowIndicesLimit().GetSecond() < iyl )
316 iyl = mPos->GetLowIndicesLimit().GetSecond();
318 if ( mPos->GetHighIndicesLimit().GetFirst() > ixh )
319 ixh = mPos->GetHighIndicesLimit().GetFirst();
321 if ( mPos->GetHighIndicesLimit().GetSecond() > iyh )
322 iyh = mPos->GetHighIndicesLimit().GetSecond();
325 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
326 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));
329 //_____________________________________________________________________________
330 Int_t AliMpRowSegment::SetIndicesToMotifPosition(Int_t i,
331 const AliMpIntPair& indices)
333 /// Set global indices to i-th motif position and returns next index
336 // Get motif position
337 AliMpMotifPosition* motifPosition
338 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
341 AliMpIntPair low = indices + AliMpIntPair(0, GetLowIndicesLimit().GetSecond());
342 motifPosition->SetLowIndicesLimit(low);
345 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
347 = motifPosition->GetLowIndicesLimit()
348 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
349 motifPosition->SetHighIndicesLimit(high);
351 // Return next index in x
352 return high.GetFirst()+1;
353 // return motifType->GetNofPadsX();
357 //_____________________________________________________________________________
358 AliMpRow* AliMpRowSegment::GetRow() const
360 /// Return the row.which this row segment belongs to.
365 //_____________________________________________________________________________
366 Int_t AliMpRowSegment::GetNofMotifs() const
368 /// Return number of motifs in this this row segment.
373 //_____________________________________________________________________________
374 Int_t AliMpRowSegment::GetMotifPositionId(Int_t i) const
376 /// Return number of motifs in this this row segment.
378 return fMotifPositionId + i*fMotifPositionDId;
381 //_____________________________________________________________________________
382 AliMpVMotif* AliMpRowSegment::GetMotif(Int_t /*i*/) const
384 /// Return the motif of this row segment.