]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpRow.cxx
- Reordering includes from most specific to more general ones
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpRow.cxx
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
16 // $Id$
17 // $MpId: AliMpRow.cxx,v 1.8 2006/03/17 11:38:43 ivana Exp $
18 // Category: sector
19 //
20 // Class AliMpRow
21 // --------------
22 // Class describing a row composed of the row segments.
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
25
26 #include "AliMpRow.h"
27 #include "AliMpVRowSegment.h"
28 #include "AliMpVRowSegmentSpecial.h"
29 #include "AliMpRowSegmentRSpecial.h"
30 #include "AliMpVMotif.h"
31 #include "AliMpMotifType.h"
32 #include "AliMpMotifPosition.h"
33 #include "AliMpMotifMap.h"
34 #include "AliMpConstants.h"
35
36 #include <TMath.h>
37 #include <Riostream.h>
38
39 ClassImp(AliMpRow)
40
41 //_____________________________________________________________________________
42 AliMpRow::AliMpRow(Int_t id, AliMpMotifMap* motifMap) 
43   : AliMpVIndexed(),
44     fID(id),
45     fOffsetY(0.),
46     fSegments(),
47     fMotifMap(motifMap)
48 {
49 /// Standard constructor
50 }
51
52 //_____________________________________________________________________________
53 AliMpRow::AliMpRow() 
54   : AliMpVIndexed(),
55     fID(0),
56     fOffsetY(0.),
57     fSegments(),
58     fMotifMap(0)
59 {
60 /// Default constructor
61 }
62
63 //_____________________________________________________________________________
64 AliMpRow::AliMpRow(const AliMpRow& right) 
65   : AliMpVIndexed(right) 
66 {
67 /// Protected copy constructor (not provided) 
68
69   Fatal("AliMpRow", "Copy constructor not provided.");
70 }
71
72 //_____________________________________________________________________________
73 AliMpRow::~AliMpRow() 
74 {
75 /// Destructor 
76
77 #ifdef WITH_STL
78   for (Int_t i=0; i<GetNofRowSegments(); i++)
79     delete fSegments[i]; 
80 #endif
81
82 #ifdef WITH_ROOT
83   fSegments.Delete();
84 #endif
85 }
86
87 //
88 // operators
89 //
90
91 //_____________________________________________________________________________
92 AliMpRow&  AliMpRow::operator=(const AliMpRow& right)
93 {
94 /// Protected assignment operator (not provided)
95
96   // check assignment to self
97   if (this == &right) return *this;
98
99   Fatal("operator =", "Assignment operator not provided.");
100     
101   return *this;  
102 }    
103
104 //
105 // private methods
106 //
107
108 //_____________________________________________________________________________
109 AliMpVRowSegment*  AliMpRow::FindRowSegment(Int_t ix) const
110 {    
111 /// Find first normal row segment with low indices limit >= ix.
112
113   for (Int_t i=0; i<GetNofRowSegments(); i++) {
114     AliMpVRowSegment* segment = GetRowSegment(i);
115
116     if (!dynamic_cast<AliMpVRowSegmentSpecial*>(segment) &&
117          segment->GetHighIndicesLimit().GetFirst() >= ix)
118          
119      return segment;     
120   }   
121
122   return 0;      
123 }
124
125 //_____________________________________________________________________________
126 AliMpMotifPosition*  
127 AliMpRow::FindMotifPosition(AliMpVRowSegment* segment, Int_t ix) const
128 {
129 /// Find first motif position in the specified row segment 
130 /// with high indices limit >= ix.
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 //_____________________________________________________________________________
152 void AliMpRow::SetHighIndicesLimits(Int_t iy)
153 {
154 /// Set the global indices high limit to its row segments,
155 /// motif positions with a given value.
156 /// Keep ix unmodified.
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 //_____________________________________________________________________________
179 void  AliMpRow::CheckEmpty() const
180 {
181 /// Give a fatal if the row is empty.
182
183   if (GetNofRowSegments() == 0) 
184     Fatal("CheckEmpty", "Empty row");
185 }
186
187 //
188 // public methods
189 //
190
191 //_____________________________________________________________________________
192 void AliMpRow::AddRowSegment(AliMpVRowSegment* rowSegment)
193 {
194 /// Add row segment at the end.
195
196 #ifdef WITH_STL
197   fSegments.push_back(rowSegment);
198 #endif
199
200 #ifdef WITH_ROOT
201   fSegments.Add(rowSegment);
202 #endif
203 }  
204   
205 //_____________________________________________________________________________
206 void AliMpRow::AddRowSegmentInFront(AliMpVRowSegment* rowSegment)
207 {
208 /// Insert row segment in the first vector position.
209
210 #ifdef WITH_STL
211   fSegments.insert(fSegments.begin(), rowSegment);
212 #endif
213
214 #ifdef WITH_ROOT
215   fSegments.AddFirst(rowSegment);
216 #endif
217 }  
218   
219 //_____________________________________________________________________________
220 AliMpVRowSegment* AliMpRow::FindRowSegment(Double_t x) const
221 {
222 /// Find the row segment for the specified x position;
223 /// return 0 if no row segment is found.
224
225   for (Int_t i=0; i<GetNofRowSegments(); i++) {
226
227 #ifdef WITH_STL
228     AliMpVRowSegment* rs = fSegments[i];
229 #endif
230 #ifdef WITH_ROOT
231     AliMpVRowSegment* rs = (AliMpVRowSegment*)fSegments.At(i);
232 #endif
233
234     if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
235       return rs;
236   }
237   
238   return 0;    
239 }    
240
241 //_____________________________________________________________________________
242 Double_t AliMpRow::LowBorderY() const
243 {
244 /// Return the lowest row offset (the Y coordinate of the position of the
245 /// low border of motif).
246
247   CheckEmpty();
248
249   return fOffsetY - GetRowSegment(0)->HalfSizeY();
250 }  
251
252 //_____________________________________________________________________________
253 Double_t AliMpRow::UpperBorderY() const
254 {
255 /// Return the uppermost row offset (the Y coordinate of the position of the
256 /// upper border of motif).
257 \
258   CheckEmpty();
259
260   return fOffsetY + GetRowSegment(0)->HalfSizeY();
261 }  
262
263 //_____________________________________________________________________________
264 AliMpVPadIterator* AliMpRow::CreateIterator() const
265 {
266 /// Iterator is not implemented.
267
268   Fatal("CreateIterator", "Iterator is not implemented.");
269   
270   return 0;
271 }  
272
273 //_____________________________________________________________________________
274 void AliMpRow::SetMotifPositions()
275 {
276 /// Create motif positions objects and fills them in the motif map.
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
296         //Bool_t warn = (rowSegment->GetNofMotifs()==1); 
297         Bool_t warn = true;
298         if (dynamic_cast<AliMpVRowSegmentSpecial*>(rowSegment)) warn = false; 
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 //_____________________________________________________________________________
310 void AliMpRow::SetGlobalIndices(AliMpDirection constPadSizeDirection, 
311                                 AliMpRow* rowBefore)
312 {
313 /// Set the global indices limits to its row segments, motif positions
314 /// and itself.
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 {
332            AliMpVRowSegment* seg = rowBefore->FindRowSegment(ix);       
333            AliMpMotifPosition* motPos =  FindMotifPosition(seg, ix);
334            if (!dynamic_cast<AliMpRowSegmentRSpecial*>(rowSegment)) {
335              if (!motPos) 
336                Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
337            
338              iy = motPos->GetHighIndicesLimit().GetSecond()+1;
339            }  
340          }
341        } 
342
343        // Set (ix, iy) to k-th motif position and update ix
344        ix = rowSegment->SetIndicesToMotifPosition(k, AliMpIntPair(ix, iy));
345     }
346     rowSegment->SetGlobalIndices(rowBefore);    
347   }
348
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();
355
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));
375 }
376
377 //_____________________________________________________________________________
378 TVector2  AliMpRow::Position() const
379 {
380 /// Return the position of the row centre.
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 //_____________________________________________________________________________
391 TVector2  AliMpRow::Dimensions() const
392 {
393 /// Return the maximum halflengths of the row in x, y.
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 //_____________________________________________________________________________
404 void AliMpRow::SetRowSegmentOffsets(const TVector2& offset)
405 {
406 /// Set the row segments offsets in X .
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 //_____________________________________________________________________________
428 Double_t AliMpRow::SetOffsetY(Double_t offsetY)
429 {
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.
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()) {
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 //_____________________________________________________________________________
457 Int_t AliMpRow::GetNofRowSegments() const 
458 {
459 /// Return number of row segments.
460
461 #ifdef WITH_STL
462   return fSegments.size();
463 #endif
464
465 #ifdef WITH_ROOT
466   return fSegments.GetSize();
467 #endif
468 }  
469
470 //_____________________________________________________________________________
471 AliMpVRowSegment* AliMpRow::GetRowSegment(Int_t i) const 
472 {
473 /// Return i-th row segment.
474
475   if (i<0 || i>=GetNofRowSegments()) {
476     AliWarningStream() << "Index outside range" << endl;
477     return 0;
478   }
479   
480 #ifdef WITH_STL
481   return fSegments[i];  
482 #endif
483
484 #ifdef WITH_ROOT
485   return (AliMpVRowSegment*)fSegments.At(i);  
486 #endif
487 }
488