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