[807] | 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: DetectorConstruction.cc,v 1.8 2007/01/11 15:41:46 vnivanch Exp $ |
---|
| 27 | // GEANT4 tag $Name: geant4-09-01-patch-02 $ |
---|
| 28 | // |
---|
| 29 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 31 | |
---|
| 32 | #include "DetectorConstruction.hh" |
---|
| 33 | #include "DetectorMessenger.hh" |
---|
| 34 | |
---|
| 35 | #include "G4Material.hh" |
---|
| 36 | #include "G4Box.hh" |
---|
| 37 | #include "G4LogicalVolume.hh" |
---|
| 38 | #include "G4PVPlacement.hh" |
---|
| 39 | #include "G4UniformMagField.hh" |
---|
| 40 | |
---|
| 41 | #include "G4GeometryManager.hh" |
---|
| 42 | #include "G4PhysicalVolumeStore.hh" |
---|
| 43 | #include "G4LogicalVolumeStore.hh" |
---|
| 44 | #include "G4SolidStore.hh" |
---|
| 45 | |
---|
| 46 | #include "G4NistManager.hh" |
---|
| 47 | |
---|
| 48 | #include "G4UnitsTable.hh" |
---|
| 49 | |
---|
| 50 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 51 | |
---|
| 52 | DetectorConstruction::DetectorConstruction() |
---|
| 53 | { |
---|
| 54 | // default parameter values |
---|
| 55 | absorSizeX = absorSizeYZ = 20*cm; |
---|
| 56 | worldSizeX = worldSizeYZ = 1.2*absorSizeX; |
---|
| 57 | |
---|
| 58 | worldMaterial = absorMaterial = 0; |
---|
| 59 | magField = 0; |
---|
| 60 | lAbsor = 0; |
---|
| 61 | |
---|
| 62 | tallySize = G4ThreeVector(); |
---|
| 63 | tallyMaterial = 0; |
---|
| 64 | tallyMass = 0.; |
---|
| 65 | tallyNumber = 0; |
---|
| 66 | tallyPosition = new G4ThreeVector[MaxTally]; |
---|
| 67 | lTally = 0; |
---|
| 68 | |
---|
| 69 | DefineMaterials(); |
---|
| 70 | SetMaterial("Water"); |
---|
| 71 | SetTallyMaterial("Water"); |
---|
| 72 | |
---|
| 73 | // create commands for interactive definition of the detector |
---|
| 74 | detectorMessenger = new DetectorMessenger(this); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 78 | |
---|
| 79 | DetectorConstruction::~DetectorConstruction() |
---|
| 80 | { delete [] tallyPosition; delete detectorMessenger;} |
---|
| 81 | |
---|
| 82 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 83 | |
---|
| 84 | G4VPhysicalVolume* DetectorConstruction::Construct() |
---|
| 85 | { |
---|
| 86 | return ConstructVolumes(); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 90 | |
---|
| 91 | void DetectorConstruction::DefineMaterials() |
---|
| 92 | { |
---|
| 93 | // |
---|
| 94 | // define Elements |
---|
| 95 | // |
---|
| 96 | G4double z, a; |
---|
| 97 | |
---|
| 98 | G4Element* H = new G4Element("Hydrogen", "H", z= 1, a= 1.008*g/mole); |
---|
| 99 | G4Element* N = new G4Element("Nitrogen", "N", z= 7, a= 14.01*g/mole); |
---|
| 100 | G4Element* O = new G4Element("Oxygen" , "O", z= 8, a= 16.00*g/mole); |
---|
| 101 | |
---|
| 102 | // |
---|
| 103 | // define Materials. |
---|
| 104 | // |
---|
| 105 | G4double density, temperature, pressure; |
---|
| 106 | G4int ncomponents, natoms; |
---|
| 107 | G4double fractionmass; |
---|
| 108 | |
---|
| 109 | G4Material* H2O = |
---|
| 110 | new G4Material("Water", density= 1.0*g/cm3, ncomponents=2); |
---|
| 111 | H2O->AddElement(H, natoms=2); |
---|
| 112 | H2O->AddElement(O, natoms=1); |
---|
| 113 | H2O->GetIonisation()->SetMeanExcitationEnergy(75.0*eV); |
---|
| 114 | |
---|
| 115 | G4Material* Air = |
---|
| 116 | new G4Material("Air" , density= 1.290*mg/cm3, ncomponents=2); |
---|
| 117 | Air->AddElement(N, fractionmass=0.7); |
---|
| 118 | Air->AddElement(O, fractionmass=0.3); |
---|
| 119 | |
---|
| 120 | density = universe_mean_density; //from PhysicalConstants.h |
---|
| 121 | pressure = 3.e-18*pascal; |
---|
| 122 | temperature = 2.73*kelvin; |
---|
| 123 | G4Material* vacuum = |
---|
| 124 | new G4Material("Galactic",z= 1,a= 1.008*g/mole,density, |
---|
| 125 | kStateGas,temperature,pressure); |
---|
| 126 | |
---|
| 127 | //default materials |
---|
| 128 | worldMaterial = vacuum; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 132 | |
---|
| 133 | G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() |
---|
| 134 | { |
---|
| 135 | G4GeometryManager::GetInstance()->OpenGeometry(); |
---|
| 136 | G4PhysicalVolumeStore::GetInstance()->Clean(); |
---|
| 137 | G4LogicalVolumeStore::GetInstance()->Clean(); |
---|
| 138 | G4SolidStore::GetInstance()->Clean(); |
---|
| 139 | |
---|
| 140 | // World |
---|
| 141 | // |
---|
| 142 | G4Box* |
---|
| 143 | sWorld = new G4Box("World", //name |
---|
| 144 | worldSizeX/2,worldSizeYZ/2,worldSizeYZ/2); //dimensions |
---|
| 145 | |
---|
| 146 | G4LogicalVolume* |
---|
| 147 | lWorld = new G4LogicalVolume(sWorld, //shape |
---|
| 148 | worldMaterial, //material |
---|
| 149 | "World"); //name |
---|
| 150 | |
---|
| 151 | G4VPhysicalVolume* |
---|
| 152 | pWorld = new G4PVPlacement(0, //no rotation |
---|
| 153 | G4ThreeVector(), //at (0,0,0) |
---|
| 154 | lWorld, //logical volume |
---|
| 155 | "World", //name |
---|
| 156 | 0, //mother volume |
---|
| 157 | false, //no boolean operation |
---|
| 158 | 0); //copy number |
---|
| 159 | // |
---|
| 160 | // Absorber |
---|
| 161 | // |
---|
| 162 | G4Box* |
---|
| 163 | sAbsor = new G4Box("Absorber", //name |
---|
| 164 | absorSizeX/2,absorSizeYZ/2,absorSizeYZ/2); //dimensions |
---|
| 165 | |
---|
| 166 | lAbsor = new G4LogicalVolume(sAbsor, //shape |
---|
| 167 | absorMaterial, //material |
---|
| 168 | "Absorber"); //name |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | new G4PVPlacement(0, //no rotation |
---|
| 172 | G4ThreeVector(), //at (0,0,0) |
---|
| 173 | lAbsor, //logical volume |
---|
| 174 | "Absorber", //name |
---|
| 175 | lWorld, //mother volume |
---|
| 176 | false, //no boolean operation |
---|
| 177 | 0); //copy number |
---|
| 178 | // |
---|
| 179 | // Tallies (optional) |
---|
| 180 | // |
---|
| 181 | if (tallyNumber > 0) { |
---|
| 182 | G4Box* |
---|
| 183 | sTally = new G4Box("Tally",tallySize.x()/2,tallySize.y()/2,tallySize.z()/2); |
---|
| 184 | lTally = new G4LogicalVolume(sTally,tallyMaterial,"Tally"); |
---|
| 185 | |
---|
| 186 | for (G4int j=0; j<tallyNumber; j++) |
---|
| 187 | { |
---|
| 188 | new G4PVPlacement(0, //no rotation |
---|
| 189 | tallyPosition[j], //position |
---|
| 190 | lTally, //logical volume |
---|
| 191 | "Tally", //name |
---|
| 192 | lAbsor, //mother volume |
---|
| 193 | false, //no boolean operation |
---|
| 194 | j); //copy number |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | tallyMass = tallySize.x()*tallySize.y()*tallySize.z() |
---|
| 198 | *(tallyMaterial->GetDensity()); |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | PrintParameters(); |
---|
| 202 | |
---|
| 203 | // |
---|
| 204 | //always return the World volume |
---|
| 205 | // |
---|
| 206 | return pWorld; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 210 | |
---|
| 211 | void DetectorConstruction::PrintParameters() |
---|
| 212 | { |
---|
| 213 | G4cout << *(G4Material::GetMaterialTable()) << G4endl; |
---|
| 214 | G4cout << "\n---------------------------------------------------------\n"; |
---|
| 215 | G4cout << "---> The Absorber is " << G4BestUnit(absorSizeX,"Length") |
---|
| 216 | << " of " << absorMaterial->GetName() << G4endl; |
---|
| 217 | G4cout << "\n---------------------------------------------------------\n"; |
---|
| 218 | |
---|
| 219 | if (tallyNumber > 0) { |
---|
| 220 | G4cout << "---> There are " << tallyNumber << " tallies : " |
---|
| 221 | << G4BestUnit(tallySize,"Length") |
---|
| 222 | << " of " << tallyMaterial->GetName() |
---|
| 223 | << " (mass : " << G4BestUnit(tallyMass,"Mass") << ")" << G4endl; |
---|
| 224 | |
---|
| 225 | for (G4int j=0; j<tallyNumber; j++) |
---|
| 226 | G4cout << "tally " << j << ": " |
---|
| 227 | << "position = " << G4BestUnit(tallyPosition[j],"Length") << G4endl; |
---|
| 228 | G4cout << "\n---------------------------------------------------------\n"; |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 233 | |
---|
| 234 | void DetectorConstruction::SetSizeX(G4double value) |
---|
| 235 | { |
---|
| 236 | absorSizeX = value; worldSizeX = 1.2*absorSizeX; |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 240 | |
---|
| 241 | void DetectorConstruction::SetSizeYZ(G4double value) |
---|
| 242 | { |
---|
| 243 | absorSizeYZ = value; |
---|
| 244 | worldSizeYZ = 1.2*absorSizeYZ; |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 248 | |
---|
| 249 | void DetectorConstruction::SetMaterial(G4String materialChoice) |
---|
| 250 | { |
---|
| 251 | // search the material by its name |
---|
| 252 | G4Material* pttoMaterial = |
---|
| 253 | G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); |
---|
| 254 | if (pttoMaterial) absorMaterial = pttoMaterial; |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 258 | |
---|
| 259 | #include "G4FieldManager.hh" |
---|
| 260 | #include "G4TransportationManager.hh" |
---|
| 261 | |
---|
| 262 | void DetectorConstruction::SetMagField(G4double fieldValue) |
---|
| 263 | { |
---|
| 264 | //apply a global uniform magnetic field along Z axis |
---|
| 265 | G4FieldManager* fieldMgr |
---|
| 266 | = G4TransportationManager::GetTransportationManager()->GetFieldManager(); |
---|
| 267 | |
---|
| 268 | if (magField) delete magField; //delete the existing magn field |
---|
| 269 | |
---|
| 270 | if (fieldValue!=0.) // create a new one if non nul |
---|
| 271 | { |
---|
| 272 | magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue)); |
---|
| 273 | fieldMgr->SetDetectorField(magField); |
---|
| 274 | fieldMgr->CreateChordFinder(magField); |
---|
| 275 | } |
---|
| 276 | else |
---|
| 277 | { |
---|
| 278 | magField = 0; |
---|
| 279 | fieldMgr->SetDetectorField(magField); |
---|
| 280 | } |
---|
| 281 | } |
---|
| 282 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 283 | |
---|
| 284 | void DetectorConstruction::SetTallySize(G4ThreeVector value) |
---|
| 285 | { |
---|
| 286 | tallySize = value; |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 290 | |
---|
| 291 | void DetectorConstruction::SetTallyMaterial(G4String materialChoice) |
---|
| 292 | { |
---|
| 293 | // search the material by its name |
---|
| 294 | G4Material* pttoMaterial = |
---|
| 295 | G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); |
---|
| 296 | if (pttoMaterial) tallyMaterial = pttoMaterial; |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 300 | |
---|
| 301 | void DetectorConstruction::SetTallyPosition(G4ThreeVector value) |
---|
| 302 | { |
---|
| 303 | if (tallyNumber < MaxTally) { |
---|
| 304 | tallyPosition[tallyNumber] = value; |
---|
| 305 | tallyNumber++; |
---|
| 306 | } |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 310 | |
---|
| 311 | #include "G4RunManager.hh" |
---|
| 312 | |
---|
| 313 | void DetectorConstruction::UpdateGeometry() |
---|
| 314 | { |
---|
| 315 | G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes()); |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|