1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 // General Root includes
19 //#include <Riostream.h>
23 // Root Geometry includes
24 #include <TGeoManager.h>
25 #include <TGeoVolume.h>
28 #include "AliITSv11GeomCable.h"
32 //*************************************************************************
33 // Base class of cable classes
36 // Ludovic Gaudichet gaudichet@to.infn.it
37 //*************************************************************************
39 ClassImp(AliITSv11GeomCable)
41 //________________________________________________________________________
42 AliITSv11GeomCable::AliITSv11GeomCable(const char* name) {
46 fPointArray.SetOwner();
51 //________________________________________________________________________
52 AliITSv11GeomCable::AliITSv11GeomCable(const AliITSv11GeomCable &s) :
53 TNamed(s.GetName(),s.GetTitle()),fDebug(s.fDebug),fPointArray(s.fPointArray),
54 fVolumeArray(s.fVolumeArray),fInitialNode(s.fInitialNode)
57 printf("Copy Constructor of AliITSv11GeomCable ???\n");
60 //________________________________________________________________________
61 AliITSv11GeomCable& AliITSv11GeomCable::operator=(const AliITSv11GeomCable &s) {
62 // Assignment operator
63 // Not fully inplemented yet !!!
64 printf("Assignment operator of AliITSv11GeomCable not fully inplemented yet !!!\n");
66 if(&s == this) return *this;
68 SetTitle(s.GetTitle());
70 // fPointArray = s.fPointArray;
71 // fVolumeArray = s.fVolumeArray;
72 fInitialNode = s.fInitialNode;
76 //________________________________________________________________________
77 AliITSv11GeomCable::~AliITSv11GeomCable() {
82 //________________________________________________________________________
83 void AliITSv11GeomCable::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt,
87 // Add a check point and its volume container to the cable
90 if (iCheckPt>=fVolumeArray.GetEntriesFast()) {
91 fVolumeArray.AddLast(vol);
92 TVectorD *point = new TVectorD(3,coord);
93 fPointArray.AddLast(point);
95 } else if ((iCheckPt >= 0)&&(iCheckPt < fVolumeArray.GetEntriesFast())) {
96 fVolumeArray.AddAt(vol, iCheckPt);
97 TVectorD *point = new TVectorD(3,coord);
98 fPointArray.AddAt(point, iCheckPt);
102 //________________________________________________________________________
103 void AliITSv11GeomCable::ResetPoints() {
105 // Remove all points to the cable
107 fPointArray.Delete();
108 fVolumeArray.Clear();
112 //________________________________________________________________________
113 Int_t AliITSv11GeomCable::GetPoint( Int_t iCheckPt, Double_t *coord)
116 // Get the check point #iCheckPt
118 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
119 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
120 CopyFrom(coord, coordVector->GetElements());
122 CopyFrom(coord, coordVector->GetMatrixArray());
127 //________________________________________________________________________
128 Int_t AliITSv11GeomCable::GetVect( Int_t iCheckPt, Double_t *coord)
131 // Get the orientation vect. related to check point #iCheckPt
134 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
135 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
136 CopyFrom(coord, coordVector->GetElements());
138 CopyFrom(coord, coordVector->GetMatrixArray());
143 //________________________________________________________________________
144 TGeoVolume *AliITSv11GeomCable::GetVolume( Int_t iCheckPt ) const {
146 // Get the volume of check point #iCheckPt
149 if (iCheckPt >= fVolumeArray.GetEntriesFast())
152 return (TGeoVolume *) fVolumeArray.UncheckedAt(iCheckPt);
155 //________________________________________________________________________
156 void AliITSv11GeomCable::SetInitialNode(TGeoVolume *vol) {
158 // Set the starting node, initializing the search for the volume
159 // containing the cable check point
161 if (fInitialNode) delete fInitialNode;
162 fInitialNode = new TGeoNodeMatrix(vol,0);
163 fInitialNode->SetName("nodeInConstruction");
166 //________________________________________________________________________
167 void AliITSv11GeomCable::ResetInitialNode() {
168 // Reset the initial node if it is set.
169 if (fInitialNode) delete fInitialNode;
173 //________________________________________________________________________
174 bool AliITSv11GeomCable::CheckDaughter(TGeoNode* node, Int_t i)
176 // Search where is the current volume in the tree of nodes
177 // stop each time it find the pointer of the current volume
178 // the path is recorded in fNodeInd[]
179 // node is the node where the search start.
180 // !!! recursive function !!!
182 Int_t j = fNodeInd[i];
183 if (node->GetVolume()==fCurrentVol) return kTRUE;
184 TObjArray *array = node->GetNodes();
186 Int_t nDaughters = array->GetEntriesFast();
188 while (j<nDaughters) {
189 TGeoNode *subNode = (TGeoNode *) array->UncheckedAt(j);
191 if (CheckDaughter(subNode, i+1)) return kTRUE;
199 //________________________________________________________________________
200 Int_t AliITSv11GeomCable::
201 GetCheckPoint( Int_t iCheckPt, Int_t iOccur, Int_t motherLevel,
203 // Get the coordinate of the check point number #iCheckPt, which is in the
204 // #iOccur occurrence of the containing volume in the node tree. Coordinates
205 // are given in the coordinate system of the #motherLevel mother level of
208 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
211 if (fInitialNode==0) {
212 TObjArray *nodes = gGeoManager->GetListOfNodes();
213 if (nodes->GetEntriesFast()==0) return kFALSE;
214 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
216 mainNode = fInitialNode;
219 fCurrentVol = GetVolume(iCheckPt);
220 ResetCheckDaughter();
221 Int_t currentOccur = 0;
223 // loop to get the volume position in the tree of nodes
224 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
227 while (fNodeInd[maxLevel]!=-1) maxLevel++;
228 fNodeInd[maxLevel-1]++;
232 while (fNodeInd[maxLevel]!=-1) maxLevel++;
234 if (maxLevel<-1) return kFALSE;
236 TGeoNode *pathNode[fgkCableMaxNodeLevel];
237 pathNode[0] = mainNode;
238 for (Int_t i=0; i<=maxLevel; i++) {
239 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
242 Double_t localCoord[3];
243 GetPoint(iCheckPt, localCoord);
244 CopyFrom(coord, localCoord);
246 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
248 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
249 pathNode[i+1]->GetMatrix()->LocalToMaster(localCoord, coord);
250 CopyFrom(localCoord, coord);
255 //________________________________________________________________________
256 Int_t AliITSv11GeomCable::GetCheckVect( Int_t iCheckPt, Int_t iOccur,
257 Int_t motherLevel, Double_t *coord)
259 // same as GetCheckPoint but with vectorial transformation ...
261 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
264 if (fInitialNode==0) {
265 TObjArray *nodes = gGeoManager->GetListOfNodes();
266 if (nodes->GetEntriesFast()==0) return kFALSE;
267 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
269 mainNode = fInitialNode;
272 fCurrentVol = GetVolume(iCheckPt);
273 ResetCheckDaughter();
274 Int_t currentOccur = 0;
276 // loop to get the volume position in the tree of nodes
277 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
280 while (fNodeInd[maxLevel]!=-1) maxLevel++;
281 fNodeInd[maxLevel-1]++;
285 while (fNodeInd[maxLevel]!=-1) maxLevel++;
287 if (maxLevel<-1) return kFALSE;
289 TGeoNode *pathNode[fgkCableMaxNodeLevel];
290 pathNode[0] = mainNode;
291 for (Int_t i=0; i<=maxLevel; i++) {
292 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
295 Double_t localCoord[3];
296 GetVect(iCheckPt, localCoord);
297 CopyFrom(coord, localCoord);
299 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
301 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
302 pathNode[i+1]->GetMatrix()->LocalToMasterVect(localCoord, coord);
303 CopyFrom(localCoord, coord);
309 //________________________________________________________________________
310 Int_t AliITSv11GeomCable::GetCheckVect( const Double_t *localCoord,
311 TGeoVolume *vol, Int_t iOccur,
312 Int_t motherLevel, Double_t *coord)
315 // Get the global vect (in coord) correponding to the local vector (localCoord)
316 // of the volume vol. Global at the level of #motherLevel level in the node tree
320 if (fInitialNode==0) {
321 TObjArray *nodes = gGeoManager->GetListOfNodes();
322 if (nodes->GetEntriesFast()==0) return kFALSE;
323 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
325 mainNode = fInitialNode; };
328 Int_t currentOccur = 0;
330 // loop to get the volume position in the tree of nodes
331 ResetCheckDaughter();
332 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
335 while (fNodeInd[maxLevel]!=-1) maxLevel++;
336 fNodeInd[maxLevel-1]++;
340 while (fNodeInd[maxLevel]!=-1) maxLevel++;
342 if (maxLevel<-1) return kFALSE;
344 TGeoNode *pathNode[fgkCableMaxNodeLevel];
345 pathNode[0] = mainNode;
346 for (Int_t i=0; i<=maxLevel; i++) {
347 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
350 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
352 Double_t tempCoord[3] = {localCoord[0], localCoord[1], localCoord[2]};
353 CopyFrom(coord, tempCoord);
354 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
355 pathNode[i+1]->GetMatrix()->LocalToMasterVect(tempCoord, coord);
356 CopyFrom(tempCoord, coord);