]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpVRowSegmentSpecial.cxx
Update for station2:
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpVRowSegmentSpecial.cxx
CommitLineData
ea4cae7a 1// $Id$
2// Category: sector
3//
4// Class AliMpVRowSegmentSpecial
5// ----------------------------
6// Class describing a special row segment composed of the
7// pad rows.
8//
9// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
10
11#include <TError.h>
12#include <Riostream.h>
13
14#include "AliMpVRowSegmentSpecial.h"
15#include "AliMpRow.h"
16#include "AliMpPadRow.h"
17#include "AliMpVPadRowSegment.h"
18#include "AliMpMotif.h"
19#include "AliMpMotifType.h"
20#include "AliMpMotifMap.h"
21#include "AliMpMotifPosition.h"
22#include "AliMpConstants.h"
23
24ClassImp(AliMpVRowSegmentSpecial)
25
26//______________________________________________________________________________
27AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(AliMpRow* row, Double_t offsetX)
28 : AliMpVRowSegment(),
29 fRow(row),
30 fOffsetX(offsetX),
31 fPadRows(),
32 fMotifs(),
33 fMotifPositionIds()
34{
35//
36}
37
38//______________________________________________________________________________
39AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial()
40 : AliMpVRowSegment(),
41 fRow(0),
42 fOffsetX(0.),
43 fPadRows(),
44 fMotifs(),
45 fMotifPositionIds()
46{
47//
48}
49
50//______________________________________________________________________________
51AliMpVRowSegmentSpecial::~AliMpVRowSegmentSpecial()
52{
53//
54 for (Int_t i=0; i<GetNofPadRows(); i++)
55 delete fPadRows[i];
56}
57
58//
59// protected methods
60//
61
62//______________________________________________________________________________
63AliMpPadRow* AliMpVRowSegmentSpecial::FindPadRow(Double_t y) const
64{
65// Finds the pad row in the given y coordinate.
66// ---
67
68 Double_t lowBorder = fRow->LowBorderY();
69 Double_t highBorder = fRow->LowBorderY();
70
71 for (Int_t i=0; i<GetNofPadRows(); i++) {
72
73 AliMpPadRow* padRow = GetPadRow(i);
74 highBorder += 2.*padRow->HalfSizeY();
75
76 if ( y >= lowBorder && y <= highBorder)
77 return padRow;
78
79 lowBorder = highBorder;
80 }
81
82 return 0;
83}
84
85//______________________________________________________________________________
86AliMpVPadRowSegment*
87AliMpVRowSegmentSpecial::FindPadRowSegment(Int_t motifPositionId) const
88{
89// Find the most down pad row segment with this motifPositionId.
90// ---
91
92 for (Int_t i=0; i<GetNofPadRows(); i++) {
93 AliMpPadRow* padRow = GetPadRow(i);
94
95 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
96 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
97
98 if (padRowSegment->GetMotifPositionId() == motifPositionId)
99 return padRowSegment;
100 }
101 }
102 return 0;
103}
104
105//______________________________________________________________________________
106AliMpIntPair
107AliMpVRowSegmentSpecial::FindRelativeLowIndicesOf(Int_t motifPositionId) const
108{
109// Returns the lowest pad indices where the motif of the given position ID
110// exists in this segment.
111// ---
112
113 AliMpIntPair ans(0,1000);
114 AliMpIntPair ans0 = ans;
115 Int_t maxNofPadsX=0;
116
117 for (Int_t i=0; i<GetNofPadRows(); i++) {
118 AliMpPadRow* padRow = GetPadRow(i);
119
120 Int_t nofPadsX=0;
121 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
122 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
123 nofPadsX += padRowSegment->GetNofPads();
124 if (padRowSegment->GetMotifPositionId() == motifPositionId) {
125 if (ans.GetFirst() < nofPadsX) ans.SetFirst(nofPadsX);
126 if (ans.GetSecond()>i) ans.SetSecond(i);
127 // ans.First = max (nof pads of this pos ID)
128 // ans.Second = min of pad row number
129 }
130 }
131 if (nofPadsX > maxNofPadsX) maxNofPadsX = nofPadsX;
132 }
133 if (ans == ans0) return AliMpIntPair::Invalid();
134
135 return AliMpIntPair(maxNofPadsX-ans.GetFirst(), ans.GetSecond());
136}
137
138//______________________________________________________________________________
139Int_t AliMpVRowSegmentSpecial::MaxNofPadsInRow() const
140{
141// Returns the maximum number of pads in this row segment along the X direction
142// ---
143
144 Int_t maxNofPads = 0;
145
146 for (Int_t i=0; i<GetNofPadRows(); i++){
147 Int_t nofPads = GetPadRow(i)->GetNofPads();
148
149 // Find maximum
150 if (nofPads > maxNofPads) maxNofPads = nofPads;
151 }
152
153 return maxNofPads;
154}
155
156//______________________________________________________________________________
157Bool_t AliMpVRowSegmentSpecial::HasMotif(const AliMpVMotif* motif) const
158{
159// Returns true if the specified motif is already in fMotifs vector,
160// returns false otherwise.
161// ---
162
163 for (UInt_t i=0; i<fMotifs.size(); i++)
164 if (fMotifs[i] == motif) return true;
165
166 return false;
167}
168
169//______________________________________________________________________________
170Int_t AliMpVRowSegmentSpecial::GetNofPadRows() const
171{
172// Returns number of pad rows.
173// ---
174
175 return fPadRows.size();
176}
177
178//______________________________________________________________________________
179AliMpPadRow* AliMpVRowSegmentSpecial::GetPadRow(Int_t i) const
180{
181// Returns number of pad rows.
182// ---
183
184 return fPadRows[i];
185}
186
187//
188// public methods
189//
190
191//______________________________________________________________________________
192void AliMpVRowSegmentSpecial::AddPadRow(AliMpPadRow* padRow)
193{
194// Adds a pad row.
195// ---
196
197 padRow->SetOffsetX(fOffsetX);
198 padRow->SetID(GetNofPadRows());
199 fPadRows.push_back(padRow);
200}
201
202//______________________________________________________________________________
203void AliMpVRowSegmentSpecial::UpdateMotifVector()
204{
205// Add motifs associated with the pad row segments in the specified
206// pad row in the fMotifs vector.
207// ---
208
209 for (Int_t i=0; i<GetNofPadRows(); i++) {
210 AliMpPadRow* padRow = GetPadRow(i);
211
212 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
213 AliMpVMotif* motif = padRow->GetPadRowSegment(j)->GetMotif();
214
215 if (!HasMotif(motif)) {
216 fMotifs.push_back(motif);
217 fMotifPositionIds.push_back(
218 padRow->GetPadRowSegment(j)->GetMotifPositionId());
219 }
220 }
221 }
222}
223
224//______________________________________________________________________________
225Double_t AliMpVRowSegmentSpecial::HalfSizeY() const
226{
227// Returns the size in y of this row segment.
228// ---
229
230 Double_t halfSizeY = 0.;
231 for (Int_t i=0; i<GetNofPadRows(); i++) {
232 halfSizeY += GetPadRow(i)->HalfSizeY();
233 }
234
235 return halfSizeY;
236}
237
238//______________________________________________________________________________
239AliMpVMotif* AliMpVRowSegmentSpecial::FindMotif(const TVector2& position) const
240{
241// Returns the motif of this row;
242// ---
243
244 AliMpPadRow* padRow
245 = FindPadRow(position.Y());
246
247 if (!padRow) return 0;
248
249 AliMpVPadRowSegment* padRowSegment
250 = padRow->FindPadRowSegment(position.X());
251
252 if (!padRowSegment) return 0;
253
254 return padRowSegment->GetMotif();
255}
256
257//______________________________________________________________________________
258Int_t AliMpVRowSegmentSpecial::FindMotifPositionId(const TVector2& position) const
259{
260// Returns the motif position identified for the given
261// geometric position.
262// ---
263
264 AliMpPadRow* padRow
265 = FindPadRow(position.Y());
266
267 if (!padRow) return 0;
268
269 AliMpVPadRowSegment* padRowSegment
270 = padRow->FindPadRowSegment(position.X());
271
272 if (!padRowSegment) return 0;
273
274 return padRowSegment->GetMotifPositionId();
275}
276
277//______________________________________________________________________________
278Bool_t AliMpVRowSegmentSpecial::HasMotifPosition(Int_t motifPositionId) const
279{
280// Returns true if the motif specified with the given position identifier
281// is in this segment.
282// ---
283
284 if (FindPadRowSegment(motifPositionId))
285 return true;
286 else
287 return false;
288}
289
290//______________________________________________________________________________
291TVector2 AliMpVRowSegmentSpecial::MotifCenter(Int_t motifPositionId) const
292{
293// Returns the coordinates of the motif specified with
294// the given position identifier.
295// ---
296
297 // Try to get the motif position from the motif map first
298 AliMpMotifPosition* motifPosition
299 = GetRow()->GetMotifMap()->FindMotifPosition(motifPositionId);
300 if (motifPosition) return motifPosition->Position();
301
302 // Use slow method otherwise
303 return MotifCenterSlow(motifPositionId);
304}
305
306//______________________________________________________________________________
307TVector2 AliMpVRowSegmentSpecial::Dimensions() const
308{
309// Returns the halflengths in x, y of the row segment rectangular envelope.
310// ---
311
312 Double_t x = 0.;
313 Double_t y = 0.;
314 for (Int_t i=0; i<GetNofPadRows(); i++) {
315 AliMpPadRow* padRow = GetPadRow(i);
316
317 // Add all pad rows y halfsizes
318 y += padRow->HalfSizeY();
319
320 // Find the biggest pad rows x halfsize
321 Double_t xx
322 = (padRow->GetPadRowSegment(0)->RightBorderX() -
323 padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX())/2.;
324 if (xx > x) x = xx;
325 }
326
327 return TVector2(x, y);
328}
329
330//______________________________________________________________________________
331void AliMpVRowSegmentSpecial::SetGlobalIndices()
332{
333// Sets indices limits.
334// ---
335
336 AliMpMotifPosition* firstPos = 0;
337 AliMpMotifPosition* lastPos = 0;
338
339 for (Int_t i=0;i<GetNofMotifs();i++) {
340 AliMpMotifPosition* mPos
341 = GetRow()->GetMotifMap()
342 ->FindMotifPosition(GetMotifPositionId(i));
343
344 if (!firstPos ||
345 mPos->GetLowIndicesLimit().GetFirst()
346 < firstPos->GetLowIndicesLimit().GetFirst())
347 firstPos = mPos;
348
349 if (!lastPos ||
350 mPos->GetHighIndicesLimit().GetFirst()
351 >lastPos->GetHighIndicesLimit().GetFirst())
352 lastPos = mPos;
353 }
354
355 // Check if the motif positions has the limits set
356 if ( !firstPos->HasValidIndices() || !lastPos->HasValidIndices())
357 Fatal("SetGlobalIndices", "Indices of motif positions have to be set first.");
358
359 SetLowIndicesLimit(firstPos->GetLowIndicesLimit());
360 SetHighIndicesLimit(lastPos->GetHighIndicesLimit());
361}
362
363//______________________________________________________________________________
364AliMpRow* AliMpVRowSegmentSpecial::GetRow() const
365{
366// Returns the row.which this row segment belongs to.
367// ---
368
369 return fRow;
370}
371
372//______________________________________________________________________________
373Int_t AliMpVRowSegmentSpecial::GetNofMotifs() const
374{
375// Returns the number of different motifs present in this row segment.
376// ---
377
378 return fMotifs.size();
379}
380
381//______________________________________________________________________________
382AliMpVMotif* AliMpVRowSegmentSpecial::GetMotif(Int_t i) const
383{
384// Returns the i-th motif present in this row segment.
385// ---
386
387 return fMotifs[i];
388}
389
390//______________________________________________________________________________
391Int_t AliMpVRowSegmentSpecial::GetMotifPositionId(Int_t i) const
392{
393// Returns the i-th motif position Id present in this row segment.
394// ---
395
396 return fMotifPositionIds[i];
397}
398