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"
37 #include "AliMpEncodePair.h"
42 #include <Riostream.h>
45 ClassImp(AliMpRowSegment)
48 //_____________________________________________________________________________
49 AliMpRowSegment::AliMpRowSegment(AliMpRow* row, AliMpVMotif* motif,
50 Int_t padOffsetX, Int_t padOffsetY,
52 Int_t motifPositionId, Int_t motifPositionDId)
54 fNofMotifs(nofMotifs),
55 fLPadOffset(AliMp::Pair(padOffsetX,padOffsetY)),
59 fMotifPositionId(motifPositionId),
60 fMotifPositionDId(motifPositionDId)
62 /// Standard constructor
64 // Keep pad offset in the low indices limits
65 SetLowIndicesLimit(fLPadOffset);
68 //_____________________________________________________________________________
69 AliMpRowSegment::AliMpRowSegment()
79 /// Default constructor
82 //_____________________________________________________________________________
83 AliMpRowSegment::~AliMpRowSegment()
92 //_____________________________________________________________________________
93 Double_t AliMpRowSegment::FirstMotifCenterX() const
95 /// Return the x coordinate of the first motif center
96 /// in the global coordinate system.
101 //_____________________________________________________________________________
102 Double_t AliMpRowSegment::LastMotifCenterX() const
104 /// Return the x coordinate of the last motif center
105 /// in the global coordinate system.
107 return fOffset.X() + 2.*(fNofMotifs-1)*fMotif->Dimensions().X();
110 //_____________________________________________________________________________
111 Double_t AliMpRowSegment::MotifCenterX(Int_t motifPositionId) const
113 /// Return the x coordinate of the motif specified with
114 /// the given position identifier.
116 // Check if x is in the row segment range
117 if (! HasMotifPosition(motifPositionId)) {
118 AliErrorStream() << "Outside row segment region" << endl;
122 // Find the position number in the segment
123 Int_t num = (motifPositionId - fMotifPositionId) * fMotifPositionDId;
125 return fOffset.X() + num*(fMotif->Dimensions().X() * 2.0);
128 //_____________________________________________________________________________
129 Double_t AliMpRowSegment::MotifCenterY(Int_t motifPositionId) const
131 /// Return the y coordinate of the motif specified with
132 /// the given position identifier.
134 // Check if x is in the row segment range
135 if (! HasMotifPosition(motifPositionId)) {
136 AliErrorStream() << "Outside row segment region" << endl;
140 return GetRow()->Position().Y() + fOffset.Y();
143 //_____________________________________________________________________________
144 Bool_t AliMpRowSegment::IsInside(const TVector2& position, Bool_t warn) const
146 /// Check if the position is inside some motif of this row segment.
148 Double_t minY = GetRow()->Position().Y() + fOffset.Y() - fMotif->Dimensions().Y();
149 Double_t maxY = GetRow()->Position().Y() + fOffset.Y() + fMotif->Dimensions().Y();
151 if ( position.X() < LeftBorderX() || position.X() > RightBorderX() ||
152 position.Y() < minY || position.Y() > maxY ) {
155 AliWarningStream() << "Outside row segment region" << endl;
166 //_____________________________________________________________________________
167 Double_t AliMpRowSegment::LeftBorderX() const
169 /// Return the x coordinate of the left row segment border
170 /// in the global coordinate system.
172 return FirstMotifCenterX() - fMotif->Dimensions().X();
175 //_____________________________________________________________________________
176 Double_t AliMpRowSegment::RightBorderX() const
178 /// Return the x coordinate of the right row segment border
179 /// in the global coordinate system.
181 return LastMotifCenterX() + fMotif->Dimensions().X();
184 //_____________________________________________________________________________
185 Double_t AliMpRowSegment::HalfSizeY() const
187 /// Return the size in y of this row segment.
189 return fMotif->Dimensions().Y() + fOffset.Y();
192 //_____________________________________________________________________________
193 AliMpVMotif* AliMpRowSegment::FindMotif(const TVector2& position) const
195 /// Return the motif of this row;
197 if (IsInside(position, false))
203 //_____________________________________________________________________________
204 Int_t AliMpRowSegment::FindMotifPositionId(const TVector2& position) const
206 /// Return the motif position identified for the given
207 /// geometric position.
209 if (!IsInside(position, false)) return 0;
211 // Find the position number in the segment
213 = Int_t((position.X() - LeftBorderX()) / (fMotif->Dimensions().X() * 2.0));
215 // Calculate the position Id
216 return fMotifPositionId + num*fMotifPositionDId;
219 //_____________________________________________________________________________
220 Bool_t AliMpRowSegment::HasMotifPosition(Int_t motifPositionId) const
222 /// Return true if the motif specified with the given position identifier
223 /// is in this segment.
225 Int_t minId = TMath::Min(fMotifPositionId,
226 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
227 Int_t maxId = TMath::Max(fMotifPositionId,
228 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
230 if (motifPositionId >= minId && motifPositionId <= maxId) {
237 //_____________________________________________________________________________
238 TVector2 AliMpRowSegment::MotifCenter(Int_t motifPositionId) const
240 /// Return the coordinates of the motif specified with
241 /// the given position identifier.
243 return TVector2(MotifCenterX(motifPositionId), MotifCenterY(motifPositionId));
246 //_____________________________________________________________________________
247 TVector2 AliMpRowSegment::Position() const
249 /// Return the position of the row segment centre.
251 Double_t x = (LeftBorderX() + RightBorderX())/2.;
252 Double_t y = GetRow()->Position().Y();
254 return TVector2(x, y);
258 //_____________________________________________________________________________
259 TVector2 AliMpRowSegment::Dimensions() const
261 /// Return the halflengths of the row segment in x, y.
264 Double_t x = (RightBorderX() - LeftBorderX())/2.;
265 Double_t y = GetRow()->Dimensions().Y();
267 return TVector2(x, y);
270 //_____________________________________________________________________________
271 void AliMpRowSegment::SetOffset(const TVector2& offset)
273 /// Calculate offset from given offset and
274 /// stored offset in pads.
276 AliMpMotifTypePadIterator iter(fMotif->GetMotifType());
279 Int_t ix = iter.CurrentItem().GetIx();
280 Int_t iy = iter.CurrentItem().GetIy();
284 + 2.*AliMp::PairFirst(fLPadOffset) * fMotif->GetPadDimensionsByIndices(ix, iy).X()
285 + fMotif->Dimensions().X();
289 + AliMp::PairSecond(fLPadOffset) * fMotif->GetPadDimensionsByIndices(ix, iy).Y();
291 fOffset = TVector2(offsetX, offsetY);
294 //_____________________________________________________________________________
295 void AliMpRowSegment::SetGlobalIndices(AliMpRow* /*rowBefore*/)
297 /// Set global indices limits.
299 // The low/high indices limits has to be taken as the highest/lowest from all
303 Int_t ixh = AliMpConstants::StartPadIndex();
304 Int_t iyh = AliMpConstants::StartPadIndex();
306 for (Int_t i=0; i<GetNofMotifs(); i++) {
308 AliMpMotifPosition* mPos
309 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
311 // Check if the motif positions has the limits set
312 if ( !mPos->HasValidIndices() )
313 Fatal("SetGlobalIndices",
314 "Indices of motif positions have to be set first.");
316 if ( mPos->GetLowLimitIx() < ixl )
317 ixl = mPos->GetLowLimitIx();
319 if ( mPos->GetLowLimitIy() < iyl )
320 iyl = mPos->GetLowLimitIy();
322 if ( mPos->GetHighLimitIx() > ixh )
323 ixh = mPos->GetHighLimitIx();
325 if ( mPos->GetHighLimitIy() > iyh )
326 iyh = mPos->GetHighLimitIy();
329 SetLowIndicesLimit(ixl, iyl);
330 SetHighIndicesLimit(ixh, iyh);
333 //_____________________________________________________________________________
334 Int_t AliMpRowSegment::SetIndicesToMotifPosition(Int_t i, MpPair_t indices)
336 /// Set global indices to i-th motif position and returns next index
339 // Get motif position
340 AliMpMotifPosition* motifPosition
341 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
344 MpPair_t low = indices + AliMp::Pair(0, GetLowLimitIy());
345 motifPosition->SetLowIndicesLimit(low);
348 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
350 = motifPosition->GetLowIndicesLimit()
351 + AliMp::Pair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
352 motifPosition->SetHighIndicesLimit(high);
354 // Return next index in x
355 return AliMp::PairFirst(high)+1;
356 // return motifType->GetNofPadsX();
360 //_____________________________________________________________________________
361 AliMpRow* AliMpRowSegment::GetRow() const
363 /// Return the row.which this row segment belongs to.
368 //_____________________________________________________________________________
369 Int_t AliMpRowSegment::GetNofMotifs() const
371 /// Return number of motifs in this this row segment.
376 //_____________________________________________________________________________
377 Int_t AliMpRowSegment::GetMotifPositionId(Int_t i) const
379 /// Return number of motifs in this this row segment.
381 return fMotifPositionId + i*fMotifPositionDId;
384 //_____________________________________________________________________________
385 AliMpVMotif* AliMpRowSegment::GetMotif(Int_t /*i*/) const
387 /// Return the motif of this row segment.