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)
59 //________________________________________________________________________
60 AliITSv11GeomCable& AliITSv11GeomCable::operator=(const AliITSv11GeomCable &s) {
61 // Assignment operator
62 // Not fully inplemented yet !!!
64 if(&s == this) return *this;
66 SetTitle(s.GetTitle());
68 // fPointArray = s.fPointArray;
69 // fVolumeArray = s.fVolumeArray;
70 fInitialNode = s.fInitialNode;
74 //________________________________________________________________________
75 AliITSv11GeomCable::~AliITSv11GeomCable() {
80 //________________________________________________________________________
81 void AliITSv11GeomCable::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt,
85 // Add a check point and its volume container to the cable
88 if (iCheckPt>=fVolumeArray.GetEntriesFast()) {
89 fVolumeArray.AddLast(vol);
90 TVectorD *point = new TVectorD(3,coord);
91 fPointArray.AddLast(point);
93 } else if ((iCheckPt >= 0)&&(iCheckPt < fVolumeArray.GetEntriesFast())) {
94 fVolumeArray.AddAt(vol, iCheckPt);
95 TVectorD *point = new TVectorD(3,coord);
96 fPointArray.AddAt(point, iCheckPt);
100 //________________________________________________________________________
101 void AliITSv11GeomCable::ResetPoints() {
103 // Remove all points to the cable
105 fPointArray.Delete();
106 fVolumeArray.Clear();
110 //________________________________________________________________________
111 Int_t AliITSv11GeomCable::GetPoint( Int_t iCheckPt, Double_t *coord)
114 // Get the check point #iCheckPt
116 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
117 CopyFrom(coord, coordVector->GetMatrixArray());
121 //________________________________________________________________________
122 Int_t AliITSv11GeomCable::GetVect( Int_t iCheckPt, Double_t *coord)
125 // Get the orientation vect. related to check point #iCheckPt
128 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
129 CopyFrom(coord, coordVector->GetMatrixArray());
133 //________________________________________________________________________
134 TGeoVolume *AliITSv11GeomCable::GetVolume( Int_t iCheckPt ) const {
136 // Get the volume of check point #iCheckPt
139 if (iCheckPt >= fVolumeArray.GetEntriesFast())
142 return (TGeoVolume *) fVolumeArray.UncheckedAt(iCheckPt);
145 //________________________________________________________________________
146 void AliITSv11GeomCable::SetInitialNode(TGeoVolume *vol) {
148 // Set the starting node, initializing the search for the volume
149 // containing the cable check point
151 if (fInitialNode) delete fInitialNode;
152 fInitialNode = new TGeoNodeMatrix(vol,0);
153 fInitialNode->SetName("nodeInConstruction");
156 //________________________________________________________________________
157 void AliITSv11GeomCable::ResetInitialNode() {
158 // Reset the initial node if it is set.
159 if (fInitialNode) delete fInitialNode;
163 //________________________________________________________________________
164 bool AliITSv11GeomCable::CheckDaughter(TGeoNode* node, Int_t i)
166 // Search where is the current volume in the tree of nodes
167 // stop each time it find the pointer of the current volume
168 // the path is recorded in fNodeInd[]
169 // node is the node where the search start.
170 // !!! recursive function !!!
172 Int_t j = fNodeInd[i];
173 if (node->GetVolume()==fCurrentVol) return kTRUE;
174 TObjArray *array = node->GetNodes();
176 Int_t nDaughters = array->GetEntriesFast();
178 while (j<nDaughters) {
179 TGeoNode *subNode = (TGeoNode *) array->UncheckedAt(j);
181 if (CheckDaughter(subNode, i+1)) return kTRUE;
189 //________________________________________________________________________
190 Int_t AliITSv11GeomCable::
191 GetCheckPoint( Int_t iCheckPt, Int_t iOccur, Int_t motherLevel,
193 // Get the coordinate of the check point number #iCheckPt, which is in the
194 // #iOccur occurrence of the containing volume in the node tree. Coordinates
195 // are given in the coordinate system of the #motherLevel mother level of
198 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
201 if (fInitialNode==0) {
202 TObjArray *nodes = gGeoManager->GetListOfNodes();
203 if (nodes->GetEntriesFast()==0) return kFALSE;
204 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
206 mainNode = fInitialNode;
209 fCurrentVol = GetVolume(iCheckPt);
210 ResetCheckDaughter();
211 Int_t currentOccur = 0;
213 // loop to get the volume position in the tree of nodes
214 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
217 while (fNodeInd[maxLevel]!=-1) maxLevel++;
218 fNodeInd[maxLevel-1]++;
222 while (fNodeInd[maxLevel]!=-1) maxLevel++;
224 if (maxLevel<-1) return kFALSE;
226 TGeoNode *pathNode[fgkCableMaxNodeLevel];
227 pathNode[0] = mainNode;
228 for (Int_t i=0; i<=maxLevel; i++) {
229 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
232 Double_t localCoord[3];
233 GetPoint(iCheckPt, localCoord);
234 CopyFrom(coord, localCoord);
236 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
238 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
239 pathNode[i+1]->GetMatrix()->LocalToMaster(localCoord, coord);
240 CopyFrom(localCoord, coord);
245 //________________________________________________________________________
246 Int_t AliITSv11GeomCable::GetCheckVect( Int_t iCheckPt, Int_t iOccur,
247 Int_t motherLevel, Double_t *coord)
249 // same as GetCheckPoint but with vectorial transformation ...
251 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
254 if (fInitialNode==0) {
255 TObjArray *nodes = gGeoManager->GetListOfNodes();
256 if (nodes->GetEntriesFast()==0) return kFALSE;
257 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
259 mainNode = fInitialNode;
262 fCurrentVol = GetVolume(iCheckPt);
263 ResetCheckDaughter();
264 Int_t currentOccur = 0;
266 // loop to get the volume position in the tree of nodes
267 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
270 while (fNodeInd[maxLevel]!=-1) maxLevel++;
271 fNodeInd[maxLevel-1]++;
275 while (fNodeInd[maxLevel]!=-1) maxLevel++;
277 if (maxLevel<-1) return kFALSE;
279 TGeoNode *pathNode[fgkCableMaxNodeLevel];
280 pathNode[0] = mainNode;
281 for (Int_t i=0; i<=maxLevel; i++) {
282 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
285 Double_t localCoord[3];
286 GetVect(iCheckPt, localCoord);
287 CopyFrom(coord, localCoord);
289 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
291 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
292 pathNode[i+1]->GetMatrix()->LocalToMasterVect(localCoord, coord);
293 CopyFrom(localCoord, coord);
299 //________________________________________________________________________
300 Int_t AliITSv11GeomCable::GetCheckVect( const Double_t *localCoord,
301 TGeoVolume *vol, Int_t iOccur,
302 Int_t motherLevel, Double_t *coord)
305 // Get the global vect (in coord) correponding to the local vector (localCoord)
306 // of the volume vol. Global at the level of #motherLevel level in the node tree
310 if (fInitialNode==0) {
311 TObjArray *nodes = gGeoManager->GetListOfNodes();
312 if (nodes->GetEntriesFast()==0) return kFALSE;
313 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
315 mainNode = fInitialNode; };
318 Int_t currentOccur = 0;
320 // loop to get the volume position in the tree of nodes
321 ResetCheckDaughter();
322 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
325 while (fNodeInd[maxLevel]!=-1) maxLevel++;
326 fNodeInd[maxLevel-1]++;
330 while (fNodeInd[maxLevel]!=-1) maxLevel++;
332 if (maxLevel<-1) return kFALSE;
334 TGeoNode *pathNode[fgkCableMaxNodeLevel];
335 pathNode[0] = mainNode;
336 for (Int_t i=0; i<=maxLevel; i++) {
337 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
340 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
342 Double_t tempCoord[3] = {localCoord[0], localCoord[1], localCoord[2]};
343 CopyFrom(coord, tempCoord);
344 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
345 pathNode[i+1]->GetMatrix()->LocalToMasterVect(tempCoord, coord);
346 CopyFrom(tempCoord, coord);