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