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: AliMpVRowSegmentSpecial.cxx,v 1.9 2006/05/24 13:58:46 ivana Exp $
20 // Class AliMpVRowSegmentSpecial
21 // ----------------------------
22 // Class describing a special row segment composed of the
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 #include "AliMpVRowSegmentSpecial.h"
29 #include "AliMpPadRow.h"
30 #include "AliMpVPadRowSegment.h"
31 #include "AliMpMotif.h"
32 #include "AliMpMotifType.h"
33 #include "AliMpMotifMap.h"
34 #include "AliMpMotifPosition.h"
35 #include "AliMpConstants.h"
37 #include <Riostream.h>
40 ClassImp(AliMpVRowSegmentSpecial)
44 const Int_t AliMpVRowSegmentSpecial::fgkMaxNofMotifPositionIds = 20;
47 //______________________________________________________________________________
48 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(AliMpRow* row, Double_t offsetX)
56 ,fNofMotifPositionIds(0)
59 /// Standard constructor
62 //______________________________________________________________________________
63 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial()
71 ,fNofMotifPositionIds(0)
74 /// Default constructor
77 fMotifPositionIds.Set(fgkMaxNofMotifPositionIds);
81 //_____________________________________________________________________________
82 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(
83 const AliMpVRowSegmentSpecial& right)
84 : AliMpVRowSegment(right)
86 /// Protected copy constructor (not provided)
88 Fatal("AliMpVRowSegmentSpecial", "Copy constructor not provided.");
91 //______________________________________________________________________________
92 AliMpVRowSegmentSpecial::~AliMpVRowSegmentSpecial()
96 for (Int_t i=0; i<GetNofPadRows(); i++)
104 //_____________________________________________________________________________
105 AliMpVRowSegmentSpecial&
106 AliMpVRowSegmentSpecial::operator=(const AliMpVRowSegmentSpecial& right)
108 /// Protected assignment operator (not provided)
110 // check assignment to self
111 if (this == &right) return *this;
113 Fatal("operator =", "Assignment operator not provided.");
122 //______________________________________________________________________________
123 AliMpPadRow* AliMpVRowSegmentSpecial::FindPadRow(Double_t y) const
125 /// Find the pad row in the given y coordinate.
127 Double_t lowBorder = fRow->LowBorderY();
128 Double_t highBorder = fRow->LowBorderY();
130 for (Int_t i=0; i<GetNofPadRows(); i++) {
132 AliMpPadRow* padRow = GetPadRow(i);
133 highBorder += 2.*padRow->HalfSizeY();
135 if ( y >= lowBorder && y <= highBorder)
138 lowBorder = highBorder;
144 //______________________________________________________________________________
146 AliMpVRowSegmentSpecial::FindPadRowSegment(Int_t motifPositionId) const
148 /// Find the most down pad row segment with this motifPositionId.
150 for (Int_t i=0; i<GetNofPadRows(); i++) {
151 AliMpPadRow* padRow = GetPadRow(i);
153 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
154 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
156 if (padRowSegment->GetMotifPositionId() == motifPositionId)
157 return padRowSegment;
163 //______________________________________________________________________________
165 AliMpVRowSegmentSpecial::FindRelativeLowIndicesOf(Int_t motifPositionId) const
167 /// Return the lowest pad indices where the motif of the given position ID
168 /// exist in this segment.
170 AliMpIntPair ans(0,1000);
171 AliMpIntPair ans0 = ans;
174 for (Int_t i=0; i<GetNofPadRows(); i++) {
175 AliMpPadRow* padRow = GetPadRow(i);
178 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
179 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
180 nofPadsX += padRowSegment->GetNofPads();
181 if (padRowSegment->GetMotifPositionId() == motifPositionId) {
182 if (ans.GetFirst() < nofPadsX) ans.SetFirst(nofPadsX);
183 if (ans.GetSecond()>i) ans.SetSecond(i);
184 // ans.First = max (nof pads of this pos ID)
185 // ans.Second = min of pad row number
188 if (nofPadsX > maxNofPadsX) maxNofPadsX = nofPadsX;
190 if (ans == ans0) return AliMpIntPair::Invalid();
192 return AliMpIntPair(maxNofPadsX-ans.GetFirst(), ans.GetSecond());
195 //______________________________________________________________________________
196 Int_t AliMpVRowSegmentSpecial::MaxNofPadsInRow() const
198 /// Return the maximum number of pads in this row segment along the X direction
200 Int_t maxNofPads = 0;
202 for (Int_t i=0; i<GetNofPadRows(); i++){
203 Int_t nofPads = GetPadRow(i)->GetNofPads();
206 if (nofPads > maxNofPads) maxNofPads = nofPads;
212 //______________________________________________________________________________
213 Bool_t AliMpVRowSegmentSpecial::HasMotif(const AliMpVMotif* motif) const
215 /// Return true if the specified motif is already in fMotifs vector,
216 /// returns false otherwise.
219 for (UInt_t i=0; i<fMotifs.size(); i++)
220 if (fMotifs[i] == motif) return true;
224 for (Int_t i=0; i<fMotifs.GetEntriesFast(); i++)
225 if (fMotifs[i] == (const TObject*)motif) return true;
231 //______________________________________________________________________________
232 Int_t AliMpVRowSegmentSpecial::GetNofPadRows() const
234 /// Return number of pad rows.
237 return fPadRows.size();
241 return fPadRows.GetEntriesFast();
245 //______________________________________________________________________________
246 AliMpPadRow* AliMpVRowSegmentSpecial::GetPadRow(Int_t i) const
248 /// Return number of pad rows.
255 return (AliMpPadRow*)fPadRows[i];
263 //______________________________________________________________________________
264 void AliMpVRowSegmentSpecial::AddPadRow(AliMpPadRow* padRow)
268 padRow->SetOffsetX(fOffsetX);
269 padRow->SetID(GetNofPadRows());
272 fPadRows.push_back(padRow);
276 fPadRows.Add(padRow);
280 //______________________________________________________________________________
281 void AliMpVRowSegmentSpecial::UpdateMotifVector()
283 /// Add motifs associated with the pad row segments in the specified
284 /// pad row in the fMotifs vector.
286 for (Int_t i=0; i<GetNofPadRows(); i++) {
287 AliMpPadRow* padRow = GetPadRow(i);
289 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
290 AliMpVMotif* motif = padRow->GetPadRowSegment(j)->GetMotif();
292 if (!HasMotif(motif)) {
294 fMotifs.push_back(motif);
295 fMotifPositionIds.push_back(
296 padRow->GetPadRowSegment(j)->GetMotifPositionId());
301 // resize array if needed
302 if (fNofMotifPositionIds<fgkMaxNofMotifPositionIds)
303 fMotifPositionIds.Set(fMotifPositionIds.GetSize()+
304 fgkMaxNofMotifPositionIds);
305 fMotifPositionIds.AddAt(
306 padRow->GetPadRowSegment(j)->GetMotifPositionId(),
307 fNofMotifPositionIds++);
314 //______________________________________________________________________________
315 Double_t AliMpVRowSegmentSpecial::HalfSizeY() const
317 /// Return the size in y of this row segment.
319 Double_t halfSizeY = 0.;
320 for (Int_t i=0; i<GetNofPadRows(); i++) {
321 halfSizeY += GetPadRow(i)->HalfSizeY();
327 //______________________________________________________________________________
328 AliMpVMotif* AliMpVRowSegmentSpecial::FindMotif(const TVector2& position) const
330 /// Return the motif of this row;
333 = FindPadRow(position.Y());
335 if (!padRow) return 0;
337 AliMpVPadRowSegment* padRowSegment
338 = padRow->FindPadRowSegment(position.X());
340 if (!padRowSegment) return 0;
342 return padRowSegment->GetMotif();
345 //______________________________________________________________________________
346 Int_t AliMpVRowSegmentSpecial::FindMotifPositionId(const TVector2& position) const
348 /// Return the motif position identified for the given
349 /// geometric position.
352 = FindPadRow(position.Y());
354 if (!padRow) return 0;
356 AliMpVPadRowSegment* padRowSegment
357 = padRow->FindPadRowSegment(position.X());
359 if (!padRowSegment) return 0;
361 return padRowSegment->GetMotifPositionId();
364 //______________________________________________________________________________
365 Bool_t AliMpVRowSegmentSpecial::HasMotifPosition(Int_t motifPositionId) const
367 /// Return true if the motif specified with the given position identifier
368 /// is in this segment.
370 if (FindPadRowSegment(motifPositionId))
376 //______________________________________________________________________________
377 TVector2 AliMpVRowSegmentSpecial::MotifCenter(Int_t motifPositionId) const
379 /// Return the coordinates of the motif specified with
380 /// the given position identifier.
382 // Try to get the motif position from the motif map first
383 AliMpMotifPosition* motifPosition
384 = GetRow()->GetMotifMap()->FindMotifPosition(motifPositionId);
385 if (motifPosition) return motifPosition->Position();
387 // Use slow method otherwise
388 return MotifCenterSlow(motifPositionId);
391 //______________________________________________________________________________
392 TVector2 AliMpVRowSegmentSpecial::Dimensions() const
394 /// Return the halflengths in x, y of the row segment rectangular envelope.
398 for (Int_t i=0; i<GetNofPadRows(); i++) {
399 AliMpPadRow* padRow = GetPadRow(i);
401 // Add all pad rows y halfsizes
402 y += padRow->HalfSizeY();
404 // Find the biggest pad rows x halfsize
406 = (padRow->GetPadRowSegment(0)->RightBorderX() -
407 padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX())/2.;
411 return TVector2(x, y);
414 //______________________________________________________________________________
415 AliMpRow* AliMpVRowSegmentSpecial::GetRow() const
417 /// Return the row.which this row segment belongs to.
422 //______________________________________________________________________________
423 Int_t AliMpVRowSegmentSpecial::GetNofMotifs() const
425 /// Return the number of different motifs present in this row segment.
428 return fMotifs.size();
431 return fMotifs.GetEntriesFast();
435 //______________________________________________________________________________
436 AliMpVMotif* AliMpVRowSegmentSpecial::GetMotif(Int_t i) const
438 /// Return the i-th motif present in this row segment.
444 return (AliMpVMotif*)fMotifs[i];
448 //______________________________________________________________________________
449 Int_t AliMpVRowSegmentSpecial::GetMotifPositionId(Int_t i) const
451 /// Return the i-th motif position Id present in this row segment.
453 return fMotifPositionIds[i];