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