]>
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 | |
108bd0fe | 44 | TGeoMedium *air = gGeoManager->GetMedium("ITS_AIR$"); |
531d6cdc | 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) : | |
33ddec7d | 164 | AliITSv11GeomCable(name), |
165 | fRadius(radius), | |
166 | fNlayer(0), | |
167 | fPhiMin(0), | |
168 | fPhiMax(360) | |
169 | { | |
b7943f00 | 170 | // Constructor |
b7943f00 | 171 | for (Int_t i=0; i<fgkCableMaxLayer ; i++) { |
172 | fLayThickness[i] = 0; | |
173 | fLayColor[i] = 0; | |
174 | fLayMedia[i] = 0; | |
175 | }; | |
5d7a6c6d | 176 | } |
b7943f00 | 177 | |
178 | //________________________________________________________________________ | |
179 | AliITSv11GeomCableRound::AliITSv11GeomCableRound(const AliITSv11GeomCableRound &s) : | |
180 | AliITSv11GeomCable(s),fRadius(s.fRadius),fNlayer(s.fNlayer),fPhiMin(s.fPhiMin), | |
181 | fPhiMax(s.fPhiMax) | |
182 | { | |
183 | // Copy Constructor | |
184 | for (Int_t i=0; i<s.fNlayer; i++) { | |
185 | fLayThickness[i] = s.fLayThickness[i]; | |
186 | fLayMedia[i] = s.fLayMedia[i]; | |
187 | fLayColor[i] = s.fLayColor[i]; | |
188 | } | |
189 | } | |
190 | ||
191 | //________________________________________________________________________ | |
192 | AliITSv11GeomCableRound& AliITSv11GeomCableRound:: | |
193 | operator=(const AliITSv11GeomCableRound &s) { | |
194 | // Assignment operator | |
195 | // Not fully inplemented yet !!! | |
196 | ||
197 | if(&s == this) return *this; | |
198 | *this = s; | |
199 | fRadius = s.fRadius; | |
200 | fPhiMin = s.fPhiMin; | |
201 | fPhiMax = s.fPhiMax; | |
202 | fNlayer = s.fNlayer; | |
203 | for (Int_t i=0; i<s.fNlayer; i++) { | |
204 | fLayThickness[i] = s.fLayThickness[i]; | |
205 | fLayMedia[i] = s.fLayMedia[i]; | |
206 | fLayColor[i] = s.fLayColor[i]; | |
207 | }; | |
208 | return *this; | |
209 | } | |
210 | ||
211 | //________________________________________________________________________ | |
212 | Int_t AliITSv11GeomCableRound::GetPoint( Int_t iCheckPt, Double_t *coord) | |
213 | const { | |
214 | // Get check point #iCheckPt | |
215 | TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(2*iCheckPt); | |
5d7a6c6d | 216 | #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0) |
217 | CopyFrom(coord, coordVector->GetElements()); | |
218 | #else | |
b7943f00 | 219 | CopyFrom(coord, coordVector->GetMatrixArray()); |
5d7a6c6d | 220 | #endif |
b7943f00 | 221 | return kTRUE; |
5d7a6c6d | 222 | } |
b7943f00 | 223 | |
224 | //________________________________________________________________________ | |
225 | Int_t AliITSv11GeomCableRound::GetVect( Int_t iCheckPt, Double_t *coord) | |
226 | const { | |
227 | // | |
228 | // Get vector transverse to the section at point #iCheckPt | |
229 | // | |
230 | ||
231 | TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(2*iCheckPt+1); | |
5d7a6c6d | 232 | #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0) |
233 | CopyFrom(coord, coordVector->GetElements()); | |
234 | #else | |
b7943f00 | 235 | CopyFrom(coord, coordVector->GetMatrixArray()); |
5d7a6c6d | 236 | #endif |
b7943f00 | 237 | return kTRUE; |
5d7a6c6d | 238 | } |
239 | ||
b7943f00 | 240 | //________________________________________________________________________ |
241 | void AliITSv11GeomCableRound::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt, | |
242 | Double_t *coord, Double_t *orthVect) | |
243 | { | |
244 | // | |
245 | // Add point #iCheckPt and its transverse vector. Point is added at (i) in | |
246 | // fPointArray and the vector is added at (i+1) | |
247 | // | |
248 | ||
249 | ||
250 | if (iCheckPt>=fVolumeArray.GetEntriesFast()) { | |
251 | fVolumeArray.AddLast(vol); | |
252 | TVectorD *point = new TVectorD(3,coord); | |
253 | TVectorD *vect = new TVectorD(3,orthVect); | |
254 | fPointArray.AddLast(point); | |
255 | fPointArray.AddLast(vect); | |
256 | ||
257 | } else if ((iCheckPt >= 0)&&(iCheckPt < fVolumeArray.GetEntriesFast())) { | |
258 | fVolumeArray.AddAt(vol, iCheckPt); | |
259 | TVectorD *point = new TVectorD(3,coord); | |
260 | TVectorD *vect = new TVectorD(3,orthVect); | |
261 | fPointArray.AddAt(point, iCheckPt*2 ); | |
262 | fPointArray.AddAt(vect, iCheckPt*2+1); | |
263 | }; | |
5d7a6c6d | 264 | } |
b7943f00 | 265 | |
266 | //________________________________________________________________________ | |
267 | void AliITSv11GeomCableRound::PrintCheckPoints() const { | |
268 | // Print all check points | |
269 | ||
270 | printf(" ---\n Printing all check points of the round cable\n"); | |
271 | for (Int_t i = 0; i<fVolumeArray.GetEntriesFast(); i++) { | |
272 | TVectorD *coordVector = (TVectorD *)fPointArray.UncheckedAt(i*2); | |
273 | //TVectorD *vectVector = (TVectorD *)fPointArray.UncheckedAt(i*2+1); | |
274 | Double_t coord[3]; | |
5d7a6c6d | 275 | #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0) |
276 | CopyFrom(coord, coordVector->GetElements()); | |
277 | #else | |
b7943f00 | 278 | CopyFrom(coord, coordVector->GetMatrixArray()); |
5d7a6c6d | 279 | #endif |
b7943f00 | 280 | printf(" ( %.2f, %.2f, %.2f )\n", coord[0], coord[1], coord[2]); |
281 | }; | |
5d7a6c6d | 282 | } |
b7943f00 | 283 | |
fa4639a3 | 284 | |
b7943f00 | 285 | //________________________________________________________________________ |
108bd0fe | 286 | TGeoVolume* AliITSv11GeomCableRound::CreateAndInsertCableSegment(Int_t p2, |
287 | TGeoCombiTrans** ct) | |
b7943f00 | 288 | { |
289 | // Creates a cable segment between points p1 and p2. | |
b7943f00 | 290 | // |
291 | // The segment volume is created inside the volume containing point2 | |
292 | // Therefore this segment should be defined in this volume only. | |
293 | // I mean here that, if the previous point is in another volume, | |
294 | // it should be just at the border between the 2 volumes. Also the | |
295 | // orientation vector of the previous point should be othogonal to | |
296 | // the surface between the 2 volumes. | |
297 | ||
298 | TGeoNode *mainNode; | |
299 | if (fInitialNode==0) { | |
300 | TObjArray *nodes = gGeoManager->GetListOfNodes(); | |
108bd0fe | 301 | if (nodes->GetEntriesFast()==0) return 0; |
b7943f00 | 302 | mainNode = (TGeoNode *) nodes->UncheckedAt(0); |
303 | } else { | |
304 | mainNode = fInitialNode; | |
305 | }; | |
306 | ||
307 | Int_t p1 = p2 - 1; | |
308 | TGeoVolume *p1Vol = GetVolume(p1); | |
309 | TGeoVolume *p2Vol = GetVolume(p2); | |
310 | ||
311 | ResetCheckDaughter(); | |
312 | fCurrentVol = p1Vol; | |
313 | if (! CheckDaughter(mainNode)) { | |
314 | printf("Error::volume containing point is not visible in node tree!\n"); | |
108bd0fe | 315 | return 0; |
b7943f00 | 316 | }; |
317 | ||
318 | Double_t coord1[3], coord2[3], vect1[3], vect2[3]; | |
319 | //================================================= | |
320 | // Get p1 position in the systeme of p2 | |
321 | if (p1Vol!=p2Vol) { | |
322 | ||
323 | Int_t p1nodeInd[fgkCableMaxNodeLevel]; | |
324 | for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i]; | |
325 | Int_t p1volLevel = 0; | |
326 | while (p1nodeInd[p1volLevel]!=-1) p1volLevel++; | |
327 | p1volLevel--; | |
328 | ||
329 | ResetCheckDaughter(); | |
330 | fCurrentVol = p2Vol; | |
331 | if (! CheckDaughter(mainNode)) { | |
332 | printf("Error::volume containing point is not visible in node tree!\n"); | |
108bd0fe | 333 | return 0; |
b7943f00 | 334 | }; |
335 | Int_t p2nodeInd[fgkCableMaxNodeLevel]; | |
336 | for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i]; | |
337 | Int_t commonMotherLevel = 0; | |
338 | while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel]) | |
339 | commonMotherLevel++; | |
340 | commonMotherLevel--; | |
341 | Int_t p2volLevel = 0; | |
342 | while (fNodeInd[p2volLevel]!=-1) p2volLevel++; | |
343 | p2volLevel--; | |
344 | ||
345 | // Get coord and vect of p1 in the common mother reference system | |
346 | GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1); | |
347 | GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1); | |
348 | // Translate them in the reference system of the volume containing p2 | |
349 | TGeoNode *pathNode[fgkCableMaxNodeLevel]; | |
350 | pathNode[0] = mainNode; | |
351 | for (Int_t i=0; i<=p2volLevel; i++) { | |
352 | pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]); | |
353 | }; | |
354 | Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]}; | |
355 | Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]}; | |
356 | ||
357 | for (Int_t i = commonMotherLevel+1; i<=p2volLevel; i++) { | |
358 | pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1); | |
359 | pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1); | |
360 | CopyFrom(globalCoord1, coord1); | |
361 | CopyFrom(globalVect1, vect1); | |
362 | }; | |
363 | } else { | |
364 | GetCheckPoint(p1, 0, 0, coord1); | |
365 | GetCheckVect(p1, 0, 0, vect1); | |
366 | }; | |
367 | ||
368 | //================================================= | |
369 | // Get p2 position in the systeme of p2 | |
370 | GetCheckPoint(p2, 0, 0, coord2); | |
371 | GetCheckVect(p2, 0, 0, vect2); | |
372 | ||
373 | Double_t cx = (coord1[0]+coord2[0])/2; | |
374 | Double_t cy = (coord1[1]+coord2[1])/2; | |
375 | Double_t cz = (coord1[2]+coord2[2])/2; | |
376 | Double_t dx = coord2[0]-coord1[0]; | |
377 | Double_t dy = coord2[1]-coord1[1]; | |
378 | Double_t dz = coord2[2]-coord1[2]; | |
379 | ||
380 | //================================================= | |
381 | // Positionning of the segment between the 2 points | |
382 | if ((dy<1e-31)&&(dy>0)) dy = 1e-31; | |
383 | if ((dz<1e-31)&&(dz>0)) dz = 1e-31; | |
384 | if ((dy>-1e-31)&&(dy<0)) dy = -1e-31; | |
385 | if ((dz>-1e-31)&&(dz<0)) dz = -1e-31; | |
386 | ||
387 | Double_t angleRot1 = -TMath::ATan2(dx,dy); | |
388 | Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx); | |
389 | Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz); | |
390 | TGeoRotation *rot = new TGeoRotation("",angleRot1*TMath::RadToDeg(), | |
391 | angleRotDiag*TMath::RadToDeg(), | |
392 | 0); | |
393 | Double_t localVect1[3], localVect2[3]; | |
394 | rot->MasterToLocalVect(vect1, localVect1); | |
395 | rot->MasterToLocalVect(vect2, localVect2); | |
396 | TGeoTranslation *trans = new TGeoTranslation("",cx, cy, cz); | |
397 | ||
398 | //================================================= | |
399 | // Create the segment and add it to the mother volume | |
400 | TGeoVolume *vCableSeg = CreateSegment(coord1, coord2, | |
7a82301d | 401 | localVect1, localVect2, p2); |
b7943f00 | 402 | |
403 | TGeoCombiTrans *combi = new TGeoCombiTrans(*trans, *rot); | |
404 | p2Vol->AddNode(vCableSeg, p2, combi); | |
405 | //================================================= | |
406 | delete rot; | |
407 | delete trans; | |
408 | ||
409 | if (fDebug) { | |
410 | printf("---\n Cable segment points : "); | |
411 | printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]); | |
412 | printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]); | |
413 | }; | |
414 | // #include <TGeoSphere.h> | |
108bd0fe | 415 | // TGeoMedium *airSDD = gGeoManager->GetMedium("ITS_AIR$"); |
b7943f00 | 416 | // TGeoSphere *sphere = new TGeoSphere(0, 0.15); |
417 | // TGeoVolume *vSphere = new TGeoVolume("", sphere, airSDD); | |
418 | // TGeoTranslation *trC = new TGeoTranslation("", cx, cy, cz); | |
419 | // TGeoTranslation *tr1 = new TGeoTranslation("",coord1[0], | |
420 | // coord1[1],coord1[2]); | |
421 | // TGeoTranslation *tr2 = new TGeoTranslation("",coord2[0], | |
422 | // coord2[1],coord2[2]); | |
423 | // p2Vol->AddNode(vSphere, p2*3-2, trC); | |
424 | // p2Vol->AddNode(vSphere, p2*3-1, tr1); | |
425 | // p2Vol->AddNode(vSphere, p2*3 , tr2); | |
426 | ||
108bd0fe | 427 | if (ct) *ct = combi; |
428 | return vCableSeg; | |
5d7a6c6d | 429 | } |
b7943f00 | 430 | |
fa4639a3 | 431 | |
432 | //________________________________________________________________________ | |
108bd0fe | 433 | TGeoVolume* AliITSv11GeomCableRound::CreateAndInsertTorusSegment(Int_t p2, |
434 | Double_t rotation, | |
435 | TGeoCombiTrans** ct) | |
fa4639a3 | 436 | { |
437 | // Create a torus cable segment between points p1 and p2. | |
438 | // The radius and position of the torus is defined by the | |
439 | // perpendicular vector of point p2 (the orientation of this vector | |
440 | // and the position of the 2 check points are enough to completely | |
441 | // define the torus) | |
442 | ||
443 | TGeoNode *mainNode; | |
444 | if (fInitialNode==0) { | |
445 | TObjArray *nodes = gGeoManager->GetListOfNodes(); | |
108bd0fe | 446 | if (nodes->GetEntriesFast()==0) return 0; |
fa4639a3 | 447 | mainNode = (TGeoNode *) nodes->UncheckedAt(0); |
448 | } else { | |
449 | mainNode = fInitialNode; | |
450 | }; | |
451 | ||
452 | Int_t p1 = p2 - 1; | |
453 | TGeoVolume *p1Vol = GetVolume(p1); | |
454 | TGeoVolume *p2Vol = GetVolume(p2); | |
455 | ||
456 | ResetCheckDaughter(); | |
457 | fCurrentVol = p1Vol; | |
458 | if (! CheckDaughter(mainNode)) { | |
459 | printf("Error::volume containing point is not visible in node tree!\n"); | |
108bd0fe | 460 | return 0; |
fa4639a3 | 461 | }; |
462 | ||
463 | Double_t coord1[3], coord2[3], vect1[3], vect2[3]; | |
464 | //================================================= | |
465 | // Get p1 position in the systeme of p2 | |
466 | if (p1Vol!=p2Vol) { | |
467 | ||
468 | Int_t p1nodeInd[fgkCableMaxNodeLevel]; | |
469 | for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i]; | |
470 | Int_t p1volLevel = 0; | |
471 | while (p1nodeInd[p1volLevel]!=-1) p1volLevel++; | |
472 | p1volLevel--; | |
473 | ||
474 | ResetCheckDaughter(); | |
475 | fCurrentVol = p2Vol; | |
476 | if (! CheckDaughter(mainNode)) { | |
477 | printf("Error::volume containing point is not visible in node tree!\n"); | |
108bd0fe | 478 | return 0; |
fa4639a3 | 479 | }; |
480 | Int_t p2nodeInd[fgkCableMaxNodeLevel]; | |
481 | for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i]; | |
482 | Int_t commonMotherLevel = 0; | |
483 | while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel]) | |
484 | commonMotherLevel++; | |
485 | commonMotherLevel--; | |
486 | Int_t p2volLevel = 0; | |
487 | while (fNodeInd[p2volLevel]!=-1) p2volLevel++; | |
488 | p2volLevel--; | |
489 | ||
490 | // Get coord and vect of p1 in the common mother reference system | |
491 | GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1); | |
492 | GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1); | |
493 | // Translate them in the reference system of the volume containing p2 | |
494 | TGeoNode *pathNode[fgkCableMaxNodeLevel]; | |
495 | pathNode[0] = mainNode; | |
496 | for (Int_t i=0; i<=p2volLevel; i++) { | |
497 | pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]); | |
498 | }; | |
499 | Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]}; | |
500 | Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]}; | |
501 | ||
502 | for (Int_t i = commonMotherLevel+1; i<=p2volLevel; i++) { | |
503 | pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1); | |
504 | pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1); | |
505 | CopyFrom(globalCoord1, coord1); | |
506 | CopyFrom(globalVect1, vect1); | |
507 | }; | |
508 | } else { | |
509 | GetCheckPoint(p1, 0, 0, coord1); | |
510 | GetCheckVect(p1, 0, 0, vect1); | |
511 | }; | |
512 | ||
513 | //================================================= | |
514 | // Get p2 position in the systeme of p2 | |
515 | GetCheckPoint(p2, 0, 0, coord2); | |
516 | GetCheckVect(p2, 0, 0, vect2); | |
517 | ||
518 | Double_t cx = (coord1[0]+coord2[0])/2; | |
519 | Double_t cy = (coord1[1]+coord2[1])/2; | |
520 | Double_t cz = (coord1[2]+coord2[2])/2; | |
521 | Double_t dx = coord2[0]-coord1[0]; | |
522 | Double_t dy = coord2[1]-coord1[1]; | |
523 | Double_t dz = coord2[2]-coord1[2]; | |
524 | Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz); | |
525 | ||
526 | //================================================= | |
527 | // Positionning of the segment between the 2 points | |
528 | if ((dy<1e-31)&&(dy>0)) dy = 1e-31; | |
529 | if ((dz<1e-31)&&(dz>0)) dz = 1e-31; | |
530 | if ((dy>-1e-31)&&(dy<0)) dy = -1e-31; | |
531 | if ((dz>-1e-31)&&(dz<0)) dz = -1e-31; | |
532 | ||
533 | Double_t angleRot1 = -TMath::ATan2(dx,dy); | |
534 | Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx); | |
535 | Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz); | |
536 | ||
537 | TGeoRotation rotTorusTemp("",angleRot1*TMath::RadToDeg(), | |
538 | angleRotDiag*TMath::RadToDeg(),0); | |
539 | TGeoRotation rotTorusToZ("",0,90,0); | |
540 | rotTorusTemp.MultiplyBy(&rotTorusToZ, kTRUE); | |
541 | Double_t localVect2[3]; | |
542 | rotTorusTemp.MasterToLocalVect(vect2, localVect2); | |
543 | if (localVect2[1]<0) { | |
544 | localVect2[0] = -localVect2[0]; | |
545 | localVect2[1] = -localVect2[1]; | |
546 | localVect2[2] = -localVect2[2]; | |
547 | }; | |
548 | Double_t normVect2 = TMath::Sqrt(localVect2[0]*localVect2[0]+ | |
549 | localVect2[1]*localVect2[1]+ | |
550 | localVect2[2]*localVect2[2]); | |
551 | Double_t axisX[3] = {1,0,0}; | |
552 | Double_t cosangleTorusSeg = (localVect2[0]*axisX[0]+ | |
553 | localVect2[1]*axisX[1]+ | |
554 | localVect2[2]*axisX[2])/normVect2; | |
555 | Double_t angleTorusSeg = TMath::ACos(cosangleTorusSeg)*TMath::RadToDeg(); | |
556 | TGeoRotation rotTorus("",angleRot1*TMath::RadToDeg(), | |
557 | angleRotDiag*TMath::RadToDeg(), | |
558 | 180-angleTorusSeg+rotation); | |
559 | rotTorus.MultiplyBy(&rotTorusToZ, kTRUE); | |
560 | rotTorus.MasterToLocalVect(vect2, localVect2); | |
561 | if (localVect2[1]<0) { | |
562 | localVect2[0] = -localVect2[0]; | |
563 | localVect2[1] = -localVect2[1]; | |
564 | localVect2[2] = -localVect2[2]; | |
565 | }; | |
566 | normVect2 = TMath::Sqrt(localVect2[0]*localVect2[0]+ | |
567 | localVect2[1]*localVect2[1]+ | |
568 | localVect2[2]*localVect2[2]); | |
569 | Double_t axisY[3] = {0,1,0}; | |
570 | Double_t cosPhi = (localVect2[0]*axisY[0]+localVect2[1]*axisY[1]+ | |
571 | localVect2[2]*axisY[2])/normVect2; | |
572 | Double_t torusPhi1 = TMath::ACos(cosPhi); | |
573 | Double_t torusR = (length/2)/TMath::Sin(torusPhi1); | |
574 | torusPhi1 = torusPhi1*TMath::RadToDeg(); | |
575 | Double_t perpLength = TMath::Sqrt(torusR*torusR-length*length/4); | |
576 | Double_t localTransT[3] = {-perpLength,0,0}; | |
577 | Double_t globalTransT[3]; | |
578 | rotTorus.LocalToMasterVect(localTransT, globalTransT); | |
579 | TGeoTranslation transTorus("",cx+globalTransT[0],cy+globalTransT[1], | |
580 | cz+globalTransT[2]); | |
581 | ||
582 | TGeoCombiTrans *combiTorus = new TGeoCombiTrans(transTorus, rotTorus); | |
583 | ||
584 | //================================================= | |
585 | // Create the segment and add it to the mother volume | |
7a82301d | 586 | TGeoVolume *vCableSegT = CreateTorus(torusPhi1, torusR, p2); |
fa4639a3 | 587 | p2Vol->AddNode(vCableSegT, p2, combiTorus); |
588 | ||
589 | if (fDebug) { | |
590 | printf("---\n Cable segment points : "); | |
591 | printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]); | |
592 | printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]); | |
593 | }; | |
594 | ||
108bd0fe | 595 | if (ct) *ct = combiTorus; |
596 | return vCableSegT; | |
5d7a6c6d | 597 | } |
fa4639a3 | 598 | |
b7943f00 | 599 | //________________________________________________________________________ |
600 | TGeoVolume *AliITSv11GeomCableRound::CreateSegment( Double_t *coord1, | |
601 | Double_t *coord2, | |
602 | Double_t *localVect1, | |
7a82301d | 603 | Double_t *localVect2, Int_t p) |
b7943f00 | 604 | { |
fa4639a3 | 605 | // Create one cylindrical segment and its layers |
b7943f00 | 606 | |
607 | //================================================= | |
608 | // Calculate segment "deformation" | |
609 | Double_t dx = coord2[0]-coord1[0]; | |
610 | Double_t dy = coord2[1]-coord1[1]; | |
611 | Double_t dz = coord2[2]-coord1[2]; | |
612 | Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz); | |
613 | ||
614 | // normal vectors have to point outside the TGeoCtub : | |
615 | if (-localVect1[2]<0) { | |
616 | localVect1[0] = -localVect1[0]; | |
617 | localVect1[1] = -localVect1[1]; | |
618 | localVect1[2] = -localVect1[2]; | |
619 | }; | |
620 | if (localVect2[2]<0) { | |
621 | localVect2[0] = -localVect2[0]; | |
622 | localVect2[1] = -localVect2[1]; | |
623 | localVect2[2] = -localVect2[2]; | |
624 | }; | |
625 | //================================================= | |
626 | // Create the segment | |
fa4639a3 | 627 | TGeoCtub *cableSeg = new TGeoCtub(0, fRadius, length/2, fPhiMin, fPhiMax, |
b7943f00 | 628 | localVect1[0],localVect1[1],localVect1[2], |
629 | localVect2[0],localVect2[1],localVect2[2]); | |
630 | ||
108bd0fe | 631 | TGeoMedium *airSDD = gGeoManager->GetMedium("ITS_AIR$"); |
7a82301d | 632 | char name[100]; |
633 | sprintf(name, "%s_%i",GetName(),p); | |
634 | TGeoVolume *vCableSeg = new TGeoVolume(name, cableSeg, airSDD); | |
b7943f00 | 635 | |
636 | // add all cable layers | |
637 | Double_t layThickness[100+1]; // 100 layers max !!! | |
638 | layThickness[0] = 0; | |
639 | for (Int_t iLay=0; iLay<fNlayer; iLay++) { | |
640 | ||
641 | layThickness[iLay+1] = fLayThickness[iLay]+layThickness[iLay]; | |
642 | TGeoCtub *lay = new TGeoCtub(layThickness[iLay], layThickness[iLay+1], | |
643 | length/2, fPhiMin, fPhiMax, | |
644 | localVect1[0],localVect1[1],localVect1[2], | |
645 | localVect2[0],localVect2[1],localVect2[2]); | |
646 | ||
647 | TGeoVolume *vLay = new TGeoVolume("vCableSegLay", lay, fLayMedia[iLay]); | |
648 | vLay->SetLineColor(fLayColor[iLay]); | |
649 | vCableSeg->AddNode(vLay, iLay+1, 0); | |
650 | }; | |
651 | ||
652 | vCableSeg->SetVisibility(kFALSE); | |
653 | return vCableSeg; | |
5d7a6c6d | 654 | } |
b7943f00 | 655 | |
656 | ||
fa4639a3 | 657 | //________________________________________________________________________ |
658 | TGeoVolume *AliITSv11GeomCableRound::CreateTorus( Double_t &phi, | |
7a82301d | 659 | Double_t &r, Int_t p) |
fa4639a3 | 660 | { |
661 | // Create one torus segment and its layers | |
662 | ||
663 | Double_t torusR = r; | |
7a82301d | 664 | // Double_t torusPhi1 = phi; |
665 | // Double_t torusDPhi = -2*torusPhi1; // bug in root ... | |
666 | Double_t torusPhi1 = 360-phi; | |
667 | Double_t torusDPhi = 2*phi; | |
fa4639a3 | 668 | |
669 | //================================================= | |
670 | // Create the segment | |
7a82301d | 671 | TGeoTorus *cableSeg = new TGeoTorus(torusR, 0, fRadius, torusPhi1, torusDPhi); |
108bd0fe | 672 | TGeoMedium *airSDD = gGeoManager->GetMedium("ITS_AIR$"); |
7a82301d | 673 | char name[100]; |
674 | sprintf(name, "%s_%i",GetName(),p); | |
675 | TGeoVolume *vCableSeg = new TGeoVolume(name, cableSeg, airSDD); | |
fa4639a3 | 676 | |
677 | // add all cable layers | |
678 | Double_t layThickness[100+1]; // 100 layers max !!! | |
679 | layThickness[0] = 0; | |
680 | for (Int_t iLay=0; iLay<fNlayer; iLay++) { | |
681 | ||
682 | layThickness[iLay+1] = fLayThickness[iLay]+layThickness[iLay]; | |
683 | TGeoTorus *lay = new TGeoTorus(torusR, layThickness[iLay], | |
684 | layThickness[iLay+1], | |
685 | torusPhi1,torusDPhi); | |
686 | ||
687 | TGeoVolume *vLay = new TGeoVolume("vCableSegLay",lay,fLayMedia[iLay]); | |
688 | vLay->SetLineColor(fLayColor[iLay]); | |
689 | vCableSeg->AddNode(vLay, iLay+1, 0); | |
690 | }; | |
691 | ||
692 | vCableSeg->SetVisibility(kFALSE); | |
693 | return vCableSeg; | |
5d7a6c6d | 694 | } |
fa4639a3 | 695 | |
696 | ||
b7943f00 | 697 | //________________________________________________________________________ |
698 | void AliITSv11GeomCableRound::SetNLayers(Int_t nLayers) { | |
699 | // Set the total number of layers | |
700 | if((nLayers>0) &&(nLayers<=fgkCableMaxLayer)) { | |
701 | fNlayer = nLayers; | |
702 | for (Int_t i = 0; i<fNlayer; i++) { | |
703 | fLayThickness[i] = 0; | |
704 | fLayMedia[i] = 0; | |
705 | }; | |
706 | }; | |
5d7a6c6d | 707 | } |
b7943f00 | 708 | |
709 | //________________________________________________________________________ | |
710 | Int_t AliITSv11GeomCableRound::SetLayer(Int_t nLayer, Double_t thick, | |
711 | TGeoMedium *medium, Int_t color) { | |
712 | // Set layer #nLayer | |
713 | if ((nLayer<0)||(nLayer>=fNlayer)) { | |
714 | printf("Set wrong layer number of the cable\n"); | |
715 | return kFALSE; | |
716 | }; | |
717 | if (nLayer>0) | |
718 | if (fLayThickness[nLayer-1]<=0) { | |
719 | printf("You must define cable layer %i first !",nLayer-1); | |
720 | return kFALSE; | |
721 | }; | |
722 | ||
723 | Double_t thickTot = 0; | |
724 | for (Int_t i=0; i<nLayer; i++) thickTot += fLayThickness[i]; | |
725 | thickTot += thick; | |
726 | if (thickTot-1e-10>fRadius) { | |
727 | printf("Can't add this layer, cable thickness would be higher than total\n"); | |
728 | return kFALSE; | |
729 | }; | |
730 | ||
731 | fLayThickness[nLayer] = thick; | |
732 | fLayMedia[nLayer] = medium; | |
733 | fLayColor[nLayer] = color; | |
734 | ||
735 | return kTRUE; | |
5d7a6c6d | 736 | } |