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