Correct use of ROOT_INCLUDE_DIR
[u/mrichter/AliRoot.git] / MUON / MUONmapping / 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
b80faac0 44using std::endl;
13985652 45/// \cond CLASSIMP
ea4cae7a 46ClassImp(AliMpRowSegmentRSpecial)
13985652 47/// \endcond
ea4cae7a 48
49//______________________________________________________________________________
50AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial(AliMpRow* row, Double_t offsetX)
51 : AliMpVRowSegmentSpecial(row, offsetX)
52{
dee1d5f1 53/// Standard constructor
ea4cae7a 54}
55
56//______________________________________________________________________________
57AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial()
58 : AliMpVRowSegmentSpecial()
59{
dee1d5f1 60/// Default constructor
ea4cae7a 61}
62
63//______________________________________________________________________________
64AliMpRowSegmentRSpecial::~AliMpRowSegmentRSpecial()
65{
dee1d5f1 66/// Destructor
ea4cae7a 67}
68
69//
70// private methods
71//
72
73//______________________________________________________________________________
74AliMpVPadRowSegment*
75AliMpRowSegmentRSpecial::FindMostLeftPadRowSegment(Int_t motifPositionId) const
76{
dee1d5f1 77/// Find the most left pad row segment with this motifPositionId.
ea4cae7a 78
79 AliMpVPadRowSegment* found = 0;
80
81 for (Int_t i=0; i<GetNofPadRows(); i++) {
82 AliMpPadRow* padRow = GetPadRow(i);
83
84 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
85 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
86
87 if ( padRowSegment->GetMotifPositionId() == motifPositionId &&
88 (!found || padRowSegment->LeftBorderX() < found->LeftBorderX()))
89
90 found = padRowSegment;
91 }
92 }
93
94 return found;
95}
96
97//______________________________________________________________________________
98void AliMpRowSegmentRSpecial::SetGlobalIndicesLow()
99{
dee1d5f1 100/// Set global low indices
ea4cae7a 101
102 // Last normal row segment in the row
103 // (preceding this special row segment)
104 AliMpVRowSegment* rowSegment
105 = GetRow()->GetRowSegment(GetRow()->GetNofRowSegments()-2);
106
107 // Set low indices limit to continue indices of the
108 // preceding row segment
168e9c4d 109 Int_t ix = rowSegment->GetHighLimitIx() + 1;
110 Int_t iy = rowSegment->GetLowLimitIy();
ea4cae7a 111
168e9c4d 112 SetLowIndicesLimit(ix, iy);
ea4cae7a 113}
114
115//
116// protected methods
117//
118
119//______________________________________________________________________________
6e97fbb8 120void AliMpRowSegmentRSpecial::MotifCenterSlow(Int_t motifPositionId,
121 Double_t& x, Double_t& y) const
ea4cae7a 122{
6e97fbb8 123/// Fill the coordinates of the motif specified with
dee1d5f1 124/// the given position identifier. \n
125/// !! Applicable only for motifs that have their most down pad in
126/// this row segment.
ea4cae7a 127
128 // Find the first (left, down) pad row segment with this motifPositionId.
129 AliMpVPadRowSegment* downPadRowSegment
130 = FindPadRowSegment(motifPositionId);
131 AliMpVPadRowSegment* leftPadRowSegment
132 = FindMostLeftPadRowSegment(motifPositionId);
133
134 // Check if the motifPositionId is present
135 if (!downPadRowSegment || !leftPadRowSegment) {
2c605e66 136 AliErrorStream() << "Outside row segment region" << endl;
6e97fbb8 137 return;
ea4cae7a 138 }
139
140 // Check if both pad row segments have the same motif
141 if (downPadRowSegment->GetMotif() != leftPadRowSegment->GetMotif()) {
2c605e66 142 AliFatal("Outside row segment region");
6e97fbb8 143 return;
ea4cae7a 144 }
145
146 // Get position of found row segment
6e97fbb8 147 x = leftPadRowSegment->LeftBorderX();
148 y = GetRow()->LowBorderY() ;
ea4cae7a 149
150 for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
151 y += GetPadRow(i)->HalfSizeY()*2.;
152
153 // Add motifs dimensions
6e97fbb8 154 x += downPadRowSegment->GetMotif()->DimensionX();
155 y += downPadRowSegment->GetMotif()->DimensionY();
ea4cae7a 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//______________________________________________________________________________
6e97fbb8 208Double_t AliMpRowSegmentRSpecial::GetPositionX() const
ea4cae7a 209{
6e97fbb8 210/// Return the x position of the row segment centre.
dee1d5f1 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
6e97fbb8 215 return GetOffsetX() + GetDimensionX();
216}
217
218//______________________________________________________________________________
219Double_t AliMpRowSegmentRSpecial::GetPositionY() const
220{
221/// Return the y position of the row segment centre.
222/// The centre is defined as the centre of the rectangular
223/// row segment envelope.
224
225 // The right edge of the last normal segment
226 return GetRow()->GetPositionY();
ea4cae7a 227}
228
229//______________________________________________________________________________
168e9c4d 230Int_t AliMpRowSegmentRSpecial::SetIndicesToMotifPosition(Int_t i, MpPair_t indices)
ea4cae7a 231{
dee1d5f1 232/// Set global indices to i-th motif position and returns next index in x.
ea4cae7a 233
234 // Update low indices limit for this row segment
235 SetGlobalIndicesLow();
580c28fd 236
ea4cae7a 237 // Check for consistence
168e9c4d 238 if ( GetLowLimitIx() != AliMp::PairFirst(indices) )
c3cd353e 239 AliFatal("Inconsistent indices");
ea4cae7a 240
241 // Get motif position
242 AliMpMotifPosition* motifPosition
243 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
580c28fd 244
245 // Set limits only once
168e9c4d 246 if ( motifPosition->IsHighLimitValid() )
247 return AliMp::PairFirst(indices);
ea4cae7a 248
249 // Low limit
580c28fd 250 //
168e9c4d 251 Int_t ixl = GetLowLimitIx();
252 Int_t iyl = GetLowLimitIy();
580c28fd 253
254 // Find the most down pad row segment with this motifPositionId.
255 AliMpVPadRowSegment* padRowSegment = FindPadRowSegment(GetMotifPositionId(i));
256 Int_t padRowID = padRowSegment->GetPadRow()->GetID();
257 iyl += padRowID;
258
259 // Add pads offset of this motif position in the row segment
168e9c4d 260 for ( Int_t im=0; im<i; im++ ) {
580c28fd 261 AliMpVPadRowSegment* rs = GetPadRow(padRowID)->GetPadRowSegment(im);
262 if ( rs->GetMotifPositionId() == GetMotifPositionId(i) ) break;
263 ixl += rs->GetNofPads();
264 }
168e9c4d 265 motifPosition->SetLowIndicesLimit(ixl, iyl);
ea4cae7a 266
580c28fd 267 // High limit
268 //
ea4cae7a 269 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
168e9c4d 270 MpPair_t high
ea4cae7a 271 = motifPosition->GetLowIndicesLimit()
168e9c4d 272 + AliMp::Pair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
ea4cae7a 273 motifPosition->SetHighIndicesLimit(high);
580c28fd 274
ea4cae7a 275 // No increment index needed (this is always the last element)
168e9c4d 276 return AliMp::PairFirst(indices);
ea4cae7a 277}
278
580c28fd 279//______________________________________________________________________________
280void AliMpRowSegmentRSpecial::SetGlobalIndices(AliMpRow* rowBefore)
281{
dee1d5f1 282/// Set indices limits.
283/// The limits are defined as the limits of the smallest rectangle which
284/// includes all pads of this special row segment.
580c28fd 285
286 // Get first motif position
287 AliMpMotifPosition* firstMotifPosition
288 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(0));
289
290 // Low ix
168e9c4d 291 Int_t ixl = firstMotifPosition->GetLowLimitIx();
580c28fd 292 // We have to take the motif position limit
293 // as it can overlap over more rows and the indices
294 // of the right border of the precedent normal segment
295 // differ from one row to another
296
297 // High ix
298 Int_t ixh = ixl + MaxNofPadsInRow() - 1;
299
300 // Low iy
301 Int_t iyl = AliMpConstants::StartPadIndex();
302 if (rowBefore) {
303 //if (constPadSizeDirection == kY) {
168e9c4d 304 iyl = rowBefore->GetHighLimitIy()+1;
580c28fd 305 //}
306 /*
307 else {
308 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ixl);
309 AliMpMotifPosition* motPos = rowBefore->FindMotifPosition(seg, ixl);
310 if (!motPos)
311 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
168e9c4d 312 iyl = motPos->GetHighLimitIy()+1;
580c28fd 313 }
314 */
315 }
316
317 // High iy
318 Int_t iyh = iyl + GetNofPadRows() - 1;
319
168e9c4d 320 SetLowIndicesLimit(ixl, iyl);
321 SetHighIndicesLimit(ixh, iyh);
580c28fd 322}
323
ea4cae7a 324