]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpVRowSegmentSpecial.cxx
Mapping test macros (D. Guez, I. Hrivnacova)
[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.
dbe945cc 8// Included in AliRoot: 2003/05/02
ea4cae7a 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
f79c58a5 26#ifdef WITH_ROOT
27const Int_t AliMpVRowSegmentSpecial::fgkMaxNofMotifPositionIds = 20;
28#endif
29
ea4cae7a 30//______________________________________________________________________________
31AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(AliMpRow* row, Double_t offsetX)
32 : AliMpVRowSegment(),
33 fRow(row),
34 fOffsetX(offsetX),
35 fPadRows(),
36 fMotifs(),
37 fMotifPositionIds()
f79c58a5 38#ifdef WITH_ROOT
39 ,fNofMotifPositionIds(0)
40#endif
ea4cae7a 41{
42//
43}
44
45//______________________________________________________________________________
46AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial()
47 : AliMpVRowSegment(),
48 fRow(0),
49 fOffsetX(0.),
50 fPadRows(),
51 fMotifs(),
52 fMotifPositionIds()
f79c58a5 53#ifdef WITH_ROOT
54 ,fNofMotifPositionIds(0)
55#endif
ea4cae7a 56{
57//
f79c58a5 58#ifdef WITH_ROOT
59 fMotifPositionIds.Set(fgkMaxNofMotifPositionIds);
60#endif
ea4cae7a 61}
62
fb1bf5c0 63//_____________________________________________________________________________
64AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(
65 const AliMpVRowSegmentSpecial& right)
66 : AliMpVRowSegment(right) {
67//
68 Fatal("AliMpVRowSegmentSpecial", "Copy constructor not provided.");
69}
70
ea4cae7a 71//______________________________________________________________________________
72AliMpVRowSegmentSpecial::~AliMpVRowSegmentSpecial()
73{
74//
75 for (Int_t i=0; i<GetNofPadRows(); i++)
76 delete fPadRows[i];
77}
78
fb1bf5c0 79//
80// operators
81//
82
83//_____________________________________________________________________________
84AliMpVRowSegmentSpecial&
85AliMpVRowSegmentSpecial::operator=(const AliMpVRowSegmentSpecial& right)
86{
87 // check assignement to self
88 if (this == &right) return *this;
89
90 Fatal("operator =", "Assignement operator not provided.");
91
92 return *this;
93}
94
ea4cae7a 95//
96// protected methods
97//
98
99//______________________________________________________________________________
100AliMpPadRow* AliMpVRowSegmentSpecial::FindPadRow(Double_t y) const
101{
102// Finds the pad row in the given y coordinate.
103// ---
104
105 Double_t lowBorder = fRow->LowBorderY();
106 Double_t highBorder = fRow->LowBorderY();
107
108 for (Int_t i=0; i<GetNofPadRows(); i++) {
109
110 AliMpPadRow* padRow = GetPadRow(i);
111 highBorder += 2.*padRow->HalfSizeY();
112
113 if ( y >= lowBorder && y <= highBorder)
114 return padRow;
115
116 lowBorder = highBorder;
117 }
118
119 return 0;
120}
121
122//______________________________________________________________________________
123AliMpVPadRowSegment*
124AliMpVRowSegmentSpecial::FindPadRowSegment(Int_t motifPositionId) const
125{
126// Find the most down pad row segment with this motifPositionId.
127// ---
128
129 for (Int_t i=0; i<GetNofPadRows(); i++) {
130 AliMpPadRow* padRow = GetPadRow(i);
131
132 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
133 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
134
135 if (padRowSegment->GetMotifPositionId() == motifPositionId)
136 return padRowSegment;
137 }
138 }
139 return 0;
140}
141
142//______________________________________________________________________________
143AliMpIntPair
144AliMpVRowSegmentSpecial::FindRelativeLowIndicesOf(Int_t motifPositionId) const
145{
146// Returns the lowest pad indices where the motif of the given position ID
147// exists in this segment.
148// ---
149
150 AliMpIntPair ans(0,1000);
151 AliMpIntPair ans0 = ans;
152 Int_t maxNofPadsX=0;
153
154 for (Int_t i=0; i<GetNofPadRows(); i++) {
155 AliMpPadRow* padRow = GetPadRow(i);
156
157 Int_t nofPadsX=0;
158 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
159 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
160 nofPadsX += padRowSegment->GetNofPads();
161 if (padRowSegment->GetMotifPositionId() == motifPositionId) {
162 if (ans.GetFirst() < nofPadsX) ans.SetFirst(nofPadsX);
163 if (ans.GetSecond()>i) ans.SetSecond(i);
164 // ans.First = max (nof pads of this pos ID)
165 // ans.Second = min of pad row number
166 }
167 }
168 if (nofPadsX > maxNofPadsX) maxNofPadsX = nofPadsX;
169 }
170 if (ans == ans0) return AliMpIntPair::Invalid();
171
172 return AliMpIntPair(maxNofPadsX-ans.GetFirst(), ans.GetSecond());
173}
174
175//______________________________________________________________________________
176Int_t AliMpVRowSegmentSpecial::MaxNofPadsInRow() const
177{
178// Returns the maximum number of pads in this row segment along the X direction
179// ---
180
181 Int_t maxNofPads = 0;
182
183 for (Int_t i=0; i<GetNofPadRows(); i++){
184 Int_t nofPads = GetPadRow(i)->GetNofPads();
185
186 // Find maximum
187 if (nofPads > maxNofPads) maxNofPads = nofPads;
188 }
189
190 return maxNofPads;
191}
192
193//______________________________________________________________________________
194Bool_t AliMpVRowSegmentSpecial::HasMotif(const AliMpVMotif* motif) const
195{
196// Returns true if the specified motif is already in fMotifs vector,
197// returns false otherwise.
198// ---
199
f79c58a5 200#ifdef WITH_STL
ea4cae7a 201 for (UInt_t i=0; i<fMotifs.size(); i++)
202 if (fMotifs[i] == motif) return true;
f79c58a5 203#endif
204
205#ifdef WITH_ROOT
206 for (Int_t i=0; i<fMotifs.GetEntriesFast(); i++)
b166d013 207 if (fMotifs[i] == (const TObject*)motif) return true;
f79c58a5 208#endif
ea4cae7a 209
210 return false;
211}
212
213//______________________________________________________________________________
214Int_t AliMpVRowSegmentSpecial::GetNofPadRows() const
215{
216// Returns number of pad rows.
217// ---
218
f79c58a5 219#ifdef WITH_STL
ea4cae7a 220 return fPadRows.size();
f79c58a5 221#endif
222
223#ifdef WITH_ROOT
224 return fPadRows.GetEntriesFast();
225#endif
ea4cae7a 226}
227
228//______________________________________________________________________________
229AliMpPadRow* AliMpVRowSegmentSpecial::GetPadRow(Int_t i) const
230{
231// Returns number of pad rows.
232// ---
233
f79c58a5 234#ifdef WITH_STL
ea4cae7a 235 return fPadRows[i];
f79c58a5 236#endif
237
238#ifdef WITH_ROOT
239 return (AliMpPadRow*)fPadRows[i];
240#endif
ea4cae7a 241}
242
243//
244// public methods
245//
246
247//______________________________________________________________________________
248void AliMpVRowSegmentSpecial::AddPadRow(AliMpPadRow* padRow)
249{
250// Adds a pad row.
251// ---
252
253 padRow->SetOffsetX(fOffsetX);
254 padRow->SetID(GetNofPadRows());
f79c58a5 255
256#ifdef WITH_STL
ea4cae7a 257 fPadRows.push_back(padRow);
f79c58a5 258#endif
259
260#ifdef WITH_ROOT
261 fPadRows.Add(padRow);
262#endif
ea4cae7a 263}
264
265//______________________________________________________________________________
266void AliMpVRowSegmentSpecial::UpdateMotifVector()
267{
268// Add motifs associated with the pad row segments in the specified
269// pad row in the fMotifs vector.
270// ---
271
272 for (Int_t i=0; i<GetNofPadRows(); i++) {
273 AliMpPadRow* padRow = GetPadRow(i);
274
275 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
276 AliMpVMotif* motif = padRow->GetPadRowSegment(j)->GetMotif();
277
278 if (!HasMotif(motif)) {
f79c58a5 279#ifdef WITH_STL
ea4cae7a 280 fMotifs.push_back(motif);
281 fMotifPositionIds.push_back(
282 padRow->GetPadRowSegment(j)->GetMotifPositionId());
f79c58a5 283#endif
284#ifdef WITH_ROOT
285 fMotifs.Add(motif);
286
287 // resize array if needed
288 if (fNofMotifPositionIds<fgkMaxNofMotifPositionIds)
289 fMotifPositionIds.Set(fMotifPositionIds.GetSize()+
290 fgkMaxNofMotifPositionIds);
291 fMotifPositionIds.AddAt(
292 padRow->GetPadRowSegment(j)->GetMotifPositionId(),
293 fNofMotifPositionIds++);
294#endif
ea4cae7a 295 }
296 }
297 }
298}
299
300//______________________________________________________________________________
301Double_t AliMpVRowSegmentSpecial::HalfSizeY() const
302{
303// Returns the size in y of this row segment.
304// ---
305
306 Double_t halfSizeY = 0.;
307 for (Int_t i=0; i<GetNofPadRows(); i++) {
308 halfSizeY += GetPadRow(i)->HalfSizeY();
309 }
310
311 return halfSizeY;
312}
313
314//______________________________________________________________________________
315AliMpVMotif* AliMpVRowSegmentSpecial::FindMotif(const TVector2& position) const
316{
317// Returns the motif of this row;
318// ---
319
320 AliMpPadRow* padRow
321 = FindPadRow(position.Y());
322
323 if (!padRow) return 0;
324
325 AliMpVPadRowSegment* padRowSegment
326 = padRow->FindPadRowSegment(position.X());
327
328 if (!padRowSegment) return 0;
329
330 return padRowSegment->GetMotif();
331}
332
333//______________________________________________________________________________
334Int_t AliMpVRowSegmentSpecial::FindMotifPositionId(const TVector2& position) const
335{
336// Returns the motif position identified for the given
337// geometric position.
338// ---
339
340 AliMpPadRow* padRow
341 = FindPadRow(position.Y());
342
343 if (!padRow) return 0;
344
345 AliMpVPadRowSegment* padRowSegment
346 = padRow->FindPadRowSegment(position.X());
347
348 if (!padRowSegment) return 0;
349
350 return padRowSegment->GetMotifPositionId();
351}
352
353//______________________________________________________________________________
354Bool_t AliMpVRowSegmentSpecial::HasMotifPosition(Int_t motifPositionId) const
355{
356// Returns true if the motif specified with the given position identifier
357// is in this segment.
358// ---
359
360 if (FindPadRowSegment(motifPositionId))
361 return true;
362 else
363 return false;
364}
365
366//______________________________________________________________________________
367TVector2 AliMpVRowSegmentSpecial::MotifCenter(Int_t motifPositionId) const
368{
369// Returns the coordinates of the motif specified with
370// the given position identifier.
371// ---
372
373 // Try to get the motif position from the motif map first
374 AliMpMotifPosition* motifPosition
375 = GetRow()->GetMotifMap()->FindMotifPosition(motifPositionId);
376 if (motifPosition) return motifPosition->Position();
377
378 // Use slow method otherwise
379 return MotifCenterSlow(motifPositionId);
380}
381
382//______________________________________________________________________________
383TVector2 AliMpVRowSegmentSpecial::Dimensions() const
384{
385// Returns the halflengths in x, y of the row segment rectangular envelope.
386// ---
387
388 Double_t x = 0.;
389 Double_t y = 0.;
390 for (Int_t i=0; i<GetNofPadRows(); i++) {
391 AliMpPadRow* padRow = GetPadRow(i);
392
393 // Add all pad rows y halfsizes
394 y += padRow->HalfSizeY();
395
396 // Find the biggest pad rows x halfsize
397 Double_t xx
398 = (padRow->GetPadRowSegment(0)->RightBorderX() -
399 padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX())/2.;
400 if (xx > x) x = xx;
401 }
402
403 return TVector2(x, y);
404}
405
406//______________________________________________________________________________
407void AliMpVRowSegmentSpecial::SetGlobalIndices()
408{
409// Sets indices limits.
410// ---
411
412 AliMpMotifPosition* firstPos = 0;
413 AliMpMotifPosition* lastPos = 0;
414
415 for (Int_t i=0;i<GetNofMotifs();i++) {
416 AliMpMotifPosition* mPos
417 = GetRow()->GetMotifMap()
418 ->FindMotifPosition(GetMotifPositionId(i));
419
420 if (!firstPos ||
421 mPos->GetLowIndicesLimit().GetFirst()
422 < firstPos->GetLowIndicesLimit().GetFirst())
423 firstPos = mPos;
424
425 if (!lastPos ||
426 mPos->GetHighIndicesLimit().GetFirst()
427 >lastPos->GetHighIndicesLimit().GetFirst())
428 lastPos = mPos;
429 }
430
431 // Check if the motif positions has the limits set
432 if ( !firstPos->HasValidIndices() || !lastPos->HasValidIndices())
433 Fatal("SetGlobalIndices", "Indices of motif positions have to be set first.");
434
435 SetLowIndicesLimit(firstPos->GetLowIndicesLimit());
436 SetHighIndicesLimit(lastPos->GetHighIndicesLimit());
437}
438
439//______________________________________________________________________________
440AliMpRow* AliMpVRowSegmentSpecial::GetRow() const
441{
442// Returns the row.which this row segment belongs to.
443// ---
444
445 return fRow;
446}
447
448//______________________________________________________________________________
449Int_t AliMpVRowSegmentSpecial::GetNofMotifs() const
450{
451// Returns the number of different motifs present in this row segment.
452// ---
453
f79c58a5 454#ifdef WITH_STL
ea4cae7a 455 return fMotifs.size();
f79c58a5 456#endif
457#ifdef WITH_ROOT
458 return fMotifs.GetEntriesFast();
459#endif
ea4cae7a 460}
461
462//______________________________________________________________________________
463AliMpVMotif* AliMpVRowSegmentSpecial::GetMotif(Int_t i) const
464{
465// Returns the i-th motif present in this row segment.
466// ---
467
f79c58a5 468#ifdef WITH_STL
ea4cae7a 469 return fMotifs[i];
f79c58a5 470#endif
471#ifdef WITH_ROOT
472 return (AliMpVMotif*)fMotifs[i];
473#endif
ea4cae7a 474}
475
476//______________________________________________________________________________
477Int_t AliMpVRowSegmentSpecial::GetMotifPositionId(Int_t i) const
478{
479// Returns the i-th motif position Id present in this row segment.
480// ---
481
482 return fMotifPositionIds[i];
483}
484