]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpVRowSegmentSpecial.cxx
In mapping:
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpVRowSegmentSpecial.cxx
CommitLineData
dee1d5f1 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
ea4cae7a 16// $Id$
13985652 17// $MpId: AliMpVRowSegmentSpecial.cxx,v 1.9 2006/05/24 13:58:46 ivana Exp $
ea4cae7a 18// Category: sector
3d1463c8 19
20//-----------------------------------------------------------------------------
ea4cae7a 21// Class AliMpVRowSegmentSpecial
22// ----------------------------
23// Class describing a special row segment composed of the
24// pad rows.
dbe945cc 25// Included in AliRoot: 2003/05/02
ea4cae7a 26// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
3d1463c8 27//-----------------------------------------------------------------------------
ea4cae7a 28
ea4cae7a 29#include "AliMpVRowSegmentSpecial.h"
30#include "AliMpRow.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"
38
63ed9c6b 39#include <Riostream.h>
ea4cae7a 40
13985652 41/// \cond CLASSIMP
42ClassImp(AliMpVRowSegmentSpecial)
43/// \endcond
44
f79c58a5 45const Int_t AliMpVRowSegmentSpecial::fgkMaxNofMotifPositionIds = 20;
f79c58a5 46
ea4cae7a 47//______________________________________________________________________________
48AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(AliMpRow* row, Double_t offsetX)
49 : AliMpVRowSegment(),
50 fRow(row),
51 fOffsetX(offsetX),
52 fPadRows(),
53 fMotifs(),
2294822d 54 fMotifPositionIds(),
55 fNofMotifPositionIds(0)
ea4cae7a 56{
dee1d5f1 57/// Standard constructor
ea4cae7a 58}
59
60//______________________________________________________________________________
61AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial()
62 : AliMpVRowSegment(),
63 fRow(0),
64 fOffsetX(0.),
65 fPadRows(),
66 fMotifs(),
2294822d 67 fMotifPositionIds(),
68 fNofMotifPositionIds(0)
ea4cae7a 69{
dee1d5f1 70/// Default constructor
71
f79c58a5 72 fMotifPositionIds.Set(fgkMaxNofMotifPositionIds);
ea4cae7a 73}
74
75//______________________________________________________________________________
76AliMpVRowSegmentSpecial::~AliMpVRowSegmentSpecial()
77{
dee1d5f1 78/// Destructor
79
ea4cae7a 80 for (Int_t i=0; i<GetNofPadRows(); i++)
81 delete fPadRows[i];
82}
83
84//
85// protected methods
86//
87
88//______________________________________________________________________________
89AliMpPadRow* AliMpVRowSegmentSpecial::FindPadRow(Double_t y) const
90{
dee1d5f1 91/// Find the pad row in the given y coordinate.
ea4cae7a 92
93 Double_t lowBorder = fRow->LowBorderY();
94 Double_t highBorder = fRow->LowBorderY();
95
96 for (Int_t i=0; i<GetNofPadRows(); i++) {
97
98 AliMpPadRow* padRow = GetPadRow(i);
99 highBorder += 2.*padRow->HalfSizeY();
100
101 if ( y >= lowBorder && y <= highBorder)
102 return padRow;
103
104 lowBorder = highBorder;
105 }
106
107 return 0;
108}
109
110//______________________________________________________________________________
111AliMpVPadRowSegment*
112AliMpVRowSegmentSpecial::FindPadRowSegment(Int_t motifPositionId) const
113{
dee1d5f1 114/// Find the most down pad row segment with this motifPositionId.
ea4cae7a 115
116 for (Int_t i=0; i<GetNofPadRows(); i++) {
117 AliMpPadRow* padRow = GetPadRow(i);
118
119 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
120 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
121
122 if (padRowSegment->GetMotifPositionId() == motifPositionId)
123 return padRowSegment;
124 }
125 }
126 return 0;
127}
128
129//______________________________________________________________________________
130AliMpIntPair
131AliMpVRowSegmentSpecial::FindRelativeLowIndicesOf(Int_t motifPositionId) const
132{
dee1d5f1 133/// Return the lowest pad indices where the motif of the given position ID
134/// exist in this segment.
ea4cae7a 135
136 AliMpIntPair ans(0,1000);
137 AliMpIntPair ans0 = ans;
138 Int_t maxNofPadsX=0;
139
140 for (Int_t i=0; i<GetNofPadRows(); i++) {
141 AliMpPadRow* padRow = GetPadRow(i);
142
143 Int_t nofPadsX=0;
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
152 }
153 }
154 if (nofPadsX > maxNofPadsX) maxNofPadsX = nofPadsX;
155 }
156 if (ans == ans0) return AliMpIntPair::Invalid();
157
158 return AliMpIntPair(maxNofPadsX-ans.GetFirst(), ans.GetSecond());
159}
160
161//______________________________________________________________________________
162Int_t AliMpVRowSegmentSpecial::MaxNofPadsInRow() const
163{
dee1d5f1 164/// Return the maximum number of pads in this row segment along the X direction
ea4cae7a 165
166 Int_t maxNofPads = 0;
167
168 for (Int_t i=0; i<GetNofPadRows(); i++){
169 Int_t nofPads = GetPadRow(i)->GetNofPads();
170
171 // Find maximum
172 if (nofPads > maxNofPads) maxNofPads = nofPads;
173 }
174
175 return maxNofPads;
176}
177
178//______________________________________________________________________________
179Bool_t AliMpVRowSegmentSpecial::HasMotif(const AliMpVMotif* motif) const
180{
dee1d5f1 181/// Return true if the specified motif is already in fMotifs vector,
182/// returns false otherwise.
ea4cae7a 183
f79c58a5 184 for (Int_t i=0; i<fMotifs.GetEntriesFast(); i++)
b166d013 185 if (fMotifs[i] == (const TObject*)motif) return true;
ea4cae7a 186
187 return false;
188}
189
190//______________________________________________________________________________
191Int_t AliMpVRowSegmentSpecial::GetNofPadRows() const
192{
dee1d5f1 193/// Return number of pad rows.
ea4cae7a 194
f79c58a5 195 return fPadRows.GetEntriesFast();
ea4cae7a 196}
197
198//______________________________________________________________________________
199AliMpPadRow* AliMpVRowSegmentSpecial::GetPadRow(Int_t i) const
200{
dee1d5f1 201/// Return number of pad rows.
ea4cae7a 202
f79c58a5 203 return (AliMpPadRow*)fPadRows[i];
ea4cae7a 204}
205
206//
207// public methods
208//
209
210//______________________________________________________________________________
211void AliMpVRowSegmentSpecial::AddPadRow(AliMpPadRow* padRow)
212{
dee1d5f1 213/// Add a pad row.
ea4cae7a 214
215 padRow->SetOffsetX(fOffsetX);
216 padRow->SetID(GetNofPadRows());
f79c58a5 217
f79c58a5 218 fPadRows.Add(padRow);
ea4cae7a 219}
220
221//______________________________________________________________________________
222void AliMpVRowSegmentSpecial::UpdateMotifVector()
223{
dee1d5f1 224/// Add motifs associated with the pad row segments in the specified
225/// pad row in the fMotifs vector.
ea4cae7a 226
227 for (Int_t i=0; i<GetNofPadRows(); i++) {
228 AliMpPadRow* padRow = GetPadRow(i);
229
230 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
231 AliMpVMotif* motif = padRow->GetPadRowSegment(j)->GetMotif();
232
233 if (!HasMotif(motif)) {
f79c58a5 234 fMotifs.Add(motif);
235
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++);
ea4cae7a 243 }
244 }
245 }
246}
247
248//______________________________________________________________________________
249Double_t AliMpVRowSegmentSpecial::HalfSizeY() const
250{
dee1d5f1 251/// Return the size in y of this row segment.
ea4cae7a 252
253 Double_t halfSizeY = 0.;
254 for (Int_t i=0; i<GetNofPadRows(); i++) {
255 halfSizeY += GetPadRow(i)->HalfSizeY();
256 }
257
258 return halfSizeY;
259}
260
261//______________________________________________________________________________
262AliMpVMotif* AliMpVRowSegmentSpecial::FindMotif(const TVector2& position) const
263{
dee1d5f1 264/// Return the motif of this row;
ea4cae7a 265
266 AliMpPadRow* padRow
267 = FindPadRow(position.Y());
268
269 if (!padRow) return 0;
270
271 AliMpVPadRowSegment* padRowSegment
272 = padRow->FindPadRowSegment(position.X());
273
274 if (!padRowSegment) return 0;
275
276 return padRowSegment->GetMotif();
277}
278
279//______________________________________________________________________________
280Int_t AliMpVRowSegmentSpecial::FindMotifPositionId(const TVector2& position) const
281{
dee1d5f1 282/// Return the motif position identified for the given
283/// geometric position.
ea4cae7a 284
285 AliMpPadRow* padRow
286 = FindPadRow(position.Y());
287
288 if (!padRow) return 0;
289
290 AliMpVPadRowSegment* padRowSegment
291 = padRow->FindPadRowSegment(position.X());
292
293 if (!padRowSegment) return 0;
294
295 return padRowSegment->GetMotifPositionId();
296}
297
298//______________________________________________________________________________
299Bool_t AliMpVRowSegmentSpecial::HasMotifPosition(Int_t motifPositionId) const
300{
dee1d5f1 301/// Return true if the motif specified with the given position identifier
302/// is in this segment.
ea4cae7a 303
304 if (FindPadRowSegment(motifPositionId))
305 return true;
306 else
307 return false;
308}
309
310//______________________________________________________________________________
311TVector2 AliMpVRowSegmentSpecial::MotifCenter(Int_t motifPositionId) const
312{
dee1d5f1 313/// Return the coordinates of the motif specified with
314/// the given position identifier.
ea4cae7a 315
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();
320
321 // Use slow method otherwise
322 return MotifCenterSlow(motifPositionId);
323}
324
325//______________________________________________________________________________
326TVector2 AliMpVRowSegmentSpecial::Dimensions() const
327{
dee1d5f1 328/// Return the halflengths in x, y of the row segment rectangular envelope.
ea4cae7a 329
330 Double_t x = 0.;
331 Double_t y = 0.;
332 for (Int_t i=0; i<GetNofPadRows(); i++) {
333 AliMpPadRow* padRow = GetPadRow(i);
334
335 // Add all pad rows y halfsizes
336 y += padRow->HalfSizeY();
337
338 // Find the biggest pad rows x halfsize
339 Double_t xx
340 = (padRow->GetPadRowSegment(0)->RightBorderX() -
341 padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX())/2.;
342 if (xx > x) x = xx;
343 }
344
345 return TVector2(x, y);
346}
347
ea4cae7a 348//______________________________________________________________________________
349AliMpRow* AliMpVRowSegmentSpecial::GetRow() const
350{
dee1d5f1 351/// Return the row.which this row segment belongs to.
ea4cae7a 352
353 return fRow;
354}
355
356//______________________________________________________________________________
357Int_t AliMpVRowSegmentSpecial::GetNofMotifs() const
358{
dee1d5f1 359/// Return the number of different motifs present in this row segment.
ea4cae7a 360
f79c58a5 361 return fMotifs.GetEntriesFast();
ea4cae7a 362}
363
364//______________________________________________________________________________
365AliMpVMotif* AliMpVRowSegmentSpecial::GetMotif(Int_t i) const
366{
dee1d5f1 367/// Return the i-th motif present in this row segment.
ea4cae7a 368
f79c58a5 369 return (AliMpVMotif*)fMotifs[i];
ea4cae7a 370}
371
372//______________________________________________________________________________
373Int_t AliMpVRowSegmentSpecial::GetMotifPositionId(Int_t i) const
374{
dee1d5f1 375/// Return the i-th motif position Id present in this row segment.
ea4cae7a 376
377 return fMotifPositionIds[i];
378}
379