Geant4  10.02.p01
G3toG4MakeSolid.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G3toG4MakeSolid.cc 67982 2013-03-13 10:36:03Z gcosmo $
28 //
29 // modified by I.Hrivnacova, V.Berejnoi 27 Sep 99
30 
31 #include "globals.hh"
32 #include "G4SystemOfUnits.hh"
33 #include "G4Box.hh"
34 #include "G4Tubs.hh"
35 #include "G4Trd.hh"
36 #include "G4Trap.hh"
37 #include "G4Cons.hh"
38 #include "G4Sphere.hh"
39 #include "G3toG4.hh"
40 #include "G4Polycone.hh"
41 #include "G4Polyhedra.hh"
42 #include "G4Para.hh"
43 #include "G4Hype.hh"
44 #include "G4EllipticalTube.hh"
45 #include "G3toG4MakeSolid.hh"
46 
47 G4VSolid* G3toG4MakeSolid(const G4String& vname, const G4String& shape,
48  const G4double* rpar, const G4int npar,
49  G4bool& NegVolPars, G4bool& Deferred,
50  G4bool* OKAxis){
51 
52  // Create the solid if no negative length parameters
53  G4VSolid *solid = 0;
54 
55  NegVolPars = false;
56 
57  // if npar = 0 assume LV deferral
58  Deferred = (npar == 0);
59  // modified
60  if (Deferred) return solid;
61 
62  for (G4int i=0;i<3;i++){
63  OKAxis[i]=false;
64  };
65 
66  if ( shape == "BOX" ) {
67  G4double pX = rpar[0]*cm;
68  G4double pY = rpar[1]*cm;
69  G4double pZ = rpar[2]*cm;
70 
71  OKAxis[0]=OKAxis[1]=OKAxis[2]=true;
72 
73  NegVolPars = pX<0 || pY<0 || pZ<0;
74 
75  if (!(NegVolPars || Deferred)) {
76  solid = new G4Box(vname, pX, pY, pZ);
77  }
78 
79  } else if ( shape == "TRD1" ) {
80  G4double pdx1 = rpar[0]*cm;
81  G4double pdx2 = rpar[1]*cm;
82  G4double pdy1 = rpar[2]*cm;
83  G4double pdy2 = pdy1;
84  G4double pdz = rpar[3]*cm;
85 
86  OKAxis[1]=OKAxis[2]=true;
87 
88  NegVolPars = pdx1<0 || pdx2<0 || pdy1<0 || pdz<0;
89 
90  if (!(NegVolPars || Deferred)) {
91  solid = new G4Trd(vname, pdx1, pdx2, pdy1, pdy2, pdz);
92  }
93 
94  } else if ( shape == "TRD2" ) {
95  G4double pdx1 = rpar[0]*cm;
96  G4double pdx2 = rpar[1]*cm;
97  G4double pdy1 = rpar[2]*cm;
98  G4double pdy2 = rpar[3]*cm;
99  G4double pdz = rpar[4]*cm;
100 
101  OKAxis[2]=true;
102 
103  NegVolPars = pdx1<0 || pdx2<0 || pdy1<0 || pdy2<0 || pdz<0;
104 
105  if (!(NegVolPars || Deferred)) {
106  solid = new G4Trd(vname, pdx1, pdx2, pdy1, pdy2, pdz);
107  }
108 
109  } else if ( shape == "TRAP" ) {
110  G4double pDz = rpar[0]*cm;
111  G4double pTheta = rpar[1]*deg;
112  G4double pPhi = rpar[2]*deg;
113  G4double pDy1 = rpar[3]*cm;
114  G4double pDx1 = rpar[4]*cm;
115  G4double pDx2 = rpar[5]*cm;
116  G4double pAlp1 = rpar[6]*deg;
117  G4double pDy2 = rpar[7]*cm;
118  G4double pDx3 = rpar[8]*cm;
119  G4double pDx4 = rpar[9]*cm;
120  G4double pAlp2 = rpar[10]*deg;
121 
122  OKAxis[2]=true;
123 
124  NegVolPars= pDz<0 || pDy1<0 || pDx1<0 || pDx2<0 || pDy2<0 || pDx3<0 || pDx4<0;
125 
126  if (!(NegVolPars || Deferred)) {
127  // added for test only
128  if (!(pDz>0)) pDz += 0.001*cm;
129  if (!(pDy1>0)) pDy1 += 0.001*cm;
130  if (!(pDx1>0)) pDx1 += 0.001*cm;
131  if (!(pDx2>0)) pDx2 += 0.001*cm;
132  if (!(pDy2>0)) pDy2 += 0.001*cm;
133  if (!(pDx3>0)) pDx3 += 0.001*cm;
134  if (!(pDx4>0)) pDx4 += 0.001*cm;
135 
136  solid = new
137  G4Trap(vname, pDz, pTheta, pPhi, pDy1, pDx1, pDx2, pAlp1, pDy2, pDx3,
138  pDx4, pAlp2);
139  }
140 
141  } else if ( shape == "TUBE" ) {
142  G4double pRMin = rpar[0]*cm;
143  G4double pRMax = rpar[1]*cm;
144  G4double pDz = rpar[2]*cm;
145  G4double pSPhi = 0.*deg;
146  G4double pDPhi = 360.*deg;
147 
148  OKAxis[0]=OKAxis[1]=OKAxis[2]=true;
149 
150  NegVolPars = pRMin<0 || pRMax<0 || pDz<0;
151 
152  if (!(NegVolPars || Deferred)) {
153  solid = new G4Tubs(vname, pRMin, pRMax, pDz, pSPhi, pDPhi);
154  }
155 
156  } else if ( shape == "TUBS" ) {
157  G4double pRMin = rpar[0]*cm;
158  G4double pRMax = rpar[1]*cm;
159  G4double pDz = rpar[2]*cm;
160  G4double pSPhi = rpar[3]*deg;
161  G4double pDPhi = rpar[4]*deg - pSPhi;
162  if ( rpar[4]*deg <= pSPhi ) pDPhi = pDPhi + 360.*deg;
163 
164  OKAxis[0]=OKAxis[1]=OKAxis[2]=true;
165 
166  NegVolPars = pRMin<0 || pRMax<0 || pDz<0;
167 
168  if (!(NegVolPars || Deferred)){
169  solid = new G4Tubs(vname, pRMin, pRMax, pDz, pSPhi, pDPhi);
170  }
171 
172  } else if ( shape == "CONE" ) {
173  G4double pDz = rpar[0]*cm;
174  G4double pRmin1 = rpar[1]*cm;
175  G4double pRmax1 = rpar[2]*cm;
176  G4double pRmin2 = rpar[3]*cm;
177  G4double pRmax2 = rpar[4]*cm;
178  G4double pSPhi = 0.*deg;
179  G4double pDPhi = 360.*deg;
180 
181  OKAxis[0]=OKAxis[1]=OKAxis[2]=true;
182 
183  NegVolPars = pDz<0 || pRmin1<0 || pRmax1<0 || pRmin2<0 || pRmax2<0;
184 
185  if (!(NegVolPars || Deferred)){
186  solid = new
187  G4Cons(vname, pRmin1, pRmax1, pRmin2, pRmax2, pDz, pSPhi, pDPhi);
188  }
189 
190  } else if ( shape == "CONS" ) {
191  G4double pDz = rpar[0]*cm;
192  G4double pRmin1 = rpar[1]*cm;
193  G4double pRmax1 = rpar[2]*cm;
194  G4double pRmin2 = rpar[3]*cm;
195  G4double pRmax2 = rpar[4]*cm;
196  G4double pSPhi = rpar[5]*deg;
197  G4double pDPhi = rpar[6]*deg - pSPhi;
198  if ( rpar[6]*deg <= pSPhi ) pDPhi = pDPhi + 360.*deg;
199 
200  OKAxis[0]=OKAxis[1]=OKAxis[2]=true;
201 
202  NegVolPars = pDz<0 || pRmin1<0 || pRmax1<0 || pRmin2<0 || pRmax2<0;
203 
204  if (!(NegVolPars || Deferred)){
205  solid = new
206  G4Cons(vname, pRmin1, pRmax1, pRmin2, pRmax2, pDz, pSPhi, pDPhi);
207  }
208 
209  } else if ( shape == "SPHE" ) {
210  G4double pRmin = rpar[0]*cm;
211  G4double pRmax = rpar[1]*cm;
212  G4double pThe1 = rpar[2]*deg;
213  G4double pThe2 = rpar[3]*deg;
214  G4double pDThe = pThe2 - pThe1;
215  G4double pPhi1 = rpar[4]*deg;
216  G4double pPhi2 = rpar[5]*deg;
217  G4double pDPhi = pPhi2 - pPhi1;
218 
219  NegVolPars = pRmin<0 || pRmax<0;
220 
221  if (!(NegVolPars || Deferred)) {
222  solid = new G4Sphere(vname, pRmin, pRmax, pPhi1, pDPhi, pThe1, pDThe);
223  }
224 
225  } else if ( shape == "PARA" ) {
226  G4double pDx = rpar[0]*cm;
227  G4double pDy = rpar[1]*cm;
228  G4double pDz = rpar[2]*cm;
229  G4double pAlph = rpar[3]*deg;
230  G4double pThet = rpar[4]*deg;
231  G4double pPhi = rpar[5]*deg;
232 
233  OKAxis[0]=OKAxis[1]=OKAxis[2]=true;
234 
235  NegVolPars = pDx<0 || pDy<0 || pDz<0;
236 
237  if (!(NegVolPars || Deferred)){
238  solid = new G4Para(vname, pDx, pDy, pDz, pAlph, pThet, pPhi);
239  }
240 
241  } else if ( shape == "PGON" ) {
242  G4int i;
243  G4int npdv = G4int(rpar[2]);
244  G4int nz = G4int(rpar[3]);
245  G4double pPhi1 = rpar[0]*deg;
246  G4double dPhi = rpar[1]*deg;
247  G4double *DzArray = new G4double[nz];
248  G4double *Rmax = new G4double[nz];
249  G4double *Rmin = new G4double[nz];
250 
251  OKAxis[0]=OKAxis[1]=OKAxis[2]=true;
252 
253  NegVolPars = 0;
254 
255  for(i=0; i<nz; i++) {
256  G4int i4=3*i+4;
257  G4int i5=i4+1;
258  G4int i6=i4+2;
259  DzArray[i] = rpar[i4]*cm;
260  Rmin[i] = rpar[i5]*cm;
261  Rmax[i] = rpar[i6]*cm;
262  }
263  solid = new G4Polyhedra(vname, pPhi1, dPhi, npdv, nz, DzArray, Rmin, Rmax);
264  delete [] DzArray;
265  delete [] Rmin;
266  delete [] Rmax;
267 
268  } else if ( shape == "PCON" ) {
269  G4int i;
270  G4double pPhi1 = rpar[0]*deg;
271  G4double dPhi = rpar[1]*deg;
272  G4int nz = G4int(rpar[2]);
273  G4double *DzArray = new G4double[nz];
274  G4double *Rmax = new G4double[nz];
275  G4double *Rmin = new G4double[nz];
276 
277  OKAxis[0]=OKAxis[1]=OKAxis[2]=true;
278 
279  NegVolPars = 0;
280 
281  for(i=0; i<nz; i++){
282  G4int i4=3*i+3;
283  G4int i5=i4+1;
284  G4int i6=i4+2;
285  DzArray[i] = rpar[i4]*cm;
286  Rmin[i] = rpar[i5]*cm;
287  Rmax[i] = rpar[i6]*cm;
288  }
289  solid = new G4Polycone(vname, pPhi1, dPhi, nz, DzArray, Rmin, Rmax);
290  delete [] DzArray;
291  delete [] Rmin;
292  delete [] Rmax;
293 
294  } else if ( shape == "ELTU" ) {
295  G4double dX = rpar[0]*cm;
296  G4double dY = rpar[1]*cm;
297  G4double dZ = rpar[2]*cm;
298 
299  OKAxis[0]=OKAxis[1]=OKAxis[2]=true;
300 
301  NegVolPars = dX<0 || dY<0 || dZ<0;
302 
303  if (!(NegVolPars || Deferred)) {
304  solid = new G4EllipticalTube(vname, dX, dY, dZ);
305  }
306 
307  } else if ( shape == "HYPE" ) {
308  G4double pRmin = rpar[0]*cm;
309  G4double pRmax = rpar[1]*cm;
310  G4double pDz = rpar[2]*cm;
311  G4double pThet = rpar[3]*deg;
312 
313  NegVolPars = pRmin<0 || pRmax<0 || pDz<0;
314 
315  if (!(NegVolPars || Deferred)){
316  solid = new G4Hype(vname, pRmin, pRmax, pThet, pThet, pDz);
317  } else {
318  G4cerr << "Negative length parameters not supported for shape "
319  << shape << G4endl;
320  }
321 
322  } else if ( shape == "GTRA" ) {
323  // $$$ not implemented.
324  G4cerr << "GTRA not supported" << G4endl;
325 
326  } else if ( shape == "CTUB" ) {
327  // $$$ not implemented.
328  G4cerr << "CTUB not supported" << G4endl;
329  }
330  return solid;
331 }
332 
333 
334 
335 
336 
337 
338 
339 
340 
341 
static const double cm
Definition: G4SIunits.hh:118
Definition: G4Para.hh:77
Definition: G4Box.hh:64
Definition: G4Tubs.hh:85
Definition: G4Trd.hh:72
int G4int
Definition: G4Types.hh:78
static const double deg
Definition: G4SIunits.hh:151
Definition: G4Hype.hh:67
bool G4bool
Definition: G4Types.hh:79
Definition: G4Cons.hh:83
#define G4endl
Definition: G4ios.hh:61
G4VSolid * G3toG4MakeSolid(const G4String &vname, const G4String &shape, const G4double *rpar, const G4int npar, G4bool &NegVolPars, G4bool &Deferred, G4bool *OKAxis)
double G4double
Definition: G4Types.hh:76
G4GLOB_DLL std::ostream G4cerr