]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSv11GeomCable.cxx
Removing extra semicolon
[u/mrichter/AliRoot.git] / ITS / AliITSv11GeomCable.cxx
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
39 ClassImp(AliITSv11GeomCable)
40
41
42 //________________________________________________________________________
43 AliITSv11GeomCable::AliITSv11GeomCable(): TNamed(),
44   fDebug(0),
45   fPointArray(),
46   fVolumeArray(),
47   fCurrentVol(0),
48   fInitialNode(0)
49
50   // constructor
51   fPointArray.SetOwner();
52 }
53
54 //________________________________________________________________________
55 AliITSv11GeomCable::AliITSv11GeomCable(const char* name): TNamed(name,""),
56   fDebug(0),
57   fPointArray(),
58   fVolumeArray(),
59   fCurrentVol(0),
60   fInitialNode(0) { 
61   // constructor
62   fPointArray.SetOwner(); 
63 }
64
65
66 //________________________________________________________________________
67 AliITSv11GeomCable::AliITSv11GeomCable(const AliITSv11GeomCable &s) :
68   TNamed(s.GetName(),s.GetTitle()),fDebug(s.fDebug),fPointArray(s.fPointArray),
69   fVolumeArray(s.fVolumeArray),fCurrentVol(s.fCurrentVol),fInitialNode(s.fInitialNode)
70 {
71   //     Copy Constructor 
72   printf("Copy Constructor of AliITSv11GeomCable ???\n");  
73 }
74
75 //________________________________________________________________________
76 AliITSv11GeomCable& AliITSv11GeomCable::operator=(const AliITSv11GeomCable &s) {
77   //     Assignment operator
78   // Not fully inplemented yet !!!
79   printf("Assignment operator of AliITSv11GeomCable not fully inplemented yet !!!\n");  
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 //________________________________________________________________________
92 AliITSv11GeomCable::~AliITSv11GeomCable() {
93   fPointArray.Clear();
94   fVolumeArray.Clear();
95 }
96
97 //________________________________________________________________________
98 void 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   };
115 }
116
117 //________________________________________________________________________
118 void AliITSv11GeomCable::ResetPoints() {
119   //
120   // Remove all points to the cable
121   //
122   fPointArray.Delete();
123   fVolumeArray.Clear();
124 }
125
126
127 //________________________________________________________________________
128 Int_t AliITSv11GeomCable::GetPoint( Int_t iCheckPt,  Double_t *coord)
129 const {
130   //
131   // Get the check point #iCheckPt
132   //
133   TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
134 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
135   CopyFrom(coord, coordVector->GetElements());
136 #else
137   CopyFrom(coord, coordVector->GetMatrixArray());
138 #endif
139   return kTRUE;
140 }
141
142 //________________________________________________________________________
143 Int_t AliITSv11GeomCable::GetVect( Int_t iCheckPt,  Double_t *coord)
144 const {
145   //
146   //  Get the orientation vect. related to check point #iCheckPt
147   //
148
149   TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(iCheckPt);
150 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
151   CopyFrom(coord, coordVector->GetElements());
152 #else
153   CopyFrom(coord, coordVector->GetMatrixArray());
154 #endif
155   return kTRUE;
156 }
157
158 //________________________________________________________________________
159 TGeoVolume *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);
168 }
169
170 //________________________________________________________________________
171 void 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");
179 }
180
181 //________________________________________________________________________
182 void AliITSv11GeomCable::ResetInitialNode() {
183   // Reset the initial node if it is set.
184   if (fInitialNode) delete fInitialNode;
185   fInitialNode = 0;
186 }
187
188 //________________________________________________________________________
189 bool 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;
212 }
213
214 //________________________________________________________________________
215 Int_t AliITSv11GeomCable::
216 GetCheckPoint( 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;
268 }
269
270 //________________________________________________________________________
271 Int_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;
321 }
322
323
324 //________________________________________________________________________
325 Int_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;
374 }
375