Geant4  10.02
G4EzVolume.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 // $Id: G4EzVolume.cc 66892 2013-01-17 10:57:59Z gunter $
27 // ====================================================================
28 // G4EzVolume.cc
29 //
30 // 2005 Q
31 // ====================================================================
32 #include "G4Material.hh"
33 #include "G4Box.hh"
34 #include "G4Tubs.hh"
35 #include "G4Cons.hh"
36 #include "G4Sphere.hh"
37 #include "G4Orb.hh"
38 #include "G4PVPlacement.hh"
39 #include "G4PVReplica.hh"
40 #include "G4PVParameterised.hh"
41 #include "G4VisAttributes.hh"
42 
43 #include "G4EzWorld.hh"
44 #include "G4EzVolume.hh"
46 
47 // ====================================================================
48 //
49 // class description
50 //
51 // ====================================================================
52 
55  : name("MyVolume"),
56  solid(0),
57  lv(0), lvsub(0),
58  nplacement(0)
60 {
61 }
62 
63 
66  : name(aname), solid(0), lv(0), lvsub(0),
67  nplacement(0)
69 {
70 }
71 
72 
76 {
77 }
78 
79 
82  G4double dx, G4double dy, G4double dz)
84 {
85  if(lv !=0 ) {
86  G4cout << "%%% Warning (G4EzVolume): volume is already created."
87  << G4endl;
88  return;
89  }
90 
91  solid= new G4Box(name, dx/2., dy/2., dz/2.);
92  lv= new G4LogicalVolume(solid, amaterial, name);
93 
94  // vis. attributes
95  va= new G4VisAttributes();
96  lv-> SetVisAttributes(va);
97 }
98 
99 
102  G4double rmin, G4double rmax, G4double dz,
103  G4double phi0, G4double dphi)
105 {
106  if(lv !=0 ) {
107  G4cout << "%%% Warning (G4EzVolume): volume is already created."
108  << G4endl;
109  return;
110  }
111 
112  solid= new G4Tubs(name, rmin, rmax, dz, phi0, dphi);
113  lv= new G4LogicalVolume(solid, amaterial, name);
114 
115  // vis. attributes
116  va= new G4VisAttributes();
117  lv-> SetVisAttributes(va);
118 }
119 
120 
123  G4double rmin1, G4double rmax1,
124  G4double rmin2, G4double rmax2,
125  G4double dz,
126  G4double phi0, G4double dphi)
128 {
129  if(lv !=0 ) {
130  G4cout << "%%% Warning (G4EzVolume): volume is already created."
131  << G4endl;
132  return;
133  }
134 
135  solid= new G4Cons(name, rmin1, rmax1, rmin2, rmax2,
136  dz, phi0, dphi);
137  lv= new G4LogicalVolume(solid, amaterial, name);
138 
139  // vis. attributes
140  va= new G4VisAttributes();
141  lv-> SetVisAttributes(va);
142 }
143 
144 
147  G4double rmin, G4double rmax,
148  G4double phi0, G4double dphi,
149  G4double theta0, G4double dtheta)
151 {
152  if(lv !=0 ) {
153  G4cout << "%%% Warning (G4EzVolume): volume is already created."
154  << G4endl;
155  return;
156  }
157 
158  solid= new G4Sphere(name, rmin, rmax, phi0, dphi, theta0, dtheta);
159  lv= new G4LogicalVolume(solid, amaterial, name);
160 
161  // vis. attributes
162  va= new G4VisAttributes();
163  lv-> SetVisAttributes(va);
164 }
165 
166 
170 {
171  if(lv !=0 ) {
172  G4cout << "%%% Warning (G4EzVolume): volume is already created."
173  << G4endl;
174  return;
175  }
176 
177  solid= new G4Orb(name, rmax);
178  lv= new G4LogicalVolume(solid, amaterial, name);
179 
180  // vis. attributes
181  va= new G4VisAttributes();
182  lv-> SetVisAttributes(va);
183 }
184 
185 
188  G4int ncopy,
189  G4EzVolume* parent)
191 {
192  if(lv==0) {
193  G4cout << "%%% Warning (G4EzVolume): volume is not yet created."
194  << G4endl;
195  return 0;
196  }
197 
198  G4PVPlacement* pv;
199  if(parent==0) { // place it in the world
201  pv= new G4PVPlacement(0, pos, name, lv, world, false, ncopy);
202  } else {
203  pv= new G4PVPlacement(0, pos, lv, name, parent->lv, false, ncopy);
204  }
205 
206  nplacement++;
207  return pv;
208 }
209 
210 
213  G4int ncopy,
214  G4EzVolume* parent)
216 {
217  if(lv==0) {
218  G4cout << "%%% Warning (G4EzVolume): volume is not yet created."
219  << G4endl;
220  return 0;
221  }
222 
223  G4PVPlacement* pv;
224  if(parent==0) { // place it in the world
226  pv= new G4PVPlacement(transform, name, lv, world, false, ncopy);
227  } else {
228  pv= new G4PVPlacement(transform, lv, name, parent->lv, false, ncopy);
229  }
230 
231  nplacement++;
232  return pv;
233 }
234 
235 
238  EAxis pAxis, G4int nReplicas,
239  G4double width, G4double offset)
241 {
242  if(lv==0) {
243  G4cout << "%%% Warning (G4EzVolume): volume is not yet created."
244  << G4endl;
245  return 0;
246  }
247 
248  G4PVReplica* pv=
249  new G4PVReplica(name, lv, parent->lv, pAxis, nReplicas, width, offset);
250 
251  nplacement += nReplicas;
252  return pv;
253 }
254 
255 
259 {
260  // creating voxel volume...
261  G4Box* avolume= dynamic_cast<G4Box*>(solid);
262  if(avolume ==0 ) {
263  G4cout << "%%% Error (G4EzVolume): voxelization is valid "
264  << "only for Box geometry." << G4endl;
265  return G4ThreeVector();
266  }
267 
268  if(lvsub !=0) {
269  G4cout << "%%% Error (G4EzVolume): already voxelized." << G4endl;
270  return G4ThreeVector();
271  }
272 
273  G4double dx= (avolume-> GetXHalfLength())*2.;
274  G4double dy= (avolume-> GetYHalfLength())*2.;
275  G4double dz= (avolume-> GetZHalfLength())*2.;
276 
277  // voxel size
278  G4double ddx= dx/nx;
279  G4double ddy= dy/ny;
280  G4double ddz= dz/nz;
281 
282  G4Box* voxel= new G4Box("voxel", ddx/2., ddy/2., ddz/2.);
283  G4Material* voxelMaterial= lv-> GetMaterial();
284  lvsub= new G4LogicalVolume(voxel, voxelMaterial, "voxel");
285 
286  G4VisAttributes* vavoxel= new G4VisAttributes(G4Color(1.,0.,0.));
287  lvsub-> SetVisAttributes(vavoxel);
288 
289  G4EzVoxelParameterization* voxelParam=
290  new G4EzVoxelParameterization(ddx, ddy, ddz, nx, ny, nz);
291  G4int nvoxel= nx*ny*nz;
292  new G4PVParameterised(name+"_voxel", lvsub, lv, kXAxis,
293  nvoxel, voxelParam);
294 
295  return G4ThreeVector(ddx, ddy, ddz);
296 }
297 
298 
299 
303 {
304  if(lvsub!=0) {
306  return;
307  }
308 
309  if(lv!=0) lv-> SetSensitiveDetector(asd);
310 
311 }
312 
G4VisAttributes * va
Definition: G4EzVolume.hh:59
G4String name
Definition: G4EzVolume.hh:55
CLHEP::Hep3Vector G4ThreeVector
G4ThreeVector VoxelizeIt(G4int nx, G4int ny, G4int nz)
Definition: G4EzVolume.cc:257
Definition: G4Box.hh:64
G4int nplacement
Definition: G4EzVolume.hh:60
G4String name
Definition: TRTMaterials.hh:40
void CreateBoxVolume(G4Material *amaterial, G4double dx, G4double dy, G4double dz)
Definition: G4EzVolume.cc:81
Definition: G4Tubs.hh:85
#define width
void CreateOrbVolume(G4Material *amaterial, G4double rmax)
Definition: G4EzVolume.cc:168
void CreateTubeVolume(G4Material *amaterial, G4double rmin, G4double rmax, G4double dz, G4double phi0=0., G4double dphi=360 *deg)
Definition: G4EzVolume.cc:101
int G4int
Definition: G4Types.hh:78
G4LogicalVolume * lv
Definition: G4EzVolume.hh:57
G4GLOB_DLL std::ostream G4cout
void SetSensitiveDetector(G4VSensitiveDetector *asd)
Definition: G4EzVolume.cc:301
Definition: G4Cons.hh:83
void CreateSphereVolume(G4Material *amaterial, G4double rmin, G4double rmax, G4double phi0=0., G4double dphi=360.*deg, G4double theta0=0., G4double dtheta=180.*deg)
Definition: G4EzVolume.cc:146
HepGeom::Transform3D G4Transform3D
G4Colour G4Color
Definition: G4Color.hh:42
Definition: G4Orb.hh:61
void CreateConeVolume(G4Material *amaterial, G4double rmin1, G4double rmax1, G4double rmin2, G4double rmax2, G4double dz, G4double phi0=0., G4double dphi=360.*deg)
Definition: G4EzVolume.cc:122
static G4VPhysicalVolume * GetWorldVolume()
Definition: G4EzWorld.hh:74
G4VSolid * solid
Definition: G4EzVolume.hh:56
EAxis
Definition: geomdefs.hh:54
G4LogicalVolume * lvsub
Definition: G4EzVolume.hh:58
G4VPhysicalVolume * ReplicateIt(G4EzVolume *parent, EAxis pAxis, G4int nReplicas, G4double width, G4double offset=0)
Definition: G4EzVolume.cc:237
#define G4endl
Definition: G4ios.hh:61
G4VPhysicalVolume * PlaceIt(const G4ThreeVector &pos, G4int ncopy=0, G4EzVolume *parent=0)
Definition: G4EzVolume.cc:187
double G4double
Definition: G4Types.hh:76
static const G4double pos
G4Material * GetMaterial() const
Definition: G4EzVolume.hh:143