]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSv11GeomCable.cxx
geometry accessed via AliITSgeomTGeo
[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
33ddec7d 41
42//________________________________________________________________________
43AliITSv11GeomCable::AliITSv11GeomCable(): TNamed(),
44 fDebug(0),
45 fPointArray(),
46 fVolumeArray(),
47 fCurrentVol(0),
48 fInitialNode(0)
49{
50 // constructor
51 fPointArray.SetOwner();
09e448ac 52}
33ddec7d 53
b7943f00 54//________________________________________________________________________
33ddec7d 55AliITSv11GeomCable::AliITSv11GeomCable(const char* name): TNamed(name,""),
56 fDebug(0),
57 fPointArray(),
58 fVolumeArray(),
59 fCurrentVol(0),
60 fInitialNode(0) {
b7943f00 61 // constructor
b7943f00 62 fPointArray.SetOwner();
5d7a6c6d 63}
b7943f00 64
65
66//________________________________________________________________________
67AliITSv11GeomCable::AliITSv11GeomCable(const AliITSv11GeomCable &s) :
68 TNamed(s.GetName(),s.GetTitle()),fDebug(s.fDebug),fPointArray(s.fPointArray),
33ddec7d 69 fVolumeArray(s.fVolumeArray),fCurrentVol(s.fCurrentVol),fInitialNode(s.fInitialNode)
b7943f00 70{
71 // Copy Constructor
fa4639a3 72 printf("Copy Constructor of AliITSv11GeomCable ???\n");
b7943f00 73}
74
75//________________________________________________________________________
76AliITSv11GeomCable& AliITSv11GeomCable::operator=(const AliITSv11GeomCable &s) {
77 // Assignment operator
78 // Not fully inplemented yet !!!
fa4639a3 79 printf("Assignment operator of AliITSv11GeomCable not fully inplemented yet !!!\n");
b7943f00 80
81 if(&s == this) return *this;
82 SetName(s.GetName());
83 SetTitle(s.GetTitle());
84 fDebug = s.fDebug;
85// fPointArray = s.fPointArray;
86// fVolumeArray = s.fVolumeArray;
87 fInitialNode = s.fInitialNode;
88 return *this;
89}
90
91//________________________________________________________________________
92AliITSv11GeomCable::~AliITSv11GeomCable() {
93 fPointArray.Clear();
94 fVolumeArray.Clear();
5d7a6c6d 95}
b7943f00 96
97//________________________________________________________________________
98void AliITSv11GeomCable::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt,
99 Double_t *coord)
100{
101 //
102 // Add a check point and its volume container to the cable
103 //
104
105 if (iCheckPt>=fVolumeArray.GetEntriesFast()) {
106 fVolumeArray.AddLast(vol);
107 TVectorD *point = new TVectorD(3,coord);
108 fPointArray.AddLast(point);
109
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);
114 };
5d7a6c6d 115}
b7943f00 116
117//________________________________________________________________________
118void AliITSv11GeomCable::ResetPoints() {
119 //
120 // Remove all points to the cable
121 //
122 fPointArray.Delete();
123 fVolumeArray.Clear();
5d7a6c6d 124}
b7943f00 125
126
127//________________________________________________________________________
128Int_t AliITSv11GeomCable::GetPoint( Int_t iCheckPt, Double_t *coord)
129const {
130 //
131 // Get the check point #iCheckPt
132 //
133 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
5d7a6c6d 134#if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
135 CopyFrom(coord, coordVector->GetElements());
136#else
b7943f00 137 CopyFrom(coord, coordVector->GetMatrixArray());
5d7a6c6d 138#endif
b7943f00 139 return kTRUE;
5d7a6c6d 140}
b7943f00 141
142//________________________________________________________________________
143Int_t AliITSv11GeomCable::GetVect( Int_t iCheckPt, Double_t *coord)
144const {
145 //
146 // Get the orientation vect. related to check point #iCheckPt
147 //
148
149 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
5d7a6c6d 150#if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
151 CopyFrom(coord, coordVector->GetElements());
152#else
b7943f00 153 CopyFrom(coord, coordVector->GetMatrixArray());
5d7a6c6d 154#endif
b7943f00 155 return kTRUE;
5d7a6c6d 156}
b7943f00 157
158//________________________________________________________________________
159TGeoVolume *AliITSv11GeomCable::GetVolume( Int_t iCheckPt ) const {
160 //
161 // Get the volume of check point #iCheckPt
162 //
163
164 if (iCheckPt >= fVolumeArray.GetEntriesFast())
165 return 0;
166 else
167 return (TGeoVolume *) fVolumeArray.UncheckedAt(iCheckPt);
5d7a6c6d 168}
b7943f00 169
170//________________________________________________________________________
171void AliITSv11GeomCable::SetInitialNode(TGeoVolume *vol) {
172 //
173 // Set the starting node, initializing the search for the volume
174 // containing the cable check point
175 //
176 if (fInitialNode) delete fInitialNode;
177 fInitialNode = new TGeoNodeMatrix(vol,0);
178 fInitialNode->SetName("nodeInConstruction");
5d7a6c6d 179}
b7943f00 180
181//________________________________________________________________________
182void AliITSv11GeomCable::ResetInitialNode() {
183 // Reset the initial node if it is set.
184 if (fInitialNode) delete fInitialNode;
185 fInitialNode = 0;
5d7a6c6d 186}
b7943f00 187
188//________________________________________________________________________
189bool AliITSv11GeomCable::CheckDaughter(TGeoNode* node, Int_t i)
190{
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 !!!
196
197 Int_t j = fNodeInd[i];
198 if (node->GetVolume()==fCurrentVol) return kTRUE;
199 TObjArray *array = node->GetNodes();
200 if (array) {
201 Int_t nDaughters = array->GetEntriesFast();
202 if (j==-1) j++;
203 while (j<nDaughters) {
204 TGeoNode *subNode = (TGeoNode *) array->UncheckedAt(j);
205 fNodeInd[i] = j;
206 if (CheckDaughter(subNode, i+1)) return kTRUE;
207 j++;
208 };
209 fNodeInd[i] = -1;
210 };
211 return kFALSE;
5d7a6c6d 212}
b7943f00 213
214//________________________________________________________________________
215Int_t AliITSv11GeomCable::
216GetCheckPoint( Int_t iCheckPt, Int_t iOccur, Int_t motherLevel,
217 Double_t *coord ) {
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
221// this volume
222
223 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
224
225 TGeoNode *mainNode;
226 if (fInitialNode==0) {
227 TObjArray *nodes = gGeoManager->GetListOfNodes();
228 if (nodes->GetEntriesFast()==0) return kFALSE;
229 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
230 } else {
231 mainNode = fInitialNode;
232 };
233
234 fCurrentVol = GetVolume(iCheckPt);
235 ResetCheckDaughter();
236 Int_t currentOccur = 0;
237
238 // loop to get the volume position in the tree of nodes
239 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
240 currentOccur++;
241 Int_t maxLevel = 0;
242 while (fNodeInd[maxLevel]!=-1) maxLevel++;
243 fNodeInd[maxLevel-1]++;
244 };
245
246 Int_t maxLevel = 0;
247 while (fNodeInd[maxLevel]!=-1) maxLevel++;
248 maxLevel--;
249 if (maxLevel<-1) return kFALSE;
250
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]);
255 };
256
257 Double_t localCoord[3];
258 GetPoint(iCheckPt, localCoord);
259 CopyFrom(coord, localCoord);
260
261 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
262
263 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
264 pathNode[i+1]->GetMatrix()->LocalToMaster(localCoord, coord);
265 CopyFrom(localCoord, coord);
266 };
267 return kTRUE;
5d7a6c6d 268}
b7943f00 269
270//________________________________________________________________________
271Int_t AliITSv11GeomCable::GetCheckVect( Int_t iCheckPt, Int_t iOccur,
272 Int_t motherLevel, Double_t *coord)
273{
274// same as GetCheckPoint but with vectorial transformation ...
275
276 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
277
278 TGeoNode *mainNode;
279 if (fInitialNode==0) {
280 TObjArray *nodes = gGeoManager->GetListOfNodes();
281 if (nodes->GetEntriesFast()==0) return kFALSE;
282 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
283 } else {
284 mainNode = fInitialNode;
285 };
286
287 fCurrentVol = GetVolume(iCheckPt);
288 ResetCheckDaughter();
289 Int_t currentOccur = 0;
290
291 // loop to get the volume position in the tree of nodes
292 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
293 currentOccur++;
294 Int_t maxLevel = 0;
295 while (fNodeInd[maxLevel]!=-1) maxLevel++;
296 fNodeInd[maxLevel-1]++;
297 };
298
299 Int_t maxLevel = 0;
300 while (fNodeInd[maxLevel]!=-1) maxLevel++;
301 maxLevel--;
302 if (maxLevel<-1) return kFALSE;
303
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]);
308 };
309
310 Double_t localCoord[3];
311 GetVect(iCheckPt, localCoord);
312 CopyFrom(coord, localCoord);
313
314 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
315
316 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
317 pathNode[i+1]->GetMatrix()->LocalToMasterVect(localCoord, coord);
318 CopyFrom(localCoord, coord);
319 };
320 return kTRUE;
5d7a6c6d 321}
b7943f00 322
323
324//________________________________________________________________________
325Int_t AliITSv11GeomCable::GetCheckVect( const Double_t *localCoord,
326 TGeoVolume *vol, Int_t iOccur,
327 Int_t motherLevel, Double_t *coord)
328{
329 //
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
332 //
333
334 TGeoNode *mainNode;
335 if (fInitialNode==0) {
336 TObjArray *nodes = gGeoManager->GetListOfNodes();
337 if (nodes->GetEntriesFast()==0) return kFALSE;
338 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
339 } else {
340 mainNode = fInitialNode; };
341
342 fCurrentVol = vol;
343 Int_t currentOccur = 0;
344
345 // loop to get the volume position in the tree of nodes
346 ResetCheckDaughter();
347 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
348 currentOccur++;
349 Int_t maxLevel = 0;
350 while (fNodeInd[maxLevel]!=-1) maxLevel++;
351 fNodeInd[maxLevel-1]++;
352 };
353
354 Int_t maxLevel = 0;
355 while (fNodeInd[maxLevel]!=-1) maxLevel++;
356 maxLevel--;
357 if (maxLevel<-1) return kFALSE;
358
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]);
363 };
364
365 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
366
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);
372 };
373 return kTRUE;
5d7a6c6d 374}
b7943f00 375