]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpRowSegmentRSpecial.cxx
bugfix: stopwatches for HLT benchmarks had been resumed at wrong point and measuremen...
[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->GetHighIndicesLimit().GetFirst() + 1;
109   Int_t iy = rowSegment->GetLowIndicesLimit().GetSecond();
110   
111   SetLowIndicesLimit(AliMpIntPair(ix, iy));
112 }
113
114 //
115 // protected methods  
116 //
117
118 //______________________________________________________________________________
119 TVector2 AliMpRowSegmentRSpecial::MotifCenterSlow(Int_t motifPositionId) const
120 {
121 /// Return the coordinates of the motif specified with
122 /// the given position identifier.                                           \n
123 /// !! Applicable only for motifs that have their most down pad in
124 /// this row segment.
125
126   // Find the first (left, down) pad row segment with this motifPositionId.
127   AliMpVPadRowSegment* downPadRowSegment 
128     = FindPadRowSegment(motifPositionId);
129   AliMpVPadRowSegment* leftPadRowSegment 
130     = FindMostLeftPadRowSegment(motifPositionId);
131   
132   // Check if the motifPositionId is present 
133   if (!downPadRowSegment || !leftPadRowSegment) {
134     AliErrorStream() << "Outside row segment region" << endl;
135     return 0;
136   }
137
138   // Check if both pad row segments have the same motif 
139   if (downPadRowSegment->GetMotif() != leftPadRowSegment->GetMotif()) {
140     AliFatal("Outside row segment region");
141     return 0;
142   }
143
144   // Get position of found row segment
145   Double_t x = leftPadRowSegment->LeftBorderX();       
146   Double_t y = GetRow()->LowBorderY()  ;   
147   
148   for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
149     y += GetPadRow(i)->HalfSizeY()*2.;
150     
151   // Add motifs dimensions
152   x += downPadRowSegment->GetMotif()->Dimensions().X();
153   y += downPadRowSegment->GetMotif()->Dimensions().Y();
154   
155   return TVector2(x, y);
156 }
157
158 //
159 // public methods  
160 //
161
162 //______________________________________________________________________________
163 Double_t  AliMpRowSegmentRSpecial::LeftBorderX() const
164 {
165 /// Return the x coordinate of the left row segment border
166 /// in the global coordinate system.
167
168   // The right edge of the last normal segment
169   Double_t sameBorder = GetOffsetX();
170
171   // Consistence check  
172   Double_t leftBorder = DBL_MAX;
173   for (Int_t i=0; i<GetNofPadRows(); i++) {
174     AliMpPadRow* padRow = GetPadRow(i);
175     Double_t border = padRow->GetPadRowSegment(0)->LeftBorderX();
176     if (border < leftBorder) leftBorder =  border;
177   }  
178
179   if (TMath::Abs(sameBorder - leftBorder) > 1.e-04)  {
180     AliErrorStream() << "WrongBorder" << endl;;
181     return sameBorder;
182   }  
183   
184   return leftBorder;
185
186 }
187
188 //______________________________________________________________________________
189 Double_t  AliMpRowSegmentRSpecial::RightBorderX() const
190 {
191 /// Return the x coordinate of the right row segment border
192 /// in the global coordinate system.
193
194   Double_t rightBorder = -DBL_MAX;
195   for (Int_t i=0; i<GetNofPadRows(); i++) {
196     AliMpPadRow* padRow = GetPadRow(i);
197     Double_t border 
198       = padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)
199         ->RightBorderX();
200       
201     if (border > rightBorder) rightBorder =  border;
202   }  
203   
204   return rightBorder;
205 }
206
207 //______________________________________________________________________________
208 TVector2 AliMpRowSegmentRSpecial::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   // The right edge of the last normal segment
215   Double_t x = GetOffsetX()  + Dimensions().X();
216   Double_t y = GetRow()->Position().Y();  
217     
218   return TVector2(x, y);   
219 }
220
221 //______________________________________________________________________________
222 Int_t AliMpRowSegmentRSpecial::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   // Update low indices limit for this row segment
228   SetGlobalIndicesLow();
229
230   // Check for consistence
231   if (GetLowIndicesLimit().GetFirst() != indices.GetFirst()) 
232     AliFatal("Inconsistent indices");
233
234   // Get motif position
235   AliMpMotifPosition* motifPosition
236     = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
237     
238   // Set limits only once
239   if ( motifPosition->GetHighIndicesLimit().IsValid() ) 
240     return indices.GetFirst();; 
241
242   // Low limit
243   //
244   Int_t ixl = GetLowIndicesLimit().GetFirst();
245   Int_t iyl = GetLowIndicesLimit().GetSecond();
246
247   // Find the most down pad row segment with this motifPositionId.
248   AliMpVPadRowSegment* padRowSegment = FindPadRowSegment(GetMotifPositionId(i));
249   Int_t padRowID = padRowSegment->GetPadRow()->GetID();
250   iyl += padRowID; 
251
252   // Add pads offset of this motif position in the row segment
253   for (Int_t im=0; im<i; im++) {
254     AliMpVPadRowSegment* rs = GetPadRow(padRowID)->GetPadRowSegment(im);
255     if ( rs->GetMotifPositionId() == GetMotifPositionId(i) ) break; 
256     ixl += rs->GetNofPads();
257   }  
258   motifPosition->SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
259
260   // High limit 
261   //     
262   AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();  
263   AliMpIntPair high 
264     = motifPosition->GetLowIndicesLimit()
265       + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);            
266   motifPosition->SetHighIndicesLimit(high);
267
268   // No increment index needed (this is always the last element)
269   return indices.GetFirst();
270 }
271
272 //______________________________________________________________________________
273 void AliMpRowSegmentRSpecial::SetGlobalIndices(AliMpRow* rowBefore)
274 {
275 /// Set indices limits.
276 /// The limits are defined as the limits of the smallest rectangle which
277 /// includes all pads of this special row segment.
278
279   // Get first motif position
280   AliMpMotifPosition* firstMotifPosition
281     = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(0));
282     
283   // Low ix
284   Int_t ixl = firstMotifPosition->GetLowIndicesLimit().GetFirst();
285               // We have to take the motif position limit
286               // as it can overlap over more rows and the indices
287               // of the right border of the precedent normal segment
288               // differ from one row to another  
289
290   // High ix
291   Int_t ixh = ixl + MaxNofPadsInRow() - 1;
292
293   // Low iy
294   Int_t iyl = AliMpConstants::StartPadIndex();
295   if (rowBefore) {
296     //if (constPadSizeDirection == kY) {
297       iyl = rowBefore->GetHighIndicesLimit().GetSecond()+1;
298     //} 
299     /*
300     else {
301       AliMpVRowSegment* seg = rowBefore->FindRowSegment(ixl);   
302       AliMpMotifPosition* motPos =  rowBefore->FindMotifPosition(seg, ixl);
303       if (!motPos) 
304         Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
305       iyl = motPos->GetHighIndicesLimit().GetSecond()+1;
306     }
307     */
308   }  
309
310   // High iy
311   Int_t iyh = iyl + GetNofPadRows() - 1;
312   
313   SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
314   SetHighIndicesLimit(AliMpIntPair(ixh, iyh));
315 }  
316
317