]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpRowSegment.cxx
Adding new option to get the DE by its name (moreover to get it by its ID).
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpRowSegment.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
5f91c9e8 16// $Id$
13985652 17// $MpId: AliMpRowSegment.cxx,v 1.10 2006/05/24 13:58:46 ivana Exp $
5f91c9e8 18// Category: sector
19//
20// Class AliMpRowSegment
21// ---------------------
22// Class describing a row segment composed of the
23// the identic motifs.
dbe945cc 24// Included in AliRoot: 2003/05/02
5f91c9e8 25// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26
5f91c9e8 27#include "AliMpRowSegment.h"
28#include "AliMpRow.h"
29#include "AliMpVMotif.h"
30#include "AliMpMotifType.h"
31#include "AliMpMotifTypePadIterator.h"
32#include "AliMpMotifMap.h"
33#include "AliMpMotifPosition.h"
580c28fd 34#include "AliMpConstants.h"
5f91c9e8 35
97186a3f 36#include "AliLog.h"
37
2c605e66 38#include <TMath.h>
39#include <Riostream.h>
40
13985652 41/// \cond CLASSIMP
5f91c9e8 42ClassImp(AliMpRowSegment)
13985652 43/// \endcond
5f91c9e8 44
45//_____________________________________________________________________________
46AliMpRowSegment::AliMpRowSegment(AliMpRow* row, AliMpVMotif* motif,
47 AliMpIntPair padOffset,
48 Int_t nofMotifs,
49 Int_t motifPositionId, Int_t motifPositionDId)
50 : AliMpVRowSegment(),
51 fNofMotifs(nofMotifs),
52 fPadOffset(padOffset),
53 fOffset(TVector2()),
54 fRow(row),
55 fMotif(motif),
56 fMotifPositionId(motifPositionId),
57 fMotifPositionDId(motifPositionDId)
58{
dee1d5f1 59/// Standard constructor
60
5f91c9e8 61 // Keep pad offset in the low indices limits
62 SetLowIndicesLimit(padOffset);
63}
64
65//_____________________________________________________________________________
66AliMpRowSegment::AliMpRowSegment()
67 : AliMpVRowSegment(),
68 fNofMotifs(0),
69 fPadOffset(AliMpIntPair()),
70 fOffset(TVector2()),
71 fRow(0),
72 fMotif(0),
73 fMotifPositionId(0),
74 fMotifPositionDId(0)
75{
dee1d5f1 76/// Default constructor
5f91c9e8 77}
78
79//_____________________________________________________________________________
dee1d5f1 80AliMpRowSegment::~AliMpRowSegment()
81{
82/// Destructor
5f91c9e8 83}
84
85//
86// private methods
87//
88
89//_____________________________________________________________________________
90Double_t AliMpRowSegment::FirstMotifCenterX() const
91{
dee1d5f1 92/// Return the x coordinate of the first motif center
93/// in the global coordinate system.
5f91c9e8 94
95 return fOffset.X();
96}
97
98//_____________________________________________________________________________
99Double_t AliMpRowSegment::LastMotifCenterX() const
100{
dee1d5f1 101/// Return the x coordinate of the last motif center
102/// in the global coordinate system.
5f91c9e8 103
104 return fOffset.X() + 2.*(fNofMotifs-1)*fMotif->Dimensions().X();
105}
106
107//_____________________________________________________________________________
108Double_t AliMpRowSegment::MotifCenterX(Int_t motifPositionId) const
109{
dee1d5f1 110/// Return the x coordinate of the motif specified with
111/// the given position identifier.
5f91c9e8 112
113 // Check if x is in the row segment range
114 if (! HasMotifPosition(motifPositionId)) {
2c605e66 115 AliErrorStream() << "Outside row segment region" << endl;
5f91c9e8 116 return 0;
117 }
118
119 // Find the position number in the segment
120 Int_t num = (motifPositionId - fMotifPositionId) * fMotifPositionDId;
121
122 return fOffset.X() + num*(fMotif->Dimensions().X() * 2.0);
123}
124
125//_____________________________________________________________________________
126Double_t AliMpRowSegment::MotifCenterY(Int_t motifPositionId) const
127{
dee1d5f1 128/// Return the y coordinate of the motif specified with
129/// the given position identifier.
5f91c9e8 130
131 // Check if x is in the row segment range
132 if (! HasMotifPosition(motifPositionId)) {
2c605e66 133 AliErrorStream() << "Outside row segment region" << endl;
5f91c9e8 134 return 0;
135 }
136
137 return GetRow()->Position().Y() + fOffset.Y();
138}
139
140//_____________________________________________________________________________
141Bool_t AliMpRowSegment::IsInside(const TVector2& position, Bool_t warn) const
142{
dee1d5f1 143/// Check if the position is inside some motif of this row segment.
5f91c9e8 144
145 Double_t minY = GetRow()->Position().Y() + fOffset.Y() - fMotif->Dimensions().Y();
146 Double_t maxY = GetRow()->Position().Y() + fOffset.Y() + fMotif->Dimensions().Y();
147
148 if ( position.X() < LeftBorderX() || position.X() > RightBorderX() ||
149 position.Y() < minY || position.Y() > maxY ) {
150
2c605e66 151 if (warn)
152 AliWarningStream() << "Outside row segment region" << endl;
5f91c9e8 153 return false;
154 }
155 else
156 return true;
157}
158
159//
160// public methods
161//
162
163//_____________________________________________________________________________
164Double_t AliMpRowSegment::LeftBorderX() const
165{
dee1d5f1 166/// Return the x coordinate of the left row segment border
167/// in the global coordinate system.
5f91c9e8 168
169 return FirstMotifCenterX() - fMotif->Dimensions().X();
170}
171
172//_____________________________________________________________________________
173Double_t AliMpRowSegment::RightBorderX() const
174{
dee1d5f1 175/// Return the x coordinate of the right row segment border
176/// in the global coordinate system.
5f91c9e8 177
178 return LastMotifCenterX() + fMotif->Dimensions().X();
179}
180
181//_____________________________________________________________________________
182Double_t AliMpRowSegment::HalfSizeY() const
183{
dee1d5f1 184/// Return the size in y of this row segment.
5f91c9e8 185
186 return fMotif->Dimensions().Y() + fOffset.Y();
187}
188
189//_____________________________________________________________________________
190AliMpVMotif* AliMpRowSegment::FindMotif(const TVector2& position) const
191{
dee1d5f1 192/// Return the motif of this row;
5f91c9e8 193
194 if (IsInside(position, false))
195 return fMotif;
196 else
197 return 0;
198}
199
200//_____________________________________________________________________________
201Int_t AliMpRowSegment::FindMotifPositionId(const TVector2& position) const
202{
dee1d5f1 203/// Return the motif position identified for the given
204/// geometric position.
5f91c9e8 205
206 if (!IsInside(position, false)) return 0;
207
208 // Find the position number in the segment
209 Int_t num
210 = Int_t((position.X() - LeftBorderX()) / (fMotif->Dimensions().X() * 2.0));
211
212 // Calculate the position Id
213 return fMotifPositionId + num*fMotifPositionDId;
214}
215
216//_____________________________________________________________________________
217Bool_t AliMpRowSegment::HasMotifPosition(Int_t motifPositionId) const
218{
dee1d5f1 219/// Return true if the motif specified with the given position identifier
220/// is in this segment.
5f91c9e8 221
222 Int_t minId = TMath::Min(fMotifPositionId,
223 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
224 Int_t maxId = TMath::Max(fMotifPositionId,
225 fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
226
227 if (motifPositionId >= minId && motifPositionId <= maxId) {
228 return true;
229 }
230 else
231 return false;
232}
233
234//_____________________________________________________________________________
235TVector2 AliMpRowSegment::MotifCenter(Int_t motifPositionId) const
236{
dee1d5f1 237/// Return the coordinates of the motif specified with
238/// the given position identifier.
5f91c9e8 239
240 return TVector2(MotifCenterX(motifPositionId), MotifCenterY(motifPositionId));
241}
242
243//_____________________________________________________________________________
244TVector2 AliMpRowSegment::Position() const
245{
dee1d5f1 246/// Return the position of the row segment centre.
5f91c9e8 247
248 Double_t x = (LeftBorderX() + RightBorderX())/2.;
249 Double_t y = GetRow()->Position().Y();
250
251 return TVector2(x, y);
252}
253
254
255//_____________________________________________________________________________
256TVector2 AliMpRowSegment::Dimensions() const
257{
dee1d5f1 258/// Return the halflengths of the row segment in x, y.
5f91c9e8 259// ---
260
261 Double_t x = (RightBorderX() - LeftBorderX())/2.;
262 Double_t y = GetRow()->Dimensions().Y();
263
264 return TVector2(x, y);
265}
266
267//_____________________________________________________________________________
268void AliMpRowSegment::SetOffset(const TVector2& offset)
269{
dee1d5f1 270/// Calculate offset from given offset and
271/// stored offset in pads.
5f91c9e8 272
273 AliMpMotifTypePadIterator iter(fMotif->GetMotifType());
274 iter.First();
275 AliMpIntPair localPos = iter.CurrentItem().GetIndices();
276
277 Double_t offsetX
278 = offset.X()
279 + 2.*fPadOffset.GetFirst() * fMotif->GetPadDimensions(localPos).X()
280 + fMotif->Dimensions().X();
281
282 Double_t offsetY
283 = offset.Y()
284 + fPadOffset.GetSecond() * fMotif->GetPadDimensions(localPos).Y();
285
286 fOffset = TVector2(offsetX, offsetY);
287}
288
580c28fd 289#include <Riostream.h>
5f91c9e8 290//_____________________________________________________________________________
580c28fd 291void AliMpRowSegment::SetGlobalIndices(AliMpRow* /*rowBefore*/)
5f91c9e8 292{
dee1d5f1 293/// Set global indices limits.
5f91c9e8 294
580c28fd 295 // The low/high indices limits has to be taken as the highest/lowest from all
296 // motif positions
297 Int_t ixl = 9999;
298 Int_t iyl = 9999;
299 Int_t ixh = AliMpConstants::StartPadIndex();
300 Int_t iyh = AliMpConstants::StartPadIndex();
301
302 for (Int_t i=0; i<GetNofMotifs(); i++) {
303
304 AliMpMotifPosition* mPos
305 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
306
307 // Check if the motif positions has the limits set
308 if ( !mPos->HasValidIndices() )
309 Fatal("SetGlobalIndices",
310 "Indices of motif positions have to be set first.");
5f91c9e8 311
580c28fd 312 if ( mPos->GetLowIndicesLimit().GetFirst() < ixl )
313 ixl = mPos->GetLowIndicesLimit().GetFirst();
314
315 if ( mPos->GetLowIndicesLimit().GetSecond() < iyl )
316 iyl = mPos->GetLowIndicesLimit().GetSecond();
317
318 if ( mPos->GetHighIndicesLimit().GetFirst() > ixh )
319 ixh = mPos->GetHighIndicesLimit().GetFirst();
320
321 if ( mPos->GetHighIndicesLimit().GetSecond() > iyh )
322 iyh = mPos->GetHighIndicesLimit().GetSecond();
323 }
324
325 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
326 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));
5f91c9e8 327}
328
329//_____________________________________________________________________________
ffb47139 330Int_t AliMpRowSegment::SetIndicesToMotifPosition(Int_t i,
331 const AliMpIntPair& indices)
5f91c9e8 332{
dee1d5f1 333/// Set global indices to i-th motif position and returns next index
334/// in x.
5f91c9e8 335
336 // Get motif position
337 AliMpMotifPosition* motifPosition
338 = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
339
340 // Low limit
341 AliMpIntPair low = indices + AliMpIntPair(0, GetLowIndicesLimit().GetSecond());
342 motifPosition->SetLowIndicesLimit(low);
343
344 // High limit
345 AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();
346 AliMpIntPair high
347 = motifPosition->GetLowIndicesLimit()
348 + AliMpIntPair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
349 motifPosition->SetHighIndicesLimit(high);
350
351 // Return next index in x
352 return high.GetFirst()+1;
353 // return motifType->GetNofPadsX();
354}
355
356
357//_____________________________________________________________________________
358AliMpRow* AliMpRowSegment::GetRow() const
359{
dee1d5f1 360/// Return the row.which this row segment belongs to.
5f91c9e8 361
362 return fRow;
363}
364
365//_____________________________________________________________________________
366Int_t AliMpRowSegment::GetNofMotifs() const
367{
dee1d5f1 368/// Return number of motifs in this this row segment.
5f91c9e8 369
370 return fNofMotifs;
371}
372
373//_____________________________________________________________________________
374Int_t AliMpRowSegment::GetMotifPositionId(Int_t i) const
375{
dee1d5f1 376/// Return number of motifs in this this row segment.
5f91c9e8 377
378 return fMotifPositionId + i*fMotifPositionDId;
379}
380
381//_____________________________________________________________________________
ffb47139 382AliMpVMotif* AliMpRowSegment::GetMotif(Int_t /*i*/) const
5f91c9e8 383{
dee1d5f1 384/// Return the motif of this row segment.
5f91c9e8 385
386 return fMotif;
387}