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