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