]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSectorSegmentation.cxx
Replacement of AliMpIntPair object with algoritmic
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSectorSegmentation.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: AliMpSectorSegmentation.cxx,v 1.15 2006/05/24 13:58:46 ivana Exp $
5f91c9e8 18// Category: sector
3d1463c8 19
20//-----------------------------------------------------------------------------
5f91c9e8 21// Class AliMpSectorSegmentation
22// -----------------------------
23// Class describing the segmentation of the sector.
24// Provides methods related to pads:
25// conversion between pad indices, pad location, pad position;
26// finding pad neighbour.
27//
28// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
3d1463c8 29//-----------------------------------------------------------------------------
5f91c9e8 30
5f91c9e8 31#include "AliMpSectorSegmentation.h"
32#include "AliMpSector.h"
33#include "AliMpZone.h"
2998a151 34#include "AliMpSubZone.h"
5f91c9e8 35#include "AliMpRow.h"
36#include "AliMpVRowSegment.h"
37#include "AliMpMotifMap.h"
38#include "AliMpVMotif.h"
39#include "AliMpMotifPosition.h"
40#include "AliMpConnection.h"
5f91c9e8 41#include "AliMpSectorAreaHPadIterator.h"
42#include "AliMpSectorAreaVPadIterator.h"
dbea2959 43#include "AliMpSectorPadIterator.h"
2998a151 44#include "AliMpArea.h"
5f91c9e8 45#include "AliMpConstants.h"
168e9c4d 46#include "AliMpEncodePair.h"
5f91c9e8 47
63bcb3c3 48#include "AliLog.h"
49
50#include <Riostream.h>
51#include <TMath.h>
5f91c9e8 52
13985652 53/// \cond CLASSIMP
54ClassImp(AliMpSectorSegmentation)
55/// \endcond
56
7c774e6d 57const Double_t AliMpSectorSegmentation::fgkS1 = 100000.;
58const Double_t AliMpSectorSegmentation::fgkS2 = 1000.;
f79c58a5 59
5f91c9e8 60//______________________________________________________________________________
d79286ca 61AliMpSectorSegmentation::AliMpSectorSegmentation(
62 const AliMpSector* sector, Bool_t own)
5f91c9e8 63 : AliMpVSegmentation(),
580c28fd 64 fkSector(sector),
d79286ca 65 fIsOwner(own),
13e7956b 66 fPadBuffer(0),
67 fPadDimensionsMap(),
580c28fd 68 fMaxIndexInX(0),
69 fMaxIndexInY(0)
5f91c9e8 70{
dee1d5f1 71/// Standard constructor
72
d79286ca 73 AliDebugStream(1) << "this = " << this << endl;
74
5f91c9e8 75 fPadBuffer = new AliMpPad(AliMpPad::Invalid());
76
77 FillPadDimensionsMap();
78}
79
80//______________________________________________________________________________
81AliMpSectorSegmentation::AliMpSectorSegmentation()
82 : AliMpVSegmentation(),
83 fkSector(0),
d79286ca 84 fIsOwner(false),
5f91c9e8 85 fPadBuffer(0),
580c28fd 86 fPadDimensionsMap(),
87 fMaxIndexInX(0),
88 fMaxIndexInY(0)
5f91c9e8 89{
dee1d5f1 90/// Default constructor
d79286ca 91
92 AliDebugStream(1) << "this = " << this << endl;
5f91c9e8 93}
94
95//______________________________________________________________________________
dee1d5f1 96AliMpSectorSegmentation::~AliMpSectorSegmentation()
97{
98/// Destructor
99
d79286ca 100 AliDebugStream(1) << "this = " << this << endl;
101
102 if ( fIsOwner ) delete fkSector;
103
5f91c9e8 104 delete fPadBuffer;
d79286ca 105
5f91c9e8 106}
107
108//
109// private methods
110//
111
f79c58a5 112//______________________________________________________________________________
113Long_t AliMpSectorSegmentation::GetIndex(const TVector2& vector2) const
114{
dee1d5f1 115/// Convert the two vector to long.
f79c58a5 116
bcf37928 117 return Long_t(TMath::Floor((vector2.X()*fgkS1 + vector2.Y())*fgkS2));
f79c58a5 118}
119
120//______________________________________________________________________________
121TVector2 AliMpSectorSegmentation::GetVector(Long_t index) const
122{
dee1d5f1 123/// Convert the long index to twovector.
f79c58a5 124
bcf37928 125 return TVector2( TMath::Floor(index/fgkS1)/fgkS2,
126 (index - TMath::Floor(index/fgkS1)*fgkS1)/fgkS2 );
f79c58a5 127}
f79c58a5 128
5f91c9e8 129//______________________________________________________________________________
130void AliMpSectorSegmentation::FillPadDimensionsMap()
131{
dee1d5f1 132/// Fill the maps between zone ids and pad dimensions.
5f91c9e8 133
134 for (Int_t i=0; i<fkSector->GetNofZones(); i++) {
135 AliMpZone* zone = fkSector->GetZone(i+1);
136 Int_t zoneID = zone->GetID();
137
138 if (!AliMpConstants::IsEqual(zone->GetPadDimensions(), TVector2())) {
f79c58a5 139
5f91c9e8 140 // regular zone
d79286ca 141 AliDebugStream(3)
142 << "Filling fPadDimensions[" << zoneID*10 << "] = ("
143 << zone->GetPadDimensions().X() << ", "
144 << zone->GetPadDimensions().Y() << ")" << endl;
145
bcf37928 146 fPadDimensionsMap.Add((Long_t)(zoneID*10),
f79c58a5 147 GetIndex(zone->GetPadDimensions()));
5f91c9e8 148 }
149 else {
150 // special zone
151 Int_t subIndex = 0;
152 for (Int_t j=0; j<zone->GetNofSubZones(); j++) {
153 AliMpSubZone* subZone = zone->GetSubZone(j);
154 AliMpVMotif* motif = subZone->GetMotif();
155
156 for (Int_t k=0; k<motif->GetNofPadDimensions(); k++) {
157 Int_t index = zoneID*10 + subIndex++;
d79286ca 158 AliDebugStream(3)
159 << "Filling fPadDimensions[" << index << "] = ("
160 << motif->GetPadDimensions(k).X() << ", "
161 << motif->GetPadDimensions(k).Y() << ") motif "
162 << motif->GetID().Data() << "-" << k << endl;
163
f79c58a5 164 fPadDimensionsMap.Add((Long_t)(index),
165 GetIndex(motif->GetPadDimensions(k)));
5f91c9e8 166 }
167 }
168 }
169 }
170}
171
172//______________________________________________________________________________
173AliMpMotifPosition*
168e9c4d 174AliMpSectorSegmentation::FindMotifPosition(Int_t ix, Int_t iy) const
5f91c9e8 175{
dee1d5f1 176/// Find the motif position which contains the given pad indices
177/// return 0 if not found
5f91c9e8 178
168e9c4d 179 switch ( fkSector->GetDirection() ) {
cddd101e 180 case AliMp::kX : {
5f91c9e8 181 // Case where all the pads have the same size along X direction
182
168e9c4d 183 for ( Int_t irow=0; irow<fkSector->GetNofRows(); ++irow ) {
5f91c9e8 184 AliMpRow* row = fkSector->GetRow(irow);
168e9c4d 185 if ( row->GetLowLimitIx() <= ix &&
186 row->GetHighLimitIx()>= ix ) {
5f91c9e8 187
168e9c4d 188 for ( Int_t iseg=0;iseg<row->GetNofRowSegments();++iseg ) {
5f91c9e8 189 AliMpVRowSegment* seg = row->GetRowSegment(iseg);
168e9c4d 190 if ( seg->GetLowLimitIx() <= ix &&
191 seg->GetHighLimitIx() >= ix ) {
5f91c9e8 192
193 AliMpMotifPosition* motifPos;
168e9c4d 194 for ( Int_t imot=0;imot<seg->GetNofMotifs();++imot ) {
5f91c9e8 195 motifPos
196 = fkSector->GetMotifMap()
197 ->FindMotifPosition(seg->GetMotifPositionId(imot));
168e9c4d 198 if (motifPos && motifPos->HasPadByIndices(AliMp::Pair(ix,iy))) return motifPos;
5f91c9e8 199 }
200 }
201 }
202 }
203 }
204 return 0;
205 }
dee1d5f1 206 break;
5f91c9e8 207 ////////////////////////////////////////////////////////////////////////////////
cddd101e 208 case AliMp::kY : {
5f91c9e8 209 // Case where all the pads have the same size along Y direction
210 // look for the row which contains the indices
211 AliMpRow* row=0;
212 Int_t irow;
168e9c4d 213 for ( irow=0; irow<fkSector->GetNofRows(); ++irow ) {
5f91c9e8 214 row = fkSector->GetRow(irow);
215 AliMpVRowSegment* lastSeg = row->GetRowSegment(row->GetNofRowSegments()-1);
168e9c4d 216 if ( lastSeg->GetLowLimitIy() <= iy &&
217 lastSeg->GetHighLimitIy() >= iy ) break;
5f91c9e8 218 // NOTE : We use the last row segment in order to ensure that
219 // we are not on a special motif
220 }
168e9c4d 221 if ( irow==fkSector->GetNofRows() ) return 0;
5f91c9e8 222 // look for the row segment, in the found row, which contains the indices
223 AliMpVRowSegment* seg=0;
224 Int_t iseg;
168e9c4d 225 for ( iseg=0;iseg<row->GetNofRowSegments();++iseg ) {
5f91c9e8 226 seg = row->GetRowSegment(iseg);
168e9c4d 227 if (seg->HasIndices(AliMp::Pair(ix, iy))) break;
5f91c9e8 228 }
168e9c4d 229 if ( iseg==row->GetNofRowSegments() ) return 0;
5f91c9e8 230
231 // look for the motif position which contains the indices
232 AliMpMotifPosition* motifPos=0;
233 Int_t imot=0;
168e9c4d 234 for ( imot=0;imot<seg->GetNofMotifs();++imot ) {
5f91c9e8 235 motifPos
236 = fkSector->GetMotifMap()
237 ->FindMotifPosition(seg->GetMotifPositionId(imot));
168e9c4d 238 if (motifPos && motifPos->HasPadByIndices(AliMp::Pair(ix, iy))) break;
5f91c9e8 239 }
240 if (imot==seg->GetNofMotifs()) return 0;
241
242 return motifPos;
243 }
244 default: return 0;
245 }
246}
247
248//______________________________________________________________________________
249AliMpPad
250AliMpSectorSegmentation::PadByXDirection(const TVector2& startPosition,
251 Double_t maxX) const
252{
dee1d5f1 253/// Find the first valid pad from starting position in the
254/// direction of pad lines up to distance dx.
5f91c9e8 255
256 // Define step limits
257 Double_t stepX = fkSector->GetMinPadDimensions().X();
258
259 // Search in X direction
260 AliMpPad pad;
168e9c4d 261 TVector2 position(startPosition);
5f91c9e8 262 do {
263 pad = PadByPosition(position, false);
264 position += TVector2(stepX, 0.);
265 }
984a565f 266 while ( !pad.IsValid() &&
267 position.X() - fkSector->GetMaxPadDimensions().X() < maxX );
5f91c9e8 268
269 // Invalidate pad if it is outside limits
984a565f 270 if ( (pad.Position().X() - pad.Dimensions().X()) > maxX )
5f91c9e8 271 pad = AliMpPad::Invalid();
272
273 return pad;
274}
275
276//______________________________________________________________________________
277AliMpPad
278AliMpSectorSegmentation::PadByYDirection(const TVector2& startPosition,
279 Double_t maxY) const
280{
dee1d5f1 281/// Find the first valid pad from starting position in the
282/// direction of pad columns up to distance dx.
5f91c9e8 283
284 // Define step limits
285 Double_t stepY = fkSector->GetMinPadDimensions().Y();
286
287 // Search in Y direction
288 AliMpPad pad;
289 TVector2 position(startPosition);
290 do {
291 pad = PadByPosition(position, false);
292 position += TVector2(0., stepY);
293 }
984a565f 294 while ( !pad.IsValid() &&
295 position.Y() - fkSector->GetMaxPadDimensions().Y()< maxY );
5f91c9e8 296
297 // Invalidate pad if it is outside limits
298 if ((pad.Position().Y() - pad.Dimensions().Y()) > maxY)
299 pad = AliMpPad::Invalid();
300
301 return pad;
302}
303
5f91c9e8 304//
305// public methods
306//
307
308//______________________________________________________________________________
309AliMpVPadIterator*
310AliMpSectorSegmentation::CreateIterator(const AliMpArea& area) const
311{
dee1d5f1 312/// Create the area iterator.
5f91c9e8 313
314 switch (fkSector->GetDirection()) {
315
cddd101e 316 case AliMp::kX: return new AliMpSectorAreaVPadIterator(this, area);
5f91c9e8 317 ;;
cddd101e 318 case AliMp::kY: return new AliMpSectorAreaHPadIterator(this, area);
5f91c9e8 319 ;;
320 }
321
322 Fatal("CreateIterator", "Incomplete switch on Sector direction");
323 return 0;
324}
325
984a565f 326//______________________________________________________________________________
3635f34f 327AliMpVPadIterator*
328AliMpSectorSegmentation::CreateIterator() const
984a565f 329{
3635f34f 330/// Create the sector iterator
331
332 return new AliMpSectorPadIterator(fkSector);
984a565f 333}
334
63bcb3c3 335//______________________________________________________________________________
3635f34f 336Int_t
337AliMpSectorSegmentation::GetNeighbours(const AliMpPad& pad, TObjArray& neighbours,
338 Bool_t includeSelf,
339 Bool_t includeVoid) const
63bcb3c3 340{
3635f34f 341 /// Uses default implementation
342 return AliMpVSegmentation::GetNeighbours(pad,neighbours,includeSelf,includeVoid);
63bcb3c3 343}
344
5f91c9e8 345//______________________________________________________________________________
346AliMpPad
168e9c4d 347AliMpSectorSegmentation::PadByLocation(Int_t manuId, Int_t manuChannel,
5f91c9e8 348 Bool_t warning) const
349{
dee1d5f1 350/// Find the pad which corresponds to the given location
5f91c9e8 351
168e9c4d 352
353
354 if ( fPadBuffer->GetManuId() == manuId &&
355 fPadBuffer->GetManuChannel() == manuChannel ) return (*fPadBuffer);
5f91c9e8 356
357 AliMpMotifPosition* motifPos =
168e9c4d 358 fkSector->GetMotifMap()->FindMotifPosition(manuId);
5f91c9e8 359 if (!motifPos){
360 if (warning) Warning("PadByLocation","The pad motif position ID doesn't exists");
361 return AliMpPad::Invalid();
362 }
363
364 AliMpVMotif* motif = motifPos->GetMotif();
168e9c4d 365 MpPair_t localIndices =
366 motif->GetMotifType()->FindLocalIndicesByGassiNum(manuChannel);
367 if ( localIndices < 0 ) {
5f91c9e8 368 if (warning) Warning("PadByLocation","The pad number doesn't exists");
369 return AliMpPad::Invalid();
370 }
371 TVector2 delta = motif->PadPositionLocal(localIndices);
168e9c4d 372
373 return (*fPadBuffer) = AliMpPad(manuId, manuChannel,
5f91c9e8 374 motifPos->GlobalIndices(localIndices),
375 motifPos->Position()+delta,
168e9c4d 376 motif->GetPadDimensionsByIndices(localIndices));
5f91c9e8 377
378}
379//______________________________________________________________________________
380AliMpPad
168e9c4d 381AliMpSectorSegmentation::PadByIndices(Int_t ix, Int_t iy, Bool_t warning ) const
5f91c9e8 382{
dee1d5f1 383/// Find the pad which corresponds to the given indices
5f91c9e8 384
168e9c4d 385
386 if ( fPadBuffer->GetIx() == ix &&
387 fPadBuffer->GetIy() == iy ) return (*fPadBuffer);
388
389 MpPair_t indices = AliMp::Pair(ix, iy);
390 AliMpMotifPosition* motifPos = FindMotifPosition(ix, iy);
5f91c9e8 391 if (!motifPos) {
073fe42a 392 if (warning)
580c28fd 393 Warning("PadByIndices","Pad indices not contained in any motif!");
5f91c9e8 394 return AliMpPad::Invalid();
395 }
396
397 // retrieve the local indices in the found motif
398 AliMpVMotif* motif = motifPos->GetMotif();
168e9c4d 399 MpPair_t localIndices = indices - motifPos->GetLowIndicesLimit();
5f91c9e8 400
401 AliMpConnection* connection=
402 motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
403
404 if (!connection){
405 if (warning) Warning("PadByIndices","No connection with the given indices!");
406 return AliMpPad::Invalid();
407 }
408
409 TVector2 localPos = motif->PadPositionLocal(localIndices);
410
411 return (*fPadBuffer)
168e9c4d 412 = AliMpPad(motifPos->GetID(),connection->GetManuChannel(),
413 ix, iy,
5f91c9e8 414 motifPos->Position()+localPos,
168e9c4d 415 motif->GetPadDimensionsByIndices(localIndices));
5f91c9e8 416
417}
418//______________________________________________________________________________
419AliMpPad
420AliMpSectorSegmentation::PadByPosition(const TVector2& position,
421 Bool_t warning) const
422{
dee1d5f1 423/// Find the pad which corresponds to the given position
5f91c9e8 424
168e9c4d 425 if (fPadBuffer->Position().X()==position.X() &&
426 fPadBuffer->Position().Y()==position.Y()) return (*fPadBuffer);
5f91c9e8 427
428 Int_t motifPosID = fkSector->FindMotifPositionId(position);
429 AliMpMotifPosition* motifPos
430 = fkSector->GetMotifMap()
431 ->FindMotifPosition(motifPosID);
432
433 if (!motifPos){
434 if (warning) Warning("PadByPosition","Position outside limits");
435 return AliMpPad::Invalid();
436 }
437
438 AliMpVMotif* motif = motifPos->GetMotif();
168e9c4d 439 MpPair_t localIndices
5f91c9e8 440 = motif->PadIndicesLocal(position-motifPos->Position());
168e9c4d 441
442 if ( localIndices < 0 ) {
654f27d4 443 if (warning) Warning("PadByPosition","Position outside motif limits");
444 return AliMpPad::Invalid();
445 }
446
5f91c9e8 447 AliMpConnection* connect =
448 motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
449
654f27d4 450 if ( ! connect ) {
5f91c9e8 451 if (warning) Warning("PadByPosition","Position outside motif limits");
452 return AliMpPad::Invalid();
453 }
454
455 return (*fPadBuffer)
168e9c4d 456 = AliMpPad(motifPosID, connect->GetManuChannel(),
5f91c9e8 457 motifPos->GlobalIndices(localIndices),
458 motifPos->Position()+motif->PadPositionLocal(localIndices),
168e9c4d 459 motif->GetPadDimensionsByIndices(localIndices));
5f91c9e8 460
461}
462
463//______________________________________________________________________________
464AliMpPad
465AliMpSectorSegmentation::PadByDirection(const TVector2& startPosition,
466 Double_t distance) const
467{
dee1d5f1 468/// Find the first valid pad from starting position in the
469/// direction of pad lines/columns up to the specified distance.
470/// Pad lines are the lines of pads in the sector with constant pad y size,
471/// pad columns are the columns of pads in the sector with constant pad x size.
5f91c9e8 472
473 switch (fkSector->GetDirection()) {
474
cddd101e 475 case AliMp::kX: return PadByYDirection(startPosition, distance);
5f91c9e8 476 ;;
cddd101e 477 case AliMp::kY: return PadByXDirection(startPosition, distance);
5f91c9e8 478 ;;
479 }
480
481 Fatal("PadByDirection", "Incomplete switch on Sector direction");
482 return AliMpPad::Invalid();
483}
484
3635f34f 485//_____________________________________________________________________________
486Bool_t
168e9c4d 487AliMpSectorSegmentation::HasPadByIndices(Int_t ix, Int_t iy) const
3635f34f 488{
489 /// Whether or not we have a pad at indices=(ix,iy)
490
168e9c4d 491 MpPair_t indices = AliMp::Pair(ix, iy);
492
493 AliMpMotifPosition* motifPos = FindMotifPosition(ix, iy);
3635f34f 494
495 if (motifPos) return motifPos->HasPadByIndices(indices);
496
497 return kFALSE;
498}
499
500//_____________________________________________________________________________
501Bool_t
168e9c4d 502AliMpSectorSegmentation::HasPadByLocation(Int_t manuId, Int_t manuChannel) const
3635f34f 503{
504 /// Whether or not we have a pad at location=(manuId,manuChannel)
505
168e9c4d 506 AliMpMotifPosition* motifPos
507 = fkSector->GetMotifMap()->FindMotifPosition(manuId);
3635f34f 508
168e9c4d 509 if ( motifPos ) return motifPos->HasPadByManuChannel(manuChannel);
3635f34f 510
511 return kFALSE;
512}
513
580c28fd 514//______________________________________________________________________________
bd984e15 515Int_t AliMpSectorSegmentation::MaxPadIndexX() const
580c28fd 516{
dee1d5f1 517/// Return maximum pad index in x
580c28fd 518
168e9c4d 519 return AliMp::PairFirst(fkSector->GetMaxPadIndices());
580c28fd 520}
521
522//______________________________________________________________________________
bd984e15 523Int_t AliMpSectorSegmentation::MaxPadIndexY() const
580c28fd 524{
dee1d5f1 525/// Return maximum pad index in y
580c28fd 526
168e9c4d 527 return AliMp::PairSecond(fkSector->GetMaxPadIndices());
bd984e15 528}
529
530//______________________________________________________________________________
531Int_t AliMpSectorSegmentation::NofPads() const
532{
533/// Return number of pads defined in the sector
534
535 return fkSector->GetNofPads();
580c28fd 536}
537
3635f34f 538//_____________________________________________________________________________
539void
540AliMpSectorSegmentation::GetAllElectronicCardIDs(TArrayI& ecn) const
5f91c9e8 541{
3635f34f 542 /// Fill the array ecn with all manuIds
5f91c9e8 543
3635f34f 544 GetSector()->GetAllMotifPositionsIDs(ecn);
545}
546
547//_____________________________________________________________________________
548Int_t
549AliMpSectorSegmentation::GetNofElectronicCards() const
550{
551 /// Get the number of manus of this sector
552
553 return fkSector->GetNofMotifPositions();
554}
555
556//_____________________________________________________________________________
557Bool_t
558AliMpSectorSegmentation::HasMotifPosition(Int_t manuId) const
559{
560 /// Whether we get a given manu. Uses default implementation
561 return (AliMpVSegmentation::HasMotifPosition(manuId) != 0x0);
562}
563
564//_____________________________________________________________________________
565AliMpMotifPosition*
566AliMpSectorSegmentation::MotifPosition(Int_t manuId) const
567{
568 /// Return a given manu
569 return fkSector->GetMotifMap()->FindMotifPosition(manuId);
5f91c9e8 570}
571
572//______________________________________________________________________________
3635f34f 573AliMp::PlaneType
574AliMpSectorSegmentation::PlaneType() const
575{
576 return GetSector()->GetPlaneType();
577}
578
579//______________________________________________________________________________
580TVector2
581AliMpSectorSegmentation::Dimensions() const
5f91c9e8 582{
3635f34f 583/// Return sector dimensions
5f91c9e8 584
3635f34f 585 return GetSector()->Dimensions();
5f91c9e8 586}
587
588//______________________________________________________________________________
3635f34f 589TVector2
590AliMpSectorSegmentation::Position() const
591{
592/// Return sector position
593
7a170a5c 594 // return GetSector()->Position();
595 return TVector2(0.,0.);
3635f34f 596}
597
598//______________________________________________________________________________
599void
600AliMpSectorSegmentation::Print(Option_t* opt) const
5f91c9e8 601{
3635f34f 602/// Print the sector
5f91c9e8 603
3635f34f 604 fkSector->Print(opt);
605}
5f91c9e8 606
607//______________________________________________________________________________
608Int_t AliMpSectorSegmentation::Zone(const AliMpPad& pad, Bool_t warning) const
609{
dee1d5f1 610/// Return the zone index of the zone containing the specified pad.
611/// This zone index is different from the zone ID,
612/// as it is unique for each pad dimensions.
613/// It is composed in this way:
614/// zoneID*10 + specific index
615/// Specific index is present only for zones containing special motifs.
5f91c9e8 616
617 if (!pad.IsValid()) {
618 if (warning) Warning("Zone(AliMpPad)", "Invalid pad");
619 return 0;
620 }
621
2294822d 622 TExMapIter it(&fPadDimensionsMap);
f79c58a5 623 Long_t key, value;
624 while ( it.Next(key, value) ) {
625 TVector2 dimensions = GetVector(value);
626 if (AliMpConstants::IsEqual(dimensions, pad.Dimensions()))
627 return (Int_t)key;
bcf37928 628 }
7c774e6d 629
630 AliError(Form("fPadDimensionsMap size is %d",fPadDimensionsMap.GetSize()));
5f91c9e8 631
632 // Should never happen
2c605e66 633 AliErrorStream()
634 << "Zone(AliMpPad pad) not found, where pad is: " << pad << endl;
5f91c9e8 635 return 0;
636}
637
638//______________________________________________________________________________
639TVector2
640AliMpSectorSegmentation::PadDimensions(Int_t zone, Bool_t warning) const
641{
dee1d5f1 642/// Return the pad dimensions for the zone with the specified zone index.
5f91c9e8 643
f79c58a5 644 Long_t value = fPadDimensionsMap.GetValue(zone);
645 if (value) return GetVector(value);
5f91c9e8 646
647 if (warning) Warning("PadDimensions(zone)", "not found");
648 return TVector2();
649}
650
3635f34f 651//______________________________________________________________________________
652TVector2 AliMpSectorSegmentation::GetMinPadDimensions() const
653{
654/// Returne the dimensions of the smallest pad.
655
656 return fkSector->GetMinPadDimensions();
657}
658
5f91c9e8 659//______________________________________________________________________________
168e9c4d 660Bool_t AliMpSectorSegmentation::CircleTest(Int_t ix, Int_t iy) const
5f91c9e8 661{
dee1d5f1 662/// Verify that all methods for retrieving pads are consistents between them.
663/// Return true if the pad with specified indices was found and verified,
664/// false otherwise.
5f91c9e8 665
168e9c4d 666 if ( ! HasPadByIndices(ix, iy) ) return false;
5f91c9e8 667
668 // Verify the indice->location->position->indice way
168e9c4d 669 AliMpPad pad1 = PadByIndices(ix, iy);
670 AliMpPad pad2 = PadByLocation(pad1.GetManuId(), pad1.GetManuChannel());
671 AliMpPad pad3 = PadByPosition(pad2.Position());
672
673 MpPair_t retIndices = pad3.GetIndices();
5f91c9e8 674
168e9c4d 675 if ( retIndices != AliMp::Pair(ix, iy) ) {
676 cout << "Pad (" << ix << ',' << iy << ") lead to inconsistency" << endl;
5f91c9e8 677 cout << "in indice->location->position->indice way..." << endl;
168e9c4d 678 cout << "starting from indices " << pad1 << endl
679 << "--> location " << pad2 << endl
680 << "--> position "
681 << '(' << pad3.Position().X() << ',' << pad3.Position().Y() << ')'
682 << endl << endl;
5f91c9e8 683 }
684
685
168e9c4d 686 // Verify the indice->position->location->indice way
687 AliMpPad pad2bis = PadByPosition(pad1.Position());
688 AliMpPad pad3bis = PadByLocation(pad2bis.GetManuId(), pad2bis.GetManuChannel());
689
690 retIndices = pad3bis.GetIndices();
691
692 if ( retIndices != AliMp::Pair(ix, iy) ) {
693 cout << "Pad (" << ix << ',' << iy << ") lead to inconsistency" << endl;
694 cout << "in indice->position->location->indice way..." << endl;
695 cout << "starting from indices " << pad1 << endl
696 << "--> position "
697 << '(' << pad2bis.Position().X() << ',' << pad2bis.Position().Y() << ')' << endl
698 << "--> location " << pad3bis
699 << endl << endl;
5f91c9e8 700 }
701
702 return true;
703}
bcf37928 704
705//______________________________________________________________________________
706void AliMpSectorSegmentation::PrintZones() const
707{
dee1d5f1 708/// Print all zones and pads dimensions from the map.
bcf37928 709
710 cout << "Zones: " << endl;
711
2294822d 712 TExMapIter it(&fPadDimensionsMap);
bcf37928 713 Long_t key, value;
714 while ( it.Next(key, value) ) {
715 //cout << "Iterating over: " << key << ", " << value << endl;
716 TVector2 dimensions = GetVector(value);
717
718 cout << " zone: " << setw(4) << key;
719 cout << " pad dimensions: ( "
720 << dimensions.X() << ", " << dimensions.Y() << ")" << endl;
721 }
bcf37928 722}
3635f34f 723