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()
67 for (Int_t i=0; i<GetNofPadRows(); i++)
75 //______________________________________________________________________________
76 AliMpPadRow* AliMpVRowSegmentSpecial::FindPadRow(Double_t y) const
78 // Finds the pad row in the given y coordinate.
81 Double_t lowBorder = fRow->LowBorderY();
82 Double_t highBorder = fRow->LowBorderY();
84 for (Int_t i=0; i<GetNofPadRows(); i++) {
86 AliMpPadRow* padRow = GetPadRow(i);
87 highBorder += 2.*padRow->HalfSizeY();
89 if ( y >= lowBorder && y <= highBorder)
92 lowBorder = highBorder;
98 //______________________________________________________________________________
100 AliMpVRowSegmentSpecial::FindPadRowSegment(Int_t motifPositionId) const
102 // Find the most down pad row segment with this motifPositionId.
105 for (Int_t i=0; i<GetNofPadRows(); i++) {
106 AliMpPadRow* padRow = GetPadRow(i);
108 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
109 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
111 if (padRowSegment->GetMotifPositionId() == motifPositionId)
112 return padRowSegment;
118 //______________________________________________________________________________
120 AliMpVRowSegmentSpecial::FindRelativeLowIndicesOf(Int_t motifPositionId) const
122 // Returns the lowest pad indices where the motif of the given position ID
123 // exists in this segment.
126 AliMpIntPair ans(0,1000);
127 AliMpIntPair ans0 = ans;
130 for (Int_t i=0; i<GetNofPadRows(); i++) {
131 AliMpPadRow* padRow = GetPadRow(i);
134 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
135 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
136 nofPadsX += padRowSegment->GetNofPads();
137 if (padRowSegment->GetMotifPositionId() == motifPositionId) {
138 if (ans.GetFirst() < nofPadsX) ans.SetFirst(nofPadsX);
139 if (ans.GetSecond()>i) ans.SetSecond(i);
140 // ans.First = max (nof pads of this pos ID)
141 // ans.Second = min of pad row number
144 if (nofPadsX > maxNofPadsX) maxNofPadsX = nofPadsX;
146 if (ans == ans0) return AliMpIntPair::Invalid();
148 return AliMpIntPair(maxNofPadsX-ans.GetFirst(), ans.GetSecond());
151 //______________________________________________________________________________
152 Int_t AliMpVRowSegmentSpecial::MaxNofPadsInRow() const
154 // Returns the maximum number of pads in this row segment along the X direction
157 Int_t maxNofPads = 0;
159 for (Int_t i=0; i<GetNofPadRows(); i++){
160 Int_t nofPads = GetPadRow(i)->GetNofPads();
163 if (nofPads > maxNofPads) maxNofPads = nofPads;
169 //______________________________________________________________________________
170 Bool_t AliMpVRowSegmentSpecial::HasMotif(const AliMpVMotif* motif) const
172 // Returns true if the specified motif is already in fMotifs vector,
173 // returns false otherwise.
177 for (UInt_t i=0; i<fMotifs.size(); i++)
178 if (fMotifs[i] == motif) return true;
182 for (Int_t i=0; i<fMotifs.GetEntriesFast(); i++)
183 if (fMotifs[i] == motif) return true;
189 //______________________________________________________________________________
190 Int_t AliMpVRowSegmentSpecial::GetNofPadRows() const
192 // Returns number of pad rows.
196 return fPadRows.size();
200 return fPadRows.GetEntriesFast();
204 //______________________________________________________________________________
205 AliMpPadRow* AliMpVRowSegmentSpecial::GetPadRow(Int_t i) const
207 // Returns number of pad rows.
215 return (AliMpPadRow*)fPadRows[i];
223 //______________________________________________________________________________
224 void AliMpVRowSegmentSpecial::AddPadRow(AliMpPadRow* padRow)
229 padRow->SetOffsetX(fOffsetX);
230 padRow->SetID(GetNofPadRows());
233 fPadRows.push_back(padRow);
237 fPadRows.Add(padRow);
241 //______________________________________________________________________________
242 void AliMpVRowSegmentSpecial::UpdateMotifVector()
244 // Add motifs associated with the pad row segments in the specified
245 // pad row in the fMotifs vector.
248 for (Int_t i=0; i<GetNofPadRows(); i++) {
249 AliMpPadRow* padRow = GetPadRow(i);
251 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
252 AliMpVMotif* motif = padRow->GetPadRowSegment(j)->GetMotif();
254 if (!HasMotif(motif)) {
256 fMotifs.push_back(motif);
257 fMotifPositionIds.push_back(
258 padRow->GetPadRowSegment(j)->GetMotifPositionId());
263 // resize array if needed
264 if (fNofMotifPositionIds<fgkMaxNofMotifPositionIds)
265 fMotifPositionIds.Set(fMotifPositionIds.GetSize()+
266 fgkMaxNofMotifPositionIds);
267 fMotifPositionIds.AddAt(
268 padRow->GetPadRowSegment(j)->GetMotifPositionId(),
269 fNofMotifPositionIds++);
276 //______________________________________________________________________________
277 Double_t AliMpVRowSegmentSpecial::HalfSizeY() const
279 // Returns the size in y of this row segment.
282 Double_t halfSizeY = 0.;
283 for (Int_t i=0; i<GetNofPadRows(); i++) {
284 halfSizeY += GetPadRow(i)->HalfSizeY();
290 //______________________________________________________________________________
291 AliMpVMotif* AliMpVRowSegmentSpecial::FindMotif(const TVector2& position) const
293 // Returns the motif of this row;
297 = FindPadRow(position.Y());
299 if (!padRow) return 0;
301 AliMpVPadRowSegment* padRowSegment
302 = padRow->FindPadRowSegment(position.X());
304 if (!padRowSegment) return 0;
306 return padRowSegment->GetMotif();
309 //______________________________________________________________________________
310 Int_t AliMpVRowSegmentSpecial::FindMotifPositionId(const TVector2& position) const
312 // Returns the motif position identified for the given
313 // geometric position.
317 = FindPadRow(position.Y());
319 if (!padRow) return 0;
321 AliMpVPadRowSegment* padRowSegment
322 = padRow->FindPadRowSegment(position.X());
324 if (!padRowSegment) return 0;
326 return padRowSegment->GetMotifPositionId();
329 //______________________________________________________________________________
330 Bool_t AliMpVRowSegmentSpecial::HasMotifPosition(Int_t motifPositionId) const
332 // Returns true if the motif specified with the given position identifier
333 // is in this segment.
336 if (FindPadRowSegment(motifPositionId))
342 //______________________________________________________________________________
343 TVector2 AliMpVRowSegmentSpecial::MotifCenter(Int_t motifPositionId) const
345 // Returns the coordinates of the motif specified with
346 // the given position identifier.
349 // Try to get the motif position from the motif map first
350 AliMpMotifPosition* motifPosition
351 = GetRow()->GetMotifMap()->FindMotifPosition(motifPositionId);
352 if (motifPosition) return motifPosition->Position();
354 // Use slow method otherwise
355 return MotifCenterSlow(motifPositionId);
358 //______________________________________________________________________________
359 TVector2 AliMpVRowSegmentSpecial::Dimensions() const
361 // Returns the halflengths in x, y of the row segment rectangular envelope.
366 for (Int_t i=0; i<GetNofPadRows(); i++) {
367 AliMpPadRow* padRow = GetPadRow(i);
369 // Add all pad rows y halfsizes
370 y += padRow->HalfSizeY();
372 // Find the biggest pad rows x halfsize
374 = (padRow->GetPadRowSegment(0)->RightBorderX() -
375 padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX())/2.;
379 return TVector2(x, y);
382 //______________________________________________________________________________
383 void AliMpVRowSegmentSpecial::SetGlobalIndices()
385 // Sets indices limits.
388 AliMpMotifPosition* firstPos = 0;
389 AliMpMotifPosition* lastPos = 0;
391 for (Int_t i=0;i<GetNofMotifs();i++) {
392 AliMpMotifPosition* mPos
393 = GetRow()->GetMotifMap()
394 ->FindMotifPosition(GetMotifPositionId(i));
397 mPos->GetLowIndicesLimit().GetFirst()
398 < firstPos->GetLowIndicesLimit().GetFirst())
402 mPos->GetHighIndicesLimit().GetFirst()
403 >lastPos->GetHighIndicesLimit().GetFirst())
407 // Check if the motif positions has the limits set
408 if ( !firstPos->HasValidIndices() || !lastPos->HasValidIndices())
409 Fatal("SetGlobalIndices", "Indices of motif positions have to be set first.");
411 SetLowIndicesLimit(firstPos->GetLowIndicesLimit());
412 SetHighIndicesLimit(lastPos->GetHighIndicesLimit());
415 //______________________________________________________________________________
416 AliMpRow* AliMpVRowSegmentSpecial::GetRow() const
418 // Returns the row.which this row segment belongs to.
424 //______________________________________________________________________________
425 Int_t AliMpVRowSegmentSpecial::GetNofMotifs() const
427 // Returns the number of different motifs present in this row segment.
431 return fMotifs.size();
434 return fMotifs.GetEntriesFast();
438 //______________________________________________________________________________
439 AliMpVMotif* AliMpVRowSegmentSpecial::GetMotif(Int_t i) const
441 // Returns the i-th motif present in this row segment.
448 return (AliMpVMotif*)fMotifs[i];
452 //______________________________________________________________________________
453 Int_t AliMpVRowSegmentSpecial::GetMotifPositionId(Int_t i) const
455 // Returns the i-th motif position Id present in this row segment.
458 return fMotifPositionIds[i];