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