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)
42 //________________________________________________________________________
43 AliITSv11GeomCable::AliITSv11GeomCable(): TNamed(),
51 fPointArray.SetOwner();
54 //________________________________________________________________________
55 AliITSv11GeomCable::AliITSv11GeomCable(const char* name): TNamed(name,""),
62 fPointArray.SetOwner();
66 //________________________________________________________________________
67 AliITSv11GeomCable::AliITSv11GeomCable(const AliITSv11GeomCable &s) :
68 TNamed(s.GetName(),s.GetTitle()),fDebug(s.fDebug),fPointArray(s.fPointArray),
69 fVolumeArray(s.fVolumeArray),fCurrentVol(s.fCurrentVol),fInitialNode(s.fInitialNode)
72 printf("Copy Constructor of AliITSv11GeomCable ???\n");
75 //________________________________________________________________________
76 AliITSv11GeomCable& AliITSv11GeomCable::operator=(const AliITSv11GeomCable &s) {
77 // Assignment operator
78 // Not fully inplemented yet !!!
79 printf("Assignment operator of AliITSv11GeomCable not fully inplemented yet !!!\n");
81 if(&s == this) return *this;
83 SetTitle(s.GetTitle());
85 // fPointArray = s.fPointArray;
86 // fVolumeArray = s.fVolumeArray;
87 fInitialNode = s.fInitialNode;
91 //________________________________________________________________________
92 AliITSv11GeomCable::~AliITSv11GeomCable() {
97 //________________________________________________________________________
98 void AliITSv11GeomCable::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt,
102 // Add a check point and its volume container to the cable
105 if (iCheckPt>=fVolumeArray.GetEntriesFast()) {
106 fVolumeArray.AddLast(vol);
107 TVectorD *point = new TVectorD(3,coord);
108 fPointArray.AddLast(point);
110 } else if ((iCheckPt >= 0)&&(iCheckPt < fVolumeArray.GetEntriesFast())) {
111 fVolumeArray.AddAt(vol, iCheckPt);
112 TVectorD *point = new TVectorD(3,coord);
113 fPointArray.AddAt(point, iCheckPt);
117 //________________________________________________________________________
118 void AliITSv11GeomCable::ResetPoints() {
120 // Remove all points to the cable
122 fPointArray.Delete();
123 fVolumeArray.Clear();
127 //________________________________________________________________________
128 Int_t AliITSv11GeomCable::GetPoint( Int_t iCheckPt, Double_t *coord)
131 // Get the check point #iCheckPt
133 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
134 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
135 CopyFrom(coord, coordVector->GetElements());
137 CopyFrom(coord, coordVector->GetMatrixArray());
142 //________________________________________________________________________
143 Int_t AliITSv11GeomCable::GetVect( Int_t iCheckPt, Double_t *coord)
146 // Get the orientation vect. related to check point #iCheckPt
149 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
150 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
151 CopyFrom(coord, coordVector->GetElements());
153 CopyFrom(coord, coordVector->GetMatrixArray());
158 //________________________________________________________________________
159 TGeoVolume *AliITSv11GeomCable::GetVolume( Int_t iCheckPt ) const {
161 // Get the volume of check point #iCheckPt
164 if (iCheckPt >= fVolumeArray.GetEntriesFast())
167 return (TGeoVolume *) fVolumeArray.UncheckedAt(iCheckPt);
170 //________________________________________________________________________
171 void AliITSv11GeomCable::SetInitialNode(TGeoVolume *vol) {
173 // Set the starting node, initializing the search for the volume
174 // containing the cable check point
176 if (fInitialNode) delete fInitialNode;
177 fInitialNode = new TGeoNodeMatrix(vol,0);
178 fInitialNode->SetName("nodeInConstruction");
181 //________________________________________________________________________
182 void AliITSv11GeomCable::ResetInitialNode() {
183 // Reset the initial node if it is set.
184 if (fInitialNode) delete fInitialNode;
188 //________________________________________________________________________
189 bool AliITSv11GeomCable::CheckDaughter(TGeoNode* node, Int_t i)
191 // Search where is the current volume in the tree of nodes
192 // stop each time it find the pointer of the current volume
193 // the path is recorded in fNodeInd[]
194 // node is the node where the search start.
195 // !!! recursive function !!!
197 Int_t j = fNodeInd[i];
198 if (node->GetVolume()==fCurrentVol) return kTRUE;
199 TObjArray *array = node->GetNodes();
201 Int_t nDaughters = array->GetEntriesFast();
203 while (j<nDaughters) {
204 TGeoNode *subNode = (TGeoNode *) array->UncheckedAt(j);
206 if (CheckDaughter(subNode, i+1)) return kTRUE;
214 //________________________________________________________________________
215 Int_t AliITSv11GeomCable::
216 GetCheckPoint( Int_t iCheckPt, Int_t iOccur, Int_t motherLevel,
218 // Get the coordinate of the check point number #iCheckPt, which is in the
219 // #iOccur occurrence of the containing volume in the node tree. Coordinates
220 // are given in the coordinate system of the #motherLevel mother level of
223 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
226 if (fInitialNode==0) {
227 TObjArray *nodes = gGeoManager->GetListOfNodes();
228 if (nodes->GetEntriesFast()==0) return kFALSE;
229 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
231 mainNode = fInitialNode;
234 fCurrentVol = GetVolume(iCheckPt);
235 ResetCheckDaughter();
236 Int_t currentOccur = 0;
238 // loop to get the volume position in the tree of nodes
239 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
242 while (fNodeInd[maxLevel]!=-1) maxLevel++;
243 fNodeInd[maxLevel-1]++;
247 while (fNodeInd[maxLevel]!=-1) maxLevel++;
249 if (maxLevel<-1) return kFALSE;
251 TGeoNode *pathNode[fgkCableMaxNodeLevel];
252 pathNode[0] = mainNode;
253 for (Int_t i=0; i<=maxLevel; i++) {
254 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
257 Double_t localCoord[3];
258 GetPoint(iCheckPt, localCoord);
259 CopyFrom(coord, localCoord);
261 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
263 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
264 pathNode[i+1]->GetMatrix()->LocalToMaster(localCoord, coord);
265 CopyFrom(localCoord, coord);
270 //________________________________________________________________________
271 Int_t AliITSv11GeomCable::GetCheckVect( Int_t iCheckPt, Int_t iOccur,
272 Int_t motherLevel, Double_t *coord)
274 // same as GetCheckPoint but with vectorial transformation ...
276 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
279 if (fInitialNode==0) {
280 TObjArray *nodes = gGeoManager->GetListOfNodes();
281 if (nodes->GetEntriesFast()==0) return kFALSE;
282 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
284 mainNode = fInitialNode;
287 fCurrentVol = GetVolume(iCheckPt);
288 ResetCheckDaughter();
289 Int_t currentOccur = 0;
291 // loop to get the volume position in the tree of nodes
292 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
295 while (fNodeInd[maxLevel]!=-1) maxLevel++;
296 fNodeInd[maxLevel-1]++;
300 while (fNodeInd[maxLevel]!=-1) maxLevel++;
302 if (maxLevel<-1) return kFALSE;
304 TGeoNode *pathNode[fgkCableMaxNodeLevel];
305 pathNode[0] = mainNode;
306 for (Int_t i=0; i<=maxLevel; i++) {
307 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
310 Double_t localCoord[3];
311 GetVect(iCheckPt, localCoord);
312 CopyFrom(coord, localCoord);
314 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
316 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
317 pathNode[i+1]->GetMatrix()->LocalToMasterVect(localCoord, coord);
318 CopyFrom(localCoord, coord);
324 //________________________________________________________________________
325 Int_t AliITSv11GeomCable::GetCheckVect( const Double_t *localCoord,
326 TGeoVolume *vol, Int_t iOccur,
327 Int_t motherLevel, Double_t *coord)
330 // Get the global vect (in coord) correponding to the local vector (localCoord)
331 // of the volume vol. Global at the level of #motherLevel level in the node tree
335 if (fInitialNode==0) {
336 TObjArray *nodes = gGeoManager->GetListOfNodes();
337 if (nodes->GetEntriesFast()==0) return kFALSE;
338 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
340 mainNode = fInitialNode; };
343 Int_t currentOccur = 0;
345 // loop to get the volume position in the tree of nodes
346 ResetCheckDaughter();
347 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
350 while (fNodeInd[maxLevel]!=-1) maxLevel++;
351 fNodeInd[maxLevel-1]++;
355 while (fNodeInd[maxLevel]!=-1) maxLevel++;
357 if (maxLevel<-1) return kFALSE;
359 TGeoNode *pathNode[fgkCableMaxNodeLevel];
360 pathNode[0] = mainNode;
361 for (Int_t i=0; i<=maxLevel; i++) {
362 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
365 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
367 Double_t tempCoord[3] = {localCoord[0], localCoord[1], localCoord[2]};
368 CopyFrom(coord, tempCoord);
369 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
370 pathNode[i+1]->GetMatrix()->LocalToMasterVect(tempCoord, coord);
371 CopyFrom(tempCoord, coord);