LCOV - code coverage report
Current view: top level - MUON/MUONmapping - AliMpRow.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 119 151 78.8 %
Date: 2016-06-14 17:26:59 Functions: 23 28 82.1 %

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

Generated by: LCOV version 1.11