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 //-----------------------------------------------------------------------------
21 // Class AliMpRowSegment
22 // ---------------------
23 // Class describing a row segment composed of the
24 // the identic motifs.
25 // Included in AliRoot: 2003/05/02
26 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 //-----------------------------------------------------------------------------
29 #include "AliMpRowSegment.h"
31 #include "AliMpVMotif.h"
32 #include "AliMpMotifType.h"
33 #include "AliMpMotifTypePadIterator.h"
34 #include "AliMpMotifMap.h"
35 #include "AliMpMotifPosition.h"
36 #include "AliMpConstants.h"
41 #include <Riostream.h>
44 ClassImp(AliMpRowSegment)
47 //_____________________________________________________________________________
48 AliMpRowSegment::AliMpRowSegment(AliMpRow* row, AliMpVMotif* motif,
49 AliMpIntPair padOffset,
51 Int_t motifPositionId, Int_t motifPositionDId)
53 fNofMotifs(nofMotifs),
54 fPadOffset(padOffset),
58 fMotifPositionId(motifPositionId),
59 fMotifPositionDId(motifPositionDId)
61 /// Standard constructor
63 // Keep pad offset in the low indices limits
64 SetLowIndicesLimit(padOffset);
67 //_____________________________________________________________________________
68 AliMpRowSegment::AliMpRowSegment()
71 fPadOffset(AliMpIntPair()),
78 /// Default constructor
81 //_____________________________________________________________________________
82 AliMpRowSegment::~AliMpRowSegment()
91 //_____________________________________________________________________________
92 Double_t AliMpRowSegment::FirstMotifCenterX() const
94 /// Return the x coordinate of the first motif center
95 /// in the global coordinate system.
100 //_____________________________________________________________________________
101 Double_t AliMpRowSegment::LastMotifCenterX() const
103 /// Return the x coordinate of the last motif center
104 /// in the global coordinate system.
106 return fOffset.X() + 2.*(fNofMotifs-1)*fMotif->Dimensions().X();
109 //_____________________________________________________________________________
110 Double_t AliMpRowSegment::MotifCenterX(Int_t motifPositionId) const
112 /// Return the x coordinate of the motif specified with
113 /// the given position identifier.
115 // Check if x is in the row segment range
116 if (! HasMotifPosition(motifPositionId)) {
117 AliErrorStream() << "Outside row segment region" << endl;
121 // Find the position number in the segment
122 Int_t num = (motifPositionId - fMotifPositionId) * fMotifPositionDId;
124 return fOffset.X() + num*(fMotif->Dimensions().X() * 2.0);
127 //_____________________________________________________________________________
128 Double_t AliMpRowSegment::MotifCenterY(Int_t motifPositionId) const
130 /// Return the y coordinate of the motif specified with
131 /// the given position identifier.
133 // Check if x is in the row segment range
134 if (! HasMotifPosition(motifPositionId)) {
135 AliErrorStream() << "Outside row segment region" << endl;
139 return GetRow()->Position().Y() + fOffset.Y();
142 //_____________________________________________________________________________
143 Bool_t AliMpRowSegment::IsInside(const TVector2& position, Bool_t warn) const
145 /// Check if the position is inside some motif of this row segment.
147 Double_t minY = GetRow()->Position().Y() + fOffset.Y() - fMotif->Dimensions().Y();
148 Double_t maxY = GetRow()->Position().Y() + fOffset.Y() + fMotif->Dimensions().Y();
150 if ( position.X() < LeftBorderX() || position.X() > RightBorderX() ||
151 position.Y() < minY || position.Y() > maxY ) {
154 AliWarningStream() << "Outside row segment region" << endl;
165 //_____________________________________________________________________________
166 Double_t AliMpRowSegment::LeftBorderX() const
168 /// Return the x coordinate of the left row segment border
169 /// in the global coordinate system.
171 return FirstMotifCenterX() - fMotif->Dimensions().X();
174 //_____________________________________________________________________________
175 Double_t AliMpRowSegment::RightBorderX() const
177 /// Return the x coordinate of the right row segment border
178 /// in the global coordinate system.
180 return LastMotifCenterX() + fMotif->Dimensions().X();
183 //_____________________________________________________________________________
184 Double_t AliMpRowSegment::HalfSizeY() const
186 /// Return the size in y of this row segment.
188 return fMotif->Dimensions().Y() + fOffset.Y();
191 //_____________________________________________________________________________
192 AliMpVMotif* AliMpRowSegment::FindMotif(const TVector2& position) const
194 /// Return the motif of this row;
196 if (IsInside(position, false))
202 //_____________________________________________________________________________
203 Int_t AliMpRowSegment::FindMotifPositionId(const TVector2& position) const
205 /// Return the motif position identified for the given
206 /// geometric position.
208 if (!IsInside(position, false)) return 0;
210 // Find the position number in the segment
212 = Int_t((position.X() - LeftBorderX()) / (fMotif->Dimensions().X() * 2.0));
214 // Calculate the position Id
215 return fMotifPositionId + num*fMotifPositionDId;
218 //_____________________________________________________________________________
219 Bool_t AliMpRowSegment::HasMotifPosition(Int_t motifPositionId) const
221 /// Return true if the motif specified with the given position identifier
222 /// is in this segment.
224 Int_t minId = TMath::Min(fMotifPositionId,
225 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
226 Int_t maxId = TMath::Max(fMotifPositionId,
227 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
229 if (motifPositionId >= minId && motifPositionId <= maxId) {
236 //_____________________________________________________________________________
237 TVector2 AliMpRowSegment::MotifCenter(Int_t motifPositionId) const
239 /// Return the coordinates of the motif specified with
240 /// the given position identifier.
242 return TVector2(MotifCenterX(motifPositionId), MotifCenterY(motifPositionId));
245 //_____________________________________________________________________________
246 TVector2 AliMpRowSegment::Position() const
248 /// Return the position of the row segment centre.
250 Double_t x = (LeftBorderX() + RightBorderX())/2.;
251 Double_t y = GetRow()->Position().Y();
253 return TVector2(x, y);
257 //_____________________________________________________________________________
258 TVector2 AliMpRowSegment::Dimensions() const
260 /// Return the halflengths of the row segment in x, y.
263 Double_t x = (RightBorderX() - LeftBorderX())/2.;
264 Double_t y = GetRow()->Dimensions().Y();
266 return TVector2(x, y);
269 //_____________________________________________________________________________
270 void AliMpRowSegment::SetOffset(const TVector2& offset)
272 /// Calculate offset from given offset and
273 /// stored offset in pads.
275 AliMpMotifTypePadIterator iter(fMotif->GetMotifType());
277 AliMpIntPair localPos = iter.CurrentItem().GetIndices();
281 + 2.*fPadOffset.GetFirst() * fMotif->GetPadDimensions(localPos).X()
282 + fMotif->Dimensions().X();
286 + fPadOffset.GetSecond() * fMotif->GetPadDimensions(localPos).Y();
288 fOffset = TVector2(offsetX, offsetY);
291 #include <Riostream.h>
292 //_____________________________________________________________________________
293 void AliMpRowSegment::SetGlobalIndices(AliMpRow* /*rowBefore*/)
295 /// Set global indices limits.
297 // The low/high indices limits has to be taken as the highest/lowest from all
301 Int_t ixh = AliMpConstants::StartPadIndex();
302 Int_t iyh = AliMpConstants::StartPadIndex();
304 for (Int_t i=0; i<GetNofMotifs(); i++) {
306 AliMpMotifPosition* mPos
307 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
309 // Check if the motif positions has the limits set
310 if ( !mPos->HasValidIndices() )
311 Fatal("SetGlobalIndices",
312 "Indices of motif positions have to be set first.");
314 if ( mPos->GetLowIndicesLimit().GetFirst() < ixl )
315 ixl = mPos->GetLowIndicesLimit().GetFirst();
317 if ( mPos->GetLowIndicesLimit().GetSecond() < iyl )
318 iyl = mPos->GetLowIndicesLimit().GetSecond();
320 if ( mPos->GetHighIndicesLimit().GetFirst() > ixh )
321 ixh = mPos->GetHighIndicesLimit().GetFirst();
323 if ( mPos->GetHighIndicesLimit().GetSecond() > iyh )
324 iyh = mPos->GetHighIndicesLimit().GetSecond();
327 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
328 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));
331 //_____________________________________________________________________________
332 Int_t AliMpRowSegment::SetIndicesToMotifPosition(Int_t i,
333 const AliMpIntPair& indices)
335 /// Set global indices to i-th motif position and returns next index
338 // Get motif position
339 AliMpMotifPosition* motifPosition
340 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
343 AliMpIntPair low = indices + AliMpIntPair(0, GetLowIndicesLimit().GetSecond());
344 motifPosition->SetLowIndicesLimit(low);
347 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
349 = motifPosition->GetLowIndicesLimit()
350 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
351 motifPosition->SetHighIndicesLimit(high);
353 // Return next index in x
354 return high.GetFirst()+1;
355 // return motifType->GetNofPadsX();
359 //_____________________________________________________________________________
360 AliMpRow* AliMpRowSegment::GetRow() const
362 /// Return the row.which this row segment belongs to.
367 //_____________________________________________________________________________
368 Int_t AliMpRowSegment::GetNofMotifs() const
370 /// Return number of motifs in this this row segment.
375 //_____________________________________________________________________________
376 Int_t AliMpRowSegment::GetMotifPositionId(Int_t i) const
378 /// Return number of motifs in this this row segment.
380 return fMotifPositionId + i*fMotifPositionDId;
383 //_____________________________________________________________________________
384 AliMpVMotif* AliMpRowSegment::GetMotif(Int_t /*i*/) const
386 /// Return the motif of this row segment.