]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpRow.cxx
new class AliMUONLoader
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpRow.cxx
CommitLineData
5f91c9e8 1// $Id$
2// Category: sector
3//
4// Class AliMpRow
5// --------------
6// Class describing a row composed of the row segments.
7//
8// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
9
10#include <Riostream.h>
11#include <TError.h>
12#include <TMath.h>
13
14#include "AliMpRow.h"
15#include "AliMpVRowSegment.h"
16#include "AliMpRowSegmentSpecial.h"
17#include "AliMpVMotif.h"
18#include "AliMpMotifType.h"
19#include "AliMpMotifPosition.h"
20#include "AliMpMotifMap.h"
21#include "AliMpConstants.h"
22
23ClassImp(AliMpRow)
24
25//_____________________________________________________________________________
26AliMpRow::AliMpRow(Int_t id, AliMpMotifMap* motifMap)
27 : AliMpVIndexed(),
28 fID(id),
29 fOffsetY(0.),
30 fSegments(),
31 fMotifMap(motifMap)
32{
33//
34}
35
36//_____________________________________________________________________________
37AliMpRow::AliMpRow()
38 : AliMpVIndexed(),
39 fID(0),
40 fOffsetY(0.),
41 fSegments(),
42 fMotifMap(0)
43{
44//
45}
46
47//_____________________________________________________________________________
48AliMpRow::~AliMpRow() {
49//
50
51 for (Int_t i=0; i<GetNofRowSegments(); i++)
52 delete fSegments[i];
53}
54
55//
56// private methods
57//
58
59//_____________________________________________________________________________
60AliMpVRowSegment* AliMpRow::FindRowSegment(Int_t ix) const
61{
62// Finds first normal row segment with low indices limit >= ix.
63// ---
64
65 for (Int_t i=0; i<GetNofRowSegments(); i++) {
66 AliMpVRowSegment* segment = GetRowSegment(i);
67
68 if (!dynamic_cast<AliMpRowSegmentSpecial*>(segment) &&
69 segment->GetHighIndicesLimit().GetFirst() >= ix)
70
71 return segment;
72 }
73
74 return 0;
75}
76
77//_____________________________________________________________________________
78AliMpMotifPosition*
79AliMpRow::FindMotifPosition(AliMpVRowSegment* segment, Int_t ix) const
80{
81// Finds first motif position in the specified row segment
82// with high indices limit >= ix.
83// ---
84
85 if (!segment) return 0;
86
87 for (Int_t i=0; i<segment->GetNofMotifs(); i++){
88 AliMpMotifPosition* motifPosition
89 = GetMotifMap()->FindMotifPosition(segment->GetMotifPositionId(i));
90
91 if(!motifPosition) {
92 Fatal("FindMotifPosition", "Not found.");
93 return 0;
94 }
95
96 if (motifPosition->GetHighIndicesLimit().GetFirst()>=ix)
97 return motifPosition;
98 }
99
100 return 0;
101}
102
103
104//_____________________________________________________________________________
105void AliMpRow::SetHighIndicesLimits(Int_t iy)
106{
107// Sets the global indices high limit to its row segments,
108// motif positions with a given value.
109// Keeps ix unmodified.
110// ---
111
112 for (Int_t j=0; j<GetNofRowSegments(); j++) {
113 AliMpVRowSegment* rowSegment = GetRowSegment(j);
114 rowSegment
115 ->SetHighIndicesLimit(
116 AliMpIntPair(rowSegment->GetHighIndicesLimit().GetFirst(),iy));
117
118 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
119
120 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
121 AliMpMotifPosition* motifPosition
122 = GetMotifMap()->FindMotifPosition(motifPositionId);
123
124 motifPosition
125 ->SetHighIndicesLimit(
126 AliMpIntPair(motifPosition->GetHighIndicesLimit().GetFirst(), iy));
127
128 }
129 }
130}
131
132//_____________________________________________________________________________
133void AliMpRow::CheckEmpty() const
134{
135// Give a fatal if row is empty.
136// ---
137
138 if (GetNofRowSegments() == 0)
139 Fatal("CheckEmpty", "Empty row");
140}
141
142//
143// public methods
144//
145
146//_____________________________________________________________________________
147void AliMpRow::AddRowSegment(AliMpVRowSegment* rowSegment)
148{
149// Adds row segment at the end.
150// ---
151
152 fSegments.push_back(rowSegment);
153}
154
155//_____________________________________________________________________________
156void AliMpRow::AddRowSegmentInFront(AliMpVRowSegment* rowSegment)
157{
158// Inserts row segment in the first vector position.
159// ---
160
161 fSegments.insert(fSegments.begin(), rowSegment);
162}
163
164//_____________________________________________________________________________
165AliMpVRowSegment* AliMpRow::FindRowSegment(Double_t x) const
166{
167// Finds the row segment for the specified x position;
168// returns 0 if no row segment is found.
169// ---
170
171 for (Int_t i=0; i<GetNofRowSegments(); i++) {
172 AliMpVRowSegment* rs = fSegments[i];
173 if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
174 return rs;
175 }
176
177 return 0;
178}
179
180//_____________________________________________________________________________
181Double_t AliMpRow::LowBorderY() const
182{
183// Returns the lowest row offset (the Y coordinate of the position of the
184// low border of motif).
185// ---
186
187 CheckEmpty();
188
189 return fOffsetY - GetRowSegment(0)->HalfSizeY();
190}
191
192//_____________________________________________________________________________
193Double_t AliMpRow::UpperBorderY() const
194{
195// Returns the uppermost row offset (the Y coordinate of the position of the
196// upper border of motif).
197// ---
198
199 CheckEmpty();
200
201 return fOffsetY + GetRowSegment(0)->HalfSizeY();
202}
203
204//_____________________________________________________________________________
205AliMpVPadIterator* AliMpRow::CreateIterator() const
206{
207// Iterator is not yet implemented.
208// ---
209
210 Fatal("CreateIterator", "Iterator is not yet implemented.");
211
212 return 0;
213}
214
215//_____________________________________________________________________________
216void AliMpRow::SetMotifPositions()
217{
218// Creates motif positions objects and fills them in the motif map.
219// ---
220
221 CheckEmpty();
222
223 for (Int_t j=0; j<GetNofRowSegments(); j++) {
224 AliMpVRowSegment* rowSegment = GetRowSegment(j);
225
226 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
227 // Get values
228 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
229 AliMpVMotif* motif = rowSegment->GetMotif(k);
230 TVector2 position = rowSegment->MotifCenter(motifPositionId);
231
232 AliMpMotifPosition* motifPosition
233 = new AliMpMotifPosition(motifPositionId, motif, position);
234 // set the initial value to of HighIndicesLimit() Invalid()
235 // (this is used for calculation of indices in case of
236 // special row segments)
237 motifPosition->SetHighIndicesLimit(AliMpIntPair::Invalid());
238
239 Bool_t warn = (rowSegment->GetNofMotifs()==1);
240 // supress warnings for special row segments
241 // which motifs can overlap the row borders
242
243 Bool_t added = GetMotifMap()->AddMotifPosition(motifPosition, warn);
244
245 if (!added) delete motifPosition;
246 }
247 }
248}
249
250//_____________________________________________________________________________
251void AliMpRow::SetGlobalIndices(AliMpDirection constPadSizeDirection,
252 AliMpRow* rowBefore)
253{
254// Sets the global indices limits to its row segments,
255// motif positions.
256// ---
257
258 Int_t ix = AliMpConstants::StartPadIndex();
259 Int_t iy = AliMpConstants::StartPadIndex();
260
261 for (Int_t j=0; j<GetNofRowSegments(); j++) {
262 AliMpVRowSegment* rowSegment = GetRowSegment(j);
263
264 ix += rowSegment->GetLowIndicesLimit().GetFirst();
265
266 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
267
268 // Find the y index value of the low edge
269 if (rowBefore) {
270 if (constPadSizeDirection == kY) {
271 iy = rowBefore->GetHighIndicesLimit().GetSecond()+1;
272 }
273 else {
274 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ix);
275 AliMpMotifPosition* motPos = FindMotifPosition(seg, ix);
276 if (!motPos)
277 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
278
279 iy = motPos->GetHighIndicesLimit().GetSecond()+1;
280 }
281 }
282
283 // Set (ix, iy) to k-th motif position and update ix
284 ix = rowSegment->SetIndicesToMotifPosition(k, AliMpIntPair(ix, iy));
285 }
286 rowSegment->SetGlobalIndices();
287 }
288
289 SetLowIndicesLimit(GetRowSegment(0)->GetLowIndicesLimit());
290 SetHighIndicesLimit(GetRowSegment(GetNofRowSegments()-1)->GetHighIndicesLimit());
291
292 return ;
293}
294
295//_____________________________________________________________________________
296TVector2 AliMpRow::Position() const
297{
298// Returns the position of the row centre.
299// ---
300
301 Double_t x = (GetRowSegment(0)->LeftBorderX() +
302 GetRowSegment(GetNofRowSegments()-1)->RightBorderX())/2.;
303
304 Double_t y = fOffsetY;
305
306 return TVector2(x, y);
307}
308
309//_____________________________________________________________________________
310TVector2 AliMpRow::Dimensions() const
311{
312// Returns the maximum halflengths of the row in x, y.
313// ---
314
315 Double_t x = (GetRowSegment(GetNofRowSegments()-1)->RightBorderX() -
316 GetRowSegment(0)->LeftBorderX())/2.;
317
318 Double_t y = GetRowSegment(0)->HalfSizeY();
319
320 return TVector2(x, y);
321}
322
323//_____________________________________________________________________________
324void AliMpRow::SetRowSegmentOffsets(const TVector2& offset)
325{
326// Sets the row segments offsets in X .
327// ---
328
329 CheckEmpty();
330
331 AliMpVRowSegment* previous = 0;
332
333 for (Int_t j=0; j<GetNofRowSegments(); j++) {
334 AliMpVRowSegment* rowSegment = GetRowSegment(j);
335
336 Double_t offsetX;
337 if (previous)
338 offsetX = previous->RightBorderX();
339 else
340 offsetX = offset.X();
341
342 rowSegment->SetOffset(TVector2(offsetX, 0.));
343 previous = rowSegment;
344 }
345}
346
347
348//_____________________________________________________________________________
349Double_t AliMpRow::SetOffsetY(Double_t offsetY)
350{
351// Sets the row offset (the Y coordinate of the position of the
352// center of motif) and returns the offset of the top border.
353// ---
354
355 CheckEmpty();
356
357 AliMpVRowSegment* first = GetRowSegment(0);
358 Double_t rowSizeY = first->HalfSizeY();
359
360 // Check if all next row segments have motif of
361 // the same size in y
362 for (Int_t i=1; i<GetNofRowSegments(); i++) {
363 Double_t sizeY = GetRowSegment(i)->HalfSizeY();
364
365 if (TMath::Abs(sizeY - rowSizeY) >= AliMpConstants::LengthTolerance()) {
366 cout << GetID() << "th row " << i << "th segment "
367 << sizeY << " " << rowSizeY << endl;
368 Fatal("SetOffsetY", "Motif with different Y size in one row");
369 return 0.;
370 }
371 }
372
373 offsetY += rowSizeY ;
374
375 fOffsetY = offsetY;
376
377 return offsetY += rowSizeY;
378}
379
380//_____________________________________________________________________________
381Int_t AliMpRow::GetNofRowSegments() const
382{
383// Returns number of row segments.
384
385 return fSegments.size();
386}
387
388//_____________________________________________________________________________
389AliMpVRowSegment* AliMpRow::GetRowSegment(Int_t i) const
390{
391 if (i<0 || i>=GetNofRowSegments()) {
392 Warning("GetRowSegment", "Index outside range");
393 return 0;
394 }
395
396 return fSegments[i];
397}
398