4 // Class AliMpSectorSegmentation
5 // -----------------------------
6 // Class describing the segmentation of the sector.
7 // Provides methods related to pads:
8 // conversion between pad indices, pad location, pad position;
9 // finding pad neighbour.
11 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
13 #include <Riostream.h>
17 #include "AliMpSectorSegmentation.h"
18 #include "AliMpSector.h"
19 #include "AliMpZone.h"
20 #include "AliMpSubZone.h"
22 #include "AliMpVRowSegment.h"
23 #include "AliMpMotifMap.h"
24 #include "AliMpVMotif.h"
25 #include "AliMpMotifPosition.h"
26 #include "AliMpConnection.h"
27 #include "AliMpNeighboursPadIterator.h"
28 #include "AliMpSectorAreaHPadIterator.h"
29 #include "AliMpSectorAreaVPadIterator.h"
30 #include "AliMpIntPair.h"
31 #include "AliMpArea.h"
32 #include "AliMpConstants.h"
34 ClassImp(AliMpSectorSegmentation)
37 const Double_t AliMpSectorSegmentation::fgkS1 = 10000.;
38 const Double_t AliMpSectorSegmentation::fgkS2 = 100.;
41 //______________________________________________________________________________
42 AliMpSectorSegmentation::AliMpSectorSegmentation(const AliMpSector* sector)
43 : AliMpVSegmentation(),
49 fPadBuffer = new AliMpPad(AliMpPad::Invalid());
51 FillPadDimensionsMap();
54 //______________________________________________________________________________
55 AliMpSectorSegmentation::AliMpSectorSegmentation()
56 : AliMpVSegmentation(),
66 //_____________________________________________________________________________
67 AliMpSectorSegmentation::AliMpSectorSegmentation(
68 const AliMpSectorSegmentation& right)
69 : AliMpVSegmentation(right) {
71 Fatal("AliMpSectorSegmentation", "Copy constructor not provided.");
74 //______________________________________________________________________________
75 AliMpSectorSegmentation::~AliMpSectorSegmentation() {
84 //_____________________________________________________________________________
85 AliMpSectorSegmentation&
86 AliMpSectorSegmentation::operator=(const AliMpSectorSegmentation& right)
88 // check assignement to self
89 if (this == &right) return *this;
91 Fatal("operator =", "Assignement operator not provided.");
101 //______________________________________________________________________________
102 Long_t AliMpSectorSegmentation::GetIndex(const TVector2& vector2) const
104 // Converts the two vector to long.
107 return Long_t(TMath::Floor((vector2.X()*fgkS1 + vector2.Y())*fgkS2));
110 //______________________________________________________________________________
111 TVector2 AliMpSectorSegmentation::GetVector(Long_t index) const
113 // Converts the long index to twovector.
116 return TVector2( TMath::Floor(index/fgkS1)/fgkS2,
117 (index - TMath::Floor(index/fgkS1)*fgkS1)/fgkS2 );
121 //______________________________________________________________________________
122 void AliMpSectorSegmentation::FillPadDimensionsMap()
124 // Fills the maps between zone ids and pad dimensions.
127 for (Int_t i=0; i<fkSector->GetNofZones(); i++) {
128 AliMpZone* zone = fkSector->GetZone(i+1);
129 Int_t zoneID = zone->GetID();
131 if (!AliMpConstants::IsEqual(zone->GetPadDimensions(), TVector2())) {
135 fPadDimensionsMap[zoneID*10] = zone->GetPadDimensions();
138 fPadDimensionsMap.Add((Long_t)(zoneID*10),
139 GetIndex(zone->GetPadDimensions()));
145 for (Int_t j=0; j<zone->GetNofSubZones(); j++) {
146 AliMpSubZone* subZone = zone->GetSubZone(j);
147 AliMpVMotif* motif = subZone->GetMotif();
149 for (Int_t k=0; k<motif->GetNofPadDimensions(); k++) {
150 Int_t index = zoneID*10 + subIndex++;
152 fPadDimensionsMap[index] = motif->GetPadDimensions(k);
155 fPadDimensionsMap.Add((Long_t)(index),
156 GetIndex(motif->GetPadDimensions(k)));
164 //______________________________________________________________________________
166 AliMpSectorSegmentation::FindMotifPosition(const AliMpIntPair& indices) const
168 // Find the motif position which contains the given pad indices
169 // return 0 if not found
172 switch (fkSector->GetDirection()) {
174 // Case where all the pads have the same size along X direction
176 for (Int_t irow=0; irow<fkSector->GetNofRows(); ++irow) {
177 AliMpRow* row = fkSector->GetRow(irow);
178 if (row->GetLowIndicesLimit().GetFirst()<=indices.GetFirst() &&
179 row->GetHighIndicesLimit().GetFirst()>=indices.GetFirst()) {
181 for (Int_t iseg=0;iseg<row->GetNofRowSegments();++iseg){
182 AliMpVRowSegment* seg = row->GetRowSegment(iseg);
183 if (seg->GetLowIndicesLimit().GetFirst()<=indices.GetFirst() &&
184 seg->GetHighIndicesLimit().GetFirst()>=indices.GetFirst()) {
186 AliMpMotifPosition* motifPos;
187 for (Int_t imot=0;imot<seg->GetNofMotifs();++imot) {
189 = fkSector->GetMotifMap()
190 ->FindMotifPosition(seg->GetMotifPositionId(imot));
191 if (motifPos && motifPos->HasPad(indices)) return motifPos;
199 ////////////////////////////////////////////////////////////////////////////////
201 // Case where all the pads have the same size along Y direction
202 // look for the row which contains the indices
205 for (irow=0; irow<fkSector->GetNofRows(); ++irow) {
206 row = fkSector->GetRow(irow);
207 AliMpVRowSegment* lastSeg = row->GetRowSegment(row->GetNofRowSegments()-1);
208 if (lastSeg->GetLowIndicesLimit().GetSecond()<=indices.GetSecond() &&
209 lastSeg->GetHighIndicesLimit().GetSecond()>=indices.GetSecond()) break;
210 // NOTE : We use the last row segment in order to ensure that
211 // we are not on a special motif
213 if (irow==fkSector->GetNofRows()) return 0;
214 // look for the row segment, in the found row, which contains the indices
215 AliMpVRowSegment* seg=0;
217 for (iseg=0;iseg<row->GetNofRowSegments();++iseg){
218 seg = row->GetRowSegment(iseg);
219 if (seg->HasIndices(indices)) break;
221 if (iseg==row->GetNofRowSegments()) return 0;
223 // look for the motif position which contains the indices
224 AliMpMotifPosition* motifPos=0;
226 for (imot=0;imot<seg->GetNofMotifs();++imot) {
228 = fkSector->GetMotifMap()
229 ->FindMotifPosition(seg->GetMotifPositionId(imot));
230 if (motifPos && motifPos->HasPad(indices)) break;
232 if (imot==seg->GetNofMotifs()) return 0;
240 //______________________________________________________________________________
242 AliMpSectorSegmentation::PadByXDirection(const TVector2& startPosition,
245 // Find the first valid pad from starting position in the
246 // direction of pad lines up to distance dx.
249 // Define step limits
250 Double_t stepX = fkSector->GetMinPadDimensions().X();
252 // Search in X direction
254 TVector2 position(startPosition);
256 pad = PadByPosition(position, false);
257 position += TVector2(stepX, 0.);
259 while ( !pad.IsValid() && position.X() < maxX );
261 // Invalidate pad if it is outside limits
262 if ((pad.Position().X() - pad.Dimensions().X()) > maxX)
263 pad = AliMpPad::Invalid();
268 //______________________________________________________________________________
270 AliMpSectorSegmentation::PadByYDirection(const TVector2& startPosition,
273 // Find the first valid pad from starting position in the
274 // direction of pad columns up to distance dx.
277 // Define step limits
278 Double_t stepY = fkSector->GetMinPadDimensions().Y();
280 // Search in Y direction
282 TVector2 position(startPosition);
284 pad = PadByPosition(position, false);
285 position += TVector2(0., stepY);
287 while ( !pad.IsValid() && position.Y() < maxY );
289 // Invalidate pad if it is outside limits
290 if ((pad.Position().Y() - pad.Dimensions().Y()) > maxY)
291 pad = AliMpPad::Invalid();
296 //______________________________________________________________________________
297 AliMpVPadIterator* AliMpSectorSegmentation::CreateIterator() const
299 // The inherited method cannot be used
301 Fatal("CreateIterator", "Center pad has to be specified.");
310 //______________________________________________________________________________
312 AliMpSectorSegmentation::CreateIterator(const AliMpArea& area) const
314 // Creates the are iterator.
315 // (The inherited method cannot be used)
318 switch (fkSector->GetDirection()) {
320 case kX: return new AliMpSectorAreaVPadIterator(this, area);
322 case kY: return new AliMpSectorAreaHPadIterator(this, area);
326 Fatal("CreateIterator", "Incomplete switch on Sector direction");
330 //______________________________________________________________________________
332 AliMpSectorSegmentation::CreateIterator(const AliMpPad& centerPad,
333 Bool_t includeCenter) const
335 // Creates the neighbours pad iterator.
336 // (The inherited method cannot be used)
338 return new AliMpNeighboursPadIterator(this, centerPad, includeCenter);
341 //______________________________________________________________________________
343 AliMpSectorSegmentation::PadByLocation(const AliMpIntPair& location,
344 Bool_t warning) const
346 // Find the pad which corresponds to the given location
348 if ((*fPadBuffer).GetLocation()==location) return (*fPadBuffer);
350 AliMpMotifPosition* motifPos =
351 fkSector->GetMotifMap()->FindMotifPosition(location.GetFirst());
353 if (warning) Warning("PadByLocation","The pad motif position ID doesn't exists");
354 return AliMpPad::Invalid();
357 AliMpVMotif* motif = motifPos->GetMotif();
358 AliMpIntPair localIndices =
359 motif->GetMotifType()->FindLocalIndicesByGassiNum(location.GetSecond());
360 if (! localIndices.IsValid()) {
361 if (warning) Warning("PadByLocation","The pad number doesn't exists");
362 return AliMpPad::Invalid();
364 TVector2 delta = motif->PadPositionLocal(localIndices);
365 return (*fPadBuffer) = AliMpPad(location,
366 motifPos->GlobalIndices(localIndices),
367 motifPos->Position()+delta,
368 motif->GetPadDimensions(localIndices));
371 //______________________________________________________________________________
373 AliMpSectorSegmentation::PadByIndices(const AliMpIntPair& indices,
374 Bool_t warning ) const
376 // Find the pad which corresponds to the given indices
378 if ((*fPadBuffer).GetIndices()==indices) return (*fPadBuffer);
380 AliMpMotifPosition* motifPos = FindMotifPosition(indices);
383 cout << "indices " << indices << endl;
384 Warning("PadByIndices","Pad indices not contained in any motif!");
386 return AliMpPad::Invalid();
389 // retrieve the local indices in the found motif
390 AliMpVMotif* motif = motifPos->GetMotif();
391 AliMpIntPair localIndices = indices - motifPos->GetLowIndicesLimit();
393 AliMpConnection* connection=
394 motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
397 if (warning) Warning("PadByIndices","No connection with the given indices!");
398 return AliMpPad::Invalid();
401 TVector2 localPos = motif->PadPositionLocal(localIndices);
404 = AliMpPad(AliMpIntPair(motifPos->GetID(),connection->GetGassiNum()),
406 motifPos->Position()+localPos,
407 motif->GetPadDimensions(localIndices));
410 //______________________________________________________________________________
412 AliMpSectorSegmentation::PadByPosition(const TVector2& position,
413 Bool_t warning) const
415 // Find the pad which corresponds to the given position
417 if ((*fPadBuffer).Position().X()==position.X() &&
418 (*fPadBuffer).Position().Y()==position.Y()) return (*fPadBuffer);
420 Int_t motifPosID = fkSector->FindMotifPositionId(position);
421 AliMpMotifPosition* motifPos
422 = fkSector->GetMotifMap()
423 ->FindMotifPosition(motifPosID);
426 if (warning) Warning("PadByPosition","Position outside limits");
427 return AliMpPad::Invalid();
430 AliMpVMotif* motif = motifPos->GetMotif();
431 AliMpIntPair localIndices
432 = motif->PadIndicesLocal(position-motifPos->Position());
434 AliMpConnection* connect =
435 motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
438 if (warning) Warning("PadByPosition","Position outside motif limits");
439 return AliMpPad::Invalid();
443 = AliMpPad(AliMpIntPair(motifPosID,connect->GetGassiNum()),
444 motifPos->GlobalIndices(localIndices),
445 motifPos->Position()+motif->PadPositionLocal(localIndices),
446 motif->GetPadDimensions(localIndices));
450 //______________________________________________________________________________
452 AliMpSectorSegmentation::PadByDirection(const TVector2& startPosition,
453 Double_t distance) const
455 // Find the first valid pad from starting position in the
456 // direction of pad lines/columns up to the specified distance.
457 // Pad lines are the lines of pads in the sector with constant pad y size,
458 // pad columns are the columns of pads in the sector with constant pad x size.
461 switch (fkSector->GetDirection()) {
463 case kX: return PadByYDirection(startPosition, distance);
465 case kY: return PadByXDirection(startPosition, distance);
469 Fatal("PadByDirection", "Incomplete switch on Sector direction");
470 return AliMpPad::Invalid();
473 //______________________________________________________________________________
474 Int_t AliMpSectorSegmentation::MaxPadIndexX()
476 // Return maximum pad index in x
478 if (fMaxIndexInX) return fMaxIndexInX;
480 for (Int_t i=0; i<fkSector->GetNofRows(); i++) {
481 Int_t ixh = fkSector->GetRow(i)->GetHighIndicesLimit().GetFirst();
482 if ( ixh > fMaxIndexInX ) fMaxIndexInX = ixh;
487 //______________________________________________________________________________
488 Int_t AliMpSectorSegmentation::MaxPadIndexY()
490 // Return maximum pad index in y
492 if (fMaxIndexInY) return fMaxIndexInY;
494 for (Int_t i=0; i<fkSector->GetNofRows(); i++) {
495 Int_t iyh = fkSector->GetRow(i)->GetHighIndicesLimit().GetSecond();
496 if ( iyh > fMaxIndexInY ) fMaxIndexInY = iyh;
501 //______________________________________________________________________________
502 Bool_t AliMpSectorSegmentation::HasPad(const AliMpIntPair& indices) const
504 // Does the pad specified by <indices> exist ?
507 return PadByIndices(indices,kFALSE) != AliMpPad::Invalid();
510 //______________________________________________________________________________
511 Bool_t AliMpSectorSegmentation::HasMotifPosition(Int_t motifPositionID) const
513 // Does the motif position specified by motifPositionID exist ?
516 return (fkSector->GetMotifMap()->FindMotifPosition(motifPositionID) != 0);
519 //______________________________________________________________________________
520 TVector2 AliMpSectorSegmentation::GetMinPadDimensions() const
522 // Returnes the dimensions of the smallest pad.
525 return fkSector->GetMinPadDimensions();
528 //______________________________________________________________________________
529 Int_t AliMpSectorSegmentation::Zone(const AliMpPad& pad, Bool_t warning) const
531 // Returns the zone index of the zone containing the specified pad.
532 // This zone index is different from the zone ID,
533 // as it is unique for each pad dimensions.
534 // It is composed in this way:
535 // zoneID*10 + specific index
536 // Specific index is present only for zones containing special motifs.
539 if (!pad.IsValid()) {
540 if (warning) Warning("Zone(AliMpPad)", "Invalid pad");
545 PadDimensionsMapCIterator it;
546 for (it = fPadDimensionsMap.begin(); it != fPadDimensionsMap.end(); ++it) {
547 if (AliMpConstants::IsEqual(it->second, pad.Dimensions()))
553 PadDimensionsMapCIterator it(&fPadDimensionsMap);
555 while ( it.Next(key, value) ) {
556 TVector2 dimensions = GetVector(value);
557 if (AliMpConstants::IsEqual(dimensions, pad.Dimensions()))
562 // Should never happen
563 Error("Zone(AliMpPad)", "not found");
568 //______________________________________________________________________________
570 AliMpSectorSegmentation::PadDimensions(Int_t zone, Bool_t warning) const
572 // Returns the pad dimensions for the zone with the specified zone index.
576 PadDimensionsMapCIterator it = fPadDimensionsMap.find(zone);
577 if (it != fPadDimensionsMap.end()) return it->second;
581 Long_t value = fPadDimensionsMap.GetValue(zone);
582 if (value) return GetVector(value);
585 if (warning) Warning("PadDimensions(zone)", "not found");
589 //______________________________________________________________________________
590 Bool_t AliMpSectorSegmentation::CircleTest(const AliMpIntPair& indices) const
592 // Verifies that all methods for retrieving pads are consistents between them.
593 // Returns true if the pad with specified indices was found and verified,
597 if (!HasPad(indices)) return false;
599 // Verify the indice->location->position->indice way
600 AliMpIntPair location = PadByIndices(indices).GetLocation();
601 TVector2 position = PadByLocation(location).Position();
602 AliMpIntPair retIndices = PadByPosition(position).GetIndices();
604 if (retIndices != indices) {
605 cout << "Pad " << indices << " lead to inconsistency" << endl;
606 cout << "in indice->location->position->indice way..." << endl;
607 cout << "starting from " << indices << "-->" << location << "-->"
608 << '(' << position.X() << ',' << position.Y() << ')'
609 << " and retIndices: " << retIndices << endl;
613 // Verify the indice->position->location->indice way
614 position = PadByIndices(indices).Position();
615 location = PadByPosition(position).GetLocation();
616 retIndices = PadByLocation(location).GetIndices();
618 if (retIndices != indices) {
619 cout << "Pad " << indices << " lead to inconsistency" << endl;
620 cout << "in indice->position->location->indice way..." <<endl;
621 cout << "starting from " << indices
622 << " and retIndices: " << retIndices << endl;
628 //______________________________________________________________________________
629 void AliMpSectorSegmentation::PrintZones() const
631 // Prints all zones and pads dimensions from the map.
634 cout << "Zones: " << endl;
637 PadDimensionsMapCIterator it;
638 for (it = fPadDimensionsMap.begin(); it != fPadDimensionsMap.end(); ++it) {
639 cout << " zone: " << setw(4) << it->first;
640 cout << " pad dimensions: ( "
641 << it->second.X() << ", " << it->second.Y() << ")" << endl;
646 PadDimensionsMapCIterator it(&fPadDimensionsMap);
648 while ( it.Next(key, value) ) {
649 //cout << "Iterating over: " << key << ", " << value << endl;
650 TVector2 dimensions = GetVector(value);
652 cout << " zone: " << setw(4) << key;
653 cout << " pad dimensions: ( "
654 << dimensions.X() << ", " << dimensions.Y() << ")" << endl;