]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSectorSegmentation.cxx
Coding conventions corrections only
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSectorSegmentation.cxx
CommitLineData
5f91c9e8 1// $Id$
2// Category: sector
3//
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.
10//
11// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
12
13#include <Riostream.h>
14#include <TMath.h>
15
16#include "AliMpSectorSegmentation.h"
17#include "AliMpSector.h"
18#include "AliMpZone.h"
2998a151 19#include "AliMpSubZone.h"
5f91c9e8 20#include "AliMpRow.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"
2998a151 29#include "AliMpIntPair.h"
30#include "AliMpArea.h"
5f91c9e8 31#include "AliMpConstants.h"
32
33ClassImp(AliMpSectorSegmentation)
34
35//______________________________________________________________________________
36AliMpSectorSegmentation::AliMpSectorSegmentation(const AliMpSector* sector)
37 : AliMpVSegmentation(),
38 fkSector(sector)
39{
40//
41 fPadBuffer = new AliMpPad(AliMpPad::Invalid());
42
43 FillPadDimensionsMap();
44}
45
46//______________________________________________________________________________
47AliMpSectorSegmentation::AliMpSectorSegmentation()
48 : AliMpVSegmentation(),
49 fkSector(0),
50 fPadBuffer(0),
51 fPadDimensionsMap()
52{
53//
54}
55
56//______________________________________________________________________________
57AliMpSectorSegmentation::~AliMpSectorSegmentation() {
58//
59 delete fPadBuffer;
60}
61
62//
63// private methods
64//
65
66//______________________________________________________________________________
67void AliMpSectorSegmentation::FillPadDimensionsMap()
68{
69// Fills the maps between zone ids and pad dimensions.
70// ---
71
72 for (Int_t i=0; i<fkSector->GetNofZones(); i++) {
73 AliMpZone* zone = fkSector->GetZone(i+1);
74 Int_t zoneID = zone->GetID();
75
76 if (!AliMpConstants::IsEqual(zone->GetPadDimensions(), TVector2())) {
77 // regular zone
78 fPadDimensionsMap[zoneID*10] = zone->GetPadDimensions();
79 }
80 else {
81 // special zone
82 Int_t subIndex = 0;
83 for (Int_t j=0; j<zone->GetNofSubZones(); j++) {
84 AliMpSubZone* subZone = zone->GetSubZone(j);
85 AliMpVMotif* motif = subZone->GetMotif();
86
87 for (Int_t k=0; k<motif->GetNofPadDimensions(); k++) {
88 Int_t index = zoneID*10 + subIndex++;
89 fPadDimensionsMap[index] = motif->GetPadDimensions(k);
90 }
91 }
92 }
93 }
94}
95
96//______________________________________________________________________________
97AliMpMotifPosition*
98AliMpSectorSegmentation::FindMotifPosition(const AliMpIntPair& indices) const
99{
100// Find the motif position which contains the given pad indices
101// return 0 if not found
102// ---
103
104 switch (fkSector->GetDirection()) {
105 case kX : {
106 // Case where all the pads have the same size along X direction
107
108 for (Int_t irow=0; irow<fkSector->GetNofRows(); ++irow) {
109 AliMpRow* row = fkSector->GetRow(irow);
110 if (row->GetLowIndicesLimit().GetFirst()<=indices.GetFirst() &&
111 row->GetHighIndicesLimit().GetFirst()>=indices.GetFirst()) {
112
113 for (Int_t iseg=0;iseg<row->GetNofRowSegments();++iseg){
114 AliMpVRowSegment* seg = row->GetRowSegment(iseg);
115 if (seg->GetLowIndicesLimit().GetFirst()<=indices.GetFirst() &&
116 seg->GetHighIndicesLimit().GetFirst()>=indices.GetFirst()) {
117
118 AliMpMotifPosition* motifPos;
119 for (Int_t imot=0;imot<seg->GetNofMotifs();++imot) {
120 motifPos
121 = fkSector->GetMotifMap()
122 ->FindMotifPosition(seg->GetMotifPositionId(imot));
123 if (motifPos && motifPos->HasPad(indices)) return motifPos;
124 }
125 }
126 }
127 }
128 }
129 return 0;
130 }
131 break;
132 ////////////////////////////////////////////////////////////////////////////////
133 case kY : {
134 // Case where all the pads have the same size along Y direction
135 // look for the row which contains the indices
136 AliMpRow* row=0;
137 Int_t irow;
138 for (irow=0; irow<fkSector->GetNofRows(); ++irow) {
139 row = fkSector->GetRow(irow);
140 AliMpVRowSegment* lastSeg = row->GetRowSegment(row->GetNofRowSegments()-1);
141 if (lastSeg->GetLowIndicesLimit().GetSecond()<=indices.GetSecond() &&
142 lastSeg->GetHighIndicesLimit().GetSecond()>=indices.GetSecond()) break;
143 // NOTE : We use the last row segment in order to ensure that
144 // we are not on a special motif
145 }
146 if (irow==fkSector->GetNofRows()) return 0;
147 // look for the row segment, in the found row, which contains the indices
148 AliMpVRowSegment* seg=0;
149 Int_t iseg;
150 for (iseg=0;iseg<row->GetNofRowSegments();++iseg){
151 seg = row->GetRowSegment(iseg);
152 if (seg->HasIndices(indices)) break;
153 }
154 if (iseg==row->GetNofRowSegments()) return 0;
155
156 // look for the motif position which contains the indices
157 AliMpMotifPosition* motifPos=0;
158 Int_t imot=0;
159 for (imot=0;imot<seg->GetNofMotifs();++imot) {
160 motifPos
161 = fkSector->GetMotifMap()
162 ->FindMotifPosition(seg->GetMotifPositionId(imot));
163 if (motifPos && motifPos->HasPad(indices)) break;
164 }
165 if (imot==seg->GetNofMotifs()) return 0;
166
167 return motifPos;
168 }
169 default: return 0;
170 }
171}
172
173//______________________________________________________________________________
174AliMpPad
175AliMpSectorSegmentation::PadByXDirection(const TVector2& startPosition,
176 Double_t maxX) const
177{
178// Find the first valid pad from starting position in the
179// direction of pad lines up to distance dx.
180// ---
181
182 // Define step limits
183 Double_t stepX = fkSector->GetMinPadDimensions().X();
184
185 // Search in X direction
186 AliMpPad pad;
187 TVector2 position(startPosition);
188 do {
189 pad = PadByPosition(position, false);
190 position += TVector2(stepX, 0.);
191 }
192 while ( !pad.IsValid() && position.X() < maxX );
193
194 // Invalidate pad if it is outside limits
195 if ((pad.Position().X() - pad.Dimensions().X()) > maxX)
196 pad = AliMpPad::Invalid();
197
198 return pad;
199}
200
201//______________________________________________________________________________
202AliMpPad
203AliMpSectorSegmentation::PadByYDirection(const TVector2& startPosition,
204 Double_t maxY) const
205{
206// Find the first valid pad from starting position in the
207// direction of pad columns up to distance dx.
208// ---
209
210 // Define step limits
211 Double_t stepY = fkSector->GetMinPadDimensions().Y();
212
213 // Search in Y direction
214 AliMpPad pad;
215 TVector2 position(startPosition);
216 do {
217 pad = PadByPosition(position, false);
218 position += TVector2(0., stepY);
219 }
220 while ( !pad.IsValid() && position.Y() < maxY );
221
222 // Invalidate pad if it is outside limits
223 if ((pad.Position().Y() - pad.Dimensions().Y()) > maxY)
224 pad = AliMpPad::Invalid();
225
226 return pad;
227}
228
229//______________________________________________________________________________
230AliMpVPadIterator* AliMpSectorSegmentation::CreateIterator() const
231{
232// The inherited method cannot be used
233
234 Fatal("CreateIterator", "Center pad has to be specified.");
235 return 0;
236}
237
238
239//
240// public methods
241//
242
243//______________________________________________________________________________
244AliMpVPadIterator*
245AliMpSectorSegmentation::CreateIterator(const AliMpArea& area) const
246{
247// Creates the are iterator.
248// (The inherited method cannot be used)
249// ---
250
251 switch (fkSector->GetDirection()) {
252
253 case kX: return new AliMpSectorAreaVPadIterator(this, area);
254 ;;
255 case kY: return new AliMpSectorAreaHPadIterator(this, area);
256 ;;
257 }
258
259 Fatal("CreateIterator", "Incomplete switch on Sector direction");
260 return 0;
261}
262
263//______________________________________________________________________________
264AliMpVPadIterator*
265AliMpSectorSegmentation::CreateIterator(const AliMpPad& centerPad,
266 Bool_t includeCenter) const
267{
268// Creates the neighbours pad iterator.
269// (The inherited method cannot be used)
270
271 return new AliMpNeighboursPadIterator(this, centerPad, includeCenter);
272}
273
274//______________________________________________________________________________
275AliMpPad
276AliMpSectorSegmentation::PadByLocation(const AliMpIntPair& location,
277 Bool_t warning) const
278{
279// Find the pad which corresponds to the given location
280
281 if ((*fPadBuffer).GetLocation()==location) return (*fPadBuffer);
282
283 AliMpMotifPosition* motifPos =
284 fkSector->GetMotifMap()->FindMotifPosition(location.GetFirst());
285 if (!motifPos){
286 if (warning) Warning("PadByLocation","The pad motif position ID doesn't exists");
287 return AliMpPad::Invalid();
288 }
289
290 AliMpVMotif* motif = motifPos->GetMotif();
291 AliMpIntPair localIndices =
292 motif->GetMotifType()->FindLocalIndicesByGassiNum(location.GetSecond());
293 if (! localIndices.IsValid()) {
294 if (warning) Warning("PadByLocation","The pad number doesn't exists");
295 return AliMpPad::Invalid();
296 }
297 TVector2 delta = motif->PadPositionLocal(localIndices);
298 return (*fPadBuffer) = AliMpPad(location,
299 motifPos->GlobalIndices(localIndices),
300 motifPos->Position()+delta,
301 motif->GetPadDimensions(localIndices));
302
303}
304//______________________________________________________________________________
305AliMpPad
306AliMpSectorSegmentation::PadByIndices(const AliMpIntPair& indices,
307 Bool_t warning ) const
308{
309// Find the pad which corresponds to the given indices
310
311 if ((*fPadBuffer).GetIndices()==indices) return (*fPadBuffer);
312
313 AliMpMotifPosition* motifPos = FindMotifPosition(indices);
314 if (!motifPos) {
315 if (warning) Warning("PadByIndices","Pad indices not contained in any motif!");
316 return AliMpPad::Invalid();
317 }
318
319 // retrieve the local indices in the found motif
320 AliMpVMotif* motif = motifPos->GetMotif();
321 AliMpIntPair localIndices = indices - motifPos->GetLowIndicesLimit();
322
323 AliMpConnection* connection=
324 motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
325
326 if (!connection){
327 if (warning) Warning("PadByIndices","No connection with the given indices!");
328 return AliMpPad::Invalid();
329 }
330
331 TVector2 localPos = motif->PadPositionLocal(localIndices);
332
333 return (*fPadBuffer)
334 = AliMpPad(AliMpIntPair(motifPos->GetID(),connection->GetGassiNum()),
335 indices,
336 motifPos->Position()+localPos,
337 motif->GetPadDimensions(localIndices));
338
339}
340//______________________________________________________________________________
341AliMpPad
342AliMpSectorSegmentation::PadByPosition(const TVector2& position,
343 Bool_t warning) const
344{
345// Find the pad which corresponds to the given position
346
347 if ((*fPadBuffer).Position().X()==position.X() &&
348 (*fPadBuffer).Position().Y()==position.Y()) return (*fPadBuffer);
349
350 Int_t motifPosID = fkSector->FindMotifPositionId(position);
351 AliMpMotifPosition* motifPos
352 = fkSector->GetMotifMap()
353 ->FindMotifPosition(motifPosID);
354
355 if (!motifPos){
356 if (warning) Warning("PadByPosition","Position outside limits");
357 return AliMpPad::Invalid();
358 }
359
360 AliMpVMotif* motif = motifPos->GetMotif();
361 AliMpIntPair localIndices
362 = motif->PadIndicesLocal(position-motifPos->Position());
363
364 AliMpConnection* connect =
365 motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
366
367 if (!connect){
368 if (warning) Warning("PadByPosition","Position outside motif limits");
369 return AliMpPad::Invalid();
370 }
371
372 return (*fPadBuffer)
373 = AliMpPad(AliMpIntPair(motifPosID,connect->GetGassiNum()),
374 motifPos->GlobalIndices(localIndices),
375 motifPos->Position()+motif->PadPositionLocal(localIndices),
376 motif->GetPadDimensions(localIndices));
377
378}
379
380//______________________________________________________________________________
381AliMpPad
382AliMpSectorSegmentation::PadByDirection(const TVector2& startPosition,
383 Double_t distance) const
384{
385// Find the first valid pad from starting position in the
386// direction of pad lines/columns up to the specified distance.
387// Pad lines are the lines of pads in the sector with constant pad y size,
388// pad columns are the columns of pads in the sector with constant pad x size.
389// ---
390
391 switch (fkSector->GetDirection()) {
392
393 case kX: return PadByYDirection(startPosition, distance);
394 ;;
395 case kY: return PadByXDirection(startPosition, distance);
396 ;;
397 }
398
399 Fatal("PadByDirection", "Incomplete switch on Sector direction");
400 return AliMpPad::Invalid();
401}
402
403//______________________________________________________________________________
404Bool_t AliMpSectorSegmentation::HasPad(const AliMpIntPair& indices) const
405{
406// Does the pad specified by <indices> exist ?
407// ---
408
409 return PadByIndices(indices,kFALSE) != AliMpPad::Invalid();
410}
411
412//______________________________________________________________________________
413Bool_t AliMpSectorSegmentation::HasMotifPosition(Int_t motifPositionID) const
414{
415// Does the motif position specified by motifPositionID exist ?
416// ---
417
418 return (fkSector->GetMotifMap()->FindMotifPosition(motifPositionID) != 0);
419}
420
421//______________________________________________________________________________
422TVector2 AliMpSectorSegmentation::GetMinPadDimensions() const
423{
424// Returnes the dimensions of the smallest pad.
425// ---
426
427 return fkSector->GetMinPadDimensions();
428}
429
430//______________________________________________________________________________
431Int_t AliMpSectorSegmentation::Zone(const AliMpPad& pad, Bool_t warning) const
432{
433// Returns the zone index of the zone containing the specified pad.
434// This zone index is different from the zone ID,
435// as it is unique for each pad dimensions.
436// It is composed in this way:
437// zoneID*10 + specific index
438// Specific index is present only for zones containing special motifs.
439// ---
440
441 if (!pad.IsValid()) {
442 if (warning) Warning("Zone(AliMpPad)", "Invalid pad");
443 return 0;
444 }
445
2998a151 446 PadDimensionsMapCIterator it;
5f91c9e8 447 for (it = fPadDimensionsMap.begin(); it != fPadDimensionsMap.end(); ++it) {
448 if (AliMpConstants::IsEqual(it->second, pad.Dimensions()))
449 return it->first;
450 }
451
452 // Should never happen
453 Fatal("Zone(AliMpPad)", "not found");
454 return 0;
455}
456
457//______________________________________________________________________________
458TVector2
459AliMpSectorSegmentation::PadDimensions(Int_t zone, Bool_t warning) const
460{
461// Returns the pad dimensions for the zone with the specified zone index.
462// ---
463
2998a151 464 PadDimensionsMapCIterator it = fPadDimensionsMap.find(zone);
5f91c9e8 465 if (it != fPadDimensionsMap.end()) return it->second;
466
467 if (warning) Warning("PadDimensions(zone)", "not found");
468 return TVector2();
469}
470
471//______________________________________________________________________________
472Bool_t AliMpSectorSegmentation::CircleTest(const AliMpIntPair& indices) const
473{
474// Verifies that all methods for retrieving pads are consistents between them.
475// Returns true if the pad with specified indices was found and verified,
476// false otherwise.
477// ---
478
479 if (!HasPad(indices)) return false;
480
481 // Verify the indice->location->position->indice way
482 AliMpIntPair location = PadByIndices(indices).GetLocation();
483 TVector2 position = PadByLocation(location).Position();
484 AliMpIntPair retIndices = PadByPosition(position).GetIndices();
485
486 if (retIndices != indices) {
487 cout << "Pad " << indices << " lead to inconsistency" << endl;
488 cout << "in indice->location->position->indice way..." << endl;
489 cout << "starting from " << indices << "-->" << location << "-->"
490 << '(' << position.X() << ',' << position.Y() << ')'
491 << " and retIndices: " << retIndices << endl;
492 }
493
494
495 // Verify the indice->position->location->indice way
496 position = PadByIndices(indices).Position();
497 location = PadByPosition(position).GetLocation();
498 retIndices = PadByLocation(location).GetIndices();
499
500 if (retIndices != indices) {
501 cout << "Pad " << indices << " lead to inconsistency" << endl;
502 cout << "in indice->position->location->indice way..." <<endl;
503 cout << "starting from " << indices
504 << " and retIndices: " << retIndices << endl;
505 }
506
507 return true;
508}