1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpRowSegmentRSpecial.cxx,v 1.7 2006/05/24 13:58:46 ivana Exp $
20 // Class AliMpRowSegmentRSpecial
21 // -----------------------------
22 // Class describing a special outer row segment composed of the
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 #include "AliMpRowSegmentRSpecial.h"
29 #include "AliMpPadRow.h"
30 #include "AliMpVPadRowSegment.h"
31 #include "AliMpMotif.h"
32 #include "AliMpMotifType.h"
33 #include "AliMpMotifMap.h"
34 #include "AliMpMotifPosition.h"
35 #include "AliMpConstants.h"
37 #include <Riostream.h>
40 ClassImp(AliMpRowSegmentRSpecial)
43 //______________________________________________________________________________
44 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial(AliMpRow* row, Double_t offsetX)
45 : AliMpVRowSegmentSpecial(row, offsetX)
47 /// Standard constructor
50 //______________________________________________________________________________
51 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial()
52 : AliMpVRowSegmentSpecial()
54 /// Default constructor
57 //______________________________________________________________________________
58 AliMpRowSegmentRSpecial::~AliMpRowSegmentRSpecial()
67 //______________________________________________________________________________
69 AliMpRowSegmentRSpecial::FindMostLeftPadRowSegment(Int_t motifPositionId) const
71 /// Find the most left pad row segment with this motifPositionId.
73 AliMpVPadRowSegment* found = 0;
75 for (Int_t i=0; i<GetNofPadRows(); i++) {
76 AliMpPadRow* padRow = GetPadRow(i);
78 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
79 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
81 if ( padRowSegment->GetMotifPositionId() == motifPositionId &&
82 (!found || padRowSegment->LeftBorderX() < found->LeftBorderX()))
84 found = padRowSegment;
91 //______________________________________________________________________________
92 void AliMpRowSegmentRSpecial::SetGlobalIndicesLow()
94 /// Set global low indices
96 // Last normal row segment in the row
97 // (preceding this special row segment)
98 AliMpVRowSegment* rowSegment
99 = GetRow()->GetRowSegment(GetRow()->GetNofRowSegments()-2);
101 // Set low indices limit to continue indices of the
102 // preceding row segment
103 Int_t ix = rowSegment->GetHighIndicesLimit().GetFirst() + 1;
104 Int_t iy = rowSegment->GetLowIndicesLimit().GetSecond();
106 SetLowIndicesLimit(AliMpIntPair(ix, iy));
113 //______________________________________________________________________________
114 TVector2 AliMpRowSegmentRSpecial::MotifCenterSlow(Int_t motifPositionId) const
116 /// Return the coordinates of the motif specified with
117 /// the given position identifier. \n
118 /// !! Applicable only for motifs that have their most down pad in
119 /// this row segment.
121 // Find the first (left, down) pad row segment with this motifPositionId.
122 AliMpVPadRowSegment* downPadRowSegment
123 = FindPadRowSegment(motifPositionId);
124 AliMpVPadRowSegment* leftPadRowSegment
125 = FindMostLeftPadRowSegment(motifPositionId);
127 // Check if the motifPositionId is present
128 if (!downPadRowSegment || !leftPadRowSegment) {
129 AliErrorStream() << "Outside row segment region" << endl;
133 // Check if both pad row segments have the same motif
134 if (downPadRowSegment->GetMotif() != leftPadRowSegment->GetMotif()) {
135 AliFatal("Outside row segment region");
139 // Get position of found row segment
140 Double_t x = leftPadRowSegment->LeftBorderX();
141 Double_t y = GetRow()->LowBorderY() ;
143 for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
144 y += GetPadRow(i)->HalfSizeY()*2.;
146 // Add motifs dimensions
147 x += downPadRowSegment->GetMotif()->Dimensions().X();
148 y += downPadRowSegment->GetMotif()->Dimensions().Y();
150 return TVector2(x, y);
157 //______________________________________________________________________________
158 Double_t AliMpRowSegmentRSpecial::LeftBorderX() const
160 /// Return the x coordinate of the left row segment border
161 /// in the global coordinate system.
163 // The right edge of the last normal segment
164 Double_t sameBorder = GetOffsetX();
167 Double_t leftBorder = DBL_MAX;
168 for (Int_t i=0; i<GetNofPadRows(); i++) {
169 AliMpPadRow* padRow = GetPadRow(i);
170 Double_t border = padRow->GetPadRowSegment(0)->LeftBorderX();
171 if (border < leftBorder) leftBorder = border;
174 if (TMath::Abs(sameBorder - leftBorder) > 1.e-04) {
175 AliErrorStream() << "WrongBorder" << endl;;
183 //______________________________________________________________________________
184 Double_t AliMpRowSegmentRSpecial::RightBorderX() const
186 /// Return the x coordinate of the right row segment border
187 /// in the global coordinate system.
189 Double_t rightBorder = -DBL_MAX;
190 for (Int_t i=0; i<GetNofPadRows(); i++) {
191 AliMpPadRow* padRow = GetPadRow(i);
193 = padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)
196 if (border > rightBorder) rightBorder = border;
202 //______________________________________________________________________________
203 TVector2 AliMpRowSegmentRSpecial::Position() const
205 /// Return the position of the row segment centre.
206 /// The centre is defined as the centre of the rectangular
207 /// row segment envelope.
209 // The right edge of the last normal segment
210 Double_t x = GetOffsetX() + Dimensions().X();
211 Double_t y = GetRow()->Position().Y();
213 return TVector2(x, y);
216 //______________________________________________________________________________
217 Int_t AliMpRowSegmentRSpecial::SetIndicesToMotifPosition(Int_t i,
218 const AliMpIntPair& indices)
220 /// Set global indices to i-th motif position and returns next index in x.
222 // Update low indices limit for this row segment
223 SetGlobalIndicesLow();
225 // Check for consistence
226 if (GetLowIndicesLimit().GetFirst() != indices.GetFirst())
227 AliFatal("Inconsistent indices");
229 // Get motif position
230 AliMpMotifPosition* motifPosition
231 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
233 // Set limits only once
234 if ( motifPosition->GetHighIndicesLimit().IsValid() )
235 return indices.GetFirst();;
239 Int_t ixl = GetLowIndicesLimit().GetFirst();
240 Int_t iyl = GetLowIndicesLimit().GetSecond();
242 // Find the most down pad row segment with this motifPositionId.
243 AliMpVPadRowSegment* padRowSegment = FindPadRowSegment(GetMotifPositionId(i));
244 Int_t padRowID = padRowSegment->GetPadRow()->GetID();
247 // Add pads offset of this motif position in the row segment
248 for (Int_t im=0; im<i; im++) {
249 AliMpVPadRowSegment* rs = GetPadRow(padRowID)->GetPadRowSegment(im);
250 if ( rs->GetMotifPositionId() == GetMotifPositionId(i) ) break;
251 ixl += rs->GetNofPads();
253 motifPosition->SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
257 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
259 = motifPosition->GetLowIndicesLimit()
260 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
261 motifPosition->SetHighIndicesLimit(high);
263 // No increment index needed (this is always the last element)
264 return indices.GetFirst();
267 //______________________________________________________________________________
268 void AliMpRowSegmentRSpecial::SetGlobalIndices(AliMpRow* rowBefore)
270 /// Set indices limits.
271 /// The limits are defined as the limits of the smallest rectangle which
272 /// includes all pads of this special row segment.
274 // Get first motif position
275 AliMpMotifPosition* firstMotifPosition
276 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(0));
279 Int_t ixl = firstMotifPosition->GetLowIndicesLimit().GetFirst();
280 // We have to take the motif position limit
281 // as it can overlap over more rows and the indices
282 // of the right border of the precedent normal segment
283 // differ from one row to another
286 Int_t ixh = ixl + MaxNofPadsInRow() - 1;
289 Int_t iyl = AliMpConstants::StartPadIndex();
291 //if (constPadSizeDirection == kY) {
292 iyl = rowBefore->GetHighIndicesLimit().GetSecond()+1;
296 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ixl);
297 AliMpMotifPosition* motPos = rowBefore->FindMotifPosition(seg, ixl);
299 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
300 iyl = motPos->GetHighIndicesLimit().GetSecond()+1;
306 Int_t iyh = iyl + GetNofPadRows() - 1;
308 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
309 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));