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