Line data Source code
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 :
16 : // $Id$
17 : // $MpId: AliMpVRowSegmentSpecial.cxx,v 1.9 2006/05/24 13:58:46 ivana Exp $
18 : // Category: sector
19 :
20 : //-----------------------------------------------------------------------------
21 : // Class AliMpVRowSegmentSpecial
22 : // ----------------------------
23 : // Class describing a special row segment composed of the
24 : // pad rows.
25 : // Included in AliRoot: 2003/05/02
26 : // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 : //-----------------------------------------------------------------------------
28 :
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 :
39 : #include <Riostream.h>
40 :
41 : /// \cond CLASSIMP
42 18 : ClassImp(AliMpVRowSegmentSpecial)
43 : /// \endcond
44 :
45 : const Int_t AliMpVRowSegmentSpecial::fgkMaxNofMotifPositionIds = 20;
46 :
47 : //______________________________________________________________________________
48 : AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(AliMpRow* row, Double_t offsetX)
49 93 : : AliMpVRowSegment(),
50 93 : fRow(row),
51 93 : fOffsetX(offsetX),
52 93 : fPadRows(),
53 93 : fMotifs(),
54 93 : fMotifPositionIds(),
55 93 : fNofMotifPositionIds(0)
56 279 : {
57 : /// Standard constructor
58 93 : }
59 :
60 : //______________________________________________________________________________
61 : AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial()
62 0 : : AliMpVRowSegment(),
63 0 : fRow(0),
64 0 : fOffsetX(0.),
65 0 : fPadRows(),
66 0 : fMotifs(),
67 0 : fMotifPositionIds(),
68 0 : fNofMotifPositionIds(0)
69 0 : {
70 : /// Default constructor
71 :
72 0 : fMotifPositionIds.Set(fgkMaxNofMotifPositionIds);
73 0 : }
74 :
75 : //______________________________________________________________________________
76 : AliMpVRowSegmentSpecial::~AliMpVRowSegmentSpecial()
77 124 : {
78 : /// Destructor
79 :
80 2718 : for (Int_t i=0; i<GetNofPadRows(); i++)
81 2532 : delete fPadRows[i];
82 62 : }
83 :
84 : //
85 : // protected methods
86 : //
87 :
88 : //______________________________________________________________________________
89 : AliMpPadRow* AliMpVRowSegmentSpecial::FindPadRow(Double_t y) const
90 : {
91 : /// Find the pad row in the given y coordinate.
92 :
93 0 : Double_t lowBorder = fRow->LowBorderY();
94 0 : Double_t highBorder = fRow->LowBorderY();
95 :
96 0 : for (Int_t i=0; i<GetNofPadRows(); i++) {
97 :
98 0 : AliMpPadRow* padRow = GetPadRow(i);
99 0 : highBorder += 2.*padRow->HalfSizeY();
100 :
101 0 : if ( y >= lowBorder && y <= highBorder)
102 0 : return padRow;
103 :
104 : lowBorder = highBorder;
105 0 : }
106 :
107 0 : return 0;
108 0 : }
109 :
110 : //______________________________________________________________________________
111 : AliMpVPadRowSegment*
112 : AliMpVRowSegmentSpecial::FindPadRowSegment(Int_t motifPositionId) const
113 : {
114 : /// Find the most down pad row segment with this motifPositionId.
115 :
116 894 : for (Int_t i=0; i<GetNofPadRows(); i++) {
117 336 : AliMpPadRow* padRow = GetPadRow(i);
118 :
119 1620 : for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
120 639 : AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
121 :
122 639 : if (padRowSegment->GetMotifPositionId() == motifPositionId)
123 222 : return padRowSegment;
124 417 : }
125 114 : }
126 0 : return 0;
127 222 : }
128 :
129 : //______________________________________________________________________________
130 : MpPair_t
131 : AliMpVRowSegmentSpecial::FindRelativeLowIndicesOf(Int_t motifPositionId) const
132 : {
133 : /// Return the lowest pad indices where the motif of the given position ID
134 : /// exist in this segment.
135 :
136 : Int_t ans0Ix = 0;
137 : Int_t ans0Iy = 1000;
138 : Int_t ansIx = 0;
139 : Int_t ansIy = 1000;
140 :
141 : Int_t maxNofPadsX=0;
142 :
143 3300 : for (Int_t i=0; i<GetNofPadRows(); i++) {
144 1506 : AliMpPadRow* padRow = GetPadRow(i);
145 :
146 : Int_t nofPadsX=0;
147 13932 : for ( Int_t j=0; j<padRow->GetNofPadRowSegments(); j++ ) {
148 5460 : AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
149 5460 : nofPadsX += padRowSegment->GetNofPads();
150 5460 : if (padRowSegment->GetMotifPositionId() == motifPositionId) {
151 1509 : if ( ansIx < nofPadsX ) ansIx = nofPadsX;
152 1338 : if ( ansIy >i ) ansIy = i;
153 : // ansIx = max (nof pads of this pos ID)
154 : // ansIy = min of pad row number
155 : }
156 : }
157 1998 : if ( nofPadsX > maxNofPadsX ) maxNofPadsX = nofPadsX;
158 : }
159 96 : if ( ansIx == ans0Ix && ansIy == ans0Iy ) return -1;
160 :
161 96 : return AliMp::Pair(maxNofPadsX-ansIx, ansIy);
162 96 : }
163 :
164 : //______________________________________________________________________________
165 : Int_t AliMpVRowSegmentSpecial::MaxNofPadsInRow() const
166 : {
167 : /// Return the maximum number of pads in this row segment along the X direction
168 :
169 : Int_t maxNofPads = 0;
170 :
171 5271 : for (Int_t i=0; i<GetNofPadRows(); i++){
172 2388 : Int_t nofPads = GetPadRow(i)->GetNofPads();
173 :
174 : // Find maximum
175 3084 : if (nofPads > maxNofPads) maxNofPads = nofPads;
176 : }
177 :
178 165 : return maxNofPads;
179 : }
180 :
181 : //______________________________________________________________________________
182 : Bool_t AliMpVRowSegmentSpecial::HasMotif(const AliMpVMotif* motif) const
183 : {
184 : /// Return true if the specified motif is already in fMotifs vector,
185 : /// returns false otherwise.
186 :
187 12258 : for (Int_t i=0; i<fMotifs.GetEntriesFast(); i++)
188 6756 : if (fMotifs[i] == (const TObject*)motif) return true;
189 :
190 183 : return false;
191 2169 : }
192 :
193 : //______________________________________________________________________________
194 : Int_t AliMpVRowSegmentSpecial::GetNofPadRows() const
195 : {
196 : /// Return number of pad rows.
197 :
198 486988 : return fPadRows.GetEntriesFast();
199 : }
200 :
201 : //______________________________________________________________________________
202 : AliMpPadRow* AliMpVRowSegmentSpecial::GetPadRow(Int_t i) const
203 : {
204 : /// Return number of pad rows.
205 :
206 454298 : return (AliMpPadRow*)fPadRows[i];
207 : }
208 :
209 : //
210 : // public methods
211 : //
212 :
213 : //______________________________________________________________________________
214 : void AliMpVRowSegmentSpecial::AddPadRow(AliMpPadRow* padRow)
215 : {
216 : /// Add a pad row.
217 :
218 2532 : padRow->SetOffsetX(fOffsetX);
219 1266 : padRow->SetID(GetNofPadRows());
220 :
221 1266 : fPadRows.Add(padRow);
222 1266 : }
223 :
224 : //______________________________________________________________________________
225 : void AliMpVRowSegmentSpecial::UpdateMotifVector()
226 : {
227 : /// Add motifs associated with the pad row segments in the specified
228 : /// pad row in the fMotifs vector.
229 :
230 2811 : for (Int_t i=0; i<GetNofPadRows(); i++) {
231 1266 : AliMpPadRow* padRow = GetPadRow(i);
232 :
233 6870 : for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
234 2169 : AliMpVMotif* motif = padRow->GetPadRowSegment(j)->GetMotif();
235 :
236 2169 : if (!HasMotif(motif)) {
237 183 : fMotifs.Add(motif);
238 :
239 : // resize array if needed
240 183 : if (fNofMotifPositionIds<fgkMaxNofMotifPositionIds)
241 183 : fMotifPositionIds.Set(fMotifPositionIds.GetSize()+
242 : fgkMaxNofMotifPositionIds);
243 366 : fMotifPositionIds.AddAt(
244 183 : padRow->GetPadRowSegment(j)->GetMotifPositionId(),
245 183 : fNofMotifPositionIds++);
246 183 : }
247 : }
248 : }
249 93 : }
250 :
251 : //______________________________________________________________________________
252 : Double_t AliMpVRowSegmentSpecial::HalfSizeY() const
253 : {
254 : /// Return the size in y of this row segment.
255 :
256 : Double_t halfSizeY = 0.;
257 404341 : for (Int_t i=0; i<GetNofPadRows(); i++) {
258 184811 : halfSizeY += GetPadRow(i)->HalfSizeY();
259 : }
260 :
261 11573 : return halfSizeY;
262 : }
263 :
264 : //______________________________________________________________________________
265 : AliMpVMotif* AliMpVRowSegmentSpecial::FindMotif(Double_t x, Double_t y) const
266 : {
267 : /// Return the motif of this row;
268 :
269 0 : AliMpPadRow* padRow = FindPadRow(y);
270 :
271 0 : if ( ! padRow ) return 0;
272 :
273 0 : AliMpVPadRowSegment* padRowSegment = padRow->FindPadRowSegment(x);
274 :
275 0 : if (! padRowSegment ) return 0;
276 :
277 0 : return padRowSegment->GetMotif();
278 0 : }
279 :
280 : //______________________________________________________________________________
281 : Int_t AliMpVRowSegmentSpecial::FindMotifPositionId(Double_t x, Double_t y) const
282 : {
283 : /// Return the motif position identified for the given
284 : /// geometric position.
285 :
286 0 : AliMpPadRow* padRow = FindPadRow(y);
287 :
288 0 : if ( ! padRow ) return 0;
289 :
290 0 : AliMpVPadRowSegment* padRowSegment = padRow->FindPadRowSegment(x);
291 :
292 0 : if ( ! padRowSegment ) return 0;
293 :
294 0 : return padRowSegment->GetMotifPositionId();
295 0 : }
296 :
297 : //______________________________________________________________________________
298 : Bool_t AliMpVRowSegmentSpecial::HasMotifPosition(Int_t motifPositionId) const
299 : {
300 : /// Return true if the motif specified with the given position identifier
301 : /// is in this segment.
302 :
303 0 : if (FindPadRowSegment(motifPositionId))
304 0 : return true;
305 : else
306 0 : return false;
307 0 : }
308 :
309 : //______________________________________________________________________________
310 : void AliMpVRowSegmentSpecial::MotifCenter(Int_t motifPositionId,
311 : Double_t& x, Double_t& y) const
312 : {
313 : /// Return the coordinates of the motif specified with
314 : /// the given position identifier.
315 :
316 : // Try to get the motif position from the motif map first
317 : AliMpMotifPosition* motifPosition
318 366 : = GetRow()->GetMotifMap()->FindMotifPosition(motifPositionId);
319 :
320 183 : if (motifPosition) {
321 30 : x = motifPosition->GetPositionX(),
322 30 : y = motifPosition->GetPositionY();
323 30 : }
324 : else {
325 153 : MotifCenterSlow(motifPositionId, x, y);
326 : }
327 183 : }
328 :
329 : //______________________________________________________________________________
330 : Double_t AliMpVRowSegmentSpecial::GetDimensionX() const
331 : {
332 : /// Return the halflengths in x, y of the row segment rectangular envelope.
333 :
334 : Double_t x = 0.;
335 0 : for (Int_t i=0; i<GetNofPadRows(); i++) {
336 0 : AliMpPadRow* padRow = GetPadRow(i);
337 :
338 : // Find the biggest pad rows x halfsize
339 : Double_t xx
340 0 : = (padRow->GetPadRowSegment(0)->RightBorderX() -
341 0 : padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX())/2.;
342 0 : if (xx > x) x = xx;
343 : }
344 :
345 0 : return x;
346 : }
347 :
348 : //______________________________________________________________________________
349 : Double_t AliMpVRowSegmentSpecial::GetDimensionY() const
350 : {
351 : /// Return the halflengths in x, y of the row segment rectangular envelope.
352 :
353 : Double_t y = 0.;
354 0 : for (Int_t i=0; i<GetNofPadRows(); i++) {
355 0 : AliMpPadRow* padRow = GetPadRow(i);
356 :
357 : // Add all pad rows y halfsizes
358 0 : y += padRow->HalfSizeY();
359 : }
360 :
361 0 : return y;
362 : }
363 :
364 : //______________________________________________________________________________
365 : AliMpRow* AliMpVRowSegmentSpecial::GetRow() const
366 : {
367 : /// Return the row.which this row segment belongs to.
368 :
369 1572 : return fRow;
370 : }
371 :
372 : //______________________________________________________________________________
373 : Int_t AliMpVRowSegmentSpecial::GetNofMotifs() const
374 : {
375 : /// Return the number of different motifs present in this row segment.
376 :
377 1892 : return fMotifs.GetEntriesFast();
378 : }
379 :
380 : //______________________________________________________________________________
381 : AliMpVMotif* AliMpVRowSegmentSpecial::GetMotif(Int_t i) const
382 : {
383 : /// Return the i-th motif present in this row segment.
384 :
385 1104 : return (AliMpVMotif*)fMotifs[i];
386 : }
387 :
388 : //______________________________________________________________________________
389 : Int_t AliMpVRowSegmentSpecial::GetMotifPositionId(Int_t i) const
390 : {
391 : /// Return the i-th motif position Id present in this row segment.
392 :
393 1340 : return fMotifPositionIds[i];
394 : }
395 :
|