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