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