]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpRowSegmentRSpecial.cxx
Coding conventions
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpRowSegmentRSpecial.cxx
CommitLineData
dee1d5f1 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
ea4cae7a 16// $Id$
13985652 17// $MpId: AliMpRowSegmentRSpecial.cxx,v 1.7 2006/05/24 13:58:46 ivana Exp $
ea4cae7a 18// Category: sector
3d1463c8 19
20//-----------------------------------------------------------------------------
ea4cae7a 21// Class AliMpRowSegmentRSpecial
22// -----------------------------
23// Class describing a special outer row segment composed of the
24// pad rows.
dbe945cc 25// Included in AliRoot: 2003/05/02
ea4cae7a 26// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
3d1463c8 27//-----------------------------------------------------------------------------
ea4cae7a 28
ea4cae7a 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"
580c28fd 37#include "AliMpConstants.h"
ea4cae7a 38
97186a3f 39#include "AliLog.h"
40
41#include <Riostream.h>
42#include <TMath.h>
43
13985652 44/// \cond CLASSIMP
ea4cae7a 45ClassImp(AliMpRowSegmentRSpecial)
13985652 46/// \endcond
ea4cae7a 47
48//______________________________________________________________________________
49AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial(AliMpRow* row, Double_t offsetX)
50 : AliMpVRowSegmentSpecial(row, offsetX)
51{
dee1d5f1 52/// Standard constructor
ea4cae7a 53}
54
55//______________________________________________________________________________
56AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial()
57 : AliMpVRowSegmentSpecial()
58{
dee1d5f1 59/// Default constructor
ea4cae7a 60}
61
62//______________________________________________________________________________
63AliMpRowSegmentRSpecial::~AliMpRowSegmentRSpecial()
64{
dee1d5f1 65/// Destructor
ea4cae7a 66}
67
68//
69// private methods
70//
71
72//______________________________________________________________________________
73AliMpVPadRowSegment*
74AliMpRowSegmentRSpecial::FindMostLeftPadRowSegment(Int_t motifPositionId) const
75{
dee1d5f1 76/// Find the most left pad row segment with this motifPositionId.
ea4cae7a 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//______________________________________________________________________________
97void AliMpRowSegmentRSpecial::SetGlobalIndicesLow()
98{
dee1d5f1 99/// Set global low indices
ea4cae7a 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//______________________________________________________________________________
119TVector2 AliMpRowSegmentRSpecial::MotifCenterSlow(Int_t motifPositionId) const
120{
dee1d5f1 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.
ea4cae7a 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) {
2c605e66 134 AliErrorStream() << "Outside row segment region" << endl;
ea4cae7a 135 return 0;
136 }
137
138 // Check if both pad row segments have the same motif
139 if (downPadRowSegment->GetMotif() != leftPadRowSegment->GetMotif()) {
2c605e66 140 AliFatal("Outside row segment region");
ea4cae7a 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//______________________________________________________________________________
163Double_t AliMpRowSegmentRSpecial::LeftBorderX() const
164{
dee1d5f1 165/// Return the x coordinate of the left row segment border
166/// in the global coordinate system.
ea4cae7a 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) {
2c605e66 180 AliErrorStream() << "WrongBorder" << endl;;
ea4cae7a 181 return sameBorder;
182 }
183
184 return leftBorder;
185
186}
187
188//______________________________________________________________________________
189Double_t AliMpRowSegmentRSpecial::RightBorderX() const
190{
dee1d5f1 191/// Return the x coordinate of the right row segment border
192/// in the global coordinate system.
ea4cae7a 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//______________________________________________________________________________
208TVector2 AliMpRowSegmentRSpecial::Position() const
209{
dee1d5f1 210/// Return the position of the row segment centre.
211/// The centre is defined as the centre of the rectangular
212/// row segment envelope.
ea4cae7a 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//______________________________________________________________________________
222Int_t AliMpRowSegmentRSpecial::SetIndicesToMotifPosition(Int_t i,
223 const AliMpIntPair& indices)
224{
dee1d5f1 225/// Set global indices to i-th motif position and returns next index in x.
ea4cae7a 226
227 // Update low indices limit for this row segment
228 SetGlobalIndicesLow();
580c28fd 229
ea4cae7a 230 // Check for consistence
231 if (GetLowIndicesLimit().GetFirst() != indices.GetFirst())
c3cd353e 232 AliFatal("Inconsistent indices");
ea4cae7a 233
234 // Get motif position
235 AliMpMotifPosition* motifPosition
236 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
580c28fd 237
238 // Set limits only once
239 if ( motifPosition->GetHighIndicesLimit().IsValid() )
240 return indices.GetFirst();;
ea4cae7a 241
242 // Low limit
580c28fd 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));
ea4cae7a 259
580c28fd 260 // High limit
261 //
ea4cae7a 262 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
263 AliMpIntPair high
264 = motifPosition->GetLowIndicesLimit()
265 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
266 motifPosition->SetHighIndicesLimit(high);
580c28fd 267
ea4cae7a 268 // No increment index needed (this is always the last element)
269 return indices.GetFirst();
270}
271
580c28fd 272//______________________________________________________________________________
273void AliMpRowSegmentRSpecial::SetGlobalIndices(AliMpRow* rowBefore)
274{
dee1d5f1 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.
580c28fd 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
ea4cae7a 317