ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4EzVolume.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4EzVolume.cc
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 // G4EzVolume.cc
28 //
29 // 2005 Q
30 // ====================================================================
31 #include "G4Material.hh"
32 #include "G4Box.hh"
33 #include "G4Tubs.hh"
34 #include "G4Cons.hh"
35 #include "G4Sphere.hh"
36 #include "G4Orb.hh"
37 #include "G4PVPlacement.hh"
38 #include "G4PVReplica.hh"
39 #include "G4PVParameterised.hh"
40 #include "G4VisAttributes.hh"
41 
42 #include "G4EzWorld.hh"
43 #include "G4EzVolume.hh"
45 
46 // ====================================================================
47 //
48 // class description
49 //
50 // ====================================================================
51 
54  : name("MyVolume"),
55  solid(0),
56  lv(0), lvsub(0),
57  nplacement(0)
59 {
60 }
61 
62 
65  : name(aname), solid(0), lv(0), lvsub(0),
66  nplacement(0)
68 {
69 }
70 
71 
75 {
76 }
77 
78 
83 {
84  if(lv !=0 ) {
85  G4cout << "%%% Warning (G4EzVolume): volume is already created."
86  << G4endl;
87  return;
88  }
89 
90  solid= new G4Box(name, dx/2., dy/2., dz/2.);
91  lv= new G4LogicalVolume(solid, amaterial, name);
92 
93  // vis. attributes
94  va= new G4VisAttributes();
95  lv-> SetVisAttributes(va);
96 }
97 
98 
102  G4double phi0, G4double dphi)
104 {
105  if(lv !=0 ) {
106  G4cout << "%%% Warning (G4EzVolume): volume is already created."
107  << G4endl;
108  return;
109  }
110 
111  solid= new G4Tubs(name, rmin, rmax, dz, phi0, dphi);
112  lv= new G4LogicalVolume(solid, amaterial, name);
113 
114  // vis. attributes
115  va= new G4VisAttributes();
116  lv-> SetVisAttributes(va);
117 }
118 
119 
122  G4double rmin1, G4double rmax1,
123  G4double rmin2, G4double rmax2,
124  G4double dz,
125  G4double phi0, G4double dphi)
127 {
128  if(lv !=0 ) {
129  G4cout << "%%% Warning (G4EzVolume): volume is already created."
130  << G4endl;
131  return;
132  }
133 
134  solid= new G4Cons(name, rmin1, rmax1, rmin2, rmax2,
135  dz, phi0, dphi);
136  lv= new G4LogicalVolume(solid, amaterial, name);
137 
138  // vis. attributes
139  va= new G4VisAttributes();
140  lv-> SetVisAttributes(va);
141 }
142 
143 
146  G4double rmin, G4double rmax,
147  G4double phi0, G4double dphi,
148  G4double theta0, G4double dtheta)
150 {
151  if(lv !=0 ) {
152  G4cout << "%%% Warning (G4EzVolume): volume is already created."
153  << G4endl;
154  return;
155  }
156 
157  solid= new G4Sphere(name, rmin, rmax, phi0, dphi, theta0, dtheta);
158  lv= new G4LogicalVolume(solid, amaterial, name);
159 
160  // vis. attributes
161  va= new G4VisAttributes();
162  lv-> SetVisAttributes(va);
163 }
164 
165 
169 {
170  if(lv !=0 ) {
171  G4cout << "%%% Warning (G4EzVolume): volume is already created."
172  << G4endl;
173  return;
174  }
175 
176  solid= new G4Orb(name, rmax);
177  lv= new G4LogicalVolume(solid, amaterial, name);
178 
179  // vis. attributes
180  va= new G4VisAttributes();
181  lv-> SetVisAttributes(va);
182 }
183 
184 
187  G4int ncopy,
188  G4EzVolume* parent)
190 {
191  if(lv==0) {
192  G4cout << "%%% Warning (G4EzVolume): volume is not yet created."
193  << G4endl;
194  return 0;
195  }
196 
197  G4PVPlacement* pv;
198  if(parent==0) { // place it in the world
200  pv= new G4PVPlacement(0, pos, name, lv, world, false, ncopy);
201  } else {
202  pv= new G4PVPlacement(0, pos, lv, name, parent->lv, false, ncopy);
203  }
204 
205  nplacement++;
206  return pv;
207 }
208 
209 
212  G4int ncopy,
213  G4EzVolume* parent)
215 {
216  if(lv==0) {
217  G4cout << "%%% Warning (G4EzVolume): volume is not yet created."
218  << G4endl;
219  return 0;
220  }
221 
222  G4PVPlacement* pv;
223  if(parent==0) { // place it in the world
225  pv= new G4PVPlacement(transform, name, lv, world, false, ncopy);
226  } else {
227  pv= new G4PVPlacement(transform, lv, name, parent->lv, false, ncopy);
228  }
229 
230  nplacement++;
231  return pv;
232 }
233 
234 
237  EAxis pAxis, G4int nReplicas,
238  G4double width, G4double offset)
240 {
241  if(lv==0) {
242  G4cout << "%%% Warning (G4EzVolume): volume is not yet created."
243  << G4endl;
244  return 0;
245  }
246 
247  G4PVReplica* pv=
248  new G4PVReplica(name, lv, parent->lv, pAxis, nReplicas, width, offset);
249 
250  nplacement += nReplicas;
251  return pv;
252 }
253 
254 
258 {
259  // creating voxel volume...
260  G4Box* avolume= dynamic_cast<G4Box*>(solid);
261  if(avolume ==0 ) {
262  G4cout << "%%% Error (G4EzVolume): voxelization is valid "
263  << "only for Box geometry." << G4endl;
264  return G4ThreeVector();
265  }
266 
267  if(lvsub !=0) {
268  G4cout << "%%% Error (G4EzVolume): already voxelized." << G4endl;
269  return G4ThreeVector();
270  }
271 
272  G4double dx= (avolume-> GetXHalfLength())*2.;
273  G4double dy= (avolume-> GetYHalfLength())*2.;
274  G4double dz= (avolume-> GetZHalfLength())*2.;
275 
276  // voxel size
277  G4double ddx= dx/nx;
278  G4double ddy= dy/ny;
279  G4double ddz= dz/nz;
280 
281  G4Box* voxel= new G4Box("voxel", ddx/2., ddy/2., ddz/2.);
282  G4Material* voxelMaterial= lv-> GetMaterial();
283  lvsub= new G4LogicalVolume(voxel, voxelMaterial, "voxel");
284 
285  G4VisAttributes* vavoxel= new G4VisAttributes(G4Color(1.,0.,0.));
286  lvsub-> SetVisAttributes(vavoxel);
287 
288  G4EzVoxelParameterization* voxelParam=
289  new G4EzVoxelParameterization(ddx, ddy, ddz, nx, ny, nz);
290  G4int nvoxel= nx*ny*nz;
291  new G4PVParameterised(name+"_voxel", lvsub, lv, kXAxis,
292  nvoxel, voxelParam);
293 
294  return G4ThreeVector(ddx, ddy, ddz);
295 }
296 
297 
298 
302 {
303  if(lvsub!=0) {
304  lvsub-> SetSensitiveDetector(asd);
305  return;
306  }
307 
308  if(lv!=0) lv-> SetSensitiveDetector(asd);
309 
310 }
311