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 // 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.
27 // Included in AliRoot: 2003/05/02
28 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
29 // Laurent Aphecetche, SUBATECH
31 #include "AliMpVSegmentation.h"
32 #include "AliMpArea.h"
33 #include "AliMpConstants.h"
38 #include "TObjArray.h"
41 ClassImp(AliMpVSegmentation)
44 //_____________________________________________________________________________
45 AliMpVSegmentation::AliMpVSegmentation()
48 /// Default constructor
51 //_____________________________________________________________________________
52 AliMpVSegmentation::~AliMpVSegmentation()
57 //_____________________________________________________________________________
58 AliMpPadPair AliMpVSegmentation::FindPads(const TVector2& position1,
59 const TVector2& position2) const
61 /// Return a pair of pads with specified position.
62 /// If both pads are identical, the second pad in pair is set to invalid.
64 AliMpPad pad1 = PadByPosition(position1, false);
65 AliMpPad pad2 = PadByPosition(position2, false);
67 if (pad1 == pad2) pad2 = AliMpPad::Invalid();
69 return AliMpPadPair(pad1, pad2);
72 //_____________________________________________________________________________
74 AliMpVSegmentation::GetNeighbours(const AliMpPad& pad,
75 TObjArray& neighbours,
77 Bool_t includeVoid) const
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);
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)
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
112 neighbours.SetOwner(kTRUE);
114 if (!pad.IsValid()) return 0;
118 testPositions = new TVector2[kNofTestPositions];
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
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
138 if ( n != kNofTestPositions ) {
139 AliError("Test on number of test positions failed.");
145 AliMpPad previous(AliMpPad::Invalid());
147 for ( Int_t i = 0; i < kNofTestPositions; ++i )
149 if ( i == centerIndex && !includeSelf )
153 previous = AliMpPad::Invalid();
154 neighbours.Add(new AliMpPad(previous));
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());
166 AliMpPad p = PadByPosition(pos,kFALSE);
168 if ( !p.IsValid() && !includeVoid ) continue;
170 if ( p != previous || !previous.IsValid() )
173 neighbours.Add(new AliMpPad(p));
184 //_____________________________________________________________________________
185 AliMpPadPair AliMpVSegmentation::PadsUp(const AliMpPad& pad) const
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.
192 = pad.Position()+ TVector2((-1.)*AliMpConstants::LengthStep(),
193 pad.Dimensions().Y()+ AliMpConstants::LengthStep());
195 = pad.Position()+ TVector2(AliMpConstants::LengthStep(),
196 pad.Dimensions().Y()+ AliMpConstants::LengthStep());
198 return FindPads(position1, position2);
201 //_____________________________________________________________________________
202 AliMpPadPair AliMpVSegmentation::PadsDown(const AliMpPad& pad) const
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.
209 = pad.Position()- TVector2(AliMpConstants::LengthStep(),
210 pad.Dimensions().Y()+ AliMpConstants::LengthStep());
213 = pad.Position()- TVector2((-1.)*AliMpConstants::LengthStep(),
214 pad.Dimensions().Y()+ AliMpConstants::LengthStep());
216 return FindPads(position1, position2);
219 //_____________________________________________________________________________
220 AliMpPadPair AliMpVSegmentation::PadsLeft(const AliMpPad& pad) const
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.
227 = pad.Position() - TVector2(pad.Dimensions().X() + AliMpConstants::LengthStep(),
228 AliMpConstants::LengthStep());
230 = pad.Position() - TVector2(pad.Dimensions().X() + AliMpConstants::LengthStep(),
231 (-1.)*AliMpConstants::LengthStep());
233 return FindPads(position1, position2);
236 //_____________________________________________________________________________
237 AliMpPadPair AliMpVSegmentation::PadsRight(const AliMpPad& pad) const
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.
244 = pad.Position() + TVector2(pad.Dimensions().X() + AliMpConstants::LengthStep(),
245 (-1.)*AliMpConstants::LengthStep());
247 = pad.Position() + TVector2(pad.Dimensions().X() + AliMpConstants::LengthStep(),
248 AliMpConstants::LengthStep());
250 return FindPads(position1, position2);