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