1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 // $MpId: AliMpSector.cxx,v 1.14 2006/05/24 13:58:46 ivana Exp $
20 //-----------------------------------------------------------------------------
23 // Class describing the sector of the MUON chamber of station 1.
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 //-----------------------------------------------------------------------------
28 #include "AliMpSector.h"
29 #include "AliMpSectorPadIterator.h"
30 #include "AliMpZone.h"
32 #include "AliMpVRowSegment.h"
33 #include "AliMpVMotif.h"
34 #include "AliMpMotifMap.h"
35 #include "AliMpEncodePair.h"
36 #include "AliMpConstants.h"
40 #include <Riostream.h>
46 //_____________________________________________________________________________
47 AliMpSector::AliMpSector(const TString& id, Int_t nofZones, Int_t nofRows,
48 AliMp::Direction direction, const TVector2& offset)
49 : TNamed("Sector", ""),
55 fDirection(direction),
56 fMinPadDimensions(TVector2(1.e6, 1.e6)),
61 /// Standard constructor
63 AliDebugStream(1) << "this = " << this << endl;
65 fMotifMap = new AliMpMotifMap;
67 for (Int_t izone = 0; izone<nofZones; izone++)
68 fZones.Add(new AliMpZone(izone+1));
70 for (Int_t irow = 0; irow<nofRows; irow++)
71 fRows.Add(new AliMpRow(irow, fMotifMap));
74 //_____________________________________________________________________________
75 AliMpSector::AliMpSector()
78 fOffset(TVector2(0., 0.)),
82 fDirection(AliMp::kX),
83 fMinPadDimensions(TVector2(0., 0.)),
88 /// Default constructor
90 AliDebugStream(1) << "this = " << this << endl;
93 //_____________________________________________________________________________
94 AliMpSector::~AliMpSector()
98 AliDebugStream(1) << "this = " << this << endl;
101 for (Int_t izone = 0; izone<GetNofZones(); izone++)
102 delete fZones[izone];
104 for (Int_t irow = 0; irow<GetNofRows(); irow++)
114 //_____________________________________________________________________________
115 AliMpVPadIterator* AliMpSector::CreateIterator() const
117 /// Create sector pad iterator
119 return new AliMpSectorPadIterator(this);
123 //_____________________________________________________________________________
124 AliMpVRowSegment* AliMpSector::FindRowSegment(const TVector2& position) const
126 /// Find the row segment in the specified position. \n
127 /// Return if no motif is found.
130 AliMpRow* row = FindRow(position);
134 // Find the row segment and return its motif
135 AliMpVRowSegment* rowSegment = row->FindRowSegment(position.X());
140 //_____________________________________________________________________________
141 void AliMpSector::SetRowOffsets()
143 /// For each row check consitency of the row segments
144 /// and calculate the row offset.
146 Double_t offset = fOffset.Y();
148 for (Int_t irow=0; irow<GetNofRows(); irow++)
149 offset = GetRow(irow)->SetOffsetY(offset);
152 //_____________________________________________________________________________
153 void AliMpSector::SetMotifPositions()
155 /// Create motif positions objects and fills them in the motif map.
157 for (Int_t i=0; i<GetNofRows(); i++)
158 GetRow(i)->SetMotifPositions();
161 //_____________________________________________________________________________
162 void AliMpSector::SetGlobalIndices()
164 /// Set the indices limits to all indexed elements
165 /// (row, row segment, motif positions).
167 AliMpRow* rowBefore=0;
168 for (Int_t i=0; i<GetNofRows(); i++) {
169 GetRow(i)->SetGlobalIndices(fDirection, rowBefore);
170 rowBefore = GetRow(i);
174 //_____________________________________________________________________________
175 void AliMpSector::SetMinMaxPadDimensions()
177 /// Set the minimal pad dimensions.
179 for (Int_t i=1; i<GetNofZones()+1; i++) {
180 TVector2 padDimensions = GetZone(i)->GetPadDimensions();
182 if ( (fDirection == AliMp::kX &&
183 padDimensions.Y() > 0. && padDimensions.Y() < fMinPadDimensions.Y()) ||
184 (fDirection == AliMp::kY &&
185 padDimensions.X() > 0. && padDimensions.X() < fMinPadDimensions.X()))
187 fMinPadDimensions = padDimensions;
189 if ( (fDirection == AliMp::kX &&
190 padDimensions.Y() > 0. && padDimensions.Y() > fMaxPadDimensions.Y()) ||
191 (fDirection == AliMp::kY &&
192 padDimensions.X() > 0. && padDimensions.X() > fMinPadDimensions.X()))
194 fMaxPadDimensions = padDimensions;
198 //_____________________________________________________________________________
199 void AliMpSector::SetMaxPadIndices()
201 /// Set maximum pad indices in x, y
203 if ( fLMaxPadIndices != 0 ) return;
205 Int_t maxIndexInX = 0;
206 Int_t maxIndexInY = 0;
207 for (Int_t i=0; i<GetNofRows(); i++) {
209 Int_t ixh = GetRow(i)->GetHighLimitIx();
210 if ( ixh > maxIndexInX ) maxIndexInX = ixh;
212 Int_t iyh = GetRow(i)->GetHighLimitIy();
213 if ( iyh > maxIndexInY ) maxIndexInY = iyh;
216 fLMaxPadIndices = AliMp::Pair(maxIndexInX, maxIndexInY);
220 //_____________________________________________________________________________
221 void AliMpSector::SetNofPads()
223 /// Set the total number of pads
225 fNofPads = fMotifMap->CalculateNofPads();
232 //_____________________________________________________________________________
233 void AliMpSector::SetRowSegmentOffsets()
235 /// For all rows set the offset to all row segments.
237 for (Int_t irow=0; irow<GetNofRows(); irow++)
238 GetRow(irow)->SetRowSegmentOffsets(fOffset);
241 //_____________________________________________________________________________
242 void AliMpSector::Initialize()
244 /// Make needed settings after sector is read from
250 SetMinMaxPadDimensions();
255 //_____________________________________________________________________________
256 void AliMpSector::PrintGeometry() const
258 /// Print the positions of rows, rows segments
260 for (Int_t i=0; i<GetNofRows(); i++) {
261 AliMpRow* row = GetRow(i);
263 cout << "ROW " << row->GetID()
264 << " center Y " << row->Position().Y() << endl;
266 for (Int_t j=0; j<row->GetNofRowSegments(); j++) {
267 AliMpVRowSegment* rowSegment = row->GetRowSegment(j);
269 cout << " ROW Segment " << j
271 << rowSegment->LeftBorderX() << " "
272 << rowSegment->RightBorderX()
274 << 2*rowSegment->Dimensions().X() << " "
281 //_____________________________________________________________________________
282 AliMpRow* AliMpSector::FindRow(const TVector2& position) const
284 /// Find the row for the specified y position. \n
285 /// If y is on border the lowest row is returned.
287 Double_t y = position.Y();
289 for (Int_t i=0; i<GetNofRows(); i++) {
290 if ( y >= ((AliMpRow*)fRows[i])->LowBorderY() &&
291 y <= ((AliMpRow*)fRows[i])->UpperBorderY())
292 return (AliMpRow*)fRows[i];
298 //_____________________________________________________________________________
299 AliMpVMotif* AliMpSector::FindMotif(const TVector2& position) const
301 /// Find the motif in the specified position. \n
302 /// Return 0 if no motif is found.
304 // Find the row segment
305 AliMpVRowSegment* rowSegment = FindRowSegment(position);
307 if (!rowSegment) return 0;
310 return rowSegment->FindMotif(position);
312 //_____________________________________________________________________________
313 Int_t AliMpSector::FindMotifPositionId(const TVector2& position) const
315 /// Find the motif position ID in the specified position. \n
316 /// Return 0 if no motif is found.
318 // Find the row segment
319 AliMpVRowSegment* rowSegment = FindRowSegment(position);
321 if (!rowSegment) return 0;
323 // Find motif position ID
324 return rowSegment->FindMotifPositionId(position);
327 //_____________________________________________________________________________
328 AliMpRow* AliMpSector::FindRow(Int_t motifPositionId) const
330 /// Find the row with the the specified motif position. \n
331 /// Return 0 if no row is found.
333 AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
335 if (segment) return segment->GetRow();
340 //_____________________________________________________________________________
341 AliMpVRowSegment* AliMpSector::FindRowSegment(Int_t motifPositionId) const
343 /// Find the row segment with the the specified motif position. \n
344 /// Return 0 if no row segment is found.
346 for (Int_t irow=0; irow<GetNofRows(); irow++) {
348 AliMpRow* row = (AliMpRow*)fRows[irow];
350 for (Int_t iseg=0; iseg<row->GetNofRowSegments(); iseg++) {
351 AliMpVRowSegment* segment = row->GetRowSegment(iseg);
352 if (segment->HasMotifPosition(motifPositionId)) return segment;
359 //_____________________________________________________________________________
360 TVector2 AliMpSector::FindPosition(Int_t motifPositionId) const
362 /// Find the position of the motif specified by its position Id. \n
363 /// Return 0 if no row segment is found.
365 AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
368 AliWarningStream() << "Given motifPositionId not found." << endl;
372 return segment->MotifCenter(motifPositionId);
375 //_____________________________________________________________________________
376 AliMpZone* AliMpSector::FindZone(const TVector2& padDimensions) const
378 /// Find the zone with specified padDimensions.
380 for (Int_t i=0; i<GetNofZones(); i++) {
381 AliMpZone* zone = GetZone(i+1);
382 if (AliMpConstants::IsEqual(padDimensions, zone->GetPadDimensions()))
386 // Return 0 if not found
390 //_____________________________________________________________________________
391 TVector2 AliMpSector::Position() const
393 /// Return the sector offset.
399 //_____________________________________________________________________________
400 TVector2 AliMpSector::Dimensions() const
402 /// Return the maximum halflengths in x, y.
406 for (Int_t i=0; i<GetNofRows(); i++) {
408 // take the largest x row dimension
409 if ( ((AliMpRow*)fRows[i])->Dimensions().X() > x)
410 x = ((AliMpRow*)fRows[i])->Dimensions().X();
412 // add all rows y dimensions
413 y += ((AliMpRow*)fRows[i])->Dimensions().Y();
416 return TVector2(x, y);
419 //_____________________________________________________________________________
420 Int_t AliMpSector::GetNofZones() const
422 /// Return the number of zones.
424 return fZones.GetEntriesFast();
427 //_____________________________________________________________________________
428 AliMpZone* AliMpSector::GetZone(Int_t zoneID) const
430 /// Return zone with specified ID.
432 if (zoneID < 1 || zoneID > GetNofZones()) {
433 AliWarningStream() << "Index outside range" << endl;
437 return (AliMpZone*)fZones[zoneID-1];
440 //_____________________________________________________________________________
441 Int_t AliMpSector::GetNofRows() const
443 /// Return the number of rows.
445 return fRows.GetEntriesFast();
448 //_____________________________________________________________________________
449 AliMpRow* AliMpSector::GetRow(Int_t rowID) const
451 /// Return row with specified ID.
453 if (rowID < 0 || rowID >= GetNofRows()) {
454 AliWarningStream() << "Index outside range" << endl;
458 return (AliMpRow*)fRows[rowID];
461 //_____________________________________________________________________________
463 AliMpSector::GetPlaneType() const
465 /// Return the plane type
467 return GetDirection()==AliMp::kY ? AliMp::kBendingPlane : AliMp::kNonBendingPlane;
470 //_____________________________________________________________________________
472 AliMpSector::GetNofMotifPositions() const
474 /// Return the number of manus
476 return fMotifMap->GetNofMotifPositions();
479 //_____________________________________________________________________________
481 AliMpSector::GetAllMotifPositionsIDs(TArrayI& ecn) const
483 /// Return the array of all motif positions IDs
485 fMotifMap->GetAllMotifPositionsIDs(ecn);
488 //_____________________________________________________________________________
490 AliMpSector::Print(Option_t* opt) const
492 /// Print the map of motifs
494 cout << "Sector," << PlaneTypeName(GetPlaneType()) << endl;
495 fMotifMap->Print(opt);