]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpRowSegmentLSpecial.cxx
Fix for the problem during PbPb run of Nov 2010 (Indra)
[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 #include "AliMpEncodePair.h"
42
43 #include "AliLog.h"
44
45 /// \cond CLASSIMP
46 ClassImp(AliMpRowSegmentLSpecial)
47 /// \endcond
48
49 //______________________________________________________________________________
50 AliMpRowSegmentLSpecial::AliMpRowSegmentLSpecial(AliMpRow* row, Double_t offsetX)
51   : AliMpVRowSegmentSpecial(row, offsetX)
52 {
53 /// Standard constructor
54 }
55
56 //______________________________________________________________________________
57 AliMpRowSegmentLSpecial::AliMpRowSegmentLSpecial() 
58   : AliMpVRowSegmentSpecial()
59 {
60 /// Default constructor
61 }
62
63 //______________________________________________________________________________
64 AliMpRowSegmentLSpecial::~AliMpRowSegmentLSpecial() 
65 {
66 /// Destructor  
67 }
68
69 //
70 // private methods  
71 //
72
73 //______________________________________________________________________________
74 AliMpVPadRowSegment*  
75 AliMpRowSegmentLSpecial::FindMostRightPadRowSegment(Int_t motifPositionId) const
76 {
77 /// Find the most right pad row segment with this motifPositionId.
78
79   AliMpVPadRowSegment* found = 0;
80
81   for (Int_t i=0; i<GetNofPadRows(); i++) {
82     AliMpPadRow* padRow = GetPadRow(i);    
83
84     for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) { 
85       AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
86
87       if ( padRowSegment->GetMotifPositionId() == motifPositionId &&
88            (!found || padRowSegment->RightBorderX() > found->RightBorderX()))
89            
90         found = padRowSegment;  
91     }
92   }
93
94   return found;         
95 }
96
97 //
98 // protected methods  
99 //
100
101 //______________________________________________________________________________
102 void AliMpRowSegmentLSpecial::MotifCenterSlow(Int_t motifPositionId,
103                                               Double_t& x, Double_t& y) const
104 {
105 /// Fill the coordinates of the motif specified with
106 /// the given position identifier.                                           \n
107 /// !! Applicable only for motifs that have their most down pad in
108 /// this row segment.
109
110   // Find the first (left, down) pad row segment with this motifPositionId.
111   AliMpVPadRowSegment* downPadRowSegment 
112     = FindPadRowSegment(motifPositionId);
113   AliMpVPadRowSegment* rightPadRowSegment 
114     = FindMostRightPadRowSegment(motifPositionId);
115   
116   // Check if the motifPositionId is present 
117   if (!downPadRowSegment || !rightPadRowSegment) {
118     AliErrorStream() << "Outside row segment region" << endl;
119     return;
120   }
121
122   // Check if both pad row segments have the same motif 
123   if (downPadRowSegment->GetMotif() != rightPadRowSegment->GetMotif()) {
124     AliFatal("Outside row segment region");
125     return;
126   }
127
128   // Get position of found row segment
129   x = rightPadRowSegment->RightBorderX();       
130   y = GetRow()->LowBorderY()  ;   
131   
132   for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
133     y += GetPadRow(i)->HalfSizeY()*2.;
134     
135   // Add motifs dimensions
136   x -= downPadRowSegment->GetMotif()->DimensionX();
137   y += downPadRowSegment->GetMotif()->DimensionY();
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   MpPair_t offset = neighbour->GetLowIndicesLimit();
157   
158   // Find max nof pads in a row
159   Int_t maxNofPads = MaxNofPadsInRow();
160
161   // Set limits
162   SetLowIndicesLimit(offset - AliMp::Pair(maxNofPads, 0));
163
164   // Reset limits in the neighbour row segment
165   // (pad offset is now included in the special segment)  
166   neighbour->SetLowIndicesLimit(0, neighbour->GetLowLimitIy());
167 }
168
169 //______________________________________________________________________________
170 Double_t  AliMpRowSegmentLSpecial::LeftBorderX() const
171 {
172 /// Return the x coordinate of the left row segment border
173 /// in the global coordinate system.
174
175   Double_t leftBorder = DBL_MAX;
176   for (Int_t i=0; i<GetNofPadRows(); i++) {
177     AliMpPadRow* padRow = GetPadRow(i);
178     Double_t border 
179       = padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX();
180       
181     if (border < leftBorder) leftBorder =  border;
182   }  
183   
184   return leftBorder;
185 }
186
187 //______________________________________________________________________________
188 Double_t  AliMpRowSegmentLSpecial::RightBorderX() const
189 {
190 /// Returns the x coordinate of the right row segment border
191 /// in the global coordinate system.
192
193   Double_t sameBorder = GetOffsetX();
194
195   // Consistence check  
196   Double_t rightBorder = -DBL_MAX;
197   for (Int_t i=0; i<GetNofPadRows(); i++) {
198     AliMpPadRow* padRow = GetPadRow(i);
199     Double_t border = padRow->GetPadRowSegment(0)->RightBorderX();
200     if (border > rightBorder) rightBorder =  border;
201   }  
202
203   if (TMath::Abs(GetOffsetX() - rightBorder) > 1.e-04)  {
204     AliErrorStream() << "WrongBorder" << endl;
205     return sameBorder;
206   }  
207   
208   return rightBorder;
209 }
210
211 //______________________________________________________________________________
212 Double_t AliMpRowSegmentLSpecial::GetPositionX() const
213 {
214 /// Return the x position of the row segment centre.
215 /// The centre is defined as the centre of the rectangular
216 /// row segment envelope.
217
218   return GetOffsetX() - GetDimensionX();                    
219 }
220
221 //______________________________________________________________________________
222 Double_t AliMpRowSegmentLSpecial::GetPositionY() const
223 {
224 /// Return the y position of the row segment centre.
225 /// The centre is defined as the centre of the rectangular
226 /// row segment envelope.
227
228   return GetRow()->GetPositionY();  
229 }
230
231 #include <Riostream.h>
232 //______________________________________________________________________________
233 Int_t AliMpRowSegmentLSpecial::SetIndicesToMotifPosition(Int_t i, MpPair_t indices)
234 {
235 /// Set global indices to i-th motif position and returns next index in x.
236
237   // Get motif position
238   AliMpMotifPosition* motifPosition
239     = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
240
241   // Low limit
242   MpPair_t low 
243     = AliMp::Pair(GetLowLimitIx() + AliMpConstants::StartPadIndex(), 
244                   AliMp::PairSecond(indices))
245       + FindRelativeLowIndicesOf(GetMotifPositionId(i));
246             
247   if (! motifPosition->IsHighLimitValid()) {   
248      motifPosition->SetLowIndicesLimit(low);
249   } 
250   else {
251     if ( motifPosition->GetLowLimitIx() > AliMp::PairFirst(low) )
252       motifPosition->SetLowIndicesLimit(
253                                  AliMp::PairFirst(low),
254                                  motifPosition->GetLowLimitIy());
255
256     if ( motifPosition->GetLowLimitIy() > AliMp::PairSecond(low) )
257        motifPosition->SetLowIndicesLimit(
258                                  motifPosition->GetLowLimitIx(),
259                                  AliMp::PairSecond(low) );
260   }
261              
262   // High limit      
263   AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();  
264   MpPair_t high 
265     = motifPosition->GetLowIndicesLimit()
266       + AliMp::Pair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);  
267                 
268   motifPosition->SetHighIndicesLimit(high);
269
270   // Increment index only if last motif position is processed 
271   if ( i != GetNofMotifs()-1 ) 
272     return AliMp::PairFirst(indices);
273     //return 0;
274   else
275     return AliMp::PairFirst(indices) + MaxNofPadsInRow();  
276     //return MaxNofPadsInRow();  
277 }
278 //______________________________________________________________________________
279 void AliMpRowSegmentLSpecial::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   // Low ix
286   Int_t ixl = GetLowLimitIx() + AliMpConstants::StartPadIndex();
287       // the pads offset was already defined by Reader
288
289   // High ix
290   Int_t ixh = ixl + MaxNofPadsInRow() - 1;
291
292   // Low iy
293   Int_t iyl = AliMpConstants::StartPadIndex();
294   if (rowBefore) {
295     //if (constPadSizeDirection == kY) {
296       iyl = rowBefore->GetHighLimitIy()+1;
297     //} 
298     /*
299     else {
300       AliMpVRowSegment* seg = rowBefore->FindRowSegment(ixl);   
301       AliMpMotifPosition* motPos =  rowBefore->FindMotifPosition(seg, ixl);
302       if (!motPos) 
303         Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
304       iyl = motPos->GetHighLimitIy()+1;
305     }
306     */
307   }  
308
309   // High iy
310   Int_t iyh = iyl + GetNofPadRows() - 1;
311   
312   SetLowIndicesLimit(ixl, iyl);
313   SetHighIndicesLimit(ixh, iyh);
314 }  
315
316
317
318