4 // Class AliMpVRowSegmentSpecial
5 // ----------------------------
6 // Class describing a special row segment composed of the
9 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
12 #include <Riostream.h>
14 #include "AliMpVRowSegmentSpecial.h"
16 #include "AliMpPadRow.h"
17 #include "AliMpVPadRowSegment.h"
18 #include "AliMpMotif.h"
19 #include "AliMpMotifType.h"
20 #include "AliMpMotifMap.h"
21 #include "AliMpMotifPosition.h"
22 #include "AliMpConstants.h"
24 ClassImp(AliMpVRowSegmentSpecial)
27 const Int_t AliMpVRowSegmentSpecial::fgkMaxNofMotifPositionIds = 20;
30 //______________________________________________________________________________
31 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(AliMpRow* row, Double_t offsetX)
39 ,fNofMotifPositionIds(0)
45 //______________________________________________________________________________
46 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial()
54 ,fNofMotifPositionIds(0)
59 fMotifPositionIds.Set(fgkMaxNofMotifPositionIds);
63 //_____________________________________________________________________________
64 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(
65 const AliMpVRowSegmentSpecial& right)
66 : AliMpVRowSegment(right) {
68 Fatal("AliMpVRowSegmentSpecial", "Copy constructor not provided.");
71 //______________________________________________________________________________
72 AliMpVRowSegmentSpecial::~AliMpVRowSegmentSpecial()
75 for (Int_t i=0; i<GetNofPadRows(); i++)
83 //_____________________________________________________________________________
84 AliMpVRowSegmentSpecial&
85 AliMpVRowSegmentSpecial::operator=(const AliMpVRowSegmentSpecial& right)
87 // check assignement to self
88 if (this == &right) return *this;
90 Fatal("operator =", "Assignement operator not provided.");
99 //______________________________________________________________________________
100 AliMpPadRow* AliMpVRowSegmentSpecial::FindPadRow(Double_t y) const
102 // Finds the pad row in the given y coordinate.
105 Double_t lowBorder = fRow->LowBorderY();
106 Double_t highBorder = fRow->LowBorderY();
108 for (Int_t i=0; i<GetNofPadRows(); i++) {
110 AliMpPadRow* padRow = GetPadRow(i);
111 highBorder += 2.*padRow->HalfSizeY();
113 if ( y >= lowBorder && y <= highBorder)
116 lowBorder = highBorder;
122 //______________________________________________________________________________
124 AliMpVRowSegmentSpecial::FindPadRowSegment(Int_t motifPositionId) const
126 // Find the most down pad row segment with this motifPositionId.
129 for (Int_t i=0; i<GetNofPadRows(); i++) {
130 AliMpPadRow* padRow = GetPadRow(i);
132 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
133 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
135 if (padRowSegment->GetMotifPositionId() == motifPositionId)
136 return padRowSegment;
142 //______________________________________________________________________________
144 AliMpVRowSegmentSpecial::FindRelativeLowIndicesOf(Int_t motifPositionId) const
146 // Returns the lowest pad indices where the motif of the given position ID
147 // exists in this segment.
150 AliMpIntPair ans(0,1000);
151 AliMpIntPair ans0 = ans;
154 for (Int_t i=0; i<GetNofPadRows(); i++) {
155 AliMpPadRow* padRow = GetPadRow(i);
158 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
159 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
160 nofPadsX += padRowSegment->GetNofPads();
161 if (padRowSegment->GetMotifPositionId() == motifPositionId) {
162 if (ans.GetFirst() < nofPadsX) ans.SetFirst(nofPadsX);
163 if (ans.GetSecond()>i) ans.SetSecond(i);
164 // ans.First = max (nof pads of this pos ID)
165 // ans.Second = min of pad row number
168 if (nofPadsX > maxNofPadsX) maxNofPadsX = nofPadsX;
170 if (ans == ans0) return AliMpIntPair::Invalid();
172 return AliMpIntPair(maxNofPadsX-ans.GetFirst(), ans.GetSecond());
175 //______________________________________________________________________________
176 Int_t AliMpVRowSegmentSpecial::MaxNofPadsInRow() const
178 // Returns the maximum number of pads in this row segment along the X direction
181 Int_t maxNofPads = 0;
183 for (Int_t i=0; i<GetNofPadRows(); i++){
184 Int_t nofPads = GetPadRow(i)->GetNofPads();
187 if (nofPads > maxNofPads) maxNofPads = nofPads;
193 //______________________________________________________________________________
194 Bool_t AliMpVRowSegmentSpecial::HasMotif(const AliMpVMotif* motif) const
196 // Returns true if the specified motif is already in fMotifs vector,
197 // returns false otherwise.
201 for (UInt_t i=0; i<fMotifs.size(); i++)
202 if (fMotifs[i] == motif) return true;
206 for (Int_t i=0; i<fMotifs.GetEntriesFast(); i++)
207 if (fMotifs[i] == motif) return true;
213 //______________________________________________________________________________
214 Int_t AliMpVRowSegmentSpecial::GetNofPadRows() const
216 // Returns number of pad rows.
220 return fPadRows.size();
224 return fPadRows.GetEntriesFast();
228 //______________________________________________________________________________
229 AliMpPadRow* AliMpVRowSegmentSpecial::GetPadRow(Int_t i) const
231 // Returns number of pad rows.
239 return (AliMpPadRow*)fPadRows[i];
247 //______________________________________________________________________________
248 void AliMpVRowSegmentSpecial::AddPadRow(AliMpPadRow* padRow)
253 padRow->SetOffsetX(fOffsetX);
254 padRow->SetID(GetNofPadRows());
257 fPadRows.push_back(padRow);
261 fPadRows.Add(padRow);
265 //______________________________________________________________________________
266 void AliMpVRowSegmentSpecial::UpdateMotifVector()
268 // Add motifs associated with the pad row segments in the specified
269 // pad row in the fMotifs vector.
272 for (Int_t i=0; i<GetNofPadRows(); i++) {
273 AliMpPadRow* padRow = GetPadRow(i);
275 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
276 AliMpVMotif* motif = padRow->GetPadRowSegment(j)->GetMotif();
278 if (!HasMotif(motif)) {
280 fMotifs.push_back(motif);
281 fMotifPositionIds.push_back(
282 padRow->GetPadRowSegment(j)->GetMotifPositionId());
287 // resize array if needed
288 if (fNofMotifPositionIds<fgkMaxNofMotifPositionIds)
289 fMotifPositionIds.Set(fMotifPositionIds.GetSize()+
290 fgkMaxNofMotifPositionIds);
291 fMotifPositionIds.AddAt(
292 padRow->GetPadRowSegment(j)->GetMotifPositionId(),
293 fNofMotifPositionIds++);
300 //______________________________________________________________________________
301 Double_t AliMpVRowSegmentSpecial::HalfSizeY() const
303 // Returns the size in y of this row segment.
306 Double_t halfSizeY = 0.;
307 for (Int_t i=0; i<GetNofPadRows(); i++) {
308 halfSizeY += GetPadRow(i)->HalfSizeY();
314 //______________________________________________________________________________
315 AliMpVMotif* AliMpVRowSegmentSpecial::FindMotif(const TVector2& position) const
317 // Returns the motif of this row;
321 = FindPadRow(position.Y());
323 if (!padRow) return 0;
325 AliMpVPadRowSegment* padRowSegment
326 = padRow->FindPadRowSegment(position.X());
328 if (!padRowSegment) return 0;
330 return padRowSegment->GetMotif();
333 //______________________________________________________________________________
334 Int_t AliMpVRowSegmentSpecial::FindMotifPositionId(const TVector2& position) const
336 // Returns the motif position identified for the given
337 // geometric position.
341 = FindPadRow(position.Y());
343 if (!padRow) return 0;
345 AliMpVPadRowSegment* padRowSegment
346 = padRow->FindPadRowSegment(position.X());
348 if (!padRowSegment) return 0;
350 return padRowSegment->GetMotifPositionId();
353 //______________________________________________________________________________
354 Bool_t AliMpVRowSegmentSpecial::HasMotifPosition(Int_t motifPositionId) const
356 // Returns true if the motif specified with the given position identifier
357 // is in this segment.
360 if (FindPadRowSegment(motifPositionId))
366 //______________________________________________________________________________
367 TVector2 AliMpVRowSegmentSpecial::MotifCenter(Int_t motifPositionId) const
369 // Returns the coordinates of the motif specified with
370 // the given position identifier.
373 // Try to get the motif position from the motif map first
374 AliMpMotifPosition* motifPosition
375 = GetRow()->GetMotifMap()->FindMotifPosition(motifPositionId);
376 if (motifPosition) return motifPosition->Position();
378 // Use slow method otherwise
379 return MotifCenterSlow(motifPositionId);
382 //______________________________________________________________________________
383 TVector2 AliMpVRowSegmentSpecial::Dimensions() const
385 // Returns the halflengths in x, y of the row segment rectangular envelope.
390 for (Int_t i=0; i<GetNofPadRows(); i++) {
391 AliMpPadRow* padRow = GetPadRow(i);
393 // Add all pad rows y halfsizes
394 y += padRow->HalfSizeY();
396 // Find the biggest pad rows x halfsize
398 = (padRow->GetPadRowSegment(0)->RightBorderX() -
399 padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX())/2.;
403 return TVector2(x, y);
406 //______________________________________________________________________________
407 void AliMpVRowSegmentSpecial::SetGlobalIndices()
409 // Sets indices limits.
412 AliMpMotifPosition* firstPos = 0;
413 AliMpMotifPosition* lastPos = 0;
415 for (Int_t i=0;i<GetNofMotifs();i++) {
416 AliMpMotifPosition* mPos
417 = GetRow()->GetMotifMap()
418 ->FindMotifPosition(GetMotifPositionId(i));
421 mPos->GetLowIndicesLimit().GetFirst()
422 < firstPos->GetLowIndicesLimit().GetFirst())
426 mPos->GetHighIndicesLimit().GetFirst()
427 >lastPos->GetHighIndicesLimit().GetFirst())
431 // Check if the motif positions has the limits set
432 if ( !firstPos->HasValidIndices() || !lastPos->HasValidIndices())
433 Fatal("SetGlobalIndices", "Indices of motif positions have to be set first.");
435 SetLowIndicesLimit(firstPos->GetLowIndicesLimit());
436 SetHighIndicesLimit(lastPos->GetHighIndicesLimit());
439 //______________________________________________________________________________
440 AliMpRow* AliMpVRowSegmentSpecial::GetRow() const
442 // Returns the row.which this row segment belongs to.
448 //______________________________________________________________________________
449 Int_t AliMpVRowSegmentSpecial::GetNofMotifs() const
451 // Returns the number of different motifs present in this row segment.
455 return fMotifs.size();
458 return fMotifs.GetEntriesFast();
462 //______________________________________________________________________________
463 AliMpVMotif* AliMpVRowSegmentSpecial::GetMotif(Int_t i) const
465 // Returns the i-th motif present in this row segment.
472 return (AliMpVMotif*)fMotifs[i];
476 //______________________________________________________________________________
477 Int_t AliMpVRowSegmentSpecial::GetMotifPositionId(Int_t i) const
479 // Returns the i-th motif position Id present in this row segment.
482 return fMotifPositionIds[i];