+TGeoVolume* AliITSv11GeomCableRound::CreateAndInsertTubeSegment(Int_t p2,
+ TGeoCombiTrans** ct)
+{
+// Creates a cable segment between points p1 and p2.
+//
+// This creates simple tube sections, i.e. the cable ends are
+// cutted perpendicularly to the tube axis. The method has to
+// be used only in this simple case, in ordder to save some memory
+
+ TGeoNode *mainNode;
+ if (fInitialNode==0) {
+ TObjArray *nodes = gGeoManager->GetListOfNodes();
+ if (nodes->GetEntriesFast()==0) return 0;
+ mainNode = (TGeoNode *) nodes->UncheckedAt(0);
+ } else {
+ mainNode = fInitialNode;
+ };
+
+ Int_t p1 = p2 - 1;
+ TGeoVolume *p1Vol = GetVolume(p1);
+ TGeoVolume *p2Vol = GetVolume(p2);
+
+ ResetCheckDaughter();
+ fCurrentVol = p1Vol;
+ if (! CheckDaughter(mainNode)) {
+ printf("Error::volume containing point is not visible in node tree!\n");
+ return 0;
+ };
+
+ Double_t coord1[3], coord2[3], vect1[3], vect2[3];
+ //=================================================
+ // Get p1 position in the systeme of p2
+ if (p1Vol!=p2Vol) {
+
+ Int_t p1nodeInd[fgkCableMaxNodeLevel];
+ for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i];
+ Int_t p1volLevel = 0;
+ while (p1nodeInd[p1volLevel]!=-1) p1volLevel++;
+ p1volLevel--;
+
+ ResetCheckDaughter();
+ fCurrentVol = p2Vol;
+ if (! CheckDaughter(mainNode)) {
+ printf("Error::volume containing point is not visible in node tree!\n");
+ return 0;
+ };
+ Int_t p2nodeInd[fgkCableMaxNodeLevel];
+ for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i];
+ Int_t commonMotherLevel = 0;
+ while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel])
+ commonMotherLevel++;
+ commonMotherLevel--;
+ Int_t p2volLevel = 0;
+ while (fNodeInd[p2volLevel]!=-1) p2volLevel++;
+ p2volLevel--;
+
+ // Get coord and vect of p1 in the common mother reference system
+ GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1);
+ GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1);
+ // Translate them in the reference system of the volume containing p2
+ TGeoNode *pathNode[fgkCableMaxNodeLevel];
+ pathNode[0] = mainNode;
+ for (Int_t i=0; i<=p2volLevel; i++) {
+ pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]);
+ };
+ Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]};
+ Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]};
+
+ for (Int_t i = commonMotherLevel+1; i<=p2volLevel; i++) {
+ pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1);
+ pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1);
+ CopyFrom(globalCoord1, coord1);
+ CopyFrom(globalVect1, vect1);
+ };
+ } else {
+ GetCheckPoint(p1, 0, 0, coord1);
+ GetCheckVect(p1, 0, 0, vect1);
+ };
+
+ //=================================================
+ // Get p2 position in the systeme of p2
+ GetCheckPoint(p2, 0, 0, coord2);
+ GetCheckVect(p2, 0, 0, vect2);
+
+ Double_t cx = (coord1[0]+coord2[0])/2;
+ Double_t cy = (coord1[1]+coord2[1])/2;
+ Double_t cz = (coord1[2]+coord2[2])/2;
+ Double_t dx = coord2[0]-coord1[0];
+ Double_t dy = coord2[1]-coord1[1];
+ Double_t dz = coord2[2]-coord1[2];
+
+ //=================================================
+ // Positionning of the segment between the 2 points
+ if ((dy<1e-31)&&(dy>0)) dy = 1e-31;
+ if ((dz<1e-31)&&(dz>0)) dz = 1e-31;
+ if ((dy>-1e-31)&&(dy<0)) dy = -1e-31;
+ if ((dz>-1e-31)&&(dz<0)) dz = -1e-31;
+
+ Double_t angleRot1 = -TMath::ATan2(dx,dy);
+ Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx);
+ Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz);
+ TGeoRotation *rot = new TGeoRotation("",angleRot1*TMath::RadToDeg(),
+ angleRotDiag*TMath::RadToDeg(),
+ 0);
+ TGeoTranslation *trans = new TGeoTranslation("",cx, cy, cz);
+
+ //=================================================
+ // Create the segment and add it to the mother volume
+ TGeoVolume *vCableSeg = CreateTubeSegment( coord1,coord2, p2);
+
+ TGeoCombiTrans *combi = new TGeoCombiTrans(*trans, *rot);
+ p2Vol->AddNode(vCableSeg, p2, combi);
+ //=================================================
+ delete rot;
+ delete trans;
+
+ if (fDebug) {
+ printf("---\n Cable segment points : ");
+ printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]);
+ printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]);
+ };
+
+ if (ct) *ct = combi;
+ return vCableSeg;
+}
+
+//________________________________________________________________________
+TGeoVolume* AliITSv11GeomCableRound::CreateAndInsertTorusSegment(Int_t p2,
+ Double_t rotation,
+ TGeoCombiTrans** ct)
+{
+ // Create a torus cable segment between points p1 and p2.
+ // The radius and position of the torus is defined by the
+ // perpendicular vector of point p2 (the orientation of this vector
+ // and the position of the 2 check points are enough to completely
+ // define the torus)
+
+ TGeoNode *mainNode;
+ if (fInitialNode==0) {
+ TObjArray *nodes = gGeoManager->GetListOfNodes();
+ if (nodes->GetEntriesFast()==0) return 0;
+ mainNode = (TGeoNode *) nodes->UncheckedAt(0);
+ } else {
+ mainNode = fInitialNode;
+ };
+
+ Int_t p1 = p2 - 1;
+ TGeoVolume *p1Vol = GetVolume(p1);
+ TGeoVolume *p2Vol = GetVolume(p2);
+
+ ResetCheckDaughter();
+ fCurrentVol = p1Vol;
+ if (! CheckDaughter(mainNode)) {
+ printf("Error::volume containing point is not visible in node tree!\n");
+ return 0;
+ };
+
+ Double_t coord1[3], coord2[3], vect1[3], vect2[3];
+ //=================================================
+ // Get p1 position in the systeme of p2
+ if (p1Vol!=p2Vol) {
+
+ Int_t p1nodeInd[fgkCableMaxNodeLevel];
+ for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i];
+ Int_t p1volLevel = 0;
+ while (p1nodeInd[p1volLevel]!=-1) p1volLevel++;
+ p1volLevel--;
+
+ ResetCheckDaughter();
+ fCurrentVol = p2Vol;
+ if (! CheckDaughter(mainNode)) {
+ printf("Error::volume containing point is not visible in node tree!\n");
+ return 0;
+ };
+ Int_t p2nodeInd[fgkCableMaxNodeLevel];
+ for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i];
+ Int_t commonMotherLevel = 0;
+ while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel])
+ commonMotherLevel++;
+ commonMotherLevel--;
+ Int_t p2volLevel = 0;
+ while (fNodeInd[p2volLevel]!=-1) p2volLevel++;
+ p2volLevel--;
+
+ // Get coord and vect of p1 in the common mother reference system
+ GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1);
+ GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1);
+ // Translate them in the reference system of the volume containing p2
+ TGeoNode *pathNode[fgkCableMaxNodeLevel];
+ pathNode[0] = mainNode;
+ for (Int_t i=0; i<=p2volLevel; i++) {
+ pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]);
+ };
+ Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]};
+ Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]};
+
+ for (Int_t i = commonMotherLevel+1; i<=p2volLevel; i++) {
+ pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1);
+ pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1);
+ CopyFrom(globalCoord1, coord1);
+ CopyFrom(globalVect1, vect1);
+ };
+ } else {
+ GetCheckPoint(p1, 0, 0, coord1);
+ GetCheckVect(p1, 0, 0, vect1);
+ };
+
+ //=================================================
+ // Get p2 position in the systeme of p2
+ GetCheckPoint(p2, 0, 0, coord2);
+ GetCheckVect(p2, 0, 0, vect2);
+
+ Double_t cx = (coord1[0]+coord2[0])/2;
+ Double_t cy = (coord1[1]+coord2[1])/2;
+ Double_t cz = (coord1[2]+coord2[2])/2;
+ Double_t dx = coord2[0]-coord1[0];
+ Double_t dy = coord2[1]-coord1[1];
+ Double_t dz = coord2[2]-coord1[2];
+ Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz);
+
+ //=================================================
+ // Positionning of the segment between the 2 points
+ if ((dy<1e-31)&&(dy>0)) dy = 1e-31;
+ if ((dz<1e-31)&&(dz>0)) dz = 1e-31;
+ if ((dy>-1e-31)&&(dy<0)) dy = -1e-31;
+ if ((dz>-1e-31)&&(dz<0)) dz = -1e-31;
+
+ Double_t angleRot1 = -TMath::ATan2(dx,dy);
+ Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx);
+ Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz);
+
+ TGeoRotation rotTorusTemp("",angleRot1*TMath::RadToDeg(),
+ angleRotDiag*TMath::RadToDeg(),0);
+ TGeoRotation rotTorusToZ("",0,90,0);
+ rotTorusTemp.MultiplyBy(&rotTorusToZ, kTRUE);
+ Double_t localVect2[3];
+ rotTorusTemp.MasterToLocalVect(vect2, localVect2);
+ if (localVect2[1]<0) {
+ localVect2[0] = -localVect2[0];
+ localVect2[1] = -localVect2[1];
+ localVect2[2] = -localVect2[2];
+ };
+ Double_t normVect2 = TMath::Sqrt(localVect2[0]*localVect2[0]+
+ localVect2[1]*localVect2[1]+
+ localVect2[2]*localVect2[2]);
+ Double_t axisX[3] = {1,0,0};
+ Double_t cosangleTorusSeg = (localVect2[0]*axisX[0]+
+ localVect2[1]*axisX[1]+
+ localVect2[2]*axisX[2])/normVect2;
+ Double_t angleTorusSeg = TMath::ACos(cosangleTorusSeg)*TMath::RadToDeg();
+
+ TGeoRotation rotTorus("",angleRot1*TMath::RadToDeg(),
+ angleRotDiag*TMath::RadToDeg(),
+ 180-angleTorusSeg+rotation);
+ rotTorus.MultiplyBy(&rotTorusToZ, kTRUE);
+ rotTorus.MasterToLocalVect(vect2, localVect2);
+ if (localVect2[1]<0) {
+ localVect2[0] = -localVect2[0];
+ localVect2[1] = -localVect2[1];
+ localVect2[2] = -localVect2[2];
+ };
+ normVect2 = TMath::Sqrt(localVect2[0]*localVect2[0]+
+ localVect2[1]*localVect2[1]+
+ localVect2[2]*localVect2[2]);
+ Double_t axisY[3] = {0,1,0};
+ Double_t cosPhi = (localVect2[0]*axisY[0]+localVect2[1]*axisY[1]+
+ localVect2[2]*axisY[2])/normVect2;
+ Double_t torusPhi1 = TMath::ACos(cosPhi);
+ Double_t torusR = (length/2)/TMath::Sin(torusPhi1);
+ torusPhi1 = torusPhi1*TMath::RadToDeg();
+ Double_t perpLength = TMath::Sqrt(torusR*torusR-length*length/4);
+ Double_t localTransT[3] = {-perpLength,0,0};
+ Double_t globalTransT[3];
+ rotTorus.LocalToMasterVect(localTransT, globalTransT);
+ TGeoTranslation transTorus("",cx+globalTransT[0],cy+globalTransT[1],
+ cz+globalTransT[2]);
+
+ TGeoCombiTrans *combiTorus = new TGeoCombiTrans(transTorus, rotTorus);
+
+ //=================================================
+ // Create the segment and add it to the mother volume
+ TGeoVolume *vCableSegT = CreateTorus(torusPhi1, torusR, p2);
+ p2Vol->AddNode(vCableSegT, p2, combiTorus);
+
+ if (fDebug) {
+ printf("---\n Cable segment points : ");
+ printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]);
+ printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]);
+ };
+
+ if (ct) *ct = combiTorus;
+ return vCableSegT;
+}
+
+//________________________________________________________________________
+TGeoVolume *AliITSv11GeomCableRound::CreateSegment( const Double_t *coord1,
+ const Double_t *coord2,