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.8 2006/03/17 11:38:43 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 const Int_t AliMpVRowSegmentSpecial::fgkMaxNofMotifPositionIds = 20;
43 ClassImp(AliMpVRowSegmentSpecial)
45 //______________________________________________________________________________
46 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(AliMpRow* row, Double_t offsetX)
54 ,fNofMotifPositionIds(0)
57 /// Standard constructor
60 //______________________________________________________________________________
61 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial()
69 ,fNofMotifPositionIds(0)
72 /// Default constructor
75 fMotifPositionIds.Set(fgkMaxNofMotifPositionIds);
79 //_____________________________________________________________________________
80 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(
81 const AliMpVRowSegmentSpecial& right)
82 : AliMpVRowSegment(right)
84 /// Protected copy constructor (not provided)
86 Fatal("AliMpVRowSegmentSpecial", "Copy constructor not provided.");
89 //______________________________________________________________________________
90 AliMpVRowSegmentSpecial::~AliMpVRowSegmentSpecial()
94 for (Int_t i=0; i<GetNofPadRows(); i++)
102 //_____________________________________________________________________________
103 AliMpVRowSegmentSpecial&
104 AliMpVRowSegmentSpecial::operator=(const AliMpVRowSegmentSpecial& right)
106 /// Protected assignment operator (not provided)
108 // check assignment to self
109 if (this == &right) return *this;
111 Fatal("operator =", "Assignment operator not provided.");
120 //______________________________________________________________________________
121 AliMpPadRow* AliMpVRowSegmentSpecial::FindPadRow(Double_t y) const
123 /// Find the pad row in the given y coordinate.
125 Double_t lowBorder = fRow->LowBorderY();
126 Double_t highBorder = fRow->LowBorderY();
128 for (Int_t i=0; i<GetNofPadRows(); i++) {
130 AliMpPadRow* padRow = GetPadRow(i);
131 highBorder += 2.*padRow->HalfSizeY();
133 if ( y >= lowBorder && y <= highBorder)
136 lowBorder = highBorder;
142 //______________________________________________________________________________
144 AliMpVRowSegmentSpecial::FindPadRowSegment(Int_t motifPositionId) const
146 /// Find the most down pad row segment with this motifPositionId.
148 for (Int_t i=0; i<GetNofPadRows(); i++) {
149 AliMpPadRow* padRow = GetPadRow(i);
151 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
152 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
154 if (padRowSegment->GetMotifPositionId() == motifPositionId)
155 return padRowSegment;
161 //______________________________________________________________________________
163 AliMpVRowSegmentSpecial::FindRelativeLowIndicesOf(Int_t motifPositionId) const
165 /// Return the lowest pad indices where the motif of the given position ID
166 /// exist in this segment.
168 AliMpIntPair ans(0,1000);
169 AliMpIntPair ans0 = ans;
172 for (Int_t i=0; i<GetNofPadRows(); i++) {
173 AliMpPadRow* padRow = GetPadRow(i);
176 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
177 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
178 nofPadsX += padRowSegment->GetNofPads();
179 if (padRowSegment->GetMotifPositionId() == motifPositionId) {
180 if (ans.GetFirst() < nofPadsX) ans.SetFirst(nofPadsX);
181 if (ans.GetSecond()>i) ans.SetSecond(i);
182 // ans.First = max (nof pads of this pos ID)
183 // ans.Second = min of pad row number
186 if (nofPadsX > maxNofPadsX) maxNofPadsX = nofPadsX;
188 if (ans == ans0) return AliMpIntPair::Invalid();
190 return AliMpIntPair(maxNofPadsX-ans.GetFirst(), ans.GetSecond());
193 //______________________________________________________________________________
194 Int_t AliMpVRowSegmentSpecial::MaxNofPadsInRow() const
196 /// Return the maximum number of pads in this row segment along the X direction
198 Int_t maxNofPads = 0;
200 for (Int_t i=0; i<GetNofPadRows(); i++){
201 Int_t nofPads = GetPadRow(i)->GetNofPads();
204 if (nofPads > maxNofPads) maxNofPads = nofPads;
210 //______________________________________________________________________________
211 Bool_t AliMpVRowSegmentSpecial::HasMotif(const AliMpVMotif* motif) const
213 /// Return true if the specified motif is already in fMotifs vector,
214 /// returns false otherwise.
217 for (UInt_t i=0; i<fMotifs.size(); i++)
218 if (fMotifs[i] == motif) return true;
222 for (Int_t i=0; i<fMotifs.GetEntriesFast(); i++)
223 if (fMotifs[i] == (const TObject*)motif) return true;
229 //______________________________________________________________________________
230 Int_t AliMpVRowSegmentSpecial::GetNofPadRows() const
232 /// Return number of pad rows.
235 return fPadRows.size();
239 return fPadRows.GetEntriesFast();
243 //______________________________________________________________________________
244 AliMpPadRow* AliMpVRowSegmentSpecial::GetPadRow(Int_t i) const
246 /// Return number of pad rows.
253 return (AliMpPadRow*)fPadRows[i];
261 //______________________________________________________________________________
262 void AliMpVRowSegmentSpecial::AddPadRow(AliMpPadRow* padRow)
266 padRow->SetOffsetX(fOffsetX);
267 padRow->SetID(GetNofPadRows());
270 fPadRows.push_back(padRow);
274 fPadRows.Add(padRow);
278 //______________________________________________________________________________
279 void AliMpVRowSegmentSpecial::UpdateMotifVector()
281 /// Add motifs associated with the pad row segments in the specified
282 /// pad row in the fMotifs vector.
284 for (Int_t i=0; i<GetNofPadRows(); i++) {
285 AliMpPadRow* padRow = GetPadRow(i);
287 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
288 AliMpVMotif* motif = padRow->GetPadRowSegment(j)->GetMotif();
290 if (!HasMotif(motif)) {
292 fMotifs.push_back(motif);
293 fMotifPositionIds.push_back(
294 padRow->GetPadRowSegment(j)->GetMotifPositionId());
299 // resize array if needed
300 if (fNofMotifPositionIds<fgkMaxNofMotifPositionIds)
301 fMotifPositionIds.Set(fMotifPositionIds.GetSize()+
302 fgkMaxNofMotifPositionIds);
303 fMotifPositionIds.AddAt(
304 padRow->GetPadRowSegment(j)->GetMotifPositionId(),
305 fNofMotifPositionIds++);
312 //______________________________________________________________________________
313 Double_t AliMpVRowSegmentSpecial::HalfSizeY() const
315 /// Return the size in y of this row segment.
317 Double_t halfSizeY = 0.;
318 for (Int_t i=0; i<GetNofPadRows(); i++) {
319 halfSizeY += GetPadRow(i)->HalfSizeY();
325 //______________________________________________________________________________
326 AliMpVMotif* AliMpVRowSegmentSpecial::FindMotif(const TVector2& position) const
328 /// Return the motif of this row;
331 = FindPadRow(position.Y());
333 if (!padRow) return 0;
335 AliMpVPadRowSegment* padRowSegment
336 = padRow->FindPadRowSegment(position.X());
338 if (!padRowSegment) return 0;
340 return padRowSegment->GetMotif();
343 //______________________________________________________________________________
344 Int_t AliMpVRowSegmentSpecial::FindMotifPositionId(const TVector2& position) const
346 /// Return the motif position identified for the given
347 /// geometric position.
350 = FindPadRow(position.Y());
352 if (!padRow) return 0;
354 AliMpVPadRowSegment* padRowSegment
355 = padRow->FindPadRowSegment(position.X());
357 if (!padRowSegment) return 0;
359 return padRowSegment->GetMotifPositionId();
362 //______________________________________________________________________________
363 Bool_t AliMpVRowSegmentSpecial::HasMotifPosition(Int_t motifPositionId) const
365 /// Return true if the motif specified with the given position identifier
366 /// is in this segment.
368 if (FindPadRowSegment(motifPositionId))
374 //______________________________________________________________________________
375 TVector2 AliMpVRowSegmentSpecial::MotifCenter(Int_t motifPositionId) const
377 /// Return the coordinates of the motif specified with
378 /// the given position identifier.
380 // Try to get the motif position from the motif map first
381 AliMpMotifPosition* motifPosition
382 = GetRow()->GetMotifMap()->FindMotifPosition(motifPositionId);
383 if (motifPosition) return motifPosition->Position();
385 // Use slow method otherwise
386 return MotifCenterSlow(motifPositionId);
389 //______________________________________________________________________________
390 TVector2 AliMpVRowSegmentSpecial::Dimensions() const
392 /// Return the halflengths in x, y of the row segment rectangular envelope.
396 for (Int_t i=0; i<GetNofPadRows(); i++) {
397 AliMpPadRow* padRow = GetPadRow(i);
399 // Add all pad rows y halfsizes
400 y += padRow->HalfSizeY();
402 // Find the biggest pad rows x halfsize
404 = (padRow->GetPadRowSegment(0)->RightBorderX() -
405 padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX())/2.;
409 return TVector2(x, y);
412 //______________________________________________________________________________
413 AliMpRow* AliMpVRowSegmentSpecial::GetRow() const
415 /// Return the row.which this row segment belongs to.
420 //______________________________________________________________________________
421 Int_t AliMpVRowSegmentSpecial::GetNofMotifs() const
423 /// Return the number of different motifs present in this row segment.
426 return fMotifs.size();
429 return fMotifs.GetEntriesFast();
433 //______________________________________________________________________________
434 AliMpVMotif* AliMpVRowSegmentSpecial::GetMotif(Int_t i) const
436 /// Return the i-th motif present in this row segment.
442 return (AliMpVMotif*)fMotifs[i];
446 //______________________________________________________________________________
447 Int_t AliMpVRowSegmentSpecial::GetMotifPositionId(Int_t i) const
449 /// Return the i-th motif position Id present in this row segment.
451 return fMotifPositionIds[i];