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