]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpVSegmentation.cxx
Replacement of AliMpIntPair object with algoritmic
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpVSegmentation.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: AliMpVSegmentation.cxx,v 1.5 2006/05/24 13:58:29 ivana Exp $
18 // Category: basic
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpVSegmentation
22 // ------------------------
23 // The abstract base class for the segmentation.
24 // Provides methods related to pads:
25 // conversion between pad indices, pad location, pad position;
26 // finding pad neighbour.
27 //
28 // Included in AliRoot: 2003/05/02
29 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
30 //         Laurent Aphecetche, SUBATECH
31 //-----------------------------------------------------------------------------
32
33
34 #include "AliMpVSegmentation.h"
35 #include "AliMpArea.h"
36 #include "AliMpConstants.h"
37
38 #include "AliLog.h"
39
40 #include "TVector2.h"
41 #include "TObjArray.h"
42
43 /// \cond CLASSIMP
44 ClassImp(AliMpVSegmentation)
45 /// \endcond
46
47 //_____________________________________________________________________________
48 AliMpVSegmentation::AliMpVSegmentation() 
49   : TObject()
50 {
51 /// Default constructor
52 }
53
54 //_____________________________________________________________________________
55 AliMpVSegmentation::~AliMpVSegmentation() 
56 {
57 /// Destructor 
58 }
59
60 //_____________________________________________________________________________
61 Int_t 
62 AliMpVSegmentation::GetNeighbours(const AliMpPad& pad, 
63                                   TObjArray& neighbours,
64                                   Bool_t includeSelf,
65                                   Bool_t includeVoid) const
66 {
67   /// Returns the list of neighbours of pad
68   static TVector2* testPositions(0x0);
69   static const Int_t kNofTestPositions(11);
70   static const Double_t kEpsilon(AliMpConstants::LengthTolerance()*2.0);
71   static Int_t centerIndex(-1);
72   
73   // testPositions are the positions (L,T,R,B) relative to pad's center (O)
74   // were we'll try to get a neighbouring pad, by getting a little
75   // bit outside the pad itself.
76   // Note that it's not symmetric as we assume that pad density
77   // can always decrease when going from left to right (or from bottom to top)
78   //
79   // L--T--R
80   // |     |
81   // L     |
82   // |  O  R
83   // L     |
84   // |     |
85   // L-B-B-R
86   //
87   // The order in which we actually test the positions has some importance,
88   // i.e. when using this information to compute status map later on. Here's
89   // the sequence :
90   //
91   // 4-- 5-- 6
92   // |       |
93   // 3       |
94   // |   0   7
95   // 2       |
96   // |       |
97   // 1-10- 9-8
98   
99   neighbours.Delete();
100   neighbours.SetOwner(kTRUE);
101   
102   if (!pad.IsValid()) return 0;
103   
104   if (!testPositions)
105   {
106     testPositions = new TVector2[kNofTestPositions];
107     Int_t n(0); 
108     // starting center
109     centerIndex = 0;
110     testPositions[n++] = TVector2(0,0); // O (pad center)
111     // then left column (L), starting from bottom
112     testPositions[n++] = TVector2(-1,-1); // 1
113     testPositions[n++] = TVector2(-1,-1/3.0); // 2 
114     testPositions[n++] = TVector2(-1,1/3.0); // 3
115     testPositions[n++] = TVector2(-1,1); // 4
116     // top (T)
117     testPositions[n++] = TVector2(0,1); // 5
118     // right column (R), starting from top
119     testPositions[n++] = TVector2(1,1); // 6
120     testPositions[n++] = TVector2(1,0); // 7
121     testPositions[n++] = TVector2(1,-1); // 8
122     // bottom (B), starting from right
123     testPositions[n++] = TVector2(1/3.0,-1); // 9 
124     testPositions[n++] = TVector2(-1/3.0,-1); // 10
125     // pad center
126     if ( n != kNofTestPositions ) {
127       AliError("Test on number of test positions failed.");
128     }  
129   }
130   
131   Int_t n(0);
132   
133   AliMpPad previous(AliMpPad::Invalid());
134   
135   for ( Int_t i = 0; i < kNofTestPositions; ++i ) 
136   {
137     if ( i == centerIndex && !includeSelf )
138     {
139       if ( includeVoid ) 
140       {
141         previous = AliMpPad::Invalid();
142         neighbours.Add(new AliMpPad(previous));
143         ++n;
144       }
145       continue;
146     }
147     
148     TVector2 shift = testPositions[i];
149     TVector2 pos = pad.Position();
150     pos += TVector2((pad.Dimensions().X()+kEpsilon)*shift.X(),
151                     (pad.Dimensions().Y()+kEpsilon)*shift.Y());
152
153     
154     AliMpPad p = PadByPosition(pos,kFALSE);
155     
156     if ( !p.IsValid() && !includeVoid ) continue;
157     
158     if ( p != previous || !previous.IsValid() ) 
159     {
160       previous = p;
161       neighbours.Add(new AliMpPad(p));
162       ++n;
163     }
164   }
165   return n;
166 }
167
168 //
169 // public methods
170 //
171
172 //_____________________________________________________________________________
173 Bool_t 
174 AliMpVSegmentation::HasPadByIndices(Int_t ix, Int_t iy) const
175 {
176   /// Default implementation. Must be overwritten if can be made more
177   /// efficient in the child class
178   
179   return ( PadByIndices(ix, iy, kFALSE) != AliMpPad::Invalid() );
180 }
181
182 //_____________________________________________________________________________
183 Bool_t 
184 AliMpVSegmentation::HasPadByLocation(Int_t manuId, Int_t manuChannel) const
185 {
186   /// Default implementation. Must be overwritten if can be made more
187   /// efficient in the child class
188   
189   return (PadByLocation(manuId, manuChannel, kFALSE) != AliMpPad::Invalid());
190 }
191
192 //_____________________________________________________________________________
193 Bool_t 
194 AliMpVSegmentation::HasMotifPosition(Int_t manuId) const
195 {
196   /// Default implementation to know if we hold a given manu
197   return ( MotifPosition(manuId) != 0x0 );
198 }
199
200