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