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"
20 #include "AliMpVRowSegment.h"
21 #include "AliMpMotifMap.h"
22 #include "AliMpVMotif.h"
23 #include "AliMpMotifPosition.h"
24 #include "AliMpConnection.h"
25 #include "AliMpNeighboursPadIterator.h"
26 #include "AliMpSectorAreaHPadIterator.h"
27 #include "AliMpSectorAreaVPadIterator.h"
28 #include "AliMpConstants.h"
30 ClassImp(AliMpSectorSegmentation)
32 //______________________________________________________________________________
33 AliMpSectorSegmentation::AliMpSectorSegmentation(const AliMpSector* sector)
34 : AliMpVSegmentation(),
38 fPadBuffer = new AliMpPad(AliMpPad::Invalid());
40 FillPadDimensionsMap();
43 //______________________________________________________________________________
44 AliMpSectorSegmentation::AliMpSectorSegmentation()
45 : AliMpVSegmentation(),
53 //______________________________________________________________________________
54 AliMpSectorSegmentation::~AliMpSectorSegmentation() {
63 //______________________________________________________________________________
64 void AliMpSectorSegmentation::FillPadDimensionsMap()
66 // Fills the maps between zone ids and pad dimensions.
69 for (Int_t i=0; i<fkSector->GetNofZones(); i++) {
70 AliMpZone* zone = fkSector->GetZone(i+1);
71 Int_t zoneID = zone->GetID();
73 if (!AliMpConstants::IsEqual(zone->GetPadDimensions(), TVector2())) {
75 fPadDimensionsMap[zoneID*10] = zone->GetPadDimensions();
80 for (Int_t j=0; j<zone->GetNofSubZones(); j++) {
81 AliMpSubZone* subZone = zone->GetSubZone(j);
82 AliMpVMotif* motif = subZone->GetMotif();
84 for (Int_t k=0; k<motif->GetNofPadDimensions(); k++) {
85 Int_t index = zoneID*10 + subIndex++;
86 fPadDimensionsMap[index] = motif->GetPadDimensions(k);
93 //______________________________________________________________________________
95 AliMpSectorSegmentation::FindMotifPosition(const AliMpIntPair& indices) const
97 // Find the motif position which contains the given pad indices
98 // return 0 if not found
101 switch (fkSector->GetDirection()) {
103 // Case where all the pads have the same size along X direction
105 for (Int_t irow=0; irow<fkSector->GetNofRows(); ++irow) {
106 AliMpRow* row = fkSector->GetRow(irow);
107 if (row->GetLowIndicesLimit().GetFirst()<=indices.GetFirst() &&
108 row->GetHighIndicesLimit().GetFirst()>=indices.GetFirst()) {
110 for (Int_t iseg=0;iseg<row->GetNofRowSegments();++iseg){
111 AliMpVRowSegment* seg = row->GetRowSegment(iseg);
112 if (seg->GetLowIndicesLimit().GetFirst()<=indices.GetFirst() &&
113 seg->GetHighIndicesLimit().GetFirst()>=indices.GetFirst()) {
115 AliMpMotifPosition* motifPos;
116 for (Int_t imot=0;imot<seg->GetNofMotifs();++imot) {
118 = fkSector->GetMotifMap()
119 ->FindMotifPosition(seg->GetMotifPositionId(imot));
120 if (motifPos && motifPos->HasPad(indices)) return motifPos;
129 ////////////////////////////////////////////////////////////////////////////////
131 // Case where all the pads have the same size along Y direction
132 // look for the row which contains the indices
135 for (irow=0; irow<fkSector->GetNofRows(); ++irow) {
136 row = fkSector->GetRow(irow);
137 AliMpVRowSegment* lastSeg = row->GetRowSegment(row->GetNofRowSegments()-1);
138 if (lastSeg->GetLowIndicesLimit().GetSecond()<=indices.GetSecond() &&
139 lastSeg->GetHighIndicesLimit().GetSecond()>=indices.GetSecond()) break;
140 // NOTE : We use the last row segment in order to ensure that
141 // we are not on a special motif
143 if (irow==fkSector->GetNofRows()) return 0;
144 // look for the row segment, in the found row, which contains the indices
145 AliMpVRowSegment* seg=0;
147 for (iseg=0;iseg<row->GetNofRowSegments();++iseg){
148 seg = row->GetRowSegment(iseg);
149 if (seg->HasIndices(indices)) break;
151 if (iseg==row->GetNofRowSegments()) return 0;
153 // look for the motif position which contains the indices
154 AliMpMotifPosition* motifPos=0;
156 for (imot=0;imot<seg->GetNofMotifs();++imot) {
158 = fkSector->GetMotifMap()
159 ->FindMotifPosition(seg->GetMotifPositionId(imot));
160 if (motifPos && motifPos->HasPad(indices)) break;
162 if (imot==seg->GetNofMotifs()) return 0;
170 //______________________________________________________________________________
172 AliMpSectorSegmentation::PadByXDirection(const TVector2& startPosition,
175 // Find the first valid pad from starting position in the
176 // direction of pad lines up to distance dx.
179 // Define step limits
180 Double_t stepX = fkSector->GetMinPadDimensions().X();
182 // Search in X direction
184 TVector2 position(startPosition);
186 pad = PadByPosition(position, false);
187 position += TVector2(stepX, 0.);
189 while ( !pad.IsValid() && position.X() < maxX );
191 // Invalidate pad if it is outside limits
192 if ((pad.Position().X() - pad.Dimensions().X()) > maxX)
193 pad = AliMpPad::Invalid();
198 //______________________________________________________________________________
200 AliMpSectorSegmentation::PadByYDirection(const TVector2& startPosition,
203 // Find the first valid pad from starting position in the
204 // direction of pad columns up to distance dx.
207 // Define step limits
208 Double_t stepY = fkSector->GetMinPadDimensions().Y();
210 // Search in Y direction
212 TVector2 position(startPosition);
214 pad = PadByPosition(position, false);
215 position += TVector2(0., stepY);
217 while ( !pad.IsValid() && position.Y() < maxY );
219 // Invalidate pad if it is outside limits
220 if ((pad.Position().Y() - pad.Dimensions().Y()) > maxY)
221 pad = AliMpPad::Invalid();
226 //______________________________________________________________________________
227 AliMpVPadIterator* AliMpSectorSegmentation::CreateIterator() const
229 // The inherited method cannot be used
231 Fatal("CreateIterator", "Center pad has to be specified.");
240 //______________________________________________________________________________
242 AliMpSectorSegmentation::CreateIterator(const AliMpArea& area) const
244 // Creates the are iterator.
245 // (The inherited method cannot be used)
248 switch (fkSector->GetDirection()) {
250 case kX: return new AliMpSectorAreaVPadIterator(this, area);
252 case kY: return new AliMpSectorAreaHPadIterator(this, area);
256 Fatal("CreateIterator", "Incomplete switch on Sector direction");
260 //______________________________________________________________________________
262 AliMpSectorSegmentation::CreateIterator(const AliMpPad& centerPad,
263 Bool_t includeCenter) const
265 // Creates the neighbours pad iterator.
266 // (The inherited method cannot be used)
268 return new AliMpNeighboursPadIterator(this, centerPad, includeCenter);
271 //______________________________________________________________________________
273 AliMpSectorSegmentation::PadByLocation(const AliMpIntPair& location,
274 Bool_t warning) const
276 // Find the pad which corresponds to the given location
278 if ((*fPadBuffer).GetLocation()==location) return (*fPadBuffer);
280 AliMpMotifPosition* motifPos =
281 fkSector->GetMotifMap()->FindMotifPosition(location.GetFirst());
283 if (warning) Warning("PadByLocation","The pad motif position ID doesn't exists");
284 return AliMpPad::Invalid();
287 AliMpVMotif* motif = motifPos->GetMotif();
288 AliMpIntPair localIndices =
289 motif->GetMotifType()->FindLocalIndicesByGassiNum(location.GetSecond());
290 if (! localIndices.IsValid()) {
291 if (warning) Warning("PadByLocation","The pad number doesn't exists");
292 return AliMpPad::Invalid();
294 TVector2 delta = motif->PadPositionLocal(localIndices);
295 return (*fPadBuffer) = AliMpPad(location,
296 motifPos->GlobalIndices(localIndices),
297 motifPos->Position()+delta,
298 motif->GetPadDimensions(localIndices));
301 //______________________________________________________________________________
303 AliMpSectorSegmentation::PadByIndices(const AliMpIntPair& indices,
304 Bool_t warning ) const
306 // Find the pad which corresponds to the given indices
308 if ((*fPadBuffer).GetIndices()==indices) return (*fPadBuffer);
310 AliMpMotifPosition* motifPos = FindMotifPosition(indices);
312 if (warning) Warning("PadByIndices","Pad indices not contained in any motif!");
313 return AliMpPad::Invalid();
316 // retrieve the local indices in the found motif
317 AliMpVMotif* motif = motifPos->GetMotif();
318 AliMpIntPair localIndices = indices - motifPos->GetLowIndicesLimit();
320 AliMpConnection* connection=
321 motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
324 if (warning) Warning("PadByIndices","No connection with the given indices!");
325 return AliMpPad::Invalid();
328 TVector2 localPos = motif->PadPositionLocal(localIndices);
331 = AliMpPad(AliMpIntPair(motifPos->GetID(),connection->GetGassiNum()),
333 motifPos->Position()+localPos,
334 motif->GetPadDimensions(localIndices));
337 //______________________________________________________________________________
339 AliMpSectorSegmentation::PadByPosition(const TVector2& position,
340 Bool_t warning) const
342 // Find the pad which corresponds to the given position
344 if ((*fPadBuffer).Position().X()==position.X() &&
345 (*fPadBuffer).Position().Y()==position.Y()) return (*fPadBuffer);
347 Int_t motifPosID = fkSector->FindMotifPositionId(position);
348 AliMpMotifPosition* motifPos
349 = fkSector->GetMotifMap()
350 ->FindMotifPosition(motifPosID);
353 if (warning) Warning("PadByPosition","Position outside limits");
354 return AliMpPad::Invalid();
357 AliMpVMotif* motif = motifPos->GetMotif();
358 AliMpIntPair localIndices
359 = motif->PadIndicesLocal(position-motifPos->Position());
361 AliMpConnection* connect =
362 motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
365 if (warning) Warning("PadByPosition","Position outside motif limits");
366 return AliMpPad::Invalid();
370 = AliMpPad(AliMpIntPair(motifPosID,connect->GetGassiNum()),
371 motifPos->GlobalIndices(localIndices),
372 motifPos->Position()+motif->PadPositionLocal(localIndices),
373 motif->GetPadDimensions(localIndices));
377 //______________________________________________________________________________
379 AliMpSectorSegmentation::PadByDirection(const TVector2& startPosition,
380 Double_t distance) const
382 // Find the first valid pad from starting position in the
383 // direction of pad lines/columns up to the specified distance.
384 // Pad lines are the lines of pads in the sector with constant pad y size,
385 // pad columns are the columns of pads in the sector with constant pad x size.
388 switch (fkSector->GetDirection()) {
390 case kX: return PadByYDirection(startPosition, distance);
392 case kY: return PadByXDirection(startPosition, distance);
396 Fatal("PadByDirection", "Incomplete switch on Sector direction");
397 return AliMpPad::Invalid();
400 //______________________________________________________________________________
401 Bool_t AliMpSectorSegmentation::HasPad(const AliMpIntPair& indices) const
403 // Does the pad specified by <indices> exist ?
406 return PadByIndices(indices,kFALSE) != AliMpPad::Invalid();
409 //______________________________________________________________________________
410 Bool_t AliMpSectorSegmentation::HasMotifPosition(Int_t motifPositionID) const
412 // Does the motif position specified by motifPositionID exist ?
415 return (fkSector->GetMotifMap()->FindMotifPosition(motifPositionID) != 0);
418 //______________________________________________________________________________
419 TVector2 AliMpSectorSegmentation::GetMinPadDimensions() const
421 // Returnes the dimensions of the smallest pad.
424 return fkSector->GetMinPadDimensions();
427 //______________________________________________________________________________
428 Int_t AliMpSectorSegmentation::Zone(const AliMpPad& pad, Bool_t warning) const
430 // Returns the zone index of the zone containing the specified pad.
431 // This zone index is different from the zone ID,
432 // as it is unique for each pad dimensions.
433 // It is composed in this way:
434 // zoneID*10 + specific index
435 // Specific index is present only for zones containing special motifs.
438 if (!pad.IsValid()) {
439 if (warning) Warning("Zone(AliMpPad)", "Invalid pad");
443 PadDimensionsMap::const_iterator it;
444 for (it = fPadDimensionsMap.begin(); it != fPadDimensionsMap.end(); ++it) {
445 if (AliMpConstants::IsEqual(it->second, pad.Dimensions()))
449 // Should never happen
450 Fatal("Zone(AliMpPad)", "not found");
454 //______________________________________________________________________________
456 AliMpSectorSegmentation::PadDimensions(Int_t zone, Bool_t warning) const
458 // Returns the pad dimensions for the zone with the specified zone index.
461 PadDimensionsMap::const_iterator it = fPadDimensionsMap.find(zone);
462 if (it != fPadDimensionsMap.end()) return it->second;
464 if (warning) Warning("PadDimensions(zone)", "not found");
468 //______________________________________________________________________________
469 Bool_t AliMpSectorSegmentation::CircleTest(const AliMpIntPair& indices) const
471 // Verifies that all methods for retrieving pads are consistents between them.
472 // Returns true if the pad with specified indices was found and verified,
476 if (!HasPad(indices)) return false;
478 // Verify the indice->location->position->indice way
479 AliMpIntPair location = PadByIndices(indices).GetLocation();
480 TVector2 position = PadByLocation(location).Position();
481 AliMpIntPair retIndices = PadByPosition(position).GetIndices();
483 if (retIndices != indices) {
484 cout << "Pad " << indices << " lead to inconsistency" << endl;
485 cout << "in indice->location->position->indice way..." << endl;
486 cout << "starting from " << indices << "-->" << location << "-->"
487 << '(' << position.X() << ',' << position.Y() << ')'
488 << " and retIndices: " << retIndices << endl;
492 // Verify the indice->position->location->indice way
493 position = PadByIndices(indices).Position();
494 location = PadByPosition(position).GetLocation();
495 retIndices = PadByLocation(location).GetIndices();
497 if (retIndices != indices) {
498 cout << "Pad " << indices << " lead to inconsistency" << endl;
499 cout << "in indice->position->location->indice way..." <<endl;
500 cout << "starting from " << indices
501 << " and retIndices: " << retIndices << endl;