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();
55 //________________________________________________________________________
56 AliITSv11GeomCable::AliITSv11GeomCable(const char* name): TNamed(name,""),
63 fPointArray.SetOwner();
67 //________________________________________________________________________
68 AliITSv11GeomCable::AliITSv11GeomCable(const AliITSv11GeomCable &s) :
69 TNamed(s.GetName(),s.GetTitle()),fDebug(s.fDebug),fPointArray(s.fPointArray),
70 fVolumeArray(s.fVolumeArray),fCurrentVol(s.fCurrentVol),fInitialNode(s.fInitialNode)
73 printf("Copy Constructor of AliITSv11GeomCable ???\n");
76 //________________________________________________________________________
77 AliITSv11GeomCable& AliITSv11GeomCable::operator=(const AliITSv11GeomCable &s) {
78 // Assignment operator
79 // Not fully inplemented yet !!!
80 printf("Assignment operator of AliITSv11GeomCable not fully inplemented yet !!!\n");
82 if(&s == this) return *this;
84 SetTitle(s.GetTitle());
86 // fPointArray = s.fPointArray;
87 // fVolumeArray = s.fVolumeArray;
88 fInitialNode = s.fInitialNode;
92 //________________________________________________________________________
93 AliITSv11GeomCable::~AliITSv11GeomCable() {
98 //________________________________________________________________________
99 void AliITSv11GeomCable::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt,
103 // Add a check point and its volume container to the cable
106 if (iCheckPt>=fVolumeArray.GetEntriesFast()) {
107 fVolumeArray.AddLast(vol);
108 TVectorD *point = new TVectorD(3,coord);
109 fPointArray.AddLast(point);
111 } else if ((iCheckPt >= 0)&&(iCheckPt < fVolumeArray.GetEntriesFast())) {
112 fVolumeArray.AddAt(vol, iCheckPt);
113 TVectorD *point = new TVectorD(3,coord);
114 fPointArray.AddAt(point, iCheckPt);
118 //________________________________________________________________________
119 void AliITSv11GeomCable::ResetPoints() {
121 // Remove all points to the cable
123 fPointArray.Delete();
124 fVolumeArray.Clear();
128 //________________________________________________________________________
129 Int_t AliITSv11GeomCable::GetPoint( Int_t iCheckPt, Double_t *coord)
132 // Get the 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 Int_t AliITSv11GeomCable::GetVect( Int_t iCheckPt, Double_t *coord)
147 // Get the orientation vect. related to check point #iCheckPt
150 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
151 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
152 CopyFrom(coord, coordVector->GetElements());
154 CopyFrom(coord, coordVector->GetMatrixArray());
159 //________________________________________________________________________
160 TGeoVolume *AliITSv11GeomCable::GetVolume( Int_t iCheckPt ) const {
162 // Get the volume of check point #iCheckPt
165 if (iCheckPt >= fVolumeArray.GetEntriesFast())
168 return (TGeoVolume *) fVolumeArray.UncheckedAt(iCheckPt);
171 //________________________________________________________________________
172 void AliITSv11GeomCable::SetInitialNode(TGeoVolume *vol) {
174 // Set the starting node, initializing the search for the volume
175 // containing the cable check point
177 if (fInitialNode) delete fInitialNode;
178 fInitialNode = new TGeoNodeMatrix(vol,0);
179 fInitialNode->SetName("nodeInConstruction");
182 //________________________________________________________________________
183 void AliITSv11GeomCable::ResetInitialNode() {
184 // Reset the initial node if it is set.
185 if (fInitialNode) delete fInitialNode;
189 //________________________________________________________________________
190 bool AliITSv11GeomCable::CheckDaughter(TGeoNode* node, Int_t i)
192 // Search where is the current volume in the tree of nodes
193 // stop each time it find the pointer of the current volume
194 // the path is recorded in fNodeInd[]
195 // node is the node where the search start.
196 // !!! recursive function !!!
198 Int_t j = fNodeInd[i];
199 if (node->GetVolume()==fCurrentVol) return kTRUE;
200 TObjArray *array = node->GetNodes();
202 Int_t nDaughters = array->GetEntriesFast();
204 while (j<nDaughters) {
205 TGeoNode *subNode = (TGeoNode *) array->UncheckedAt(j);
207 if (CheckDaughter(subNode, i+1)) return kTRUE;
215 //________________________________________________________________________
216 Int_t AliITSv11GeomCable::
217 GetCheckPoint( Int_t iCheckPt, Int_t iOccur, Int_t motherLevel,
219 // Get the coordinate of the check point number #iCheckPt, which is in the
220 // #iOccur occurrence of the containing volume in the node tree. Coordinates
221 // are given in the coordinate system of the #motherLevel mother level of
224 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
227 if (fInitialNode==0) {
228 TObjArray *nodes = gGeoManager->GetListOfNodes();
229 if (nodes->GetEntriesFast()==0) return kFALSE;
230 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
232 mainNode = fInitialNode;
235 fCurrentVol = GetVolume(iCheckPt);
236 ResetCheckDaughter();
237 Int_t currentOccur = 0;
239 // loop to get the volume position in the tree of nodes
240 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
243 while (fNodeInd[maxLevel]!=-1) maxLevel++;
244 fNodeInd[maxLevel-1]++;
248 while (fNodeInd[maxLevel]!=-1) maxLevel++;
250 if (maxLevel<-1) return kFALSE;
252 TGeoNode *pathNode[fgkCableMaxNodeLevel];
253 pathNode[0] = mainNode;
254 for (Int_t i=0; i<=maxLevel; i++) {
255 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
258 Double_t localCoord[3];
259 GetPoint(iCheckPt, localCoord);
260 CopyFrom(coord, localCoord);
262 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
264 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
265 pathNode[i+1]->GetMatrix()->LocalToMaster(localCoord, coord);
266 CopyFrom(localCoord, coord);
271 //________________________________________________________________________
272 Int_t AliITSv11GeomCable::GetCheckVect( Int_t iCheckPt, Int_t iOccur,
273 Int_t motherLevel, Double_t *coord)
275 // same as GetCheckPoint but with vectorial transformation ...
277 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
280 if (fInitialNode==0) {
281 TObjArray *nodes = gGeoManager->GetListOfNodes();
282 if (nodes->GetEntriesFast()==0) return kFALSE;
283 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
285 mainNode = fInitialNode;
288 fCurrentVol = GetVolume(iCheckPt);
289 ResetCheckDaughter();
290 Int_t currentOccur = 0;
292 // loop to get the volume position in the tree of nodes
293 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
296 while (fNodeInd[maxLevel]!=-1) maxLevel++;
297 fNodeInd[maxLevel-1]++;
301 while (fNodeInd[maxLevel]!=-1) maxLevel++;
303 if (maxLevel<-1) return kFALSE;
305 TGeoNode *pathNode[fgkCableMaxNodeLevel];
306 pathNode[0] = mainNode;
307 for (Int_t i=0; i<=maxLevel; i++) {
308 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
311 Double_t localCoord[3];
312 GetVect(iCheckPt, localCoord);
313 CopyFrom(coord, localCoord);
315 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
317 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
318 pathNode[i+1]->GetMatrix()->LocalToMasterVect(localCoord, coord);
319 CopyFrom(localCoord, coord);
325 //________________________________________________________________________
326 Int_t AliITSv11GeomCable::GetCheckVect( const Double_t *localCoord,
327 TGeoVolume *vol, Int_t iOccur,
328 Int_t motherLevel, Double_t *coord)
331 // Get the global vect (in coord) correponding to the local vector (localCoord)
332 // of the volume vol. Global at the level of #motherLevel level in the node tree
336 if (fInitialNode==0) {
337 TObjArray *nodes = gGeoManager->GetListOfNodes();
338 if (nodes->GetEntriesFast()==0) return kFALSE;
339 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
341 mainNode = fInitialNode; };
344 Int_t currentOccur = 0;
346 // loop to get the volume position in the tree of nodes
347 ResetCheckDaughter();
348 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
351 while (fNodeInd[maxLevel]!=-1) maxLevel++;
352 fNodeInd[maxLevel-1]++;
356 while (fNodeInd[maxLevel]!=-1) maxLevel++;
358 if (maxLevel<-1) return kFALSE;
360 TGeoNode *pathNode[fgkCableMaxNodeLevel];
361 pathNode[0] = mainNode;
362 for (Int_t i=0; i<=maxLevel; i++) {
363 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
366 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
368 Double_t tempCoord[3] = {localCoord[0], localCoord[1], localCoord[2]};
369 CopyFrom(coord, tempCoord);
370 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
371 pathNode[i+1]->GetMatrix()->LocalToMasterVect(tempCoord, coord);
372 CopyFrom(tempCoord, coord);