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