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