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