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>
16 #include "AliMpSectorSegmentation.h"
17 #include "AliMpSector.h"
18 #include "AliMpZone.h"
19 #include "AliMpSubZone.h"
21 #include "AliMpVRowSegment.h"
22 #include "AliMpMotifMap.h"
23 #include "AliMpVMotif.h"
24 #include "AliMpMotifPosition.h"
25 #include "AliMpConnection.h"
26 #include "AliMpNeighboursPadIterator.h"
27 #include "AliMpSectorAreaHPadIterator.h"
28 #include "AliMpSectorAreaVPadIterator.h"
29 #include "AliMpIntPair.h"
30 #include "AliMpArea.h"
31 #include "AliMpConstants.h"
33 ClassImp(AliMpSectorSegmentation)
36 const Double_t AliMpSectorSegmentation::fgkSeparator = 10000.;
39 //______________________________________________________________________________
40 AliMpSectorSegmentation::AliMpSectorSegmentation(const AliMpSector* sector)
41 : AliMpVSegmentation(),
45 fPadBuffer = new AliMpPad(AliMpPad::Invalid());
47 FillPadDimensionsMap();
50 //______________________________________________________________________________
51 AliMpSectorSegmentation::AliMpSectorSegmentation()
52 : AliMpVSegmentation(),
60 //______________________________________________________________________________
61 AliMpSectorSegmentation::~AliMpSectorSegmentation() {
71 //______________________________________________________________________________
72 Long_t AliMpSectorSegmentation::GetIndex(const TVector2& vector2) const
74 // Converts the twovector to long.
77 if (vector2.X() >= fgkSeparator || vector2.Y() >= fgkSeparator)
78 Fatal("GetIndex", "Index out of limit.");
80 return Long_t(vector2.X()*fgkSeparator + vector2.Y() + 1.);
83 //______________________________________________________________________________
84 TVector2 AliMpSectorSegmentation::GetVector(Long_t index) const
86 // Converts the long index to twovector.
89 return TVector2(TMath::Floor((index-1.)/fgkSeparator),
90 (index-1.) - TMath::Floor((index-1.)/fgkSeparator)*fgkSeparator);
94 //______________________________________________________________________________
95 void AliMpSectorSegmentation::FillPadDimensionsMap()
97 // Fills the maps between zone ids and pad dimensions.
100 for (Int_t i=0; i<fkSector->GetNofZones(); i++) {
101 AliMpZone* zone = fkSector->GetZone(i+1);
102 Int_t zoneID = zone->GetID();
104 if (!AliMpConstants::IsEqual(zone->GetPadDimensions(), TVector2())) {
108 fPadDimensionsMap[zoneID*10] = zone->GetPadDimensions();
111 fPadDimensionsMap.Add((Long_t)(zoneID*10),
112 GetIndex(zone->GetPadDimensions()));
118 for (Int_t j=0; j<zone->GetNofSubZones(); j++) {
119 AliMpSubZone* subZone = zone->GetSubZone(j);
120 AliMpVMotif* motif = subZone->GetMotif();
122 for (Int_t k=0; k<motif->GetNofPadDimensions(); k++) {
123 Int_t index = zoneID*10 + subIndex++;
125 fPadDimensionsMap[index] = motif->GetPadDimensions(k);
128 fPadDimensionsMap.Add((Long_t)(index),
129 GetIndex(motif->GetPadDimensions(k)));
137 //______________________________________________________________________________
139 AliMpSectorSegmentation::FindMotifPosition(const AliMpIntPair& indices) const
141 // Find the motif position which contains the given pad indices
142 // return 0 if not found
145 switch (fkSector->GetDirection()) {
147 // Case where all the pads have the same size along X direction
149 for (Int_t irow=0; irow<fkSector->GetNofRows(); ++irow) {
150 AliMpRow* row = fkSector->GetRow(irow);
151 if (row->GetLowIndicesLimit().GetFirst()<=indices.GetFirst() &&
152 row->GetHighIndicesLimit().GetFirst()>=indices.GetFirst()) {
154 for (Int_t iseg=0;iseg<row->GetNofRowSegments();++iseg){
155 AliMpVRowSegment* seg = row->GetRowSegment(iseg);
156 if (seg->GetLowIndicesLimit().GetFirst()<=indices.GetFirst() &&
157 seg->GetHighIndicesLimit().GetFirst()>=indices.GetFirst()) {
159 AliMpMotifPosition* motifPos;
160 for (Int_t imot=0;imot<seg->GetNofMotifs();++imot) {
162 = fkSector->GetMotifMap()
163 ->FindMotifPosition(seg->GetMotifPositionId(imot));
164 if (motifPos && motifPos->HasPad(indices)) return motifPos;
173 ////////////////////////////////////////////////////////////////////////////////
175 // Case where all the pads have the same size along Y direction
176 // look for the row which contains the indices
179 for (irow=0; irow<fkSector->GetNofRows(); ++irow) {
180 row = fkSector->GetRow(irow);
181 AliMpVRowSegment* lastSeg = row->GetRowSegment(row->GetNofRowSegments()-1);
182 if (lastSeg->GetLowIndicesLimit().GetSecond()<=indices.GetSecond() &&
183 lastSeg->GetHighIndicesLimit().GetSecond()>=indices.GetSecond()) break;
184 // NOTE : We use the last row segment in order to ensure that
185 // we are not on a special motif
187 if (irow==fkSector->GetNofRows()) return 0;
188 // look for the row segment, in the found row, which contains the indices
189 AliMpVRowSegment* seg=0;
191 for (iseg=0;iseg<row->GetNofRowSegments();++iseg){
192 seg = row->GetRowSegment(iseg);
193 if (seg->HasIndices(indices)) break;
195 if (iseg==row->GetNofRowSegments()) return 0;
197 // look for the motif position which contains the indices
198 AliMpMotifPosition* motifPos=0;
200 for (imot=0;imot<seg->GetNofMotifs();++imot) {
202 = fkSector->GetMotifMap()
203 ->FindMotifPosition(seg->GetMotifPositionId(imot));
204 if (motifPos && motifPos->HasPad(indices)) break;
206 if (imot==seg->GetNofMotifs()) return 0;
214 //______________________________________________________________________________
216 AliMpSectorSegmentation::PadByXDirection(const TVector2& startPosition,
219 // Find the first valid pad from starting position in the
220 // direction of pad lines up to distance dx.
223 // Define step limits
224 Double_t stepX = fkSector->GetMinPadDimensions().X();
226 // Search in X direction
228 TVector2 position(startPosition);
230 pad = PadByPosition(position, false);
231 position += TVector2(stepX, 0.);
233 while ( !pad.IsValid() && position.X() < maxX );
235 // Invalidate pad if it is outside limits
236 if ((pad.Position().X() - pad.Dimensions().X()) > maxX)
237 pad = AliMpPad::Invalid();
242 //______________________________________________________________________________
244 AliMpSectorSegmentation::PadByYDirection(const TVector2& startPosition,
247 // Find the first valid pad from starting position in the
248 // direction of pad columns up to distance dx.
251 // Define step limits
252 Double_t stepY = fkSector->GetMinPadDimensions().Y();
254 // Search in Y direction
256 TVector2 position(startPosition);
258 pad = PadByPosition(position, false);
259 position += TVector2(0., stepY);
261 while ( !pad.IsValid() && position.Y() < maxY );
263 // Invalidate pad if it is outside limits
264 if ((pad.Position().Y() - pad.Dimensions().Y()) > maxY)
265 pad = AliMpPad::Invalid();
270 //______________________________________________________________________________
271 AliMpVPadIterator* AliMpSectorSegmentation::CreateIterator() const
273 // The inherited method cannot be used
275 Fatal("CreateIterator", "Center pad has to be specified.");
284 //______________________________________________________________________________
286 AliMpSectorSegmentation::CreateIterator(const AliMpArea& area) const
288 // Creates the are iterator.
289 // (The inherited method cannot be used)
292 switch (fkSector->GetDirection()) {
294 case kX: return new AliMpSectorAreaVPadIterator(this, area);
296 case kY: return new AliMpSectorAreaHPadIterator(this, area);
300 Fatal("CreateIterator", "Incomplete switch on Sector direction");
304 //______________________________________________________________________________
306 AliMpSectorSegmentation::CreateIterator(const AliMpPad& centerPad,
307 Bool_t includeCenter) const
309 // Creates the neighbours pad iterator.
310 // (The inherited method cannot be used)
312 return new AliMpNeighboursPadIterator(this, centerPad, includeCenter);
315 //______________________________________________________________________________
317 AliMpSectorSegmentation::PadByLocation(const AliMpIntPair& location,
318 Bool_t warning) const
320 // Find the pad which corresponds to the given location
322 if ((*fPadBuffer).GetLocation()==location) return (*fPadBuffer);
324 AliMpMotifPosition* motifPos =
325 fkSector->GetMotifMap()->FindMotifPosition(location.GetFirst());
327 if (warning) Warning("PadByLocation","The pad motif position ID doesn't exists");
328 return AliMpPad::Invalid();
331 AliMpVMotif* motif = motifPos->GetMotif();
332 AliMpIntPair localIndices =
333 motif->GetMotifType()->FindLocalIndicesByGassiNum(location.GetSecond());
334 if (! localIndices.IsValid()) {
335 if (warning) Warning("PadByLocation","The pad number doesn't exists");
336 return AliMpPad::Invalid();
338 TVector2 delta = motif->PadPositionLocal(localIndices);
339 return (*fPadBuffer) = AliMpPad(location,
340 motifPos->GlobalIndices(localIndices),
341 motifPos->Position()+delta,
342 motif->GetPadDimensions(localIndices));
345 //______________________________________________________________________________
347 AliMpSectorSegmentation::PadByIndices(const AliMpIntPair& indices,
348 Bool_t warning ) const
350 // Find the pad which corresponds to the given indices
352 if ((*fPadBuffer).GetIndices()==indices) return (*fPadBuffer);
354 AliMpMotifPosition* motifPos = FindMotifPosition(indices);
356 if (warning) Warning("PadByIndices","Pad indices not contained in any motif!");
357 return AliMpPad::Invalid();
360 // retrieve the local indices in the found motif
361 AliMpVMotif* motif = motifPos->GetMotif();
362 AliMpIntPair localIndices = indices - motifPos->GetLowIndicesLimit();
364 AliMpConnection* connection=
365 motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
368 if (warning) Warning("PadByIndices","No connection with the given indices!");
369 return AliMpPad::Invalid();
372 TVector2 localPos = motif->PadPositionLocal(localIndices);
375 = AliMpPad(AliMpIntPair(motifPos->GetID(),connection->GetGassiNum()),
377 motifPos->Position()+localPos,
378 motif->GetPadDimensions(localIndices));
381 //______________________________________________________________________________
383 AliMpSectorSegmentation::PadByPosition(const TVector2& position,
384 Bool_t warning) const
386 // Find the pad which corresponds to the given position
388 if ((*fPadBuffer).Position().X()==position.X() &&
389 (*fPadBuffer).Position().Y()==position.Y()) return (*fPadBuffer);
391 Int_t motifPosID = fkSector->FindMotifPositionId(position);
392 AliMpMotifPosition* motifPos
393 = fkSector->GetMotifMap()
394 ->FindMotifPosition(motifPosID);
397 if (warning) Warning("PadByPosition","Position outside limits");
398 return AliMpPad::Invalid();
401 AliMpVMotif* motif = motifPos->GetMotif();
402 AliMpIntPair localIndices
403 = motif->PadIndicesLocal(position-motifPos->Position());
405 AliMpConnection* connect =
406 motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
409 if (warning) Warning("PadByPosition","Position outside motif limits");
410 return AliMpPad::Invalid();
414 = AliMpPad(AliMpIntPair(motifPosID,connect->GetGassiNum()),
415 motifPos->GlobalIndices(localIndices),
416 motifPos->Position()+motif->PadPositionLocal(localIndices),
417 motif->GetPadDimensions(localIndices));
421 //______________________________________________________________________________
423 AliMpSectorSegmentation::PadByDirection(const TVector2& startPosition,
424 Double_t distance) const
426 // Find the first valid pad from starting position in the
427 // direction of pad lines/columns up to the specified distance.
428 // Pad lines are the lines of pads in the sector with constant pad y size,
429 // pad columns are the columns of pads in the sector with constant pad x size.
432 switch (fkSector->GetDirection()) {
434 case kX: return PadByYDirection(startPosition, distance);
436 case kY: return PadByXDirection(startPosition, distance);
440 Fatal("PadByDirection", "Incomplete switch on Sector direction");
441 return AliMpPad::Invalid();
444 //______________________________________________________________________________
445 Bool_t AliMpSectorSegmentation::HasPad(const AliMpIntPair& indices) const
447 // Does the pad specified by <indices> exist ?
450 return PadByIndices(indices,kFALSE) != AliMpPad::Invalid();
453 //______________________________________________________________________________
454 Bool_t AliMpSectorSegmentation::HasMotifPosition(Int_t motifPositionID) const
456 // Does the motif position specified by motifPositionID exist ?
459 return (fkSector->GetMotifMap()->FindMotifPosition(motifPositionID) != 0);
462 //______________________________________________________________________________
463 TVector2 AliMpSectorSegmentation::GetMinPadDimensions() const
465 // Returnes the dimensions of the smallest pad.
468 return fkSector->GetMinPadDimensions();
471 //______________________________________________________________________________
472 Int_t AliMpSectorSegmentation::Zone(const AliMpPad& pad, Bool_t warning) const
474 // Returns the zone index of the zone containing the specified pad.
475 // This zone index is different from the zone ID,
476 // as it is unique for each pad dimensions.
477 // It is composed in this way:
478 // zoneID*10 + specific index
479 // Specific index is present only for zones containing special motifs.
482 if (!pad.IsValid()) {
483 if (warning) Warning("Zone(AliMpPad)", "Invalid pad");
488 PadDimensionsMapCIterator it;
489 for (it = fPadDimensionsMap.begin(); it != fPadDimensionsMap.end(); ++it) {
490 if (AliMpConstants::IsEqual(it->second, pad.Dimensions()))
496 PadDimensionsMapCIterator it(&fPadDimensionsMap);
498 while ( it.Next(key, value) ) {
499 TVector2 dimensions = GetVector(value);
500 if (AliMpConstants::IsEqual(dimensions, pad.Dimensions()))
507 // Should never happen
508 Fatal("Zone(AliMpPad)", "not found");
512 //______________________________________________________________________________
514 AliMpSectorSegmentation::PadDimensions(Int_t zone, Bool_t warning) const
516 // Returns the pad dimensions for the zone with the specified zone index.
520 PadDimensionsMapCIterator it = fPadDimensionsMap.find(zone);
521 if (it != fPadDimensionsMap.end()) return it->second;
525 Long_t value = fPadDimensionsMap.GetValue(zone);
526 if (value) return GetVector(value);
529 if (warning) Warning("PadDimensions(zone)", "not found");
533 //______________________________________________________________________________
534 Bool_t AliMpSectorSegmentation::CircleTest(const AliMpIntPair& indices) const
536 // Verifies that all methods for retrieving pads are consistents between them.
537 // Returns true if the pad with specified indices was found and verified,
541 if (!HasPad(indices)) return false;
543 // Verify the indice->location->position->indice way
544 AliMpIntPair location = PadByIndices(indices).GetLocation();
545 TVector2 position = PadByLocation(location).Position();
546 AliMpIntPair retIndices = PadByPosition(position).GetIndices();
548 if (retIndices != indices) {
549 cout << "Pad " << indices << " lead to inconsistency" << endl;
550 cout << "in indice->location->position->indice way..." << endl;
551 cout << "starting from " << indices << "-->" << location << "-->"
552 << '(' << position.X() << ',' << position.Y() << ')'
553 << " and retIndices: " << retIndices << endl;
557 // Verify the indice->position->location->indice way
558 position = PadByIndices(indices).Position();
559 location = PadByPosition(position).GetLocation();
560 retIndices = PadByLocation(location).GetIndices();
562 if (retIndices != indices) {
563 cout << "Pad " << indices << " lead to inconsistency" << endl;
564 cout << "in indice->position->location->indice way..." <<endl;
565 cout << "starting from " << indices
566 << " and retIndices: " << retIndices << endl;