]> git.uio.no Git - u/mrichter/AliRoot.git/blame - AliGeant3/AliNode.cxx
Bugfix in AliPoints2Memory
[u/mrichter/AliRoot.git] / AliGeant3 / AliNode.cxx
CommitLineData
a524cc6b 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$Log$
18Revision 1.1 2001/07/09 11:44:01 morsch
19Node class derived from TNode to allow expansion of volume divisions.
20
21*/
22
23
24#include "AliNode.h"
25#include "TShape.h"
26#include "TTUBE.h"
27#include "TBRIK.h"
28#include "TTRD1.h"
29#include "TTRD2.h"
30#include "TTRAP.h"
31#include "TTUBS.h"
32#include "TCONE.h"
33#include "TCONS.h"
34#include "TSPHE.h"
35#include "TPARA.h"
36#include "TPGON.h"
37#include "TPCON.h"
38#include "TTUBS.h"
39#include "TELTU.h"
40#include "THYPE.h"
41#include "TGTRA.h"
42#include "TCTUB.h"
43
44ClassImp(AliNode)
45 AliNode::AliNode(const char* name, const char* title, const char* shapename,
46 Double_t x, Double_t y, Double_t z, const char* matrixname,
47 Option_t* option) :
48 TNode(name, title, shapename, x, y, z, matrixname, option)
49{
50 fNDivision = -1;
51 fAxis = 0;
52 fStartC = 0.;
53 fStep = 0.;
54}
55
56 AliNode::AliNode(const char* name, const char* title, TShape* shape,
57 Double_t x, Double_t y, Double_t z, TRotMatrix* matrix,
58 Option_t* option) :
59 TNode(name, title, shape, x, y, z, matrix, option)
60{
61 fNDivision = -1;
62 fAxis = 0;
63 fStartC = 0.;
64 fStep = 0.;
65}
66
67void AliNode::SetDivision(Int_t ndiv, Int_t axis, Float_t start, Float_t step)
68{
69 fNDivision = ndiv;
70 fAxis = axis;
71 fStartC = start;
72 fStep = step;
73}
74
75void AliNode::ExpandDivisions()
76{
77 Int_t i;
78 char vName[20];
79 char nName[20];
80
81 char tmp[4];
82 AliNode* node;
83 TShape* parent = fParent->GetShape();
84 TShape* newsh;
85
86 strcpy(tmp, parent->GetTitle());
87 Int_t ndiv = fNDivision;
88
89// TUBE
90
91 if (strcmp(tmp, "TUBE")==0) {
92 TTUBE * shape = (TTUBE*) parent;
93
94 Float_t dZ = shape->GetDz();
95 Float_t rMin = shape->GetRmin();
96 Float_t rMax = shape->GetRmax();
97
98 if (fAxis == 1) {
99// radial-division
100 Float_t dr = (rMax-rMin)/Float_t(fNDivision);
101 Float_t r1, r2;
102 for (i=0; i<ndiv; i++) {
103 r1 = rMin+Float_t(i)*dr;
104 r2 = r1+dr;
105 sprintf(vName, "%sD%d", fShape->GetName(), i);
106 sprintf(nName, "%sD%d", GetName(), i);
107 newsh = new TTUBE(vName, "TUBE", "void", r1, r2, dZ);
108 fParent->cd();
109 node = new AliNode(nName,"", newsh, 0., 0., 0.);
110 node->AddSons(fNodes);
111 cd();
112 }
113
114 } else if (fAxis == 2) {
115// phi-division
116 Float_t dPhi = 360./Float_t(fNDivision);
117 Float_t phi1, phi2;
118 for (i=0; i<ndiv; i++) {
119 phi1 = Float_t(i)*dPhi;
120 phi2 = phi1+dPhi;
121 sprintf(vName, "%sD%d", fShape->GetName(), i);
122 sprintf(nName, "%sD%d", GetName(), i);
123 newsh = new TTUBS(vName, "TUBS", "void", rMin, rMax, dZ, phi1, phi2);
124 fParent->cd();
125 node = new AliNode(nName, "", newsh, 0., 0., 0.);
126 node->AddSons(fNodes);
127 cd();
128 }
129 } else {
130// z-division
131 Float_t delZ = dZ/Float_t(fNDivision);
132 for (i=0; i<ndiv; i++) {
133 sprintf(vName, "%sD%d", fShape->GetName(), i);
134 sprintf(nName, "%sD%d", GetName(), i);
135 newsh = new TTUBE(vName, "TUBE", "void", rMin, rMax, delZ);
136 fParent->cd();
137 Float_t zpos = -dZ+delZ*(2.*Float_t(i)+1.);
138 node = new AliNode(nName, "",newsh, 0., 0., zpos);
139 node->AddSons(fNodes);
140 cd();
141 }
142 }
143//
144// TUBS
145//
146 } else if (strcmp(tmp, "TUBS")==0) {
147 TTUBS * shape = (TTUBS*) parent;
148 Float_t dZ = shape->GetDz();
149 Float_t rMin = shape->GetRmin();
150 Float_t rMax = shape->GetRmax();
151 Float_t phi1 = shape->GetPhi1();
152 Float_t phi2 = shape->GetPhi2();
153
154 if (fAxis == 1) {
155// radial-division
156 Float_t dr = (rMax-rMin)/Float_t(fNDivision);
157 Float_t r1, r2;
158 Int_t ndiv = fNDivision;
159 for (i=0; i<ndiv; i++) {
160 r1 = rMin+Float_t(i)*dr;
161 r2 = r1+dr;
162 sprintf(vName, "%sD%d", fShape->GetName(), i);
163 sprintf(nName, "%sD%d", GetName(), i);
164 newsh = new TTUBS(vName, "TUBS", "void", r1, r2, dZ, phi1, phi2);
165 fParent->cd();
166 node = new AliNode(nName,"", newsh, 0., 0., 0.);
167 node->AddSons(fNodes);
168 cd();
169 }
170
171 } else if (fAxis == 2) {
172// phi-division
173 Float_t dPhi = (phi2-phi1)/Float_t(fNDivision);
174 Float_t nphi1, nphi2;
175
176 for (i=0; i<fNDivision; i++) {
177 nphi1 = phi1+Float_t(i)*dPhi;
178 nphi2 = nphi1+dPhi;
179 sprintf(vName, "%sD%d", fShape->GetName(), i);
180 sprintf(nName, "%sD%d", GetName(), i);
181
182 newsh = new TTUBS(vName, "TUBS", "void", rMin, rMax, dZ, nphi1, nphi2);
183 fParent->cd();
184 node = new AliNode(nName, "", newsh, 0., 0., 0.);
185 node->AddSons(fNodes);
186 cd();
187 }
188 } else {
189// z-division
190 Float_t delZ = dZ/Float_t(fNDivision);
191 for (i=0; i<ndiv; i++) {
192 sprintf(vName, "%sD%d", fShape->GetName(), i);
193 sprintf(nName, "%sD%d", GetName(), i);
194 newsh = new TTUBS(vName, "TUBS", "void", rMin, rMax, delZ, phi1, phi2);
195 fParent->cd();
196 Float_t zpos = -dZ+delZ*(2.*Float_t(i)+1.);
197 node = new AliNode(nName, "",newsh, 0., 0., zpos);
198 node->AddSons(fNodes);
199 cd();
200 }
201 }
202
203 } else if (strcmp(tmp, "CONE")==0) {
204 TCONE * shape = (TCONE*) parent;
205
206 Float_t dZ = shape->GetDz();
207 Float_t rMin1 = shape->GetRmin();
208 Float_t rMax1 = shape->GetRmax();
209 Float_t rMin2 = shape->GetRmin2();
210 Float_t rMax2 = shape->GetRmax2();
211
212 if (fAxis == 1) {
213// radial-division
214 Float_t dr1 = (rMax1-rMin1)/Float_t(fNDivision);
215 Float_t dr2 = (rMax2-rMin2)/Float_t(fNDivision);
216 Float_t r11, r12, r21, r22;
217 for (i=0; i<ndiv; i++) {
218 r11 = rMin1+Float_t(i)*dr1;
219 r12 = r11+dr1;
220 r21 = rMin2+Float_t(i)*dr2;
221 r22 = r21+dr2;
222
223 sprintf(vName, "%sD%d", fShape->GetName(), i);
224 sprintf(nName, "%sD%d", GetName(), i);
225 newsh = new TCONE(vName, "CONE", "void", dZ, r11, r12, r21, r22);
226 fParent->cd();
227 node = new AliNode(nName,"", newsh, 0., 0., 0.);
228 node->AddSons(fNodes);
229 cd();
230 }
231 } else if (fAxis == 2) {
232// phi-division
233 Float_t dPhi = 360./Float_t(fNDivision);
234 Float_t phi1, phi2;
235 for (i=0; i<ndiv; i++) {
236 phi1 = Float_t(i)*dPhi;
237 phi2 = phi1+dPhi;
238 sprintf(vName, "%sD%d", fShape->GetName(), i);
239 sprintf(nName, "%sD%d", GetName(), i);
240 newsh = new TCONS(vName, "CONS", "void", dZ, rMin1, rMax1,
241 rMin2, rMax2, phi1, phi2);
242 fParent->cd();
243 node = new AliNode(nName, "",newsh, 0., 0., 0.);
244 node->AddSons(fNodes);
245 cd();
246 }
247 } else {
248// z-division
249 Float_t delZ = dZ/Float_t(fNDivision);
250 for (i=0; i<ndiv; i++) {
251 sprintf(vName, "%sD%d", fShape->GetName(), i);
252 sprintf(nName, "%sD%d", GetName(), i);
253 newsh = new TCONE(vName, "CONE", "void", delZ, rMin1, rMax1, rMin2, rMax2);
254 fParent->cd();
255 Float_t zpos = -dZ+delZ*(2.*Float_t(i)+1.);
256 node = new AliNode(nName, "",newsh, 0., 0., zpos);
257 node->AddSons(fNodes);
258 cd();
259 }
260 }
261
262 } else if (strcmp(tmp, "CONS")==0) {
263 TCONS * shape = (TCONS*) parent;
264 Float_t dZ = shape->GetDz();
265 Float_t rMin1 = shape->GetRmin();
266 Float_t rMax1 = shape->GetRmax();
267 Float_t rMin2 = shape->GetRmin2();
268 Float_t rMax2 = shape->GetRmax2();
269 Float_t phi1 = shape->GetPhi1();
270 Float_t phi2 = shape->GetPhi2();
271 if (fAxis == 1) {
272// radial-division
273 Float_t dr1 = (rMax1-rMin1)/Float_t(fNDivision);
274 Float_t dr2 = (rMax2-rMin2)/Float_t(fNDivision);
275 Float_t r11, r12, r21, r22;
276 for (i=0; i<ndiv; i++) {
277 r11 = rMin1+Float_t(i)*dr1;
278 r12 = r11+dr1;
279 r21 = rMin2+Float_t(i)*dr2;
280 r22 = r21+dr2;
281
282 sprintf(vName, "%sD%d", fShape->GetName(), i);
283 sprintf(nName, "%sD%d", GetName(), i);
284 newsh = new TCONS(vName, "CONS", "void", dZ, r11, r12, r21, r22, phi1, phi2);
285 fParent->cd();
286 node = new AliNode(nName,"", newsh, 0., 0., 0.);
287 node->AddSons(fNodes);
288 cd();
289 }
290
291 } else if (fAxis == 2) {
292// phi-division
293 Float_t dPhi = (phi2-phi1)/Float_t(fNDivision);
294 Float_t nphi1, nphi2;
295
296 for (i=0; i<fNDivision; i++) {
297 nphi1 = phi1+Float_t(i)*dPhi;
298 nphi2 = nphi1+dPhi;
299 sprintf(vName, "%sD%d", fShape->GetName(), i);
300 sprintf(nName, "%sD%d", GetName(), i);
301
302 newsh = new TCONS(vName, "CONS", "void", dZ, rMin1, rMax1, rMin2, rMax2, nphi1, nphi2);
303 fParent->cd();
304 node = new AliNode(nName, "", newsh, 0., 0., 0.);
305 node->AddSons(fNodes);
306 cd();
307 }
308 } else {
309// z-division
310 Float_t delZ = dZ/Float_t(fNDivision);
311 for (i=0; i<ndiv; i++) {
312 sprintf(vName, "%sD%d", fShape->GetName(), i);
313 sprintf(nName, "%sD%d", GetName(), i);
314 newsh = new TCONS(vName, "CONS", "void", delZ, rMin1, rMax1, rMin2, rMax2, phi1, phi2);
315 fParent->cd();
316 Float_t zpos = -dZ+delZ*(2.*Float_t(i)+1.);
317 node = new AliNode(nName,"",newsh, 0., 0., zpos);
318 node->AddSons(fNodes);
319 cd();
320 }
321 }
322 } else if (strcmp(tmp, "BRIK")==0) {
323//
324// BRIK
325//
326 TBRIK * shape = (TBRIK*) parent;
327 Float_t dX = shape->GetDx();
328 Float_t dY = shape->GetDy();
329 Float_t dZ = shape->GetDz();
330
331 if (fAxis == 1) {
332// division in x
333 Float_t delX = dX/Float_t(fNDivision);
334 for (i=0; i<ndiv; i++) {
335 sprintf(vName, "%sD%d", fShape->GetName(), i);
336 sprintf(nName, "%sD%d", GetName(), i);
337 newsh = new TBRIK(vName, "BRIK", "void", delX, dY, dZ);
338 fParent->cd();
339 Float_t xpos = -dX+delX*(2.*Float_t(i)+1.);
340 node = new AliNode(nName,"",newsh, xpos, 0., 0.);
341 node->AddSons(fNodes);
342 cd();
343 }
344 } else if (fAxis == 2) {
345// division in y
346 Float_t delY = dY/Float_t(fNDivision);
347 for (i=0; i<ndiv; i++) {
348 sprintf(vName, "%sD%d", fShape->GetName(), i);
349 sprintf(nName, "%sD%d", GetName(), i);
350 newsh = new TBRIK(vName, "BRIK", "void", dX, delY, dZ);
351 fParent->cd();
352 Float_t ypos = -dY+delY*(2.*Float_t(i)+1.);
353 node = new AliNode(nName,"",newsh, 0., ypos, 0.);
354 node->AddSons(fNodes);
355 cd();
356 }
357 } else {
358// division in z
359 Float_t delZ = dZ/Float_t(fNDivision);
360 for (i=0; i<ndiv; i++) {
361 sprintf(vName, "%sD%d", fShape->GetName(), i);
362 sprintf(nName, "%sD%d", GetName(), i);
363 newsh = new TBRIK(vName, "BRIK", "void", dX, dY, delZ);
364 fParent->cd();
365 Float_t zpos = -dZ+delZ*(2.*Float_t(i)+1.);
366 node = new AliNode(nName,"",newsh, 0., 0., zpos);
367 node->AddSons(fNodes);
368 cd();
369 }
370 }
371 }
372}
373
374void AliNode::AddSons(TList* list)
375{
376 if (!list) return;
377 if (!fNodes) fNodes = new TList();
378
379 TIter next(list);
380 AliNode* node;
381
382 while((node = (AliNode*)next())) {
383 AliNode* newNode = new AliNode(*node, this);
384 fNodes->Add(newNode);
385 newNode->SetParent(this);
386 newNode->AddSons(node->GetListOfNodes());
387 }
388}
389
390
391AliNode::AliNode(const AliNode &node, AliNode* parent)
392{
393 fNDivision = node.Ndiv();
394 fAxis = node.Axis();
395 fStartC = node.StartC();
396 fStep = node.Step();
397 fName = node.GetName();
398 fTitle = node.GetTitle();
399 fX = node.GetX();
400 fY = node.GetY();
401 fZ = node.GetZ();
402 fMatrix = node.GetMatrix();
403 fNodes = 0;
404 fParent = parent;
405
406
407 if (fNDivision > 0) {
408 fShape = new TShape(*node.GetShape());
409 } else {
410 fShape = (TShape*) node.GetShape()->Clone();
411 }
412
413
414// fShape = (TShape*) shape->Clone();
415/*
416 char tmp[4];
417 strcpy(tmp, shape->ClassName());
418
419 if (strcmp(tmp, "TTUBE")==0)
420 fShape = (TTUBE*)shape->Clone();
421 else if (strcmp(tmp, "TBRIK")==0)
422 fShape = (TBRIK*)shape->Clone();
423 else if (strcmp(tmp, "TCONE")==0)
424 fShape = (TCONE*)shape->Clone();
425 else if (strcmp(tmp, "TCONS")==0)
426 fShape = (TCONS*)shape->Clone();
427 else if (strcmp(tmp, "TTUBS")==0)
428 fShape = (TTUBS*)shape->Clone();
429 else if (strcmp(tmp, "TTRAP")==0)
430 fShape = (TTRAP*)shape->Clone();
431 else if (strcmp(tmp, "TTRD1")==0)
432 fShape = (TTRD1*)shape->Clone();
433 else if (strcmp(tmp, "TTRD2")==0)
434 fShape = (TTRD2*)shape->Clone();
435 else if (strcmp(tmp, "TSPHE")==0)
436 fShape = (TSPHE*)shape->Clone();
437 else if (strcmp(tmp, "TPGON")==0)
438 fShape = (TPGON*)shape->Clone();
439 else if (strcmp(tmp, "TPCON")==0)
440 fShape = (TPCON*)shape->Clone();
441*/
442}
443
444void AliNode::AddSon(AliNode* node)
445{
446 fNodes->Add(node);
447}
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462