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