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