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