1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpVSegmentation.cxx,v 1.5 2006/05/24 13:58:29 ivana Exp $
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.
28 // Included in AliRoot: 2003/05/02
29 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
30 // Laurent Aphecetche, SUBATECH
31 //-----------------------------------------------------------------------------
34 #include "AliMpVSegmentation.h"
35 #include "AliMpArea.h"
36 #include "AliMpConstants.h"
41 #include "TObjArray.h"
44 ClassImp(AliMpVSegmentation)
47 //_____________________________________________________________________________
48 AliMpVSegmentation::AliMpVSegmentation()
51 /// Default constructor
54 //_____________________________________________________________________________
55 AliMpVSegmentation::~AliMpVSegmentation()
60 //_____________________________________________________________________________
61 AliMpPadPair AliMpVSegmentation::FindPads(const TVector2& position1,
62 const TVector2& position2) const
64 /// Return a pair of pads with specified position.
65 /// If both pads are identical, the second pad in pair is set to invalid.
67 AliMpPad pad1 = PadByPosition(position1, false);
68 AliMpPad pad2 = PadByPosition(position2, false);
70 if (pad1 == pad2) pad2 = AliMpPad::Invalid();
72 return AliMpPadPair(pad1, pad2);
75 //_____________________________________________________________________________
77 AliMpVSegmentation::GetNeighbours(const AliMpPad& pad,
78 TObjArray& neighbours,
80 Bool_t includeVoid) const
82 /// Returns the list of neighbours of pad
83 static TVector2* testPositions(0x0);
84 static const Int_t kNofTestPositions(11);
85 static const Double_t kEpsilon(AliMpConstants::LengthTolerance()*2.0);
86 static Int_t centerIndex(-1);
88 // testPositions are the positions (L,T,R,B) relative to pad's center (O)
89 // were we'll try to get a neighbouring pad, by getting a little
90 // bit outside the pad itself.
91 // Note that it's not symmetric as we assume that pad density
92 // can always decrease when going from left to right (or from bottom to top)
102 // The order in which we actually test the positions has some importance,
103 // i.e. when using this information to compute status map later on. Here's
115 neighbours.SetOwner(kTRUE);
117 if (!pad.IsValid()) return 0;
121 testPositions = new TVector2[kNofTestPositions];
125 testPositions[n++] = TVector2(0,0); // O (pad center)
126 // then left column (L), starting from bottom
127 testPositions[n++] = TVector2(-1,-1); // 1
128 testPositions[n++] = TVector2(-1,-1/3.0); // 2
129 testPositions[n++] = TVector2(-1,1/3.0); // 3
130 testPositions[n++] = TVector2(-1,1); // 4
132 testPositions[n++] = TVector2(0,1); // 5
133 // right column (R), starting from top
134 testPositions[n++] = TVector2(1,1); // 6
135 testPositions[n++] = TVector2(1,0); // 7
136 testPositions[n++] = TVector2(1,-1); // 8
137 // bottom (B), starting from right
138 testPositions[n++] = TVector2(1/3.0,-1); // 9
139 testPositions[n++] = TVector2(-1/3.0,-1); // 10
141 if ( n != kNofTestPositions ) {
142 AliError("Test on number of test positions failed.");
148 AliMpPad previous(AliMpPad::Invalid());
150 for ( Int_t i = 0; i < kNofTestPositions; ++i )
152 if ( i == centerIndex && !includeSelf )
156 previous = AliMpPad::Invalid();
157 neighbours.Add(new AliMpPad(previous));
163 TVector2 shift = testPositions[i];
164 TVector2 pos = pad.Position();
165 pos += TVector2((pad.Dimensions().X()+kEpsilon)*shift.X(),
166 (pad.Dimensions().Y()+kEpsilon)*shift.Y());
169 AliMpPad p = PadByPosition(pos,kFALSE);
171 if ( !p.IsValid() && !includeVoid ) continue;
173 if ( p != previous || !previous.IsValid() )
176 neighbours.Add(new AliMpPad(p));
187 //_____________________________________________________________________________
188 AliMpPadPair AliMpVSegmentation::PadsUp(const AliMpPad& pad) const
190 /// Return a pair of pads neighbouring up to the specified pad.
191 /// If there is only one neighbouring pad,
192 /// the second pad in pair is invalid.
195 = pad.Position()+ TVector2((-1.)*AliMpConstants::LengthStep(),
196 pad.Dimensions().Y()+ AliMpConstants::LengthStep());
198 = pad.Position()+ TVector2(AliMpConstants::LengthStep(),
199 pad.Dimensions().Y()+ AliMpConstants::LengthStep());
201 return FindPads(position1, position2);
204 //_____________________________________________________________________________
205 AliMpPadPair AliMpVSegmentation::PadsDown(const AliMpPad& pad) const
207 /// Return a pair of pads neighbouring down to the specified pad.
208 /// If there is only one neighbouring pad,
209 /// the second pad in pair is invalid.
212 = pad.Position()- TVector2(AliMpConstants::LengthStep(),
213 pad.Dimensions().Y()+ AliMpConstants::LengthStep());
216 = pad.Position()- TVector2((-1.)*AliMpConstants::LengthStep(),
217 pad.Dimensions().Y()+ AliMpConstants::LengthStep());
219 return FindPads(position1, position2);
222 //_____________________________________________________________________________
223 AliMpPadPair AliMpVSegmentation::PadsLeft(const AliMpPad& pad) const
225 /// Return a pair of pads neighbouring left to the specified pad.
226 /// If there is only one neighbouring pad,
227 /// the second in pair is invalid.
230 = pad.Position() - TVector2(pad.Dimensions().X() + AliMpConstants::LengthStep(),
231 AliMpConstants::LengthStep());
233 = pad.Position() - TVector2(pad.Dimensions().X() + AliMpConstants::LengthStep(),
234 (-1.)*AliMpConstants::LengthStep());
236 return FindPads(position1, position2);
239 //_____________________________________________________________________________
240 AliMpPadPair AliMpVSegmentation::PadsRight(const AliMpPad& pad) const
242 /// Return a pair of pads neighbouring right to the specified pad.
243 /// If there is only one neighbouring pad,
244 /// the second in pair is invalid.
247 = pad.Position() + TVector2(pad.Dimensions().X() + AliMpConstants::LengthStep(),
248 (-1.)*AliMpConstants::LengthStep());
250 = pad.Position() + TVector2(pad.Dimensions().X() + AliMpConstants::LengthStep(),
251 AliMpConstants::LengthStep());
253 return FindPads(position1, position2);
256 //_____________________________________________________________________________
258 AliMpVSegmentation::HasPadByIndices(const AliMpIntPair& indices) const
260 /// Default implementation. Must be overwritten if can be made more
261 /// efficient in the child class
263 return (PadByIndices(indices,kFALSE) != AliMpPad::Invalid());
266 //_____________________________________________________________________________
268 AliMpVSegmentation::HasPadByLocation(const AliMpIntPair& location) const
270 /// Default implementation. Must be overwritten if can be made more
271 /// efficient in the child class
273 return (PadByLocation(location,kFALSE) != AliMpPad::Invalid());
276 //_____________________________________________________________________________
278 AliMpVSegmentation::HasMotifPosition(Int_t manuId) const
280 /// Default implementation to know if we hold a given manu
281 return ( MotifPosition(manuId) != 0x0 );