]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpRowSegmentRSpecial.cxx
d37026919c5a048d71b6ca29151dddc567937264
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpRowSegmentRSpecial.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: AliMpRowSegmentRSpecial.cxx,v 1.7 2006/05/24 13:58:46 ivana Exp $
18 // Category: sector
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpRowSegmentRSpecial
22 // -----------------------------
23 // Class describing a special outer row segment composed of the 
24 // pad rows.
25 // Included in AliRoot: 2003/05/02
26 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 //-----------------------------------------------------------------------------
28
29 #include "AliMpRowSegmentRSpecial.h"
30 #include "AliMpRow.h"
31 #include "AliMpPadRow.h"
32 #include "AliMpVPadRowSegment.h"
33 #include "AliMpMotif.h"
34 #include "AliMpMotifType.h"
35 #include "AliMpMotifMap.h"
36 #include "AliMpMotifPosition.h"
37 #include "AliMpConstants.h"
38
39 #include "AliLog.h"
40
41 #include <Riostream.h>
42 #include <TMath.h>
43
44 /// \cond CLASSIMP
45 ClassImp(AliMpRowSegmentRSpecial)
46 /// \endcond
47
48 //______________________________________________________________________________
49 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial(AliMpRow* row, Double_t offsetX)
50   : AliMpVRowSegmentSpecial(row, offsetX)
51 {
52 /// Standard constructor 
53 }
54
55 //______________________________________________________________________________
56 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial() 
57   : AliMpVRowSegmentSpecial()
58 {
59 /// Default constructor 
60 }
61
62 //______________________________________________________________________________
63 AliMpRowSegmentRSpecial::~AliMpRowSegmentRSpecial() 
64 {
65 /// Destructor  
66 }
67
68 //
69 // private methods  
70 //
71
72 //______________________________________________________________________________
73 AliMpVPadRowSegment*  
74 AliMpRowSegmentRSpecial::FindMostLeftPadRowSegment(Int_t motifPositionId) const
75 {
76 /// Find the most left pad row segment with this motifPositionId.
77
78   AliMpVPadRowSegment* found = 0;
79
80   for (Int_t i=0; i<GetNofPadRows(); i++) {
81     AliMpPadRow* padRow = GetPadRow(i);    
82
83     for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) { 
84       AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
85
86       if ( padRowSegment->GetMotifPositionId() == motifPositionId &&
87            (!found || padRowSegment->LeftBorderX() < found->LeftBorderX()))
88            
89         found = padRowSegment;  
90     }
91   }
92
93   return found;         
94 }
95
96 //______________________________________________________________________________
97 void AliMpRowSegmentRSpecial::SetGlobalIndicesLow()
98 {
99 /// Set global low indices
100    
101   // Last normal row segment in the row
102   // (preceding this special row segment)
103   AliMpVRowSegment* rowSegment 
104     =  GetRow()->GetRowSegment(GetRow()->GetNofRowSegments()-2);
105     
106   // Set low indices limit to continue indices of the
107   // preceding row segment  
108   Int_t ix = rowSegment->GetHighLimitIx() + 1;
109   Int_t iy = rowSegment->GetLowLimitIy();
110   
111   SetLowIndicesLimit(ix, iy);
112 }
113
114 //
115 // protected methods  
116 //
117
118 //______________________________________________________________________________
119 void AliMpRowSegmentRSpecial::MotifCenterSlow(Int_t motifPositionId,
120                                               Double_t& x, Double_t& y) const
121 {
122 /// Fill the coordinates of the motif specified with
123 /// the given position identifier.                                           \n
124 /// !! Applicable only for motifs that have their most down pad in
125 /// this row segment.
126
127   // Find the first (left, down) pad row segment with this motifPositionId.
128   AliMpVPadRowSegment* downPadRowSegment 
129     = FindPadRowSegment(motifPositionId);
130   AliMpVPadRowSegment* leftPadRowSegment 
131     = FindMostLeftPadRowSegment(motifPositionId);
132   
133   // Check if the motifPositionId is present 
134   if (!downPadRowSegment || !leftPadRowSegment) {
135     AliErrorStream() << "Outside row segment region" << endl;
136     return;
137   }
138
139   // Check if both pad row segments have the same motif 
140   if (downPadRowSegment->GetMotif() != leftPadRowSegment->GetMotif()) {
141     AliFatal("Outside row segment region");
142     return;
143   }
144
145   // Get position of found row segment
146   x = leftPadRowSegment->LeftBorderX();       
147   y = GetRow()->LowBorderY()  ;   
148   
149   for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
150     y += GetPadRow(i)->HalfSizeY()*2.;
151     
152   // Add motifs dimensions
153   x += downPadRowSegment->GetMotif()->DimensionX();
154   y += downPadRowSegment->GetMotif()->DimensionY();
155 }
156
157 //
158 // public methods  
159 //
160
161 //______________________________________________________________________________
162 Double_t  AliMpRowSegmentRSpecial::LeftBorderX() const
163 {
164 /// Return the x coordinate of the left row segment border
165 /// in the global coordinate system.
166
167   // The right edge of the last normal segment
168   Double_t sameBorder = GetOffsetX();
169
170   // Consistence check  
171   Double_t leftBorder = DBL_MAX;
172   for (Int_t i=0; i<GetNofPadRows(); i++) {
173     AliMpPadRow* padRow = GetPadRow(i);
174     Double_t border = padRow->GetPadRowSegment(0)->LeftBorderX();
175     if (border < leftBorder) leftBorder =  border;
176   }  
177
178   if (TMath::Abs(sameBorder - leftBorder) > 1.e-04)  {
179     AliErrorStream() << "WrongBorder" << endl;;
180     return sameBorder;
181   }  
182   
183   return leftBorder;
184
185 }
186
187 //______________________________________________________________________________
188 Double_t  AliMpRowSegmentRSpecial::RightBorderX() const
189 {
190 /// Return the x coordinate of the right row segment border
191 /// in the global coordinate system.
192
193   Double_t rightBorder = -DBL_MAX;
194   for (Int_t i=0; i<GetNofPadRows(); i++) {
195     AliMpPadRow* padRow = GetPadRow(i);
196     Double_t border 
197       = padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)
198         ->RightBorderX();
199       
200     if (border > rightBorder) rightBorder =  border;
201   }  
202   
203   return rightBorder;
204 }
205
206 //______________________________________________________________________________
207 Double_t AliMpRowSegmentRSpecial::GetPositionX() const
208 {
209 /// Return the x position of the row segment centre.
210 /// The centre is defined as the centre of the rectangular
211 /// row segment envelope.
212
213   // The right edge of the last normal segment
214   return GetOffsetX()  + GetDimensionX();
215 }
216
217 //______________________________________________________________________________
218 Double_t AliMpRowSegmentRSpecial::GetPositionY() const
219 {
220 /// Return the y position of the row segment centre.
221 /// The centre is defined as the centre of the rectangular
222 /// row segment envelope.
223
224   // The right edge of the last normal segment
225   return GetRow()->GetPositionY();  
226 }
227
228 //______________________________________________________________________________
229 Int_t AliMpRowSegmentRSpecial::SetIndicesToMotifPosition(Int_t i, MpPair_t indices)
230 {
231 /// Set global indices to i-th motif position and returns next index in x.
232
233   // Update low indices limit for this row segment
234   SetGlobalIndicesLow();
235
236   // Check for consistence
237   if ( GetLowLimitIx() != AliMp::PairFirst(indices) ) 
238     AliFatal("Inconsistent indices");
239
240   // Get motif position
241   AliMpMotifPosition* motifPosition
242     = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
243     
244   // Set limits only once
245   if ( motifPosition->IsHighLimitValid() ) 
246     return AliMp::PairFirst(indices); 
247
248   // Low limit
249   //
250   Int_t ixl = GetLowLimitIx();
251   Int_t iyl = GetLowLimitIy();
252
253   // Find the most down pad row segment with this motifPositionId.
254   AliMpVPadRowSegment* padRowSegment = FindPadRowSegment(GetMotifPositionId(i));
255   Int_t padRowID = padRowSegment->GetPadRow()->GetID();
256   iyl += padRowID; 
257
258   // Add pads offset of this motif position in the row segment
259   for ( Int_t im=0; im<i; im++ ) {
260     AliMpVPadRowSegment* rs = GetPadRow(padRowID)->GetPadRowSegment(im);
261     if ( rs->GetMotifPositionId() == GetMotifPositionId(i) ) break; 
262     ixl += rs->GetNofPads();
263   }  
264   motifPosition->SetLowIndicesLimit(ixl, iyl);
265
266   // High limit 
267   //     
268   AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();  
269   MpPair_t high 
270     = motifPosition->GetLowIndicesLimit()
271       + AliMp::Pair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);            
272   motifPosition->SetHighIndicesLimit(high);
273
274   // No increment index needed (this is always the last element)
275   return AliMp::PairFirst(indices);
276 }
277
278 //______________________________________________________________________________
279 void AliMpRowSegmentRSpecial::SetGlobalIndices(AliMpRow* rowBefore)
280 {
281 /// Set indices limits.
282 /// The limits are defined as the limits of the smallest rectangle which
283 /// includes all pads of this special row segment.
284
285   // Get first motif position
286   AliMpMotifPosition* firstMotifPosition
287     = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(0));
288     
289   // Low ix
290   Int_t ixl = firstMotifPosition->GetLowLimitIx();
291               // We have to take the motif position limit
292               // as it can overlap over more rows and the indices
293               // of the right border of the precedent normal segment
294               // differ from one row to another  
295
296   // High ix
297   Int_t ixh = ixl + MaxNofPadsInRow() - 1;
298
299   // Low iy
300   Int_t iyl = AliMpConstants::StartPadIndex();
301   if (rowBefore) {
302     //if (constPadSizeDirection == kY) {
303       iyl = rowBefore->GetHighLimitIy()+1;
304     //} 
305     /*
306     else {
307       AliMpVRowSegment* seg = rowBefore->FindRowSegment(ixl);   
308       AliMpMotifPosition* motPos =  rowBefore->FindMotifPosition(seg, ixl);
309       if (!motPos) 
310         Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
311       iyl = motPos->GetHighLimitIy()+1;
312     }
313     */
314   }  
315
316   // High iy
317   Int_t iyh = iyl + GetNofPadRows() - 1;
318   
319   SetLowIndicesLimit(ixl, iyl);
320   SetHighIndicesLimit(ixh, iyh);
321 }  
322
323