]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSv11GeomCable.cxx
Bug fix (Yu.Belikov)
[u/mrichter/AliRoot.git] / ITS / AliITSv11GeomCable.cxx
CommitLineData
b7943f00 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16
17
18// General Root includes
19//#include <Riostream.h>
20//#include <TMath.h>
21#include <TVectorD.h>
22
23// Root Geometry includes
24#include <TGeoManager.h>
25#include <TGeoVolume.h>
26#include <TGeoNode.h>
27
28#include "AliITSv11GeomCable.h"
29
30
31
32//*************************************************************************
33// Base class of cable classes
34//
35//
36// Ludovic Gaudichet gaudichet@to.infn.it
37//*************************************************************************
38
39ClassImp(AliITSv11GeomCable)
40
41//________________________________________________________________________
42AliITSv11GeomCable::AliITSv11GeomCable(const char* name) {
43 // constructor
44 fDebug = 0;
45 fInitialNode = 0;
46 fPointArray.SetOwner();
47 SetName(name);
48};
49
50
51//________________________________________________________________________
52AliITSv11GeomCable::AliITSv11GeomCable(const AliITSv11GeomCable &s) :
53 TNamed(s.GetName(),s.GetTitle()),fDebug(s.fDebug),fPointArray(s.fPointArray),
54 fVolumeArray(s.fVolumeArray),fInitialNode(s.fInitialNode)
55{
56 // Copy Constructor
57}
58
59//________________________________________________________________________
60AliITSv11GeomCable& AliITSv11GeomCable::operator=(const AliITSv11GeomCable &s) {
61 // Assignment operator
62 // Not fully inplemented yet !!!
63
64 if(&s == this) return *this;
65 SetName(s.GetName());
66 SetTitle(s.GetTitle());
67 fDebug = s.fDebug;
68// fPointArray = s.fPointArray;
69// fVolumeArray = s.fVolumeArray;
70 fInitialNode = s.fInitialNode;
71 return *this;
72}
73
74//________________________________________________________________________
75AliITSv11GeomCable::~AliITSv11GeomCable() {
76 fPointArray.Clear();
77 fVolumeArray.Clear();
78};
79
80//________________________________________________________________________
81void AliITSv11GeomCable::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt,
82 Double_t *coord)
83{
84 //
85 // Add a check point and its volume container to the cable
86 //
87
88 if (iCheckPt>=fVolumeArray.GetEntriesFast()) {
89 fVolumeArray.AddLast(vol);
90 TVectorD *point = new TVectorD(3,coord);
91 fPointArray.AddLast(point);
92
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);
97 };
98};
99
100//________________________________________________________________________
101void AliITSv11GeomCable::ResetPoints() {
102 //
103 // Remove all points to the cable
104 //
105 fPointArray.Delete();
106 fVolumeArray.Clear();
107};
108
109
110//________________________________________________________________________
111Int_t AliITSv11GeomCable::GetPoint( Int_t iCheckPt, Double_t *coord)
112const {
113 //
114 // Get the check point #iCheckPt
115 //
116 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
99d29480 117#if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
118 CopyFrom(coord, coordVector->GetElements());
119#else
b7943f00 120 CopyFrom(coord, coordVector->GetMatrixArray());
99d29480 121#endif
b7943f00 122 return kTRUE;
123};
124
125//________________________________________________________________________
126Int_t AliITSv11GeomCable::GetVect( Int_t iCheckPt, Double_t *coord)
127const {
128 //
129 // Get the orientation vect. related to check point #iCheckPt
130 //
131
132 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
99d29480 133#if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
134 CopyFrom(coord, coordVector->GetElements());
135#else
b7943f00 136 CopyFrom(coord, coordVector->GetMatrixArray());
99d29480 137#endif
b7943f00 138 return kTRUE;
139};
140
141//________________________________________________________________________
142TGeoVolume *AliITSv11GeomCable::GetVolume( Int_t iCheckPt ) const {
143 //
144 // Get the volume of check point #iCheckPt
145 //
146
147 if (iCheckPt >= fVolumeArray.GetEntriesFast())
148 return 0;
149 else
150 return (TGeoVolume *) fVolumeArray.UncheckedAt(iCheckPt);
151};
152
153//________________________________________________________________________
154void AliITSv11GeomCable::SetInitialNode(TGeoVolume *vol) {
155 //
156 // Set the starting node, initializing the search for the volume
157 // containing the cable check point
158 //
159 if (fInitialNode) delete fInitialNode;
160 fInitialNode = new TGeoNodeMatrix(vol,0);
161 fInitialNode->SetName("nodeInConstruction");
162};
163
164//________________________________________________________________________
165void AliITSv11GeomCable::ResetInitialNode() {
166 // Reset the initial node if it is set.
167 if (fInitialNode) delete fInitialNode;
168 fInitialNode = 0;
169};
170
171//________________________________________________________________________
172bool AliITSv11GeomCable::CheckDaughter(TGeoNode* node, Int_t i)
173{
174// Search where is the current volume in the tree of nodes
175// stop each time it find the pointer of the current volume
176// the path is recorded in fNodeInd[]
177// node is the node where the search start.
178// !!! recursive function !!!
179
180 Int_t j = fNodeInd[i];
181 if (node->GetVolume()==fCurrentVol) return kTRUE;
182 TObjArray *array = node->GetNodes();
183 if (array) {
184 Int_t nDaughters = array->GetEntriesFast();
185 if (j==-1) j++;
186 while (j<nDaughters) {
187 TGeoNode *subNode = (TGeoNode *) array->UncheckedAt(j);
188 fNodeInd[i] = j;
189 if (CheckDaughter(subNode, i+1)) return kTRUE;
190 j++;
191 };
192 fNodeInd[i] = -1;
193 };
194 return kFALSE;
195};
196
197//________________________________________________________________________
198Int_t AliITSv11GeomCable::
199GetCheckPoint( Int_t iCheckPt, Int_t iOccur, Int_t motherLevel,
200 Double_t *coord ) {
201// Get the coordinate of the check point number #iCheckPt, which is in the
202// #iOccur occurrence of the containing volume in the node tree. Coordinates
203// are given in the coordinate system of the #motherLevel mother level of
204// this volume
205
206 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
207
208 TGeoNode *mainNode;
209 if (fInitialNode==0) {
210 TObjArray *nodes = gGeoManager->GetListOfNodes();
211 if (nodes->GetEntriesFast()==0) return kFALSE;
212 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
213 } else {
214 mainNode = fInitialNode;
215 };
216
217 fCurrentVol = GetVolume(iCheckPt);
218 ResetCheckDaughter();
219 Int_t currentOccur = 0;
220
221 // loop to get the volume position in the tree of nodes
222 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
223 currentOccur++;
224 Int_t maxLevel = 0;
225 while (fNodeInd[maxLevel]!=-1) maxLevel++;
226 fNodeInd[maxLevel-1]++;
227 };
228
229 Int_t maxLevel = 0;
230 while (fNodeInd[maxLevel]!=-1) maxLevel++;
231 maxLevel--;
232 if (maxLevel<-1) return kFALSE;
233
234 TGeoNode *pathNode[fgkCableMaxNodeLevel];
235 pathNode[0] = mainNode;
236 for (Int_t i=0; i<=maxLevel; i++) {
237 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
238 };
239
240 Double_t localCoord[3];
241 GetPoint(iCheckPt, localCoord);
242 CopyFrom(coord, localCoord);
243
244 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
245
246 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
247 pathNode[i+1]->GetMatrix()->LocalToMaster(localCoord, coord);
248 CopyFrom(localCoord, coord);
249 };
250 return kTRUE;
251};
252
253//________________________________________________________________________
254Int_t AliITSv11GeomCable::GetCheckVect( Int_t iCheckPt, Int_t iOccur,
255 Int_t motherLevel, Double_t *coord)
256{
257// same as GetCheckPoint but with vectorial transformation ...
258
259 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
260
261 TGeoNode *mainNode;
262 if (fInitialNode==0) {
263 TObjArray *nodes = gGeoManager->GetListOfNodes();
264 if (nodes->GetEntriesFast()==0) return kFALSE;
265 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
266 } else {
267 mainNode = fInitialNode;
268 };
269
270 fCurrentVol = GetVolume(iCheckPt);
271 ResetCheckDaughter();
272 Int_t currentOccur = 0;
273
274 // loop to get the volume position in the tree of nodes
275 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
276 currentOccur++;
277 Int_t maxLevel = 0;
278 while (fNodeInd[maxLevel]!=-1) maxLevel++;
279 fNodeInd[maxLevel-1]++;
280 };
281
282 Int_t maxLevel = 0;
283 while (fNodeInd[maxLevel]!=-1) maxLevel++;
284 maxLevel--;
285 if (maxLevel<-1) return kFALSE;
286
287 TGeoNode *pathNode[fgkCableMaxNodeLevel];
288 pathNode[0] = mainNode;
289 for (Int_t i=0; i<=maxLevel; i++) {
290 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
291 };
292
293 Double_t localCoord[3];
294 GetVect(iCheckPt, localCoord);
295 CopyFrom(coord, localCoord);
296
297 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
298
299 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
300 pathNode[i+1]->GetMatrix()->LocalToMasterVect(localCoord, coord);
301 CopyFrom(localCoord, coord);
302 };
303 return kTRUE;
304};
305
306
307//________________________________________________________________________
308Int_t AliITSv11GeomCable::GetCheckVect( const Double_t *localCoord,
309 TGeoVolume *vol, Int_t iOccur,
310 Int_t motherLevel, Double_t *coord)
311{
312 //
313 // Get the global vect (in coord) correponding to the local vector (localCoord)
314 // of the volume vol. Global at the level of #motherLevel level in the node tree
315 //
316
317 TGeoNode *mainNode;
318 if (fInitialNode==0) {
319 TObjArray *nodes = gGeoManager->GetListOfNodes();
320 if (nodes->GetEntriesFast()==0) return kFALSE;
321 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
322 } else {
323 mainNode = fInitialNode; };
324
325 fCurrentVol = vol;
326 Int_t currentOccur = 0;
327
328 // loop to get the volume position in the tree of nodes
329 ResetCheckDaughter();
330 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
331 currentOccur++;
332 Int_t maxLevel = 0;
333 while (fNodeInd[maxLevel]!=-1) maxLevel++;
334 fNodeInd[maxLevel-1]++;
335 };
336
337 Int_t maxLevel = 0;
338 while (fNodeInd[maxLevel]!=-1) maxLevel++;
339 maxLevel--;
340 if (maxLevel<-1) return kFALSE;
341
342 TGeoNode *pathNode[fgkCableMaxNodeLevel];
343 pathNode[0] = mainNode;
344 for (Int_t i=0; i<=maxLevel; i++) {
345 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
346 };
347
348 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
349
350 Double_t tempCoord[3] = {localCoord[0], localCoord[1], localCoord[2]};
351 CopyFrom(coord, tempCoord);
352 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
353 pathNode[i+1]->GetMatrix()->LocalToMasterVect(tempCoord, coord);
354 CopyFrom(tempCoord, coord);
355 };
356 return kTRUE;
357};
358