]>
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> | |
25 | #include <TGeoVolume.h> | |
26 | #include <TGeoTube.h> | |
fa4639a3 | 27 | #include <TGeoTorus.h> |
b7943f00 | 28 | #include <TGeoMatrix.h> |
29 | ||
30 | #include "AliITSv11GeomCableRound.h" | |
31 | ||
32 | //************************************************************************* | |
33 | // Class for round cables | |
34 | // | |
35 | // Ludovic Gaudichet gaudichet@to.infn.it | |
36 | //************************************************************************* | |
37 | ||
fa4639a3 | 38 | /* |
39 | // ************************************************************************ | |
40 | // Here is a example on how to use this class | |
41 | // ************************************************************************ | |
42 | ||
43 | // Getting some media | |
531d6cdc | 44 | TGeoMedium *air = gGeoManager->GetMedium("ITS_ITSair"); |
45 | TGeoMedium *water = gGeoManager->GetMedium("ITS_WATER"); | |
46 | TGeoMedium *alu = gGeoManager->GetMedium("ITS_ITSal"); | |
fa4639a3 | 47 | |
48 | // Creating a small box inside a bigger one (containers) | |
49 | TGeoBBox *box1 = new TGeoBBox("box1", 6,10,10); | |
50 | TGeoBBox *bigBox = new TGeoBBox("bigBox", 20,10,10); | |
51 | TGeoVolume *vbox1 = new TGeoVolume("vbox1", box1, air); | |
52 | TGeoVolume *vBigBox = new TGeoVolume("vBigBox", bigBox, air); | |
53 | vbox1->SetVisibility(kFALSE); | |
54 | vBigBox->SetVisibility(kFALSE); | |
55 | ||
56 | TGeoTranslation *tr1 = new TGeoTranslation("negTr",-14,0,0); | |
57 | vBigBox->AddNode(vbox1, 1, tr1); | |
58 | moth->AddNode(vBigBox, 1, 0); | |
59 | ||
60 | // ************************************************** | |
61 | // Inserting a round cable (or here a water pipe...) | |
62 | // ************************************************** | |
63 | ||
64 | Int_t waterColor = 7; | |
65 | Int_t aluColor = 5; | |
66 | AliITSv11GeomCableRound roundCable("waterPipe", 0.9); //radius of 0.9cm | |
67 | roundCable.SetNLayers(2); | |
68 | roundCable.SetLayer(0, 0.7, water, waterColor); // radius of 0.7cm | |
69 | roundCable.SetLayer(1, 0.2, alu, aluColor); // thickness of 0.2cm | |
70 | ||
71 | // ****** Set check points and their containers ****** | |
72 | // The 2 first points are in the small box (vbox1) | |
73 | // The second point is at the boundary | |
74 | ||
75 | Double_t coord0[3] = {0,-2,-2}; | |
76 | Double_t coord1[3] = {6,2,1}; | |
77 | Double_t vect0[3] = {1,1,0}; | |
78 | Double_t vect1[3] = {1,0,0}; | |
79 | // coordinates have to be given in the specified container | |
80 | // reference system (here it's going to be vbox1). | |
81 | // vect1 and vect2 are vectors perpendicular to the segment ends | |
82 | // (These vectors don't need to be normalized) | |
83 | roundCable.AddCheckPoint( vbox1, 0, coord0, vect0); | |
84 | roundCable.AddCheckPoint( vbox1, 1, coord1, vect1); | |
85 | ||
86 | // Then, let's cross the boundary ! You just need | |
87 | // to put the next point in the other volume, vBigBox. | |
88 | // At the moment of creating the second segment, it will | |
89 | // be inserted in this volume. That is why the point 1 had to | |
90 | // be at the boundary, because otherwise the second segment | |
91 | // between de points 1 and 2 would have been inserted in the | |
92 | // vBigBox but in the same time would have cross its | |
93 | // boundary ... | |
94 | Double_t coord2[3] = {-2,6,4}; // coord. syst. of vBigBox ! | |
95 | Double_t vect2[3]= {1,1,0.5}; | |
96 | roundCable.AddCheckPoint( vBigBox, 2, coord2, vect2); | |
97 | ||
98 | Double_t coord3[3] = {4,6,4}; | |
99 | Double_t vect3[3]= {-1,0,0}; | |
100 | roundCable.AddCheckPoint( vBigBox, 3, coord3, vect3); | |
101 | ||
102 | Double_t coord4[3] = {4,0,-4}; | |
103 | Double_t vect4[3]= {1,0,0}; | |
104 | roundCable.AddCheckPoint( vBigBox, 4, coord4, vect4); | |
105 | ||
106 | Double_t coord5[3] = {4,-6,4}; | |
107 | Double_t vect5[3]= {1,0,0}; | |
108 | roundCable.AddCheckPoint( vBigBox, 5, coord5, vect5); | |
109 | ||
110 | Double_t coord6[3] = {7,-6,4}; | |
111 | Double_t vect6[3]= {1,0,0}; | |
112 | roundCable.AddCheckPoint( vBigBox, 6, coord6, vect6); | |
113 | ||
114 | Double_t r = 7; | |
115 | Double_t angle = 70*TMath::DegToRad(); | |
116 | Double_t coord7[3] = {coord6[0] +r*sin(angle), coord6[1], | |
117 | coord6[2] -r*(1-cos(angle)) }; | |
118 | Double_t vect7[3]= {r*cos(angle),0,-r*sin(angle)}; | |
119 | roundCable.AddCheckPoint( vBigBox, 7, coord7, vect7); | |
120 | ||
121 | Double_t coord8[3] = { coord7[0]+vect7[0], coord7[1]+vect7[1],-10}; | |
122 | Double_t vect8[3]= {0,0,1}; | |
123 | roundCable.AddCheckPoint( vBigBox, 8, coord8, vect8); | |
124 | ||
125 | // ****** Creating the corresponding volume ****** | |
126 | // Since the container volumes of the check points have | |
127 | // been recorded, this can be done at any moments, providing | |
128 | // that the container volumes are found in the sub-nodes | |
129 | // of the initial node (the top volume of the TGeoManager or | |
130 | // the volume set in SetInitialNode(TGeoVolume*) function) | |
131 | ||
132 | roundCable.SetInitialNode(vBigBox); //Set the root node | |
133 | roundCable.CreateAndInsertCableSegment( 1); | |
134 | // This command means : create the segment between point 0 | |
135 | // and point 1. The segment is automatically inserted in the | |
136 | // container volume of point 1. | |
137 | ||
138 | roundCable.CreateAndInsertCableSegment( 2); | |
139 | roundCable.CreateAndInsertCableSegment( 3); | |
140 | ||
141 | // The following segment is going to be a torus segment. | |
142 | // The radius and position of the torus is defined by the | |
143 | // orthogonal vector of point 4 (the orientation of this vector | |
144 | // and the position of the 2 check points are enough to define | |
145 | // completely the torus) | |
146 | roundCable.CreateAndInsertTorusSegment( 4, 180); | |
147 | // The second argument is an additionnal rotation of the | |
148 | // segment around the axis defined by the 2 check points. | |
149 | ||
150 | roundCable.CreateAndInsertTorusSegment( 5); | |
151 | roundCable.CreateAndInsertCableSegment( 6); | |
152 | roundCable.CreateAndInsertTorusSegment( 7,180); | |
153 | roundCable.CreateAndInsertCableSegment( 8); | |
154 | ||
155 | */ | |
156 | ||
157 | ||
158 | ||
b7943f00 | 159 | ClassImp(AliITSv11GeomCableRound) |
160 | ||
161 | //________________________________________________________________________ | |
162 | AliITSv11GeomCableRound:: | |
163 | AliITSv11GeomCableRound(const char* name, Double_t radius) : | |
164 | AliITSv11GeomCable(name) { | |
165 | // Constructor | |
166 | fRadius = radius; | |
167 | fNlayer = 0; | |
168 | for (Int_t i=0; i<fgkCableMaxLayer ; i++) { | |
169 | fLayThickness[i] = 0; | |
170 | fLayColor[i] = 0; | |
171 | fLayMedia[i] = 0; | |
172 | }; | |
173 | fPhiMin = 0; | |
174 | fPhiMax = 360; | |
5d7a6c6d | 175 | } |
b7943f00 | 176 | |
177 | //________________________________________________________________________ | |
178 | AliITSv11GeomCableRound::AliITSv11GeomCableRound(const AliITSv11GeomCableRound &s) : | |
179 | AliITSv11GeomCable(s),fRadius(s.fRadius),fNlayer(s.fNlayer),fPhiMin(s.fPhiMin), | |
180 | fPhiMax(s.fPhiMax) | |
181 | { | |
182 | // Copy Constructor | |
183 | for (Int_t i=0; i<s.fNlayer; i++) { | |
184 | fLayThickness[i] = s.fLayThickness[i]; | |
185 | fLayMedia[i] = s.fLayMedia[i]; | |
186 | fLayColor[i] = s.fLayColor[i]; | |
187 | } | |
188 | } | |
189 | ||
190 | //________________________________________________________________________ | |
191 | AliITSv11GeomCableRound& AliITSv11GeomCableRound:: | |
192 | operator=(const AliITSv11GeomCableRound &s) { | |
193 | // Assignment operator | |
194 | // Not fully inplemented yet !!! | |
195 | ||
196 | if(&s == this) return *this; | |
197 | *this = s; | |
198 | fRadius = s.fRadius; | |
199 | fPhiMin = s.fPhiMin; | |
200 | fPhiMax = s.fPhiMax; | |
201 | fNlayer = s.fNlayer; | |
202 | for (Int_t i=0; i<s.fNlayer; i++) { | |
203 | fLayThickness[i] = s.fLayThickness[i]; | |
204 | fLayMedia[i] = s.fLayMedia[i]; | |
205 | fLayColor[i] = s.fLayColor[i]; | |
206 | }; | |
207 | return *this; | |
208 | } | |
209 | ||
210 | //________________________________________________________________________ | |
211 | Int_t AliITSv11GeomCableRound::GetPoint( Int_t iCheckPt, Double_t *coord) | |
212 | const { | |
213 | // Get check point #iCheckPt | |
214 | TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(2*iCheckPt); | |
5d7a6c6d | 215 | #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0) |
216 | CopyFrom(coord, coordVector->GetElements()); | |
217 | #else | |
b7943f00 | 218 | CopyFrom(coord, coordVector->GetMatrixArray()); |
5d7a6c6d | 219 | #endif |
b7943f00 | 220 | return kTRUE; |
5d7a6c6d | 221 | } |
b7943f00 | 222 | |
223 | //________________________________________________________________________ | |
224 | Int_t AliITSv11GeomCableRound::GetVect( Int_t iCheckPt, Double_t *coord) | |
225 | const { | |
226 | // | |
227 | // Get vector transverse to the section at point #iCheckPt | |
228 | // | |
229 | ||
230 | TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(2*iCheckPt+1); | |
5d7a6c6d | 231 | #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0) |
232 | CopyFrom(coord, coordVector->GetElements()); | |
233 | #else | |
b7943f00 | 234 | CopyFrom(coord, coordVector->GetMatrixArray()); |
5d7a6c6d | 235 | #endif |
b7943f00 | 236 | return kTRUE; |
5d7a6c6d | 237 | } |
238 | ||
b7943f00 | 239 | //________________________________________________________________________ |
240 | void AliITSv11GeomCableRound::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt, | |
241 | Double_t *coord, Double_t *orthVect) | |
242 | { | |
243 | // | |
244 | // Add point #iCheckPt and its transverse vector. Point is added at (i) in | |
245 | // fPointArray and the vector is added at (i+1) | |
246 | // | |
247 | ||
248 | ||
249 | if (iCheckPt>=fVolumeArray.GetEntriesFast()) { | |
250 | fVolumeArray.AddLast(vol); | |
251 | TVectorD *point = new TVectorD(3,coord); | |
252 | TVectorD *vect = new TVectorD(3,orthVect); | |
253 | fPointArray.AddLast(point); | |
254 | fPointArray.AddLast(vect); | |
255 | ||
256 | } else if ((iCheckPt >= 0)&&(iCheckPt < fVolumeArray.GetEntriesFast())) { | |
257 | fVolumeArray.AddAt(vol, iCheckPt); | |
258 | TVectorD *point = new TVectorD(3,coord); | |
259 | TVectorD *vect = new TVectorD(3,orthVect); | |
260 | fPointArray.AddAt(point, iCheckPt*2 ); | |
261 | fPointArray.AddAt(vect, iCheckPt*2+1); | |
262 | }; | |
5d7a6c6d | 263 | } |
b7943f00 | 264 | |
265 | //________________________________________________________________________ | |
266 | void AliITSv11GeomCableRound::PrintCheckPoints() const { | |
267 | // Print all check points | |
268 | ||
269 | printf(" ---\n Printing all check points of the round cable\n"); | |
270 | for (Int_t i = 0; i<fVolumeArray.GetEntriesFast(); i++) { | |
271 | TVectorD *coordVector = (TVectorD *)fPointArray.UncheckedAt(i*2); | |
272 | //TVectorD *vectVector = (TVectorD *)fPointArray.UncheckedAt(i*2+1); | |
273 | Double_t coord[3]; | |
5d7a6c6d | 274 | #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0) |
275 | CopyFrom(coord, coordVector->GetElements()); | |
276 | #else | |
b7943f00 | 277 | CopyFrom(coord, coordVector->GetMatrixArray()); |
5d7a6c6d | 278 | #endif |
b7943f00 | 279 | printf(" ( %.2f, %.2f, %.2f )\n", coord[0], coord[1], coord[2]); |
280 | }; | |
5d7a6c6d | 281 | } |
b7943f00 | 282 | |
fa4639a3 | 283 | |
b7943f00 | 284 | //________________________________________________________________________ |
285 | Int_t AliITSv11GeomCableRound::CreateAndInsertCableSegment(Int_t p2) | |
286 | { | |
287 | // Creates a cable segment between points p1 and p2. | |
b7943f00 | 288 | // |
289 | // The segment volume is created inside the volume containing point2 | |
290 | // Therefore this segment should be defined in this volume only. | |
291 | // I mean here that, if the previous point is in another volume, | |
292 | // it should be just at the border between the 2 volumes. Also the | |
293 | // orientation vector of the previous point should be othogonal to | |
294 | // the surface between the 2 volumes. | |
295 | ||
296 | TGeoNode *mainNode; | |
297 | if (fInitialNode==0) { | |
298 | TObjArray *nodes = gGeoManager->GetListOfNodes(); | |
299 | if (nodes->GetEntriesFast()==0) return kFALSE; | |
300 | mainNode = (TGeoNode *) nodes->UncheckedAt(0); | |
301 | } else { | |
302 | mainNode = fInitialNode; | |
303 | }; | |
304 | ||
305 | Int_t p1 = p2 - 1; | |
306 | TGeoVolume *p1Vol = GetVolume(p1); | |
307 | TGeoVolume *p2Vol = GetVolume(p2); | |
308 | ||
309 | ResetCheckDaughter(); | |
310 | fCurrentVol = p1Vol; | |
311 | if (! CheckDaughter(mainNode)) { | |
312 | printf("Error::volume containing point is not visible in node tree!\n"); | |
313 | return kFALSE; | |
314 | }; | |
315 | ||
316 | Double_t coord1[3], coord2[3], vect1[3], vect2[3]; | |
317 | //================================================= | |
318 | // Get p1 position in the systeme of p2 | |
319 | if (p1Vol!=p2Vol) { | |
320 | ||
321 | Int_t p1nodeInd[fgkCableMaxNodeLevel]; | |
322 | for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i]; | |
323 | Int_t p1volLevel = 0; | |
324 | while (p1nodeInd[p1volLevel]!=-1) p1volLevel++; | |
325 | p1volLevel--; | |
326 | ||
327 | ResetCheckDaughter(); | |
328 | fCurrentVol = p2Vol; | |
329 | if (! CheckDaughter(mainNode)) { | |
330 | printf("Error::volume containing point is not visible in node tree!\n"); | |
331 | return kFALSE; | |
332 | }; | |
333 | Int_t p2nodeInd[fgkCableMaxNodeLevel]; | |
334 | for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i]; | |
335 | Int_t commonMotherLevel = 0; | |
336 | while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel]) | |
337 | commonMotherLevel++; | |
338 | commonMotherLevel--; | |
339 | Int_t p2volLevel = 0; | |
340 | while (fNodeInd[p2volLevel]!=-1) p2volLevel++; | |
341 | p2volLevel--; | |
342 | ||
343 | // Get coord and vect of p1 in the common mother reference system | |
344 | GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1); | |
345 | GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1); | |
346 | // Translate them in the reference system of the volume containing p2 | |
347 | TGeoNode *pathNode[fgkCableMaxNodeLevel]; | |
348 | pathNode[0] = mainNode; | |
349 | for (Int_t i=0; i<=p2volLevel; i++) { | |
350 | pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]); | |
351 | }; | |
352 | Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]}; | |
353 | Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]}; | |
354 | ||
355 | for (Int_t i = commonMotherLevel+1; i<=p2volLevel; i++) { | |
356 | pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1); | |
357 | pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1); | |
358 | CopyFrom(globalCoord1, coord1); | |
359 | CopyFrom(globalVect1, vect1); | |
360 | }; | |
361 | } else { | |
362 | GetCheckPoint(p1, 0, 0, coord1); | |
363 | GetCheckVect(p1, 0, 0, vect1); | |
364 | }; | |
365 | ||
366 | //================================================= | |
367 | // Get p2 position in the systeme of p2 | |
368 | GetCheckPoint(p2, 0, 0, coord2); | |
369 | GetCheckVect(p2, 0, 0, vect2); | |
370 | ||
371 | Double_t cx = (coord1[0]+coord2[0])/2; | |
372 | Double_t cy = (coord1[1]+coord2[1])/2; | |
373 | Double_t cz = (coord1[2]+coord2[2])/2; | |
374 | Double_t dx = coord2[0]-coord1[0]; | |
375 | Double_t dy = coord2[1]-coord1[1]; | |
376 | Double_t dz = coord2[2]-coord1[2]; | |
377 | ||
378 | //================================================= | |
379 | // Positionning of the segment between the 2 points | |
380 | if ((dy<1e-31)&&(dy>0)) dy = 1e-31; | |
381 | if ((dz<1e-31)&&(dz>0)) dz = 1e-31; | |
382 | if ((dy>-1e-31)&&(dy<0)) dy = -1e-31; | |
383 | if ((dz>-1e-31)&&(dz<0)) dz = -1e-31; | |
384 | ||
385 | Double_t angleRot1 = -TMath::ATan2(dx,dy); | |
386 | Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx); | |
387 | Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz); | |
388 | TGeoRotation *rot = new TGeoRotation("",angleRot1*TMath::RadToDeg(), | |
389 | angleRotDiag*TMath::RadToDeg(), | |
390 | 0); | |
391 | Double_t localVect1[3], localVect2[3]; | |
392 | rot->MasterToLocalVect(vect1, localVect1); | |
393 | rot->MasterToLocalVect(vect2, localVect2); | |
394 | TGeoTranslation *trans = new TGeoTranslation("",cx, cy, cz); | |
395 | ||
396 | //================================================= | |
397 | // Create the segment and add it to the mother volume | |
398 | TGeoVolume *vCableSeg = CreateSegment(coord1, coord2, | |
399 | localVect1, localVect2); | |
400 | ||
401 | TGeoCombiTrans *combi = new TGeoCombiTrans(*trans, *rot); | |
402 | p2Vol->AddNode(vCableSeg, p2, combi); | |
403 | //================================================= | |
404 | delete rot; | |
405 | delete trans; | |
406 | ||
407 | if (fDebug) { | |
408 | printf("---\n Cable segment points : "); | |
409 | printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]); | |
410 | printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]); | |
411 | }; | |
412 | // #include <TGeoSphere.h> | |
531d6cdc | 413 | // TGeoMedium *airSDD = gGeoManager->GetMedium("ITS_ITSsddAir"); |
b7943f00 | 414 | // TGeoSphere *sphere = new TGeoSphere(0, 0.15); |
415 | // TGeoVolume *vSphere = new TGeoVolume("", sphere, airSDD); | |
416 | // TGeoTranslation *trC = new TGeoTranslation("", cx, cy, cz); | |
417 | // TGeoTranslation *tr1 = new TGeoTranslation("",coord1[0], | |
418 | // coord1[1],coord1[2]); | |
419 | // TGeoTranslation *tr2 = new TGeoTranslation("",coord2[0], | |
420 | // coord2[1],coord2[2]); | |
421 | // p2Vol->AddNode(vSphere, p2*3-2, trC); | |
422 | // p2Vol->AddNode(vSphere, p2*3-1, tr1); | |
423 | // p2Vol->AddNode(vSphere, p2*3 , tr2); | |
424 | ||
425 | return kTRUE; | |
5d7a6c6d | 426 | } |
b7943f00 | 427 | |
fa4639a3 | 428 | |
429 | //________________________________________________________________________ | |
430 | Int_t AliITSv11GeomCableRound::CreateAndInsertTorusSegment(Int_t p2, Double_t rotation) | |
431 | { | |
432 | // Create a torus cable segment between points p1 and p2. | |
433 | // The radius and position of the torus is defined by the | |
434 | // perpendicular vector of point p2 (the orientation of this vector | |
435 | // and the position of the 2 check points are enough to completely | |
436 | // define the torus) | |
437 | ||
438 | TGeoNode *mainNode; | |
439 | if (fInitialNode==0) { | |
440 | TObjArray *nodes = gGeoManager->GetListOfNodes(); | |
441 | if (nodes->GetEntriesFast()==0) return kFALSE; | |
442 | mainNode = (TGeoNode *) nodes->UncheckedAt(0); | |
443 | } else { | |
444 | mainNode = fInitialNode; | |
445 | }; | |
446 | ||
447 | Int_t p1 = p2 - 1; | |
448 | TGeoVolume *p1Vol = GetVolume(p1); | |
449 | TGeoVolume *p2Vol = GetVolume(p2); | |
450 | ||
451 | ResetCheckDaughter(); | |
452 | fCurrentVol = p1Vol; | |
453 | if (! CheckDaughter(mainNode)) { | |
454 | printf("Error::volume containing point is not visible in node tree!\n"); | |
455 | return kFALSE; | |
456 | }; | |
457 | ||
458 | Double_t coord1[3], coord2[3], vect1[3], vect2[3]; | |
459 | //================================================= | |
460 | // Get p1 position in the systeme of p2 | |
461 | if (p1Vol!=p2Vol) { | |
462 | ||
463 | Int_t p1nodeInd[fgkCableMaxNodeLevel]; | |
464 | for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i]; | |
465 | Int_t p1volLevel = 0; | |
466 | while (p1nodeInd[p1volLevel]!=-1) p1volLevel++; | |
467 | p1volLevel--; | |
468 | ||
469 | ResetCheckDaughter(); | |
470 | fCurrentVol = p2Vol; | |
471 | if (! CheckDaughter(mainNode)) { | |
472 | printf("Error::volume containing point is not visible in node tree!\n"); | |
473 | return kFALSE; | |
474 | }; | |
475 | Int_t p2nodeInd[fgkCableMaxNodeLevel]; | |
476 | for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i]; | |
477 | Int_t commonMotherLevel = 0; | |
478 | while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel]) | |
479 | commonMotherLevel++; | |
480 | commonMotherLevel--; | |
481 | Int_t p2volLevel = 0; | |
482 | while (fNodeInd[p2volLevel]!=-1) p2volLevel++; | |
483 | p2volLevel--; | |
484 | ||
485 | // Get coord and vect of p1 in the common mother reference system | |
486 | GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1); | |
487 | GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1); | |
488 | // Translate them in the reference system of the volume containing p2 | |
489 | TGeoNode *pathNode[fgkCableMaxNodeLevel]; | |
490 | pathNode[0] = mainNode; | |
491 | for (Int_t i=0; i<=p2volLevel; i++) { | |
492 | pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]); | |
493 | }; | |
494 | Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]}; | |
495 | Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]}; | |
496 | ||
497 | for (Int_t i = commonMotherLevel+1; i<=p2volLevel; i++) { | |
498 | pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1); | |
499 | pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1); | |
500 | CopyFrom(globalCoord1, coord1); | |
501 | CopyFrom(globalVect1, vect1); | |
502 | }; | |
503 | } else { | |
504 | GetCheckPoint(p1, 0, 0, coord1); | |
505 | GetCheckVect(p1, 0, 0, vect1); | |
506 | }; | |
507 | ||
508 | //================================================= | |
509 | // Get p2 position in the systeme of p2 | |
510 | GetCheckPoint(p2, 0, 0, coord2); | |
511 | GetCheckVect(p2, 0, 0, vect2); | |
512 | ||
513 | Double_t cx = (coord1[0]+coord2[0])/2; | |
514 | Double_t cy = (coord1[1]+coord2[1])/2; | |
515 | Double_t cz = (coord1[2]+coord2[2])/2; | |
516 | Double_t dx = coord2[0]-coord1[0]; | |
517 | Double_t dy = coord2[1]-coord1[1]; | |
518 | Double_t dz = coord2[2]-coord1[2]; | |
519 | Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz); | |
520 | ||
521 | //================================================= | |
522 | // Positionning of the segment between the 2 points | |
523 | if ((dy<1e-31)&&(dy>0)) dy = 1e-31; | |
524 | if ((dz<1e-31)&&(dz>0)) dz = 1e-31; | |
525 | if ((dy>-1e-31)&&(dy<0)) dy = -1e-31; | |
526 | if ((dz>-1e-31)&&(dz<0)) dz = -1e-31; | |
527 | ||
528 | Double_t angleRot1 = -TMath::ATan2(dx,dy); | |
529 | Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx); | |
530 | Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz); | |
531 | ||
532 | TGeoRotation rotTorusTemp("",angleRot1*TMath::RadToDeg(), | |
533 | angleRotDiag*TMath::RadToDeg(),0); | |
534 | TGeoRotation rotTorusToZ("",0,90,0); | |
535 | rotTorusTemp.MultiplyBy(&rotTorusToZ, kTRUE); | |
536 | Double_t localVect2[3]; | |
537 | rotTorusTemp.MasterToLocalVect(vect2, localVect2); | |
538 | if (localVect2[1]<0) { | |
539 | localVect2[0] = -localVect2[0]; | |
540 | localVect2[1] = -localVect2[1]; | |
541 | localVect2[2] = -localVect2[2]; | |
542 | }; | |
543 | Double_t normVect2 = TMath::Sqrt(localVect2[0]*localVect2[0]+ | |
544 | localVect2[1]*localVect2[1]+ | |
545 | localVect2[2]*localVect2[2]); | |
546 | Double_t axisX[3] = {1,0,0}; | |
547 | Double_t cosangleTorusSeg = (localVect2[0]*axisX[0]+ | |
548 | localVect2[1]*axisX[1]+ | |
549 | localVect2[2]*axisX[2])/normVect2; | |
550 | Double_t angleTorusSeg = TMath::ACos(cosangleTorusSeg)*TMath::RadToDeg(); | |
551 | TGeoRotation rotTorus("",angleRot1*TMath::RadToDeg(), | |
552 | angleRotDiag*TMath::RadToDeg(), | |
553 | 180-angleTorusSeg+rotation); | |
554 | rotTorus.MultiplyBy(&rotTorusToZ, kTRUE); | |
555 | rotTorus.MasterToLocalVect(vect2, localVect2); | |
556 | if (localVect2[1]<0) { | |
557 | localVect2[0] = -localVect2[0]; | |
558 | localVect2[1] = -localVect2[1]; | |
559 | localVect2[2] = -localVect2[2]; | |
560 | }; | |
561 | normVect2 = TMath::Sqrt(localVect2[0]*localVect2[0]+ | |
562 | localVect2[1]*localVect2[1]+ | |
563 | localVect2[2]*localVect2[2]); | |
564 | Double_t axisY[3] = {0,1,0}; | |
565 | Double_t cosPhi = (localVect2[0]*axisY[0]+localVect2[1]*axisY[1]+ | |
566 | localVect2[2]*axisY[2])/normVect2; | |
567 | Double_t torusPhi1 = TMath::ACos(cosPhi); | |
568 | Double_t torusR = (length/2)/TMath::Sin(torusPhi1); | |
569 | torusPhi1 = torusPhi1*TMath::RadToDeg(); | |
570 | Double_t perpLength = TMath::Sqrt(torusR*torusR-length*length/4); | |
571 | Double_t localTransT[3] = {-perpLength,0,0}; | |
572 | Double_t globalTransT[3]; | |
573 | rotTorus.LocalToMasterVect(localTransT, globalTransT); | |
574 | TGeoTranslation transTorus("",cx+globalTransT[0],cy+globalTransT[1], | |
575 | cz+globalTransT[2]); | |
576 | ||
577 | TGeoCombiTrans *combiTorus = new TGeoCombiTrans(transTorus, rotTorus); | |
578 | ||
579 | //================================================= | |
580 | // Create the segment and add it to the mother volume | |
581 | TGeoVolume *vCableSegT = CreateTorus(torusPhi1, torusR); | |
582 | p2Vol->AddNode(vCableSegT, p2, combiTorus); | |
583 | ||
584 | if (fDebug) { | |
585 | printf("---\n Cable segment points : "); | |
586 | printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]); | |
587 | printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]); | |
588 | }; | |
589 | ||
590 | return kTRUE; | |
5d7a6c6d | 591 | } |
fa4639a3 | 592 | |
b7943f00 | 593 | //________________________________________________________________________ |
594 | TGeoVolume *AliITSv11GeomCableRound::CreateSegment( Double_t *coord1, | |
595 | Double_t *coord2, | |
596 | Double_t *localVect1, | |
597 | Double_t *localVect2 ) | |
598 | { | |
fa4639a3 | 599 | // Create one cylindrical segment and its layers |
b7943f00 | 600 | |
601 | //================================================= | |
602 | // Calculate segment "deformation" | |
603 | Double_t dx = coord2[0]-coord1[0]; | |
604 | Double_t dy = coord2[1]-coord1[1]; | |
605 | Double_t dz = coord2[2]-coord1[2]; | |
606 | Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz); | |
607 | ||
608 | // normal vectors have to point outside the TGeoCtub : | |
609 | if (-localVect1[2]<0) { | |
610 | localVect1[0] = -localVect1[0]; | |
611 | localVect1[1] = -localVect1[1]; | |
612 | localVect1[2] = -localVect1[2]; | |
613 | }; | |
614 | if (localVect2[2]<0) { | |
615 | localVect2[0] = -localVect2[0]; | |
616 | localVect2[1] = -localVect2[1]; | |
617 | localVect2[2] = -localVect2[2]; | |
618 | }; | |
619 | //================================================= | |
620 | // Create the segment | |
fa4639a3 | 621 | TGeoCtub *cableSeg = new TGeoCtub(0, fRadius, length/2, fPhiMin, fPhiMax, |
b7943f00 | 622 | localVect1[0],localVect1[1],localVect1[2], |
623 | localVect2[0],localVect2[1],localVect2[2]); | |
624 | ||
531d6cdc | 625 | TGeoMedium *airSDD = gGeoManager->GetMedium("ITS_ITSair"); |
b7943f00 | 626 | TGeoVolume *vCableSeg = new TGeoVolume(GetName(), cableSeg, airSDD); |
627 | ||
628 | // add all cable layers | |
629 | Double_t layThickness[100+1]; // 100 layers max !!! | |
630 | layThickness[0] = 0; | |
631 | for (Int_t iLay=0; iLay<fNlayer; iLay++) { | |
632 | ||
633 | layThickness[iLay+1] = fLayThickness[iLay]+layThickness[iLay]; | |
634 | TGeoCtub *lay = new TGeoCtub(layThickness[iLay], layThickness[iLay+1], | |
635 | length/2, fPhiMin, fPhiMax, | |
636 | localVect1[0],localVect1[1],localVect1[2], | |
637 | localVect2[0],localVect2[1],localVect2[2]); | |
638 | ||
639 | TGeoVolume *vLay = new TGeoVolume("vCableSegLay", lay, fLayMedia[iLay]); | |
640 | vLay->SetLineColor(fLayColor[iLay]); | |
641 | vCableSeg->AddNode(vLay, iLay+1, 0); | |
642 | }; | |
643 | ||
644 | vCableSeg->SetVisibility(kFALSE); | |
645 | return vCableSeg; | |
5d7a6c6d | 646 | } |
b7943f00 | 647 | |
648 | ||
fa4639a3 | 649 | //________________________________________________________________________ |
650 | TGeoVolume *AliITSv11GeomCableRound::CreateTorus( Double_t &phi, | |
651 | Double_t &r) | |
652 | { | |
653 | // Create one torus segment and its layers | |
654 | ||
655 | Double_t torusR = r; | |
656 | Double_t torusPhi1 = phi; | |
657 | Double_t torusDPhi = -2*torusPhi1; | |
658 | ||
659 | //================================================= | |
660 | // Create the segment | |
661 | TGeoTorus *cableSeg = new TGeoTorus(torusR, 0,fRadius,torusPhi1,torusDPhi); | |
531d6cdc | 662 | TGeoMedium *airSDD = gGeoManager->GetMedium("ITS_ITSair"); |
fa4639a3 | 663 | TGeoVolume *vCableSeg = new TGeoVolume(GetName(), cableSeg, airSDD); |
664 | ||
665 | // add all cable layers | |
666 | Double_t layThickness[100+1]; // 100 layers max !!! | |
667 | layThickness[0] = 0; | |
668 | for (Int_t iLay=0; iLay<fNlayer; iLay++) { | |
669 | ||
670 | layThickness[iLay+1] = fLayThickness[iLay]+layThickness[iLay]; | |
671 | TGeoTorus *lay = new TGeoTorus(torusR, layThickness[iLay], | |
672 | layThickness[iLay+1], | |
673 | torusPhi1,torusDPhi); | |
674 | ||
675 | TGeoVolume *vLay = new TGeoVolume("vCableSegLay",lay,fLayMedia[iLay]); | |
676 | vLay->SetLineColor(fLayColor[iLay]); | |
677 | vCableSeg->AddNode(vLay, iLay+1, 0); | |
678 | }; | |
679 | ||
680 | vCableSeg->SetVisibility(kFALSE); | |
681 | return vCableSeg; | |
5d7a6c6d | 682 | } |
fa4639a3 | 683 | |
684 | ||
b7943f00 | 685 | //________________________________________________________________________ |
686 | void AliITSv11GeomCableRound::SetNLayers(Int_t nLayers) { | |
687 | // Set the total number of layers | |
688 | if((nLayers>0) &&(nLayers<=fgkCableMaxLayer)) { | |
689 | fNlayer = nLayers; | |
690 | for (Int_t i = 0; i<fNlayer; i++) { | |
691 | fLayThickness[i] = 0; | |
692 | fLayMedia[i] = 0; | |
693 | }; | |
694 | }; | |
5d7a6c6d | 695 | } |
b7943f00 | 696 | |
697 | //________________________________________________________________________ | |
698 | Int_t AliITSv11GeomCableRound::SetLayer(Int_t nLayer, Double_t thick, | |
699 | TGeoMedium *medium, Int_t color) { | |
700 | // Set layer #nLayer | |
701 | if ((nLayer<0)||(nLayer>=fNlayer)) { | |
702 | printf("Set wrong layer number of the cable\n"); | |
703 | return kFALSE; | |
704 | }; | |
705 | if (nLayer>0) | |
706 | if (fLayThickness[nLayer-1]<=0) { | |
707 | printf("You must define cable layer %i first !",nLayer-1); | |
708 | return kFALSE; | |
709 | }; | |
710 | ||
711 | Double_t thickTot = 0; | |
712 | for (Int_t i=0; i<nLayer; i++) thickTot += fLayThickness[i]; | |
713 | thickTot += thick; | |
714 | if (thickTot-1e-10>fRadius) { | |
715 | printf("Can't add this layer, cable thickness would be higher than total\n"); | |
716 | return kFALSE; | |
717 | }; | |
718 | ||
719 | fLayThickness[nLayer] = thick; | |
720 | fLayMedia[nLayer] = medium; | |
721 | fLayColor[nLayer] = color; | |
722 | ||
723 | return kTRUE; | |
5d7a6c6d | 724 | } |