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