Commenting out the infamous speed eater = StdoutToAliDebug until a better solution...
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpVSegmentation.cxx
CommitLineData
dee1d5f1 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
5f91c9e8 16// $Id$
13985652 17// $MpId: AliMpVSegmentation.cxx,v 1.5 2006/05/24 13:58:29 ivana Exp $
5f91c9e8 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//
dbe945cc 27// Included in AliRoot: 2003/05/02
5f91c9e8 28// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
c49cb542 29// Laurent Aphecetche, SUBATECH
5f91c9e8 30
31#include "AliMpVSegmentation.h"
c49cb542 32#include "AliMpArea.h"
5f91c9e8 33#include "AliMpConstants.h"
34
c49cb542 35#include "AliLog.h"
36
37#include "TVector2.h"
38#include "TObjArray.h"
39
13985652 40/// \cond CLASSIMP
5f91c9e8 41ClassImp(AliMpVSegmentation)
13985652 42/// \endcond
5f91c9e8 43
44//_____________________________________________________________________________
45AliMpVSegmentation::AliMpVSegmentation()
46 : TObject()
47{
dee1d5f1 48/// Default constructor
5f91c9e8 49}
50
51//_____________________________________________________________________________
dee1d5f1 52AliMpVSegmentation::~AliMpVSegmentation()
53{
54/// Destructor
5f91c9e8 55}
56
c49cb542 57//_____________________________________________________________________________
5f91c9e8 58AliMpPadPair AliMpVSegmentation::FindPads(const TVector2& position1,
59 const TVector2& position2) const
60{
dee1d5f1 61/// Return a pair of pads with specified position.
62/// If both pads are identical, the second pad in pair is set to invalid.
5f91c9e8 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
c49cb542 72//_____________________________________________________________________________
73Int_t
74AliMpVSegmentation::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
c6da08f6 89 // can always decrease when going from left to right (or from bottom to top)
c49cb542 90 //
c6da08f6 91 // L--T--R
c49cb542 92 // | |
93 // L |
94 // | O R
95 // L |
96 // | |
c6da08f6 97 // L-B-B-R
c49cb542 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 //
c6da08f6 103 // 4-- 5-- 6
104 // | |
105 // 3 |
106 // | 0 7
107 // 2 |
108 // | |
109 // 1-10- 9-8
c49cb542 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
c6da08f6 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
c49cb542 130 // right column (R), starting from top
c6da08f6 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
c49cb542 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
5f91c9e8 180//
181// public methods
182//
183
184//_____________________________________________________________________________
185AliMpPadPair AliMpVSegmentation::PadsUp(const AliMpPad& pad) const
186{
dee1d5f1 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.
5f91c9e8 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//_____________________________________________________________________________
202AliMpPadPair AliMpVSegmentation::PadsDown(const AliMpPad& pad) const
203{
dee1d5f1 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.
5f91c9e8 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//_____________________________________________________________________________
220AliMpPadPair AliMpVSegmentation::PadsLeft(const AliMpPad& pad) const
221{
dee1d5f1 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.
5f91c9e8 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//_____________________________________________________________________________
237AliMpPadPair AliMpVSegmentation::PadsRight(const AliMpPad& pad) const
238{
dee1d5f1 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.
5f91c9e8 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