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