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