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>
34 #include <TGeoMatrix.h>
37 #include "AliITSv11GeomCableFlat.h"
40 ClassImp(AliITSv11GeomCableFlat)
42 //________________________________________________________________________
43 AliITSv11GeomCableFlat::AliITSv11GeomCableFlat():
50 for (Int_t i=0; i<fgkCableMaxLayer ; i++) {
58 //________________________________________________________________________
59 AliITSv11GeomCableFlat::
60 AliITSv11GeomCableFlat(const char* name, Double_t width, Double_t thick) :
61 AliITSv11GeomCable(name),
66 // standard constructor
67 for (Int_t i=0; i<fgkCableMaxLayer ; i++) {
75 //________________________________________________________________________
76 AliITSv11GeomCableFlat::AliITSv11GeomCableFlat(const AliITSv11GeomCableFlat &s) :
77 AliITSv11GeomCable(s),fWidth(s.fWidth),fThick(s.fThick),fNlayer(s.fNlayer)
80 for (Int_t i=0; i<s.fNlayer; i++) {
81 fLayThickness[i] = s.fLayThickness[i];
82 fTranslation[i] = s.fTranslation[i];
83 fLayMedia[i] = s.fLayMedia[i];
84 fLayColor[i] = s.fLayColor[i];
88 //________________________________________________________________________
89 AliITSv11GeomCableFlat& AliITSv11GeomCableFlat::
90 operator=(const AliITSv11GeomCableFlat &s) {
91 // Assignment operator
92 // Not fully inplemented yet !!!
94 if(&s == this) return *this;
99 for (Int_t i=0; i<s.fNlayer; i++) {
100 fLayThickness[i] = s.fLayThickness[i];
101 fTranslation[i] = s.fTranslation[i];
102 fLayMedia[i] = s.fLayMedia[i];
103 fLayColor[i] = s.fLayColor[i];
108 //________________________________________________________________________
109 Int_t AliITSv11GeomCableFlat::GetPoint( Int_t iCheckPt, Double_t *coord)
111 // Get the correct point #iCheckPt
112 TVectorD *coordVector =(TVectorD *)fPointArray.At(2*iCheckPt);
114 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
115 CopyFrom(coord, coordVector->GetElements());
117 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());
145 //________________________________________________________________________
146 void AliITSv11GeomCableFlat::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt,
147 Double_t *coord, Double_t *orthVect)
150 // Add a check point. In the fPointArray, the point is at i and its vector
154 // if (iCheckPt>=fVolumeArray.GetEntriesFast()) {
155 // fVolumeArray.AddLast(vol);
156 // TVectorD *point = new TVectorD(3,coord);
157 // TVectorD *vect = new TVectorD(3,orthVect);
158 // fPointArray.AddLast(point);
159 // fPointArray.AddLast(vect);
161 // } else if ((iCheckPt >= 0)&&(iCheckPt < fVolumeArray.GetEntriesFast())) {
162 // fVolumeArray.AddAt(vol, iCheckPt);
163 // TVectorD *point = new TVectorD(3,coord);
164 // TVectorD *vect = new TVectorD(3,orthVect);
165 // fPointArray.AddAt(point, iCheckPt*2 );
166 // fPointArray.AddAt(vect, iCheckPt*2+1);
168 fVolumeArray.AddAtAndExpand(vol, iCheckPt);
169 TVectorD *point = new TVectorD(3,coord);
170 TVectorD *vect = new TVectorD(3,orthVect);
171 fPointArray.AddAtAndExpand(point, iCheckPt*2 );
172 fPointArray.AddAtAndExpand(vect, iCheckPt*2+1);
175 //________________________________________________________________________
176 void AliITSv11GeomCableFlat::PrintCheckPoints() const {
177 // print all check points of the cable
178 printf(" ---\n Printing all check points of the flat cable\n");
179 for (Int_t i = 0; i<fVolumeArray.GetEntriesFast(); i++) {
181 if (GetPoint( i, coord))
182 printf(" ( %.2f, %.2f, %.2f )\n", coord[0], coord[1], coord[2]);
186 //________________________________________________________________________
187 Int_t 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 kFALSE;
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 kFALSE;
271 if (! GetCheckVect(p1, 0, 0, vect1) ) return kFALSE;
274 //=================================================
275 // Get p2 position in the systeme of p2
276 if (! GetCheckPoint(p2, 0, 0, coord2) ) return kFALSE;
277 if (! GetCheckVect(p2, 0, 0, vect2) ) return kFALSE;
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 Double_t angleRotZ = 0;
304 TGeoRotation rotTemp("",angleRot1*TMath::RadToDeg(),
305 angleRotDiag*TMath::RadToDeg(), rotation);
306 Double_t localX[3] = {0,1,0};
308 rotTemp.LocalToMasterVect(localX, globalX);
309 CopyFrom(localX, globalX);
310 GetCheckVect(localX, p2Vol, 0, fgkCableMaxNodeLevel+1, globalX);
311 Double_t orthVect[3];
312 GetCheckVect(vect1, p2Vol, 0, fgkCableMaxNodeLevel+1, orthVect);
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};
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))
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);
353 TGeoRotation rotArbSeg("", 0, 90, 0);
354 rotArbSeg.MultiplyBy(&rot, kFALSE);
355 TGeoTranslation trans("",cx, cy, cz);
356 TGeoCombiTrans *combiB = new TGeoCombiTrans(trans, rotArbSeg);
357 p2Vol->AddNode(vCableSegB, p2, combiB);
358 //=================================================;
361 printf("---\n Cable segment points : ");
362 printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]);
363 printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]);
366 // #include <TGeoSphere.h>
367 // TGeoMedium *airSDD = gGeoManager->GetMedium("ITS_ITSsddAir");
368 // TGeoSphere *sphere = new TGeoSphere(0, 0.05);
369 // TGeoVolume *vSphere = new TGeoVolume("", sphere, airSDD);
370 // TGeoTranslation *trC = new TGeoTranslation("", cx, cy, cz);
371 // TGeoTranslation *tr1 = new TGeoTranslation("",coord1[0],
372 // coord1[1],coord1[2]);
373 // TGeoTranslation *tr2 = new TGeoTranslation("",coord2[0],
374 // coord2[1],coord2[2]);
375 // p2Vol->AddNode(vSphere, p2*3-2, trC);
376 // p2Vol->AddNode(vSphere, p2*3-1, tr1);
377 // p2Vol->AddNode(vSphere, p2*3 , tr2);
382 //________________________________________________________________________
383 TGeoVolume *AliITSv11GeomCableFlat::CreateSegment( Double_t *coord1,
385 Double_t *localVect1,
386 Double_t *localVect2 )
389 //=================================================
390 // Calculate segment "deformation"
391 Double_t dx = coord2[0]-coord1[0];
392 Double_t dy = coord2[1]-coord1[1];
393 Double_t dz = coord2[2]-coord1[2];
394 Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz);
396 Double_t cosTheta1 = -1./TMath::Sqrt( 1 + localVect1[0]*localVect1[0]
397 /localVect1[2]/localVect1[2] );
398 Double_t cosTheta2 = 1./TMath::Sqrt( 1 + localVect2[0]*localVect2[0]
399 /localVect2[2]/localVect2[2] );
400 if (localVect1[2]<0) cosTheta1 = -cosTheta1;
401 if (localVect2[2]<0) cosTheta2 = -cosTheta2;
403 Double_t dL1 = 0.5*fWidth*TMath::Tan(TMath::ACos(cosTheta1));
404 Double_t dL2 = 0.5*fWidth*TMath::Tan(TMath::ACos(cosTheta2));
405 if (localVect1[0]<0) dL1 = - dL1;
406 if (localVect2[0]<0) dL2 = - dL2;
408 Double_t cosPhi1 = -1./TMath::Sqrt( 1 + localVect1[1]*localVect1[1]
409 /localVect1[2]/localVect1[2] );
410 Double_t cosPhi2 = 1./TMath::Sqrt( 1 + localVect2[1]*localVect2[1]
411 /localVect2[2]/localVect2[2] );
412 if (localVect1[2]<0) cosPhi1 = -cosPhi1;
413 if (localVect2[2]<0) cosPhi2 = -cosPhi2;
415 Double_t tanACosCosPhi1 = TMath::Tan(TMath::ACos(cosPhi1));
416 Double_t tanACosCosPhi2 = TMath::Tan(TMath::ACos(cosPhi2));
417 if (localVect1[1]<0) tanACosCosPhi1 = -tanACosCosPhi1;
418 if (localVect2[1]<0) tanACosCosPhi2 = -tanACosCosPhi2;
420 Double_t dl1 = 0.5*fThick*tanACosCosPhi1;
421 Double_t dl2 = 0.5*fThick*tanACosCosPhi2;
423 //=================================================
424 // Create the segment
425 TGeoArb8 *cableSeg = new TGeoArb8(fThick/2);
426 cableSeg->SetVertex( 0, -fWidth/2, -length/2 - dL1 + dl1);
427 cableSeg->SetVertex( 1, -fWidth/2, length/2 + dL2 - dl2);
428 cableSeg->SetVertex( 2, fWidth/2, length/2 - dL2 - dl2);
429 cableSeg->SetVertex( 3, fWidth/2, -length/2 + dL1 + dl1);
430 cableSeg->SetVertex( 4, -fWidth/2, -length/2 - dL1 - dl1);
431 cableSeg->SetVertex( 5, -fWidth/2, length/2 + dL2 + dl2);
432 cableSeg->SetVertex( 6, fWidth/2, length/2 - dL2 + dl2);
433 cableSeg->SetVertex( 7, fWidth/2, -length/2 + dL1 - dl1);
435 TGeoMedium *airSDD = gGeoManager->GetMedium("ITS_ITSair");
436 TGeoVolume *vCableSeg = new TGeoVolume(GetName(), cableSeg, airSDD);
438 // add all cable layers
439 for (Int_t iLay=0; iLay<fNlayer; iLay++) {
441 Double_t dl1Lay = 0.5*fLayThickness[iLay]*tanACosCosPhi1;
442 Double_t dl2Lay = 0.5*fLayThickness[iLay]*tanACosCosPhi2;
444 Double_t ztr = -fThick/2;
445 for (Int_t i=0;i<iLay; i++) ztr+= fLayThickness[i];
446 ztr+= fLayThickness[iLay]/2;
448 Double_t dl1LayS = ztr*tanACosCosPhi1;
449 Double_t dl2LayS = ztr*tanACosCosPhi2;
451 TGeoArb8 *lay = new TGeoArb8(fLayThickness[iLay]/2);
452 lay->SetVertex( 0, -fWidth/2, -length/2 - dL1 + dl1Lay - dl1LayS);
453 lay->SetVertex( 1, -fWidth/2, length/2 + dL2 - dl2Lay + dl2LayS);
454 lay->SetVertex( 2, fWidth/2, length/2 - dL2 - dl2Lay + dl2LayS);
455 lay->SetVertex( 3, fWidth/2, -length/2 + dL1 + dl1Lay - dl1LayS);
456 lay->SetVertex( 4, -fWidth/2, -length/2 - dL1 - dl1Lay - dl1LayS);
457 lay->SetVertex( 5, -fWidth/2, length/2 + dL2 + dl2Lay + dl2LayS);
458 lay->SetVertex( 6, fWidth/2, length/2 - dL2 + dl2Lay + dl2LayS);
459 lay->SetVertex( 7, fWidth/2, -length/2 + dL1 - dl1Lay - dl1LayS);
460 TGeoVolume *vLay = new TGeoVolume("vCableSegLay", lay, fLayMedia[iLay]);
461 vLay->SetLineColor(fLayColor[iLay]);
463 if (fTranslation[iLay]==0)
464 fTranslation[iLay] = new TGeoTranslation(0, 0, ztr);
465 vCableSeg->AddNode(vLay, iLay+1, fTranslation[iLay]);
468 //vCableSeg->SetVisibility(kFALSE);
473 //________________________________________________________________________
474 void AliITSv11GeomCableFlat::SetNLayers(Int_t nLayers) {
475 // Set the number of layers
476 if((nLayers>0) &&(nLayers<=fgkCableMaxLayer)) {
479 for (Int_t i=0; i<fgkCableMaxLayer ; i++) {
480 fLayThickness[i] = 0;
488 //________________________________________________________________________
489 Int_t AliITSv11GeomCableFlat::SetLayer(Int_t nLayer, Double_t thick,
490 TGeoMedium *medium, Int_t color) {
491 // Set the layer number nLayer
492 if ((nLayer<0)||(nLayer>=fNlayer)) {
493 printf("Set wrong layer number of the cable\n");
497 if (fLayThickness[nLayer-1]<=0) {
498 printf("AliITSv11GeomCableFlat::SetLayer():"
499 " You must define cable layer %i first !",nLayer-1);
503 Double_t thickTot = 0;
504 for (Int_t i=0; i<nLayer; i++) thickTot += fLayThickness[i];
506 if (thickTot-1e-10>fThick) {
507 printf("Can't add this layer, cable thickness would be higher than total\n");
511 fLayThickness[nLayer] = thick;
512 fLayMedia[nLayer] = medium;
513 fLayColor[nLayer] = color;
514 fTranslation[nLayer] = 0;