]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSv11GeomCableRound.cxx
Backward compatibility (T.Kuhr)
[u/mrichter/AliRoot.git] / ITS / AliITSv11GeomCableRound.cxx
CommitLineData
b7943f00 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16
17
18// General Root includes
19//#include <Riostream.h>
20#include <TMath.h>
21#include <TVectorD.h>
22
23// Root Geometry includes
24#include <TGeoManager.h>
25#include <TGeoVolume.h>
26#include <TGeoTube.h>
27#include <TGeoMatrix.h>
28
29#include "AliITSv11GeomCableRound.h"
30
31//*************************************************************************
32// Class for round cables
33//
34// Ludovic Gaudichet gaudichet@to.infn.it
35//*************************************************************************
36
37ClassImp(AliITSv11GeomCableRound)
38
39//________________________________________________________________________
40AliITSv11GeomCableRound::
41AliITSv11GeomCableRound(const char* name, Double_t radius) :
42AliITSv11GeomCable(name) {
43 // Constructor
44 fRadius = radius;
45 fNlayer = 0;
46 for (Int_t i=0; i<fgkCableMaxLayer ; i++) {
47 fLayThickness[i] = 0;
48 fLayColor[i] = 0;
49 fLayMedia[i] = 0;
50 };
51 fPhiMin = 0;
52 fPhiMax = 360;
53};
54
55//________________________________________________________________________
56AliITSv11GeomCableRound::AliITSv11GeomCableRound(const AliITSv11GeomCableRound &s) :
57 AliITSv11GeomCable(s),fRadius(s.fRadius),fNlayer(s.fNlayer),fPhiMin(s.fPhiMin),
58 fPhiMax(s.fPhiMax)
59{
60 // Copy Constructor
61 for (Int_t i=0; i<s.fNlayer; i++) {
62 fLayThickness[i] = s.fLayThickness[i];
63 fLayMedia[i] = s.fLayMedia[i];
64 fLayColor[i] = s.fLayColor[i];
65 }
66}
67
68//________________________________________________________________________
69AliITSv11GeomCableRound& AliITSv11GeomCableRound::
70operator=(const AliITSv11GeomCableRound &s) {
71 // Assignment operator
72 // Not fully inplemented yet !!!
73
74 if(&s == this) return *this;
75 *this = s;
76 fRadius = s.fRadius;
77 fPhiMin = s.fPhiMin;
78 fPhiMax = s.fPhiMax;
79 fNlayer = s.fNlayer;
80 for (Int_t i=0; i<s.fNlayer; i++) {
81 fLayThickness[i] = s.fLayThickness[i];
82 fLayMedia[i] = s.fLayMedia[i];
83 fLayColor[i] = s.fLayColor[i];
84 };
85 return *this;
86}
87
88//________________________________________________________________________
89Int_t AliITSv11GeomCableRound::GetPoint( Int_t iCheckPt, Double_t *coord)
90 const {
91 // Get check point #iCheckPt
92 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(2*iCheckPt);
99d29480 93#if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
94 CopyFrom(coord, coordVector->GetElements());
95#else
b7943f00 96 CopyFrom(coord, coordVector->GetMatrixArray());
99d29480 97#endif
b7943f00 98 return kTRUE;
99};
100
101//________________________________________________________________________
102Int_t AliITSv11GeomCableRound::GetVect( Int_t iCheckPt, Double_t *coord)
103 const {
104 //
105 // Get vector transverse to the section at point #iCheckPt
106 //
107
108 TVectorD *coordVector =(TVectorD *)fPointArray.UncheckedAt(2*iCheckPt+1);
99d29480 109#if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
110 CopyFrom(coord, coordVector->GetElements());
111#else
b7943f00 112 CopyFrom(coord, coordVector->GetMatrixArray());
99d29480 113#endif
b7943f00 114 return kTRUE;
115};
116//________________________________________________________________________
117void AliITSv11GeomCableRound::AddCheckPoint( TGeoVolume *vol, Int_t iCheckPt,
118 Double_t *coord, Double_t *orthVect)
119{
120 //
121 // Add point #iCheckPt and its transverse vector. Point is added at (i) in
122 // fPointArray and the vector is added at (i+1)
123 //
124
125
126 if (iCheckPt>=fVolumeArray.GetEntriesFast()) {
127 fVolumeArray.AddLast(vol);
128 TVectorD *point = new TVectorD(3,coord);
129 TVectorD *vect = new TVectorD(3,orthVect);
130 fPointArray.AddLast(point);
131 fPointArray.AddLast(vect);
132
133 } else if ((iCheckPt >= 0)&&(iCheckPt < fVolumeArray.GetEntriesFast())) {
134 fVolumeArray.AddAt(vol, iCheckPt);
135 TVectorD *point = new TVectorD(3,coord);
136 TVectorD *vect = new TVectorD(3,orthVect);
137 fPointArray.AddAt(point, iCheckPt*2 );
138 fPointArray.AddAt(vect, iCheckPt*2+1);
139 };
140};
141
142//________________________________________________________________________
143void AliITSv11GeomCableRound::PrintCheckPoints() const {
144 // Print all check points
145
146 printf(" ---\n Printing all check points of the round cable\n");
147 for (Int_t i = 0; i<fVolumeArray.GetEntriesFast(); i++) {
148 TVectorD *coordVector = (TVectorD *)fPointArray.UncheckedAt(i*2);
149 //TVectorD *vectVector = (TVectorD *)fPointArray.UncheckedAt(i*2+1);
150 Double_t coord[3];
99d29480 151#if ROOT_VERSION_CODE < ROOT_VERSION(4,0,0)
152 CopyFrom(coord, coordVector->GetElements());
153#else
b7943f00 154 CopyFrom(coord, coordVector->GetMatrixArray());
99d29480 155#endif
b7943f00 156
157 printf(" ( %.2f, %.2f, %.2f )\n", coord[0], coord[1], coord[2]);
158 };
159
160};
161
162//________________________________________________________________________
163Int_t AliITSv11GeomCableRound::CreateAndInsertCableSegment(Int_t p2)
164{
165// Creates a cable segment between points p1 and p2.
166// Rotation is the eventual rotation of the flat cable
167// along its length axis
168//
169// The segment volume is created inside the volume containing point2
170// Therefore this segment should be defined in this volume only.
171// I mean here that, if the previous point is in another volume,
172// it should be just at the border between the 2 volumes. Also the
173// orientation vector of the previous point should be othogonal to
174// the surface between the 2 volumes.
175
176 TGeoNode *mainNode;
177 if (fInitialNode==0) {
178 TObjArray *nodes = gGeoManager->GetListOfNodes();
179 if (nodes->GetEntriesFast()==0) return kFALSE;
180 mainNode = (TGeoNode *) nodes->UncheckedAt(0);
181 } else {
182 mainNode = fInitialNode;
183 };
184
185 Int_t p1 = p2 - 1;
186 TGeoVolume *p1Vol = GetVolume(p1);
187 TGeoVolume *p2Vol = GetVolume(p2);
188
189 ResetCheckDaughter();
190 fCurrentVol = p1Vol;
191 if (! CheckDaughter(mainNode)) {
192 printf("Error::volume containing point is not visible in node tree!\n");
193 return kFALSE;
194 };
195
196 Double_t coord1[3], coord2[3], vect1[3], vect2[3];
197 //=================================================
198 // Get p1 position in the systeme of p2
199 if (p1Vol!=p2Vol) {
200
201 Int_t p1nodeInd[fgkCableMaxNodeLevel];
202 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p1nodeInd[i]=fNodeInd[i];
203 Int_t p1volLevel = 0;
204 while (p1nodeInd[p1volLevel]!=-1) p1volLevel++;
205 p1volLevel--;
206
207 ResetCheckDaughter();
208 fCurrentVol = p2Vol;
209 if (! CheckDaughter(mainNode)) {
210 printf("Error::volume containing point is not visible in node tree!\n");
211 return kFALSE;
212 };
213 Int_t p2nodeInd[fgkCableMaxNodeLevel];
214 for (Int_t i=0; i<fgkCableMaxNodeLevel; i++) p2nodeInd[i]=fNodeInd[i];
215 Int_t commonMotherLevel = 0;
216 while (p1nodeInd[commonMotherLevel]==fNodeInd[commonMotherLevel])
217 commonMotherLevel++;
218 commonMotherLevel--;
219 Int_t p2volLevel = 0;
220 while (fNodeInd[p2volLevel]!=-1) p2volLevel++;
221 p2volLevel--;
222
223 // Get coord and vect of p1 in the common mother reference system
224 GetCheckPoint(p1, 0, p1volLevel-commonMotherLevel, coord1);
225 GetCheckVect( p1, 0, p1volLevel-commonMotherLevel, vect1);
226 // Translate them in the reference system of the volume containing p2
227 TGeoNode *pathNode[fgkCableMaxNodeLevel];
228 pathNode[0] = mainNode;
229 for (Int_t i=0; i<=p2volLevel; i++) {
230 pathNode[i+1] = pathNode[i]->GetDaughter(p2nodeInd[i]);
231 };
232 Double_t globalCoord1[3] = {coord1[0], coord1[1], coord1[2]};
233 Double_t globalVect1[3] = {vect1[0], vect1[1], vect1[2]};
234
235 for (Int_t i = commonMotherLevel+1; i<=p2volLevel; i++) {
236 pathNode[i+1]->GetMatrix()->MasterToLocal(globalCoord1, coord1);
237 pathNode[i+1]->GetMatrix()->MasterToLocalVect(globalVect1, vect1);
238 CopyFrom(globalCoord1, coord1);
239 CopyFrom(globalVect1, vect1);
240 };
241 } else {
242 GetCheckPoint(p1, 0, 0, coord1);
243 GetCheckVect(p1, 0, 0, vect1);
244 };
245
246 //=================================================
247 // Get p2 position in the systeme of p2
248 GetCheckPoint(p2, 0, 0, coord2);
249 GetCheckVect(p2, 0, 0, vect2);
250
251 Double_t cx = (coord1[0]+coord2[0])/2;
252 Double_t cy = (coord1[1]+coord2[1])/2;
253 Double_t cz = (coord1[2]+coord2[2])/2;
254 Double_t dx = coord2[0]-coord1[0];
255 Double_t dy = coord2[1]-coord1[1];
256 Double_t dz = coord2[2]-coord1[2];
257
258 //=================================================
259 // Positionning of the segment between the 2 points
260 if ((dy<1e-31)&&(dy>0)) dy = 1e-31;
261 if ((dz<1e-31)&&(dz>0)) dz = 1e-31;
262 if ((dy>-1e-31)&&(dy<0)) dy = -1e-31;
263 if ((dz>-1e-31)&&(dz<0)) dz = -1e-31;
264
265 Double_t angleRot1 = -TMath::ATan2(dx,dy);
266 Double_t planDiagL = TMath::Sqrt(dy*dy+dx*dx);
267 Double_t angleRotDiag = -TMath::ATan2(planDiagL,dz);
268 TGeoRotation *rot = new TGeoRotation("",angleRot1*TMath::RadToDeg(),
269 angleRotDiag*TMath::RadToDeg(),
270 0);
271 Double_t localVect1[3], localVect2[3];
272 rot->MasterToLocalVect(vect1, localVect1);
273 rot->MasterToLocalVect(vect2, localVect2);
274 TGeoTranslation *trans = new TGeoTranslation("",cx, cy, cz);
275
276 //=================================================
277 // Create the segment and add it to the mother volume
278 TGeoVolume *vCableSeg = CreateSegment(coord1, coord2,
279 localVect1, localVect2);
280
281 TGeoCombiTrans *combi = new TGeoCombiTrans(*trans, *rot);
282 p2Vol->AddNode(vCableSeg, p2, combi);
283 //=================================================
284 delete rot;
285 delete trans;
286
287 if (fDebug) {
288 printf("---\n Cable segment points : ");
289 printf("%f, %f, %f\n",coord1[0], coord1[1], coord1[2]);
290 printf("%f, %f, %f\n",coord2[0], coord2[1], coord2[2]);
291 };
292// #include <TGeoSphere.h>
293// TGeoMedium *airSDD = gGeoManager->GetMedium("ITSsddAir");
294// TGeoSphere *sphere = new TGeoSphere(0, 0.15);
295// TGeoVolume *vSphere = new TGeoVolume("", sphere, airSDD);
296// TGeoTranslation *trC = new TGeoTranslation("", cx, cy, cz);
297// TGeoTranslation *tr1 = new TGeoTranslation("",coord1[0],
298// coord1[1],coord1[2]);
299// TGeoTranslation *tr2 = new TGeoTranslation("",coord2[0],
300// coord2[1],coord2[2]);
301// p2Vol->AddNode(vSphere, p2*3-2, trC);
302// p2Vol->AddNode(vSphere, p2*3-1, tr1);
303// p2Vol->AddNode(vSphere, p2*3 , tr2);
304
305 return kTRUE;
306};
307
308//________________________________________________________________________
309TGeoVolume *AliITSv11GeomCableRound::CreateSegment( Double_t *coord1,
310 Double_t *coord2,
311 Double_t *localVect1,
312 Double_t *localVect2 )
313{
314
315 //=================================================
316 // Calculate segment "deformation"
317 Double_t dx = coord2[0]-coord1[0];
318 Double_t dy = coord2[1]-coord1[1];
319 Double_t dz = coord2[2]-coord1[2];
320 Double_t length = TMath::Sqrt(dx*dx+dy*dy+dz*dz);
321
322 // normal vectors have to point outside the TGeoCtub :
323 if (-localVect1[2]<0) {
324 localVect1[0] = -localVect1[0];
325 localVect1[1] = -localVect1[1];
326 localVect1[2] = -localVect1[2];
327 };
328 if (localVect2[2]<0) {
329 localVect2[0] = -localVect2[0];
330 localVect2[1] = -localVect2[1];
331 localVect2[2] = -localVect2[2];
332 };
333 //=================================================
334 // Create the segment
335 TGeoCtub *cableSeg = new TGeoCtub(0., fRadius, length/2, fPhiMin, fPhiMax,
336 localVect1[0],localVect1[1],localVect1[2],
337 localVect2[0],localVect2[1],localVect2[2]);
338
339 TGeoMedium *airSDD = gGeoManager->GetMedium("ITSair");
340 TGeoVolume *vCableSeg = new TGeoVolume(GetName(), cableSeg, airSDD);
341
342 // add all cable layers
343 Double_t layThickness[100+1]; // 100 layers max !!!
344 layThickness[0] = 0;
345 for (Int_t iLay=0; iLay<fNlayer; iLay++) {
346
347 layThickness[iLay+1] = fLayThickness[iLay]+layThickness[iLay];
348 TGeoCtub *lay = new TGeoCtub(layThickness[iLay], layThickness[iLay+1],
349 length/2, fPhiMin, fPhiMax,
350 localVect1[0],localVect1[1],localVect1[2],
351 localVect2[0],localVect2[1],localVect2[2]);
352
353 TGeoVolume *vLay = new TGeoVolume("vCableSegLay", lay, fLayMedia[iLay]);
354 vLay->SetLineColor(fLayColor[iLay]);
355 vCableSeg->AddNode(vLay, iLay+1, 0);
356 };
357
358 vCableSeg->SetVisibility(kFALSE);
359 return vCableSeg;
360};
361
362
363//________________________________________________________________________
364void AliITSv11GeomCableRound::SetNLayers(Int_t nLayers) {
365 // Set the total number of layers
366 if((nLayers>0) &&(nLayers<=fgkCableMaxLayer)) {
367 fNlayer = nLayers;
368 for (Int_t i = 0; i<fNlayer; i++) {
369 fLayThickness[i] = 0;
370 fLayMedia[i] = 0;
371 };
372 };
373};
374
375//________________________________________________________________________
376Int_t AliITSv11GeomCableRound::SetLayer(Int_t nLayer, Double_t thick,
377 TGeoMedium *medium, Int_t color) {
378 // Set layer #nLayer
379 if ((nLayer<0)||(nLayer>=fNlayer)) {
380 printf("Set wrong layer number of the cable\n");
381 return kFALSE;
382 };
383 if (nLayer>0)
384 if (fLayThickness[nLayer-1]<=0) {
385 printf("You must define cable layer %i first !",nLayer-1);
386 return kFALSE;
387 };
388
389 Double_t thickTot = 0;
390 for (Int_t i=0; i<nLayer; i++) thickTot += fLayThickness[i];
391 thickTot += thick;
392 if (thickTot-1e-10>fRadius) {
393 printf("Can't add this layer, cable thickness would be higher than total\n");
394 return kFALSE;
395 };
396
397 fLayThickness[nLayer] = thick;
398 fLayMedia[nLayer] = medium;
399 fLayColor[nLayer] = color;
400
401 return kTRUE;
402};