4 // Class AliMpRowSegment
5 // ---------------------
6 // Class describing a row segment composed of the
8 // Included in AliRoot: 2003/05/02
9 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
14 #include "AliMpRowSegment.h"
16 #include "AliMpVMotif.h"
17 #include "AliMpMotifType.h"
18 #include "AliMpMotifTypePadIterator.h"
19 #include "AliMpMotifMap.h"
20 #include "AliMpMotifPosition.h"
22 ClassImp(AliMpRowSegment)
24 //_____________________________________________________________________________
25 AliMpRowSegment::AliMpRowSegment(AliMpRow* row, AliMpVMotif* motif,
26 AliMpIntPair padOffset,
28 Int_t motifPositionId, Int_t motifPositionDId)
30 fNofMotifs(nofMotifs),
31 fPadOffset(padOffset),
35 fMotifPositionId(motifPositionId),
36 fMotifPositionDId(motifPositionDId)
39 // Keep pad offset in the low indices limits
40 SetLowIndicesLimit(padOffset);
43 //_____________________________________________________________________________
44 AliMpRowSegment::AliMpRowSegment()
47 fPadOffset(AliMpIntPair()),
57 //_____________________________________________________________________________
58 AliMpRowSegment::AliMpRowSegment(const AliMpRowSegment& right)
59 : AliMpVRowSegment(right) {
61 Fatal("AliMpRowSegment", "Copy constructor not provided.");
64 //_____________________________________________________________________________
65 AliMpRowSegment::~AliMpRowSegment() {
73 //_____________________________________________________________________________
74 AliMpRowSegment& AliMpRowSegment::operator=(const AliMpRowSegment& right)
76 // check assignement to self
77 if (this == &right) return *this;
79 Fatal("operator =", "Assignement operator not provided.");
88 //_____________________________________________________________________________
89 Double_t AliMpRowSegment::FirstMotifCenterX() const
91 // Returns the x coordinate of the first motif center
92 // in global coordinate system.
98 //_____________________________________________________________________________
99 Double_t AliMpRowSegment::LastMotifCenterX() const
101 // Returns the x coordinate of the last motif center
102 // in global coordinate system.
105 return fOffset.X() + 2.*(fNofMotifs-1)*fMotif->Dimensions().X();
108 //_____________________________________________________________________________
109 Double_t AliMpRowSegment::MotifCenterX(Int_t motifPositionId) const
111 // Returns the x coordinate of the motif specified with
112 // the given position identifier.
115 // Check if x is in the row segment range
116 if (! HasMotifPosition(motifPositionId)) {
117 Error("MotifCenterX", "Outside row segment region");
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 // Returns the y coordinate of the motif specified with
131 // the given position identifier.
134 // Check if x is in the row segment range
135 if (! HasMotifPosition(motifPositionId)) {
136 Error("MotifCenterY", "Outside row segment region");
140 return GetRow()->Position().Y() + fOffset.Y();
143 //_____________________________________________________________________________
144 Bool_t AliMpRowSegment::IsInside(const TVector2& position, Bool_t warn) const
146 // Checks if the position is inside some motif of this row segment.
149 Double_t minY = GetRow()->Position().Y() + fOffset.Y() - fMotif->Dimensions().Y();
150 Double_t maxY = GetRow()->Position().Y() + fOffset.Y() + fMotif->Dimensions().Y();
152 if ( position.X() < LeftBorderX() || position.X() > RightBorderX() ||
153 position.Y() < minY || position.Y() > maxY ) {
155 if (warn) Error("MotifPositionId", "Outside row segment region");
166 //_____________________________________________________________________________
167 Double_t AliMpRowSegment::LeftBorderX() const
169 // Returns the x coordinate of the left row segment border
170 // in global coordinate system.
173 return FirstMotifCenterX() - fMotif->Dimensions().X();
176 //_____________________________________________________________________________
177 Double_t AliMpRowSegment::RightBorderX() const
179 // Returns the x coordinate of the right row segment border
180 // in global coordinate system.
183 return LastMotifCenterX() + fMotif->Dimensions().X();
186 //_____________________________________________________________________________
187 Double_t AliMpRowSegment::HalfSizeY() const
189 // Returns the size in y of this row segment.
192 return fMotif->Dimensions().Y() + fOffset.Y();
195 //_____________________________________________________________________________
196 AliMpVMotif* AliMpRowSegment::FindMotif(const TVector2& position) const
198 // Returns the motif of this row;
201 if (IsInside(position, false))
207 //_____________________________________________________________________________
208 Int_t AliMpRowSegment::FindMotifPositionId(const TVector2& position) const
210 // Returns the motif position identified for the given
211 // geometric position.
214 if (!IsInside(position, false)) return 0;
216 // Find the position number in the segment
218 = Int_t((position.X() - LeftBorderX()) / (fMotif->Dimensions().X() * 2.0));
220 // Calculate the position Id
221 return fMotifPositionId + num*fMotifPositionDId;
224 //_____________________________________________________________________________
225 Bool_t AliMpRowSegment::HasMotifPosition(Int_t motifPositionId) const
227 // Returns true if the motif specified with the given position identifier
228 // is in this segment.
231 Int_t minId = TMath::Min(fMotifPositionId,
232 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
233 Int_t maxId = TMath::Max(fMotifPositionId,
234 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
236 if (motifPositionId >= minId && motifPositionId <= maxId) {
243 //_____________________________________________________________________________
244 TVector2 AliMpRowSegment::MotifCenter(Int_t motifPositionId) const
246 // Returns the coordinates of the motif specified with
247 // the given position identifier.
250 return TVector2(MotifCenterX(motifPositionId), MotifCenterY(motifPositionId));
253 //_____________________________________________________________________________
254 TVector2 AliMpRowSegment::Position() const
256 // Returns the position of the row segment centre.
259 Double_t x = (LeftBorderX() + RightBorderX())/2.;
260 Double_t y = GetRow()->Position().Y();
262 return TVector2(x, y);
266 //_____________________________________________________________________________
267 TVector2 AliMpRowSegment::Dimensions() const
269 // Returns the halflengths of the row segment in x, y.
272 Double_t x = (RightBorderX() - LeftBorderX())/2.;
273 Double_t y = GetRow()->Dimensions().Y();
275 return TVector2(x, y);
278 //_____________________________________________________________________________
279 void AliMpRowSegment::SetOffset(const TVector2& offset)
281 // Calculates offset from given offset and
282 // stored offset in pads.
285 AliMpMotifTypePadIterator iter(fMotif->GetMotifType());
287 AliMpIntPair localPos = iter.CurrentItem().GetIndices();
291 + 2.*fPadOffset.GetFirst() * fMotif->GetPadDimensions(localPos).X()
292 + fMotif->Dimensions().X();
296 + fPadOffset.GetSecond() * fMotif->GetPadDimensions(localPos).Y();
298 fOffset = TVector2(offsetX, offsetY);
301 //_____________________________________________________________________________
302 void AliMpRowSegment::SetGlobalIndices()
304 // Sets indices limits.
307 AliMpMotifPosition* firstPos
308 = GetRow()->GetMotifMap()
309 ->FindMotifPosition(GetMotifPositionId(0));
311 AliMpMotifPosition* lastPos
312 = GetRow()->GetMotifMap()
313 ->FindMotifPosition(GetMotifPositionId(GetNofMotifs()-1));
315 // Check if the motif positions has the limits set
316 if ( !firstPos->HasValidIndices() || !lastPos->HasValidIndices())
317 Fatal("SetGlobalIndices", "Indices of motif positions have to be set first.");
319 SetLowIndicesLimit(firstPos->GetLowIndicesLimit());
320 SetHighIndicesLimit(lastPos->GetHighIndicesLimit());
323 //_____________________________________________________________________________
324 Int_t AliMpRowSegment::SetIndicesToMotifPosition(Int_t i,
325 const AliMpIntPair& indices)
327 // Sets global indices to i-th motif position and returns next index
331 // Get motif position
332 AliMpMotifPosition* motifPosition
333 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
336 AliMpIntPair low = indices + AliMpIntPair(0, GetLowIndicesLimit().GetSecond());
337 motifPosition->SetLowIndicesLimit(low);
340 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
342 = motifPosition->GetLowIndicesLimit()
343 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
344 motifPosition->SetHighIndicesLimit(high);
346 // Return next index in x
347 return high.GetFirst()+1;
348 // return motifType->GetNofPadsX();
352 //_____________________________________________________________________________
353 AliMpRow* AliMpRowSegment::GetRow() const
355 // Returns the row.which this row segment belongs to.
361 //_____________________________________________________________________________
362 Int_t AliMpRowSegment::GetNofMotifs() const
364 // Returns number of motifs in this this row segment.
370 //_____________________________________________________________________________
371 Int_t AliMpRowSegment::GetMotifPositionId(Int_t i) const
373 // Returns number of motifs in this this row segment.
376 return fMotifPositionId + i*fMotifPositionDId;
379 //_____________________________________________________________________________
380 AliMpVMotif* AliMpRowSegment::GetMotif(Int_t /*i*/) const
382 // Returns the motif of this row segment.