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