]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpVSegmentation.cxx
- Adding *.C *.txt *.sh to FILE_PATTERNS
[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 // Class AliMpVSegmentation
21 // ------------------------
22 // The abstract base class for the segmentation.
23 // Provides methods related to pads:
24 // conversion between pad indices, pad location, pad position;
25 // finding pad neighbour.
26 //
27 // Included in AliRoot: 2003/05/02
28 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
29 //         Laurent Aphecetche, SUBATECH
30
31 #include "AliMpVSegmentation.h"
32 #include "AliMpArea.h"
33 #include "AliMpConstants.h"
34
35 #include "AliLog.h"
36
37 #include "TVector2.h"
38 #include "TObjArray.h"
39
40 /// \cond CLASSIMP
41 ClassImp(AliMpVSegmentation)
42 /// \endcond
43
44 //_____________________________________________________________________________
45 AliMpVSegmentation::AliMpVSegmentation() 
46   : TObject()
47 {
48 /// Default constructor
49 }
50
51 //_____________________________________________________________________________
52 AliMpVSegmentation::~AliMpVSegmentation() 
53 {
54 /// Destructor 
55 }
56
57 //_____________________________________________________________________________
58 AliMpPadPair AliMpVSegmentation::FindPads(const TVector2& position1, 
59                                           const TVector2& position2) const
60 {
61 /// Return a pair of pads with specified position.
62 /// If both pads are identical, the second pad in pair is set to invalid.
63
64   AliMpPad pad1 = PadByPosition(position1, false);
65   AliMpPad pad2 = PadByPosition(position2, false);
66                                      
67   if (pad1 == pad2) pad2 = AliMpPad::Invalid();                              
68
69   return AliMpPadPair(pad1, pad2);
70 }  
71
72 //_____________________________________________________________________________
73 Int_t 
74 AliMpVSegmentation::GetNeighbours(const AliMpPad& pad, 
75                                   TObjArray& neighbours,
76                                   Bool_t includeSelf,
77                                   Bool_t includeVoid) const
78 {
79   /// Returns the list of neighbours of pad
80   static TVector2* testPositions(0x0);
81   static const Int_t kNofTestPositions(11);
82   static const Double_t kEpsilon(AliMpConstants::LengthTolerance()*2.0);
83   static Int_t centerIndex(-1);
84   
85   // testPositions are the positions (L,T,R,B) relative to pad's center (O)
86   // were we'll try to get a neighbouring pad, by getting a little
87   // bit outside the pad itself.
88   // Note that it's not symmetric as we assume that pad density
89   // can always decrease when going from left to right (or from bottom to top)
90   //
91   // L--T--R
92   // |     |
93   // L     |
94   // |  O  R
95   // L     |
96   // |     |
97   // L-B-B-R
98   //
99   // The order in which we actually test the positions has some importance,
100   // i.e. when using this information to compute status map later on. Here's
101   // the sequence :
102   //
103   // 4-- 5-- 6
104   // |       |
105   // 3       |
106   // |   0   7
107   // 2       |
108   // |       |
109   // 1-10- 9-8
110   
111   neighbours.Delete();
112   neighbours.SetOwner(kTRUE);
113   
114   if (!pad.IsValid()) return 0;
115   
116   if (!testPositions)
117   {
118     testPositions = new TVector2[kNofTestPositions];
119     Int_t n(0); 
120     // starting center
121     centerIndex = 0;
122     testPositions[n++] = TVector2(0,0); // O (pad center)
123     // then left column (L), starting from bottom
124     testPositions[n++] = TVector2(-1,-1); // 1
125     testPositions[n++] = TVector2(-1,-1/3.0); // 2 
126     testPositions[n++] = TVector2(-1,1/3.0); // 3
127     testPositions[n++] = TVector2(-1,1); // 4
128     // top (T)
129     testPositions[n++] = TVector2(0,1); // 5
130     // right column (R), starting from top
131     testPositions[n++] = TVector2(1,1); // 6
132     testPositions[n++] = TVector2(1,0); // 7
133     testPositions[n++] = TVector2(1,-1); // 8
134     // bottom (B), starting from right
135     testPositions[n++] = TVector2(1/3.0,-1); // 9 
136     testPositions[n++] = TVector2(-1/3.0,-1); // 10
137     // pad center
138     if ( n != kNofTestPositions ) {
139       AliError("Test on number of test positions failed.");
140     }  
141   }
142   
143   Int_t n(0);
144   
145   AliMpPad previous(AliMpPad::Invalid());
146   
147   for ( Int_t i = 0; i < kNofTestPositions; ++i ) 
148   {
149     if ( i == centerIndex && !includeSelf )
150     {
151       if ( includeVoid ) 
152       {
153         previous = AliMpPad::Invalid();
154         neighbours.Add(new AliMpPad(previous));
155         ++n;
156       }
157       continue;
158     }
159     
160     TVector2 shift = testPositions[i];
161     TVector2 pos = pad.Position();
162     pos += TVector2((pad.Dimensions().X()+kEpsilon)*shift.X(),
163                     (pad.Dimensions().Y()+kEpsilon)*shift.Y());
164
165     
166     AliMpPad p = PadByPosition(pos,kFALSE);
167     
168     if ( !p.IsValid() && !includeVoid ) continue;
169     
170     if ( p != previous || !previous.IsValid() ) 
171     {
172       previous = p;
173       neighbours.Add(new AliMpPad(p));
174       ++n;
175     }
176   }
177   return n;
178 }
179
180 //
181 // public methods
182 //
183
184 //_____________________________________________________________________________
185 AliMpPadPair AliMpVSegmentation::PadsUp(const AliMpPad& pad) const
186 {
187 /// Return a pair of pads neighbouring up to the specified pad.
188 /// If there is only one neighbouring pad,
189 /// the second pad in pair is invalid.
190
191   TVector2 position1 
192     = pad.Position()+ TVector2((-1.)*AliMpConstants::LengthStep(), 
193                                pad.Dimensions().Y()+ AliMpConstants::LengthStep());
194   TVector2 position2 
195     = pad.Position()+ TVector2(AliMpConstants::LengthStep(), 
196                                pad.Dimensions().Y()+ AliMpConstants::LengthStep());
197                                
198   return FindPads(position1, position2);
199 }
200
201 //_____________________________________________________________________________
202 AliMpPadPair AliMpVSegmentation::PadsDown(const AliMpPad& pad) const
203 {
204 /// Return a pair of pads neighbouring down to the specified pad.
205 /// If there is only one neighbouring pad,
206 /// the second pad in pair is invalid.
207
208   TVector2 position1 
209     = pad.Position()- TVector2(AliMpConstants::LengthStep(), 
210                                pad.Dimensions().Y()+ AliMpConstants::LengthStep());
211
212   TVector2 position2
213     = pad.Position()- TVector2((-1.)*AliMpConstants::LengthStep(), 
214                                pad.Dimensions().Y()+ AliMpConstants::LengthStep());
215                                      
216   return FindPads(position1, position2);
217 }
218
219 //_____________________________________________________________________________
220 AliMpPadPair AliMpVSegmentation::PadsLeft(const AliMpPad& pad) const
221 {
222 /// Return a pair of pads neighbouring left to the specified pad.
223 /// If there is only one neighbouring pad,
224 /// the second in pair is invalid.
225
226   TVector2 position1 
227     = pad.Position() - TVector2(pad.Dimensions().X() + AliMpConstants::LengthStep(),
228                                 AliMpConstants::LengthStep()); 
229   TVector2 position2
230     = pad.Position() - TVector2(pad.Dimensions().X() + AliMpConstants::LengthStep(),
231                                 (-1.)*AliMpConstants::LengthStep()); 
232
233   return FindPads(position1, position2);
234 }
235
236 //_____________________________________________________________________________
237 AliMpPadPair AliMpVSegmentation::PadsRight(const AliMpPad& pad) const
238 {
239 /// Return a pair of pads neighbouring right to the specified pad.
240 /// If there is only one neighbouring pad,
241 /// the second in pair is invalid.
242
243   TVector2 position1 
244     = pad.Position() + TVector2(pad.Dimensions().X() + AliMpConstants::LengthStep(),
245                                 (-1.)*AliMpConstants::LengthStep()); 
246   TVector2 position2
247     = pad.Position() + TVector2(pad.Dimensions().X() + AliMpConstants::LengthStep(),
248                                 AliMpConstants::LengthStep()); 
249                                      
250   return FindPads(position1, position2);
251 }
252