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 "AliMpIntPair.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)),
58 fMaxPadIndices(AliMpIntPair::Invalid()),
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.)),
85 fMaxPadIndices(AliMpIntPair::Invalid()),
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 AliMpIntPair indices(0,0);
168 AliMpRow* rowBefore=0;
169 for (Int_t i=0; i<GetNofRows(); i++) {
170 GetRow(i)->SetGlobalIndices(fDirection, rowBefore);
171 rowBefore = GetRow(i);
175 //_____________________________________________________________________________
176 void AliMpSector::SetMinMaxPadDimensions()
178 /// Set the minimal pad dimensions.
180 for (Int_t i=1; i<GetNofZones()+1; i++) {
181 TVector2 padDimensions = GetZone(i)->GetPadDimensions();
183 if ( (fDirection == AliMp::kX &&
184 padDimensions.Y() > 0. && padDimensions.Y() < fMinPadDimensions.Y()) ||
185 (fDirection == AliMp::kY &&
186 padDimensions.X() > 0. && padDimensions.X() < fMinPadDimensions.X()))
188 fMinPadDimensions = padDimensions;
190 if ( (fDirection == AliMp::kX &&
191 padDimensions.Y() > 0. && padDimensions.Y() > fMaxPadDimensions.Y()) ||
192 (fDirection == AliMp::kY &&
193 padDimensions.X() > 0. && padDimensions.X() > fMinPadDimensions.X()))
195 fMaxPadDimensions = padDimensions;
199 //_____________________________________________________________________________
200 void AliMpSector::SetMaxPadIndices()
202 /// Set maximum pad indices in x, y
204 if ( fMaxPadIndices != AliMpIntPair::Invalid() ) return;
206 Int_t maxIndexInX = 0;
207 Int_t maxIndexInY = 0;
208 for (Int_t i=0; i<GetNofRows(); i++) {
210 Int_t ixh = GetRow(i)->GetHighIndicesLimit().GetFirst();
211 if ( ixh > maxIndexInX ) maxIndexInX = ixh;
213 Int_t iyh = GetRow(i)->GetHighIndicesLimit().GetSecond();
214 if ( iyh > maxIndexInY ) maxIndexInY = iyh;
217 fMaxPadIndices = AliMpIntPair(maxIndexInX, maxIndexInY);
221 //_____________________________________________________________________________
222 void AliMpSector::SetNofPads()
224 /// Set the total number of pads
226 fNofPads = fMotifMap->CalculateNofPads();
233 //_____________________________________________________________________________
234 void AliMpSector::SetRowSegmentOffsets()
236 /// For all rows set the offset to all row segments.
238 for (Int_t irow=0; irow<GetNofRows(); irow++)
239 GetRow(irow)->SetRowSegmentOffsets(fOffset);
242 //_____________________________________________________________________________
243 void AliMpSector::Initialize()
245 /// Make needed settings after sector is read from
251 SetMinMaxPadDimensions();
256 //_____________________________________________________________________________
257 void AliMpSector::PrintGeometry() const
259 /// Print the positions of rows, rows segments
261 for (Int_t i=0; i<GetNofRows(); i++) {
262 AliMpRow* row = GetRow(i);
264 cout << "ROW " << row->GetID()
265 << " center Y " << row->Position().Y() << endl;
267 for (Int_t j=0; j<row->GetNofRowSegments(); j++) {
268 AliMpVRowSegment* rowSegment = row->GetRowSegment(j);
270 cout << " ROW Segment " << j
272 << rowSegment->LeftBorderX() << " "
273 << rowSegment->RightBorderX()
275 << 2*rowSegment->Dimensions().X() << " "
282 //_____________________________________________________________________________
283 AliMpRow* AliMpSector::FindRow(const TVector2& position) const
285 /// Find the row for the specified y position. \n
286 /// If y is on border the lowest row is returned.
288 Double_t y = position.Y();
290 for (Int_t i=0; i<GetNofRows(); i++) {
291 if ( y >= ((AliMpRow*)fRows[i])->LowBorderY() &&
292 y <= ((AliMpRow*)fRows[i])->UpperBorderY())
293 return (AliMpRow*)fRows[i];
299 //_____________________________________________________________________________
300 AliMpVMotif* AliMpSector::FindMotif(const TVector2& position) const
302 /// Find the motif in the specified position. \n
303 /// Return 0 if no motif is found.
305 // Find the row segment
306 AliMpVRowSegment* rowSegment = FindRowSegment(position);
308 if (!rowSegment) return 0;
311 return rowSegment->FindMotif(position);
313 //_____________________________________________________________________________
314 Int_t AliMpSector::FindMotifPositionId(const TVector2& position) const
316 /// Find the motif position ID in the specified position. \n
317 /// Return 0 if no motif is found.
319 // Find the row segment
320 AliMpVRowSegment* rowSegment = FindRowSegment(position);
322 if (!rowSegment) return 0;
324 // Find motif position ID
325 return rowSegment->FindMotifPositionId(position);
328 //_____________________________________________________________________________
329 AliMpRow* AliMpSector::FindRow(Int_t motifPositionId) const
331 /// Find the row with the the specified motif position. \n
332 /// Return 0 if no row is found.
334 AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
336 if (segment) return segment->GetRow();
341 //_____________________________________________________________________________
342 AliMpVRowSegment* AliMpSector::FindRowSegment(Int_t motifPositionId) const
344 /// Find the row segment with the the specified motif position. \n
345 /// Return 0 if no row segment is found.
347 for (Int_t irow=0; irow<GetNofRows(); irow++) {
349 AliMpRow* row = (AliMpRow*)fRows[irow];
351 for (Int_t iseg=0; iseg<row->GetNofRowSegments(); iseg++) {
352 AliMpVRowSegment* segment = row->GetRowSegment(iseg);
353 if (segment->HasMotifPosition(motifPositionId)) return segment;
360 //_____________________________________________________________________________
361 TVector2 AliMpSector::FindPosition(Int_t motifPositionId) const
363 /// Find the position of the motif specified by its position Id. \n
364 /// Return 0 if no row segment is found.
366 AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
369 AliWarningStream() << "Given motifPositionId not found." << endl;
373 return segment->MotifCenter(motifPositionId);
376 //_____________________________________________________________________________
377 AliMpZone* AliMpSector::FindZone(const TVector2& padDimensions) const
379 /// Find the zone with specified padDimensions.
381 for (Int_t i=0; i<GetNofZones(); i++) {
382 AliMpZone* zone = GetZone(i+1);
383 if (AliMpConstants::IsEqual(padDimensions, zone->GetPadDimensions()))
387 // Return 0 if not found
391 //_____________________________________________________________________________
392 TVector2 AliMpSector::Position() const
394 /// Return the sector offset.
400 //_____________________________________________________________________________
401 TVector2 AliMpSector::Dimensions() const
403 /// Return the maximum halflengths in x, y.
407 for (Int_t i=0; i<GetNofRows(); i++) {
409 // take the largest x row dimension
410 if ( ((AliMpRow*)fRows[i])->Dimensions().X() > x)
411 x = ((AliMpRow*)fRows[i])->Dimensions().X();
413 // add all rows y dimensions
414 y += ((AliMpRow*)fRows[i])->Dimensions().Y();
417 return TVector2(x, y);
420 //_____________________________________________________________________________
421 Int_t AliMpSector::GetNofZones() const
423 /// Return the number of zones.
425 return fZones.GetEntriesFast();
428 //_____________________________________________________________________________
429 AliMpZone* AliMpSector::GetZone(Int_t zoneID) const
431 /// Return zone with specified ID.
433 if (zoneID < 1 || zoneID > GetNofZones()) {
434 AliWarningStream() << "Index outside range" << endl;
438 return (AliMpZone*)fZones[zoneID-1];
441 //_____________________________________________________________________________
442 Int_t AliMpSector::GetNofRows() const
444 /// Return the number of rows.
446 return fRows.GetEntriesFast();
449 //_____________________________________________________________________________
450 AliMpRow* AliMpSector::GetRow(Int_t rowID) const
452 /// Return row with specified ID.
454 if (rowID < 0 || rowID >= GetNofRows()) {
455 AliWarningStream() << "Index outside range" << endl;
459 return (AliMpRow*)fRows[rowID];
462 //_____________________________________________________________________________
464 AliMpSector::GetPlaneType() const
466 /// Return the plane type
468 return GetDirection()==AliMp::kY ? AliMp::kBendingPlane : AliMp::kNonBendingPlane;
471 //_____________________________________________________________________________
473 AliMpSector::GetNofMotifPositions() const
475 /// Return the number of manus
477 return fMotifMap->GetNofMotifPositions();
480 //_____________________________________________________________________________
482 AliMpSector::GetAllMotifPositionsIDs(TArrayI& ecn) const
484 /// Return the array of all motif positions IDs
486 fMotifMap->GetAllMotifPositionsIDs(ecn);
489 //_____________________________________________________________________________
491 AliMpSector::Print(Option_t* opt) const
493 /// Print the map of motifs
495 cout << "Sector," << PlaneTypeName(GetPlaneType()) << endl;
496 fMotifMap->Print(opt);