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