New geometry: SDD, cables and update on V11 (L. Gaudichet)
[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);
117 CopyFrom(coord, coordVector->GetMatrixArray());
118 return kTRUE;
119};
120
121//________________________________________________________________________
122Int_t AliITSv11GeomCable::GetVect( Int_t iCheckPt, Double_t *coord)
123const {
124 //
125 // Get the orientation vect. related to check point #iCheckPt
126 //
127
128 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
129 CopyFrom(coord, coordVector->GetMatrixArray());
130 return kTRUE;
131};
132
133//________________________________________________________________________
134TGeoVolume *AliITSv11GeomCable::GetVolume( Int_t iCheckPt ) const {
135 //
136 // Get the volume of check point #iCheckPt
137 //
138
139 if (iCheckPt >= fVolumeArray.GetEntriesFast())
140 return 0;
141 else
142 return (TGeoVolume *) fVolumeArray.UncheckedAt(iCheckPt);
143};
144
145//________________________________________________________________________
146void AliITSv11GeomCable::SetInitialNode(TGeoVolume *vol) {
147 //
148 // Set the starting node, initializing the search for the volume
149 // containing the cable check point
150 //
151 if (fInitialNode) delete fInitialNode;
152 fInitialNode = new TGeoNodeMatrix(vol,0);
153 fInitialNode->SetName("nodeInConstruction");
154};
155
156//________________________________________________________________________
157void AliITSv11GeomCable::ResetInitialNode() {
158 // Reset the initial node if it is set.
159 if (fInitialNode) delete fInitialNode;
160 fInitialNode = 0;
161};
162
163//________________________________________________________________________
164bool AliITSv11GeomCable::CheckDaughter(TGeoNode* node, Int_t i)
165{
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 !!!
171
172 Int_t j = fNodeInd[i];
173 if (node->GetVolume()==fCurrentVol) return kTRUE;
174 TObjArray *array = node->GetNodes();
175 if (array) {
176 Int_t nDaughters = array->GetEntriesFast();
177 if (j==-1) j++;
178 while (j<nDaughters) {
179 TGeoNode *subNode = (TGeoNode *) array->UncheckedAt(j);
180 fNodeInd[i] = j;
181 if (CheckDaughter(subNode, i+1)) return kTRUE;
182 j++;
183 };
184 fNodeInd[i] = -1;
185 };
186 return kFALSE;
187};
188
189//________________________________________________________________________
190Int_t AliITSv11GeomCable::
191GetCheckPoint( Int_t iCheckPt, Int_t iOccur, Int_t motherLevel,
192 Double_t *coord ) {
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
196// this volume
197
198 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
199
200 TGeoNode *mainNode;
201 if (fInitialNode==0) {
202 TObjArray *nodes = gGeoManager->GetListOfNodes();
203 if (nodes->GetEntriesFast()==0) return kFALSE;
204 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
205 } else {
206 mainNode = fInitialNode;
207 };
208
209 fCurrentVol = GetVolume(iCheckPt);
210 ResetCheckDaughter();
211 Int_t currentOccur = 0;
212
213 // loop to get the volume position in the tree of nodes
214 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
215 currentOccur++;
216 Int_t maxLevel = 0;
217 while (fNodeInd[maxLevel]!=-1) maxLevel++;
218 fNodeInd[maxLevel-1]++;
219 };
220
221 Int_t maxLevel = 0;
222 while (fNodeInd[maxLevel]!=-1) maxLevel++;
223 maxLevel--;
224 if (maxLevel<-1) return kFALSE;
225
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]);
230 };
231
232 Double_t localCoord[3];
233 GetPoint(iCheckPt, localCoord);
234 CopyFrom(coord, localCoord);
235
236 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
237
238 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
239 pathNode[i+1]->GetMatrix()->LocalToMaster(localCoord, coord);
240 CopyFrom(localCoord, coord);
241 };
242 return kTRUE;
243};
244
245//________________________________________________________________________
246Int_t AliITSv11GeomCable::GetCheckVect( Int_t iCheckPt, Int_t iOccur,
247 Int_t motherLevel, Double_t *coord)
248{
249// same as GetCheckPoint but with vectorial transformation ...
250
251 if (iCheckPt >= fVolumeArray.GetEntriesFast()) return kFALSE;
252
253 TGeoNode *mainNode;
254 if (fInitialNode==0) {
255 TObjArray *nodes = gGeoManager->GetListOfNodes();
256 if (nodes->GetEntriesFast()==0) return kFALSE;
257 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
258 } else {
259 mainNode = fInitialNode;
260 };
261
262 fCurrentVol = GetVolume(iCheckPt);
263 ResetCheckDaughter();
264 Int_t currentOccur = 0;
265
266 // loop to get the volume position in the tree of nodes
267 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
268 currentOccur++;
269 Int_t maxLevel = 0;
270 while (fNodeInd[maxLevel]!=-1) maxLevel++;
271 fNodeInd[maxLevel-1]++;
272 };
273
274 Int_t maxLevel = 0;
275 while (fNodeInd[maxLevel]!=-1) maxLevel++;
276 maxLevel--;
277 if (maxLevel<-1) return kFALSE;
278
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]);
283 };
284
285 Double_t localCoord[3];
286 GetVect(iCheckPt, localCoord);
287 CopyFrom(coord, localCoord);
288
289 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
290
291 for (Int_t i=maxLevel; i>maxLevel-motherLevel; i--) {
292 pathNode[i+1]->GetMatrix()->LocalToMasterVect(localCoord, coord);
293 CopyFrom(localCoord, coord);
294 };
295 return kTRUE;
296};
297
298
299//________________________________________________________________________
300Int_t AliITSv11GeomCable::GetCheckVect( const Double_t *localCoord,
301 TGeoVolume *vol, Int_t iOccur,
302 Int_t motherLevel, Double_t *coord)
303{
304 //
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
307 //
308
309 TGeoNode *mainNode;
310 if (fInitialNode==0) {
311 TObjArray *nodes = gGeoManager->GetListOfNodes();
312 if (nodes->GetEntriesFast()==0) return kFALSE;
313 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
314 } else {
315 mainNode = fInitialNode; };
316
317 fCurrentVol = vol;
318 Int_t currentOccur = 0;
319
320 // loop to get the volume position in the tree of nodes
321 ResetCheckDaughter();
322 while ( CheckDaughter(mainNode) && (currentOccur!=iOccur) ) {
323 currentOccur++;
324 Int_t maxLevel = 0;
325 while (fNodeInd[maxLevel]!=-1) maxLevel++;
326 fNodeInd[maxLevel-1]++;
327 };
328
329 Int_t maxLevel = 0;
330 while (fNodeInd[maxLevel]!=-1) maxLevel++;
331 maxLevel--;
332 if (maxLevel<-1) return kFALSE;
333
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]);
338 };
339
340 if (motherLevel>maxLevel+2) motherLevel = maxLevel+2;
341
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);
347 };
348 return kTRUE;
349};
350