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