6 // Class describing the sector of the MUON chamber of station 1.
8 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
11 #include <Riostream.h>
13 #include "AliMpSector.h"
14 #include "AliMpSectorPadIterator.h"
15 #include "AliMpZone.h"
17 #include "AliMpVRowSegment.h"
18 #include "AliMpVMotif.h"
19 #include "AliMpMotifMap.h"
20 #include "AliMpIntPair.h"
21 #include "AliMpConstants.h"
25 //_____________________________________________________________________________
26 AliMpSector::AliMpSector(const TString& id, Int_t nofZones, Int_t nofRows,
27 AliMpDirection direction)
30 fOffset(TVector2(0., 0.)),
33 fDirection(direction),
34 fMinPadDimensions(TVector2(1.e6, 1.e6))
37 fMotifMap = new AliMpMotifMap();
40 for (Int_t izone = 0; izone<nofZones; izone++)
41 fZones.push_back(new AliMpZone(izone+1));
43 for (Int_t irow = 0; irow<nofRows; irow++)
44 fRows.push_back(new AliMpRow(irow, fMotifMap));
48 for (Int_t izone = 0; izone<nofZones; izone++)
49 fZones.Add(new AliMpZone(izone+1));
51 for (Int_t irow = 0; irow<nofRows; irow++)
52 fRows.Add(new AliMpRow(irow, fMotifMap));
57 //_____________________________________________________________________________
58 AliMpSector::AliMpSector(const AliMpSector& right)
61 Fatal("AliMpSector", "Copy constructor not provided.");
64 //_____________________________________________________________________________
65 AliMpSector::AliMpSector()
68 fOffset(TVector2(0., 0.)),
73 fMinPadDimensions(TVector2(0., 0.))
78 //_____________________________________________________________________________
79 AliMpSector::~AliMpSector() {
82 for (Int_t izone = 0; izone<GetNofZones(); izone++)
85 for (Int_t irow = 0; irow<GetNofRows(); irow++)
95 //_____________________________________________________________________________
96 AliMpSector& AliMpSector::operator=(const AliMpSector& right)
98 // check assignement to self
99 if (this == &right) return *this;
101 Fatal("operator =", "Assignement operator not provided.");
110 //_____________________________________________________________________________
111 AliMpVPadIterator* AliMpSector::CreateIterator() const
113 return new AliMpSectorPadIterator(this);
117 //_____________________________________________________________________________
118 AliMpVRowSegment* AliMpSector::FindRowSegment(const TVector2& position) const
120 // Finds the row segment in the specified position.
121 // Returns 0 if no motif is found.
125 AliMpRow* row = FindRow(position);
129 // Find the row segment and return its motif
130 AliMpVRowSegment* rowSegment = row->FindRowSegment(position.X());
135 //_____________________________________________________________________________
136 void AliMpSector::SetRowOffsets()
138 // For each row checks consitency of the row segments
139 // and calculates the row offset.
142 Double_t offset = fOffset.Y();
144 for (Int_t irow=0; irow<GetNofRows(); irow++)
145 offset = GetRow(irow)->SetOffsetY(offset);
148 //_____________________________________________________________________________
149 void AliMpSector::SetMotifPositions()
151 // Creates motif positions objects and fills them in the motif map.
154 for (Int_t i=0; i<GetNofRows(); i++)
155 GetRow(i)->SetMotifPositions();
158 //_____________________________________________________________________________
159 void AliMpSector::SetGlobalIndices()
161 // Set the indices limits to all indexed elements
162 // (row, row segment, motif positions).
165 AliMpIntPair indices(0,0);
166 AliMpRow* rowBefore=0;
167 for (Int_t i=0; i<GetNofRows(); i++) {
168 GetRow(i)->SetGlobalIndices(fDirection, rowBefore);
169 rowBefore = GetRow(i);
173 //_____________________________________________________________________________
174 void AliMpSector::SetMinPadDimensions()
176 // Sets the minimal pad dimensions.
179 for (Int_t i=1; i<GetNofZones()+1; i++) {
180 TVector2 padDimensions = GetZone(i)->GetPadDimensions();
182 if ( fDirection == kX &&
183 padDimensions.Y() > 0. && padDimensions.Y() < fMinPadDimensions.Y() ||
185 padDimensions.X() > 0. && padDimensions.X() < fMinPadDimensions.X())
187 fMinPadDimensions = padDimensions;
195 //_____________________________________________________________________________
196 void AliMpSector::SetRowSegmentOffsets()
198 // For all rows sets offset to all row segments.
201 for (Int_t irow=0; irow<GetNofRows(); irow++)
202 GetRow(irow)->SetRowSegmentOffsets(fOffset);
205 //_____________________________________________________________________________
206 void AliMpSector::Initialize()
208 // Makes needed settings after sector is read from
215 SetMinPadDimensions();
218 //_____________________________________________________________________________
219 void AliMpSector::PrintGeometry() const
221 // Prints the positions of rows, rows segments
224 for (Int_t i=0; i<GetNofRows(); i++) {
225 AliMpRow* row = GetRow(i);
227 cout << "ROW " << row->GetID()
228 << " center Y " << row->Position().Y() << endl;
230 for (Int_t j=0; j<row->GetNofRowSegments(); j++) {
231 AliMpVRowSegment* rowSegment = row->GetRowSegment(j);
233 cout << " ROW Segment " << j
235 << rowSegment->LeftBorderX() << " "
236 << rowSegment->RightBorderX()
238 << 2*rowSegment->Dimensions().X() << " "
245 //_____________________________________________________________________________
246 AliMpRow* AliMpSector::FindRow(const TVector2& position) const
248 // Finds the row for the specified y position.
249 // If y is on border the lowest row is returned.
252 Double_t y = position.Y();
255 for (Int_t i=0; i<GetNofRows(); i++) {
256 if ( y >= fRows[i]->LowBorderY() && y <= fRows[i]->UpperBorderY())
262 for (Int_t i=0; i<GetNofRows(); i++) {
263 if ( y >= ((AliMpRow*)fRows[i])->LowBorderY() &&
264 y <= ((AliMpRow*)fRows[i])->UpperBorderY())
265 return (AliMpRow*)fRows[i];
272 //_____________________________________________________________________________
273 AliMpVMotif* AliMpSector::FindMotif(const TVector2& position) const
275 // Finds the motif in the specified position.
276 // Returns 0 if no motif is found.
279 // Find the row segment
280 AliMpVRowSegment* rowSegment = FindRowSegment(position);
282 if (!rowSegment) return 0;
285 return rowSegment->FindMotif(position);
288 //_____________________________________________________________________________
289 Int_t AliMpSector::FindMotifPositionId(const TVector2& position) const
291 // Finds the motif position ID in the specified position.
292 // Returns 0 if no motif is found.
295 // Find the row segment
296 AliMpVRowSegment* rowSegment = FindRowSegment(position);
298 if (!rowSegment) return 0;
300 // Find motif position ID
301 return rowSegment->FindMotifPositionId(position);
304 //_____________________________________________________________________________
305 AliMpRow* AliMpSector::FindRow(Int_t motifPositionId) const
307 // Finds the row with the the specified motif position.
308 // Returns 0 if no row is found.
311 AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
313 if (segment) return segment->GetRow();
318 //_____________________________________________________________________________
319 AliMpVRowSegment* AliMpSector::FindRowSegment(Int_t motifPositionId) const
321 // Finds the row segment with the the specified motif position.
322 // Returns 0 if no row segment is found.
325 for (Int_t irow=0; irow<GetNofRows(); irow++) {
328 AliMpRow* row = fRows[irow];
331 AliMpRow* row = (AliMpRow*)fRows[irow];
334 for (Int_t iseg=0; iseg<row->GetNofRowSegments(); iseg++) {
335 AliMpVRowSegment* segment = row->GetRowSegment(iseg);
336 if (segment->HasMotifPosition(motifPositionId)) return segment;
343 //_____________________________________________________________________________
344 TVector2 AliMpSector::FindPosition(Int_t motifPositionId) const
346 // Finds the position of the motif specified by its position Id.
347 // Returns 0 if no row segment is found.
350 AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
353 Warning("FindPosition", "Given motifPositionId not found.");
357 return segment->MotifCenter(motifPositionId);
360 //_____________________________________________________________________________
361 AliMpZone* AliMpSector::FindZone(const TVector2& padDimensions) const
363 // Finds the zone with specified padDimensions.
366 for (Int_t i=0; i<GetNofZones(); i++) {
367 AliMpZone* zone = GetZone(i+1);
368 if (AliMpConstants::IsEqual(padDimensions, zone->GetPadDimensions()))
372 // Return 0 if not found
376 //_____________________________________________________________________________
377 TVector2 AliMpSector::Position() const
379 // Returns the offset.
386 //_____________________________________________________________________________
387 TVector2 AliMpSector::Dimensions() const
389 // Returns the maximum halflength in x, y.
394 for (Int_t i=0; i<GetNofRows(); i++) {
397 // take the largest x row dimension
398 if (fRows[i]->Dimensions().X() > x)
399 x = fRows[i]->Dimensions().X();
401 // add all rows y dimensions
402 y += fRows[i]->Dimensions().Y();
406 // take the largest x row dimension
407 if ( ((AliMpRow*)fRows[i])->Dimensions().X() > x)
408 x = ((AliMpRow*)fRows[i])->Dimensions().X();
410 // add all rows y dimensions
411 y += ((AliMpRow*)fRows[i])->Dimensions().Y();
415 return TVector2(x, y);
418 //_____________________________________________________________________________
419 Int_t AliMpSector::GetNofZones() const
421 // Returns the number of zones.
425 return fZones.size();
429 return fZones.GetEntriesFast();
433 //_____________________________________________________________________________
434 AliMpZone* AliMpSector::GetZone(Int_t zoneID) const
436 // Returns zone with specified ID.
439 if (zoneID < 1 || zoneID > GetNofZones()) {
440 Warning("GetZone", "Index outside range");
445 return fZones[zoneID-1];
449 return (AliMpZone*)fZones[zoneID-1];
453 //_____________________________________________________________________________
454 Int_t AliMpSector::GetNofRows() const
456 // Returns the number of rows.
464 return fRows.GetEntriesFast();
468 //_____________________________________________________________________________
469 AliMpRow* AliMpSector::GetRow(Int_t rowID) const
471 // Returns row with specified ID.
474 if (rowID < 0 || rowID >= GetNofRows()) {
475 Warning("GetRow", "Index outside range");
484 return (AliMpRow*)fRows[rowID];