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