]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpRow.cxx
Be explicit with the kind of manus we are counting (Laurent)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpRow.cxx
CommitLineData
dee1d5f1 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
5f91c9e8 16// $Id$
13985652 17// $MpId: AliMpRow.cxx,v 1.9 2006/05/24 13:58:46 ivana Exp $
5f91c9e8 18// Category: sector
3d1463c8 19
20//-----------------------------------------------------------------------------
5f91c9e8 21// Class AliMpRow
22// --------------
23// Class describing a row composed of the row segments.
dbe945cc 24// Included in AliRoot: 2003/05/02
5f91c9e8 25// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
3d1463c8 26//-----------------------------------------------------------------------------
5f91c9e8 27
5f91c9e8 28#include "AliMpRow.h"
29#include "AliMpVRowSegment.h"
348e0500 30#include "AliMpVRowSegmentSpecial.h"
31#include "AliMpRowSegmentRSpecial.h"
5f91c9e8 32#include "AliMpVMotif.h"
33#include "AliMpMotifType.h"
34#include "AliMpMotifPosition.h"
35#include "AliMpMotifMap.h"
36#include "AliMpConstants.h"
37
cddd101e 38#include "AliLog.h"
39
2c605e66 40#include <TMath.h>
41#include <Riostream.h>
42
13985652 43/// \cond CLASSIMP
5f91c9e8 44ClassImp(AliMpRow)
13985652 45/// \endcond
5f91c9e8 46
47//_____________________________________________________________________________
48AliMpRow::AliMpRow(Int_t id, AliMpMotifMap* motifMap)
49 : AliMpVIndexed(),
50 fID(id),
51 fOffsetY(0.),
52 fSegments(),
53 fMotifMap(motifMap)
54{
dee1d5f1 55/// Standard constructor
5f91c9e8 56}
57
58//_____________________________________________________________________________
59AliMpRow::AliMpRow()
60 : AliMpVIndexed(),
61 fID(0),
62 fOffsetY(0.),
63 fSegments(),
64 fMotifMap(0)
65{
dee1d5f1 66/// Default constructor
5f91c9e8 67}
68
69//_____________________________________________________________________________
dee1d5f1 70AliMpRow::~AliMpRow()
71{
72/// Destructor
5f91c9e8 73
f79c58a5 74#ifdef WITH_STL
5f91c9e8 75 for (Int_t i=0; i<GetNofRowSegments(); i++)
76 delete fSegments[i];
f79c58a5 77#endif
78
79#ifdef WITH_ROOT
80 fSegments.Delete();
81#endif
5f91c9e8 82}
83
84//
85// private methods
86//
87
88//_____________________________________________________________________________
89AliMpVRowSegment* AliMpRow::FindRowSegment(Int_t ix) const
90{
dee1d5f1 91/// Find first normal row segment with low indices limit >= ix.
5f91c9e8 92
93 for (Int_t i=0; i<GetNofRowSegments(); i++) {
94 AliMpVRowSegment* segment = GetRowSegment(i);
95
348e0500 96 if (!dynamic_cast<AliMpVRowSegmentSpecial*>(segment) &&
5f91c9e8 97 segment->GetHighIndicesLimit().GetFirst() >= ix)
98
99 return segment;
100 }
348e0500 101
5f91c9e8 102 return 0;
103}
104
105//_____________________________________________________________________________
106AliMpMotifPosition*
107AliMpRow::FindMotifPosition(AliMpVRowSegment* segment, Int_t ix) const
108{
dee1d5f1 109/// Find first motif position in the specified row segment
110/// with high indices limit >= ix.
5f91c9e8 111
112 if (!segment) return 0;
113
114 for (Int_t i=0; i<segment->GetNofMotifs(); i++){
115 AliMpMotifPosition* motifPosition
116 = GetMotifMap()->FindMotifPosition(segment->GetMotifPositionId(i));
117
118 if(!motifPosition) {
119 Fatal("FindMotifPosition", "Not found.");
120 return 0;
121 }
122
123 if (motifPosition->GetHighIndicesLimit().GetFirst()>=ix)
124 return motifPosition;
125 }
126
127 return 0;
128}
129
130
131//_____________________________________________________________________________
132void AliMpRow::SetHighIndicesLimits(Int_t iy)
133{
dee1d5f1 134/// Set the global indices high limit to its row segments,
135/// motif positions with a given value.
136/// Keep ix unmodified.
5f91c9e8 137
138 for (Int_t j=0; j<GetNofRowSegments(); j++) {
139 AliMpVRowSegment* rowSegment = GetRowSegment(j);
140 rowSegment
141 ->SetHighIndicesLimit(
142 AliMpIntPair(rowSegment->GetHighIndicesLimit().GetFirst(),iy));
143
144 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
145
146 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
147 AliMpMotifPosition* motifPosition
148 = GetMotifMap()->FindMotifPosition(motifPositionId);
149
150 motifPosition
151 ->SetHighIndicesLimit(
152 AliMpIntPair(motifPosition->GetHighIndicesLimit().GetFirst(), iy));
153
154 }
155 }
156}
157
158//_____________________________________________________________________________
159void AliMpRow::CheckEmpty() const
160{
dee1d5f1 161/// Give a fatal if the row is empty.
5f91c9e8 162
163 if (GetNofRowSegments() == 0)
164 Fatal("CheckEmpty", "Empty row");
165}
166
167//
168// public methods
169//
170
171//_____________________________________________________________________________
172void AliMpRow::AddRowSegment(AliMpVRowSegment* rowSegment)
173{
dee1d5f1 174/// Add row segment at the end.
5f91c9e8 175
f79c58a5 176#ifdef WITH_STL
5f91c9e8 177 fSegments.push_back(rowSegment);
f79c58a5 178#endif
179
180#ifdef WITH_ROOT
181 fSegments.Add(rowSegment);
182#endif
5f91c9e8 183}
184
185//_____________________________________________________________________________
186void AliMpRow::AddRowSegmentInFront(AliMpVRowSegment* rowSegment)
187{
dee1d5f1 188/// Insert row segment in the first vector position.
5f91c9e8 189
f79c58a5 190#ifdef WITH_STL
5f91c9e8 191 fSegments.insert(fSegments.begin(), rowSegment);
f79c58a5 192#endif
193
194#ifdef WITH_ROOT
195 fSegments.AddFirst(rowSegment);
196#endif
5f91c9e8 197}
198
199//_____________________________________________________________________________
200AliMpVRowSegment* AliMpRow::FindRowSegment(Double_t x) const
201{
dee1d5f1 202/// Find the row segment for the specified x position;
203/// return 0 if no row segment is found.
5f91c9e8 204
205 for (Int_t i=0; i<GetNofRowSegments(); i++) {
f79c58a5 206
207#ifdef WITH_STL
5f91c9e8 208 AliMpVRowSegment* rs = fSegments[i];
f79c58a5 209#endif
210#ifdef WITH_ROOT
211 AliMpVRowSegment* rs = (AliMpVRowSegment*)fSegments.At(i);
212#endif
213
5f91c9e8 214 if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
215 return rs;
216 }
217
218 return 0;
219}
220
221//_____________________________________________________________________________
222Double_t AliMpRow::LowBorderY() const
223{
dee1d5f1 224/// Return the lowest row offset (the Y coordinate of the position of the
225/// low border of motif).
5f91c9e8 226
227 CheckEmpty();
228
229 return fOffsetY - GetRowSegment(0)->HalfSizeY();
230}
231
232//_____________________________________________________________________________
233Double_t AliMpRow::UpperBorderY() const
234{
dee1d5f1 235/// Return the uppermost row offset (the Y coordinate of the position of the
236/// upper border of motif).
237\
5f91c9e8 238 CheckEmpty();
239
240 return fOffsetY + GetRowSegment(0)->HalfSizeY();
241}
242
243//_____________________________________________________________________________
244AliMpVPadIterator* AliMpRow::CreateIterator() const
245{
dee1d5f1 246/// Iterator is not implemented.
5f91c9e8 247
dee1d5f1 248 Fatal("CreateIterator", "Iterator is not implemented.");
5f91c9e8 249
250 return 0;
251}
252
253//_____________________________________________________________________________
254void AliMpRow::SetMotifPositions()
255{
dee1d5f1 256/// Create motif positions objects and fills them in the motif map.
5f91c9e8 257
258 CheckEmpty();
259
260 for (Int_t j=0; j<GetNofRowSegments(); j++) {
261 AliMpVRowSegment* rowSegment = GetRowSegment(j);
262
263 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
264 // Get values
265 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
266 AliMpVMotif* motif = rowSegment->GetMotif(k);
267 TVector2 position = rowSegment->MotifCenter(motifPositionId);
268
269 AliMpMotifPosition* motifPosition
270 = new AliMpMotifPosition(motifPositionId, motif, position);
271 // set the initial value to of HighIndicesLimit() Invalid()
272 // (this is used for calculation of indices in case of
273 // special row segments)
274 motifPosition->SetHighIndicesLimit(AliMpIntPair::Invalid());
275
348e0500 276 //Bool_t warn = (rowSegment->GetNofMotifs()==1);
277 Bool_t warn = true;
278 if (dynamic_cast<AliMpVRowSegmentSpecial*>(rowSegment)) warn = false;
5f91c9e8 279 // supress warnings for special row segments
280 // which motifs can overlap the row borders
281
282 Bool_t added = GetMotifMap()->AddMotifPosition(motifPosition, warn);
283
284 if (!added) delete motifPosition;
285 }
286 }
287}
288
289//_____________________________________________________________________________
cddd101e 290void AliMpRow::SetGlobalIndices(AliMp::Direction constPadSizeDirection,
5f91c9e8 291 AliMpRow* rowBefore)
292{
dee1d5f1 293/// Set the global indices limits to its row segments, motif positions
294/// and itself.
5f91c9e8 295
296 Int_t ix = AliMpConstants::StartPadIndex();
297 Int_t iy = AliMpConstants::StartPadIndex();
298
299 for (Int_t j=0; j<GetNofRowSegments(); j++) {
300 AliMpVRowSegment* rowSegment = GetRowSegment(j);
301
302 ix += rowSegment->GetLowIndicesLimit().GetFirst();
303
304 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
305
306 // Find the y index value of the low edge
307 if (rowBefore) {
cddd101e 308 if (constPadSizeDirection == AliMp::kY) {
5f91c9e8 309 iy = rowBefore->GetHighIndicesLimit().GetSecond()+1;
310 }
311 else {
348e0500 312 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ix);
5f91c9e8 313 AliMpMotifPosition* motPos = FindMotifPosition(seg, ix);
348e0500 314 if (!dynamic_cast<AliMpRowSegmentRSpecial*>(rowSegment)) {
315 if (!motPos)
316 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
5f91c9e8 317
348e0500 318 iy = motPos->GetHighIndicesLimit().GetSecond()+1;
319 }
5f91c9e8 320 }
321 }
322
323 // Set (ix, iy) to k-th motif position and update ix
580c28fd 324 ix = rowSegment->SetIndicesToMotifPosition(k, AliMpIntPair(ix, iy));
5f91c9e8 325 }
580c28fd 326 rowSegment->SetGlobalIndices(rowBefore);
5f91c9e8 327 }
328
580c28fd 329 // The low/high indices limits has to be taken as the highest/lowest from all
330 // row segments
331 Int_t ixl = 9999;
332 Int_t iyl = 9999;
333 Int_t ixh = AliMpConstants::StartPadIndex();
334 Int_t iyh = AliMpConstants::StartPadIndex();
5f91c9e8 335
580c28fd 336 for (Int_t i=0; i<GetNofRowSegments(); i++) {
337
338 AliMpVRowSegment* rowSegment = GetRowSegment(i);
339
340 if ( rowSegment->GetLowIndicesLimit().GetFirst() < ixl )
341 ixl = rowSegment->GetLowIndicesLimit().GetFirst();
342
343 if ( rowSegment->GetLowIndicesLimit().GetSecond() < iyl )
344 iyl = rowSegment->GetLowIndicesLimit().GetSecond();
345
346 if ( rowSegment->GetHighIndicesLimit().GetFirst() > ixh )
347 ixh = rowSegment->GetHighIndicesLimit().GetFirst();
348
349 if ( rowSegment->GetHighIndicesLimit().GetSecond() > iyh )
350 iyh = rowSegment->GetHighIndicesLimit().GetSecond();
351 }
352
353 SetLowIndicesLimit(AliMpIntPair(ixl, iyl));
354 SetHighIndicesLimit(AliMpIntPair(ixh, iyh));
5f91c9e8 355}
356
357//_____________________________________________________________________________
358TVector2 AliMpRow::Position() const
359{
dee1d5f1 360/// Return the position of the row centre.
5f91c9e8 361
362 Double_t x = (GetRowSegment(0)->LeftBorderX() +
363 GetRowSegment(GetNofRowSegments()-1)->RightBorderX())/2.;
364
365 Double_t y = fOffsetY;
366
367 return TVector2(x, y);
368}
369
370//_____________________________________________________________________________
371TVector2 AliMpRow::Dimensions() const
372{
dee1d5f1 373/// Return the maximum halflengths of the row in x, y.
5f91c9e8 374
375 Double_t x = (GetRowSegment(GetNofRowSegments()-1)->RightBorderX() -
376 GetRowSegment(0)->LeftBorderX())/2.;
377
378 Double_t y = GetRowSegment(0)->HalfSizeY();
379
380 return TVector2(x, y);
381}
382
383//_____________________________________________________________________________
384void AliMpRow::SetRowSegmentOffsets(const TVector2& offset)
385{
dee1d5f1 386/// Set the row segments offsets in X .
5f91c9e8 387
388 CheckEmpty();
389
390 AliMpVRowSegment* previous = 0;
391
392 for (Int_t j=0; j<GetNofRowSegments(); j++) {
393 AliMpVRowSegment* rowSegment = GetRowSegment(j);
394
395 Double_t offsetX;
396 if (previous)
397 offsetX = previous->RightBorderX();
398 else
399 offsetX = offset.X();
400
401 rowSegment->SetOffset(TVector2(offsetX, 0.));
402 previous = rowSegment;
403 }
404}
405
406
407//_____________________________________________________________________________
408Double_t AliMpRow::SetOffsetY(Double_t offsetY)
409{
dee1d5f1 410/// Set the row offset (the Y coordinate of the position of the
411/// center of motif) and returns the offset of the top border.
5f91c9e8 412
413 CheckEmpty();
414
415 AliMpVRowSegment* first = GetRowSegment(0);
416 Double_t rowSizeY = first->HalfSizeY();
417
418 // Check if all next row segments have motif of
419 // the same size in y
420 for (Int_t i=1; i<GetNofRowSegments(); i++) {
421 Double_t sizeY = GetRowSegment(i)->HalfSizeY();
422
423 if (TMath::Abs(sizeY - rowSizeY) >= AliMpConstants::LengthTolerance()) {
5f91c9e8 424 Fatal("SetOffsetY", "Motif with different Y size in one row");
425 return 0.;
426 }
427 }
428
429 offsetY += rowSizeY ;
430
431 fOffsetY = offsetY;
432
433 return offsetY += rowSizeY;
434}
435
436//_____________________________________________________________________________
437Int_t AliMpRow::GetNofRowSegments() const
438{
dee1d5f1 439/// Return number of row segments.
5f91c9e8 440
f79c58a5 441#ifdef WITH_STL
5f91c9e8 442 return fSegments.size();
f79c58a5 443#endif
444
445#ifdef WITH_ROOT
446 return fSegments.GetSize();
447#endif
5f91c9e8 448}
449
450//_____________________________________________________________________________
451AliMpVRowSegment* AliMpRow::GetRowSegment(Int_t i) const
452{
dee1d5f1 453/// Return i-th row segment.
fb1bf5c0 454
5f91c9e8 455 if (i<0 || i>=GetNofRowSegments()) {
2c605e66 456 AliWarningStream() << "Index outside range" << endl;
5f91c9e8 457 return 0;
458 }
459
f79c58a5 460#ifdef WITH_STL
5f91c9e8 461 return fSegments[i];
f79c58a5 462#endif
463
464#ifdef WITH_ROOT
465 return (AliMpVRowSegment*)fSegments.At(i);
466#endif
5f91c9e8 467}
468