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());
127 //________________________________________________________________________
128 Int_t AliITSv11GeomCableFlat::GetVect( Int_t iCheckPt, Double_t *coord)
130 // Get the correct vect corresponding to point #iCheckPt
132 TVectorD *coordVector =(TVectorD *)fPointArray.At(2*iCheckPt+1);
134 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
135 CopyFrom(coord, coordVector->GetElements());
137 CopyFrom(coord, coordVector->GetMatrixArray());
146 //________________________________________________________________________
147 void AliITSv11GeomCableFlat::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt,
148 Double_t *coord, Double_t *orthVect)
151 // Add a check point. In the fPointArray, the point is at i and its vector
155 // if (iCheckPt>=fVolumeArray.GetEntriesFast()) {
156 // fVolumeArray.AddLast(vol);
157 // TVectorD *point = new TVectorD(3,coord);
158 // TVectorD *vect = new TVectorD(3,orthVect);
159 // fPointArray.AddLast(point);
160 // fPointArray.AddLast(vect);
162 // } else if ((iCheckPt >= 0)&&(iCheckPt < fVolumeArray.GetEntriesFast())) {
163 // fVolumeArray.AddAt(vol, iCheckPt);
164 // TVectorD *point = new TVectorD(3,coord);
165 // TVectorD *vect = new TVectorD(3,orthVect);
166 // fPointArray.AddAt(point, iCheckPt*2 );
167 // fPointArray.AddAt(vect, iCheckPt*2+1);
169 fVolumeArray.AddAtAndExpand(vol, iCheckPt);
170 TVectorD *point = new TVectorD(3,coord);
171 TVectorD *vect = new TVectorD(3,orthVect);
172 fPointArray.AddAtAndExpand(point, iCheckPt*2 );
173 fPointArray.AddAtAndExpand(vect, iCheckPt*2+1);
176 //________________________________________________________________________
177 void AliITSv11GeomCableFlat::PrintCheckPoints() const {
178 // print all check points of the cable
179 printf(" ---\n Printing all check points of the flat cable\n");
180 for (Int_t i = 0; i<fVolumeArray.GetEntriesFast(); i++) {
182 if (GetPoint( i, coord))
183 printf(" ( %.2f, %.2f, %.2f )\n", coord[0], coord[1], coord[2]);
187 //________________________________________________________________________
188 TGeoVolume* AliITSv11GeomCableFlat::CreateAndInsertCableSegment(Int_t p2,
191 // Creates a cable segment between points p1 and p2.
192 // Rotation is the eventual rotation of the flat cable
193 // along its length axis
195 // The segment volume is created inside the volume containing point2
196 // Therefore this segment should be defined in this volume only.
197 // I mean here that, if the previous point is in another volume,
198 // it should be just at the border between the 2 volumes. Also the
199 // orientation vector of the previous point should be orthogonal to
200 // the surface between the 2 volumes.
203 if (fInitialNode==0) {
204 TObjArray *nodes = gGeoManager->GetListOfNodes();
205 if (nodes->GetEntriesFast()==0) return 0;
206 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
208 mainNode = fInitialNode;
212 TGeoVolume *p2Vol = GetVolume(p2);
213 TGeoVolume *p1Vol = GetVolume(p1);
215 ResetCheckDaughter();
217 if (! CheckDaughter(mainNode)) {
218 printf("Error::volume containing point is not visible in node tree!\n");
222 Double_t coord1[3], coord2[3], vect1[3], vect2[3];
223 //=================================================
224 // Get p1 position in the systeme of p2
227 Int_t p1nodeInd[fgkCableMaxNodeLevel];
228 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i];
229 Int_t p1volLevel = 0;
230 while (p1nodeInd[p1volLevel]!=-1) p1volLevel++;
233 ResetCheckDaughter();
235 if (! CheckDaughter(mainNode)) {
236 printf("Error::volume containing point is not visible in node tree!\n");
239 Int_t p2nodeInd[fgkCableMaxNodeLevel];
240 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i];
241 Int_t commonMotherLevel = 0;
242 while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel])
245 Int_t p2volLevel = 0;
246 while (fNodeInd[p2volLevel]!=-1) p2volLevel++;
249 // Get coord and vect of p1 in the common mother reference system
250 if (! GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1) )
252 if (! GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1) )
255 // Translate them in the reference system of the volume containing p2
256 TGeoNode *pathNode[fgkCableMaxNodeLevel];
257 pathNode[0] = mainNode;
258 for (Int_t i=0; i<=p2volLevel; i++) {
259 pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]);
261 Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]};
262 Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]};
264 for (Int_t i = commonMotherLevel+1; i <= p2volLevel; i++) {
265 pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1);
266 pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1);
267 CopyFrom(globalCoord1, coord1);
268 CopyFrom(globalVect1, vect1);
271 if (! GetCheckPoint(p1, 0, 0, coord1) ) return 0;
272 if (! GetCheckVect(p1, 0, 0, vect1) ) return 0;
275 //=================================================
276 // Get p2 position in the systeme of p2
277 if (! GetCheckPoint(p2, 0, 0, coord2) ) return 0;
278 if (! GetCheckVect(p2, 0, 0, vect2) ) return 0;
280 Double_t cx = (coord1[0]+coord2[0])/2;
281 Double_t cy = (coord1[1]+coord2[1])/2;
282 Double_t cz = (coord1[2]+coord2[2])/2;
283 Double_t dx = coord2[0]-coord1[0];
284 Double_t dy = coord2[1]-coord1[1];
285 Double_t dz = coord2[2]-coord1[2];
287 //=================================================
288 // Positionning of the segment between the 2 points
289 if (TMath::Abs(dy)<1e-231) dy = 1e-231;
290 if (TMath::Abs(dz)<1e-231) dz = 1e-231;
291 //Double_t angleRot1 = -TMath::ATan(dx/dy);
292 //Double_t planDiagL = -TMath::Sqrt(dy*dy+dx*dx);
293 //if (dy<0) planDiagL = -planDiagL;
294 //Double_t angleRotDiag = TMath::ATan(planDiagL/dz);
296 Double_t angleRot1 = -TMath::ATan2(dx,dy);
297 Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx);
298 Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz);
299 //--- (Calculate rotation of segment on the Z axis)
300 //-- Here I'm trying to calculate the rotation to be applied in
301 //-- order to match as closer as possible this segment and the
303 //-- It seems that some times it doesn't work ...
304 Double_t angleRotZ = 0;
305 TGeoRotation rotTemp("",angleRot1*TMath::RadToDeg(),
306 angleRotDiag*TMath::RadToDeg(), rotation);
307 Double_t localX[3] = {0,1,0};
309 rotTemp.LocalToMasterVect(localX, globalX);
310 CopyFrom(localX, globalX);
311 GetCheckVect(localX, p2Vol, 0, fgkCableMaxNodeLevel+1, globalX);
312 Double_t orthVect[3];
313 GetCheckVect(vect1, p2Vol, 0, fgkCableMaxNodeLevel+1, orthVect);
315 Double_t orthVectNorm2 = ScalProd(orthVect,orthVect);
316 Double_t alpha1 = ScalProd(fPreviousX,orthVect)/orthVectNorm2;
317 Double_t alpha2 = ScalProd(globalX,orthVect)/orthVectNorm2;
318 Double_t globalX1p[3], globalX2p[3];
319 globalX1p[0] = fPreviousX[0] - alpha1*orthVect[0];
320 globalX1p[1] = fPreviousX[1] - alpha1*orthVect[1];
321 globalX1p[2] = fPreviousX[2] - alpha1*orthVect[2];
322 globalX2p[0] = globalX[0] - alpha2*orthVect[0];
323 globalX2p[1] = globalX[1] - alpha2*orthVect[1];
324 globalX2p[2] = globalX[2] - alpha2*orthVect[2];
325 //-- now I'm searching the 3th vect which makes an orthogonal base
326 //-- with orthVect and globalX1p ...
327 Double_t nulVect[3] = {0,0,0};
329 TMath::Normal2Plane(nulVect, orthVect, globalX1p, axis3);
330 Double_t globalX1pNorm2 = ScalProd(globalX1p, globalX1p);
331 Double_t beta = ScalProd(globalX2p, globalX1p)/globalX1pNorm2;
332 Double_t gamma = ScalProd(globalX2p, axis3);
333 angleRotZ = (TMath::ATan2(1,0) - TMath::ATan2(beta, gamma))
336 // cout << "!!!!!!!!!!!!!!!!!!! angle = " <<angleRotZ << endl;
337 CopyFrom(fPreviousX, globalX);
339 Double_t localVect1[3], localVect2[3];
340 TGeoRotation rot("",angleRot1*TMath::RadToDeg(),
341 angleRotDiag*TMath::RadToDeg(),
343 // rotation-angleRotZ);
344 // since angleRotZ doesn't always work, I won't use it ...
346 rot.MasterToLocalVect(vect1, localVect1);
347 rot.MasterToLocalVect(vect2, localVect2);
349 //=================================================
350 // Create the segment and add it to the mother volume
351 TGeoVolume *vCableSegB = CreateSegment(coord1, coord2,
352 localVect1, localVect2);
353 // TGeoVolume *vCableSegB = CreateBoxSegment(coord1, coord2);
355 TGeoRotation rotArbSeg("", 0, 90, 0);
356 rotArbSeg.MultiplyBy(&rot, kFALSE);
357 TGeoTranslation trans("",cx, cy, cz);
358 TGeoCombiTrans *combiB = new TGeoCombiTrans(trans, rotArbSeg);
359 p2Vol->AddNode(vCableSegB, p2, combiB);
360 //=================================================;
363 printf("---\n Cable segment points : ");
364 printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]);
365 printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]);
368 // #include <TGeoSphere.h>
369 // TGeoMedium *airSDD = gGeoManager->GetMedium("ITS_ITSsddAir");
370 // TGeoSphere *sphere = new TGeoSphere(0, 0.05);
371 // TGeoVolume *vSphere = new TGeoVolume("", sphere, airSDD);
372 // TGeoTranslation *trC = new TGeoTranslation("", cx, cy, cz);
373 // TGeoTranslation *tr1 = new TGeoTranslation("",coord1[0],
374 // coord1[1],coord1[2]);
375 // TGeoTranslation *tr2 = new TGeoTranslation("",coord2[0],
376 // coord2[1],coord2[2]);
377 // p2Vol->AddNode(vSphere, p2*3-2, trC);
378 // p2Vol->AddNode(vSphere, p2*3-1, tr1);
379 // p2Vol->AddNode(vSphere, p2*3 , tr2);
384 //________________________________________________________________________
385 TGeoVolume* AliITSv11GeomCableFlat::CreateAndInsertBoxCableSegment(Int_t p2,
388 // This function is to be use only when the segment has the shape
389 // of a simple box, i.e. the normal vector to its end is perpendicular
390 // to the segment own axis
391 // Creates a cable segment between points p1 and p2.
392 // Rotation is the eventual rotation of the flat cable
393 // along its length axis
395 // The segment volume is created inside the volume containing point2
396 // Therefore this segment should be defined in this volume only.
397 // I mean here that, if the previous point is in another volume,
398 // it should be just at the border between the 2 volumes. Also the
399 // orientation vector of the previous point should be orthogonal to
400 // the surface between the 2 volumes.
403 if (fInitialNode==0) {
404 TObjArray *nodes = gGeoManager->GetListOfNodes();
405 if (nodes->GetEntriesFast()==0) return 0;
406 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
408 mainNode = fInitialNode;
412 TGeoVolume *p2Vol = GetVolume(p2);
413 TGeoVolume *p1Vol = GetVolume(p1);
415 ResetCheckDaughter();
417 if (! CheckDaughter(mainNode)) {
418 printf("Error::volume containing point is not visible in node tree!\n");
422 Double_t coord1[3], coord2[3], vect1[3], vect2[3];
423 //=================================================
424 // Get p1 position in the systeme of p2
427 Int_t p1nodeInd[fgkCableMaxNodeLevel];
428 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i];
429 Int_t p1volLevel = 0;
430 while (p1nodeInd[p1volLevel]!=-1) p1volLevel++;
433 ResetCheckDaughter();
435 if (! CheckDaughter(mainNode)) {
436 printf("Error::volume containing point is not visible in node tree!\n");
439 Int_t p2nodeInd[fgkCableMaxNodeLevel];
440 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i];
441 Int_t commonMotherLevel = 0;
442 while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel])
445 Int_t p2volLevel = 0;
446 while (fNodeInd[p2volLevel]!=-1) p2volLevel++;
449 // Get coord and vect of p1 in the common mother reference system
450 if (! GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1) )
452 if (! GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1) )
455 // Translate them in the reference system of the volume containing p2
456 TGeoNode *pathNode[fgkCableMaxNodeLevel];
457 pathNode[0] = mainNode;
458 for (Int_t i=0; i<=p2volLevel; i++) {
459 pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]);
461 Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]};
462 Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]};
464 for (Int_t i = commonMotherLevel+1; i <= p2volLevel; i++) {
465 pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1);
466 pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1);
467 CopyFrom(globalCoord1, coord1);
468 CopyFrom(globalVect1, vect1);
471 if (! GetCheckPoint(p1, 0, 0, coord1) ) return 0;
472 if (! GetCheckVect(p1, 0, 0, vect1) ) return 0;
475 //=================================================
476 // Get p2 position in the systeme of p2
477 if (! GetCheckPoint(p2, 0, 0, coord2) ) return 0;
478 if (! GetCheckVect(p2, 0, 0, vect2) ) return 0;
480 Double_t cx = (coord1[0]+coord2[0])/2;
481 Double_t cy = (coord1[1]+coord2[1])/2;
482 Double_t cz = (coord1[2]+coord2[2])/2;
483 Double_t dx = coord2[0]-coord1[0];
484 Double_t dy = coord2[1]-coord1[1];
485 Double_t dz = coord2[2]-coord1[2];
487 //=================================================
488 // Positionning of the segment between the 2 points
489 if (TMath::Abs(dy)<1e-231) dy = 1e-231;
490 if (TMath::Abs(dz)<1e-231) dz = 1e-231;
491 //Double_t angleRot1 = -TMath::ATan(dx/dy);
492 //Double_t planDiagL = -TMath::Sqrt(dy*dy+dx*dx);
493 //if (dy<0) planDiagL = -planDiagL;
494 //Double_t angleRotDiag = TMath::ATan(planDiagL/dz);
496 Double_t angleRot1 = -TMath::ATan2(dx,dy);
497 Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx);
498 Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz);
499 //--- (Calculate rotation of segment on the Z axis)
500 //-- Here I'm trying to calculate the rotation to be applied in
501 //-- order to match as closer as possible this segment and the
503 //-- It seems that some times it doesn't work ...
504 Double_t angleRotZ = 0;
505 TGeoRotation rotTemp("",angleRot1*TMath::RadToDeg(),
506 angleRotDiag*TMath::RadToDeg(), rotation);
507 Double_t localX[3] = {0,1,0};
509 rotTemp.LocalToMasterVect(localX, globalX);
510 CopyFrom(localX, globalX);
511 GetCheckVect(localX, p2Vol, 0, fgkCableMaxNodeLevel+1, globalX);
512 Double_t orthVect[3];
513 GetCheckVect(vect1, p2Vol, 0, fgkCableMaxNodeLevel+1, orthVect);
515 Double_t orthVectNorm2 = ScalProd(orthVect,orthVect);
516 Double_t alpha1 = ScalProd(fPreviousX,orthVect)/orthVectNorm2;
517 Double_t alpha2 = ScalProd(globalX,orthVect)/orthVectNorm2;
518 Double_t globalX1p[3], globalX2p[3];
519 globalX1p[0] = fPreviousX[0] - alpha1*orthVect[0];
520 globalX1p[1] = fPreviousX[1] - alpha1*orthVect[1];
521 globalX1p[2] = fPreviousX[2] - alpha1*orthVect[2];
522 globalX2p[0] = globalX[0] - alpha2*orthVect[0];
523 globalX2p[1] = globalX[1] - alpha2*orthVect[1];
524 globalX2p[2] = globalX[2] - alpha2*orthVect[2];
525 //-- now I'm searching the 3th vect which makes an orthogonal base
526 //-- with orthVect and globalX1p ...
527 Double_t nulVect[3] = {0,0,0};
529 TMath::Normal2Plane(nulVect, orthVect, globalX1p, axis3);
530 Double_t globalX1pNorm2 = ScalProd(globalX1p, globalX1p);
531 Double_t beta = ScalProd(globalX2p, globalX1p)/globalX1pNorm2;
532 Double_t gamma = ScalProd(globalX2p, axis3);
533 angleRotZ = (TMath::ATan2(1,0) - TMath::ATan2(beta, gamma))
536 // cout << "!!!!!!!!!!!!!!!!!!! angle = " <<angleRotZ << endl;
537 CopyFrom(fPreviousX, globalX);
539 Double_t localVect1[3], localVect2[3];
540 TGeoRotation rot("",angleRot1*TMath::RadToDeg(),
541 angleRotDiag*TMath::RadToDeg(),
543 // rotation-angleRotZ);
544 // since angleRotZ doesn't always work, I won't use it ...
546 rot.MasterToLocalVect(vect1, localVect1);
547 rot.MasterToLocalVect(vect2, localVect2);
549 //=================================================
550 // Create the segment and add it to the mother volume
551 TGeoVolume *vCableSegB = CreateBoxSegment(coord1, coord2);
553 TGeoRotation rotArbSeg("", 0, 90, 0);
554 rotArbSeg.MultiplyBy(&rot, kFALSE);
555 TGeoTranslation trans("",cx, cy, cz);
556 TGeoCombiTrans *combiB = new TGeoCombiTrans(trans, rotArbSeg);
557 p2Vol->AddNode(vCableSegB, p2, combiB);
558 //=================================================;
561 printf("---\n Cable segment points : ");
562 printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]);
563 printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]);
569 //________________________________________________________________________
570 TGeoVolume* AliITSv11GeomCableFlat::CreateAndInsertCableCylSegment(Int_t p2,
573 // Create a flat cable segment with a curvature between points p1 and p2.
574 // The radius and position of the curve is defined by the
575 // perpendicular vector of point p2 (the orientation of this vector
576 // and the position of the 2 check points are enough to completely
578 // Rotation is the eventual rotation of the flat cable
579 // along its length axis
583 if (fInitialNode==0) {
584 TObjArray *nodes = gGeoManager->GetListOfNodes();
585 if (nodes->GetEntriesFast()==0) return 0;
586 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
588 mainNode = fInitialNode;
592 TGeoVolume *p1Vol = GetVolume(p1);
593 TGeoVolume *p2Vol = GetVolume(p2);
595 ResetCheckDaughter();
597 if (! CheckDaughter(mainNode)) {
598 printf("Error::volume containing point is not visible in node tree!\n");
602 Double_t coord1[3], coord2[3], vect1[3], vect2[3];
603 //=================================================
604 // Get p1 position in the systeme of p2
607 Int_t p1nodeInd[fgkCableMaxNodeLevel];
608 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i];
609 Int_t p1volLevel = 0;
610 while (p1nodeInd[p1volLevel]!=-1) p1volLevel++;
613 ResetCheckDaughter();
615 if (! CheckDaughter(mainNode)) {
616 printf("Error::volume containing point is not visible in node tree!\n");
619 Int_t p2nodeInd[fgkCableMaxNodeLevel];
620 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i];
621 Int_t commonMotherLevel = 0;
622 while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel])
625 Int_t p2volLevel = 0;
626 while (fNodeInd[p2volLevel]!=-1) p2volLevel++;
629 // Get coord and vect of p1 in the common mother reference system
630 GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1);
631 GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1);
632 // Translate them in the reference system of the volume containing p2
633 TGeoNode *pathNode[fgkCableMaxNodeLevel];
634 pathNode[0] = mainNode;
635 for (Int_t i=0; i<=p2volLevel; i++) {
636 pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]);
638 Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]};
639 Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]};
641 for (Int_t i = commonMotherLevel+1; i<=p2volLevel; i++) {
642 pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1);
643 pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1);
644 CopyFrom(globalCoord1, coord1);
645 CopyFrom(globalVect1, vect1);
648 GetCheckPoint(p1, 0, 0, coord1);
649 GetCheckVect(p1, 0, 0, vect1);
652 //=================================================
653 // Get p2 position in the systeme of p2
654 GetCheckPoint(p2, 0, 0, coord2);
655 GetCheckVect(p2, 0, 0, vect2);
657 Double_t cx = (coord1[0]+coord2[0])/2;
658 Double_t cy = (coord1[1]+coord2[1])/2;
659 Double_t cz = (coord1[2]+coord2[2])/2;
660 Double_t dx = coord2[0]-coord1[0];
661 Double_t dy = coord2[1]-coord1[1];
662 Double_t dz = coord2[2]-coord1[2];
663 Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz);
665 //=================================================
666 // Positionning of the segment between the 2 points
667 if ((dy<1e-31)&&(dy>0)) dy = 1e-31;
668 if ((dz<1e-31)&&(dz>0)) dz = 1e-31;
669 if ((dy>-1e-31)&&(dy<0)) dy = -1e-31;
670 if ((dz>-1e-31)&&(dz<0)) dz = -1e-31;
672 Double_t angleRot1 = -TMath::ATan2(dx,dy);
673 Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx);
674 Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz);
676 TGeoRotation rotTorusTemp("",angleRot1*TMath::RadToDeg(),
677 angleRotDiag*TMath::RadToDeg(),0);
678 TGeoRotation rotTorusToZ("",0,90,0);
679 rotTorusTemp.MultiplyBy(&rotTorusToZ, kTRUE);
680 Double_t localVect2[3];
681 rotTorusTemp.MasterToLocalVect(vect2, localVect2);
682 if (localVect2[1]<0) {
683 localVect2[0] = -localVect2[0];
684 localVect2[1] = -localVect2[1];
685 localVect2[2] = -localVect2[2];
687 Double_t normVect2 = TMath::Sqrt(localVect2[0]*localVect2[0]+
688 localVect2[1]*localVect2[1]+
689 localVect2[2]*localVect2[2]);
690 Double_t axisX[3] = {1,0,0};
691 Double_t cosangleTorusSeg = (localVect2[0]*axisX[0]+
692 localVect2[1]*axisX[1]+
693 localVect2[2]*axisX[2])/normVect2;
694 Double_t angleTorusSeg = TMath::ACos(cosangleTorusSeg)*TMath::RadToDeg();
695 TGeoRotation rotTorus("",angleRot1*TMath::RadToDeg(),
696 angleRotDiag*TMath::RadToDeg(),
697 45-angleTorusSeg+rotation);
698 //180-angleTorusSeg+rotation);
699 rotTorus.MultiplyBy(&rotTorusToZ, kTRUE);
700 rotTorus.MasterToLocalVect(vect2, localVect2);
701 if (localVect2[1]<0) {
702 localVect2[0] = -localVect2[0];
703 localVect2[1] = -localVect2[1];
704 localVect2[2] = -localVect2[2];
706 normVect2 = TMath::Sqrt(localVect2[0]*localVect2[0]+
707 localVect2[1]*localVect2[1]+
708 localVect2[2]*localVect2[2]);
709 Double_t axisY[3] = {0,1,0};
710 Double_t cosPhi = (localVect2[0]*axisY[0]+localVect2[1]*axisY[1]+
711 localVect2[2]*axisY[2])/normVect2;
712 Double_t torusPhi1 = TMath::ACos(cosPhi);
713 Double_t torusR = (length/2)/TMath::Sin(torusPhi1);
714 torusPhi1 = torusPhi1*TMath::RadToDeg();
715 Double_t perpLength = TMath::Sqrt(torusR*torusR-length*length/4);
716 Double_t localTransT[3] = {-perpLength,0,0};
717 Double_t globalTransT[3];
718 rotTorus.LocalToMasterVect(localTransT, globalTransT);
719 TGeoTranslation transTorus("",cx+globalTransT[0],cy+globalTransT[1],
722 TGeoCombiTrans *combiTorus = new TGeoCombiTrans(transTorus, rotTorus);
724 //=================================================
725 // Create the segment and add it to the mother volume
726 TGeoVolume *vCableSegT = CreateCylSegment(torusPhi1, torusR);
727 p2Vol->AddNode(vCableSegT, p2, combiTorus);
730 printf("---\n Cable segment points : ");
731 printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]);
732 printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]);
739 //________________________________________________________________________
740 TGeoVolume *AliITSv11GeomCableFlat::CreateSegment( Double_t *coord1,
742 Double_t *localVect1,
743 Double_t *localVect2 )
746 //=================================================
747 // Calculate segment "deformation"
748 Double_t dx = coord2[0]-coord1[0];
749 Double_t dy = coord2[1]-coord1[1];
750 Double_t dz = coord2[2]-coord1[2];
751 Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz);
753 Double_t cosTheta1 = -1./TMath::Sqrt( 1 + localVect1[0]*localVect1[0]
754 /localVect1[2]/localVect1[2] );
755 Double_t cosTheta2 = 1./TMath::Sqrt( 1 + localVect2[0]*localVect2[0]
756 /localVect2[2]/localVect2[2] );
757 if (localVect1[2]<0) cosTheta1 = -cosTheta1;
758 if (localVect2[2]<0) cosTheta2 = -cosTheta2;
760 Double_t dL1 = 0.5*fWidth*TMath::Tan(TMath::ACos(cosTheta1));
761 Double_t dL2 = 0.5*fWidth*TMath::Tan(TMath::ACos(cosTheta2));
762 if (localVect1[0]<0) dL1 = - dL1;
763 if (localVect2[0]<0) dL2 = - dL2;
765 Double_t cosPhi1 = -1./TMath::Sqrt( 1 + localVect1[1]*localVect1[1]
766 /localVect1[2]/localVect1[2] );
767 Double_t cosPhi2 = 1./TMath::Sqrt( 1 + localVect2[1]*localVect2[1]
768 /localVect2[2]/localVect2[2] );
769 if (localVect1[2]<0) cosPhi1 = -cosPhi1;
770 if (localVect2[2]<0) cosPhi2 = -cosPhi2;
772 Double_t tanACosCosPhi1 = TMath::Tan(TMath::ACos(cosPhi1));
773 Double_t tanACosCosPhi2 = TMath::Tan(TMath::ACos(cosPhi2));
774 if (localVect1[1]<0) tanACosCosPhi1 = -tanACosCosPhi1;
775 if (localVect2[1]<0) tanACosCosPhi2 = -tanACosCosPhi2;
777 Double_t dl1 = 0.5*fThick*tanACosCosPhi1;
778 Double_t dl2 = 0.5*fThick*tanACosCosPhi2;
780 //=================================================
781 // Create the segment
782 TGeoArb8 *cableSeg = new TGeoArb8(fThick/2);
783 cableSeg->SetVertex( 0, -fWidth/2, -length/2 - dL1 + dl1);
784 cableSeg->SetVertex( 1, -fWidth/2, length/2 + dL2 - dl2);
785 cableSeg->SetVertex( 2, fWidth/2, length/2 - dL2 - dl2);
786 cableSeg->SetVertex( 3, fWidth/2, -length/2 + dL1 + dl1);
787 cableSeg->SetVertex( 4, -fWidth/2, -length/2 - dL1 - dl1);
788 cableSeg->SetVertex( 5, -fWidth/2, length/2 + dL2 + dl2);
789 cableSeg->SetVertex( 6, fWidth/2, length/2 - dL2 + dl2);
790 cableSeg->SetVertex( 7, fWidth/2, -length/2 + dL1 - dl1);
792 TGeoMedium *airSDD = gGeoManager->GetMedium("ITS_ITSair");
793 TGeoVolume *vCableSeg = new TGeoVolume(GetName(), cableSeg, airSDD);
795 // add all cable layers
796 for (Int_t iLay=0; iLay<fNlayer; iLay++) {
798 Double_t dl1Lay = 0.5*fLayThickness[iLay]*tanACosCosPhi1;
799 Double_t dl2Lay = 0.5*fLayThickness[iLay]*tanACosCosPhi2;
801 Double_t ztr = -fThick/2;
802 for (Int_t i=0;i<iLay; i++) ztr+= fLayThickness[i];
803 ztr+= fLayThickness[iLay]/2;
805 Double_t dl1LayS = ztr*tanACosCosPhi1;
806 Double_t dl2LayS = ztr*tanACosCosPhi2;
808 TGeoArb8 *lay = new TGeoArb8(fLayThickness[iLay]/2);
809 lay->SetVertex( 0, -fWidth/2, -length/2 - dL1 + dl1Lay - dl1LayS);
810 lay->SetVertex( 1, -fWidth/2, length/2 + dL2 - dl2Lay + dl2LayS);
811 lay->SetVertex( 2, fWidth/2, length/2 - dL2 - dl2Lay + dl2LayS);
812 lay->SetVertex( 3, fWidth/2, -length/2 + dL1 + dl1Lay - dl1LayS);
813 lay->SetVertex( 4, -fWidth/2, -length/2 - dL1 - dl1Lay - dl1LayS);
814 lay->SetVertex( 5, -fWidth/2, length/2 + dL2 + dl2Lay + dl2LayS);
815 lay->SetVertex( 6, fWidth/2, length/2 - dL2 + dl2Lay + dl2LayS);
816 lay->SetVertex( 7, fWidth/2, -length/2 + dL1 - dl1Lay - dl1LayS);
817 TGeoVolume *vLay = new TGeoVolume("vCableSegLay", lay, fLayMedia[iLay]);
818 vLay->SetLineColor(fLayColor[iLay]);
820 if (fTranslation[iLay]==0)
821 fTranslation[iLay] = new TGeoTranslation(0, 0, ztr);
822 vCableSeg->AddNode(vLay, iLay+1, fTranslation[iLay]);
825 vCableSeg->SetVisibility(kFALSE);
830 //________________________________________________________________________
831 TGeoVolume *AliITSv11GeomCableFlat::CreateCylSegment(Double_t &phi,
835 Double_t phi1 = 360-phi;
836 Double_t phi2 = 360+phi;
838 Double_t rMin = r-fThick/2;
839 Double_t rMax = r+fThick/2;
840 //=================================================
841 // Create the segment
843 TGeoTubeSeg *cableSeg = new TGeoTubeSeg(rMin, rMax, fWidth/2,
845 TGeoMedium *airSDD = gGeoManager->GetMedium("ITS_ITSair");
846 TGeoVolume *vCableSeg = new TGeoVolume(GetName(), cableSeg, airSDD);
848 // add all cable layers
849 for (Int_t iLay=0; iLay<fNlayer; iLay++) {
851 Double_t ztr = -fThick/2;
852 for (Int_t i=0;i<iLay; i++) ztr+= fLayThickness[i];
855 rMax = r + ztr + fLayThickness[iLay];
856 TGeoTubeSeg *lay = new TGeoTubeSeg(rMin, rMax, fWidth/2,
859 TGeoVolume *vLay = new TGeoVolume("vCableSegLay", lay, fLayMedia[iLay]);
860 vLay->SetLineColor(fLayColor[iLay]);
862 vCableSeg->AddNode(vLay, iLay+1, 0);
865 vCableSeg->SetVisibility(kFALSE);
870 //________________________________________________________________________
871 TGeoVolume *AliITSv11GeomCableFlat::CreateBoxSegment( Double_t *coord1,
875 //=================================================
876 // Create a segment for the case it is a simple box
877 Double_t dx = coord2[0]-coord1[0];
878 Double_t dy = coord2[1]-coord1[1];
879 Double_t dz = coord2[2]-coord1[2];
880 Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz);
882 TGeoBBox *cableSeg = new TGeoBBox(fWidth/2, length/2, fThick/2);
884 TGeoMedium *airSDD = gGeoManager->GetMedium("ITS_ITSair");
885 TGeoVolume *vCableSeg = new TGeoVolume(GetName(), cableSeg, airSDD);
887 // add all cable layers
888 for (Int_t iLay=0; iLay<fNlayer; iLay++) {
890 Double_t ztr = -fThick/2;
891 for (Int_t i=0;i<iLay; i++) ztr+= fLayThickness[i];
892 ztr+= fLayThickness[iLay]/2;
894 TGeoBBox *lay = new TGeoBBox(fWidth/2, length/2, fLayThickness[iLay]/2);
897 TGeoVolume *vLay = new TGeoVolume("vCableSegLay", lay, fLayMedia[iLay]);
898 vLay->SetLineColor(fLayColor[iLay]);
900 if (fTranslation[iLay]==0)
901 fTranslation[iLay] = new TGeoTranslation(0, 0, ztr);
902 vCableSeg->AddNode(vLay, iLay+1, fTranslation[iLay]);
905 vCableSeg->SetVisibility(kFALSE);
909 //________________________________________________________________________
910 void AliITSv11GeomCableFlat::SetNLayers(Int_t nLayers) {
911 // Set the number of layers
912 if((nLayers>0) &&(nLayers<=fgkCableMaxLayer)) {
915 for (Int_t i=0; i<fgkCableMaxLayer ; i++) {
916 fLayThickness[i] = 0;
924 //________________________________________________________________________
925 Int_t AliITSv11GeomCableFlat::SetLayer(Int_t nLayer, Double_t thick,
926 TGeoMedium *medium, Int_t color) {
927 // Set the layer number nLayer
928 if ((nLayer<0)||(nLayer>=fNlayer)) {
929 printf("Set wrong layer number of the cable\n");
933 if (fLayThickness[nLayer-1]<=0) {
934 printf("AliITSv11GeomCableFlat::SetLayer():"
935 " You must define cable layer %i first !",nLayer-1);
939 Double_t thickTot = 0;
940 for (Int_t i=0; i<nLayer; i++) thickTot += fLayThickness[i];
942 if (thickTot-1e-10>fThick) {
943 printf("Can't add this layer, cable thickness would be higher than total\n");
947 fLayThickness[nLayer] = thick;
948 fLayMedia[nLayer] = medium;
949 fLayColor[nLayer] = color;
950 fTranslation[nLayer] = 0;