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