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