1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //*************************************************************************
19 // Class for flat cables
21 // Ludovic Gaudichet gaudichet@to.infn.it
22 //*************************************************************************
26 // General Root includes
27 //#include <Riostream.h>
31 // Root Geometry includes
32 #include <TGeoManager.h>
33 #include <TGeoVolume.h>
36 #include <TGeoMatrix.h>
39 #include "AliITSv11GeomCableFlat.h"
42 ClassImp(AliITSv11GeomCableFlat)
44 //________________________________________________________________________
45 AliITSv11GeomCableFlat::AliITSv11GeomCableFlat():
52 for (Int_t i=0; i<fgkCableMaxLayer ; i++) {
58 for(Int_t i=0;i<3;i++)fPreviousX[i]=0.;
61 //________________________________________________________________________
62 AliITSv11GeomCableFlat::
63 AliITSv11GeomCableFlat(const char* name, Double_t width, Double_t thick) :
64 AliITSv11GeomCable(name),
69 // standard constructor
70 for (Int_t i=0; i<fgkCableMaxLayer ; i++) {
76 for(Int_t i=0;i<3;i++)fPreviousX[i]=0.;
79 //________________________________________________________________________
80 AliITSv11GeomCableFlat::AliITSv11GeomCableFlat(const AliITSv11GeomCableFlat &s) :
81 AliITSv11GeomCable(s),fWidth(s.fWidth),fThick(s.fThick),fNlayer(s.fNlayer)
84 for (Int_t i=0; i<s.fNlayer; i++) {
85 fLayThickness[i] = s.fLayThickness[i];
86 fTranslation[i] = s.fTranslation[i];
87 fLayMedia[i] = s.fLayMedia[i];
88 fLayColor[i] = s.fLayColor[i];
90 for(Int_t i=0;i<3;i++)fPreviousX[i]=s.fPreviousX[i];
94 //________________________________________________________________________
95 AliITSv11GeomCableFlat& AliITSv11GeomCableFlat::
96 operator=(const AliITSv11GeomCableFlat &s) {
97 // Assignment operator
98 // Not fully inplemented yet !!!
100 if(&s == this) return *this;
105 for (Int_t i=0; i<s.fNlayer; i++) {
106 fLayThickness[i] = s.fLayThickness[i];
107 fTranslation[i] = s.fTranslation[i];
108 fLayMedia[i] = s.fLayMedia[i];
109 fLayColor[i] = s.fLayColor[i];
114 //________________________________________________________________________
115 Int_t AliITSv11GeomCableFlat::GetPoint( Int_t iCheckPt, Double_t *coord)
117 // Get the correct point #iCheckPt
118 TVectorD *coordVector =(TVectorD *)fPointArray.At(2*iCheckPt);
120 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
121 CopyFrom(coord, coordVector->GetElements());
123 CopyFrom(coord, coordVector->GetMatrixArray());
131 //________________________________________________________________________
132 Int_t AliITSv11GeomCableFlat::GetVect( Int_t iCheckPt, Double_t *coord)
134 // Get the correct vect corresponding to point #iCheckPt
136 TVectorD *coordVector =(TVectorD *)fPointArray.At(2*iCheckPt+1);
138 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
139 CopyFrom(coord, coordVector->GetElements());
141 CopyFrom(coord, coordVector->GetMatrixArray());
149 //________________________________________________________________________
150 void AliITSv11GeomCableFlat::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt,
151 Double_t *coord, Double_t *orthVect)
154 // Add a check point. In the fPointArray, the point is at i and its vector
158 // if (iCheckPt>=fVolumeArray.GetEntriesFast()) {
159 // fVolumeArray.AddLast(vol);
160 // TVectorD *point = new TVectorD(3,coord);
161 // TVectorD *vect = new TVectorD(3,orthVect);
162 // fPointArray.AddLast(point);
163 // fPointArray.AddLast(vect);
165 // } else if ((iCheckPt >= 0)&&(iCheckPt < fVolumeArray.GetEntriesFast())) {
166 // fVolumeArray.AddAt(vol, iCheckPt);
167 // TVectorD *point = new TVectorD(3,coord);
168 // TVectorD *vect = new TVectorD(3,orthVect);
169 // fPointArray.AddAt(point, iCheckPt*2 );
170 // fPointArray.AddAt(vect, iCheckPt*2+1);
172 fVolumeArray.AddAtAndExpand(vol, iCheckPt);
173 TVectorD *point = new TVectorD(3,coord);
174 TVectorD *vect = new TVectorD(3,orthVect);
175 fPointArray.AddAtAndExpand(point, iCheckPt*2 );
176 fPointArray.AddAtAndExpand(vect, iCheckPt*2+1);
179 //________________________________________________________________________
180 void AliITSv11GeomCableFlat::PrintCheckPoints() const {
181 // print all check points of the cable
182 printf(" ---\n Printing all check points of the flat cable\n");
183 for (Int_t i = 0; i<fVolumeArray.GetEntriesFast(); i++) {
185 if (GetPoint( i, coord))
186 printf(" ( %.2f, %.2f, %.2f )\n", coord[0], coord[1], coord[2]);
190 //________________________________________________________________________
191 TGeoVolume* AliITSv11GeomCableFlat::CreateAndInsertCableSegment(Int_t p2,
195 // Creates a cable segment between points p1 and p2.
196 // Rotation is the eventual rotation of the flat cable
197 // along its length axis
199 // The segment volume is created inside the volume containing point2
200 // Therefore this segment should be defined in this volume only.
201 // I mean here that, if the previous point is in another volume,
202 // it should be just at the border between the 2 volumes. Also the
203 // orientation vector of the previous point should be orthogonal to
204 // the surface between the 2 volumes.
207 if (fInitialNode==0) {
208 TObjArray *nodes = gGeoManager->GetListOfNodes();
209 if (nodes->GetEntriesFast()==0) return 0;
210 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
212 mainNode = fInitialNode;
216 TGeoVolume *p2Vol = GetVolume(p2);
217 TGeoVolume *p1Vol = GetVolume(p1);
219 ResetCheckDaughter();
221 if (! CheckDaughter(mainNode)) {
222 printf("Error::volume containing point is not visible in node tree!\n");
226 Double_t coord1[3], coord2[3], vect1[3], vect2[3];
227 //=================================================
228 // Get p1 position in the systeme of p2
231 Int_t p1nodeInd[fgkCableMaxNodeLevel];
232 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i];
233 Int_t p1volLevel = 0;
234 while (p1nodeInd[p1volLevel]!=-1) p1volLevel++;
237 ResetCheckDaughter();
239 if (! CheckDaughter(mainNode)) {
240 printf("Error::volume containing point is not visible in node tree!\n");
243 Int_t p2nodeInd[fgkCableMaxNodeLevel];
244 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i];
245 Int_t commonMotherLevel = 0;
246 while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel])
249 Int_t p2volLevel = 0;
250 while (fNodeInd[p2volLevel]!=-1) p2volLevel++;
253 // Get coord and vect of p1 in the common mother reference system
254 if (! GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1) )
256 if (! GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1) )
259 // Translate them in the reference system of the volume containing p2
260 TGeoNode *pathNode[fgkCableMaxNodeLevel];
261 pathNode[0] = mainNode;
262 for (Int_t i=0; i<=p2volLevel; i++) {
263 pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]);
265 Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]};
266 Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]};
268 for (Int_t i = commonMotherLevel+1; i <= p2volLevel; i++) {
269 pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1);
270 pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1);
271 CopyFrom(globalCoord1, coord1);
272 CopyFrom(globalVect1, vect1);
275 if (! GetCheckPoint(p1, 0, 0, coord1) ) return 0;
276 if (! GetCheckVect(p1, 0, 0, vect1) ) return 0;
279 //=================================================
280 // Get p2 position in the systeme of p2
281 if (! GetCheckPoint(p2, 0, 0, coord2) ) return 0;
282 if (! GetCheckVect(p2, 0, 0, vect2) ) return 0;
284 Double_t cx = (coord1[0]+coord2[0])/2;
285 Double_t cy = (coord1[1]+coord2[1])/2;
286 Double_t cz = (coord1[2]+coord2[2])/2;
287 Double_t dx = coord2[0]-coord1[0];
288 Double_t dy = coord2[1]-coord1[1];
289 Double_t dz = coord2[2]-coord1[2];
291 //=================================================
292 // Positionning of the segment between the 2 points
293 if (TMath::Abs(dy)<1e-231) dy = 1e-231;
294 if (TMath::Abs(dz)<1e-231) dz = 1e-231;
295 //Double_t angleRot1 = -TMath::ATan(dx/dy);
296 //Double_t planDiagL = -TMath::Sqrt(dy*dy+dx*dx);
297 //if (dy<0) planDiagL = -planDiagL;
298 //Double_t angleRotDiag = TMath::ATan(planDiagL/dz);
300 Double_t angleRot1 = -TMath::ATan2(dx,dy);
301 Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx);
302 Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz);
303 //--- (Calculate rotation of segment on the Z axis)
304 //-- Here I'm trying to calculate the rotation to be applied in
305 //-- order to match as closer as possible this segment and the
307 //-- It seems that some times it doesn't work ...
308 TGeoRotation rotTemp("",angleRot1*TMath::RadToDeg(),
309 angleRotDiag*TMath::RadToDeg(), rotation);
310 Double_t localX[3] = {0,1,0};
312 rotTemp.LocalToMasterVect(localX, globalX);
313 CopyFrom(localX, globalX);
314 GetCheckVect(localX, p2Vol, 0, fgkCableMaxNodeLevel+1, globalX);
315 Double_t orthVect[3];
316 GetCheckVect(vect1, p2Vol, 0, fgkCableMaxNodeLevel+1, orthVect);
317 // Double_t angleRotZ = 0;
319 // Double_t orthVectNorm2 = ScalProd(orthVect,orthVect);
320 // Double_t alpha1 = ScalProd(fPreviousX,orthVect)/orthVectNorm2;
321 // Double_t alpha2 = ScalProd(globalX,orthVect)/orthVectNorm2;
322 // Double_t globalX1p[3], globalX2p[3];
323 // globalX1p[0] = fPreviousX[0] - alpha1*orthVect[0];
324 // globalX1p[1] = fPreviousX[1] - alpha1*orthVect[1];
325 // globalX1p[2] = fPreviousX[2] - alpha1*orthVect[2];
326 // globalX2p[0] = globalX[0] - alpha2*orthVect[0];
327 // globalX2p[1] = globalX[1] - alpha2*orthVect[1];
328 // globalX2p[2] = globalX[2] - alpha2*orthVect[2];
329 // //-- now I'm searching the 3th vect which makes an orthogonal base
330 // //-- with orthVect and globalX1p ...
331 // Double_t nulVect[3] = {0,0,0};
332 // Double_t axis3[3];
333 // TMath::Normal2Plane(nulVect, orthVect, globalX1p, axis3);
334 // Double_t globalX1pNorm2 = ScalProd(globalX1p, globalX1p);
335 // Double_t beta = ScalProd(globalX2p, globalX1p)/globalX1pNorm2;
336 // Double_t gamma = ScalProd(globalX2p, axis3);
337 // angleRotZ = (TMath::ATan2(1,0) - TMath::ATan2(beta, gamma))
338 // *TMath::RadToDeg();
340 // cout << "!!!!!!!!!!!!!!!!!!! angle = " <<angleRotZ << endl;
341 CopyFrom(fPreviousX, globalX);
343 Double_t localVect1[3], localVect2[3];
344 TGeoRotation rot("",angleRot1*TMath::RadToDeg(),
345 angleRotDiag*TMath::RadToDeg(),
347 // rotation-angleRotZ);
348 // since angleRotZ doesn't always work, I won't use it ...
350 rot.MasterToLocalVect(vect1, localVect1);
351 rot.MasterToLocalVect(vect2, localVect2);
353 //=================================================
354 // Create the segment and add it to the mother volume
355 TGeoVolume *vCableSegB = CreateSegment(coord1, coord2,
356 localVect1, localVect2);
357 TGeoRotation rotArbSeg("", 0, 90, 0);
358 rotArbSeg.MultiplyBy(&rot, kFALSE);
359 TGeoTranslation trans("",cx, cy, cz);
360 TGeoCombiTrans *combiB = new TGeoCombiTrans(trans, rotArbSeg);
361 p2Vol->AddNode(vCableSegB, p2, combiB);
362 //=================================================;
365 printf("---\n Cable segment points : ");
366 printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]);
367 printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]);
370 // #include <TGeoSphere.h>
371 // TGeoMedium *airSDD = gGeoManager->GetMedium("ITS_AIR$");
372 // TGeoSphere *sphere = new TGeoSphere(0, 0.05);
373 // TGeoVolume *vSphere = new TGeoVolume("", sphere, airSDD);
374 // TGeoTranslation *trC = new TGeoTranslation("", cx, cy, cz);
375 // TGeoTranslation *tr1 = new TGeoTranslation("",coord1[0],
376 // coord1[1],coord1[2]);
377 // TGeoTranslation *tr2 = new TGeoTranslation("",coord2[0],
378 // coord2[1],coord2[2]);
379 // p2Vol->AddNode(vSphere, p2*3-2, trC);
380 // p2Vol->AddNode(vSphere, p2*3-1, tr1);
381 // p2Vol->AddNode(vSphere, p2*3 , tr2);
382 if (ct) *ct = combiB;
386 //________________________________________________________________________
387 TGeoVolume* AliITSv11GeomCableFlat::CreateAndInsertBoxCableSegment(Int_t p2,
391 // This function is to be use only when the segment has the shape
392 // of a simple box, i.e. the normal vector to its end is perpendicular
393 // to the segment own axis
394 // Creates a cable segment between points p1 and p2.
395 // Rotation is the eventual rotation of the flat cable
396 // along its length axis
398 // The segment volume is created inside the volume containing point2
399 // Therefore this segment should be defined in this volume only.
400 // I mean here that, if the previous point is in another volume,
401 // it should be just at the border between the 2 volumes. Also the
402 // orientation vector of the previous point should be orthogonal to
403 // the surface between the 2 volumes.
406 if (fInitialNode==0) {
407 TObjArray *nodes = gGeoManager->GetListOfNodes();
408 if (nodes->GetEntriesFast()==0) return 0;
409 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
411 mainNode = fInitialNode;
415 TGeoVolume *p2Vol = GetVolume(p2);
416 TGeoVolume *p1Vol = GetVolume(p1);
418 ResetCheckDaughter();
420 if (! CheckDaughter(mainNode)) {
421 printf("Error::volume containing point is not visible in node tree!\n");
425 Double_t coord1[3], coord2[3], vect1[3], vect2[3];
426 //=================================================
427 // Get p1 position in the systeme of p2
430 Int_t p1nodeInd[fgkCableMaxNodeLevel];
431 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i];
432 Int_t p1volLevel = 0;
433 while (p1nodeInd[p1volLevel]!=-1) p1volLevel++;
436 ResetCheckDaughter();
438 if (! CheckDaughter(mainNode)) {
439 printf("Error::volume containing point is not visible in node tree!\n");
442 Int_t p2nodeInd[fgkCableMaxNodeLevel];
443 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i];
444 Int_t commonMotherLevel = 0;
445 while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel])
448 Int_t p2volLevel = 0;
449 while (fNodeInd[p2volLevel]!=-1) p2volLevel++;
452 // Get coord and vect of p1 in the common mother reference system
453 if (! GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1) )
455 if (! GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1) )
458 // Translate them in the reference system of the volume containing p2
459 TGeoNode *pathNode[fgkCableMaxNodeLevel];
460 pathNode[0] = mainNode;
461 for (Int_t i=0; i<=p2volLevel; i++) {
462 pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]);
464 Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]};
465 Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]};
467 for (Int_t i = commonMotherLevel+1; i <= p2volLevel; i++) {
468 pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1);
469 pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1);
470 CopyFrom(globalCoord1, coord1);
471 CopyFrom(globalVect1, vect1);
474 if (! GetCheckPoint(p1, 0, 0, coord1) ) return 0;
475 if (! GetCheckVect(p1, 0, 0, vect1) ) return 0;
478 //=================================================
479 // Get p2 position in the systeme of p2
480 if (! GetCheckPoint(p2, 0, 0, coord2) ) return 0;
481 if (! GetCheckVect(p2, 0, 0, vect2) ) return 0;
483 Double_t cx = (coord1[0]+coord2[0])/2;
484 Double_t cy = (coord1[1]+coord2[1])/2;
485 Double_t cz = (coord1[2]+coord2[2])/2;
486 Double_t dx = coord2[0]-coord1[0];
487 Double_t dy = coord2[1]-coord1[1];
488 Double_t dz = coord2[2]-coord1[2];
490 //=================================================
491 // Positionning of the segment between the 2 points
492 if (TMath::Abs(dy)<1e-231) dy = 1e-231;
493 if (TMath::Abs(dz)<1e-231) dz = 1e-231;
494 //Double_t angleRot1 = -TMath::ATan(dx/dy);
495 //Double_t planDiagL = -TMath::Sqrt(dy*dy+dx*dx);
496 //if (dy<0) planDiagL = -planDiagL;
497 //Double_t angleRotDiag = TMath::ATan(planDiagL/dz);
499 Double_t angleRot1 = -TMath::ATan2(dx,dy);
500 Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx);
501 Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz);
502 //--- (Calculate rotation of segment on the Z axis)
503 //-- Here I'm trying to calculate the rotation to be applied in
504 //-- order to match as closer as possible this segment and the
506 //-- It seems that some times it doesn't work ...
507 TGeoRotation rotTemp("",angleRot1*TMath::RadToDeg(),
508 angleRotDiag*TMath::RadToDeg(), rotation);
509 Double_t localX[3] = {0,1,0};
511 rotTemp.LocalToMasterVect(localX, globalX);
512 CopyFrom(localX, globalX);
513 GetCheckVect(localX, p2Vol, 0, fgkCableMaxNodeLevel+1, globalX);
514 Double_t orthVect[3];
515 GetCheckVect(vect1, p2Vol, 0, fgkCableMaxNodeLevel+1, orthVect);
516 // Double_t angleRotZ = 0;
518 // Double_t orthVectNorm2 = ScalProd(orthVect,orthVect);
519 // Double_t alpha1 = ScalProd(fPreviousX,orthVect)/orthVectNorm2;
520 // Double_t alpha2 = ScalProd(globalX,orthVect)/orthVectNorm2;
521 // Double_t globalX1p[3], globalX2p[3];
522 // globalX1p[0] = fPreviousX[0] - alpha1*orthVect[0];
523 // globalX1p[1] = fPreviousX[1] - alpha1*orthVect[1];
524 // globalX1p[2] = fPreviousX[2] - alpha1*orthVect[2];
525 // globalX2p[0] = globalX[0] - alpha2*orthVect[0];
526 // globalX2p[1] = globalX[1] - alpha2*orthVect[1];
527 // globalX2p[2] = globalX[2] - alpha2*orthVect[2];
528 // //-- now I'm searching the 3th vect which makes an orthogonal base
529 // //-- with orthVect and globalX1p ...
530 // Double_t nulVect[3] = {0,0,0};
531 // Double_t axis3[3];
532 // TMath::Normal2Plane(nulVect, orthVect, globalX1p, axis3);
533 // Double_t globalX1pNorm2 = ScalProd(globalX1p, globalX1p);
534 // Double_t beta = ScalProd(globalX2p, globalX1p)/globalX1pNorm2;
535 // Double_t gamma = ScalProd(globalX2p, axis3);
536 // angleRotZ = (TMath::ATan2(1,0) - TMath::ATan2(beta, gamma))
537 // *TMath::RadToDeg();
539 CopyFrom(fPreviousX, globalX);
541 Double_t localVect1[3], localVect2[3];
542 TGeoRotation rot("",angleRot1*TMath::RadToDeg(),
543 angleRotDiag*TMath::RadToDeg(),
545 // rotation-angleRotZ);
546 // since angleRotZ doesn't always work, I won't use it ...
548 rot.MasterToLocalVect(vect1, localVect1);
549 rot.MasterToLocalVect(vect2, localVect2);
551 //=================================================
552 // Create the segment and add it to the mother volume
553 TGeoVolume *vCableSegB = CreateBoxSegment(coord1, coord2);
555 TGeoRotation rotArbSeg("", 0, 90, 0);
556 rotArbSeg.MultiplyBy(&rot, kFALSE);
557 TGeoTranslation trans("",cx, cy, cz);
558 TGeoCombiTrans *combiB = new TGeoCombiTrans(trans, rotArbSeg);
559 p2Vol->AddNode(vCableSegB, p2, combiB);
560 //=================================================;
563 printf("---\n Cable segment points : ");
564 printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]);
565 printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]);
568 if (ct) *ct = combiB;
572 //________________________________________________________________________
573 TGeoVolume* AliITSv11GeomCableFlat::CreateAndInsertCableCylSegment(Int_t p2,
577 // Create a flat cable segment with a curvature between points p1 and p2.
578 // The radius and position of the curve is defined by the
579 // perpendicular vector of point p2 (the orientation of this vector
580 // and the position of the 2 check points are enough to completely
582 // Rotation is the eventual rotation of the flat cable
583 // along its length axis
587 if (fInitialNode==0) {
588 TObjArray *nodes = gGeoManager->GetListOfNodes();
589 if (nodes->GetEntriesFast()==0) return 0;
590 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
592 mainNode = fInitialNode;
596 TGeoVolume *p1Vol = GetVolume(p1);
597 TGeoVolume *p2Vol = GetVolume(p2);
599 ResetCheckDaughter();
601 if (! CheckDaughter(mainNode)) {
602 printf("Error::volume containing point is not visible in node tree!\n");
606 Double_t coord1[3], coord2[3], vect1[3], vect2[3];
607 //=================================================
608 // Get p1 position in the systeme of p2
611 Int_t p1nodeInd[fgkCableMaxNodeLevel];
612 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i];
613 Int_t p1volLevel = 0;
614 while (p1nodeInd[p1volLevel]!=-1) p1volLevel++;
617 ResetCheckDaughter();
619 if (! CheckDaughter(mainNode)) {
620 printf("Error::volume containing point is not visible in node tree!\n");
623 Int_t p2nodeInd[fgkCableMaxNodeLevel];
624 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i];
625 Int_t commonMotherLevel = 0;
626 while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel])
629 Int_t p2volLevel = 0;
630 while (fNodeInd[p2volLevel]!=-1) p2volLevel++;
633 // Get coord and vect of p1 in the common mother reference system
634 GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1);
635 GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1);
636 // Translate them in the reference system of the volume containing p2
637 TGeoNode *pathNode[fgkCableMaxNodeLevel];
638 pathNode[0] = mainNode;
639 for (Int_t i=0; i<=p2volLevel; i++) {
640 pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]);
642 Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]};
643 Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]};
645 for (Int_t i = commonMotherLevel+1; i<=p2volLevel; i++) {
646 pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1);
647 pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1);
648 CopyFrom(globalCoord1, coord1);
649 CopyFrom(globalVect1, vect1);
652 GetCheckPoint(p1, 0, 0, coord1);
653 GetCheckVect(p1, 0, 0, vect1);
656 //=================================================
657 // Get p2 position in the systeme of p2
658 GetCheckPoint(p2, 0, 0, coord2);
659 GetCheckVect(p2, 0, 0, vect2);
661 Double_t cx = (coord1[0]+coord2[0])/2;
662 Double_t cy = (coord1[1]+coord2[1])/2;
663 Double_t cz = (coord1[2]+coord2[2])/2;
664 Double_t dx = coord2[0]-coord1[0];
665 Double_t dy = coord2[1]-coord1[1];
666 Double_t dz = coord2[2]-coord1[2];
667 Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz);
669 //=================================================
670 // Positionning of the segment between the 2 points
671 if ((dy<1e-31)&&(dy>0)) dy = 1e-31;
672 if ((dz<1e-31)&&(dz>0)) dz = 1e-31;
673 if ((dy>-1e-31)&&(dy<0)) dy = -1e-31;
674 if ((dz>-1e-31)&&(dz<0)) dz = -1e-31;
676 Double_t angleRot1 = -TMath::ATan2(dx,dy);
677 Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx);
678 Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz);
680 TGeoRotation rotTorusTemp("",angleRot1*TMath::RadToDeg(),
681 angleRotDiag*TMath::RadToDeg(),0);
682 TGeoRotation rotTorusToZ("",0,90,0);
683 rotTorusTemp.MultiplyBy(&rotTorusToZ, kTRUE);
684 Double_t localVect2[3];
685 rotTorusTemp.MasterToLocalVect(vect2, localVect2);
686 if (localVect2[1]<0) {
687 localVect2[0] = -localVect2[0];
688 localVect2[1] = -localVect2[1];
689 localVect2[2] = -localVect2[2];
691 Double_t normVect2 = TMath::Sqrt(localVect2[0]*localVect2[0]+
692 localVect2[1]*localVect2[1]+
693 localVect2[2]*localVect2[2]);
694 Double_t axisX[3] = {1,0,0};
695 Double_t cosangleTorusSeg = (localVect2[0]*axisX[0]+
696 localVect2[1]*axisX[1]+
697 localVect2[2]*axisX[2])/normVect2;
698 Double_t angleTorusSeg = TMath::ACos(cosangleTorusSeg)*TMath::RadToDeg();
699 TGeoRotation rotTorus("",angleRot1*TMath::RadToDeg(),
700 angleRotDiag*TMath::RadToDeg(),
701 45-angleTorusSeg+rotation);
702 //180-angleTorusSeg+rotation);
703 rotTorus.MultiplyBy(&rotTorusToZ, kTRUE);
704 rotTorus.MasterToLocalVect(vect2, localVect2);
705 if (localVect2[1]<0) {
706 localVect2[0] = -localVect2[0];
707 localVect2[1] = -localVect2[1];
708 localVect2[2] = -localVect2[2];
710 normVect2 = TMath::Sqrt(localVect2[0]*localVect2[0]+
711 localVect2[1]*localVect2[1]+
712 localVect2[2]*localVect2[2]);
713 Double_t axisY[3] = {0,1,0};
714 Double_t cosPhi = (localVect2[0]*axisY[0]+localVect2[1]*axisY[1]+
715 localVect2[2]*axisY[2])/normVect2;
716 Double_t torusPhi1 = TMath::ACos(cosPhi);
717 Double_t torusR = (length/2)/TMath::Sin(torusPhi1);
718 torusPhi1 = torusPhi1*TMath::RadToDeg();
719 Double_t perpLength = TMath::Sqrt((torusR-0.5*length)*(torusR+0.5*length));
720 Double_t localTransT[3] = {-perpLength,0,0};
721 Double_t globalTransT[3];
722 rotTorus.LocalToMasterVect(localTransT, globalTransT);
723 TGeoTranslation transTorus("",cx+globalTransT[0],cy+globalTransT[1],
726 TGeoCombiTrans *combiTorus = new TGeoCombiTrans(transTorus, rotTorus);
728 //=================================================
729 // Create the segment and add it to the mother volume
730 TGeoVolume *vCableSegT = CreateCylSegment(torusPhi1, torusR);
731 p2Vol->AddNode(vCableSegT, p2, combiTorus);
734 printf("---\n Cable segment points : ");
735 printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]);
736 printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]);
739 if (ct) *ct = combiTorus;
743 //________________________________________________________________________
744 TGeoVolume *AliITSv11GeomCableFlat::CreateSegment( const Double_t *coord1,
745 const Double_t *coord2,
746 const Double_t *localVect1,
747 const Double_t *localVect2 )
749 // Create a segment with arbitrary vertices (general case)
750 //=================================================
751 // Calculate segment "deformation"
752 Double_t dx = coord2[0]-coord1[0];
753 Double_t dy = coord2[1]-coord1[1];
754 Double_t dz = coord2[2]-coord1[2];
755 Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz);
757 Double_t cosTheta1 = -1./TMath::Sqrt( 1 + localVect1[0]*localVect1[0]
758 /localVect1[2]/localVect1[2] );
759 Double_t cosTheta2 = 1./TMath::Sqrt( 1 + localVect2[0]*localVect2[0]
760 /localVect2[2]/localVect2[2] );
761 if (localVect1[2]<0) cosTheta1 = -cosTheta1;
762 if (localVect2[2]<0) cosTheta2 = -cosTheta2;
764 Double_t dL1 = 0.5*fWidth*TMath::Tan(TMath::ACos(cosTheta1));
765 Double_t dL2 = 0.5*fWidth*TMath::Tan(TMath::ACos(cosTheta2));
766 if (localVect1[0]<0) dL1 = - dL1;
767 if (localVect2[0]<0) dL2 = - dL2;
769 Double_t cosPhi1 = -1./TMath::Sqrt( 1 + localVect1[1]*localVect1[1]
770 /localVect1[2]/localVect1[2] );
771 Double_t cosPhi2 = 1./TMath::Sqrt( 1 + localVect2[1]*localVect2[1]
772 /localVect2[2]/localVect2[2] );
773 if (localVect1[2]<0) cosPhi1 = -cosPhi1;
774 if (localVect2[2]<0) cosPhi2 = -cosPhi2;
776 Double_t tanACosCosPhi1 = TMath::Tan(TMath::ACos(cosPhi1));
777 Double_t tanACosCosPhi2 = TMath::Tan(TMath::ACos(cosPhi2));
778 if (localVect1[1]<0) tanACosCosPhi1 = -tanACosCosPhi1;
779 if (localVect2[1]<0) tanACosCosPhi2 = -tanACosCosPhi2;
781 Double_t dl1 = 0.5*fThick*tanACosCosPhi1*0.99999999999999;
782 Double_t dl2 = 0.5*fThick*tanACosCosPhi2*0.99999999999999;
783 // 0.9999999999999 is for correcting problems in TGeo...
784 //=================================================
785 // Create the segment
786 TGeoArb8 *cableSeg = new TGeoArb8(fThick/2);
787 cableSeg->SetVertex( 0, -fWidth/2, -length/2 - dL1 + dl1);
788 cableSeg->SetVertex( 1, -fWidth/2, length/2 + dL2 - dl2);
789 cableSeg->SetVertex( 2, fWidth/2, length/2 - dL2 - dl2);
790 cableSeg->SetVertex( 3, fWidth/2, -length/2 + dL1 + dl1);
791 cableSeg->SetVertex( 4, -fWidth/2, -length/2 - dL1 - dl1);
792 cableSeg->SetVertex( 5, -fWidth/2, length/2 + dL2 + dl2);
793 cableSeg->SetVertex( 6, fWidth/2, length/2 - dL2 + dl2);
794 cableSeg->SetVertex( 7, fWidth/2, -length/2 + dL1 - dl1);
796 TGeoVolume *vCableSeg = new TGeoVolume(GetName(), cableSeg, fLayMedia[fNlayer-1]);
797 vCableSeg->SetLineColor(fLayColor[fNlayer-1]);
799 // add all cable layers but the last
800 for (Int_t iLay=0; iLay<fNlayer-1; iLay++) {
802 Double_t dl1Lay = 0.5*fLayThickness[iLay]*tanACosCosPhi1;
803 Double_t dl2Lay = 0.5*fLayThickness[iLay]*tanACosCosPhi2;
805 Double_t ztr = -fThick/2;
806 for (Int_t i=0;i<iLay; i++) ztr+= fLayThickness[i];
807 ztr+= fLayThickness[iLay]/2;
809 Double_t dl1LayS = ztr*tanACosCosPhi1;
810 Double_t dl2LayS = ztr*tanACosCosPhi2;
812 TGeoArb8 *lay = new TGeoArb8(fLayThickness[iLay]/2);
813 lay->SetVertex( 0, -fWidth/2, -length/2 - dL1 + dl1Lay - dl1LayS);
814 lay->SetVertex( 1, -fWidth/2, length/2 + dL2 - dl2Lay + dl2LayS);
815 lay->SetVertex( 2, fWidth/2, length/2 - dL2 - dl2Lay + dl2LayS);
816 lay->SetVertex( 3, fWidth/2, -length/2 + dL1 + dl1Lay - dl1LayS);
817 lay->SetVertex( 4, -fWidth/2, -length/2 - dL1 - dl1Lay - dl1LayS);
818 lay->SetVertex( 5, -fWidth/2, length/2 + dL2 + dl2Lay + dl2LayS);
819 lay->SetVertex( 6, fWidth/2, length/2 - dL2 + dl2Lay + dl2LayS);
820 lay->SetVertex( 7, fWidth/2, -length/2 + dL1 - dl1Lay - dl1LayS);
821 TGeoVolume *vLay = new TGeoVolume("vCableSegLay", lay, fLayMedia[iLay]);
822 vLay->SetLineColor(fLayColor[iLay]);
824 if (fTranslation[iLay]==0)
825 fTranslation[iLay] = new TGeoTranslation(0, 0, ztr);
826 vCableSeg->AddNode(vLay, iLay+1, fTranslation[iLay]);
829 //vCableSeg->SetVisibility(kFALSE);
833 //________________________________________________________________________
834 TGeoVolume *AliITSv11GeomCableFlat::CreateCylSegment(const Double_t &phi,
837 // Create a segment in shape of a cylinder, allows to represent
838 // a folded flat cable
840 Double_t phi1 = 360-phi;
841 Double_t phi2 = 360+phi;
843 Double_t rMin = r-fThick/2;
844 Double_t rMax = r+fThick/2;
845 //=================================================
846 // Create the segment
848 TGeoTubeSeg *cableSeg = new TGeoTubeSeg(rMin, rMax, fWidth/2,
850 TGeoVolume *vCableSeg = new TGeoVolume(GetName(), cableSeg, fLayMedia[fNlayer-1]);
851 vCableSeg->SetLineColor(fLayColor[fNlayer-1]);
853 // add all cable layers but the last
854 for (Int_t iLay=0; iLay<fNlayer-1; iLay++) {
856 Double_t ztr = -fThick/2;
857 for (Int_t i=0;i<iLay; i++) ztr+= fLayThickness[i];
860 rMax = r + ztr + fLayThickness[iLay];
861 TGeoTubeSeg *lay = new TGeoTubeSeg(rMin, rMax, fWidth/2,
864 TGeoVolume *vLay = new TGeoVolume("vCableSegLay", lay, fLayMedia[iLay]);
865 vLay->SetLineColor(fLayColor[iLay]);
867 vCableSeg->AddNode(vLay, iLay+1, 0);
870 //vCableSeg->SetVisibility(kFALSE);
874 //________________________________________________________________________
875 TGeoVolume *AliITSv11GeomCableFlat::CreateBoxSegment( const Double_t *coord1,
876 const Double_t *coord2)
878 // Create a segment for the case it is a simple box
879 //=================================================
880 Double_t dx = coord2[0]-coord1[0];
881 Double_t dy = coord2[1]-coord1[1];
882 Double_t dz = coord2[2]-coord1[2];
883 Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz);
885 TGeoBBox *cableSeg = new TGeoBBox(fWidth/2, length/2, fThick/2);
886 TGeoVolume *vCableSeg = new TGeoVolume(GetName(), cableSeg, fLayMedia[fNlayer-1]);
887 vCableSeg->SetLineColor(fLayColor[fNlayer-1]);
888 // This volume is the cable container. It codes also the material for the
891 // add all cable layers but the last one
892 for (Int_t iLay=0; iLay<fNlayer-1; iLay++) {
894 Double_t ztr = -fThick/2;
895 for (Int_t i=0;i<iLay; i++) ztr+= fLayThickness[i];
896 ztr+= fLayThickness[iLay]/2;
898 TGeoBBox *lay = new TGeoBBox(fWidth/2, length/2, fLayThickness[iLay]/2);
900 TGeoVolume *vLay = new TGeoVolume("vCableSegLay", lay, fLayMedia[iLay]);
901 vLay->SetLineColor(fLayColor[iLay]);
903 if (fTranslation[iLay]==0)
904 fTranslation[iLay] = new TGeoTranslation(0, 0, ztr);
905 vCableSeg->AddNode(vLay, iLay+1, fTranslation[iLay]);
908 //vCableSeg->SetVisibility(kFALSE);
912 //________________________________________________________________________
913 void AliITSv11GeomCableFlat::SetNLayers(Int_t nLayers) {
914 // Set the number of layers
915 if((nLayers>0) &&(nLayers<=fgkCableMaxLayer)) {
918 for (Int_t i=0; i<fgkCableMaxLayer ; i++) {
919 fLayThickness[i] = 0;
927 //________________________________________________________________________
928 Int_t AliITSv11GeomCableFlat::SetLayer(Int_t nLayer, Double_t thick,
929 TGeoMedium *medium, Int_t color) {
930 // Set the layer number nLayer
931 if ((nLayer<0)||(nLayer>=fNlayer)) {
932 printf("Set wrong layer number of the cable\n");
936 if (fLayThickness[nLayer-1]<=0) {
937 printf("AliITSv11GeomCableFlat::SetLayer():"
938 " You must define cable layer %i first !",nLayer-1);
942 Double_t thickTot = 0;
943 for (Int_t i=0; i<nLayer; i++) thickTot += fLayThickness[i];
945 if (thickTot-1e-10>fThick) {
946 printf("Can't add this layer, cable thickness would be higher than total\n");
950 fLayThickness[nLayer] = thick;
951 fLayMedia[nLayer] = medium;
952 fLayColor[nLayer] = color;
953 fTranslation[nLayer] = 0;