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(const AliMpRowSegment& right)
79 : AliMpVRowSegment(right)
81 /// Protected copy constructor (not provided)
83 Fatal("AliMpRowSegment", "Copy constructor not provided.");
86 //_____________________________________________________________________________
87 AliMpRowSegment::~AliMpRowSegment()
96 //_____________________________________________________________________________
97 AliMpRowSegment& AliMpRowSegment::operator=(const AliMpRowSegment& right)
99 /// Protected assignment operator (not provided)
101 // check assignment to self
102 if (this == &right) return *this;
104 Fatal("operator =", "Assignment operator not provided.");
113 //_____________________________________________________________________________
114 Double_t AliMpRowSegment::FirstMotifCenterX() const
116 /// Return the x coordinate of the first motif center
117 /// in the global coordinate system.
122 //_____________________________________________________________________________
123 Double_t AliMpRowSegment::LastMotifCenterX() const
125 /// Return the x coordinate of the last motif center
126 /// in the global coordinate system.
128 return fOffset.X() + 2.*(fNofMotifs-1)*fMotif->Dimensions().X();
131 //_____________________________________________________________________________
132 Double_t AliMpRowSegment::MotifCenterX(Int_t motifPositionId) const
134 /// Return the x coordinate of the motif specified with
135 /// the given position identifier.
137 // Check if x is in the row segment range
138 if (! HasMotifPosition(motifPositionId)) {
139 AliErrorStream() << "Outside row segment region" << endl;
143 // Find the position number in the segment
144 Int_t num = (motifPositionId - fMotifPositionId) * fMotifPositionDId;
146 return fOffset.X() + num*(fMotif->Dimensions().X() * 2.0);
149 //_____________________________________________________________________________
150 Double_t AliMpRowSegment::MotifCenterY(Int_t motifPositionId) const
152 /// Return the y coordinate of the motif specified with
153 /// the given position identifier.
155 // Check if x is in the row segment range
156 if (! HasMotifPosition(motifPositionId)) {
157 AliErrorStream() << "Outside row segment region" << endl;
161 return GetRow()->Position().Y() + fOffset.Y();
164 //_____________________________________________________________________________
165 Bool_t AliMpRowSegment::IsInside(const TVector2& position, Bool_t warn) const
167 /// Check if the position is inside some motif of this row segment.
169 Double_t minY = GetRow()->Position().Y() + fOffset.Y() - fMotif->Dimensions().Y();
170 Double_t maxY = GetRow()->Position().Y() + fOffset.Y() + fMotif->Dimensions().Y();
172 if ( position.X() < LeftBorderX() || position.X() > RightBorderX() ||
173 position.Y() < minY || position.Y() > maxY ) {
176 AliWarningStream() << "Outside row segment region" << endl;
187 //_____________________________________________________________________________
188 Double_t AliMpRowSegment::LeftBorderX() const
190 /// Return the x coordinate of the left row segment border
191 /// in the global coordinate system.
193 return FirstMotifCenterX() - fMotif->Dimensions().X();
196 //_____________________________________________________________________________
197 Double_t AliMpRowSegment::RightBorderX() const
199 /// Return the x coordinate of the right row segment border
200 /// in the global coordinate system.
202 return LastMotifCenterX() + fMotif->Dimensions().X();
205 //_____________________________________________________________________________
206 Double_t AliMpRowSegment::HalfSizeY() const
208 /// Return the size in y of this row segment.
210 return fMotif->Dimensions().Y() + fOffset.Y();
213 //_____________________________________________________________________________
214 AliMpVMotif* AliMpRowSegment::FindMotif(const TVector2& position) const
216 /// Return the motif of this row;
218 if (IsInside(position, false))
224 //_____________________________________________________________________________
225 Int_t AliMpRowSegment::FindMotifPositionId(const TVector2& position) const
227 /// Return the motif position identified for the given
228 /// geometric position.
230 if (!IsInside(position, false)) return 0;
232 // Find the position number in the segment
234 = Int_t((position.X() - LeftBorderX()) / (fMotif->Dimensions().X() * 2.0));
236 // Calculate the position Id
237 return fMotifPositionId + num*fMotifPositionDId;
240 //_____________________________________________________________________________
241 Bool_t AliMpRowSegment::HasMotifPosition(Int_t motifPositionId) const
243 /// Return true if the motif specified with the given position identifier
244 /// is in this segment.
246 Int_t minId = TMath::Min(fMotifPositionId,
247 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
248 Int_t maxId = TMath::Max(fMotifPositionId,
249 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
251 if (motifPositionId >= minId && motifPositionId <= maxId) {
258 //_____________________________________________________________________________
259 TVector2 AliMpRowSegment::MotifCenter(Int_t motifPositionId) const
261 /// Return the coordinates of the motif specified with
262 /// the given position identifier.
264 return TVector2(MotifCenterX(motifPositionId), MotifCenterY(motifPositionId));
267 //_____________________________________________________________________________
268 TVector2 AliMpRowSegment::Position() const
270 /// Return the position of the row segment centre.
272 Double_t x = (LeftBorderX() + RightBorderX())/2.;
273 Double_t y = GetRow()->Position().Y();
275 return TVector2(x, y);
279 //_____________________________________________________________________________
280 TVector2 AliMpRowSegment::Dimensions() const
282 /// Return the halflengths of the row segment in x, y.
285 Double_t x = (RightBorderX() - LeftBorderX())/2.;
286 Double_t y = GetRow()->Dimensions().Y();
288 return TVector2(x, y);
291 //_____________________________________________________________________________
292 void AliMpRowSegment::SetOffset(const TVector2& offset)
294 /// Calculate offset from given offset and
295 /// stored offset in pads.
297 AliMpMotifTypePadIterator iter(fMotif->GetMotifType());
299 AliMpIntPair localPos = iter.CurrentItem().GetIndices();
303 + 2.*fPadOffset.GetFirst() * fMotif->GetPadDimensions(localPos).X()
304 + fMotif->Dimensions().X();
308 + fPadOffset.GetSecond() * fMotif->GetPadDimensions(localPos).Y();
310 fOffset = TVector2(offsetX, offsetY);
313 #include <Riostream.h>
314 //_____________________________________________________________________________
315 void AliMpRowSegment::SetGlobalIndices(AliMpRow* /*rowBefore*/)
317 /// Set global indices limits.
319 // The low/high indices limits has to be taken as the highest/lowest from all
323 Int_t ixh = AliMpConstants::StartPadIndex();
324 Int_t iyh = AliMpConstants::StartPadIndex();
326 for (Int_t i=0; i<GetNofMotifs(); i++) {
328 AliMpMotifPosition* mPos
329 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
331 // Check if the motif positions has the limits set
332 if ( !mPos->HasValidIndices() )
333 Fatal("SetGlobalIndices",
334 "Indices of motif positions have to be set first.");
336 if ( mPos->GetLowIndicesLimit().GetFirst() < ixl )
337 ixl = mPos->GetLowIndicesLimit().GetFirst();
339 if ( mPos->GetLowIndicesLimit().GetSecond() < iyl )
340 iyl = mPos->GetLowIndicesLimit().GetSecond();
342 if ( mPos->GetHighIndicesLimit().GetFirst() > ixh )
343 ixh = mPos->GetHighIndicesLimit().GetFirst();
345 if ( mPos->GetHighIndicesLimit().GetSecond() > iyh )
346 iyh = mPos->GetHighIndicesLimit().GetSecond();
349 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
350 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));
353 //_____________________________________________________________________________
354 Int_t AliMpRowSegment::SetIndicesToMotifPosition(Int_t i,
355 const AliMpIntPair& indices)
357 /// Set global indices to i-th motif position and returns next index
360 // Get motif position
361 AliMpMotifPosition* motifPosition
362 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
365 AliMpIntPair low = indices + AliMpIntPair(0, GetLowIndicesLimit().GetSecond());
366 motifPosition->SetLowIndicesLimit(low);
369 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
371 = motifPosition->GetLowIndicesLimit()
372 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
373 motifPosition->SetHighIndicesLimit(high);
375 // Return next index in x
376 return high.GetFirst()+1;
377 // return motifType->GetNofPadsX();
381 //_____________________________________________________________________________
382 AliMpRow* AliMpRowSegment::GetRow() const
384 /// Return the row.which this row segment belongs to.
389 //_____________________________________________________________________________
390 Int_t AliMpRowSegment::GetNofMotifs() const
392 /// Return number of motifs in this this row segment.
397 //_____________________________________________________________________________
398 Int_t AliMpRowSegment::GetMotifPositionId(Int_t i) const
400 /// Return number of motifs in this this row segment.
402 return fMotifPositionId + i*fMotifPositionDId;
405 //_____________________________________________________________________________
406 AliMpVMotif* AliMpRowSegment::GetMotif(Int_t /*i*/) const
408 /// Return the motif of this row segment.