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