Obsolete versions of install scripts removed.
[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
fa4639a3 57 printf("Copy Constructor of AliITSv11GeomCable ???\n");
b7943f00 58}
59
60//________________________________________________________________________
61AliITSv11GeomCable& AliITSv11GeomCable::operator=(const AliITSv11GeomCable &s) {
62 // Assignment operator
63 // Not fully inplemented yet !!!
fa4639a3 64 printf("Assignment operator of AliITSv11GeomCable not fully inplemented yet !!!\n");
b7943f00 65
66 if(&s == this) return *this;
67 SetName(s.GetName());
68 SetTitle(s.GetTitle());
69 fDebug = s.fDebug;
70// fPointArray = s.fPointArray;
71// fVolumeArray = s.fVolumeArray;
72 fInitialNode = s.fInitialNode;
73 return *this;
74}
75
76//________________________________________________________________________
77AliITSv11GeomCable::~AliITSv11GeomCable() {
78 fPointArray.Clear();
79 fVolumeArray.Clear();
80};
81
82//________________________________________________________________________
83void AliITSv11GeomCable::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt,
84 Double_t *coord)
85{
86 //
87 // Add a check point and its volume container to the cable
88 //
89
90 if (iCheckPt>=fVolumeArray.GetEntriesFast()) {
91 fVolumeArray.AddLast(vol);
92 TVectorD *point = new TVectorD(3,coord);
93 fPointArray.AddLast(point);
94
95 } else if ((iCheckPt >= 0)&&(iCheckPt < fVolumeArray.GetEntriesFast())) {
96 fVolumeArray.AddAt(vol, iCheckPt);
97 TVectorD *point = new TVectorD(3,coord);
98 fPointArray.AddAt(point, iCheckPt);
99 };
100};
101
102//________________________________________________________________________
103void AliITSv11GeomCable::ResetPoints() {
104 //
105 // Remove all points to the cable
106 //
107 fPointArray.Delete();
108 fVolumeArray.Clear();
109};
110
111
112//________________________________________________________________________
113Int_t AliITSv11GeomCable::GetPoint( Int_t iCheckPt, Double_t *coord)
114const {
115 //
116 // Get the check point #iCheckPt
117 //
118 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
119 CopyFrom(coord, coordVector->GetMatrixArray());
120 return kTRUE;
121};
122
123//________________________________________________________________________
124Int_t AliITSv11GeomCable::GetVect( Int_t iCheckPt, Double_t *coord)
125const {
126 //
127 // Get the orientation vect. related to check point #iCheckPt
128 //
129
130 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
131 CopyFrom(coord, coordVector->GetMatrixArray());
132 return kTRUE;
133};
134
135//________________________________________________________________________
136TGeoVolume *AliITSv11GeomCable::GetVolume( Int_t iCheckPt ) const {
137 //
138 // Get the volume of check point #iCheckPt
139 //
140
141 if (iCheckPt >= fVolumeArray.GetEntriesFast())
142 return 0;
143 else
144 return (TGeoVolume *) fVolumeArray.UncheckedAt(iCheckPt);
145};
146
147//________________________________________________________________________
148void AliITSv11GeomCable::SetInitialNode(TGeoVolume *vol) {
149 //
150 // Set the starting node, initializing the search for the volume
151 // containing the cable check point
152 //
153 if (fInitialNode) delete fInitialNode;
154 fInitialNode = new TGeoNodeMatrix(vol,0);
155 fInitialNode->SetName("nodeInConstruction");
156};
157
158//________________________________________________________________________
159void AliITSv11GeomCable::ResetInitialNode() {
160 // Reset the initial node if it is set.
161 if (fInitialNode) delete fInitialNode;
162 fInitialNode = 0;
163};
164
165//________________________________________________________________________
166bool AliITSv11GeomCable::CheckDaughter(TGeoNode* node, Int_t i)
167{
168// Search where is the current volume in the tree of nodes
169// stop each time it find the pointer of the current volume
170// the path is recorded in fNodeInd[]
171// node is the node where the search start.
172// !!! recursive function !!!
173
174 Int_t j = fNodeInd[i];
175 if (node->GetVolume()==fCurrentVol) return kTRUE;
176 TObjArray *array = node->GetNodes();
177 if (array) {
178 Int_t nDaughters = array->GetEntriesFast();
179 if (j==-1) j++;
180 while (j<nDaughters) {
181 TGeoNode *subNode = (TGeoNode *) array->UncheckedAt(j);
182 fNodeInd[i] = j;
183 if (CheckDaughter(subNode, i+1)) return kTRUE;
184 j++;
185 };
186 fNodeInd[i] = -1;
187 };
188 return kFALSE;
189};
190
191//________________________________________________________________________
192Int_t AliITSv11GeomCable::
193GetCheckPoint( Int_t iCheckPt, Int_t iOccur, Int_t motherLevel,
194 Double_t *coord ) {
195// Get the coordinate of the check point number #iCheckPt, which is in the
196// #iOccur occurrence of the containing volume in the node tree. Coordinates
197// are given in the coordinate system of the #motherLevel mother level of
198// this volume
199
200 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
201
202 TGeoNode *mainNode;
203 if (fInitialNode==0) {
204 TObjArray *nodes = gGeoManager->GetListOfNodes();
205 if (nodes->GetEntriesFast()==0) return kFALSE;
206 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
207 } else {
208 mainNode = fInitialNode;
209 };
210
211 fCurrentVol = GetVolume(iCheckPt);
212 ResetCheckDaughter();
213 Int_t currentOccur = 0;
214
215 // loop to get the volume position in the tree of nodes
216 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
217 currentOccur++;
218 Int_t maxLevel = 0;
219 while (fNodeInd[maxLevel]!=-1) maxLevel++;
220 fNodeInd[maxLevel-1]++;
221 };
222
223 Int_t maxLevel = 0;
224 while (fNodeInd[maxLevel]!=-1) maxLevel++;
225 maxLevel--;
226 if (maxLevel<-1) return kFALSE;
227
228 TGeoNode *pathNode[fgkCableMaxNodeLevel];
229 pathNode[0] = mainNode;
230 for (Int_t i=0; i<=maxLevel; i++) {
231 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
232 };
233
234 Double_t localCoord[3];
235 GetPoint(iCheckPt, localCoord);
236 CopyFrom(coord, localCoord);
237
238 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
239
240 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
241 pathNode[i+1]->GetMatrix()->LocalToMaster(localCoord, coord);
242 CopyFrom(localCoord, coord);
243 };
244 return kTRUE;
245};
246
247//________________________________________________________________________
248Int_t AliITSv11GeomCable::GetCheckVect( Int_t iCheckPt, Int_t iOccur,
249 Int_t motherLevel, Double_t *coord)
250{
251// same as GetCheckPoint but with vectorial transformation ...
252
253 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
254
255 TGeoNode *mainNode;
256 if (fInitialNode==0) {
257 TObjArray *nodes = gGeoManager->GetListOfNodes();
258 if (nodes->GetEntriesFast()==0) return kFALSE;
259 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
260 } else {
261 mainNode = fInitialNode;
262 };
263
264 fCurrentVol = GetVolume(iCheckPt);
265 ResetCheckDaughter();
266 Int_t currentOccur = 0;
267
268 // loop to get the volume position in the tree of nodes
269 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
270 currentOccur++;
271 Int_t maxLevel = 0;
272 while (fNodeInd[maxLevel]!=-1) maxLevel++;
273 fNodeInd[maxLevel-1]++;
274 };
275
276 Int_t maxLevel = 0;
277 while (fNodeInd[maxLevel]!=-1) maxLevel++;
278 maxLevel--;
279 if (maxLevel<-1) return kFALSE;
280
281 TGeoNode *pathNode[fgkCableMaxNodeLevel];
282 pathNode[0] = mainNode;
283 for (Int_t i=0; i<=maxLevel; i++) {
284 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
285 };
286
287 Double_t localCoord[3];
288 GetVect(iCheckPt, localCoord);
289 CopyFrom(coord, localCoord);
290
291 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
292
293 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
294 pathNode[i+1]->GetMatrix()->LocalToMasterVect(localCoord, coord);
295 CopyFrom(localCoord, coord);
296 };
297 return kTRUE;
298};
299
300
301//________________________________________________________________________
302Int_t AliITSv11GeomCable::GetCheckVect( const Double_t *localCoord,
303 TGeoVolume *vol, Int_t iOccur,
304 Int_t motherLevel, Double_t *coord)
305{
306 //
307 // Get the global vect (in coord) correponding to the local vector (localCoord)
308 // of the volume vol. Global at the level of #motherLevel level in the node tree
309 //
310
311 TGeoNode *mainNode;
312 if (fInitialNode==0) {
313 TObjArray *nodes = gGeoManager->GetListOfNodes();
314 if (nodes->GetEntriesFast()==0) return kFALSE;
315 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
316 } else {
317 mainNode = fInitialNode; };
318
319 fCurrentVol = vol;
320 Int_t currentOccur = 0;
321
322 // loop to get the volume position in the tree of nodes
323 ResetCheckDaughter();
324 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
325 currentOccur++;
326 Int_t maxLevel = 0;
327 while (fNodeInd[maxLevel]!=-1) maxLevel++;
328 fNodeInd[maxLevel-1]++;
329 };
330
331 Int_t maxLevel = 0;
332 while (fNodeInd[maxLevel]!=-1) maxLevel++;
333 maxLevel--;
334 if (maxLevel<-1) return kFALSE;
335
336 TGeoNode *pathNode[fgkCableMaxNodeLevel];
337 pathNode[0] = mainNode;
338 for (Int_t i=0; i<=maxLevel; i++) {
339 pathNode[i+1] = pathNode[i]->GetDaughter(fNodeInd[i]);
340 };
341
342 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
343
344 Double_t tempCoord[3] = {localCoord[0], localCoord[1], localCoord[2]};
345 CopyFrom(coord, tempCoord);
346 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
347 pathNode[i+1]->GetMatrix()->LocalToMasterVect(tempCoord, coord);
348 CopyFrom(tempCoord, coord);
349 };
350 return kTRUE;
351};
352