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(),
47 fPadBuffer = new AliMpPad(AliMpPad::Invalid());
49 FillPadDimensionsMap();
52 //______________________________________________________________________________
53 AliMpSectorSegmentation::AliMpSectorSegmentation()
54 : AliMpVSegmentation(),
62 //_____________________________________________________________________________
63 AliMpSectorSegmentation::AliMpSectorSegmentation(
64 const AliMpSectorSegmentation& right)
65 : AliMpVSegmentation(right) {
67 Fatal("AliMpSectorSegmentation", "Copy constructor not provided.");
70 //______________________________________________________________________________
71 AliMpSectorSegmentation::~AliMpSectorSegmentation() {
80 //_____________________________________________________________________________
81 AliMpSectorSegmentation&
82 AliMpSectorSegmentation::operator=(const AliMpSectorSegmentation& right)
84 // check assignement to self
85 if (this == &right) return *this;
87 Fatal("operator =", "Assignement operator not provided.");
97 //______________________________________________________________________________
98 Long_t AliMpSectorSegmentation::GetIndex(const TVector2& vector2) const
100 // Converts the two vector to long.
103 return Long_t(TMath::Floor((vector2.X()*fgkS1 + vector2.Y())*fgkS2));
106 //______________________________________________________________________________
107 TVector2 AliMpSectorSegmentation::GetVector(Long_t index) const
109 // Converts the long index to twovector.
112 return TVector2( TMath::Floor(index/fgkS1)/fgkS2,
113 (index - TMath::Floor(index/fgkS1)*fgkS1)/fgkS2 );
117 //______________________________________________________________________________
118 void AliMpSectorSegmentation::FillPadDimensionsMap()
120 // Fills the maps between zone ids and pad dimensions.
123 for (Int_t i=0; i<fkSector->GetNofZones(); i++) {
124 AliMpZone* zone = fkSector->GetZone(i+1);
125 Int_t zoneID = zone->GetID();
127 if (!AliMpConstants::IsEqual(zone->GetPadDimensions(), TVector2())) {
131 fPadDimensionsMap[zoneID*10] = zone->GetPadDimensions();
134 fPadDimensionsMap.Add((Long_t)(zoneID*10),
135 GetIndex(zone->GetPadDimensions()));
141 for (Int_t j=0; j<zone->GetNofSubZones(); j++) {
142 AliMpSubZone* subZone = zone->GetSubZone(j);
143 AliMpVMotif* motif = subZone->GetMotif();
145 for (Int_t k=0; k<motif->GetNofPadDimensions(); k++) {
146 Int_t index = zoneID*10 + subIndex++;
148 fPadDimensionsMap[index] = motif->GetPadDimensions(k);
151 fPadDimensionsMap.Add((Long_t)(index),
152 GetIndex(motif->GetPadDimensions(k)));
160 //______________________________________________________________________________
162 AliMpSectorSegmentation::FindMotifPosition(const AliMpIntPair& indices) const
164 // Find the motif position which contains the given pad indices
165 // return 0 if not found
168 switch (fkSector->GetDirection()) {
170 // Case where all the pads have the same size along X direction
172 for (Int_t irow=0; irow<fkSector->GetNofRows(); ++irow) {
173 AliMpRow* row = fkSector->GetRow(irow);
174 if (row->GetLowIndicesLimit().GetFirst()<=indices.GetFirst() &&
175 row->GetHighIndicesLimit().GetFirst()>=indices.GetFirst()) {
177 for (Int_t iseg=0;iseg<row->GetNofRowSegments();++iseg){
178 AliMpVRowSegment* seg = row->GetRowSegment(iseg);
179 if (seg->GetLowIndicesLimit().GetFirst()<=indices.GetFirst() &&
180 seg->GetHighIndicesLimit().GetFirst()>=indices.GetFirst()) {
182 AliMpMotifPosition* motifPos;
183 for (Int_t imot=0;imot<seg->GetNofMotifs();++imot) {
185 = fkSector->GetMotifMap()
186 ->FindMotifPosition(seg->GetMotifPositionId(imot));
187 if (motifPos && motifPos->HasPad(indices)) return motifPos;
196 ////////////////////////////////////////////////////////////////////////////////
198 // Case where all the pads have the same size along Y direction
199 // look for the row which contains the indices
202 for (irow=0; irow<fkSector->GetNofRows(); ++irow) {
203 row = fkSector->GetRow(irow);
204 AliMpVRowSegment* lastSeg = row->GetRowSegment(row->GetNofRowSegments()-1);
205 if (lastSeg->GetLowIndicesLimit().GetSecond()<=indices.GetSecond() &&
206 lastSeg->GetHighIndicesLimit().GetSecond()>=indices.GetSecond()) break;
207 // NOTE : We use the last row segment in order to ensure that
208 // we are not on a special motif
210 if (irow==fkSector->GetNofRows()) return 0;
211 // look for the row segment, in the found row, which contains the indices
212 AliMpVRowSegment* seg=0;
214 for (iseg=0;iseg<row->GetNofRowSegments();++iseg){
215 seg = row->GetRowSegment(iseg);
216 if (seg->HasIndices(indices)) break;
218 if (iseg==row->GetNofRowSegments()) return 0;
220 // look for the motif position which contains the indices
221 AliMpMotifPosition* motifPos=0;
223 for (imot=0;imot<seg->GetNofMotifs();++imot) {
225 = fkSector->GetMotifMap()
226 ->FindMotifPosition(seg->GetMotifPositionId(imot));
227 if (motifPos && motifPos->HasPad(indices)) break;
229 if (imot==seg->GetNofMotifs()) return 0;
237 //______________________________________________________________________________
239 AliMpSectorSegmentation::PadByXDirection(const TVector2& startPosition,
242 // Find the first valid pad from starting position in the
243 // direction of pad lines up to distance dx.
246 // Define step limits
247 Double_t stepX = fkSector->GetMinPadDimensions().X();
249 // Search in X direction
251 TVector2 position(startPosition);
253 pad = PadByPosition(position, false);
254 position += TVector2(stepX, 0.);
256 while ( !pad.IsValid() && position.X() < maxX );
258 // Invalidate pad if it is outside limits
259 if ((pad.Position().X() - pad.Dimensions().X()) > maxX)
260 pad = AliMpPad::Invalid();
265 //______________________________________________________________________________
267 AliMpSectorSegmentation::PadByYDirection(const TVector2& startPosition,
270 // Find the first valid pad from starting position in the
271 // direction of pad columns up to distance dx.
274 // Define step limits
275 Double_t stepY = fkSector->GetMinPadDimensions().Y();
277 // Search in Y direction
279 TVector2 position(startPosition);
281 pad = PadByPosition(position, false);
282 position += TVector2(0., stepY);
284 while ( !pad.IsValid() && position.Y() < maxY );
286 // Invalidate pad if it is outside limits
287 if ((pad.Position().Y() - pad.Dimensions().Y()) > maxY)
288 pad = AliMpPad::Invalid();
293 //______________________________________________________________________________
294 AliMpVPadIterator* AliMpSectorSegmentation::CreateIterator() const
296 // The inherited method cannot be used
298 Fatal("CreateIterator", "Center pad has to be specified.");
307 //______________________________________________________________________________
309 AliMpSectorSegmentation::CreateIterator(const AliMpArea& area) const
311 // Creates the are iterator.
312 // (The inherited method cannot be used)
315 switch (fkSector->GetDirection()) {
317 case kX: return new AliMpSectorAreaVPadIterator(this, area);
319 case kY: return new AliMpSectorAreaHPadIterator(this, area);
323 Fatal("CreateIterator", "Incomplete switch on Sector direction");
327 //______________________________________________________________________________
329 AliMpSectorSegmentation::CreateIterator(const AliMpPad& centerPad,
330 Bool_t includeCenter) const
332 // Creates the neighbours pad iterator.
333 // (The inherited method cannot be used)
335 return new AliMpNeighboursPadIterator(this, centerPad, includeCenter);
338 //______________________________________________________________________________
340 AliMpSectorSegmentation::PadByLocation(const AliMpIntPair& location,
341 Bool_t warning) const
343 // Find the pad which corresponds to the given location
345 if ((*fPadBuffer).GetLocation()==location) return (*fPadBuffer);
347 AliMpMotifPosition* motifPos =
348 fkSector->GetMotifMap()->FindMotifPosition(location.GetFirst());
350 if (warning) Warning("PadByLocation","The pad motif position ID doesn't exists");
351 return AliMpPad::Invalid();
354 AliMpVMotif* motif = motifPos->GetMotif();
355 AliMpIntPair localIndices =
356 motif->GetMotifType()->FindLocalIndicesByGassiNum(location.GetSecond());
357 if (! localIndices.IsValid()) {
358 if (warning) Warning("PadByLocation","The pad number doesn't exists");
359 return AliMpPad::Invalid();
361 TVector2 delta = motif->PadPositionLocal(localIndices);
362 return (*fPadBuffer) = AliMpPad(location,
363 motifPos->GlobalIndices(localIndices),
364 motifPos->Position()+delta,
365 motif->GetPadDimensions(localIndices));
368 //______________________________________________________________________________
370 AliMpSectorSegmentation::PadByIndices(const AliMpIntPair& indices,
371 Bool_t warning ) const
373 // Find the pad which corresponds to the given indices
375 if ((*fPadBuffer).GetIndices()==indices) return (*fPadBuffer);
377 AliMpMotifPosition* motifPos = FindMotifPosition(indices);
379 if (warning) Warning("PadByIndices","Pad indices not contained in any motif!");
380 return AliMpPad::Invalid();
383 // retrieve the local indices in the found motif
384 AliMpVMotif* motif = motifPos->GetMotif();
385 AliMpIntPair localIndices = indices - motifPos->GetLowIndicesLimit();
387 AliMpConnection* connection=
388 motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
391 if (warning) Warning("PadByIndices","No connection with the given indices!");
392 return AliMpPad::Invalid();
395 TVector2 localPos = motif->PadPositionLocal(localIndices);
398 = AliMpPad(AliMpIntPair(motifPos->GetID(),connection->GetGassiNum()),
400 motifPos->Position()+localPos,
401 motif->GetPadDimensions(localIndices));
404 //______________________________________________________________________________
406 AliMpSectorSegmentation::PadByPosition(const TVector2& position,
407 Bool_t warning) const
409 // Find the pad which corresponds to the given position
411 if ((*fPadBuffer).Position().X()==position.X() &&
412 (*fPadBuffer).Position().Y()==position.Y()) return (*fPadBuffer);
414 Int_t motifPosID = fkSector->FindMotifPositionId(position);
415 AliMpMotifPosition* motifPos
416 = fkSector->GetMotifMap()
417 ->FindMotifPosition(motifPosID);
420 if (warning) Warning("PadByPosition","Position outside limits");
421 return AliMpPad::Invalid();
424 AliMpVMotif* motif = motifPos->GetMotif();
425 AliMpIntPair localIndices
426 = motif->PadIndicesLocal(position-motifPos->Position());
428 AliMpConnection* connect =
429 motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
432 if (warning) Warning("PadByPosition","Position outside motif limits");
433 return AliMpPad::Invalid();
437 = AliMpPad(AliMpIntPair(motifPosID,connect->GetGassiNum()),
438 motifPos->GlobalIndices(localIndices),
439 motifPos->Position()+motif->PadPositionLocal(localIndices),
440 motif->GetPadDimensions(localIndices));
444 //______________________________________________________________________________
446 AliMpSectorSegmentation::PadByDirection(const TVector2& startPosition,
447 Double_t distance) const
449 // Find the first valid pad from starting position in the
450 // direction of pad lines/columns up to the specified distance.
451 // Pad lines are the lines of pads in the sector with constant pad y size,
452 // pad columns are the columns of pads in the sector with constant pad x size.
455 switch (fkSector->GetDirection()) {
457 case kX: return PadByYDirection(startPosition, distance);
459 case kY: return PadByXDirection(startPosition, distance);
463 Fatal("PadByDirection", "Incomplete switch on Sector direction");
464 return AliMpPad::Invalid();
467 //______________________________________________________________________________
468 Bool_t AliMpSectorSegmentation::HasPad(const AliMpIntPair& indices) const
470 // Does the pad specified by <indices> exist ?
473 return PadByIndices(indices,kFALSE) != AliMpPad::Invalid();
476 //______________________________________________________________________________
477 Bool_t AliMpSectorSegmentation::HasMotifPosition(Int_t motifPositionID) const
479 // Does the motif position specified by motifPositionID exist ?
482 return (fkSector->GetMotifMap()->FindMotifPosition(motifPositionID) != 0);
485 //______________________________________________________________________________
486 TVector2 AliMpSectorSegmentation::GetMinPadDimensions() const
488 // Returnes the dimensions of the smallest pad.
491 return fkSector->GetMinPadDimensions();
494 //______________________________________________________________________________
495 Int_t AliMpSectorSegmentation::Zone(const AliMpPad& pad, Bool_t warning) const
497 // Returns the zone index of the zone containing the specified pad.
498 // This zone index is different from the zone ID,
499 // as it is unique for each pad dimensions.
500 // It is composed in this way:
501 // zoneID*10 + specific index
502 // Specific index is present only for zones containing special motifs.
505 if (!pad.IsValid()) {
506 if (warning) Warning("Zone(AliMpPad)", "Invalid pad");
511 PadDimensionsMapCIterator it;
512 for (it = fPadDimensionsMap.begin(); it != fPadDimensionsMap.end(); ++it) {
513 if (AliMpConstants::IsEqual(it->second, pad.Dimensions()))
519 PadDimensionsMapCIterator it(&fPadDimensionsMap);
521 while ( it.Next(key, value) ) {
522 TVector2 dimensions = GetVector(value);
523 if (AliMpConstants::IsEqual(dimensions, pad.Dimensions()))
528 // Should never happen
529 Error("Zone(AliMpPad)", "not found");
534 //______________________________________________________________________________
536 AliMpSectorSegmentation::PadDimensions(Int_t zone, Bool_t warning) const
538 // Returns the pad dimensions for the zone with the specified zone index.
542 PadDimensionsMapCIterator it = fPadDimensionsMap.find(zone);
543 if (it != fPadDimensionsMap.end()) return it->second;
547 Long_t value = fPadDimensionsMap.GetValue(zone);
548 if (value) return GetVector(value);
551 if (warning) Warning("PadDimensions(zone)", "not found");
555 //______________________________________________________________________________
556 Bool_t AliMpSectorSegmentation::CircleTest(const AliMpIntPair& indices) const
558 // Verifies that all methods for retrieving pads are consistents between them.
559 // Returns true if the pad with specified indices was found and verified,
563 if (!HasPad(indices)) return false;
565 // Verify the indice->location->position->indice way
566 AliMpIntPair location = PadByIndices(indices).GetLocation();
567 TVector2 position = PadByLocation(location).Position();
568 AliMpIntPair retIndices = PadByPosition(position).GetIndices();
570 if (retIndices != indices) {
571 cout << "Pad " << indices << " lead to inconsistency" << endl;
572 cout << "in indice->location->position->indice way..." << endl;
573 cout << "starting from " << indices << "-->" << location << "-->"
574 << '(' << position.X() << ',' << position.Y() << ')'
575 << " and retIndices: " << retIndices << endl;
579 // Verify the indice->position->location->indice way
580 position = PadByIndices(indices).Position();
581 location = PadByPosition(position).GetLocation();
582 retIndices = PadByLocation(location).GetIndices();
584 if (retIndices != indices) {
585 cout << "Pad " << indices << " lead to inconsistency" << endl;
586 cout << "in indice->position->location->indice way..." <<endl;
587 cout << "starting from " << indices
588 << " and retIndices: " << retIndices << endl;
594 //______________________________________________________________________________
595 void AliMpSectorSegmentation::PrintZones() const
597 // Prints all zones and pads dimensions from the map.
600 cout << "Zones: " << endl;
603 PadDimensionsMapCIterator it;
604 for (it = fPadDimensionsMap.begin(); it != fPadDimensionsMap.end(); ++it) {
605 cout << " zone: " << setw(4) << it->first;
606 cout << " pad dimensions: ( "
607 << it->second.X() << ", " << it->second.Y() << ")" << endl;
612 PadDimensionsMapCIterator it(&fPadDimensionsMap);
614 while ( it.Next(key, value) ) {
615 //cout << "Iterating over: " << key << ", " << value << endl;
616 TVector2 dimensions = GetVector(value);
618 cout << " zone: " << setw(4) << key;
619 cout << " pad dimensions: ( "
620 << dimensions.X() << ", " << dimensions.Y() << ")" << endl;