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 **************************************************************************/
17 //*************************************************************************
18 // Class for flat cables
20 // Ludovic Gaudichet gaudichet@to.infn.it
21 //*************************************************************************
25 // General Root includes
26 //#include <Riostream.h>
30 // Root Geometry includes
31 #include <TGeoManager.h>
32 #include <TGeoVolume.h>
35 #include <TGeoMatrix.h>
38 #include "AliITSv11GeomCableFlat.h"
41 ClassImp(AliITSv11GeomCableFlat)
43 //________________________________________________________________________
44 AliITSv11GeomCableFlat::AliITSv11GeomCableFlat():
51 for (Int_t i=0; i<fgkCableMaxLayer ; i++) {
59 //________________________________________________________________________
60 AliITSv11GeomCableFlat::
61 AliITSv11GeomCableFlat(const char* name, Double_t width, Double_t thick) :
62 AliITSv11GeomCable(name),
67 // standard constructor
68 for (Int_t i=0; i<fgkCableMaxLayer ; i++) {
76 //________________________________________________________________________
77 AliITSv11GeomCableFlat::AliITSv11GeomCableFlat(const AliITSv11GeomCableFlat &s) :
78 AliITSv11GeomCable(s),fWidth(s.fWidth),fThick(s.fThick),fNlayer(s.fNlayer)
81 for (Int_t i=0; i<s.fNlayer; i++) {
82 fLayThickness[i] = s.fLayThickness[i];
83 fTranslation[i] = s.fTranslation[i];
84 fLayMedia[i] = s.fLayMedia[i];
85 fLayColor[i] = s.fLayColor[i];
89 //________________________________________________________________________
90 AliITSv11GeomCableFlat& AliITSv11GeomCableFlat::
91 operator=(const AliITSv11GeomCableFlat &s) {
92 // Assignment operator
93 // Not fully inplemented yet !!!
95 if(&s == this) return *this;
100 for (Int_t i=0; i<s.fNlayer; i++) {
101 fLayThickness[i] = s.fLayThickness[i];
102 fTranslation[i] = s.fTranslation[i];
103 fLayMedia[i] = s.fLayMedia[i];
104 fLayColor[i] = s.fLayColor[i];
109 //________________________________________________________________________
110 Int_t AliITSv11GeomCableFlat::GetPoint( Int_t iCheckPt, Double_t *coord)
112 // Get the correct point #iCheckPt
113 TVectorD *coordVector =(TVectorD *)fPointArray.At(2*iCheckPt);
115 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
116 CopyFrom(coord, coordVector->GetElements());
118 CopyFrom(coord, coordVector->GetMatrixArray());
126 //________________________________________________________________________
127 Int_t AliITSv11GeomCableFlat::GetVect( Int_t iCheckPt, Double_t *coord)
129 // Get the correct vect corresponding to point #iCheckPt
131 TVectorD *coordVector =(TVectorD *)fPointArray.At(2*iCheckPt+1);
133 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
134 CopyFrom(coord, coordVector->GetElements());
136 CopyFrom(coord, coordVector->GetMatrixArray());
144 //________________________________________________________________________
145 void AliITSv11GeomCableFlat::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt,
146 Double_t *coord, Double_t *orthVect)
149 // Add a check point. In the fPointArray, the point is at i and its vector
153 // if (iCheckPt>=fVolumeArray.GetEntriesFast()) {
154 // fVolumeArray.AddLast(vol);
155 // TVectorD *point = new TVectorD(3,coord);
156 // TVectorD *vect = new TVectorD(3,orthVect);
157 // fPointArray.AddLast(point);
158 // fPointArray.AddLast(vect);
160 // } else if ((iCheckPt >= 0)&&(iCheckPt < fVolumeArray.GetEntriesFast())) {
161 // fVolumeArray.AddAt(vol, iCheckPt);
162 // TVectorD *point = new TVectorD(3,coord);
163 // TVectorD *vect = new TVectorD(3,orthVect);
164 // fPointArray.AddAt(point, iCheckPt*2 );
165 // fPointArray.AddAt(vect, iCheckPt*2+1);
167 fVolumeArray.AddAtAndExpand(vol, iCheckPt);
168 TVectorD *point = new TVectorD(3,coord);
169 TVectorD *vect = new TVectorD(3,orthVect);
170 fPointArray.AddAtAndExpand(point, iCheckPt*2 );
171 fPointArray.AddAtAndExpand(vect, iCheckPt*2+1);
174 //________________________________________________________________________
175 void AliITSv11GeomCableFlat::PrintCheckPoints() const {
176 // print all check points of the cable
177 printf(" ---\n Printing all check points of the flat cable\n");
178 for (Int_t i = 0; i<fVolumeArray.GetEntriesFast(); i++) {
180 if (GetPoint( i, coord))
181 printf(" ( %.2f, %.2f, %.2f )\n", coord[0], coord[1], coord[2]);
185 //________________________________________________________________________
186 TGeoVolume* AliITSv11GeomCableFlat::CreateAndInsertCableSegment(Int_t p2,
190 // Creates a cable segment between points p1 and p2.
191 // Rotation is the eventual rotation of the flat cable
192 // along its length axis
194 // The segment volume is created inside the volume containing point2
195 // Therefore this segment should be defined in this volume only.
196 // I mean here that, if the previous point is in another volume,
197 // it should be just at the border between the 2 volumes. Also the
198 // orientation vector of the previous point should be orthogonal to
199 // the surface between the 2 volumes.
202 if (fInitialNode==0) {
203 TObjArray *nodes = gGeoManager->GetListOfNodes();
204 if (nodes->GetEntriesFast()==0) return 0;
205 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
207 mainNode = fInitialNode;
211 TGeoVolume *p2Vol = GetVolume(p2);
212 TGeoVolume *p1Vol = GetVolume(p1);
214 ResetCheckDaughter();
216 if (! CheckDaughter(mainNode)) {
217 printf("Error::volume containing point is not visible in node tree!\n");
221 Double_t coord1[3], coord2[3], vect1[3], vect2[3];
222 //=================================================
223 // Get p1 position in the systeme of p2
226 Int_t p1nodeInd[fgkCableMaxNodeLevel];
227 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i];
228 Int_t p1volLevel = 0;
229 while (p1nodeInd[p1volLevel]!=-1) p1volLevel++;
232 ResetCheckDaughter();
234 if (! CheckDaughter(mainNode)) {
235 printf("Error::volume containing point is not visible in node tree!\n");
238 Int_t p2nodeInd[fgkCableMaxNodeLevel];
239 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i];
240 Int_t commonMotherLevel = 0;
241 while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel])
244 Int_t p2volLevel = 0;
245 while (fNodeInd[p2volLevel]!=-1) p2volLevel++;
248 // Get coord and vect of p1 in the common mother reference system
249 if (! GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1) )
251 if (! GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1) )
254 // Translate them in the reference system of the volume containing p2
255 TGeoNode *pathNode[fgkCableMaxNodeLevel];
256 pathNode[0] = mainNode;
257 for (Int_t i=0; i<=p2volLevel; i++) {
258 pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]);
260 Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]};
261 Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]};
263 for (Int_t i = commonMotherLevel+1; i <= p2volLevel; i++) {
264 pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1);
265 pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1);
266 CopyFrom(globalCoord1, coord1);
267 CopyFrom(globalVect1, vect1);
270 if (! GetCheckPoint(p1, 0, 0, coord1) ) return 0;
271 if (! GetCheckVect(p1, 0, 0, vect1) ) return 0;
274 //=================================================
275 // Get p2 position in the systeme of p2
276 if (! GetCheckPoint(p2, 0, 0, coord2) ) return 0;
277 if (! GetCheckVect(p2, 0, 0, vect2) ) return 0;
279 Double_t cx = (coord1[0]+coord2[0])/2;
280 Double_t cy = (coord1[1]+coord2[1])/2;
281 Double_t cz = (coord1[2]+coord2[2])/2;
282 Double_t dx = coord2[0]-coord1[0];
283 Double_t dy = coord2[1]-coord1[1];
284 Double_t dz = coord2[2]-coord1[2];
286 //=================================================
287 // Positionning of the segment between the 2 points
288 if (TMath::Abs(dy)<1e-231) dy = 1e-231;
289 if (TMath::Abs(dz)<1e-231) dz = 1e-231;
290 //Double_t angleRot1 = -TMath::ATan(dx/dy);
291 //Double_t planDiagL = -TMath::Sqrt(dy*dy+dx*dx);
292 //if (dy<0) planDiagL = -planDiagL;
293 //Double_t angleRotDiag = TMath::ATan(planDiagL/dz);
295 Double_t angleRot1 = -TMath::ATan2(dx,dy);
296 Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx);
297 Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz);
298 //--- (Calculate rotation of segment on the Z axis)
299 //-- Here I'm trying to calculate the rotation to be applied in
300 //-- order to match as closer as possible this segment and the
302 //-- It seems that some times it doesn't work ...
303 TGeoRotation rotTemp("",angleRot1*TMath::RadToDeg(),
304 angleRotDiag*TMath::RadToDeg(), rotation);
305 Double_t localX[3] = {0,1,0};
307 rotTemp.LocalToMasterVect(localX, globalX);
308 CopyFrom(localX, globalX);
309 GetCheckVect(localX, p2Vol, 0, fgkCableMaxNodeLevel+1, globalX);
310 Double_t orthVect[3];
311 GetCheckVect(vect1, p2Vol, 0, fgkCableMaxNodeLevel+1, orthVect);
312 // Double_t angleRotZ = 0;
314 // Double_t orthVectNorm2 = ScalProd(orthVect,orthVect);
315 // Double_t alpha1 = ScalProd(fPreviousX,orthVect)/orthVectNorm2;
316 // Double_t alpha2 = ScalProd(globalX,orthVect)/orthVectNorm2;
317 // Double_t globalX1p[3], globalX2p[3];
318 // globalX1p[0] = fPreviousX[0] - alpha1*orthVect[0];
319 // globalX1p[1] = fPreviousX[1] - alpha1*orthVect[1];
320 // globalX1p[2] = fPreviousX[2] - alpha1*orthVect[2];
321 // globalX2p[0] = globalX[0] - alpha2*orthVect[0];
322 // globalX2p[1] = globalX[1] - alpha2*orthVect[1];
323 // globalX2p[2] = globalX[2] - alpha2*orthVect[2];
324 // //-- now I'm searching the 3th vect which makes an orthogonal base
325 // //-- with orthVect and globalX1p ...
326 // Double_t nulVect[3] = {0,0,0};
327 // Double_t axis3[3];
328 // TMath::Normal2Plane(nulVect, orthVect, globalX1p, axis3);
329 // Double_t globalX1pNorm2 = ScalProd(globalX1p, globalX1p);
330 // Double_t beta = ScalProd(globalX2p, globalX1p)/globalX1pNorm2;
331 // Double_t gamma = ScalProd(globalX2p, axis3);
332 // angleRotZ = (TMath::ATan2(1,0) - TMath::ATan2(beta, gamma))
333 // *TMath::RadToDeg();
335 // cout << "!!!!!!!!!!!!!!!!!!! angle = " <<angleRotZ << endl;
336 CopyFrom(fPreviousX, globalX);
338 Double_t localVect1[3], localVect2[3];
339 TGeoRotation rot("",angleRot1*TMath::RadToDeg(),
340 angleRotDiag*TMath::RadToDeg(),
342 // rotation-angleRotZ);
343 // since angleRotZ doesn't always work, I won't use it ...
345 rot.MasterToLocalVect(vect1, localVect1);
346 rot.MasterToLocalVect(vect2, localVect2);
348 //=================================================
349 // Create the segment and add it to the mother volume
350 TGeoVolume *vCableSegB = CreateSegment(coord1, coord2,
351 localVect1, localVect2);
352 TGeoRotation rotArbSeg("", 0, 90, 0);
353 rotArbSeg.MultiplyBy(&rot, kFALSE);
354 TGeoTranslation trans("",cx, cy, cz);
355 TGeoCombiTrans *combiB = new TGeoCombiTrans(trans, rotArbSeg);
356 p2Vol->AddNode(vCableSegB, p2, combiB);
357 //=================================================;
360 printf("---\n Cable segment points : ");
361 printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]);
362 printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]);
365 // #include <TGeoSphere.h>
366 // TGeoMedium *airSDD = gGeoManager->GetMedium("ITS_AIR$");
367 // TGeoSphere *sphere = new TGeoSphere(0, 0.05);
368 // TGeoVolume *vSphere = new TGeoVolume("", sphere, airSDD);
369 // TGeoTranslation *trC = new TGeoTranslation("", cx, cy, cz);
370 // TGeoTranslation *tr1 = new TGeoTranslation("",coord1[0],
371 // coord1[1],coord1[2]);
372 // TGeoTranslation *tr2 = new TGeoTranslation("",coord2[0],
373 // coord2[1],coord2[2]);
374 // p2Vol->AddNode(vSphere, p2*3-2, trC);
375 // p2Vol->AddNode(vSphere, p2*3-1, tr1);
376 // p2Vol->AddNode(vSphere, p2*3 , tr2);
377 if (ct) *ct = combiB;
381 //________________________________________________________________________
382 TGeoVolume* AliITSv11GeomCableFlat::CreateAndInsertBoxCableSegment(Int_t p2,
386 // This function is to be use only when the segment has the shape
387 // of a simple box, i.e. the normal vector to its end is perpendicular
388 // to the segment own axis
389 // Creates a cable segment between points p1 and p2.
390 // Rotation is the eventual rotation of the flat cable
391 // along its length axis
393 // The segment volume is created inside the volume containing point2
394 // Therefore this segment should be defined in this volume only.
395 // I mean here that, if the previous point is in another volume,
396 // it should be just at the border between the 2 volumes. Also the
397 // orientation vector of the previous point should be orthogonal to
398 // the surface between the 2 volumes.
401 if (fInitialNode==0) {
402 TObjArray *nodes = gGeoManager->GetListOfNodes();
403 if (nodes->GetEntriesFast()==0) return 0;
404 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
406 mainNode = fInitialNode;
410 TGeoVolume *p2Vol = GetVolume(p2);
411 TGeoVolume *p1Vol = GetVolume(p1);
413 ResetCheckDaughter();
415 if (! CheckDaughter(mainNode)) {
416 printf("Error::volume containing point is not visible in node tree!\n");
420 Double_t coord1[3], coord2[3], vect1[3], vect2[3];
421 //=================================================
422 // Get p1 position in the systeme of p2
425 Int_t p1nodeInd[fgkCableMaxNodeLevel];
426 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i];
427 Int_t p1volLevel = 0;
428 while (p1nodeInd[p1volLevel]!=-1) p1volLevel++;
431 ResetCheckDaughter();
433 if (! CheckDaughter(mainNode)) {
434 printf("Error::volume containing point is not visible in node tree!\n");
437 Int_t p2nodeInd[fgkCableMaxNodeLevel];
438 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i];
439 Int_t commonMotherLevel = 0;
440 while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel])
443 Int_t p2volLevel = 0;
444 while (fNodeInd[p2volLevel]!=-1) p2volLevel++;
447 // Get coord and vect of p1 in the common mother reference system
448 if (! GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1) )
450 if (! GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1) )
453 // Translate them in the reference system of the volume containing p2
454 TGeoNode *pathNode[fgkCableMaxNodeLevel];
455 pathNode[0] = mainNode;
456 for (Int_t i=0; i<=p2volLevel; i++) {
457 pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]);
459 Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]};
460 Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]};
462 for (Int_t i = commonMotherLevel+1; i <= p2volLevel; i++) {
463 pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1);
464 pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1);
465 CopyFrom(globalCoord1, coord1);
466 CopyFrom(globalVect1, vect1);
469 if (! GetCheckPoint(p1, 0, 0, coord1) ) return 0;
470 if (! GetCheckVect(p1, 0, 0, vect1) ) return 0;
473 //=================================================
474 // Get p2 position in the systeme of p2
475 if (! GetCheckPoint(p2, 0, 0, coord2) ) return 0;
476 if (! GetCheckVect(p2, 0, 0, vect2) ) return 0;
478 Double_t cx = (coord1[0]+coord2[0])/2;
479 Double_t cy = (coord1[1]+coord2[1])/2;
480 Double_t cz = (coord1[2]+coord2[2])/2;
481 Double_t dx = coord2[0]-coord1[0];
482 Double_t dy = coord2[1]-coord1[1];
483 Double_t dz = coord2[2]-coord1[2];
485 //=================================================
486 // Positionning of the segment between the 2 points
487 if (TMath::Abs(dy)<1e-231) dy = 1e-231;
488 if (TMath::Abs(dz)<1e-231) dz = 1e-231;
489 //Double_t angleRot1 = -TMath::ATan(dx/dy);
490 //Double_t planDiagL = -TMath::Sqrt(dy*dy+dx*dx);
491 //if (dy<0) planDiagL = -planDiagL;
492 //Double_t angleRotDiag = TMath::ATan(planDiagL/dz);
494 Double_t angleRot1 = -TMath::ATan2(dx,dy);
495 Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx);
496 Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz);
497 //--- (Calculate rotation of segment on the Z axis)
498 //-- Here I'm trying to calculate the rotation to be applied in
499 //-- order to match as closer as possible this segment and the
501 //-- It seems that some times it doesn't work ...
502 TGeoRotation rotTemp("",angleRot1*TMath::RadToDeg(),
503 angleRotDiag*TMath::RadToDeg(), rotation);
504 Double_t localX[3] = {0,1,0};
506 rotTemp.LocalToMasterVect(localX, globalX);
507 CopyFrom(localX, globalX);
508 GetCheckVect(localX, p2Vol, 0, fgkCableMaxNodeLevel+1, globalX);
509 Double_t orthVect[3];
510 GetCheckVect(vect1, p2Vol, 0, fgkCableMaxNodeLevel+1, orthVect);
511 // Double_t angleRotZ = 0;
513 // Double_t orthVectNorm2 = ScalProd(orthVect,orthVect);
514 // Double_t alpha1 = ScalProd(fPreviousX,orthVect)/orthVectNorm2;
515 // Double_t alpha2 = ScalProd(globalX,orthVect)/orthVectNorm2;
516 // Double_t globalX1p[3], globalX2p[3];
517 // globalX1p[0] = fPreviousX[0] - alpha1*orthVect[0];
518 // globalX1p[1] = fPreviousX[1] - alpha1*orthVect[1];
519 // globalX1p[2] = fPreviousX[2] - alpha1*orthVect[2];
520 // globalX2p[0] = globalX[0] - alpha2*orthVect[0];
521 // globalX2p[1] = globalX[1] - alpha2*orthVect[1];
522 // globalX2p[2] = globalX[2] - alpha2*orthVect[2];
523 // //-- now I'm searching the 3th vect which makes an orthogonal base
524 // //-- with orthVect and globalX1p ...
525 // Double_t nulVect[3] = {0,0,0};
526 // Double_t axis3[3];
527 // TMath::Normal2Plane(nulVect, orthVect, globalX1p, axis3);
528 // Double_t globalX1pNorm2 = ScalProd(globalX1p, globalX1p);
529 // Double_t beta = ScalProd(globalX2p, globalX1p)/globalX1pNorm2;
530 // Double_t gamma = ScalProd(globalX2p, axis3);
531 // angleRotZ = (TMath::ATan2(1,0) - TMath::ATan2(beta, gamma))
532 // *TMath::RadToDeg();
534 CopyFrom(fPreviousX, globalX);
536 Double_t localVect1[3], localVect2[3];
537 TGeoRotation rot("",angleRot1*TMath::RadToDeg(),
538 angleRotDiag*TMath::RadToDeg(),
540 // rotation-angleRotZ);
541 // since angleRotZ doesn't always work, I won't use it ...
543 rot.MasterToLocalVect(vect1, localVect1);
544 rot.MasterToLocalVect(vect2, localVect2);
546 //=================================================
547 // Create the segment and add it to the mother volume
548 TGeoVolume *vCableSegB = CreateBoxSegment(coord1, coord2);
550 TGeoRotation rotArbSeg("", 0, 90, 0);
551 rotArbSeg.MultiplyBy(&rot, kFALSE);
552 TGeoTranslation trans("",cx, cy, cz);
553 TGeoCombiTrans *combiB = new TGeoCombiTrans(trans, rotArbSeg);
554 p2Vol->AddNode(vCableSegB, p2, combiB);
555 //=================================================;
558 printf("---\n Cable segment points : ");
559 printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]);
560 printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]);
563 if (ct) *ct = combiB;
567 //________________________________________________________________________
568 TGeoVolume* AliITSv11GeomCableFlat::CreateAndInsertCableCylSegment(Int_t p2,
572 // Create a flat cable segment with a curvature between points p1 and p2.
573 // The radius and position of the curve is defined by the
574 // perpendicular vector of point p2 (the orientation of this vector
575 // and the position of the 2 check points are enough to completely
577 // Rotation is the eventual rotation of the flat cable
578 // along its length axis
582 if (fInitialNode==0) {
583 TObjArray *nodes = gGeoManager->GetListOfNodes();
584 if (nodes->GetEntriesFast()==0) return 0;
585 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
587 mainNode = fInitialNode;
591 TGeoVolume *p1Vol = GetVolume(p1);
592 TGeoVolume *p2Vol = GetVolume(p2);
594 ResetCheckDaughter();
596 if (! CheckDaughter(mainNode)) {
597 printf("Error::volume containing point is not visible in node tree!\n");
601 Double_t coord1[3], coord2[3], vect1[3], vect2[3];
602 //=================================================
603 // Get p1 position in the systeme of p2
606 Int_t p1nodeInd[fgkCableMaxNodeLevel];
607 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i];
608 Int_t p1volLevel = 0;
609 while (p1nodeInd[p1volLevel]!=-1) p1volLevel++;
612 ResetCheckDaughter();
614 if (! CheckDaughter(mainNode)) {
615 printf("Error::volume containing point is not visible in node tree!\n");
618 Int_t p2nodeInd[fgkCableMaxNodeLevel];
619 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i];
620 Int_t commonMotherLevel = 0;
621 while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel])
624 Int_t p2volLevel = 0;
625 while (fNodeInd[p2volLevel]!=-1) p2volLevel++;
628 // Get coord and vect of p1 in the common mother reference system
629 GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1);
630 GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1);
631 // Translate them in the reference system of the volume containing p2
632 TGeoNode *pathNode[fgkCableMaxNodeLevel];
633 pathNode[0] = mainNode;
634 for (Int_t i=0; i<=p2volLevel; i++) {
635 pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]);
637 Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]};
638 Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]};
640 for (Int_t i = commonMotherLevel+1; i<=p2volLevel; i++) {
641 pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1);
642 pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1);
643 CopyFrom(globalCoord1, coord1);
644 CopyFrom(globalVect1, vect1);
647 GetCheckPoint(p1, 0, 0, coord1);
648 GetCheckVect(p1, 0, 0, vect1);
651 //=================================================
652 // Get p2 position in the systeme of p2
653 GetCheckPoint(p2, 0, 0, coord2);
654 GetCheckVect(p2, 0, 0, vect2);
656 Double_t cx = (coord1[0]+coord2[0])/2;
657 Double_t cy = (coord1[1]+coord2[1])/2;
658 Double_t cz = (coord1[2]+coord2[2])/2;
659 Double_t dx = coord2[0]-coord1[0];
660 Double_t dy = coord2[1]-coord1[1];
661 Double_t dz = coord2[2]-coord1[2];
662 Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz);
664 //=================================================
665 // Positionning of the segment between the 2 points
666 if ((dy<1e-31)&&(dy>0)) dy = 1e-31;
667 if ((dz<1e-31)&&(dz>0)) dz = 1e-31;
668 if ((dy>-1e-31)&&(dy<0)) dy = -1e-31;
669 if ((dz>-1e-31)&&(dz<0)) dz = -1e-31;
671 Double_t angleRot1 = -TMath::ATan2(dx,dy);
672 Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx);
673 Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz);
675 TGeoRotation rotTorusTemp("",angleRot1*TMath::RadToDeg(),
676 angleRotDiag*TMath::RadToDeg(),0);
677 TGeoRotation rotTorusToZ("",0,90,0);
678 rotTorusTemp.MultiplyBy(&rotTorusToZ, kTRUE);
679 Double_t localVect2[3];
680 rotTorusTemp.MasterToLocalVect(vect2, localVect2);
681 if (localVect2[1]<0) {
682 localVect2[0] = -localVect2[0];
683 localVect2[1] = -localVect2[1];
684 localVect2[2] = -localVect2[2];
686 Double_t normVect2 = TMath::Sqrt(localVect2[0]*localVect2[0]+
687 localVect2[1]*localVect2[1]+
688 localVect2[2]*localVect2[2]);
689 Double_t axisX[3] = {1,0,0};
690 Double_t cosangleTorusSeg = (localVect2[0]*axisX[0]+
691 localVect2[1]*axisX[1]+
692 localVect2[2]*axisX[2])/normVect2;
693 Double_t angleTorusSeg = TMath::ACos(cosangleTorusSeg)*TMath::RadToDeg();
694 TGeoRotation rotTorus("",angleRot1*TMath::RadToDeg(),
695 angleRotDiag*TMath::RadToDeg(),
696 45-angleTorusSeg+rotation);
697 //180-angleTorusSeg+rotation);
698 rotTorus.MultiplyBy(&rotTorusToZ, kTRUE);
699 rotTorus.MasterToLocalVect(vect2, localVect2);
700 if (localVect2[1]<0) {
701 localVect2[0] = -localVect2[0];
702 localVect2[1] = -localVect2[1];
703 localVect2[2] = -localVect2[2];
705 normVect2 = TMath::Sqrt(localVect2[0]*localVect2[0]+
706 localVect2[1]*localVect2[1]+
707 localVect2[2]*localVect2[2]);
708 Double_t axisY[3] = {0,1,0};
709 Double_t cosPhi = (localVect2[0]*axisY[0]+localVect2[1]*axisY[1]+
710 localVect2[2]*axisY[2])/normVect2;
711 Double_t torusPhi1 = TMath::ACos(cosPhi);
712 Double_t torusR = (length/2)/TMath::Sin(torusPhi1);
713 torusPhi1 = torusPhi1*TMath::RadToDeg();
714 Double_t perpLength = TMath::Sqrt(torusR*torusR-length*length/4);
715 Double_t localTransT[3] = {-perpLength,0,0};
716 Double_t globalTransT[3];
717 rotTorus.LocalToMasterVect(localTransT, globalTransT);
718 TGeoTranslation transTorus("",cx+globalTransT[0],cy+globalTransT[1],
721 TGeoCombiTrans *combiTorus = new TGeoCombiTrans(transTorus, rotTorus);
723 //=================================================
724 // Create the segment and add it to the mother volume
725 TGeoVolume *vCableSegT = CreateCylSegment(torusPhi1, torusR);
726 p2Vol->AddNode(vCableSegT, p2, combiTorus);
729 printf("---\n Cable segment points : ");
730 printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]);
731 printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]);
734 if (ct) *ct = combiTorus;
738 //________________________________________________________________________
739 TGeoVolume *AliITSv11GeomCableFlat::CreateSegment( Double_t *coord1,
741 Double_t *localVect1,
742 Double_t *localVect2 )
744 // Create a segment with arbitrary vertices (general case)
745 //=================================================
746 // Calculate segment "deformation"
747 Double_t dx = coord2[0]-coord1[0];
748 Double_t dy = coord2[1]-coord1[1];
749 Double_t dz = coord2[2]-coord1[2];
750 Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz);
752 Double_t cosTheta1 = -1./TMath::Sqrt( 1 + localVect1[0]*localVect1[0]
753 /localVect1[2]/localVect1[2] );
754 Double_t cosTheta2 = 1./TMath::Sqrt( 1 + localVect2[0]*localVect2[0]
755 /localVect2[2]/localVect2[2] );
756 if (localVect1[2]<0) cosTheta1 = -cosTheta1;
757 if (localVect2[2]<0) cosTheta2 = -cosTheta2;
759 Double_t dL1 = 0.5*fWidth*TMath::Tan(TMath::ACos(cosTheta1));
760 Double_t dL2 = 0.5*fWidth*TMath::Tan(TMath::ACos(cosTheta2));
761 if (localVect1[0]<0) dL1 = - dL1;
762 if (localVect2[0]<0) dL2 = - dL2;
764 Double_t cosPhi1 = -1./TMath::Sqrt( 1 + localVect1[1]*localVect1[1]
765 /localVect1[2]/localVect1[2] );
766 Double_t cosPhi2 = 1./TMath::Sqrt( 1 + localVect2[1]*localVect2[1]
767 /localVect2[2]/localVect2[2] );
768 if (localVect1[2]<0) cosPhi1 = -cosPhi1;
769 if (localVect2[2]<0) cosPhi2 = -cosPhi2;
771 Double_t tanACosCosPhi1 = TMath::Tan(TMath::ACos(cosPhi1));
772 Double_t tanACosCosPhi2 = TMath::Tan(TMath::ACos(cosPhi2));
773 if (localVect1[1]<0) tanACosCosPhi1 = -tanACosCosPhi1;
774 if (localVect2[1]<0) tanACosCosPhi2 = -tanACosCosPhi2;
776 Double_t dl1 = 0.5*fThick*tanACosCosPhi1*0.99999999999999;
777 Double_t dl2 = 0.5*fThick*tanACosCosPhi2*0.99999999999999;
778 // 0.9999999999999 is for correcting problems in TGeo...
779 //=================================================
780 // Create the segment
781 TGeoArb8 *cableSeg = new TGeoArb8(fThick/2);
782 cableSeg->SetVertex( 0, -fWidth/2, -length/2 - dL1 + dl1);
783 cableSeg->SetVertex( 1, -fWidth/2, length/2 + dL2 - dl2);
784 cableSeg->SetVertex( 2, fWidth/2, length/2 - dL2 - dl2);
785 cableSeg->SetVertex( 3, fWidth/2, -length/2 + dL1 + dl1);
786 cableSeg->SetVertex( 4, -fWidth/2, -length/2 - dL1 - dl1);
787 cableSeg->SetVertex( 5, -fWidth/2, length/2 + dL2 + dl2);
788 cableSeg->SetVertex( 6, fWidth/2, length/2 - dL2 + dl2);
789 cableSeg->SetVertex( 7, fWidth/2, -length/2 + dL1 - dl1);
791 TGeoVolume *vCableSeg = new TGeoVolume(GetName(), cableSeg, fLayMedia[fNlayer-1]);
793 // add all cable layers but the last
794 for (Int_t iLay=0; iLay<fNlayer-1; iLay++) {
796 Double_t dl1Lay = 0.5*fLayThickness[iLay]*tanACosCosPhi1;
797 Double_t dl2Lay = 0.5*fLayThickness[iLay]*tanACosCosPhi2;
799 Double_t ztr = -fThick/2;
800 for (Int_t i=0;i<iLay; i++) ztr+= fLayThickness[i];
801 ztr+= fLayThickness[iLay]/2;
803 Double_t dl1LayS = ztr*tanACosCosPhi1;
804 Double_t dl2LayS = ztr*tanACosCosPhi2;
806 TGeoArb8 *lay = new TGeoArb8(fLayThickness[iLay]/2);
807 lay->SetVertex( 0, -fWidth/2, -length/2 - dL1 + dl1Lay - dl1LayS);
808 lay->SetVertex( 1, -fWidth/2, length/2 + dL2 - dl2Lay + dl2LayS);
809 lay->SetVertex( 2, fWidth/2, length/2 - dL2 - dl2Lay + dl2LayS);
810 lay->SetVertex( 3, fWidth/2, -length/2 + dL1 + dl1Lay - dl1LayS);
811 lay->SetVertex( 4, -fWidth/2, -length/2 - dL1 - dl1Lay - dl1LayS);
812 lay->SetVertex( 5, -fWidth/2, length/2 + dL2 + dl2Lay + dl2LayS);
813 lay->SetVertex( 6, fWidth/2, length/2 - dL2 + dl2Lay + dl2LayS);
814 lay->SetVertex( 7, fWidth/2, -length/2 + dL1 - dl1Lay - dl1LayS);
815 TGeoVolume *vLay = new TGeoVolume("vCableSegLay", lay, fLayMedia[iLay]);
816 vLay->SetLineColor(fLayColor[iLay]);
818 if (fTranslation[iLay]==0)
819 fTranslation[iLay] = new TGeoTranslation(0, 0, ztr);
820 vCableSeg->AddNode(vLay, iLay+1, fTranslation[iLay]);
823 //vCableSeg->SetVisibility(kFALSE);
827 //________________________________________________________________________
828 TGeoVolume *AliITSv11GeomCableFlat::CreateCylSegment(Double_t &phi,
831 // Create a segment in shape of a cylinder, allows to represent
832 // a folded flat cable
834 Double_t phi1 = 360-phi;
835 Double_t phi2 = 360+phi;
837 Double_t rMin = r-fThick/2;
838 Double_t rMax = r+fThick/2;
839 //=================================================
840 // Create the segment
842 TGeoTubeSeg *cableSeg = new TGeoTubeSeg(rMin, rMax, fWidth/2,
844 TGeoVolume *vCableSeg = new TGeoVolume(GetName(), cableSeg, fLayMedia[fNlayer-1]);
846 // add all cable layers but the last
847 for (Int_t iLay=0; iLay<fNlayer-1; iLay++) {
849 Double_t ztr = -fThick/2;
850 for (Int_t i=0;i<iLay; i++) ztr+= fLayThickness[i];
853 rMax = r + ztr + fLayThickness[iLay];
854 TGeoTubeSeg *lay = new TGeoTubeSeg(rMin, rMax, fWidth/2,
857 TGeoVolume *vLay = new TGeoVolume("vCableSegLay", lay, fLayMedia[iLay]);
858 vLay->SetLineColor(fLayColor[iLay]);
860 vCableSeg->AddNode(vLay, iLay+1, 0);
863 //vCableSeg->SetVisibility(kFALSE);
867 //________________________________________________________________________
868 TGeoVolume *AliITSv11GeomCableFlat::CreateBoxSegment( Double_t *coord1,
871 // Create a segment for the case it is a simple box
872 //=================================================
873 Double_t dx = coord2[0]-coord1[0];
874 Double_t dy = coord2[1]-coord1[1];
875 Double_t dz = coord2[2]-coord1[2];
876 Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz);
878 TGeoBBox *cableSeg = new TGeoBBox(fWidth/2, length/2, fThick/2);
879 TGeoVolume *vCableSeg = new TGeoVolume(GetName(), cableSeg, fLayMedia[fNlayer-1]);
880 // This volume is the cable container. It codes also the material for the
883 // add all cable layers but the last one
884 for (Int_t iLay=0; iLay<fNlayer-1; iLay++) {
886 Double_t ztr = -fThick/2;
887 for (Int_t i=0;i<iLay; i++) ztr+= fLayThickness[i];
888 ztr+= fLayThickness[iLay]/2;
890 TGeoBBox *lay = new TGeoBBox(fWidth/2, length/2, fLayThickness[iLay]/2);
892 TGeoVolume *vLay = new TGeoVolume("vCableSegLay", lay, fLayMedia[iLay]);
893 vLay->SetLineColor(fLayColor[iLay]);
895 if (fTranslation[iLay]==0)
896 fTranslation[iLay] = new TGeoTranslation(0, 0, ztr);
897 vCableSeg->AddNode(vLay, iLay+1, fTranslation[iLay]);
900 //vCableSeg->SetVisibility(kFALSE);
904 //________________________________________________________________________
905 void AliITSv11GeomCableFlat::SetNLayers(Int_t nLayers) {
906 // Set the number of layers
907 if((nLayers>0) &&(nLayers<=fgkCableMaxLayer)) {
910 for (Int_t i=0; i<fgkCableMaxLayer ; i++) {
911 fLayThickness[i] = 0;
919 //________________________________________________________________________
920 Int_t AliITSv11GeomCableFlat::SetLayer(Int_t nLayer, Double_t thick,
921 TGeoMedium *medium, Int_t color) {
922 // Set the layer number nLayer
923 if ((nLayer<0)||(nLayer>=fNlayer)) {
924 printf("Set wrong layer number of the cable\n");
928 if (fLayThickness[nLayer-1]<=0) {
929 printf("AliITSv11GeomCableFlat::SetLayer():"
930 " You must define cable layer %i first !",nLayer-1);
934 Double_t thickTot = 0;
935 for (Int_t i=0; i<nLayer; i++) thickTot += fLayThickness[i];
937 if (thickTot-1e-10>fThick) {
938 printf("Can't add this layer, cable thickness would be higher than total\n");
942 fLayThickness[nLayer] = thick;
943 fLayMedia[nLayer] = medium;
944 fLayColor[nLayer] = color;
945 fTranslation[nLayer] = 0;