]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSector.cxx
- All mapping enums within namespace (AliMp).
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSector.cxx
CommitLineData
dee1d5f1 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
5f91c9e8 16// $Id$
13985652 17// $MpId: AliMpSector.cxx,v 1.14 2006/05/24 13:58:46 ivana Exp $
5f91c9e8 18// Category: sector
19//
20// Class AliMpSector
21// -----------------
22// Class describing the sector of the MUON chamber of station 1.
dbe945cc 23// Included in AliRoot: 2003/05/02
5f91c9e8 24// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
25
5f91c9e8 26#include "AliMpSector.h"
27#include "AliMpSectorPadIterator.h"
28#include "AliMpZone.h"
29#include "AliMpRow.h"
30#include "AliMpVRowSegment.h"
31#include "AliMpVMotif.h"
32#include "AliMpMotifMap.h"
33#include "AliMpIntPair.h"
34#include "AliMpConstants.h"
35
cddd101e 36#include "AliLog.h"
37
2c605e66 38#include <Riostream.h>
39
13985652 40/// \cond CLASSIMP
5f91c9e8 41ClassImp(AliMpSector)
13985652 42/// \endcond
5f91c9e8 43
44//_____________________________________________________________________________
d1d8330f 45AliMpSector::AliMpSector(const TString& id, Int_t nofZones, Int_t nofRows,
cddd101e 46 AliMp::Direction direction, const TVector2& offset)
5006ec94 47 : TNamed("Sector", ""),
5f91c9e8 48 fID(id),
14b7b896 49 fOffset(offset),
5f91c9e8 50 fZones(),
51 fRows(),
13e7956b 52 fMotifMap(0),
5f91c9e8 53 fDirection(direction),
f9a3ff6a 54 fMinPadDimensions(TVector2(1.e6, 1.e6)),
55 fMaxPadIndices(AliMpIntPair::Invalid()),
56 fNofPads(0)
5f91c9e8 57{
dee1d5f1 58/// Standard constructor
59
642b74ab 60 AliDebugStream(1) << "this = " << this << endl;
61
5006ec94 62 fMotifMap = new AliMpMotifMap(true);
63 //fMotifMap = new AliMpMotifMap();
5f91c9e8 64
f79c58a5 65#ifdef WITH_STL
5f91c9e8 66 for (Int_t izone = 0; izone<nofZones; izone++)
67 fZones.push_back(new AliMpZone(izone+1));
68
69 for (Int_t irow = 0; irow<nofRows; irow++)
70 fRows.push_back(new AliMpRow(irow, fMotifMap));
f79c58a5 71#endif
72
73#ifdef WITH_ROOT
74 for (Int_t izone = 0; izone<nofZones; izone++)
75 fZones.Add(new AliMpZone(izone+1));
76
77 for (Int_t irow = 0; irow<nofRows; irow++)
78 fRows.Add(new AliMpRow(irow, fMotifMap));
79#endif
5f91c9e8 80}
81
82//_____________________________________________________________________________
83AliMpSector::AliMpSector()
5006ec94 84 : TNamed(),
5f91c9e8 85 fID(""),
86 fOffset(TVector2(0., 0.)),
87 fZones(),
88 fRows(),
89 fMotifMap(0),
cddd101e 90 fDirection(AliMp::kX),
f9a3ff6a 91 fMinPadDimensions(TVector2(0., 0.)),
92 fMaxPadIndices(AliMpIntPair::Invalid()),
93 fNofPads(0)
5f91c9e8 94{
dee1d5f1 95/// Default constructor
642b74ab 96
97 AliDebugStream(1) << "this = " << this << endl;
5f91c9e8 98}
99
100//_____________________________________________________________________________
dee1d5f1 101AliMpSector::~AliMpSector()
102{
103/// Destructor
104
642b74ab 105 AliDebugStream(1) << "this = " << this << endl;
106
5f91c9e8 107 // deletes
108 for (Int_t izone = 0; izone<GetNofZones(); izone++)
109 delete fZones[izone];
110
111 for (Int_t irow = 0; irow<GetNofRows(); irow++)
112 delete fRows[irow];
113
114 delete fMotifMap;
115}
116
117//
118// private methods
119//
120
121//_____________________________________________________________________________
122AliMpVPadIterator* AliMpSector::CreateIterator() const
123{
dee1d5f1 124/// Create sector pad iterator
125
5f91c9e8 126 return new AliMpSectorPadIterator(this);
127}
128
129
130//_____________________________________________________________________________
131AliMpVRowSegment* AliMpSector::FindRowSegment(const TVector2& position) const
132{
dee1d5f1 133/// Find the row segment in the specified position. \n
134/// Return if no motif is found.
5f91c9e8 135
136 // Find row
137 AliMpRow* row = FindRow(position);
138
139 if (!row) return 0;
140
141 // Find the row segment and return its motif
142 AliMpVRowSegment* rowSegment = row->FindRowSegment(position.X());
143
144 return rowSegment;
145}
146
147//_____________________________________________________________________________
148void AliMpSector::SetRowOffsets()
149{
dee1d5f1 150/// For each row check consitency of the row segments
151/// and calculate the row offset.
5f91c9e8 152
153 Double_t offset = fOffset.Y();
154
f79c58a5 155 for (Int_t irow=0; irow<GetNofRows(); irow++)
5f91c9e8 156 offset = GetRow(irow)->SetOffsetY(offset);
157}
158
159//_____________________________________________________________________________
160void AliMpSector::SetMotifPositions()
161{
dee1d5f1 162/// Create motif positions objects and fills them in the motif map.
5f91c9e8 163
f79c58a5 164 for (Int_t i=0; i<GetNofRows(); i++)
5f91c9e8 165 GetRow(i)->SetMotifPositions();
166}
167
168//_____________________________________________________________________________
169void AliMpSector::SetGlobalIndices()
170{
dee1d5f1 171/// Set the indices limits to all indexed elements
172/// (row, row segment, motif positions).
5f91c9e8 173
174 AliMpIntPair indices(0,0);
175 AliMpRow* rowBefore=0;
f79c58a5 176 for (Int_t i=0; i<GetNofRows(); i++) {
5f91c9e8 177 GetRow(i)->SetGlobalIndices(fDirection, rowBefore);
178 rowBefore = GetRow(i);
179 }
180}
181
182//_____________________________________________________________________________
183void AliMpSector::SetMinPadDimensions()
184{
dee1d5f1 185/// Set the minimal pad dimensions.
5f91c9e8 186
187 for (Int_t i=1; i<GetNofZones()+1; i++) {
188 TVector2 padDimensions = GetZone(i)->GetPadDimensions();
189
cddd101e 190 if ( fDirection == AliMp::kX &&
5f91c9e8 191 padDimensions.Y() > 0. && padDimensions.Y() < fMinPadDimensions.Y() ||
cddd101e 192 fDirection == AliMp::kY &&
5f91c9e8 193 padDimensions.X() > 0. && padDimensions.X() < fMinPadDimensions.X())
194
195 fMinPadDimensions = padDimensions;
196 }
197}
198
f9a3ff6a 199//_____________________________________________________________________________
200void AliMpSector::SetMaxPadIndices()
201{
202/// Set maximum pad indices in x, y
203
204 if ( fMaxPadIndices != AliMpIntPair::Invalid() ) return;
205
206 Int_t maxIndexInX = 0;
207 Int_t maxIndexInY = 0;
208 for (Int_t i=0; i<GetNofRows(); i++) {
209
210 Int_t ixh = GetRow(i)->GetHighIndicesLimit().GetFirst();
211 if ( ixh > maxIndexInX ) maxIndexInX = ixh;
212
213 Int_t iyh = GetRow(i)->GetHighIndicesLimit().GetSecond();
214 if ( iyh > maxIndexInY ) maxIndexInY = iyh;
215 }
216
217 fMaxPadIndices = AliMpIntPair(maxIndexInX, maxIndexInY);
218}
219
220
221//_____________________________________________________________________________
222void AliMpSector::SetNofPads()
223{
224/// Set the total number of pads
225
226 fNofPads = fMotifMap->CalculateNofPads();
227}
228
5f91c9e8 229//
230// public methods
231//
232
233//_____________________________________________________________________________
234void AliMpSector::SetRowSegmentOffsets()
235{
dee1d5f1 236/// For all rows set the offset to all row segments.
5f91c9e8 237
f79c58a5 238 for (Int_t irow=0; irow<GetNofRows(); irow++)
5f91c9e8 239 GetRow(irow)->SetRowSegmentOffsets(fOffset);
240}
241
242//_____________________________________________________________________________
243void AliMpSector::Initialize()
244{
dee1d5f1 245/// Make needed settings after sector is read from
246/// data files.
5f91c9e8 247
248 SetRowOffsets();
249 SetMotifPositions();
250 SetGlobalIndices();
251 SetMinPadDimensions();
f9a3ff6a 252 SetMaxPadIndices();
253 SetNofPads();
5f91c9e8 254}
255
256//_____________________________________________________________________________
257void AliMpSector::PrintGeometry() const
258{
dee1d5f1 259/// Print the positions of rows, rows segments
5f91c9e8 260
261 for (Int_t i=0; i<GetNofRows(); i++) {
262 AliMpRow* row = GetRow(i);
263
264 cout << "ROW " << row->GetID()
265 << " center Y " << row->Position().Y() << endl;
266
267 for (Int_t j=0; j<row->GetNofRowSegments(); j++) {
268 AliMpVRowSegment* rowSegment = row->GetRowSegment(j);
269
270 cout << " ROW Segment " << j
271 << " borders "
272 << rowSegment->LeftBorderX() << " "
273 << rowSegment->RightBorderX()
274 << " x-size "
275 << 2*rowSegment->Dimensions().X() << " "
276 << endl;
277 }
278 }
279}
280
281
282//_____________________________________________________________________________
283AliMpRow* AliMpSector::FindRow(const TVector2& position) const
284{
dee1d5f1 285/// Find the row for the specified y position. \n
286/// If y is on border the lowest row is returned.
5f91c9e8 287
288 Double_t y = position.Y();
289
f79c58a5 290#ifdef WITH_STL
291 for (Int_t i=0; i<GetNofRows(); i++) {
5f91c9e8 292 if ( y >= fRows[i]->LowBorderY() && y <= fRows[i]->UpperBorderY())
293 return fRows[i];
294 }
f79c58a5 295#endif
296
297#ifdef WITH_ROOT
298 for (Int_t i=0; i<GetNofRows(); i++) {
299 if ( y >= ((AliMpRow*)fRows[i])->LowBorderY() &&
300 y <= ((AliMpRow*)fRows[i])->UpperBorderY())
301 return (AliMpRow*)fRows[i];
302 }
303#endif
5f91c9e8 304
305 return 0;
306}
307
308//_____________________________________________________________________________
309AliMpVMotif* AliMpSector::FindMotif(const TVector2& position) const
310{
dee1d5f1 311/// Find the motif in the specified position. \n
312/// Return 0 if no motif is found.
5f91c9e8 313
314 // Find the row segment
315 AliMpVRowSegment* rowSegment = FindRowSegment(position);
316
317 if (!rowSegment) return 0;
318
319 // Find motif
320 return rowSegment->FindMotif(position);
321}
5f91c9e8 322//_____________________________________________________________________________
323Int_t AliMpSector::FindMotifPositionId(const TVector2& position) const
324{
dee1d5f1 325/// Find the motif position ID in the specified position. \n
326/// Return 0 if no motif is found.
327
5f91c9e8 328 // Find the row segment
329 AliMpVRowSegment* rowSegment = FindRowSegment(position);
330
331 if (!rowSegment) return 0;
332
333 // Find motif position ID
334 return rowSegment->FindMotifPositionId(position);
335}
336
337//_____________________________________________________________________________
338AliMpRow* AliMpSector::FindRow(Int_t motifPositionId) const
339{
dee1d5f1 340/// Find the row with the the specified motif position. \n
341/// Return 0 if no row is found.
5f91c9e8 342
343 AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
344
345 if (segment) return segment->GetRow();
346
347 return 0;
348}
349
350//_____________________________________________________________________________
351AliMpVRowSegment* AliMpSector::FindRowSegment(Int_t motifPositionId) const
352{
dee1d5f1 353/// Find the row segment with the the specified motif position. \n
354/// Return 0 if no row segment is found.
5f91c9e8 355
f79c58a5 356 for (Int_t irow=0; irow<GetNofRows(); irow++) {
357
358#ifdef WITH_STL
5f91c9e8 359 AliMpRow* row = fRows[irow];
f79c58a5 360#endif
361#ifdef WITH_ROOT
362 AliMpRow* row = (AliMpRow*)fRows[irow];
363#endif
5f91c9e8 364
365 for (Int_t iseg=0; iseg<row->GetNofRowSegments(); iseg++) {
366 AliMpVRowSegment* segment = row->GetRowSegment(iseg);
367 if (segment->HasMotifPosition(motifPositionId)) return segment;
368 }
369 }
370
371 return 0;
372}
373
374//_____________________________________________________________________________
375TVector2 AliMpSector::FindPosition(Int_t motifPositionId) const
376{
dee1d5f1 377/// Find the position of the motif specified by its position Id. \n
378/// Return 0 if no row segment is found.
5f91c9e8 379
380 AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
381
382 if (!segment) {
2c605e66 383 AliWarningStream() << "Given motifPositionId not found." << endl;
5f91c9e8 384 return TVector2();
385 }
386
387 return segment->MotifCenter(motifPositionId);
388}
389
390//_____________________________________________________________________________
391AliMpZone* AliMpSector::FindZone(const TVector2& padDimensions) const
392{
dee1d5f1 393/// Find the zone with specified padDimensions.
5f91c9e8 394
395 for (Int_t i=0; i<GetNofZones(); i++) {
396 AliMpZone* zone = GetZone(i+1);
397 if (AliMpConstants::IsEqual(padDimensions, zone->GetPadDimensions()))
398 return zone;
399 }
400
401 // Return 0 if not found
402 return 0;
403}
404
405//_____________________________________________________________________________
406TVector2 AliMpSector::Position() const
407{
dee1d5f1 408/// Return the sector offset.
5f91c9e8 409
410 return fOffset;
411}
412
413
414//_____________________________________________________________________________
415TVector2 AliMpSector::Dimensions() const
416{
dee1d5f1 417/// Return the maximum halflengths in x, y.
5f91c9e8 418
419 Double_t x = 0.;
420 Double_t y = 0.;
421 for (Int_t i=0; i<GetNofRows(); i++) {
422
f79c58a5 423#ifdef WITH_STL
5f91c9e8 424 // take the largest x row dimension
425 if (fRows[i]->Dimensions().X() > x)
426 x = fRows[i]->Dimensions().X();
427
428 // add all rows y dimensions
429 y += fRows[i]->Dimensions().Y();
f79c58a5 430#endif
431
432#ifdef WITH_ROOT
433 // take the largest x row dimension
434 if ( ((AliMpRow*)fRows[i])->Dimensions().X() > x)
435 x = ((AliMpRow*)fRows[i])->Dimensions().X();
436
437 // add all rows y dimensions
438 y += ((AliMpRow*)fRows[i])->Dimensions().Y();
439#endif
5f91c9e8 440 }
441
442 return TVector2(x, y);
443}
444
445//_____________________________________________________________________________
446Int_t AliMpSector::GetNofZones() const
447{
dee1d5f1 448/// Return the number of zones.
5f91c9e8 449
f79c58a5 450#ifdef WITH_STL
5f91c9e8 451 return fZones.size();
f79c58a5 452#endif
453
454#ifdef WITH_ROOT
455 return fZones.GetEntriesFast();
456#endif
5f91c9e8 457}
458
459//_____________________________________________________________________________
460AliMpZone* AliMpSector::GetZone(Int_t zoneID) const
461{
dee1d5f1 462/// Return zone with specified ID.
5f91c9e8 463
464 if (zoneID < 1 || zoneID > GetNofZones()) {
2c605e66 465 AliWarningStream() << "Index outside range" << endl;
5f91c9e8 466 return 0;
467 }
468
f79c58a5 469#ifdef WITH_STL
5f91c9e8 470 return fZones[zoneID-1];
f79c58a5 471#endif
472
473#ifdef WITH_ROOT
474 return (AliMpZone*)fZones[zoneID-1];
475#endif
5f91c9e8 476}
477
478//_____________________________________________________________________________
479Int_t AliMpSector::GetNofRows() const
480{
dee1d5f1 481/// Return the number of rows.
5f91c9e8 482
f79c58a5 483#ifdef WITH_STL
5f91c9e8 484 return fRows.size();
f79c58a5 485#endif
486
487#ifdef WITH_ROOT
488 return fRows.GetEntriesFast();
489#endif
5f91c9e8 490}
491
492//_____________________________________________________________________________
493AliMpRow* AliMpSector::GetRow(Int_t rowID) const
494{
dee1d5f1 495/// Return row with specified ID.
5f91c9e8 496
497 if (rowID < 0 || rowID >= GetNofRows()) {
2c605e66 498 AliWarningStream() << "Index outside range" << endl;
5f91c9e8 499 return 0;
500 }
501
f79c58a5 502#ifdef WITH_STL
5f91c9e8 503 return fRows[rowID];
f79c58a5 504#endif
505
506#ifdef WITH_ROOT
507 return (AliMpRow*)fRows[rowID];
508#endif
5f91c9e8 509}
c9da0af9 510
f9a3ff6a 511//_____________________________________________________________________________
cddd101e 512AliMp::PlaneType
f9a3ff6a 513AliMpSector::GetPlaneType() const
514{
515/// Return the plane type
516
cddd101e 517 return GetDirection()==AliMp::kY ? AliMp::kBendingPlane : AliMp::kNonBendingPlane;
f9a3ff6a 518}
519
520//_____________________________________________________________________________
521void
522AliMpSector::GetAllMotifPositionsIDs(TArrayI& ecn) const
523{
524/// Return the array of all motif positions IDs
525
526 fMotifMap->GetAllMotifPositionsIDs(ecn);
527}
528
c9da0af9 529//_____________________________________________________________________________
530void
531AliMpSector::Print(Option_t* opt) const
532{
f9a3ff6a 533/// Print the map of motifs
534
535 cout << "Sector," << PlaneTypeName(GetPlaneType()) << endl;
c9da0af9 536 fMotifMap->Print(opt);
537}