4 // Class AliMpRowSegment
5 // ---------------------
6 // Class describing a row segment composed of the
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() {
66 //_____________________________________________________________________________
67 Double_t AliMpRowSegment::FirstMotifCenterX() const
69 // Returns the x coordinate of the first motif center
70 // in global coordinate system.
76 //_____________________________________________________________________________
77 Double_t AliMpRowSegment::LastMotifCenterX() const
79 // Returns the x coordinate of the last motif center
80 // in global coordinate system.
83 return fOffset.X() + 2.*(fNofMotifs-1)*fMotif->Dimensions().X();
86 //_____________________________________________________________________________
87 Double_t AliMpRowSegment::MotifCenterX(Int_t motifPositionId) const
89 // Returns the x coordinate of the motif specified with
90 // the given position identifier.
93 // Check if x is in the row segment range
94 if (! HasMotifPosition(motifPositionId)) {
95 Error("MotifCenterX", "Outside row segment region");
99 // Find the position number in the segment
100 Int_t num = (motifPositionId - fMotifPositionId) * fMotifPositionDId;
102 return fOffset.X() + num*(fMotif->Dimensions().X() * 2.0);
105 //_____________________________________________________________________________
106 Double_t AliMpRowSegment::MotifCenterY(Int_t motifPositionId) const
108 // Returns the y coordinate of the motif specified with
109 // the given position identifier.
112 // Check if x is in the row segment range
113 if (! HasMotifPosition(motifPositionId)) {
114 Error("MotifCenterY", "Outside row segment region");
118 return GetRow()->Position().Y() + fOffset.Y();
121 //_____________________________________________________________________________
122 Bool_t AliMpRowSegment::IsInside(const TVector2& position, Bool_t warn) const
124 // Checks if the position is inside some motif of this row segment.
127 Double_t minY = GetRow()->Position().Y() + fOffset.Y() - fMotif->Dimensions().Y();
128 Double_t maxY = GetRow()->Position().Y() + fOffset.Y() + fMotif->Dimensions().Y();
130 if ( position.X() < LeftBorderX() || position.X() > RightBorderX() ||
131 position.Y() < minY || position.Y() > maxY ) {
133 if (warn) Error("MotifPositionId", "Outside row segment region");
144 //_____________________________________________________________________________
145 Double_t AliMpRowSegment::LeftBorderX() const
147 // Returns the x coordinate of the left row segment border
148 // in global coordinate system.
151 return FirstMotifCenterX() - fMotif->Dimensions().X();
154 //_____________________________________________________________________________
155 Double_t AliMpRowSegment::RightBorderX() const
157 // Returns the x coordinate of the right row segment border
158 // in global coordinate system.
161 return LastMotifCenterX() + fMotif->Dimensions().X();
164 //_____________________________________________________________________________
165 Double_t AliMpRowSegment::HalfSizeY() const
167 // Returns the size in y of this row segment.
170 return fMotif->Dimensions().Y() + fOffset.Y();
173 //_____________________________________________________________________________
174 AliMpVMotif* AliMpRowSegment::FindMotif(const TVector2& position) const
176 // Returns the motif of this row;
179 if (IsInside(position, false))
185 //_____________________________________________________________________________
186 Int_t AliMpRowSegment::FindMotifPositionId(const TVector2& position) const
188 // Returns the motif position identified for the given
189 // geometric position.
192 if (!IsInside(position, false)) return 0;
194 // Find the position number in the segment
196 = Int_t((position.X() - LeftBorderX()) / (fMotif->Dimensions().X() * 2.0));
198 // Calculate the position Id
199 return fMotifPositionId + num*fMotifPositionDId;
202 //_____________________________________________________________________________
203 Bool_t AliMpRowSegment::HasMotifPosition(Int_t motifPositionId) const
205 // Returns true if the motif specified with the given position identifier
206 // is in this segment.
209 Int_t minId = TMath::Min(fMotifPositionId,
210 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
211 Int_t maxId = TMath::Max(fMotifPositionId,
212 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
214 if (motifPositionId >= minId && motifPositionId <= maxId) {
221 //_____________________________________________________________________________
222 TVector2 AliMpRowSegment::MotifCenter(Int_t motifPositionId) const
224 // Returns the coordinates of the motif specified with
225 // the given position identifier.
228 return TVector2(MotifCenterX(motifPositionId), MotifCenterY(motifPositionId));
231 //_____________________________________________________________________________
232 TVector2 AliMpRowSegment::Position() const
234 // Returns the position of the row segment centre.
237 Double_t x = (LeftBorderX() + RightBorderX())/2.;
238 Double_t y = GetRow()->Position().Y();
240 return TVector2(x, y);
244 //_____________________________________________________________________________
245 TVector2 AliMpRowSegment::Dimensions() const
247 // Returns the halflengths of the row segment in x, y.
250 Double_t x = (RightBorderX() - LeftBorderX())/2.;
251 Double_t y = GetRow()->Dimensions().Y();
253 return TVector2(x, y);
256 //_____________________________________________________________________________
257 void AliMpRowSegment::SetOffset(const TVector2& offset)
259 // Calculates offset from given offset and
260 // stored offset in pads.
263 AliMpMotifTypePadIterator iter(fMotif->GetMotifType());
265 AliMpIntPair localPos = iter.CurrentItem().GetIndices();
269 + 2.*fPadOffset.GetFirst() * fMotif->GetPadDimensions(localPos).X()
270 + fMotif->Dimensions().X();
274 + fPadOffset.GetSecond() * fMotif->GetPadDimensions(localPos).Y();
276 fOffset = TVector2(offsetX, offsetY);
279 //_____________________________________________________________________________
280 void AliMpRowSegment::SetGlobalIndices()
282 // Sets indices limits.
285 AliMpMotifPosition* firstPos
286 = GetRow()->GetMotifMap()
287 ->FindMotifPosition(GetMotifPositionId(0));
289 AliMpMotifPosition* lastPos
290 = GetRow()->GetMotifMap()
291 ->FindMotifPosition(GetMotifPositionId(GetNofMotifs()-1));
293 // Check if the motif positions has the limits set
294 if ( !firstPos->HasValidIndices() || !lastPos->HasValidIndices())
295 Fatal("SetGlobalIndices", "Indices of motif positions have to be set first.");
297 SetLowIndicesLimit(firstPos->GetLowIndicesLimit());
298 SetHighIndicesLimit(lastPos->GetHighIndicesLimit());
301 //_____________________________________________________________________________
302 Int_t AliMpRowSegment::SetIndicesToMotifPosition(Int_t i,
303 const AliMpIntPair& indices)
305 // Sets global indices to i-th motif position and returns next index
309 // Get motif position
310 AliMpMotifPosition* motifPosition
311 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
314 AliMpIntPair low = indices + AliMpIntPair(0, GetLowIndicesLimit().GetSecond());
315 motifPosition->SetLowIndicesLimit(low);
318 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
320 = motifPosition->GetLowIndicesLimit()
321 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
322 motifPosition->SetHighIndicesLimit(high);
324 // Return next index in x
325 return high.GetFirst()+1;
326 // return motifType->GetNofPadsX();
330 //_____________________________________________________________________________
331 AliMpRow* AliMpRowSegment::GetRow() const
333 // Returns the row.which this row segment belongs to.
339 //_____________________________________________________________________________
340 Int_t AliMpRowSegment::GetNofMotifs() const
342 // Returns number of motifs in this this row segment.
348 //_____________________________________________________________________________
349 Int_t AliMpRowSegment::GetMotifPositionId(Int_t i) const
351 // Returns number of motifs in this this row segment.
354 return fMotifPositionId + i*fMotifPositionDId;
357 //_____________________________________________________________________________
358 AliMpVMotif* AliMpRowSegment::GetMotif(Int_t /*i*/) const
360 // Returns the motif of this row segment.