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 //-----------------------------------------------------------------------------
21 // Class AliMpVRowSegmentSpecial
22 // ----------------------------
23 // Class describing a special row segment composed of the
25 // Included in AliRoot: 2003/05/02
26 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 //-----------------------------------------------------------------------------
29 #include "AliMpVRowSegmentSpecial.h"
31 #include "AliMpPadRow.h"
32 #include "AliMpVPadRowSegment.h"
33 #include "AliMpMotif.h"
34 #include "AliMpMotifType.h"
35 #include "AliMpMotifMap.h"
36 #include "AliMpMotifPosition.h"
37 #include "AliMpConstants.h"
39 #include <Riostream.h>
42 ClassImp(AliMpVRowSegmentSpecial)
46 const Int_t AliMpVRowSegmentSpecial::fgkMaxNofMotifPositionIds = 20;
49 //______________________________________________________________________________
50 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(AliMpRow* row, Double_t offsetX)
58 ,fNofMotifPositionIds(0)
61 /// Standard constructor
64 //______________________________________________________________________________
65 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial()
73 ,fNofMotifPositionIds(0)
76 /// Default constructor
79 fMotifPositionIds.Set(fgkMaxNofMotifPositionIds);
83 //______________________________________________________________________________
84 AliMpVRowSegmentSpecial::~AliMpVRowSegmentSpecial()
88 for (Int_t i=0; i<GetNofPadRows(); i++)
96 //______________________________________________________________________________
97 AliMpPadRow* AliMpVRowSegmentSpecial::FindPadRow(Double_t y) const
99 /// Find the pad row in the given y coordinate.
101 Double_t lowBorder = fRow->LowBorderY();
102 Double_t highBorder = fRow->LowBorderY();
104 for (Int_t i=0; i<GetNofPadRows(); i++) {
106 AliMpPadRow* padRow = GetPadRow(i);
107 highBorder += 2.*padRow->HalfSizeY();
109 if ( y >= lowBorder && y <= highBorder)
112 lowBorder = highBorder;
118 //______________________________________________________________________________
120 AliMpVRowSegmentSpecial::FindPadRowSegment(Int_t motifPositionId) const
122 /// Find the most down pad row segment with this motifPositionId.
124 for (Int_t i=0; i<GetNofPadRows(); i++) {
125 AliMpPadRow* padRow = GetPadRow(i);
127 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
128 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
130 if (padRowSegment->GetMotifPositionId() == motifPositionId)
131 return padRowSegment;
137 //______________________________________________________________________________
139 AliMpVRowSegmentSpecial::FindRelativeLowIndicesOf(Int_t motifPositionId) const
141 /// Return the lowest pad indices where the motif of the given position ID
142 /// exist in this segment.
144 AliMpIntPair ans(0,1000);
145 AliMpIntPair ans0 = ans;
148 for (Int_t i=0; i<GetNofPadRows(); i++) {
149 AliMpPadRow* padRow = GetPadRow(i);
152 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
153 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
154 nofPadsX += padRowSegment->GetNofPads();
155 if (padRowSegment->GetMotifPositionId() == motifPositionId) {
156 if (ans.GetFirst() < nofPadsX) ans.SetFirst(nofPadsX);
157 if (ans.GetSecond()>i) ans.SetSecond(i);
158 // ans.First = max (nof pads of this pos ID)
159 // ans.Second = min of pad row number
162 if (nofPadsX > maxNofPadsX) maxNofPadsX = nofPadsX;
164 if (ans == ans0) return AliMpIntPair::Invalid();
166 return AliMpIntPair(maxNofPadsX-ans.GetFirst(), ans.GetSecond());
169 //______________________________________________________________________________
170 Int_t AliMpVRowSegmentSpecial::MaxNofPadsInRow() const
172 /// Return the maximum number of pads in this row segment along the X direction
174 Int_t maxNofPads = 0;
176 for (Int_t i=0; i<GetNofPadRows(); i++){
177 Int_t nofPads = GetPadRow(i)->GetNofPads();
180 if (nofPads > maxNofPads) maxNofPads = nofPads;
186 //______________________________________________________________________________
187 Bool_t AliMpVRowSegmentSpecial::HasMotif(const AliMpVMotif* motif) const
189 /// Return true if the specified motif is already in fMotifs vector,
190 /// returns false otherwise.
193 for (UInt_t i=0; i<fMotifs.size(); i++)
194 if (fMotifs[i] == motif) return true;
198 for (Int_t i=0; i<fMotifs.GetEntriesFast(); i++)
199 if (fMotifs[i] == (const TObject*)motif) return true;
205 //______________________________________________________________________________
206 Int_t AliMpVRowSegmentSpecial::GetNofPadRows() const
208 /// Return number of pad rows.
211 return fPadRows.size();
215 return fPadRows.GetEntriesFast();
219 //______________________________________________________________________________
220 AliMpPadRow* AliMpVRowSegmentSpecial::GetPadRow(Int_t i) const
222 /// Return number of pad rows.
229 return (AliMpPadRow*)fPadRows[i];
237 //______________________________________________________________________________
238 void AliMpVRowSegmentSpecial::AddPadRow(AliMpPadRow* padRow)
242 padRow->SetOffsetX(fOffsetX);
243 padRow->SetID(GetNofPadRows());
246 fPadRows.push_back(padRow);
250 fPadRows.Add(padRow);
254 //______________________________________________________________________________
255 void AliMpVRowSegmentSpecial::UpdateMotifVector()
257 /// Add motifs associated with the pad row segments in the specified
258 /// pad row in the fMotifs vector.
260 for (Int_t i=0; i<GetNofPadRows(); i++) {
261 AliMpPadRow* padRow = GetPadRow(i);
263 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
264 AliMpVMotif* motif = padRow->GetPadRowSegment(j)->GetMotif();
266 if (!HasMotif(motif)) {
268 fMotifs.push_back(motif);
269 fMotifPositionIds.push_back(
270 padRow->GetPadRowSegment(j)->GetMotifPositionId());
275 // resize array if needed
276 if (fNofMotifPositionIds<fgkMaxNofMotifPositionIds)
277 fMotifPositionIds.Set(fMotifPositionIds.GetSize()+
278 fgkMaxNofMotifPositionIds);
279 fMotifPositionIds.AddAt(
280 padRow->GetPadRowSegment(j)->GetMotifPositionId(),
281 fNofMotifPositionIds++);
288 //______________________________________________________________________________
289 Double_t AliMpVRowSegmentSpecial::HalfSizeY() const
291 /// Return the size in y of this row segment.
293 Double_t halfSizeY = 0.;
294 for (Int_t i=0; i<GetNofPadRows(); i++) {
295 halfSizeY += GetPadRow(i)->HalfSizeY();
301 //______________________________________________________________________________
302 AliMpVMotif* AliMpVRowSegmentSpecial::FindMotif(const TVector2& position) const
304 /// Return the motif of this row;
307 = FindPadRow(position.Y());
309 if (!padRow) return 0;
311 AliMpVPadRowSegment* padRowSegment
312 = padRow->FindPadRowSegment(position.X());
314 if (!padRowSegment) return 0;
316 return padRowSegment->GetMotif();
319 //______________________________________________________________________________
320 Int_t AliMpVRowSegmentSpecial::FindMotifPositionId(const TVector2& position) const
322 /// Return the motif position identified for the given
323 /// geometric position.
326 = FindPadRow(position.Y());
328 if (!padRow) return 0;
330 AliMpVPadRowSegment* padRowSegment
331 = padRow->FindPadRowSegment(position.X());
333 if (!padRowSegment) return 0;
335 return padRowSegment->GetMotifPositionId();
338 //______________________________________________________________________________
339 Bool_t AliMpVRowSegmentSpecial::HasMotifPosition(Int_t motifPositionId) const
341 /// Return true if the motif specified with the given position identifier
342 /// is in this segment.
344 if (FindPadRowSegment(motifPositionId))
350 //______________________________________________________________________________
351 TVector2 AliMpVRowSegmentSpecial::MotifCenter(Int_t motifPositionId) const
353 /// Return the coordinates of the motif specified with
354 /// the given position identifier.
356 // Try to get the motif position from the motif map first
357 AliMpMotifPosition* motifPosition
358 = GetRow()->GetMotifMap()->FindMotifPosition(motifPositionId);
359 if (motifPosition) return motifPosition->Position();
361 // Use slow method otherwise
362 return MotifCenterSlow(motifPositionId);
365 //______________________________________________________________________________
366 TVector2 AliMpVRowSegmentSpecial::Dimensions() const
368 /// Return the halflengths in x, y of the row segment rectangular envelope.
372 for (Int_t i=0; i<GetNofPadRows(); i++) {
373 AliMpPadRow* padRow = GetPadRow(i);
375 // Add all pad rows y halfsizes
376 y += padRow->HalfSizeY();
378 // Find the biggest pad rows x halfsize
380 = (padRow->GetPadRowSegment(0)->RightBorderX() -
381 padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX())/2.;
385 return TVector2(x, y);
388 //______________________________________________________________________________
389 AliMpRow* AliMpVRowSegmentSpecial::GetRow() const
391 /// Return the row.which this row segment belongs to.
396 //______________________________________________________________________________
397 Int_t AliMpVRowSegmentSpecial::GetNofMotifs() const
399 /// Return the number of different motifs present in this row segment.
402 return fMotifs.size();
405 return fMotifs.GetEntriesFast();
409 //______________________________________________________________________________
410 AliMpVMotif* AliMpVRowSegmentSpecial::GetMotif(Int_t i) const
412 /// Return the i-th motif present in this row segment.
418 return (AliMpVMotif*)fMotifs[i];
422 //______________________________________________________________________________
423 Int_t AliMpVRowSegmentSpecial::GetMotifPositionId(Int_t i) const
425 /// Return the i-th motif position Id present in this row segment.
427 return fMotifPositionIds[i];