]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSector.cxx
Pass AliMpIntPair/TVector2/TString arguments by const reference.
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSector.cxx
1 // $Id$
2 // Category: sector
3 //
4 // Class AliMpSector
5 // -----------------
6 // Class describing the sector of the MUON chamber of station 1.
7 //
8 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
9
10 #include <Riostream.h>
11
12 #include "AliMpSector.h"
13 #include "AliMpSectorPadIterator.h"
14 #include "AliMpZone.h"
15 #include "AliMpRow.h"
16 #include "AliMpVRowSegment.h"
17 #include "AliMpVMotif.h"
18 #include "AliMpMotifMap.h"
19 #include "AliMpIntPair.h"
20 #include "AliMpConstants.h"
21
22 ClassImp(AliMpSector)
23
24 //_____________________________________________________________________________
25 AliMpSector::AliMpSector(const TString& id, Int_t nofZones, Int_t nofRows, 
26                          AliMpDirection direction) 
27   : TObject(),
28     fID(id),
29     fOffset(TVector2(0., 0.)),
30     fZones(),
31     fRows(),
32     fDirection(direction),
33     fMinPadDimensions(TVector2(1.e6, 1.e6))
34 {
35 //
36   fMotifMap = new AliMpMotifMap();
37
38   for (Int_t izone = 0; izone<nofZones; izone++) 
39     fZones.push_back(new AliMpZone(izone+1));
40     
41   for (Int_t irow = 0; irow<nofRows; irow++) 
42     fRows.push_back(new AliMpRow(irow, fMotifMap));
43     
44 }
45
46 //_____________________________________________________________________________
47 AliMpSector::AliMpSector() 
48   : TObject(),
49     fID(""),    
50     fOffset(TVector2(0., 0.)),
51     fZones(),
52     fRows(),
53     fMotifMap(0),
54     fDirection(kX),
55     fMinPadDimensions(TVector2(0., 0.))
56 {
57 //
58 }
59
60 //_____________________________________________________________________________
61 AliMpSector::~AliMpSector() {
62 // 
63   // deletes 
64   for (Int_t izone = 0; izone<GetNofZones(); izone++) 
65     delete fZones[izone];
66     
67   for (Int_t irow = 0; irow<GetNofRows(); irow++) 
68     delete fRows[irow];
69
70   delete fMotifMap;
71 }
72
73 //
74 // private methods
75 //
76
77 //_____________________________________________________________________________
78 AliMpVPadIterator* AliMpSector::CreateIterator() const
79 {
80   return new AliMpSectorPadIterator(this);
81 }
82
83
84 //_____________________________________________________________________________
85 AliMpVRowSegment* AliMpSector::FindRowSegment(const TVector2& position) const
86 {
87 // Finds the row segment in the specified position.
88 // Returns 0 if no motif is found.
89 // ---
90   
91   // Find row
92   AliMpRow* row = FindRow(position);
93   
94   if (!row) return 0;
95
96   // Find the row segment and return its motif
97   AliMpVRowSegment* rowSegment = row->FindRowSegment(position.X());
98   
99   return rowSegment;
100 }
101
102 //_____________________________________________________________________________
103 void  AliMpSector::SetRowOffsets()
104 {
105 // For each row checks consitency of the row segments
106 // and calculates the row offset.
107 // ---
108
109   Double_t offset = fOffset.Y();
110   
111   for (UInt_t irow=0; irow<fRows.size(); irow++)
112     offset = GetRow(irow)->SetOffsetY(offset);    
113 }
114
115 //_____________________________________________________________________________
116 void  AliMpSector::SetMotifPositions()
117 {
118 // Creates motif positions objects and fills them in the motif map.
119 // ---
120
121   for (UInt_t i=0; i<fRows.size(); i++)
122     GetRow(i)->SetMotifPositions();
123 }
124
125 //_____________________________________________________________________________
126 void  AliMpSector::SetGlobalIndices()
127 {
128 // Set the indices limits to all indexed elements
129 // (row, row segment, motif positions).
130 // ---
131
132   AliMpIntPair indices(0,0); 
133   AliMpRow* rowBefore=0;
134   for (UInt_t i=0; i<fRows.size(); i++) {
135     GetRow(i)->SetGlobalIndices(fDirection, rowBefore);
136     rowBefore = GetRow(i);
137   }
138 }
139
140 //_____________________________________________________________________________
141 void  AliMpSector::SetMinPadDimensions()
142 {
143 // Sets the minimal pad dimensions.
144 // ---
145
146   for (Int_t i=1; i<GetNofZones()+1; i++) {
147     TVector2 padDimensions = GetZone(i)->GetPadDimensions();
148     
149     if ( fDirection == kX &&  
150          padDimensions.Y() > 0. && padDimensions.Y() < fMinPadDimensions.Y() ||
151          fDirection == kY && 
152          padDimensions.X() > 0. && padDimensions.X() < fMinPadDimensions.X())
153       
154       fMinPadDimensions = padDimensions;
155   }
156 }
157
158 //
159 // public methods
160 //
161
162 //_____________________________________________________________________________
163 void  AliMpSector::SetRowSegmentOffsets()
164 {
165 // For all rows sets offset to all row segments.
166 // ---
167
168   for (UInt_t irow=0; irow<fRows.size(); irow++)
169     GetRow(irow)->SetRowSegmentOffsets(fOffset);    
170 }
171
172 //_____________________________________________________________________________
173 void AliMpSector::Initialize() 
174 {
175 // Makes needed settings after sector is read from
176 // data files.
177 // ---
178
179   SetRowOffsets();
180   SetMotifPositions();
181   SetGlobalIndices();
182   SetMinPadDimensions();
183 }  
184
185 //_____________________________________________________________________________
186 void AliMpSector::PrintGeometry()  const
187 {
188 // Prints the positions of rows, rows segments
189 // ---
190
191   for (Int_t i=0; i<GetNofRows(); i++) {
192     AliMpRow* row = GetRow(i);
193     
194     cout << "ROW " << row->GetID() 
195          << "  center Y " << row->Position().Y() << endl;
196
197     for (Int_t j=0; j<row->GetNofRowSegments(); j++) {
198        AliMpVRowSegment* rowSegment = row->GetRowSegment(j);
199         
200        cout << "   ROW Segment " << j 
201             << "  borders " 
202             << rowSegment->LeftBorderX() << "  "
203             << rowSegment->RightBorderX()
204             << "  x-size " 
205             << 2*rowSegment->Dimensions().X() << "  "
206             << endl;
207     }
208   }
209 }     
210              
211
212 //_____________________________________________________________________________
213 AliMpRow* AliMpSector::FindRow(const TVector2& position) const
214 {
215 // Finds the row for the specified y position.
216 // If y is on border the lowest row is returned.
217 // ---
218   
219   Double_t y = position.Y();
220   
221   for (UInt_t i=0; i<fRows.size(); i++) {
222     if ( y >= fRows[i]->LowBorderY() && y <= fRows[i]->UpperBorderY())
223       return fRows[i];
224   }    
225   
226   return 0;
227 }
228
229 //_____________________________________________________________________________
230 AliMpVMotif* AliMpSector::FindMotif(const TVector2& position) const
231 {
232 // Finds the motif in the specified position.
233 // Returns 0 if no motif is found.
234 // ---
235   
236   // Find the row segment
237   AliMpVRowSegment* rowSegment = FindRowSegment(position);
238   
239   if (!rowSegment) return 0;
240   
241   // Find motif
242   return rowSegment->FindMotif(position);  
243 }
244
245 //_____________________________________________________________________________
246 Int_t AliMpSector::FindMotifPositionId(const TVector2& position) const
247 {
248 // Finds the motif position ID in the specified position.
249 // Returns 0 if no motif is found.
250 // ---
251   
252   // Find the row segment
253   AliMpVRowSegment* rowSegment = FindRowSegment(position);
254   
255   if (!rowSegment) return 0;
256     
257   // Find motif position ID
258   return rowSegment->FindMotifPositionId(position);  
259 }
260
261 //_____________________________________________________________________________
262 AliMpRow* AliMpSector::FindRow(Int_t motifPositionId) const
263 {
264 // Finds the row with the the specified motif position.
265 // Returns 0 if no row is found.
266 // ---
267
268   AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
269   
270   if (segment) return segment->GetRow();
271   
272   return 0;  
273 }
274
275 //_____________________________________________________________________________
276 AliMpVRowSegment* AliMpSector::FindRowSegment(Int_t motifPositionId) const
277 {
278 // Finds the row segment with the the specified motif position.
279 // Returns 0 if no row segment is found.
280 // ---
281
282   for (UInt_t irow=0; irow<fRows.size(); irow++) {
283     AliMpRow* row = fRows[irow];
284    
285     for (Int_t iseg=0; iseg<row->GetNofRowSegments(); iseg++) {
286       AliMpVRowSegment* segment = row->GetRowSegment(iseg); 
287       if (segment->HasMotifPosition(motifPositionId)) return segment;
288     }
289   }
290   
291   return 0;    
292 }
293
294 //_____________________________________________________________________________
295 TVector2  AliMpSector::FindPosition(Int_t motifPositionId) const
296 {
297 // Finds the position of the motif specified by its position Id.
298 // Returns 0 if no row segment is found.
299 // ---
300
301   AliMpVRowSegment* segment = FindRowSegment(motifPositionId);
302
303   if (!segment) {
304     Warning("FindPosition", "Given motifPositionId not found.");
305     return TVector2();
306   }   
307
308   return segment->MotifCenter(motifPositionId);
309 }
310    
311 //_____________________________________________________________________________
312 AliMpZone*  AliMpSector::FindZone(const TVector2& padDimensions) const
313 {
314 // Finds the zone with specified padDimensions.
315 // ---
316
317   for (Int_t i=0; i<GetNofZones(); i++) {
318     AliMpZone* zone = GetZone(i+1);
319     if (AliMpConstants::IsEqual(padDimensions, zone->GetPadDimensions())) 
320       return zone;
321   }
322   
323   // Return 0 if not found
324   return 0;      
325 }
326
327 //_____________________________________________________________________________
328 TVector2 AliMpSector::Position() const
329 {
330 // Returns the offset.
331 // ---
332
333   return fOffset;
334 }  
335
336
337 //_____________________________________________________________________________
338 TVector2 AliMpSector::Dimensions() const
339 {
340 // Returns the maximum halflength in x, y.
341 // ---
342
343   Double_t x = 0.;
344   Double_t y = 0.;
345   for (Int_t i=0; i<GetNofRows(); i++) {
346
347     // take the largest x row dimension
348     if (fRows[i]->Dimensions().X() > x) 
349       x = fRows[i]->Dimensions().X();
350       
351     // add all rows y dimensions  
352     y += fRows[i]->Dimensions().Y();
353   }
354   
355   return TVector2(x, y);  
356 }  
357
358 //_____________________________________________________________________________
359 Int_t AliMpSector::GetNofZones() const
360 {    
361 // Returns the number of zones.
362 // ---
363
364   return fZones.size();
365 }  
366
367 //_____________________________________________________________________________
368 AliMpZone* AliMpSector::GetZone(Int_t zoneID) const
369 {
370 // Returns zone with specified ID.
371 // ---
372
373   if (zoneID < 1 || zoneID > GetNofZones()) {
374     Warning("GetZone", "Index outside range");
375     return 0;
376   }
377   
378   return fZones[zoneID-1];
379 }  
380
381 //_____________________________________________________________________________
382 Int_t AliMpSector::GetNofRows() const
383 {
384 // Returns the number of rows.
385 // ---
386
387   return fRows.size();
388 }  
389
390 //_____________________________________________________________________________
391 AliMpRow* AliMpSector::GetRow(Int_t rowID) const
392 {
393 // Returns row with specified ID.
394 // ---
395
396   if (rowID < 0 || rowID >= GetNofRows()) {
397     Warning("GetRow", "Index outside range");
398     return 0;
399   }
400   
401   return fRows[rowID];
402 }