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