LCOV - code coverage report
Current view: top level - MUON/MUONmapping - AliMpRowSegment.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 90 114 78.9 %
Date: 2016-06-14 17:26:59 Functions: 28 31 90.3 %

          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: AliMpRowSegment.cxx,v 1.10 2006/05/24 13:58:46 ivana Exp $
      18             : // Category: sector
      19             : 
      20             : //-----------------------------------------------------------------------------
      21             : // Class AliMpRowSegment
      22             : // ---------------------
      23             : // Class describing a row segment composed of the 
      24             : // the identic motifs.
      25             : // Included in AliRoot: 2003/05/02
      26             : // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
      27             : //-----------------------------------------------------------------------------
      28             : 
      29             : #include "AliMpRowSegment.h"
      30             : #include "AliMpRow.h"
      31             : #include "AliMpVMotif.h"
      32             : #include "AliMpMotifType.h"
      33             : #include "AliMpMotifTypePadIterator.h"
      34             : #include "AliMpMotifMap.h"
      35             : #include "AliMpMotifPosition.h"
      36             : #include "AliMpConstants.h"
      37             : #include "AliMpEncodePair.h"
      38             : 
      39             : #include "AliLog.h"
      40             : 
      41             : #include <TMath.h>
      42             : #include <Riostream.h>
      43             : 
      44             : using std::endl;
      45             : /// \cond CLASSIMP
      46          18 : ClassImp(AliMpRowSegment)
      47             : /// \endcond
      48             : 
      49             : //_____________________________________________________________________________
      50             : AliMpRowSegment::AliMpRowSegment(AliMpRow* row, AliMpVMotif* motif, 
      51             :                                  Int_t padOffsetX, Int_t padOffsetY,
      52             :                                  Int_t nofMotifs,
      53             :                                  Int_t motifPositionId, Int_t motifPositionDId)
      54         525 :   : AliMpVRowSegment(),
      55         525 :     fNofMotifs(nofMotifs),
      56        1050 :     fLPadOffset(AliMp::Pair(padOffsetX,padOffsetY)),
      57         525 :     fOffsetX(0.),
      58         525 :     fOffsetY(0.),
      59         525 :     fRow(row),
      60         525 :     fMotif(motif),
      61         525 :     fMotifPositionId(motifPositionId),
      62         525 :     fMotifPositionDId(motifPositionDId)
      63        2625 : {
      64             : /// Standard constructor
      65             :  
      66             :   // Keep pad offset in the low indices limits
      67         525 :   SetLowIndicesLimit(fLPadOffset);
      68        1050 : }
      69             : 
      70             : //_____________________________________________________________________________
      71             : AliMpRowSegment::AliMpRowSegment() 
      72           0 :   : AliMpVRowSegment(),
      73           0 :     fNofMotifs(0),
      74           0 :     fLPadOffset(0),
      75           0 :     fOffsetX(0.),
      76           0 :     fOffsetY(0.),
      77           0 :     fRow(0),
      78           0 :     fMotif(0),
      79           0 :     fMotifPositionId(0),
      80           0 :     fMotifPositionDId(0)
      81           0 : {
      82             : /// Default constructor
      83           0 : }
      84             : 
      85             : //_____________________________________________________________________________
      86             : AliMpRowSegment::~AliMpRowSegment() 
      87        1400 : {
      88             : /// Destructor  
      89        1400 : }
      90             : 
      91             : //
      92             : // private methods  
      93             : //
      94             : 
      95             : //_____________________________________________________________________________
      96             : Double_t AliMpRowSegment::FirstMotifCenterX() const
      97             : {
      98             : /// Return the x coordinate of the first motif center
      99             : /// in the global coordinate system.
     100             : 
     101       20684 :   return fOffsetX;
     102             : }  
     103             : 
     104             : //_____________________________________________________________________________
     105             : Double_t AliMpRowSegment::LastMotifCenterX() const
     106             : {
     107             : /// Return the x coordinate of the last motif center
     108             : /// in the global coordinate system.
     109             : 
     110       16168 :   return fOffsetX + 2.*(fNofMotifs-1)*fMotif->DimensionX();
     111             : }
     112             : 
     113             : //_____________________________________________________________________________
     114             : Double_t AliMpRowSegment::MotifCenterX(Int_t motifPositionId) const
     115             : {
     116             : /// Return the x coordinate of the motif specified with
     117             : /// the given position identifier.
     118             : 
     119             :   // Check if x is in the row segment range
     120        5058 :   if (! HasMotifPosition(motifPositionId)) {
     121           0 :     AliErrorStream() << "Outside row segment region" << endl;
     122           0 :     return 0;
     123             :   }
     124             :   
     125             :   // Find the position number in the segment  
     126        2529 :   Int_t num = (motifPositionId - fMotifPositionId) *  fMotifPositionDId;
     127             : 
     128        2529 :   return fOffsetX + num*(fMotif->DimensionX() * 2.0);
     129        2529 : }
     130             : 
     131             : //_____________________________________________________________________________
     132             : Double_t AliMpRowSegment::MotifCenterY(Int_t motifPositionId) const
     133             : {
     134             : /// Return the y coordinate of the motif specified with
     135             : /// the given position identifier.
     136             : 
     137             :   // Check if x is in the row segment range
     138        5058 :   if (! HasMotifPosition(motifPositionId)) {
     139           0 :     AliErrorStream() << "Outside row segment region" << endl;
     140           0 :     return 0;
     141             :   }
     142             :   
     143        2529 :   return GetRow()->GetPositionY() + fOffsetY;
     144        2529 : }
     145             : 
     146             : //_____________________________________________________________________________
     147             : Bool_t AliMpRowSegment::IsInside(Double_t x, Double_t y, Bool_t warn) const
     148             : {
     149             : /// Check if the position is inside some motif of this row segment.
     150             : 
     151        2657 :   Double_t minY = GetRow()->GetPositionY() + fOffsetY - fMotif->DimensionY();
     152        2657 :   Double_t maxY = GetRow()->GetPositionY() + fOffsetY + fMotif->DimensionY();
     153             : 
     154        7971 :   if ( x < LeftBorderX() || x > RightBorderX() ||
     155        5314 :        y < minY || y > maxY ) {
     156             : 
     157           0 :     if (warn)
     158           0 :       AliWarningStream() << "Outside row segment region" << endl;
     159           0 :     return false;
     160             :   }
     161             :   else
     162        2657 :     return true;
     163        2657 : }    
     164             : 
     165             : //
     166             : // public methods  
     167             : //
     168             : 
     169             : //_____________________________________________________________________________
     170             : Double_t  AliMpRowSegment::LeftBorderX() const
     171             : {
     172             : /// Return the x coordinate of the left row segment border
     173             : /// in the global coordinate system.
     174             : 
     175       20684 :   return FirstMotifCenterX() - fMotif->DimensionX();
     176             : }
     177             : 
     178             : //_____________________________________________________________________________
     179             : Double_t  AliMpRowSegment::RightBorderX() const
     180             : {
     181             : /// Return the x coordinate of the right row segment border
     182             : /// in the global coordinate system.
     183             : 
     184       16168 :   return LastMotifCenterX() + fMotif->DimensionX();
     185             : }
     186             : 
     187             : //_____________________________________________________________________________
     188             : Double_t  AliMpRowSegment::HalfSizeY() const
     189             : {
     190             : /// Return the size in y of this row segment.
     191             : 
     192       21638 :   return fMotif->DimensionY() + fOffsetY;
     193             : }
     194             : 
     195             : //_____________________________________________________________________________
     196             : AliMpVMotif*  AliMpRowSegment::FindMotif(Double_t x, Double_t y) const
     197             : {
     198             : /// Return the motif of this row; 
     199             : 
     200           0 :   if ( IsInside(x, y, false) )
     201           0 :     return fMotif;
     202             :   else  
     203           0 :     return 0;
     204           0 : }  
     205             : 
     206             : //_____________________________________________________________________________
     207             : Int_t AliMpRowSegment::FindMotifPositionId(Double_t x, Double_t y) const
     208             : {
     209             : /// Return the motif position identified for the given
     210             : /// geometric position.
     211             : 
     212        5314 :   if ( ! IsInside(x, y, false) ) return 0;
     213             : 
     214             :   // Find the position number in the segment  
     215             :   Int_t num 
     216        2657 :     = Int_t((x - LeftBorderX()) / (fMotif->DimensionX() * 2.0));
     217             : 
     218             :   // Calculate the position Id
     219        2657 :   return fMotifPositionId + num*fMotifPositionDId;  
     220        2657 : }
     221             : 
     222             : //_____________________________________________________________________________
     223             : Bool_t AliMpRowSegment::HasMotifPosition(Int_t motifPositionId) const
     224             : {
     225             : /// Return true if the motif specified with the given position identifier
     226             : /// is in this segment.
     227             : 
     228       15174 :   Int_t minId = TMath::Min(fMotifPositionId, 
     229        5058 :                     fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
     230       10116 :   Int_t maxId = TMath::Max(fMotifPositionId, 
     231        5058 :                     fMotifPositionId + (fNofMotifs-1)*fMotifPositionDId);
     232             : 
     233       10116 :   if (motifPositionId >= minId && motifPositionId <= maxId) {
     234        5058 :     return true;
     235             :   }
     236             :   else 
     237           0 :     return false;
     238        5058 : }
     239             : 
     240             : //_____________________________________________________________________________
     241             : void AliMpRowSegment::MotifCenter(Int_t motifPositionId,
     242             :                                   Double_t& x, Double_t& y) const
     243             : {
     244             : /// Return the coordinates of the motif specified with
     245             : /// the given position identifier.
     246             : 
     247        5058 :   x = MotifCenterX(motifPositionId);
     248        2529 :   y = MotifCenterY(motifPositionId);
     249        2529 : }
     250             : 
     251             : //_____________________________________________________________________________
     252             : Double_t AliMpRowSegment::GetPositionX() const
     253             : {
     254             : /// Return the x position of the row segment centre.
     255             : 
     256         336 :   return (LeftBorderX() + RightBorderX())/2.;               
     257             : }
     258             : 
     259             : //_____________________________________________________________________________
     260             : Double_t AliMpRowSegment::GetPositionY() const
     261             : {
     262             : /// Return the y position of the row segment centre.
     263             : 
     264         336 :   return GetRow()->GetPositionY();  
     265             : }
     266             : 
     267             : //_____________________________________________________________________________
     268             : Double_t AliMpRowSegment::GetDimensionX() const
     269             : {
     270             : /// Return the halflengths of the row segment in x, y.
     271             : // ---
     272             : 
     273         336 :   return (RightBorderX() - LeftBorderX())/2.;               
     274             : }
     275             : 
     276             : //_____________________________________________________________________________
     277             : Double_t AliMpRowSegment::GetDimensionY() const
     278             : {
     279             : /// Return the halflengths of the row segment in x, y.
     280             : // ---
     281             : 
     282         336 :   return GetRow()->GetDimensionY();  
     283             : }
     284             : 
     285             : //_____________________________________________________________________________
     286             : void   AliMpRowSegment::SetOffset(Double_t x, Double_t y)
     287             : {
     288             : /// Calculate offset from given offset and 
     289             : /// stored offset in pads.
     290             : 
     291        1050 :   AliMpMotifTypePadIterator iter(fMotif->GetMotifType());
     292         525 :   iter.First();
     293             : 
     294        1575 :   Int_t ix = iter.CurrentItem().GetIx();
     295        1575 :   Int_t iy = iter.CurrentItem().GetIy();
     296             :   
     297         525 :   Double_t dx, dy;
     298         525 :   fMotif->GetPadDimensionsByIndices(ix, iy, dx, dy);  
     299             : 
     300         525 :   fOffsetX 
     301        2100 :      = x + 2.*AliMp::PairFirst(fLPadOffset) * dx + fMotif->DimensionX(); 
     302             : 
     303         525 :   fOffsetY
     304        1575 :     = y + AliMp::PairSecond(fLPadOffset) * dy; 
     305         525 : }
     306             : 
     307             : //_____________________________________________________________________________
     308             : void AliMpRowSegment::SetGlobalIndices(AliMpRow* /*rowBefore*/)
     309             : {
     310             : /// Set global indices limits.
     311             : 
     312             :   // The low/high indices limits has to be taken as the highest/lowest from all 
     313             :   // motif positions
     314             :   Int_t ixl = 9999;
     315             :   Int_t iyl = 9999;
     316        1050 :   Int_t ixh = AliMpConstants::StartPadIndex();
     317         525 :   Int_t iyh = AliMpConstants::StartPadIndex();
     318             : 
     319        6108 :   for (Int_t i=0; i<GetNofMotifs(); i++) {
     320             :      
     321             :      AliMpMotifPosition* mPos 
     322        2529 :        = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
     323             :        
     324             :      // Check if the motif positions has the limits set
     325        2529 :      if ( !mPos->HasValidIndices() )
     326           0 :        Fatal("SetGlobalIndices", 
     327             :              "Indices of motif positions have to be set first.");
     328             :             
     329        2529 :      if ( mPos->GetLowLimitIx() < ixl ) 
     330         525 :        ixl = mPos->GetLowLimitIx();
     331             :        
     332        2529 :      if ( mPos->GetLowLimitIy() < iyl ) 
     333         702 :        iyl = mPos->GetLowLimitIy();
     334             : 
     335        2529 :      if ( mPos->GetHighLimitIx() > ixh ) 
     336        2529 :        ixh = mPos->GetHighLimitIx();
     337             :        
     338        2529 :      if ( mPos->GetHighLimitIy() > iyh ) 
     339         525 :        iyh = mPos->GetHighLimitIy();
     340             :   }     
     341             : 
     342         525 :   SetLowIndicesLimit(ixl, iyl);
     343         525 :   SetHighIndicesLimit(ixh, iyh);
     344         525 : }  
     345             : 
     346             : //_____________________________________________________________________________
     347             : Int_t AliMpRowSegment::SetIndicesToMotifPosition(Int_t i, MpPair_t indices)
     348             : {
     349             : /// Set global indices to i-th motif position and returns next index
     350             : /// in x.
     351             : 
     352             :   // Get motif position
     353             :   AliMpMotifPosition* motifPosition
     354        5058 :     = GetRow()->GetMotifMap()->FindMotifPosition(GetMotifPositionId(i));
     355             : 
     356             :   // Low limit
     357        2529 :   MpPair_t low = indices + AliMp::Pair(0, GetLowLimitIy());
     358        2529 :   motifPosition->SetLowIndicesLimit(low);
     359             :           
     360             :   // High limit
     361        2529 :   AliMpMotifType* motifType = motifPosition->GetMotif()->GetMotifType();    
     362             :   MpPair_t high
     363        2529 :     = motifPosition->GetLowIndicesLimit()
     364        2529 :       + AliMp::Pair(motifType->GetNofPadsX()-1, motifType->GetNofPadsY()-1);
     365        2529 :   motifPosition->SetHighIndicesLimit(high);
     366             : 
     367             :   // Return next index in x
     368        2529 :   return AliMp::PairFirst(high)+1;
     369             :   // return motifType->GetNofPadsX();
     370             : }
     371             : 
     372             : 
     373             : //_____________________________________________________________________________
     374             : AliMpRow*  AliMpRowSegment::GetRow() const
     375             : {
     376             : /// Return the row.which this row segment belongs to.
     377             : 
     378       26474 :   return fRow;
     379             : }  
     380             : 
     381             : //_____________________________________________________________________________
     382             : Int_t  AliMpRowSegment::GetNofMotifs() const
     383             : {
     384             : /// Return number of motifs in this this row segment.
     385             : 
     386       33220 :   return fNofMotifs;
     387             : }  
     388             : 
     389             : //_____________________________________________________________________________
     390             : Int_t  AliMpRowSegment::GetMotifPositionId(Int_t i) const
     391             : {
     392             : /// Return number of motifs in this this row segment.
     393             : 
     394       29734 :   return fMotifPositionId + i*fMotifPositionDId;
     395             : }  
     396             : 
     397             : //_____________________________________________________________________________
     398             : AliMpVMotif*  AliMpRowSegment::GetMotif(Int_t /*i*/) const
     399             : {
     400             : /// Return the motif of this row segment.
     401             : 
     402        5058 :   return fMotif;
     403             : }  

Generated by: LCOV version 1.11