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"
39 #include <Riostream.h>
43 ClassImp(AliMpRowSegmentRSpecial)
46 //______________________________________________________________________________
47 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial(AliMpRow* row, Double_t offsetX)
48 : AliMpVRowSegmentSpecial(row, offsetX)
50 /// Standard constructor
53 //______________________________________________________________________________
54 AliMpRowSegmentRSpecial::AliMpRowSegmentRSpecial()
55 : AliMpVRowSegmentSpecial()
57 /// Default constructor
60 //______________________________________________________________________________
61 AliMpRowSegmentRSpecial::~AliMpRowSegmentRSpecial()
70 //______________________________________________________________________________
72 AliMpRowSegmentRSpecial::FindMostLeftPadRowSegment(Int_t motifPositionId) const
74 /// Find the most left pad row segment with this motifPositionId.
76 AliMpVPadRowSegment* found = 0;
78 for (Int_t i=0; i<GetNofPadRows(); i++) {
79 AliMpPadRow* padRow = GetPadRow(i);
81 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
82 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
84 if ( padRowSegment->GetMotifPositionId() == motifPositionId &&
85 (!found || padRowSegment->LeftBorderX() < found->LeftBorderX()))
87 found = padRowSegment;
94 //______________________________________________________________________________
95 void AliMpRowSegmentRSpecial::SetGlobalIndicesLow()
97 /// Set global low indices
99 // Last normal row segment in the row
100 // (preceding this special row segment)
101 AliMpVRowSegment* rowSegment
102 = GetRow()->GetRowSegment(GetRow()->GetNofRowSegments()-2);
104 // Set low indices limit to continue indices of the
105 // preceding row segment
106 Int_t ix = rowSegment->GetHighIndicesLimit().GetFirst() + 1;
107 Int_t iy = rowSegment->GetLowIndicesLimit().GetSecond();
109 SetLowIndicesLimit(AliMpIntPair(ix, iy));
116 //______________________________________________________________________________
117 TVector2 AliMpRowSegmentRSpecial::MotifCenterSlow(Int_t motifPositionId) const
119 /// Return the coordinates of the motif specified with
120 /// the given position identifier. \n
121 /// !! Applicable only for motifs that have their most down pad in
122 /// this row segment.
124 // Find the first (left, down) pad row segment with this motifPositionId.
125 AliMpVPadRowSegment* downPadRowSegment
126 = FindPadRowSegment(motifPositionId);
127 AliMpVPadRowSegment* leftPadRowSegment
128 = FindMostLeftPadRowSegment(motifPositionId);
130 // Check if the motifPositionId is present
131 if (!downPadRowSegment || !leftPadRowSegment) {
132 AliErrorStream() << "Outside row segment region" << endl;
136 // Check if both pad row segments have the same motif
137 if (downPadRowSegment->GetMotif() != leftPadRowSegment->GetMotif()) {
138 AliFatal("Outside row segment region");
142 // Get position of found row segment
143 Double_t x = leftPadRowSegment->LeftBorderX();
144 Double_t y = GetRow()->LowBorderY() ;
146 for (Int_t i=0; i<downPadRowSegment->GetPadRow()->GetID(); i++)
147 y += GetPadRow(i)->HalfSizeY()*2.;
149 // Add motifs dimensions
150 x += downPadRowSegment->GetMotif()->Dimensions().X();
151 y += downPadRowSegment->GetMotif()->Dimensions().Y();
153 return TVector2(x, y);
160 //______________________________________________________________________________
161 Double_t AliMpRowSegmentRSpecial::LeftBorderX() const
163 /// Return the x coordinate of the left row segment border
164 /// in the global coordinate system.
166 // The right edge of the last normal segment
167 Double_t sameBorder = GetOffsetX();
170 Double_t leftBorder = DBL_MAX;
171 for (Int_t i=0; i<GetNofPadRows(); i++) {
172 AliMpPadRow* padRow = GetPadRow(i);
173 Double_t border = padRow->GetPadRowSegment(0)->LeftBorderX();
174 if (border < leftBorder) leftBorder = border;
177 if (TMath::Abs(sameBorder - leftBorder) > 1.e-04) {
178 AliErrorStream() << "WrongBorder" << endl;;
186 //______________________________________________________________________________
187 Double_t AliMpRowSegmentRSpecial::RightBorderX() const
189 /// Return the x coordinate of the right row segment border
190 /// in the global coordinate system.
192 Double_t rightBorder = -DBL_MAX;
193 for (Int_t i=0; i<GetNofPadRows(); i++) {
194 AliMpPadRow* padRow = GetPadRow(i);
196 = padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)
199 if (border > rightBorder) rightBorder = border;
205 //______________________________________________________________________________
206 TVector2 AliMpRowSegmentRSpecial::Position() const
208 /// Return the position of the row segment centre.
209 /// The centre is defined as the centre of the rectangular
210 /// row segment envelope.
212 // The right edge of the last normal segment
213 Double_t x = GetOffsetX() + Dimensions().X();
214 Double_t y = GetRow()->Position().Y();
216 return TVector2(x, y);
219 //______________________________________________________________________________
220 Int_t AliMpRowSegmentRSpecial::SetIndicesToMotifPosition(Int_t i,
221 const AliMpIntPair& indices)
223 /// Set global indices to i-th motif position and returns next index in x.
225 // Update low indices limit for this row segment
226 SetGlobalIndicesLow();
228 // Check for consistence
229 if (GetLowIndicesLimit().GetFirst() != indices.GetFirst())
230 AliFatal("Inconsistent indices");
232 // Get motif position
233 AliMpMotifPosition* motifPosition
234 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
236 // Set limits only once
237 if ( motifPosition->GetHighIndicesLimit().IsValid() )
238 return indices.GetFirst();;
242 Int_t ixl = GetLowIndicesLimit().GetFirst();
243 Int_t iyl = GetLowIndicesLimit().GetSecond();
245 // Find the most down pad row segment with this motifPositionId.
246 AliMpVPadRowSegment* padRowSegment = FindPadRowSegment(GetMotifPositionId(i));
247 Int_t padRowID = padRowSegment->GetPadRow()->GetID();
250 // Add pads offset of this motif position in the row segment
251 for (Int_t im=0; im<i; im++) {
252 AliMpVPadRowSegment* rs = GetPadRow(padRowID)->GetPadRowSegment(im);
253 if ( rs->GetMotifPositionId() == GetMotifPositionId(i) ) break;
254 ixl += rs->GetNofPads();
256 motifPosition->SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
260 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
262 = motifPosition->GetLowIndicesLimit()
263 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
264 motifPosition->SetHighIndicesLimit(high);
266 // No increment index needed (this is always the last element)
267 return indices.GetFirst();
270 //______________________________________________________________________________
271 void AliMpRowSegmentRSpecial::SetGlobalIndices(AliMpRow* rowBefore)
273 /// Set indices limits.
274 /// The limits are defined as the limits of the smallest rectangle which
275 /// includes all pads of this special row segment.
277 // Get first motif position
278 AliMpMotifPosition* firstMotifPosition
279 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(0));
282 Int_t ixl = firstMotifPosition->GetLowIndicesLimit().GetFirst();
283 // We have to take the motif position limit
284 // as it can overlap over more rows and the indices
285 // of the right border of the precedent normal segment
286 // differ from one row to another
289 Int_t ixh = ixl + MaxNofPadsInRow() - 1;
292 Int_t iyl = AliMpConstants::StartPadIndex();
294 //if (constPadSizeDirection == kY) {
295 iyl = rowBefore->GetHighIndicesLimit().GetSecond()+1;
299 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ixl);
300 AliMpMotifPosition* motPos = rowBefore->FindMotifPosition(seg, ixl);
302 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
303 iyl = motPos->GetHighIndicesLimit().GetSecond()+1;
309 Int_t iyh = iyl + GetNofPadRows() - 1;
311 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
312 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));