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