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