LCOV - code coverage report
Current view: top level - ITS/ITSsim - AliITSv11GeomCable.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 108 149 72.5 %
Date: 2016-06-14 17:26:59 Functions: 11 19 57.9 %

          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             : 
      17             : 
      18             : // General Root includes
      19             : //#include <Riostream.h>
      20             : //#include <TMath.h>
      21             : #include <TVectorD.h>
      22             : 
      23             : // Root Geometry includes
      24             : #include <TGeoManager.h>
      25             : #include <TGeoMatrix.h>
      26             : #include <TGeoVolume.h>
      27             : #include <TGeoNode.h>
      28             : 
      29             : #include "AliITSv11GeomCable.h"
      30             : 
      31             : 
      32             : 
      33             : //*************************************************************************
      34             : //   Base class of cable classes
      35             : //
      36             : //
      37             : // Ludovic Gaudichet                                   gaudichet@to.infn.it
      38             : //*************************************************************************
      39             : 
      40         116 : ClassImp(AliITSv11GeomCable)
      41             : 
      42             : 
      43             : //________________________________________________________________________
      44          44 : AliITSv11GeomCable::AliITSv11GeomCable(): TNamed(),
      45          44 :   fDebug(0),
      46          44 :   fPointArray(),
      47          44 :   fVolumeArray(),
      48          44 :   fCurrentVol(0),
      49          44 :   fInitialNode(0)
      50         132 : { 
      51             :   // constructor
      52          44 :   fPointArray.SetOwner();
      53        4488 :   for(Int_t i=0;i<fgkCableMaxNodeLevel;i++)fNodeInd[i]=0;
      54          44 : }
      55             : 
      56             : //________________________________________________________________________
      57          56 : AliITSv11GeomCable::AliITSv11GeomCable(const char* name): TNamed(name,""),
      58          56 :   fDebug(0),
      59          56 :   fPointArray(),
      60          56 :   fVolumeArray(),
      61          56 :   fCurrentVol(0),
      62         224 :   fInitialNode(0) { 
      63             :   // constructor
      64          56 :   fPointArray.SetOwner(); 
      65        5712 :   for(Int_t i=0;i<fgkCableMaxNodeLevel;i++)fNodeInd[i]=0;
      66          56 : }
      67             : 
      68             : 
      69             : //________________________________________________________________________
      70         176 : AliITSv11GeomCable::~AliITSv11GeomCable() {
      71          88 :   fPointArray.Clear();
      72          88 :   fVolumeArray.Clear();
      73          88 : }
      74             : 
      75             : //________________________________________________________________________
      76             : void AliITSv11GeomCable::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt,
      77             :                                         Double_t *coord)
      78             : {
      79             :   //
      80             :   // Add a check point and its volume container to the cable
      81             :   //
      82             : 
      83           0 :   if (iCheckPt>=fVolumeArray.GetEntriesFast()) {
      84           0 :     fVolumeArray.AddLast(vol);
      85           0 :     TVectorD *point = new TVectorD(3,coord);
      86           0 :     fPointArray.AddLast(point);
      87             : 
      88           0 :   } else if ((iCheckPt >= 0)&&(iCheckPt < fVolumeArray.GetEntriesFast())) {
      89           0 :     fVolumeArray.AddAt(vol, iCheckPt);
      90           0 :     TVectorD *point = new TVectorD(3,coord);
      91           0 :     fPointArray.AddAt(point, iCheckPt);
      92           0 :   };
      93           0 : }
      94             : 
      95             : //________________________________________________________________________
      96             : void AliITSv11GeomCable::ResetPoints() {
      97             :   //
      98             :   // Remove all points to the cable
      99             :   //
     100          38 :   fPointArray.Delete();
     101          19 :   fVolumeArray.Clear();
     102          19 : }
     103             : 
     104             : 
     105             : //________________________________________________________________________
     106             : Int_t AliITSv11GeomCable::GetPoint( Int_t iCheckPt,  Double_t *coord)
     107             : const {
     108             :   //
     109             :   // Get the check point #iCheckPt
     110             :   //
     111           0 :   TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
     112             : #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
     113             :   CopyFrom(coord, coordVector->GetElements());
     114             : #else
     115           0 :   CopyFrom(coord, coordVector->GetMatrixArray());
     116             : #endif
     117           0 :   return kTRUE;
     118             : }
     119             : 
     120             : //________________________________________________________________________
     121             : Int_t AliITSv11GeomCable::GetVect( Int_t iCheckPt,  Double_t *coord)
     122             : const {
     123             :   //
     124             :   //  Get the orientation vect. related to check point #iCheckPt
     125             :   //
     126             : 
     127           0 :   TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
     128             : #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
     129             :   CopyFrom(coord, coordVector->GetElements());
     130             : #else
     131           0 :   CopyFrom(coord, coordVector->GetMatrixArray());
     132             : #endif
     133           0 :   return kTRUE;
     134             : }
     135             : 
     136             : //________________________________________________________________________
     137             : TGeoVolume *AliITSv11GeomCable::GetVolume( Int_t iCheckPt ) const {
     138             :   //
     139             :   // Get the volume of check point #iCheckPt
     140             :   //
     141             : 
     142        2460 :   if (iCheckPt >= fVolumeArray.GetEntriesFast())
     143           0 :     return 0;
     144             :   else
     145        1230 :     return (TGeoVolume *) fVolumeArray.UncheckedAt(iCheckPt);
     146        1230 : }
     147             : 
     148             : //________________________________________________________________________
     149             : void AliITSv11GeomCable::SetInitialNode(TGeoVolume *vol) {
     150             :   //
     151             :   // Set the starting node, initializing the search for the volume
     152             :   // containing the cable check point
     153             :   //
     154         196 :   if (fInitialNode) delete fInitialNode;
     155         196 :   fInitialNode = new TGeoNodeMatrix(vol,0);
     156          98 :   fInitialNode->SetName("nodeInConstruction");
     157          98 : }
     158             : 
     159             : //________________________________________________________________________
     160             : void AliITSv11GeomCable::ResetInitialNode() {
     161             :   // Reset the initial node if it is set.
     162           0 :   if (fInitialNode) delete fInitialNode;
     163           0 :   fInitialNode = 0;
     164           0 : }
     165             : 
     166             : //________________________________________________________________________
     167             : bool AliITSv11GeomCable::CheckDaughter(const TGeoNode* node, Int_t i)
     168             : {
     169             : // Search where is the current volume in the tree of nodes
     170             : // stop each time it find the pointer of the current volume
     171             : // the path is recorded in fNodeInd[]
     172             : // node is the node where the search start.
     173             : // !!! recursive function !!!
     174             : 
     175     1495822 :   Int_t j = fNodeInd[i];
     176      749252 :   if (node->GetVolume()==fCurrentVol) return kTRUE;
     177      746570 :   TObjArray *array = node->GetNodes();
     178      746570 :   if (array) {
     179      199932 :     Int_t nDaughters = array->GetEntriesFast();
     180      399864 :     if (j==-1) j++;
     181      946018 :     while (j<nDaughters) {
     182      746570 :       TGeoNode *subNode = (TGeoNode *) array->UncheckedAt(j);
     183      746570 :       fNodeInd[i] = j;
     184      747054 :       if (CheckDaughter(subNode, i+1)) return kTRUE;
     185      746086 :       j++;
     186      746086 :     };
     187      199448 :     fNodeInd[i] = -1;
     188      199448 :   };
     189      746086 :   return kFALSE;
     190      747911 : }
     191             : 
     192             : //________________________________________________________________________
     193             : Int_t AliITSv11GeomCable::
     194             : GetCheckPoint( Int_t iCheckPt, Int_t iOccur, Int_t motherLevel,
     195             :                Double_t *coord ) {
     196             : // Get the coordinate of the check point number #iCheckPt, which is in the
     197             : // #iOccur occurrence of the containing volume in the node tree. Coordinates
     198             : // are given in the coordinate system of the #motherLevel mother level of
     199             : // this volume
     200             :   
     201         820 :   if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
     202             : 
     203             :   TGeoNode *mainNode;
     204         410 :   if (fInitialNode==0) {
     205           0 :     TObjArray *nodes = gGeoManager->GetListOfNodes();
     206           0 :     if (nodes->GetEntriesFast()==0) return kFALSE;
     207           0 :     mainNode = (TGeoNode *) nodes->UncheckedAt(0);
     208           0 :   } else {
     209             :     mainNode = fInitialNode;
     210             :   };
     211             : 
     212         410 :   fCurrentVol = GetVolume(iCheckPt);
     213         410 :   ResetCheckDaughter();
     214             :   Int_t currentOccur = 0;
     215             : 
     216             :   // loop to get the volume position in the tree of nodes
     217        1230 :   while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
     218           0 :     currentOccur++;
     219             :     Int_t maxLevel = 0;
     220           0 :     while (fNodeInd[maxLevel]!=-1) maxLevel++;
     221           0 :     fNodeInd[maxLevel-1]++;
     222             :   };
     223             : 
     224             :   Int_t maxLevel = 0;
     225        1076 :   while (fNodeInd[maxLevel]!=-1) maxLevel++;
     226         410 :   maxLevel--;
     227         410 :   if (maxLevel<-1) return kFALSE;
     228             : 
     229         410 :   TGeoNode *pathNode[fgkCableMaxNodeLevel];
     230         410 :   pathNode[0] = mainNode;
     231        1076 :   for (Int_t i=0; i<=maxLevel; i++) {
     232         128 :     pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
     233             :   };
     234             : 
     235         410 :   Double_t localCoord[3];
     236         410 :   GetPoint(iCheckPt, localCoord);
     237         410 :   CopyFrom(coord, localCoord);
     238             : 
     239         410 :   if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
     240             : 
     241         892 :   for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
     242          36 :     pathNode[i+1]->GetMatrix()->LocalToMaster(localCoord, coord);
     243          36 :     CopyFrom(localCoord, coord);
     244             :   };
     245             :   return kTRUE;
     246         820 : }
     247             : 
     248             : //________________________________________________________________________
     249             : Int_t AliITSv11GeomCable::GetCheckVect( Int_t iCheckPt, Int_t iOccur,
     250             :                                         Int_t motherLevel, Double_t *coord)
     251             : {
     252             : // same as GetCheckPoint but with vectorial transformation ...
     253             : 
     254         820 :   if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
     255             : 
     256             :   TGeoNode *mainNode;
     257         410 :   if (fInitialNode==0) {
     258           0 :     TObjArray *nodes = gGeoManager->GetListOfNodes();
     259           0 :     if (nodes->GetEntriesFast()==0) return kFALSE;
     260           0 :     mainNode = (TGeoNode *) nodes->UncheckedAt(0);
     261           0 :   } else {
     262             :     mainNode = fInitialNode;
     263             :   };
     264             : 
     265         410 :   fCurrentVol = GetVolume(iCheckPt);
     266         410 :   ResetCheckDaughter();
     267             :   Int_t currentOccur = 0;
     268             : 
     269             :   // loop to get the volume position in the tree of nodes
     270        1230 :   while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
     271           0 :     currentOccur++;
     272             :     Int_t maxLevel = 0;
     273           0 :     while (fNodeInd[maxLevel]!=-1) maxLevel++;
     274           0 :     fNodeInd[maxLevel-1]++;
     275             :   };
     276             : 
     277             :   Int_t maxLevel = 0;
     278        1076 :   while (fNodeInd[maxLevel]!=-1) maxLevel++;
     279         410 :   maxLevel--;
     280         410 :   if (maxLevel<-1) return kFALSE;
     281             : 
     282         410 :   TGeoNode *pathNode[fgkCableMaxNodeLevel];
     283         410 :   pathNode[0] = mainNode;
     284        1076 :   for (Int_t i=0; i<=maxLevel; i++) {
     285         128 :     pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
     286             :   };
     287             : 
     288         410 :   Double_t localCoord[3];
     289         410 :   GetVect(iCheckPt, localCoord);
     290         410 :   CopyFrom(coord, localCoord);
     291             : 
     292         410 :   if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
     293             : 
     294         892 :   for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
     295          36 :     pathNode[i+1]->GetMatrix()->LocalToMasterVect(localCoord, coord);
     296          36 :     CopyFrom(localCoord, coord);
     297             :   };
     298             :   return kTRUE;
     299         820 : }
     300             : 
     301             : 
     302             : //________________________________________________________________________
     303             : Int_t AliITSv11GeomCable::GetCheckVect( const Double_t *localCoord,
     304             :                                         TGeoVolume *vol, Int_t iOccur,
     305             :                                         Int_t motherLevel, Double_t *coord)
     306             : {
     307             :   //
     308             :   // Get the global vect (in coord) correponding to the local vector (localCoord)
     309             :   // of the volume vol. Global at the level of #motherLevel level in the node tree
     310             :   //
     311             : 
     312             :   TGeoNode *mainNode;
     313         560 :   if (fInitialNode==0) {
     314           0 :     TObjArray *nodes = gGeoManager->GetListOfNodes();
     315           0 :     if (nodes->GetEntriesFast()==0) return kFALSE;
     316           0 :     mainNode = (TGeoNode *) nodes->UncheckedAt(0);
     317           0 :   } else {
     318             :     mainNode = fInitialNode; };
     319             : 
     320         280 :   fCurrentVol = vol;
     321             :   Int_t currentOccur = 0;
     322             : 
     323             :   // loop to get the volume position in the tree of nodes
     324         280 :   ResetCheckDaughter();
     325         840 :   while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
     326           0 :     currentOccur++;
     327             :     Int_t maxLevel = 0;
     328           0 :     while (fNodeInd[maxLevel]!=-1) maxLevel++;
     329           0 :     fNodeInd[maxLevel-1]++;
     330             :   };
     331             : 
     332             :   Int_t maxLevel = 0;
     333         816 :   while (fNodeInd[maxLevel]!=-1) maxLevel++;
     334         280 :   maxLevel--;
     335         280 :   if (maxLevel<-1) return kFALSE;
     336             : 
     337         280 :   TGeoNode *pathNode[fgkCableMaxNodeLevel];
     338         280 :   pathNode[0] = mainNode;
     339         816 :   for (Int_t i=0; i<=maxLevel; i++) {
     340         128 :     pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
     341             :   };
     342             : 
     343         560 :   if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
     344             : 
     345         280 :   Double_t tempCoord[3] = {localCoord[0], localCoord[1], localCoord[2]};
     346         280 :   CopyFrom(coord, tempCoord);
     347        1376 :   for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
     348         408 :     pathNode[i+1]->GetMatrix()->LocalToMasterVect(tempCoord, coord);
     349         408 :     CopyFrom(tempCoord, coord);
     350             :   };
     351             :   return kTRUE;
     352         560 : }
     353             : 

Generated by: LCOV version 1.11