6 // Class describing the sector of the MUON chamber of station 1.
8 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
10 #include <Riostream.h>
12 #include "AliMpSector.h"
13 #include "AliMpSectorPadIterator.h"
14 #include "AliMpZone.h"
16 #include "AliMpVRowSegment.h"
17 #include "AliMpVMotif.h"
18 #include "AliMpMotifMap.h"
19 #include "AliMpIntPair.h"
20 #include "AliMpConstants.h"
24 //_____________________________________________________________________________
25 AliMpSector::AliMpSector(const TString& id, Int_t nofZones, Int_t nofRows,
26 AliMpDirection direction)
29 fOffset(TVector2(0., 0.)),
32 fDirection(direction),
33 fMinPadDimensions(TVector2(1.e6, 1.e6))
36 fMotifMap = new AliMpMotifMap();
39 for (Int_t izone = 0; izone<nofZones; izone++)
40 fZones.push_back(new AliMpZone(izone+1));
42 for (Int_t irow = 0; irow<nofRows; irow++)
43 fRows.push_back(new AliMpRow(irow, fMotifMap));
47 for (Int_t izone = 0; izone<nofZones; izone++)
48 fZones.Add(new AliMpZone(izone+1));
50 for (Int_t irow = 0; irow<nofRows; irow++)
51 fRows.Add(new AliMpRow(irow, fMotifMap));
56 //_____________________________________________________________________________
57 AliMpSector::AliMpSector()
60 fOffset(TVector2(0., 0.)),
65 fMinPadDimensions(TVector2(0., 0.))
70 //_____________________________________________________________________________
71 AliMpSector::~AliMpSector() {
74 for (Int_t izone = 0; izone<GetNofZones(); izone++)
77 for (Int_t irow = 0; irow<GetNofRows(); irow++)
87 //_____________________________________________________________________________
88 AliMpVPadIterator* AliMpSector::CreateIterator() const
90 return new AliMpSectorPadIterator(this);
94 //_____________________________________________________________________________
95 AliMpVRowSegment* AliMpSector::FindRowSegment(const TVector2& position) const
97 // Finds the row segment in the specified position.
98 // Returns 0 if no motif is found.
102 AliMpRow* row = FindRow(position);
106 // Find the row segment and return its motif
107 AliMpVRowSegment* rowSegment = row->FindRowSegment(position.X());
112 //_____________________________________________________________________________
113 void AliMpSector::SetRowOffsets()
115 // For each row checks consitency of the row segments
116 // and calculates the row offset.
119 Double_t offset = fOffset.Y();
121 for (Int_t irow=0; irow<GetNofRows(); irow++)
122 offset = GetRow(irow)->SetOffsetY(offset);
125 //_____________________________________________________________________________
126 void AliMpSector::SetMotifPositions()
128 // Creates motif positions objects and fills them in the motif map.
131 for (Int_t i=0; i<GetNofRows(); i++)
132 GetRow(i)->SetMotifPositions();
135 //_____________________________________________________________________________
136 void AliMpSector::SetGlobalIndices()
138 // Set the indices limits to all indexed elements
139 // (row, row segment, motif positions).
142 AliMpIntPair indices(0,0);
143 AliMpRow* rowBefore=0;
144 for (Int_t i=0; i<GetNofRows(); i++) {
145 GetRow(i)->SetGlobalIndices(fDirection, rowBefore);
146 rowBefore = GetRow(i);
150 //_____________________________________________________________________________
151 void AliMpSector::SetMinPadDimensions()
153 // Sets the minimal pad dimensions.
156 for (Int_t i=1; i<GetNofZones()+1; i++) {
157 TVector2 padDimensions = GetZone(i)->GetPadDimensions();
159 if ( fDirection == kX &&
160 padDimensions.Y() > 0. && padDimensions.Y() < fMinPadDimensions.Y() ||
162 padDimensions.X() > 0. && padDimensions.X() < fMinPadDimensions.X())
164 fMinPadDimensions = padDimensions;
172 //_____________________________________________________________________________
173 void AliMpSector::SetRowSegmentOffsets()
175 // For all rows sets offset to all row segments.
178 for (Int_t irow=0; irow<GetNofRows(); irow++)
179 GetRow(irow)->SetRowSegmentOffsets(fOffset);
182 //_____________________________________________________________________________
183 void AliMpSector::Initialize()
185 // Makes needed settings after sector is read from
192 SetMinPadDimensions();
195 //_____________________________________________________________________________
196 void AliMpSector::PrintGeometry() const
198 // Prints the positions of rows, rows segments
201 for (Int_t i=0; i<GetNofRows(); i++) {
202 AliMpRow* row = GetRow(i);
204 cout << "ROW " << row->GetID()
205 << " center Y " << row->Position().Y() << endl;
207 for (Int_t j=0; j<row->GetNofRowSegments(); j++) {
208 AliMpVRowSegment* rowSegment = row->GetRowSegment(j);
210 cout << " ROW Segment " << j
212 << rowSegment->LeftBorderX() << " "
213 << rowSegment->RightBorderX()
215 << 2*rowSegment->Dimensions().X() << " "
222 //_____________________________________________________________________________
223 AliMpRow* AliMpSector::FindRow(const TVector2& position) const
225 // Finds the row for the specified y position.
226 // If y is on border the lowest row is returned.
229 Double_t y = position.Y();
232 for (Int_t i=0; i<GetNofRows(); i++) {
233 if ( y >= fRows[i]->LowBorderY() && y <= fRows[i]->UpperBorderY())
239 for (Int_t i=0; i<GetNofRows(); i++) {
240 if ( y >= ((AliMpRow*)fRows[i])->LowBorderY() &&
241 y <= ((AliMpRow*)fRows[i])->UpperBorderY())
242 return (AliMpRow*)fRows[i];
249 //_____________________________________________________________________________
250 AliMpVMotif* AliMpSector::FindMotif(const TVector2& position) const
252 // Finds the motif in the specified position.
253 // Returns 0 if no motif is found.
256 // Find the row segment
257 AliMpVRowSegment* rowSegment = FindRowSegment(position);
259 if (!rowSegment) return 0;
262 return rowSegment->FindMotif(position);
265 //_____________________________________________________________________________
266 Int_t AliMpSector::FindMotifPositionId(const TVector2& position) const
268 // Finds the motif position ID in the specified position.
269 // Returns 0 if no motif is found.
272 // Find the row segment
273 AliMpVRowSegment* rowSegment = FindRowSegment(position);
275 if (!rowSegment) return 0;
277 // Find motif position ID
278 return rowSegment->FindMotifPositionId(position);
281 //_____________________________________________________________________________
282 AliMpRow* AliMpSector::FindRow(Int_t motifPositionId) const
284 // Finds the row with the the specified motif position.
285 // Returns 0 if no row is found.
288 AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
290 if (segment) return segment->GetRow();
295 //_____________________________________________________________________________
296 AliMpVRowSegment* AliMpSector::FindRowSegment(Int_t motifPositionId) const
298 // Finds the row segment with the the specified motif position.
299 // Returns 0 if no row segment is found.
302 for (Int_t irow=0; irow<GetNofRows(); irow++) {
305 AliMpRow* row = fRows[irow];
308 AliMpRow* row = (AliMpRow*)fRows[irow];
311 for (Int_t iseg=0; iseg<row->GetNofRowSegments(); iseg++) {
312 AliMpVRowSegment* segment = row->GetRowSegment(iseg);
313 if (segment->HasMotifPosition(motifPositionId)) return segment;
320 //_____________________________________________________________________________
321 TVector2 AliMpSector::FindPosition(Int_t motifPositionId) const
323 // Finds the position of the motif specified by its position Id.
324 // Returns 0 if no row segment is found.
327 AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
330 Warning("FindPosition", "Given motifPositionId not found.");
334 return segment->MotifCenter(motifPositionId);
337 //_____________________________________________________________________________
338 AliMpZone* AliMpSector::FindZone(const TVector2& padDimensions) const
340 // Finds the zone with specified padDimensions.
343 for (Int_t i=0; i<GetNofZones(); i++) {
344 AliMpZone* zone = GetZone(i+1);
345 if (AliMpConstants::IsEqual(padDimensions, zone->GetPadDimensions()))
349 // Return 0 if not found
353 //_____________________________________________________________________________
354 TVector2 AliMpSector::Position() const
356 // Returns the offset.
363 //_____________________________________________________________________________
364 TVector2 AliMpSector::Dimensions() const
366 // Returns the maximum halflength in x, y.
371 for (Int_t i=0; i<GetNofRows(); i++) {
374 // take the largest x row dimension
375 if (fRows[i]->Dimensions().X() > x)
376 x = fRows[i]->Dimensions().X();
378 // add all rows y dimensions
379 y += fRows[i]->Dimensions().Y();
383 // take the largest x row dimension
384 if ( ((AliMpRow*)fRows[i])->Dimensions().X() > x)
385 x = ((AliMpRow*)fRows[i])->Dimensions().X();
387 // add all rows y dimensions
388 y += ((AliMpRow*)fRows[i])->Dimensions().Y();
392 return TVector2(x, y);
395 //_____________________________________________________________________________
396 Int_t AliMpSector::GetNofZones() const
398 // Returns the number of zones.
402 return fZones.size();
406 return fZones.GetEntriesFast();
410 //_____________________________________________________________________________
411 AliMpZone* AliMpSector::GetZone(Int_t zoneID) const
413 // Returns zone with specified ID.
416 if (zoneID < 1 || zoneID > GetNofZones()) {
417 Warning("GetZone", "Index outside range");
422 return fZones[zoneID-1];
426 return (AliMpZone*)fZones[zoneID-1];
430 //_____________________________________________________________________________
431 Int_t AliMpSector::GetNofRows() const
433 // Returns the number of rows.
441 return fRows.GetEntriesFast();
445 //_____________________________________________________________________________
446 AliMpRow* AliMpSector::GetRow(Int_t rowID) const
448 // Returns row with specified ID.
451 if (rowID < 0 || rowID >= GetNofRows()) {
452 Warning("GetRow", "Index outside range");
461 return (AliMpRow*)fRows[rowID];