]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpVRowSegmentSpecial.cxx
In assignment operator: call Copy function only once
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpVRowSegmentSpecial.cxx
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 ClassImp(AliMpVRowSegmentSpecial)
43 /// \endcond
44
45 #ifdef WITH_ROOT
46 const Int_t  AliMpVRowSegmentSpecial::fgkMaxNofMotifPositionIds = 20;
47 #endif    
48
49 //______________________________________________________________________________
50 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(AliMpRow* row, Double_t offsetX)
51   : AliMpVRowSegment(),
52     fRow(row),
53     fOffsetX(offsetX),
54     fPadRows(),
55     fMotifs(),
56     fMotifPositionIds()
57 #ifdef WITH_ROOT
58     ,fNofMotifPositionIds(0)
59 #endif    
60 {
61 /// Standard constructor  
62 }
63
64 //______________________________________________________________________________
65 AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial() 
66   : AliMpVRowSegment(),
67     fRow(0),
68     fOffsetX(0.),
69     fPadRows(),
70     fMotifs(),
71     fMotifPositionIds()
72 #ifdef WITH_ROOT
73     ,fNofMotifPositionIds(0)
74 #endif    
75 {
76 /// Default constructor  
77
78 #ifdef WITH_ROOT
79    fMotifPositionIds.Set(fgkMaxNofMotifPositionIds);
80 #endif    
81 }
82
83 //______________________________________________________________________________
84 AliMpVRowSegmentSpecial::~AliMpVRowSegmentSpecial() 
85 {
86 /// Destructor
87   
88   for (Int_t i=0; i<GetNofPadRows(); i++)
89     delete fPadRows[i];
90 }
91
92 //
93 // protected methods  
94 //
95
96 //______________________________________________________________________________
97 AliMpPadRow*  AliMpVRowSegmentSpecial::FindPadRow(Double_t y) const
98 {
99 /// Find the pad row in the given y coordinate.
100
101   Double_t lowBorder =  fRow->LowBorderY();
102   Double_t highBorder = fRow->LowBorderY();
103   
104   for (Int_t i=0; i<GetNofPadRows(); i++) {    
105
106     AliMpPadRow* padRow = GetPadRow(i);
107     highBorder += 2.*padRow->HalfSizeY();
108
109     if ( y >= lowBorder &&  y <= highBorder)
110       return padRow;
111
112     lowBorder = highBorder;
113   }
114   
115   return 0;     
116 }
117
118 //______________________________________________________________________________
119 AliMpVPadRowSegment*  
120 AliMpVRowSegmentSpecial::FindPadRowSegment(Int_t motifPositionId) const
121 {
122 /// Find the most down pad row segment with this motifPositionId.
123
124   for (Int_t i=0; i<GetNofPadRows(); i++) {
125     AliMpPadRow* padRow = GetPadRow(i);    
126
127     for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) { 
128       AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
129
130       if (padRowSegment->GetMotifPositionId() == motifPositionId) 
131         return padRowSegment;
132     }
133   }
134   return 0;     
135 }
136
137 //______________________________________________________________________________
138 AliMpIntPair 
139 AliMpVRowSegmentSpecial::FindRelativeLowIndicesOf(Int_t motifPositionId) const 
140
141 /// Return the lowest pad indices where the motif of the given position ID
142 /// exist in this segment.
143
144   AliMpIntPair ans(0,1000);
145   AliMpIntPair ans0 = ans;
146   Int_t maxNofPadsX=0;
147   
148   for (Int_t i=0; i<GetNofPadRows(); i++) {
149     AliMpPadRow* padRow = GetPadRow(i);
150
151     Int_t nofPadsX=0;
152     for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
153       AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
154       nofPadsX += padRowSegment->GetNofPads();
155       if (padRowSegment->GetMotifPositionId() == motifPositionId) {
156          if (ans.GetFirst() < nofPadsX) ans.SetFirst(nofPadsX);
157          if (ans.GetSecond()>i) ans.SetSecond(i);
158                   // ans.First = max (nof pads of this pos ID)
159                   // ans.Second = min of pad row number
160       }
161     }  
162     if (nofPadsX > maxNofPadsX) maxNofPadsX = nofPadsX;
163   }    
164   if (ans == ans0) return AliMpIntPair::Invalid();
165   
166   return AliMpIntPair(maxNofPadsX-ans.GetFirst(), ans.GetSecond());
167 }
168  
169 //______________________________________________________________________________
170 Int_t  AliMpVRowSegmentSpecial::MaxNofPadsInRow() const 
171
172 /// Return the maximum number of pads in this row segment along the X direction
173
174   Int_t maxNofPads = 0;    
175
176   for (Int_t i=0; i<GetNofPadRows(); i++){
177     Int_t nofPads = GetPadRow(i)->GetNofPads(); 
178
179     // Find maximum
180     if (nofPads > maxNofPads) maxNofPads = nofPads;
181   }
182     
183   return maxNofPads;
184 }
185
186 //______________________________________________________________________________
187 Bool_t AliMpVRowSegmentSpecial::HasMotif(const AliMpVMotif* motif) const
188 {
189 /// Return true if the specified motif is already in fMotifs vector,
190 /// returns false otherwise.
191
192 #ifdef WITH_STL
193   for (UInt_t i=0; i<fMotifs.size(); i++)
194     if (fMotifs[i] == motif) return true;
195 #endif
196
197 #ifdef WITH_ROOT
198   for (Int_t i=0; i<fMotifs.GetEntriesFast(); i++)
199     if (fMotifs[i] == (const TObject*)motif) return true;
200 #endif
201
202   return false;  
203 }
204
205 //______________________________________________________________________________
206 Int_t AliMpVRowSegmentSpecial::GetNofPadRows() const
207 {
208 /// Return number of pad rows.
209
210 #ifdef WITH_STL
211   return fPadRows.size();
212 #endif
213
214 #ifdef WITH_ROOT
215   return fPadRows.GetEntriesFast();
216 #endif
217 }  
218
219 //______________________________________________________________________________
220 AliMpPadRow* AliMpVRowSegmentSpecial::GetPadRow(Int_t i) const
221 {
222 /// Return number of pad rows.
223
224 #ifdef WITH_STL
225   return fPadRows[i];
226 #endif
227
228 #ifdef WITH_ROOT
229   return (AliMpPadRow*)fPadRows[i];
230 #endif
231 }  
232
233 //
234 // public methods  
235 //
236
237 //______________________________________________________________________________
238 void  AliMpVRowSegmentSpecial::AddPadRow(AliMpPadRow* padRow)
239 {
240 /// Add a pad row.
241
242   padRow->SetOffsetX(fOffsetX);
243   padRow->SetID(GetNofPadRows());
244
245 #ifdef WITH_STL
246   fPadRows.push_back(padRow);
247 #endif
248
249 #ifdef WITH_ROOT
250   fPadRows.Add(padRow);
251 #endif
252 }  
253
254 //______________________________________________________________________________
255 void AliMpVRowSegmentSpecial::UpdateMotifVector()
256 {
257 /// Add motifs associated with the pad row segments in the specified
258 /// pad row in the fMotifs vector.
259
260   for (Int_t i=0; i<GetNofPadRows(); i++) {
261     AliMpPadRow* padRow = GetPadRow(i);
262  
263     for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
264       AliMpVMotif* motif = padRow->GetPadRowSegment(j)->GetMotif();            
265
266       if (!HasMotif(motif)) {
267 #ifdef WITH_STL
268         fMotifs.push_back(motif);        
269         fMotifPositionIds.push_back(
270           padRow->GetPadRowSegment(j)->GetMotifPositionId());
271 #endif
272 #ifdef WITH_ROOT
273         fMotifs.Add(motif);
274         
275         // resize array if needed
276         if (fNofMotifPositionIds<fgkMaxNofMotifPositionIds)
277           fMotifPositionIds.Set(fMotifPositionIds.GetSize()+
278                                 fgkMaxNofMotifPositionIds);      
279         fMotifPositionIds.AddAt(
280           padRow->GetPadRowSegment(j)->GetMotifPositionId(),
281           fNofMotifPositionIds++);
282 #endif
283       }
284     }  
285   }
286 }
287
288 //______________________________________________________________________________
289 Double_t  AliMpVRowSegmentSpecial::HalfSizeY() const
290 {
291 /// Return the size in y of this row segment.
292
293   Double_t halfSizeY = 0.;
294   for (Int_t i=0; i<GetNofPadRows(); i++) {
295     halfSizeY += GetPadRow(i)->HalfSizeY();
296   }  
297   
298   return halfSizeY;
299 }
300
301 //______________________________________________________________________________
302 AliMpVMotif*  AliMpVRowSegmentSpecial::FindMotif(const TVector2& position) const
303 {
304 /// Return the motif of this row; 
305
306   AliMpPadRow* padRow 
307     = FindPadRow(position.Y());
308   
309   if (!padRow) return 0;
310
311   AliMpVPadRowSegment* padRowSegment 
312     = padRow->FindPadRowSegment(position.X());
313     
314   if (!padRowSegment) return 0;
315
316   return padRowSegment->GetMotif();
317 }  
318
319 //______________________________________________________________________________
320 Int_t AliMpVRowSegmentSpecial::FindMotifPositionId(const TVector2& position) const
321 {
322 /// Return the motif position identified for the given
323 /// geometric position.
324
325   AliMpPadRow* padRow 
326     = FindPadRow(position.Y());
327   
328   if (!padRow) return 0;
329
330   AliMpVPadRowSegment* padRowSegment 
331     = padRow->FindPadRowSegment(position.X());
332     
333   if (!padRowSegment) return 0;
334
335   return padRowSegment->GetMotifPositionId();
336 }
337
338 //______________________________________________________________________________
339 Bool_t AliMpVRowSegmentSpecial::HasMotifPosition(Int_t motifPositionId) const
340 {
341 /// Return true if the motif specified with the given position identifier
342 /// is in this segment.
343
344   if (FindPadRowSegment(motifPositionId))
345     return true;
346   else  
347     return false;       
348 }
349
350 //______________________________________________________________________________
351 TVector2 AliMpVRowSegmentSpecial::MotifCenter(Int_t motifPositionId) const
352 {
353 /// Return the coordinates of the motif specified with
354 /// the given position identifier.
355
356   // Try to get the motif position from the motif map first
357   AliMpMotifPosition* motifPosition
358     = GetRow()->GetMotifMap()->FindMotifPosition(motifPositionId);
359   if (motifPosition) return motifPosition->Position();
360
361   // Use slow method otherwise
362   return MotifCenterSlow(motifPositionId);
363 }
364
365 //______________________________________________________________________________
366 TVector2 AliMpVRowSegmentSpecial::Dimensions() const
367 {
368 /// Return the halflengths in x, y of the row segment rectangular envelope.
369
370   Double_t x = 0.;                  
371   Double_t y = 0.;  
372   for (Int_t i=0; i<GetNofPadRows(); i++) {    
373     AliMpPadRow* padRow = GetPadRow(i); 
374     
375     // Add all pad rows y halfsizes   
376     y += padRow->HalfSizeY();
377
378     // Find the biggest pad rows x halfsize
379     Double_t xx 
380       = (padRow->GetPadRowSegment(0)->RightBorderX() -
381          padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX())/2.;
382     if (xx > x) x = xx;            
383   }                  
384     
385   return TVector2(x, y);   
386 }
387
388 //______________________________________________________________________________
389 AliMpRow*  AliMpVRowSegmentSpecial::GetRow() const
390 {
391 /// Return the row.which this row segment belongs to.
392
393   return fRow;
394 }  
395
396 //______________________________________________________________________________
397 Int_t  AliMpVRowSegmentSpecial::GetNofMotifs() const 
398
399 /// Return the number of different motifs present in this row segment.
400
401 #ifdef WITH_STL
402   return fMotifs.size();
403 #endif
404 #ifdef WITH_ROOT
405   return fMotifs.GetEntriesFast();
406 #endif
407 }  
408
409 //______________________________________________________________________________
410 AliMpVMotif* AliMpVRowSegmentSpecial::GetMotif(Int_t i) const  
411 {
412 /// Return the i-th motif present in this row segment.
413
414 #ifdef WITH_STL
415    return fMotifs[i]; 
416 #endif
417 #ifdef WITH_ROOT
418    return (AliMpVMotif*)fMotifs[i]; 
419 #endif
420 }
421
422 //______________________________________________________________________________
423 Int_t  AliMpVRowSegmentSpecial::GetMotifPositionId(Int_t i) const 
424
425 /// Return the i-th motif position Id present in this row segment.
426
427    return fMotifPositionIds[i]; 
428
429