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)
45 const Int_t AliMpVRowSegmentSpecial::fgkMaxNofMotifPositionIds = 20;
47 //______________________________________________________________________________
48 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(AliMpRow* row, Double_t offsetX)
55 fNofMotifPositionIds(0)
57 /// Standard constructor
60 //______________________________________________________________________________
61 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial()
68 fNofMotifPositionIds(0)
70 /// Default constructor
72 fMotifPositionIds.Set(fgkMaxNofMotifPositionIds);
75 //______________________________________________________________________________
76 AliMpVRowSegmentSpecial::~AliMpVRowSegmentSpecial()
80 for (Int_t i=0; i<GetNofPadRows(); i++)
88 //______________________________________________________________________________
89 AliMpPadRow* AliMpVRowSegmentSpecial::FindPadRow(Double_t y) const
91 /// Find the pad row in the given y coordinate.
93 Double_t lowBorder = fRow->LowBorderY();
94 Double_t highBorder = fRow->LowBorderY();
96 for (Int_t i=0; i<GetNofPadRows(); i++) {
98 AliMpPadRow* padRow = GetPadRow(i);
99 highBorder += 2.*padRow->HalfSizeY();
101 if ( y >= lowBorder && y <= highBorder)
104 lowBorder = highBorder;
110 //______________________________________________________________________________
112 AliMpVRowSegmentSpecial::FindPadRowSegment(Int_t motifPositionId) const
114 /// Find the most down pad row segment with this motifPositionId.
116 for (Int_t i=0; i<GetNofPadRows(); i++) {
117 AliMpPadRow* padRow = GetPadRow(i);
119 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
120 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
122 if (padRowSegment->GetMotifPositionId() == motifPositionId)
123 return padRowSegment;
129 //______________________________________________________________________________
131 AliMpVRowSegmentSpecial::FindRelativeLowIndicesOf(Int_t motifPositionId) const
133 /// Return the lowest pad indices where the motif of the given position ID
134 /// exist in this segment.
136 AliMpIntPair ans(0,1000);
137 AliMpIntPair ans0 = ans;
140 for (Int_t i=0; i<GetNofPadRows(); i++) {
141 AliMpPadRow* padRow = GetPadRow(i);
144 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
145 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
146 nofPadsX += padRowSegment->GetNofPads();
147 if (padRowSegment->GetMotifPositionId() == motifPositionId) {
148 if (ans.GetFirst() < nofPadsX) ans.SetFirst(nofPadsX);
149 if (ans.GetSecond()>i) ans.SetSecond(i);
150 // ans.First = max (nof pads of this pos ID)
151 // ans.Second = min of pad row number
154 if (nofPadsX > maxNofPadsX) maxNofPadsX = nofPadsX;
156 if (ans == ans0) return AliMpIntPair::Invalid();
158 return AliMpIntPair(maxNofPadsX-ans.GetFirst(), ans.GetSecond());
161 //______________________________________________________________________________
162 Int_t AliMpVRowSegmentSpecial::MaxNofPadsInRow() const
164 /// Return the maximum number of pads in this row segment along the X direction
166 Int_t maxNofPads = 0;
168 for (Int_t i=0; i<GetNofPadRows(); i++){
169 Int_t nofPads = GetPadRow(i)->GetNofPads();
172 if (nofPads > maxNofPads) maxNofPads = nofPads;
178 //______________________________________________________________________________
179 Bool_t AliMpVRowSegmentSpecial::HasMotif(const AliMpVMotif* motif) const
181 /// Return true if the specified motif is already in fMotifs vector,
182 /// returns false otherwise.
184 for (Int_t i=0; i<fMotifs.GetEntriesFast(); i++)
185 if (fMotifs[i] == (const TObject*)motif) return true;
190 //______________________________________________________________________________
191 Int_t AliMpVRowSegmentSpecial::GetNofPadRows() const
193 /// Return number of pad rows.
195 return fPadRows.GetEntriesFast();
198 //______________________________________________________________________________
199 AliMpPadRow* AliMpVRowSegmentSpecial::GetPadRow(Int_t i) const
201 /// Return number of pad rows.
203 return (AliMpPadRow*)fPadRows[i];
210 //______________________________________________________________________________
211 void AliMpVRowSegmentSpecial::AddPadRow(AliMpPadRow* padRow)
215 padRow->SetOffsetX(fOffsetX);
216 padRow->SetID(GetNofPadRows());
218 fPadRows.Add(padRow);
221 //______________________________________________________________________________
222 void AliMpVRowSegmentSpecial::UpdateMotifVector()
224 /// Add motifs associated with the pad row segments in the specified
225 /// pad row in the fMotifs vector.
227 for (Int_t i=0; i<GetNofPadRows(); i++) {
228 AliMpPadRow* padRow = GetPadRow(i);
230 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
231 AliMpVMotif* motif = padRow->GetPadRowSegment(j)->GetMotif();
233 if (!HasMotif(motif)) {
236 // resize array if needed
237 if (fNofMotifPositionIds<fgkMaxNofMotifPositionIds)
238 fMotifPositionIds.Set(fMotifPositionIds.GetSize()+
239 fgkMaxNofMotifPositionIds);
240 fMotifPositionIds.AddAt(
241 padRow->GetPadRowSegment(j)->GetMotifPositionId(),
242 fNofMotifPositionIds++);
248 //______________________________________________________________________________
249 Double_t AliMpVRowSegmentSpecial::HalfSizeY() const
251 /// Return the size in y of this row segment.
253 Double_t halfSizeY = 0.;
254 for (Int_t i=0; i<GetNofPadRows(); i++) {
255 halfSizeY += GetPadRow(i)->HalfSizeY();
261 //______________________________________________________________________________
262 AliMpVMotif* AliMpVRowSegmentSpecial::FindMotif(const TVector2& position) const
264 /// Return the motif of this row;
267 = FindPadRow(position.Y());
269 if (!padRow) return 0;
271 AliMpVPadRowSegment* padRowSegment
272 = padRow->FindPadRowSegment(position.X());
274 if (!padRowSegment) return 0;
276 return padRowSegment->GetMotif();
279 //______________________________________________________________________________
280 Int_t AliMpVRowSegmentSpecial::FindMotifPositionId(const TVector2& position) const
282 /// Return the motif position identified for the given
283 /// geometric position.
286 = FindPadRow(position.Y());
288 if (!padRow) return 0;
290 AliMpVPadRowSegment* padRowSegment
291 = padRow->FindPadRowSegment(position.X());
293 if (!padRowSegment) return 0;
295 return padRowSegment->GetMotifPositionId();
298 //______________________________________________________________________________
299 Bool_t AliMpVRowSegmentSpecial::HasMotifPosition(Int_t motifPositionId) const
301 /// Return true if the motif specified with the given position identifier
302 /// is in this segment.
304 if (FindPadRowSegment(motifPositionId))
310 //______________________________________________________________________________
311 TVector2 AliMpVRowSegmentSpecial::MotifCenter(Int_t motifPositionId) const
313 /// Return the coordinates of the motif specified with
314 /// the given position identifier.
316 // Try to get the motif position from the motif map first
317 AliMpMotifPosition* motifPosition
318 = GetRow()->GetMotifMap()->FindMotifPosition(motifPositionId);
319 if (motifPosition) return motifPosition->Position();
321 // Use slow method otherwise
322 return MotifCenterSlow(motifPositionId);
325 //______________________________________________________________________________
326 TVector2 AliMpVRowSegmentSpecial::Dimensions() const
328 /// Return the halflengths in x, y of the row segment rectangular envelope.
332 for (Int_t i=0; i<GetNofPadRows(); i++) {
333 AliMpPadRow* padRow = GetPadRow(i);
335 // Add all pad rows y halfsizes
336 y += padRow->HalfSizeY();
338 // Find the biggest pad rows x halfsize
340 = (padRow->GetPadRowSegment(0)->RightBorderX() -
341 padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX())/2.;
345 return TVector2(x, y);
348 //______________________________________________________________________________
349 AliMpRow* AliMpVRowSegmentSpecial::GetRow() const
351 /// Return the row.which this row segment belongs to.
356 //______________________________________________________________________________
357 Int_t AliMpVRowSegmentSpecial::GetNofMotifs() const
359 /// Return the number of different motifs present in this row segment.
361 return fMotifs.GetEntriesFast();
364 //______________________________________________________________________________
365 AliMpVMotif* AliMpVRowSegmentSpecial::GetMotif(Int_t i) const
367 /// Return the i-th motif present in this row segment.
369 return (AliMpVMotif*)fMotifs[i];
372 //______________________________________________________________________________
373 Int_t AliMpVRowSegmentSpecial::GetMotifPositionId(Int_t i) const
375 /// Return the i-th motif position Id present in this row segment.
377 return fMotifPositionIds[i];