]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpPadRow.cxx
bb0ecd94ed2d7f98020e028079a34cb3dc7394c1
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpPadRow.cxx
1 // $Id$
2 // --------------------------------------------------------
3 // Category: sector
4 //
5 // Class AliMpPadRow
6 // ------------------
7 // Class describing a pad row composed of the pad row segments.
8 //
9 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
10
11 #include <TError.h>
12
13 #include "AliMpPadRow.h"
14 #include "AliMpPadRowLSegment.h"
15 #include "AliMpPadRowRSegment.h"
16
17 ClassImp(AliMpPadRow)
18
19 //_____________________________________________________________________________
20 AliMpPadRow::AliMpPadRow(AliMpXDirection direction) 
21   : TObject(),
22     fDirection(direction), 
23     fID(0)
24 {
25 //
26 }
27
28 //_____________________________________________________________________________
29 AliMpPadRow::AliMpPadRow() 
30   : TObject(),
31     fDirection(kLeft), 
32     fID(0)
33 {
34 //
35 }
36
37 //_____________________________________________________________________________
38 AliMpPadRow::~AliMpPadRow() {
39 //  
40
41   for (Int_t i=0; i<GetNofPadRowSegments() ; i++)
42     delete fSegments[i];
43 }
44
45 //
46 // private methods
47 //
48
49 //_____________________________________________________________________________
50 Double_t AliMpPadRow::CurrentBorderX() const
51 {
52 // Returns the left/right x border 
53 // (depending on the direction which the row segments are filled in).
54 // ---
55
56   if (GetNofPadRowSegments() == 0)
57       return fOffsetX;
58   else 
59     if (fDirection == kLeft)
60       return GetPadRowSegment(GetNofPadRowSegments()-1)->LeftBorderX();
61     else  
62       return GetPadRowSegment(GetNofPadRowSegments()-1)->RightBorderX();
63 }
64
65 //
66 // public methods
67 //
68
69 //_____________________________________________________________________________
70 AliMpVPadRowSegment* 
71 AliMpPadRow::AddPadRowSegment(AliMpMotif* motif, Int_t motifPositionId,
72                               Int_t nofPads)
73 {
74 // Adds pad row segment.
75 // ---
76
77   AliMpVPadRowSegment* padRowSegment = 0;
78
79   if (fDirection == kLeft) {
80     padRowSegment 
81       = new AliMpPadRowLSegment(this, motif, motifPositionId, nofPads);
82   }    
83   else  {
84     padRowSegment 
85       = new AliMpPadRowRSegment(this, motif, motifPositionId, nofPads);
86   }     
87
88   // Set pad row segment offset
89   padRowSegment->SetOffsetX(CurrentBorderX());
90
91   // Adds the pad row segment
92   fSegments.push_back(padRowSegment);
93   
94   return padRowSegment;
95 }  
96   
97 //_____________________________________________________________________________
98 AliMpVPadRowSegment* AliMpPadRow::FindPadRowSegment(Double_t x) const
99 {
100 // Finds the row segment for the specified x position;
101 // returns 0 if no row segment is found.
102 // ---
103
104   for (Int_t i=0; i<GetNofPadRowSegments(); i++) {
105     AliMpVPadRowSegment* rs = GetPadRowSegment(i);
106     if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
107       return rs;
108   }
109   
110   return 0;    
111 }    
112
113 //_____________________________________________________________________________
114 Double_t  AliMpPadRow::HalfSizeY() const
115 {
116   return GetPadRowSegment(0)->HalfSizeY();
117 }
118
119 //_____________________________________________________________________________
120 void  AliMpPadRow::SetID(Int_t id)
121 {
122 // Sets the ID.
123 // ---
124
125   fID = id;
126 }    
127
128 //_____________________________________________________________________________
129 void  AliMpPadRow::SetOffsetX(Double_t offsetX)
130 {
131 // Sets the x offset.
132 // ---
133
134   fOffsetX = offsetX;
135 }    
136
137 //_____________________________________________________________________________
138 Int_t AliMpPadRow::GetID() const 
139 {
140 // Returns the row ID.
141 // ---
142
143   return fID;
144 }  
145
146 //_____________________________________________________________________________
147 Int_t AliMpPadRow::GetNofPadRowSegments() const 
148 {
149 // Returns number of row segments.
150 // ---
151
152   return fSegments.size();
153 }  
154
155 //_____________________________________________________________________________
156 AliMpVPadRowSegment* AliMpPadRow::GetPadRowSegment(Int_t i) const 
157 {
158   if (i<0 || i>=GetNofPadRowSegments()) {
159     Warning("GetRowSegment", "Index outside range");
160     return 0;
161   }
162   
163   return fSegments[i];  
164 }
165
166 //_____________________________________________________________________________
167 Int_t AliMpPadRow::GetNofPads() const 
168 {
169 // Returns number of pads in this pad row.
170 // ---
171
172   Int_t nofPads=0;
173   for (Int_t i=0; i<GetNofPadRowSegments(); i++)
174     nofPads += GetPadRowSegment(i)->GetNofPads();
175
176   return nofPads;
177 }  
178