]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSector.cxx
In mapping:
[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 "AliMpIntPair.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     fMaxPadIndices(AliMpIntPair::Invalid()),
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     fMaxPadIndices(AliMpIntPair::Invalid()),
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   AliMpIntPair indices(0,0); 
168   AliMpRow* rowBefore=0;
169   for (Int_t i=0; i<GetNofRows(); i++) {
170     GetRow(i)->SetGlobalIndices(fDirection, rowBefore);
171     rowBefore = GetRow(i);
172   }
173 }
174
175 //_____________________________________________________________________________
176 void  AliMpSector::SetMinMaxPadDimensions()
177 {
178 /// Set the minimal pad dimensions.
179
180   for (Int_t i=1; i<GetNofZones()+1; i++) {
181     TVector2 padDimensions = GetZone(i)->GetPadDimensions();
182     
183     if ( (fDirection == AliMp::kX &&  
184           padDimensions.Y() > 0. && padDimensions.Y() < fMinPadDimensions.Y()) ||
185          (fDirection == AliMp::kY && 
186           padDimensions.X() > 0. && padDimensions.X() < fMinPadDimensions.X()))
187       
188       fMinPadDimensions = padDimensions;
189
190     if ( (fDirection == AliMp::kX &&  
191           padDimensions.Y() > 0. && padDimensions.Y() > fMaxPadDimensions.Y()) ||
192          (fDirection == AliMp::kY && 
193           padDimensions.X() > 0. && padDimensions.X() > fMinPadDimensions.X()))
194       
195       fMaxPadDimensions = padDimensions;
196   }
197 }
198
199 //_____________________________________________________________________________
200 void  AliMpSector::SetMaxPadIndices()
201 {
202 /// Set maximum pad indices in x, y
203
204   if ( fMaxPadIndices != AliMpIntPair::Invalid() ) return;
205   
206   Int_t maxIndexInX = 0;
207   Int_t maxIndexInY = 0;
208   for (Int_t i=0; i<GetNofRows(); i++) {
209
210     Int_t ixh = GetRow(i)->GetHighIndicesLimit().GetFirst();
211     if ( ixh > maxIndexInX ) maxIndexInX = ixh;
212
213     Int_t iyh = GetRow(i)->GetHighIndicesLimit().GetSecond();
214     if ( iyh > maxIndexInY ) maxIndexInY = iyh;
215   }  
216   
217   fMaxPadIndices = AliMpIntPair(maxIndexInX, maxIndexInY);
218 }
219
220
221 //_____________________________________________________________________________
222 void  AliMpSector::SetNofPads()
223 {
224 /// Set the total number of pads
225
226   fNofPads = fMotifMap->CalculateNofPads();
227 }
228
229 //
230 // public methods
231 //
232
233 //_____________________________________________________________________________
234 void  AliMpSector::SetRowSegmentOffsets()
235 {
236 /// For all rows set the offset to all row segments.
237
238   for (Int_t irow=0; irow<GetNofRows(); irow++)
239     GetRow(irow)->SetRowSegmentOffsets(fOffset);    
240 }
241
242 //_____________________________________________________________________________
243 void AliMpSector::Initialize() 
244 {
245 /// Make needed settings after sector is read from
246 /// data files.
247
248   SetRowOffsets();
249   SetMotifPositions();
250   SetGlobalIndices();
251   SetMinMaxPadDimensions();
252   SetMaxPadIndices();
253   SetNofPads();
254 }  
255
256 //_____________________________________________________________________________
257 void AliMpSector::PrintGeometry()  const
258 {
259 /// Print the positions of rows, rows segments
260
261   for (Int_t i=0; i<GetNofRows(); i++) {
262     AliMpRow* row = GetRow(i);
263     
264     cout << "ROW " << row->GetID() 
265          << "  center Y " << row->Position().Y() << endl;
266
267     for (Int_t j=0; j<row->GetNofRowSegments(); j++) {
268        AliMpVRowSegment* rowSegment = row->GetRowSegment(j);
269         
270        cout << "   ROW Segment " << j 
271             << "  borders " 
272             << rowSegment->LeftBorderX() << "  "
273             << rowSegment->RightBorderX()
274             << "  x-size " 
275             << 2*rowSegment->Dimensions().X() << "  "
276             << endl;
277     }
278   }
279 }     
280              
281
282 //_____________________________________________________________________________
283 AliMpRow* AliMpSector::FindRow(const TVector2& position) const
284 {
285 /// Find the row for the specified y position.                              \n
286 /// If y is on border the lowest row is returned.
287   
288   Double_t y = position.Y();
289   
290   for (Int_t i=0; i<GetNofRows(); i++) {
291     if ( y >= ((AliMpRow*)fRows[i])->LowBorderY() && 
292          y <= ((AliMpRow*)fRows[i])->UpperBorderY())
293       return (AliMpRow*)fRows[i];
294   }    
295   
296   return 0;
297 }
298
299 //_____________________________________________________________________________
300 AliMpVMotif* AliMpSector::FindMotif(const TVector2& position) const
301 {
302 /// Find the motif in the specified position.                               \n
303 /// Return 0 if no motif is found.
304   
305   // Find the row segment
306   AliMpVRowSegment* rowSegment = FindRowSegment(position);
307   
308   if (!rowSegment) return 0;
309   
310   // Find motif
311   return rowSegment->FindMotif(position);  
312 }
313 //_____________________________________________________________________________
314 Int_t AliMpSector::FindMotifPositionId(const TVector2& position) const
315 {
316 /// Find the motif position ID in the specified position.                   \n
317 /// Return 0 if no motif is found.
318  
319   // Find the row segment
320   AliMpVRowSegment* rowSegment = FindRowSegment(position);
321   
322   if (!rowSegment) return 0;
323     
324   // Find motif position ID
325   return rowSegment->FindMotifPositionId(position);  
326 }
327
328 //_____________________________________________________________________________
329 AliMpRow* AliMpSector::FindRow(Int_t motifPositionId) const
330 {
331 /// Find the row with the the specified motif position.                     \n
332 /// Return 0 if no row is found.
333
334   AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
335   
336   if (segment) return segment->GetRow();
337   
338   return 0;  
339 }
340
341 //_____________________________________________________________________________
342 AliMpVRowSegment* AliMpSector::FindRowSegment(Int_t motifPositionId) const
343 {
344 /// Find the row segment with the the specified motif position.            \n
345 /// Return 0 if no row segment is found.
346
347   for (Int_t irow=0; irow<GetNofRows(); irow++) {
348
349     AliMpRow* row = (AliMpRow*)fRows[irow];
350
351     for (Int_t iseg=0; iseg<row->GetNofRowSegments(); iseg++) {
352       AliMpVRowSegment* segment = row->GetRowSegment(iseg); 
353       if (segment->HasMotifPosition(motifPositionId)) return segment;
354     }
355   }
356   
357   return 0;    
358 }
359
360 //_____________________________________________________________________________
361 TVector2  AliMpSector::FindPosition(Int_t motifPositionId) const
362 {
363 /// Find the position of the motif specified by its position Id.            \n
364 /// Return 0 if no row segment is found.
365
366   AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
367
368   if (!segment) {
369     AliWarningStream() << "Given motifPositionId not found." << endl;
370     return TVector2();
371   }   
372
373   return segment->MotifCenter(motifPositionId);
374 }
375    
376 //_____________________________________________________________________________
377 AliMpZone*  AliMpSector::FindZone(const TVector2& padDimensions) const
378 {
379 /// Find the zone with specified padDimensions.
380
381   for (Int_t i=0; i<GetNofZones(); i++) {
382     AliMpZone* zone = GetZone(i+1);
383     if (AliMpConstants::IsEqual(padDimensions, zone->GetPadDimensions())) 
384       return zone;
385   }
386   
387   // Return 0 if not found
388   return 0;      
389 }
390
391 //_____________________________________________________________________________
392 TVector2 AliMpSector::Position() const
393 {
394 /// Return the sector offset.
395
396   return fOffset;
397 }  
398
399
400 //_____________________________________________________________________________
401 TVector2 AliMpSector::Dimensions() const
402 {
403 /// Return the maximum halflengths in x, y.
404
405   Double_t x = 0.;
406   Double_t y = 0.;
407   for (Int_t i=0; i<GetNofRows(); i++) {
408
409     // take the largest x row dimension
410     if ( ((AliMpRow*)fRows[i])->Dimensions().X() > x) 
411       x = ((AliMpRow*)fRows[i])->Dimensions().X();
412       
413     // add all rows y dimensions  
414     y += ((AliMpRow*)fRows[i])->Dimensions().Y();
415   }
416   
417   return TVector2(x, y);  
418 }  
419
420 //_____________________________________________________________________________
421 Int_t AliMpSector::GetNofZones() const
422 {    
423 /// Return the number of zones.
424
425   return fZones.GetEntriesFast();
426 }  
427
428 //_____________________________________________________________________________
429 AliMpZone* AliMpSector::GetZone(Int_t zoneID) const
430 {
431 /// Return zone with specified ID.
432
433   if (zoneID < 1 || zoneID > GetNofZones()) {
434     AliWarningStream() << "Index outside range" << endl;
435     return 0;
436   }
437   
438   return (AliMpZone*)fZones[zoneID-1];
439 }  
440
441 //_____________________________________________________________________________
442 Int_t AliMpSector::GetNofRows() const
443 {
444 /// Return the number of rows.
445
446   return fRows.GetEntriesFast();
447 }  
448
449 //_____________________________________________________________________________
450 AliMpRow* AliMpSector::GetRow(Int_t rowID) const
451 {
452 /// Return row with specified ID.
453
454   if (rowID < 0 || rowID >= GetNofRows()) {
455     AliWarningStream() << "Index outside range" << endl;
456     return 0;
457   }
458   
459   return (AliMpRow*)fRows[rowID];
460 }
461
462 //_____________________________________________________________________________
463 AliMp::PlaneType
464 AliMpSector::GetPlaneType() const
465 {
466 /// Return the plane type
467
468   return GetDirection()==AliMp::kY ? AliMp::kBendingPlane : AliMp::kNonBendingPlane;
469 }
470
471 //_____________________________________________________________________________
472 Int_t 
473 AliMpSector::GetNofMotifPositions() const
474 {
475   /// Return the number of manus
476   
477   return fMotifMap->GetNofMotifPositions();
478 }
479
480 //_____________________________________________________________________________
481 void 
482 AliMpSector::GetAllMotifPositionsIDs(TArrayI& ecn) const
483 {
484 /// Return the array of all motif positions IDs
485
486   fMotifMap->GetAllMotifPositionsIDs(ecn);
487 }
488
489 //_____________________________________________________________________________
490 void
491 AliMpSector::Print(Option_t* opt) const
492 {
493 /// Print the map of motifs
494
495   cout << "Sector," << PlaneTypeName(GetPlaneType()) << endl;
496   fMotifMap->Print(opt);
497 }