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.6 2005/08/26 15:43:36 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
28 #include <Riostream.h>
30 #include "AliMpVRowSegmentSpecial.h"
32 #include "AliMpPadRow.h"
33 #include "AliMpVPadRowSegment.h"
34 #include "AliMpMotif.h"
35 #include "AliMpMotifType.h"
36 #include "AliMpMotifMap.h"
37 #include "AliMpMotifPosition.h"
38 #include "AliMpConstants.h"
40 ClassImp(AliMpVRowSegmentSpecial)
43 const Int_t AliMpVRowSegmentSpecial::fgkMaxNofMotifPositionIds = 20;
46 //______________________________________________________________________________
47 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(AliMpRow* row, Double_t offsetX)
55 ,fNofMotifPositionIds(0)
58 /// Standard constructor
61 //______________________________________________________________________________
62 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial()
70 ,fNofMotifPositionIds(0)
73 /// Default constructor
76 fMotifPositionIds.Set(fgkMaxNofMotifPositionIds);
80 //_____________________________________________________________________________
81 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(
82 const AliMpVRowSegmentSpecial& right)
83 : AliMpVRowSegment(right)
85 /// Protected copy constructor (not provided)
87 Fatal("AliMpVRowSegmentSpecial", "Copy constructor not provided.");
90 //______________________________________________________________________________
91 AliMpVRowSegmentSpecial::~AliMpVRowSegmentSpecial()
95 for (Int_t i=0; i<GetNofPadRows(); i++)
103 //_____________________________________________________________________________
104 AliMpVRowSegmentSpecial&
105 AliMpVRowSegmentSpecial::operator=(const AliMpVRowSegmentSpecial& right)
107 /// Protected assignment operator (not provided)
109 // check assignment to self
110 if (this == &right) return *this;
112 Fatal("operator =", "Assignment operator not provided.");
121 //______________________________________________________________________________
122 AliMpPadRow* AliMpVRowSegmentSpecial::FindPadRow(Double_t y) const
124 /// Find the pad row in the given y coordinate.
126 Double_t lowBorder = fRow->LowBorderY();
127 Double_t highBorder = fRow->LowBorderY();
129 for (Int_t i=0; i<GetNofPadRows(); i++) {
131 AliMpPadRow* padRow = GetPadRow(i);
132 highBorder += 2.*padRow->HalfSizeY();
134 if ( y >= lowBorder && y <= highBorder)
137 lowBorder = highBorder;
143 //______________________________________________________________________________
145 AliMpVRowSegmentSpecial::FindPadRowSegment(Int_t motifPositionId) const
147 /// Find the most down pad row segment with this motifPositionId.
149 for (Int_t i=0; i<GetNofPadRows(); i++) {
150 AliMpPadRow* padRow = GetPadRow(i);
152 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
153 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
155 if (padRowSegment->GetMotifPositionId() == motifPositionId)
156 return padRowSegment;
162 //______________________________________________________________________________
164 AliMpVRowSegmentSpecial::FindRelativeLowIndicesOf(Int_t motifPositionId) const
166 /// Return the lowest pad indices where the motif of the given position ID
167 /// exist in this segment.
169 AliMpIntPair ans(0,1000);
170 AliMpIntPair ans0 = ans;
173 for (Int_t i=0; i<GetNofPadRows(); i++) {
174 AliMpPadRow* padRow = GetPadRow(i);
177 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
178 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
179 nofPadsX += padRowSegment->GetNofPads();
180 if (padRowSegment->GetMotifPositionId() == motifPositionId) {
181 if (ans.GetFirst() < nofPadsX) ans.SetFirst(nofPadsX);
182 if (ans.GetSecond()>i) ans.SetSecond(i);
183 // ans.First = max (nof pads of this pos ID)
184 // ans.Second = min of pad row number
187 if (nofPadsX > maxNofPadsX) maxNofPadsX = nofPadsX;
189 if (ans == ans0) return AliMpIntPair::Invalid();
191 return AliMpIntPair(maxNofPadsX-ans.GetFirst(), ans.GetSecond());
194 //______________________________________________________________________________
195 Int_t AliMpVRowSegmentSpecial::MaxNofPadsInRow() const
197 /// Return the maximum number of pads in this row segment along the X direction
199 Int_t maxNofPads = 0;
201 for (Int_t i=0; i<GetNofPadRows(); i++){
202 Int_t nofPads = GetPadRow(i)->GetNofPads();
205 if (nofPads > maxNofPads) maxNofPads = nofPads;
211 //______________________________________________________________________________
212 Bool_t AliMpVRowSegmentSpecial::HasMotif(const AliMpVMotif* motif) const
214 /// Return true if the specified motif is already in fMotifs vector,
215 /// returns false otherwise.
218 for (UInt_t i=0; i<fMotifs.size(); i++)
219 if (fMotifs[i] == motif) return true;
223 for (Int_t i=0; i<fMotifs.GetEntriesFast(); i++)
224 if (fMotifs[i] == (const TObject*)motif) return true;
230 //______________________________________________________________________________
231 Int_t AliMpVRowSegmentSpecial::GetNofPadRows() const
233 /// Return number of pad rows.
236 return fPadRows.size();
240 return fPadRows.GetEntriesFast();
244 //______________________________________________________________________________
245 AliMpPadRow* AliMpVRowSegmentSpecial::GetPadRow(Int_t i) const
247 /// Return number of pad rows.
254 return (AliMpPadRow*)fPadRows[i];
262 //______________________________________________________________________________
263 void AliMpVRowSegmentSpecial::AddPadRow(AliMpPadRow* padRow)
267 padRow->SetOffsetX(fOffsetX);
268 padRow->SetID(GetNofPadRows());
271 fPadRows.push_back(padRow);
275 fPadRows.Add(padRow);
279 //______________________________________________________________________________
280 void AliMpVRowSegmentSpecial::UpdateMotifVector()
282 /// Add motifs associated with the pad row segments in the specified
283 /// pad row in the fMotifs vector.
285 for (Int_t i=0; i<GetNofPadRows(); i++) {
286 AliMpPadRow* padRow = GetPadRow(i);
288 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
289 AliMpVMotif* motif = padRow->GetPadRowSegment(j)->GetMotif();
291 if (!HasMotif(motif)) {
293 fMotifs.push_back(motif);
294 fMotifPositionIds.push_back(
295 padRow->GetPadRowSegment(j)->GetMotifPositionId());
300 // resize array if needed
301 if (fNofMotifPositionIds<fgkMaxNofMotifPositionIds)
302 fMotifPositionIds.Set(fMotifPositionIds.GetSize()+
303 fgkMaxNofMotifPositionIds);
304 fMotifPositionIds.AddAt(
305 padRow->GetPadRowSegment(j)->GetMotifPositionId(),
306 fNofMotifPositionIds++);
313 //______________________________________________________________________________
314 Double_t AliMpVRowSegmentSpecial::HalfSizeY() const
316 /// Return the size in y of this row segment.
318 Double_t halfSizeY = 0.;
319 for (Int_t i=0; i<GetNofPadRows(); i++) {
320 halfSizeY += GetPadRow(i)->HalfSizeY();
326 //______________________________________________________________________________
327 AliMpVMotif* AliMpVRowSegmentSpecial::FindMotif(const TVector2& position) const
329 /// Return the motif of this row;
332 = FindPadRow(position.Y());
334 if (!padRow) return 0;
336 AliMpVPadRowSegment* padRowSegment
337 = padRow->FindPadRowSegment(position.X());
339 if (!padRowSegment) return 0;
341 return padRowSegment->GetMotif();
344 //______________________________________________________________________________
345 Int_t AliMpVRowSegmentSpecial::FindMotifPositionId(const TVector2& position) const
347 /// Return the motif position identified for the given
348 /// geometric position.
351 = FindPadRow(position.Y());
353 if (!padRow) return 0;
355 AliMpVPadRowSegment* padRowSegment
356 = padRow->FindPadRowSegment(position.X());
358 if (!padRowSegment) return 0;
360 return padRowSegment->GetMotifPositionId();
363 //______________________________________________________________________________
364 Bool_t AliMpVRowSegmentSpecial::HasMotifPosition(Int_t motifPositionId) const
366 /// Return true if the motif specified with the given position identifier
367 /// is in this segment.
369 if (FindPadRowSegment(motifPositionId))
375 //______________________________________________________________________________
376 TVector2 AliMpVRowSegmentSpecial::MotifCenter(Int_t motifPositionId) const
378 /// Return the coordinates of the motif specified with
379 /// the given position identifier.
381 // Try to get the motif position from the motif map first
382 AliMpMotifPosition* motifPosition
383 = GetRow()->GetMotifMap()->FindMotifPosition(motifPositionId);
384 if (motifPosition) return motifPosition->Position();
386 // Use slow method otherwise
387 return MotifCenterSlow(motifPositionId);
390 //______________________________________________________________________________
391 TVector2 AliMpVRowSegmentSpecial::Dimensions() const
393 /// Return the halflengths in x, y of the row segment rectangular envelope.
397 for (Int_t i=0; i<GetNofPadRows(); i++) {
398 AliMpPadRow* padRow = GetPadRow(i);
400 // Add all pad rows y halfsizes
401 y += padRow->HalfSizeY();
403 // Find the biggest pad rows x halfsize
405 = (padRow->GetPadRowSegment(0)->RightBorderX() -
406 padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX())/2.;
410 return TVector2(x, y);
413 //______________________________________________________________________________
414 AliMpRow* AliMpVRowSegmentSpecial::GetRow() const
416 /// Return the row.which this row segment belongs to.
421 //______________________________________________________________________________
422 Int_t AliMpVRowSegmentSpecial::GetNofMotifs() const
424 /// Return the number of different motifs present in this row segment.
427 return fMotifs.size();
430 return fMotifs.GetEntriesFast();
434 //______________________________________________________________________________
435 AliMpVMotif* AliMpVRowSegmentSpecial::GetMotif(Int_t i) const
437 /// Return the i-th motif present in this row segment.
443 return (AliMpVMotif*)fMotifs[i];
447 //______________________________________________________________________________
448 Int_t AliMpVRowSegmentSpecial::GetMotifPositionId(Int_t i) const
450 /// Return the i-th motif position Id present in this row segment.
452 return fMotifPositionIds[i];