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