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