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 <TGeoMatrix.h>
26 #include <TGeoVolume.h>
29 #include "AliITSv11GeomCable.h"
33 //*************************************************************************
34 // Base class of cable classes
37 // Ludovic Gaudichet gaudichet@to.infn.it
38 //*************************************************************************
40 ClassImp(AliITSv11GeomCable)
43 //________________________________________________________________________
44 AliITSv11GeomCable::AliITSv11GeomCable(): TNamed(),
52 fPointArray.SetOwner();
53 for(Int_t i=0;i<fgkCableMaxNodeLevel;i++)fNodeInd[i]=0;
56 //________________________________________________________________________
57 AliITSv11GeomCable::AliITSv11GeomCable(const char* name): TNamed(name,""),
64 fPointArray.SetOwner();
65 for(Int_t i=0;i<fgkCableMaxNodeLevel;i++)fNodeInd[i]=0;
69 //________________________________________________________________________
70 AliITSv11GeomCable::~AliITSv11GeomCable() {
75 //________________________________________________________________________
76 void AliITSv11GeomCable::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt,
80 // Add a check point and its volume container to the cable
83 if (iCheckPt>=fVolumeArray.GetEntriesFast()) {
84 fVolumeArray.AddLast(vol);
85 TVectorD *point = new TVectorD(3,coord);
86 fPointArray.AddLast(point);
88 } else if ((iCheckPt >= 0)&&(iCheckPt < fVolumeArray.GetEntriesFast())) {
89 fVolumeArray.AddAt(vol, iCheckPt);
90 TVectorD *point = new TVectorD(3,coord);
91 fPointArray.AddAt(point, iCheckPt);
95 //________________________________________________________________________
96 void AliITSv11GeomCable::ResetPoints() {
98 // Remove all points to the cable
100 fPointArray.Delete();
101 fVolumeArray.Clear();
105 //________________________________________________________________________
106 Int_t AliITSv11GeomCable::GetPoint( Int_t iCheckPt, Double_t *coord)
109 // Get the check point #iCheckPt
111 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
112 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
113 CopyFrom(coord, coordVector->GetElements());
115 CopyFrom(coord, coordVector->GetMatrixArray());
120 //________________________________________________________________________
121 Int_t AliITSv11GeomCable::GetVect( Int_t iCheckPt, Double_t *coord)
124 // Get the orientation vect. related to check point #iCheckPt
127 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
128 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
129 CopyFrom(coord, coordVector->GetElements());
131 CopyFrom(coord, coordVector->GetMatrixArray());
136 //________________________________________________________________________
137 TGeoVolume *AliITSv11GeomCable::GetVolume( Int_t iCheckPt ) const {
139 // Get the volume of check point #iCheckPt
142 if (iCheckPt >= fVolumeArray.GetEntriesFast())
145 return (TGeoVolume *) fVolumeArray.UncheckedAt(iCheckPt);
148 //________________________________________________________________________
149 void AliITSv11GeomCable::SetInitialNode(TGeoVolume *vol) {
151 // Set the starting node, initializing the search for the volume
152 // containing the cable check point
154 if (fInitialNode) delete fInitialNode;
155 fInitialNode = new TGeoNodeMatrix(vol,0);
156 fInitialNode->SetName("nodeInConstruction");
159 //________________________________________________________________________
160 void AliITSv11GeomCable::ResetInitialNode() {
161 // Reset the initial node if it is set.
162 if (fInitialNode) delete fInitialNode;
166 //________________________________________________________________________
167 bool AliITSv11GeomCable::CheckDaughter(const TGeoNode* node, Int_t i)
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 !!!
175 Int_t j = fNodeInd[i];
176 if (node->GetVolume()==fCurrentVol) return kTRUE;
177 TObjArray *array = node->GetNodes();
179 Int_t nDaughters = array->GetEntriesFast();
181 while (j<nDaughters) {
182 TGeoNode *subNode = (TGeoNode *) array->UncheckedAt(j);
184 if (CheckDaughter(subNode, i+1)) return kTRUE;
192 //________________________________________________________________________
193 Int_t AliITSv11GeomCable::
194 GetCheckPoint( Int_t iCheckPt, Int_t iOccur, Int_t motherLevel,
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
201 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
204 if (fInitialNode==0) {
205 TObjArray *nodes = gGeoManager->GetListOfNodes();
206 if (nodes->GetEntriesFast()==0) return kFALSE;
207 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
209 mainNode = fInitialNode;
212 fCurrentVol = GetVolume(iCheckPt);
213 ResetCheckDaughter();
214 Int_t currentOccur = 0;
216 // loop to get the volume position in the tree of nodes
217 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
220 while (fNodeInd[maxLevel]!=-1) maxLevel++;
221 fNodeInd[maxLevel-1]++;
225 while (fNodeInd[maxLevel]!=-1) maxLevel++;
227 if (maxLevel<-1) return kFALSE;
229 TGeoNode *pathNode[fgkCableMaxNodeLevel];
230 pathNode[0] = mainNode;
231 for (Int_t i=0; i<=maxLevel; i++) {
232 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
235 Double_t localCoord[3];
236 GetPoint(iCheckPt, localCoord);
237 CopyFrom(coord, localCoord);
239 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
241 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
242 pathNode[i+1]->GetMatrix()->LocalToMaster(localCoord, coord);
243 CopyFrom(localCoord, coord);
248 //________________________________________________________________________
249 Int_t AliITSv11GeomCable::GetCheckVect( Int_t iCheckPt, Int_t iOccur,
250 Int_t motherLevel, Double_t *coord)
252 // same as GetCheckPoint but with vectorial transformation ...
254 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
257 if (fInitialNode==0) {
258 TObjArray *nodes = gGeoManager->GetListOfNodes();
259 if (nodes->GetEntriesFast()==0) return kFALSE;
260 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
262 mainNode = fInitialNode;
265 fCurrentVol = GetVolume(iCheckPt);
266 ResetCheckDaughter();
267 Int_t currentOccur = 0;
269 // loop to get the volume position in the tree of nodes
270 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
273 while (fNodeInd[maxLevel]!=-1) maxLevel++;
274 fNodeInd[maxLevel-1]++;
278 while (fNodeInd[maxLevel]!=-1) maxLevel++;
280 if (maxLevel<-1) return kFALSE;
282 TGeoNode *pathNode[fgkCableMaxNodeLevel];
283 pathNode[0] = mainNode;
284 for (Int_t i=0; i<=maxLevel; i++) {
285 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
288 Double_t localCoord[3];
289 GetVect(iCheckPt, localCoord);
290 CopyFrom(coord, localCoord);
292 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
294 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
295 pathNode[i+1]->GetMatrix()->LocalToMasterVect(localCoord, coord);
296 CopyFrom(localCoord, coord);
302 //________________________________________________________________________
303 Int_t AliITSv11GeomCable::GetCheckVect( const Double_t *localCoord,
304 TGeoVolume *vol, Int_t iOccur,
305 Int_t motherLevel, Double_t *coord)
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
313 if (fInitialNode==0) {
314 TObjArray *nodes = gGeoManager->GetListOfNodes();
315 if (nodes->GetEntriesFast()==0) return kFALSE;
316 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
318 mainNode = fInitialNode; };
321 Int_t currentOccur = 0;
323 // loop to get the volume position in the tree of nodes
324 ResetCheckDaughter();
325 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
328 while (fNodeInd[maxLevel]!=-1) maxLevel++;
329 fNodeInd[maxLevel-1]++;
333 while (fNodeInd[maxLevel]!=-1) maxLevel++;
335 if (maxLevel<-1) return kFALSE;
337 TGeoNode *pathNode[fgkCableMaxNodeLevel];
338 pathNode[0] = mainNode;
339 for (Int_t i=0; i<=maxLevel; i++) {
340 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
343 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
345 Double_t tempCoord[3] = {localCoord[0], localCoord[1], localCoord[2]};
346 CopyFrom(coord, tempCoord);
347 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
348 pathNode[i+1]->GetMatrix()->LocalToMasterVect(tempCoord, coord);
349 CopyFrom(tempCoord, coord);