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;
68 for (Int_t izone = 0; izone<nofZones; izone++)
69 fZones.push_back(new AliMpZone(izone+1));
71 for (Int_t irow = 0; irow<nofRows; irow++)
72 fRows.push_back(new AliMpRow(irow, fMotifMap));
76 for (Int_t izone = 0; izone<nofZones; izone++)
77 fZones.Add(new AliMpZone(izone+1));
79 for (Int_t irow = 0; irow<nofRows; irow++)
80 fRows.Add(new AliMpRow(irow, fMotifMap));
84 //_____________________________________________________________________________
85 AliMpSector::AliMpSector()
88 fOffset(TVector2(0., 0.)),
92 fDirection(AliMp::kX),
93 fMinPadDimensions(TVector2(0., 0.)),
95 fMaxPadIndices(AliMpIntPair::Invalid()),
98 /// Default constructor
100 AliDebugStream(1) << "this = " << this << endl;
103 //_____________________________________________________________________________
104 AliMpSector::~AliMpSector()
108 AliDebugStream(1) << "this = " << this << endl;
111 for (Int_t izone = 0; izone<GetNofZones(); izone++)
112 delete fZones[izone];
114 for (Int_t irow = 0; irow<GetNofRows(); irow++)
124 //_____________________________________________________________________________
125 AliMpVPadIterator* AliMpSector::CreateIterator() const
127 /// Create sector pad iterator
129 return new AliMpSectorPadIterator(this);
133 //_____________________________________________________________________________
134 AliMpVRowSegment* AliMpSector::FindRowSegment(const TVector2& position) const
136 /// Find the row segment in the specified position. \n
137 /// Return if no motif is found.
140 AliMpRow* row = FindRow(position);
144 // Find the row segment and return its motif
145 AliMpVRowSegment* rowSegment = row->FindRowSegment(position.X());
150 //_____________________________________________________________________________
151 void AliMpSector::SetRowOffsets()
153 /// For each row check consitency of the row segments
154 /// and calculate the row offset.
156 Double_t offset = fOffset.Y();
158 for (Int_t irow=0; irow<GetNofRows(); irow++)
159 offset = GetRow(irow)->SetOffsetY(offset);
162 //_____________________________________________________________________________
163 void AliMpSector::SetMotifPositions()
165 /// Create motif positions objects and fills them in the motif map.
167 for (Int_t i=0; i<GetNofRows(); i++)
168 GetRow(i)->SetMotifPositions();
171 //_____________________________________________________________________________
172 void AliMpSector::SetGlobalIndices()
174 /// Set the indices limits to all indexed elements
175 /// (row, row segment, motif positions).
177 AliMpIntPair indices(0,0);
178 AliMpRow* rowBefore=0;
179 for (Int_t i=0; i<GetNofRows(); i++) {
180 GetRow(i)->SetGlobalIndices(fDirection, rowBefore);
181 rowBefore = GetRow(i);
185 //_____________________________________________________________________________
186 void AliMpSector::SetMinMaxPadDimensions()
188 /// Set the minimal pad dimensions.
190 for (Int_t i=1; i<GetNofZones()+1; i++) {
191 TVector2 padDimensions = GetZone(i)->GetPadDimensions();
193 if ( (fDirection == AliMp::kX &&
194 padDimensions.Y() > 0. && padDimensions.Y() < fMinPadDimensions.Y()) ||
195 (fDirection == AliMp::kY &&
196 padDimensions.X() > 0. && padDimensions.X() < fMinPadDimensions.X()))
198 fMinPadDimensions = padDimensions;
200 if ( (fDirection == AliMp::kX &&
201 padDimensions.Y() > 0. && padDimensions.Y() > fMaxPadDimensions.Y()) ||
202 (fDirection == AliMp::kY &&
203 padDimensions.X() > 0. && padDimensions.X() > fMinPadDimensions.X()))
205 fMaxPadDimensions = padDimensions;
209 //_____________________________________________________________________________
210 void AliMpSector::SetMaxPadIndices()
212 /// Set maximum pad indices in x, y
214 if ( fMaxPadIndices != AliMpIntPair::Invalid() ) return;
216 Int_t maxIndexInX = 0;
217 Int_t maxIndexInY = 0;
218 for (Int_t i=0; i<GetNofRows(); i++) {
220 Int_t ixh = GetRow(i)->GetHighIndicesLimit().GetFirst();
221 if ( ixh > maxIndexInX ) maxIndexInX = ixh;
223 Int_t iyh = GetRow(i)->GetHighIndicesLimit().GetSecond();
224 if ( iyh > maxIndexInY ) maxIndexInY = iyh;
227 fMaxPadIndices = AliMpIntPair(maxIndexInX, maxIndexInY);
231 //_____________________________________________________________________________
232 void AliMpSector::SetNofPads()
234 /// Set the total number of pads
236 fNofPads = fMotifMap->CalculateNofPads();
243 //_____________________________________________________________________________
244 void AliMpSector::SetRowSegmentOffsets()
246 /// For all rows set the offset to all row segments.
248 for (Int_t irow=0; irow<GetNofRows(); irow++)
249 GetRow(irow)->SetRowSegmentOffsets(fOffset);
252 //_____________________________________________________________________________
253 void AliMpSector::Initialize()
255 /// Make needed settings after sector is read from
261 SetMinMaxPadDimensions();
266 //_____________________________________________________________________________
267 void AliMpSector::PrintGeometry() const
269 /// Print the positions of rows, rows segments
271 for (Int_t i=0; i<GetNofRows(); i++) {
272 AliMpRow* row = GetRow(i);
274 cout << "ROW " << row->GetID()
275 << " center Y " << row->Position().Y() << endl;
277 for (Int_t j=0; j<row->GetNofRowSegments(); j++) {
278 AliMpVRowSegment* rowSegment = row->GetRowSegment(j);
280 cout << " ROW Segment " << j
282 << rowSegment->LeftBorderX() << " "
283 << rowSegment->RightBorderX()
285 << 2*rowSegment->Dimensions().X() << " "
292 //_____________________________________________________________________________
293 AliMpRow* AliMpSector::FindRow(const TVector2& position) const
295 /// Find the row for the specified y position. \n
296 /// If y is on border the lowest row is returned.
298 Double_t y = position.Y();
301 for (Int_t i=0; i<GetNofRows(); i++) {
302 if ( y >= fRows[i]->LowBorderY() && y <= fRows[i]->UpperBorderY())
308 for (Int_t i=0; i<GetNofRows(); i++) {
309 if ( y >= ((AliMpRow*)fRows[i])->LowBorderY() &&
310 y <= ((AliMpRow*)fRows[i])->UpperBorderY())
311 return (AliMpRow*)fRows[i];
318 //_____________________________________________________________________________
319 AliMpVMotif* AliMpSector::FindMotif(const TVector2& position) const
321 /// Find the motif in the specified position. \n
322 /// Return 0 if no motif is found.
324 // Find the row segment
325 AliMpVRowSegment* rowSegment = FindRowSegment(position);
327 if (!rowSegment) return 0;
330 return rowSegment->FindMotif(position);
332 //_____________________________________________________________________________
333 Int_t AliMpSector::FindMotifPositionId(const TVector2& position) const
335 /// Find the motif position ID in the specified position. \n
336 /// Return 0 if no motif is found.
338 // Find the row segment
339 AliMpVRowSegment* rowSegment = FindRowSegment(position);
341 if (!rowSegment) return 0;
343 // Find motif position ID
344 return rowSegment->FindMotifPositionId(position);
347 //_____________________________________________________________________________
348 AliMpRow* AliMpSector::FindRow(Int_t motifPositionId) const
350 /// Find the row with the the specified motif position. \n
351 /// Return 0 if no row is found.
353 AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
355 if (segment) return segment->GetRow();
360 //_____________________________________________________________________________
361 AliMpVRowSegment* AliMpSector::FindRowSegment(Int_t motifPositionId) const
363 /// Find the row segment with the the specified motif position. \n
364 /// Return 0 if no row segment is found.
366 for (Int_t irow=0; irow<GetNofRows(); irow++) {
369 AliMpRow* row = fRows[irow];
372 AliMpRow* row = (AliMpRow*)fRows[irow];
375 for (Int_t iseg=0; iseg<row->GetNofRowSegments(); iseg++) {
376 AliMpVRowSegment* segment = row->GetRowSegment(iseg);
377 if (segment->HasMotifPosition(motifPositionId)) return segment;
384 //_____________________________________________________________________________
385 TVector2 AliMpSector::FindPosition(Int_t motifPositionId) const
387 /// Find the position of the motif specified by its position Id. \n
388 /// Return 0 if no row segment is found.
390 AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
393 AliWarningStream() << "Given motifPositionId not found." << endl;
397 return segment->MotifCenter(motifPositionId);
400 //_____________________________________________________________________________
401 AliMpZone* AliMpSector::FindZone(const TVector2& padDimensions) const
403 /// Find the zone with specified padDimensions.
405 for (Int_t i=0; i<GetNofZones(); i++) {
406 AliMpZone* zone = GetZone(i+1);
407 if (AliMpConstants::IsEqual(padDimensions, zone->GetPadDimensions()))
411 // Return 0 if not found
415 //_____________________________________________________________________________
416 TVector2 AliMpSector::Position() const
418 /// Return the sector offset.
424 //_____________________________________________________________________________
425 TVector2 AliMpSector::Dimensions() const
427 /// Return the maximum halflengths in x, y.
431 for (Int_t i=0; i<GetNofRows(); i++) {
434 // take the largest x row dimension
435 if (fRows[i]->Dimensions().X() > x)
436 x = fRows[i]->Dimensions().X();
438 // add all rows y dimensions
439 y += fRows[i]->Dimensions().Y();
443 // take the largest x row dimension
444 if ( ((AliMpRow*)fRows[i])->Dimensions().X() > x)
445 x = ((AliMpRow*)fRows[i])->Dimensions().X();
447 // add all rows y dimensions
448 y += ((AliMpRow*)fRows[i])->Dimensions().Y();
452 return TVector2(x, y);
455 //_____________________________________________________________________________
456 Int_t AliMpSector::GetNofZones() const
458 /// Return the number of zones.
461 return fZones.size();
465 return fZones.GetEntriesFast();
469 //_____________________________________________________________________________
470 AliMpZone* AliMpSector::GetZone(Int_t zoneID) const
472 /// Return zone with specified ID.
474 if (zoneID < 1 || zoneID > GetNofZones()) {
475 AliWarningStream() << "Index outside range" << endl;
480 return fZones[zoneID-1];
484 return (AliMpZone*)fZones[zoneID-1];
488 //_____________________________________________________________________________
489 Int_t AliMpSector::GetNofRows() const
491 /// Return the number of rows.
498 return fRows.GetEntriesFast();
502 //_____________________________________________________________________________
503 AliMpRow* AliMpSector::GetRow(Int_t rowID) const
505 /// Return row with specified ID.
507 if (rowID < 0 || rowID >= GetNofRows()) {
508 AliWarningStream() << "Index outside range" << endl;
517 return (AliMpRow*)fRows[rowID];
521 //_____________________________________________________________________________
523 AliMpSector::GetPlaneType() const
525 /// Return the plane type
527 return GetDirection()==AliMp::kY ? AliMp::kBendingPlane : AliMp::kNonBendingPlane;
530 //_____________________________________________________________________________
532 AliMpSector::GetNofMotifPositions() const
534 /// Return the number of manus
536 return fMotifMap->GetNofMotifPositions();
539 //_____________________________________________________________________________
541 AliMpSector::GetAllMotifPositionsIDs(TArrayI& ecn) const
543 /// Return the array of all motif positions IDs
545 fMotifMap->GetAllMotifPositionsIDs(ecn);
548 //_____________________________________________________________________________
550 AliMpSector::Print(Option_t* opt) const
552 /// Print the map of motifs
554 cout << "Sector," << PlaneTypeName(GetPlaneType()) << endl;
555 fMotifMap->Print(opt);