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