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.8 2005/08/26 15:43:36 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
30 #include "AliMpRowSegment.h"
32 #include "AliMpVMotif.h"
33 #include "AliMpMotifType.h"
34 #include "AliMpMotifTypePadIterator.h"
35 #include "AliMpMotifMap.h"
36 #include "AliMpMotifPosition.h"
37 #include "AliMpConstants.h"
39 ClassImp(AliMpRowSegment)
41 //_____________________________________________________________________________
42 AliMpRowSegment::AliMpRowSegment(AliMpRow* row, AliMpVMotif* motif,
43 AliMpIntPair padOffset,
45 Int_t motifPositionId, Int_t motifPositionDId)
47 fNofMotifs(nofMotifs),
48 fPadOffset(padOffset),
52 fMotifPositionId(motifPositionId),
53 fMotifPositionDId(motifPositionDId)
55 /// Standard constructor
57 // Keep pad offset in the low indices limits
58 SetLowIndicesLimit(padOffset);
61 //_____________________________________________________________________________
62 AliMpRowSegment::AliMpRowSegment()
65 fPadOffset(AliMpIntPair()),
72 /// Default constructor
75 //_____________________________________________________________________________
76 AliMpRowSegment::AliMpRowSegment(const AliMpRowSegment& right)
77 : AliMpVRowSegment(right)
79 /// Protected copy constructor (not provided)
81 Fatal("AliMpRowSegment", "Copy constructor not provided.");
84 //_____________________________________________________________________________
85 AliMpRowSegment::~AliMpRowSegment()
94 //_____________________________________________________________________________
95 AliMpRowSegment& AliMpRowSegment::operator=(const AliMpRowSegment& right)
97 /// Protected assignment operator (not provided)
99 // check assignment to self
100 if (this == &right) return *this;
102 Fatal("operator =", "Assignment operator not provided.");
111 //_____________________________________________________________________________
112 Double_t AliMpRowSegment::FirstMotifCenterX() const
114 /// Return the x coordinate of the first motif center
115 /// in the global coordinate system.
120 //_____________________________________________________________________________
121 Double_t AliMpRowSegment::LastMotifCenterX() const
123 /// Return the x coordinate of the last motif center
124 /// in the global coordinate system.
126 return fOffset.X() + 2.*(fNofMotifs-1)*fMotif->Dimensions().X();
129 //_____________________________________________________________________________
130 Double_t AliMpRowSegment::MotifCenterX(Int_t motifPositionId) const
132 /// Return the x coordinate of the motif specified with
133 /// the given position identifier.
135 // Check if x is in the row segment range
136 if (! HasMotifPosition(motifPositionId)) {
137 Error("MotifCenterX", "Outside row segment region");
141 // Find the position number in the segment
142 Int_t num = (motifPositionId - fMotifPositionId) * fMotifPositionDId;
144 return fOffset.X() + num*(fMotif->Dimensions().X() * 2.0);
147 //_____________________________________________________________________________
148 Double_t AliMpRowSegment::MotifCenterY(Int_t motifPositionId) const
150 /// Return the y coordinate of the motif specified with
151 /// the given position identifier.
153 // Check if x is in the row segment range
154 if (! HasMotifPosition(motifPositionId)) {
155 Error("MotifCenterY", "Outside row segment region");
159 return GetRow()->Position().Y() + fOffset.Y();
162 //_____________________________________________________________________________
163 Bool_t AliMpRowSegment::IsInside(const TVector2& position, Bool_t warn) const
165 /// Check if the position is inside some motif of this row segment.
167 Double_t minY = GetRow()->Position().Y() + fOffset.Y() - fMotif->Dimensions().Y();
168 Double_t maxY = GetRow()->Position().Y() + fOffset.Y() + fMotif->Dimensions().Y();
170 if ( position.X() < LeftBorderX() || position.X() > RightBorderX() ||
171 position.Y() < minY || position.Y() > maxY ) {
173 if (warn) Error("MotifPositionId", "Outside row segment region");
184 //_____________________________________________________________________________
185 Double_t AliMpRowSegment::LeftBorderX() const
187 /// Return the x coordinate of the left row segment border
188 /// in the global coordinate system.
190 return FirstMotifCenterX() - fMotif->Dimensions().X();
193 //_____________________________________________________________________________
194 Double_t AliMpRowSegment::RightBorderX() const
196 /// Return the x coordinate of the right row segment border
197 /// in the global coordinate system.
199 return LastMotifCenterX() + fMotif->Dimensions().X();
202 //_____________________________________________________________________________
203 Double_t AliMpRowSegment::HalfSizeY() const
205 /// Return the size in y of this row segment.
207 return fMotif->Dimensions().Y() + fOffset.Y();
210 //_____________________________________________________________________________
211 AliMpVMotif* AliMpRowSegment::FindMotif(const TVector2& position) const
213 /// Return the motif of this row;
215 if (IsInside(position, false))
221 //_____________________________________________________________________________
222 Int_t AliMpRowSegment::FindMotifPositionId(const TVector2& position) const
224 /// Return the motif position identified for the given
225 /// geometric position.
227 if (!IsInside(position, false)) return 0;
229 // Find the position number in the segment
231 = Int_t((position.X() - LeftBorderX()) / (fMotif->Dimensions().X() * 2.0));
233 // Calculate the position Id
234 return fMotifPositionId + num*fMotifPositionDId;
237 //_____________________________________________________________________________
238 Bool_t AliMpRowSegment::HasMotifPosition(Int_t motifPositionId) const
240 /// Return true if the motif specified with the given position identifier
241 /// is in this segment.
243 Int_t minId = TMath::Min(fMotifPositionId,
244 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
245 Int_t maxId = TMath::Max(fMotifPositionId,
246 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
248 if (motifPositionId >= minId && motifPositionId <= maxId) {
255 //_____________________________________________________________________________
256 TVector2 AliMpRowSegment::MotifCenter(Int_t motifPositionId) const
258 /// Return the coordinates of the motif specified with
259 /// the given position identifier.
261 return TVector2(MotifCenterX(motifPositionId), MotifCenterY(motifPositionId));
264 //_____________________________________________________________________________
265 TVector2 AliMpRowSegment::Position() const
267 /// Return the position of the row segment centre.
269 Double_t x = (LeftBorderX() + RightBorderX())/2.;
270 Double_t y = GetRow()->Position().Y();
272 return TVector2(x, y);
276 //_____________________________________________________________________________
277 TVector2 AliMpRowSegment::Dimensions() const
279 /// Return the halflengths of the row segment in x, y.
282 Double_t x = (RightBorderX() - LeftBorderX())/2.;
283 Double_t y = GetRow()->Dimensions().Y();
285 return TVector2(x, y);
288 //_____________________________________________________________________________
289 void AliMpRowSegment::SetOffset(const TVector2& offset)
291 /// Calculate offset from given offset and
292 /// stored offset in pads.
294 AliMpMotifTypePadIterator iter(fMotif->GetMotifType());
296 AliMpIntPair localPos = iter.CurrentItem().GetIndices();
300 + 2.*fPadOffset.GetFirst() * fMotif->GetPadDimensions(localPos).X()
301 + fMotif->Dimensions().X();
305 + fPadOffset.GetSecond() * fMotif->GetPadDimensions(localPos).Y();
307 fOffset = TVector2(offsetX, offsetY);
310 #include <Riostream.h>
311 //_____________________________________________________________________________
312 void AliMpRowSegment::SetGlobalIndices(AliMpRow* /*rowBefore*/)
314 /// Set global indices limits.
316 // The low/high indices limits has to be taken as the highest/lowest from all
320 Int_t ixh = AliMpConstants::StartPadIndex();
321 Int_t iyh = AliMpConstants::StartPadIndex();
323 for (Int_t i=0; i<GetNofMotifs(); i++) {
325 AliMpMotifPosition* mPos
326 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
328 // Check if the motif positions has the limits set
329 if ( !mPos->HasValidIndices() )
330 Fatal("SetGlobalIndices",
331 "Indices of motif positions have to be set first.");
333 if ( mPos->GetLowIndicesLimit().GetFirst() < ixl )
334 ixl = mPos->GetLowIndicesLimit().GetFirst();
336 if ( mPos->GetLowIndicesLimit().GetSecond() < iyl )
337 iyl = mPos->GetLowIndicesLimit().GetSecond();
339 if ( mPos->GetHighIndicesLimit().GetFirst() > ixh )
340 ixh = mPos->GetHighIndicesLimit().GetFirst();
342 if ( mPos->GetHighIndicesLimit().GetSecond() > iyh )
343 iyh = mPos->GetHighIndicesLimit().GetSecond();
346 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
347 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));
350 //_____________________________________________________________________________
351 Int_t AliMpRowSegment::SetIndicesToMotifPosition(Int_t i,
352 const AliMpIntPair& indices)
354 /// Set global indices to i-th motif position and returns next index
357 // Get motif position
358 AliMpMotifPosition* motifPosition
359 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
362 AliMpIntPair low = indices + AliMpIntPair(0, GetLowIndicesLimit().GetSecond());
363 motifPosition->SetLowIndicesLimit(low);
366 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
368 = motifPosition->GetLowIndicesLimit()
369 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
370 motifPosition->SetHighIndicesLimit(high);
372 // Return next index in x
373 return high.GetFirst()+1;
374 // return motifType->GetNofPadsX();
378 //_____________________________________________________________________________
379 AliMpRow* AliMpRowSegment::GetRow() const
381 /// Return the row.which this row segment belongs to.
386 //_____________________________________________________________________________
387 Int_t AliMpRowSegment::GetNofMotifs() const
389 /// Return number of motifs in this this row segment.
394 //_____________________________________________________________________________
395 Int_t AliMpRowSegment::GetMotifPositionId(Int_t i) const
397 /// Return number of motifs in this this row segment.
399 return fMotifPositionId + i*fMotifPositionDId;
402 //_____________________________________________________________________________
403 AliMpVMotif* AliMpRowSegment::GetMotif(Int_t /*i*/) const
405 /// Return the motif of this row segment.