]>
Commit | Line | Data |
---|---|---|
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: AliMpRowSegment.cxx,v 1.10 2006/05/24 13:58:46 ivana Exp $ |
5f91c9e8 | 18 | // Category: sector |
3d1463c8 | 19 | |
20 | //----------------------------------------------------------------------------- | |
5f91c9e8 | 21 | // Class AliMpRowSegment |
22 | // --------------------- | |
23 | // Class describing a row segment composed of the | |
24 | // the identic motifs. | |
dbe945cc | 25 | // Included in AliRoot: 2003/05/02 |
5f91c9e8 | 26 | // Authors: David Guez, Ivana Hrivnacova; IPN Orsay |
3d1463c8 | 27 | //----------------------------------------------------------------------------- |
5f91c9e8 | 28 | |
5f91c9e8 | 29 | #include "AliMpRowSegment.h" |
30 | #include "AliMpRow.h" | |
31 | #include "AliMpVMotif.h" | |
32 | #include "AliMpMotifType.h" | |
33 | #include "AliMpMotifTypePadIterator.h" | |
34 | #include "AliMpMotifMap.h" | |
35 | #include "AliMpMotifPosition.h" | |
580c28fd | 36 | #include "AliMpConstants.h" |
168e9c4d | 37 | #include "AliMpEncodePair.h" |
5f91c9e8 | 38 | |
97186a3f | 39 | #include "AliLog.h" |
40 | ||
2c605e66 | 41 | #include <TMath.h> |
42 | #include <Riostream.h> | |
43 | ||
b80faac0 | 44 | using std::endl; |
13985652 | 45 | /// \cond CLASSIMP |
5f91c9e8 | 46 | ClassImp(AliMpRowSegment) |
13985652 | 47 | /// \endcond |
5f91c9e8 | 48 | |
49 | //_____________________________________________________________________________ | |
50 | AliMpRowSegment::AliMpRowSegment(AliMpRow* row, AliMpVMotif* motif, | |
168e9c4d | 51 | Int_t padOffsetX, Int_t padOffsetY, |
5f91c9e8 | 52 | Int_t nofMotifs, |
53 | Int_t motifPositionId, Int_t motifPositionDId) | |
54 | : AliMpVRowSegment(), | |
55 | fNofMotifs(nofMotifs), | |
168e9c4d | 56 | fLPadOffset(AliMp::Pair(padOffsetX,padOffsetY)), |
6e97fbb8 | 57 | fOffsetX(0.), |
58 | fOffsetY(0.), | |
5f91c9e8 | 59 | fRow(row), |
60 | fMotif(motif), | |
61 | fMotifPositionId(motifPositionId), | |
62 | fMotifPositionDId(motifPositionDId) | |
63 | { | |
dee1d5f1 | 64 | /// Standard constructor |
65 | ||
5f91c9e8 | 66 | // Keep pad offset in the low indices limits |
168e9c4d | 67 | SetLowIndicesLimit(fLPadOffset); |
5f91c9e8 | 68 | } |
69 | ||
70 | //_____________________________________________________________________________ | |
71 | AliMpRowSegment::AliMpRowSegment() | |
72 | : AliMpVRowSegment(), | |
73 | fNofMotifs(0), | |
168e9c4d | 74 | fLPadOffset(0), |
6e97fbb8 | 75 | fOffsetX(0.), |
76 | fOffsetY(0.), | |
5f91c9e8 | 77 | fRow(0), |
78 | fMotif(0), | |
79 | fMotifPositionId(0), | |
80 | fMotifPositionDId(0) | |
81 | { | |
dee1d5f1 | 82 | /// Default constructor |
5f91c9e8 | 83 | } |
84 | ||
85 | //_____________________________________________________________________________ | |
dee1d5f1 | 86 | AliMpRowSegment::~AliMpRowSegment() |
87 | { | |
88 | /// Destructor | |
5f91c9e8 | 89 | } |
90 | ||
79f44b3b | 91 | // |
5f91c9e8 | 92 | // private methods |
93 | // | |
94 | ||
95 | //_____________________________________________________________________________ | |
96 | Double_t AliMpRowSegment::FirstMotifCenterX() const | |
97 | { | |
dee1d5f1 | 98 | /// Return the x coordinate of the first motif center |
99 | /// in the global coordinate system. | |
5f91c9e8 | 100 | |
6e97fbb8 | 101 | return fOffsetX; |
5f91c9e8 | 102 | } |
103 | ||
104 | //_____________________________________________________________________________ | |
105 | Double_t AliMpRowSegment::LastMotifCenterX() const | |
106 | { | |
dee1d5f1 | 107 | /// Return the x coordinate of the last motif center |
108 | /// in the global coordinate system. | |
5f91c9e8 | 109 | |
6e97fbb8 | 110 | return fOffsetX + 2.*(fNofMotifs-1)*fMotif->DimensionX(); |
5f91c9e8 | 111 | } |
112 | ||
113 | //_____________________________________________________________________________ | |
114 | Double_t AliMpRowSegment::MotifCenterX(Int_t motifPositionId) const | |
115 | { | |
dee1d5f1 | 116 | /// Return the x coordinate of the motif specified with |
117 | /// the given position identifier. | |
5f91c9e8 | 118 | |
119 | // Check if x is in the row segment range | |
120 | if (! HasMotifPosition(motifPositionId)) { | |
2c605e66 | 121 | AliErrorStream() << "Outside row segment region" << endl; |
5f91c9e8 | 122 | return 0; |
123 | } | |
124 | ||
125 | // Find the position number in the segment | |
126 | Int_t num = (motifPositionId - fMotifPositionId) * fMotifPositionDId; | |
127 | ||
6e97fbb8 | 128 | return fOffsetX + num*(fMotif->DimensionX() * 2.0); |
5f91c9e8 | 129 | } |
130 | ||
131 | //_____________________________________________________________________________ | |
132 | Double_t AliMpRowSegment::MotifCenterY(Int_t motifPositionId) const | |
133 | { | |
dee1d5f1 | 134 | /// Return the y coordinate of the motif specified with |
135 | /// the given position identifier. | |
5f91c9e8 | 136 | |
137 | // Check if x is in the row segment range | |
138 | if (! HasMotifPosition(motifPositionId)) { | |
2c605e66 | 139 | AliErrorStream() << "Outside row segment region" << endl; |
5f91c9e8 | 140 | return 0; |
141 | } | |
142 | ||
6e97fbb8 | 143 | return GetRow()->GetPositionY() + fOffsetY; |
5f91c9e8 | 144 | } |
145 | ||
146 | //_____________________________________________________________________________ | |
6e97fbb8 | 147 | Bool_t AliMpRowSegment::IsInside(Double_t x, Double_t y, Bool_t warn) const |
5f91c9e8 | 148 | { |
dee1d5f1 | 149 | /// Check if the position is inside some motif of this row segment. |
5f91c9e8 | 150 | |
6e97fbb8 | 151 | Double_t minY = GetRow()->GetPositionY() + fOffsetY - fMotif->DimensionY(); |
152 | Double_t maxY = GetRow()->GetPositionY() + fOffsetY + fMotif->DimensionY(); | |
5f91c9e8 | 153 | |
6e97fbb8 | 154 | if ( x < LeftBorderX() || x > RightBorderX() || |
155 | y < minY || y > maxY ) { | |
5f91c9e8 | 156 | |
2c605e66 | 157 | if (warn) |
158 | AliWarningStream() << "Outside row segment region" << endl; | |
5f91c9e8 | 159 | return false; |
160 | } | |
161 | else | |
162 | return true; | |
163 | } | |
164 | ||
165 | // | |
166 | // public methods | |
167 | // | |
168 | ||
169 | //_____________________________________________________________________________ | |
170 | Double_t AliMpRowSegment::LeftBorderX() const | |
171 | { | |
dee1d5f1 | 172 | /// Return the x coordinate of the left row segment border |
173 | /// in the global coordinate system. | |
5f91c9e8 | 174 | |
6e97fbb8 | 175 | return FirstMotifCenterX() - fMotif->DimensionX(); |
5f91c9e8 | 176 | } |
177 | ||
178 | //_____________________________________________________________________________ | |
179 | Double_t AliMpRowSegment::RightBorderX() const | |
180 | { | |
dee1d5f1 | 181 | /// Return the x coordinate of the right row segment border |
182 | /// in the global coordinate system. | |
5f91c9e8 | 183 | |
6e97fbb8 | 184 | return LastMotifCenterX() + fMotif->DimensionX(); |
5f91c9e8 | 185 | } |
186 | ||
187 | //_____________________________________________________________________________ | |
188 | Double_t AliMpRowSegment::HalfSizeY() const | |
189 | { | |
dee1d5f1 | 190 | /// Return the size in y of this row segment. |
5f91c9e8 | 191 | |
6e97fbb8 | 192 | return fMotif->DimensionY() + fOffsetY; |
5f91c9e8 | 193 | } |
194 | ||
195 | //_____________________________________________________________________________ | |
6e97fbb8 | 196 | AliMpVMotif* AliMpRowSegment::FindMotif(Double_t x, Double_t y) const |
5f91c9e8 | 197 | { |
dee1d5f1 | 198 | /// Return the motif of this row; |
5f91c9e8 | 199 | |
6e97fbb8 | 200 | if ( IsInside(x, y, false) ) |
5f91c9e8 | 201 | return fMotif; |
202 | else | |
203 | return 0; | |
204 | } | |
205 | ||
206 | //_____________________________________________________________________________ | |
6e97fbb8 | 207 | Int_t AliMpRowSegment::FindMotifPositionId(Double_t x, Double_t y) const |
5f91c9e8 | 208 | { |
dee1d5f1 | 209 | /// Return the motif position identified for the given |
210 | /// geometric position. | |
5f91c9e8 | 211 | |
6e97fbb8 | 212 | if ( ! IsInside(x, y, false) ) return 0; |
5f91c9e8 | 213 | |
214 | // Find the position number in the segment | |
215 | Int_t num | |
6e97fbb8 | 216 | = Int_t((x - LeftBorderX()) / (fMotif->DimensionX() * 2.0)); |
5f91c9e8 | 217 | |
218 | // Calculate the position Id | |
219 | return fMotifPositionId + num*fMotifPositionDId; | |
220 | } | |
221 | ||
222 | //_____________________________________________________________________________ | |
223 | Bool_t AliMpRowSegment::HasMotifPosition(Int_t motifPositionId) const | |
224 | { | |
dee1d5f1 | 225 | /// Return true if the motif specified with the given position identifier |
226 | /// is in this segment. | |
5f91c9e8 | 227 | |
228 | Int_t minId = TMath::Min(fMotifPositionId, | |
229 | fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId); | |
230 | Int_t maxId = TMath::Max(fMotifPositionId, | |
231 | fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId); | |
232 | ||
233 | if (motifPositionId >= minId && motifPositionId <= maxId) { | |
234 | return true; | |
235 | } | |
236 | else | |
237 | return false; | |
238 | } | |
239 | ||
240 | //_____________________________________________________________________________ | |
6e97fbb8 | 241 | void AliMpRowSegment::MotifCenter(Int_t motifPositionId, |
242 | Double_t& x, Double_t& y) const | |
5f91c9e8 | 243 | { |
dee1d5f1 | 244 | /// Return the coordinates of the motif specified with |
245 | /// the given position identifier. | |
5f91c9e8 | 246 | |
6e97fbb8 | 247 | x = MotifCenterX(motifPositionId); |
248 | y = MotifCenterY(motifPositionId); | |
5f91c9e8 | 249 | } |
250 | ||
251 | //_____________________________________________________________________________ | |
6e97fbb8 | 252 | Double_t AliMpRowSegment::GetPositionX() const |
5f91c9e8 | 253 | { |
6e97fbb8 | 254 | /// Return the x position of the row segment centre. |
5f91c9e8 | 255 | |
6e97fbb8 | 256 | return (LeftBorderX() + RightBorderX())/2.; |
5f91c9e8 | 257 | } |
258 | ||
6e97fbb8 | 259 | //_____________________________________________________________________________ |
260 | Double_t AliMpRowSegment::GetPositionY() const | |
261 | { | |
262 | /// Return the y position of the row segment centre. | |
263 | ||
264 | return GetRow()->GetPositionY(); | |
265 | } | |
5f91c9e8 | 266 | |
267 | //_____________________________________________________________________________ | |
6e97fbb8 | 268 | Double_t AliMpRowSegment::GetDimensionX() const |
5f91c9e8 | 269 | { |
dee1d5f1 | 270 | /// Return the halflengths of the row segment in x, y. |
5f91c9e8 | 271 | // --- |
272 | ||
6e97fbb8 | 273 | return (RightBorderX() - LeftBorderX())/2.; |
5f91c9e8 | 274 | } |
275 | ||
276 | //_____________________________________________________________________________ | |
6e97fbb8 | 277 | Double_t AliMpRowSegment::GetDimensionY() const |
278 | { | |
279 | /// Return the halflengths of the row segment in x, y. | |
280 | // --- | |
281 | ||
282 | return GetRow()->GetDimensionY(); | |
283 | } | |
284 | ||
285 | //_____________________________________________________________________________ | |
286 | void AliMpRowSegment::SetOffset(Double_t x, Double_t y) | |
5f91c9e8 | 287 | { |
dee1d5f1 | 288 | /// Calculate offset from given offset and |
289 | /// stored offset in pads. | |
5f91c9e8 | 290 | |
291 | AliMpMotifTypePadIterator iter(fMotif->GetMotifType()); | |
292 | iter.First(); | |
168e9c4d | 293 | |
294 | Int_t ix = iter.CurrentItem().GetIx(); | |
295 | Int_t iy = iter.CurrentItem().GetIy(); | |
6e97fbb8 | 296 | |
297 | Double_t dx, dy; | |
298 | fMotif->GetPadDimensionsByIndices(ix, iy, dx, dy); | |
5f91c9e8 | 299 | |
6e97fbb8 | 300 | fOffsetX |
301 | = x + 2.*AliMp::PairFirst(fLPadOffset) * dx + fMotif->DimensionX(); | |
5f91c9e8 | 302 | |
6e97fbb8 | 303 | fOffsetY |
304 | = y + AliMp::PairSecond(fLPadOffset) * dy; | |
5f91c9e8 | 305 | } |
306 | ||
307 | //_____________________________________________________________________________ | |
580c28fd | 308 | void AliMpRowSegment::SetGlobalIndices(AliMpRow* /*rowBefore*/) |
5f91c9e8 | 309 | { |
dee1d5f1 | 310 | /// Set global indices limits. |
5f91c9e8 | 311 | |
580c28fd | 312 | // The low/high indices limits has to be taken as the highest/lowest from all |
313 | // motif positions | |
314 | Int_t ixl = 9999; | |
315 | Int_t iyl = 9999; | |
316 | Int_t ixh = AliMpConstants::StartPadIndex(); | |
317 | Int_t iyh = AliMpConstants::StartPadIndex(); | |
318 | ||
319 | for (Int_t i=0; i<GetNofMotifs(); i++) { | |
320 | ||
321 | AliMpMotifPosition* mPos | |
322 | = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i)); | |
323 | ||
324 | // Check if the motif positions has the limits set | |
325 | if ( !mPos->HasValidIndices() ) | |
326 | Fatal("SetGlobalIndices", | |
327 | "Indices of motif positions have to be set first."); | |
5f91c9e8 | 328 | |
168e9c4d | 329 | if ( mPos->GetLowLimitIx() < ixl ) |
330 | ixl = mPos->GetLowLimitIx(); | |
580c28fd | 331 | |
168e9c4d | 332 | if ( mPos->GetLowLimitIy() < iyl ) |
333 | iyl = mPos->GetLowLimitIy(); | |
580c28fd | 334 | |
168e9c4d | 335 | if ( mPos->GetHighLimitIx() > ixh ) |
336 | ixh = mPos->GetHighLimitIx(); | |
580c28fd | 337 | |
168e9c4d | 338 | if ( mPos->GetHighLimitIy() > iyh ) |
339 | iyh = mPos->GetHighLimitIy(); | |
580c28fd | 340 | } |
341 | ||
168e9c4d | 342 | SetLowIndicesLimit(ixl, iyl); |
343 | SetHighIndicesLimit(ixh, iyh); | |
5f91c9e8 | 344 | } |
345 | ||
346 | //_____________________________________________________________________________ | |
168e9c4d | 347 | Int_t AliMpRowSegment::SetIndicesToMotifPosition(Int_t i, MpPair_t indices) |
5f91c9e8 | 348 | { |
dee1d5f1 | 349 | /// Set global indices to i-th motif position and returns next index |
350 | /// in x. | |
5f91c9e8 | 351 | |
352 | // Get motif position | |
353 | AliMpMotifPosition* motifPosition | |
354 | = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i)); | |
355 | ||
356 | // Low limit | |
168e9c4d | 357 | MpPair_t low = indices + AliMp::Pair(0, GetLowLimitIy()); |
5f91c9e8 | 358 | motifPosition->SetLowIndicesLimit(low); |
359 | ||
360 | // High limit | |
361 | AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType(); | |
168e9c4d | 362 | MpPair_t high |
363 | = motifPosition->GetLowIndicesLimit() | |
364 | + AliMp::Pair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1); | |
5f91c9e8 | 365 | motifPosition->SetHighIndicesLimit(high); |
366 | ||
367 | // Return next index in x | |
168e9c4d | 368 | return AliMp::PairFirst(high)+1; |
5f91c9e8 | 369 | // return motifType->GetNofPadsX(); |
370 | } | |
371 | ||
372 | ||
373 | //_____________________________________________________________________________ | |
374 | AliMpRow* AliMpRowSegment::GetRow() const | |
375 | { | |
dee1d5f1 | 376 | /// Return the row.which this row segment belongs to. |
5f91c9e8 | 377 | |
378 | return fRow; | |
379 | } | |
380 | ||
381 | //_____________________________________________________________________________ | |
382 | Int_t AliMpRowSegment::GetNofMotifs() const | |
383 | { | |
dee1d5f1 | 384 | /// Return number of motifs in this this row segment. |
5f91c9e8 | 385 | |
386 | return fNofMotifs; | |
387 | } | |
388 | ||
389 | //_____________________________________________________________________________ | |
390 | Int_t AliMpRowSegment::GetMotifPositionId(Int_t i) const | |
391 | { | |
dee1d5f1 | 392 | /// Return number of motifs in this this row segment. |
5f91c9e8 | 393 | |
394 | return fMotifPositionId + i*fMotifPositionDId; | |
395 | } | |
396 | ||
397 | //_____________________________________________________________________________ | |
ffb47139 | 398 | AliMpVMotif* AliMpRowSegment::GetMotif(Int_t /*i*/) const |
5f91c9e8 | 399 | { |
dee1d5f1 | 400 | /// Return the motif of this row segment. |
5f91c9e8 | 401 | |
402 | return fMotif; | |
403 | } |