Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 /// \file DetectorConstruction.cc 26 /// \file DetectorConstruction.cc 27 /// \brief Implementation of the DetectorConst 27 /// \brief Implementation of the DetectorConstruction class 28 // 28 // >> 29 // $Id: DetectorConstruction.cc 70755 2013-06-05 12:17:48Z ihrivnac $ 29 // 30 // >> 31 30 //....oooOO0OOooo........oooOO0OOooo........oo 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 34 33 #include "DetectorConstruction.hh" 35 #include "DetectorConstruction.hh" 34 << 35 #include "DetectorMessenger.hh" 36 #include "DetectorMessenger.hh" >> 37 #include "G4Material.hh" >> 38 #include "G4NistManager.hh" 36 39 37 #include "G4Box.hh" 40 #include "G4Box.hh" 38 #include "G4GeometryManager.hh" << 41 #include "G4Sphere.hh" 39 #include "G4LogicalVolume.hh" 42 #include "G4LogicalVolume.hh" 40 #include "G4LogicalVolumeStore.hh" << 41 #include "G4Material.hh" << 42 #include "G4NistManager.hh" << 43 #include "G4PVPlacement.hh" 43 #include "G4PVPlacement.hh" 44 #include "G4PhysicalConstants.hh" << 44 >> 45 #include "G4GeometryManager.hh" 45 #include "G4PhysicalVolumeStore.hh" 46 #include "G4PhysicalVolumeStore.hh" 46 #include "G4RunManager.hh" << 47 #include "G4LogicalVolumeStore.hh" 47 #include "G4SolidStore.hh" 48 #include "G4SolidStore.hh" 48 #include "G4Sphere.hh" << 49 #include "G4RunManager.hh" 49 #include "G4SystemOfUnits.hh" << 50 50 #include "G4UnitsTable.hh" 51 #include "G4UnitsTable.hh" >> 52 #include "G4SystemOfUnits.hh" >> 53 #include "G4PhysicalConstants.hh" 51 54 52 //....oooOO0OOooo........oooOO0OOooo........oo 55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 53 56 54 DetectorConstruction::DetectorConstruction() 57 DetectorConstruction::DetectorConstruction() >> 58 :G4VUserDetectorConstruction(), >> 59 fMaterial(0), fLAbsor(0), fWorldMat(0), fPWorld(0), fDetectorMessenger(0) 55 { 60 { 56 fRadius = 30 * cm; << 61 fRadius = 30*cm; 57 fWorldSize = 1.1 * fRadius; << 62 fWorldSize = 1.1*fRadius; 58 DefineMaterials(); 63 DefineMaterials(); 59 SetMaterial("Water_ts"); << 64 SetMaterial("Water_ts"); 60 fDetectorMessenger = new DetectorMessenger(t 65 fDetectorMessenger = new DetectorMessenger(this); 61 } 66 } 62 67 63 //....oooOO0OOooo........oooOO0OOooo........oo 68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 64 69 65 DetectorConstruction::~DetectorConstruction() 70 DetectorConstruction::~DetectorConstruction() 66 { << 71 { delete fDetectorMessenger;} 67 delete fDetectorMessenger; << 68 } << 69 72 70 //....oooOO0OOooo........oooOO0OOooo........oo 73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 71 74 72 G4VPhysicalVolume* DetectorConstruction::Const 75 G4VPhysicalVolume* DetectorConstruction::Construct() 73 { 76 { 74 return ConstructVolumes(); 77 return ConstructVolumes(); 75 } 78 } 76 79 77 //....oooOO0OOooo........oooOO0OOooo........oo 80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 78 81 79 void DetectorConstruction::DefineMaterials() 82 void DetectorConstruction::DefineMaterials() 80 { 83 { 81 // specific element name for thermal neutron 84 // specific element name for thermal neutronHP 82 // (see G4ParticleHPThermalScatteringNames.c 85 // (see G4ParticleHPThermalScatteringNames.cc) 83 86 84 G4int ncomponents, natoms; 87 G4int ncomponents, natoms; 85 88 86 // pressurized water 89 // pressurized water 87 G4Element* H = new G4Element("TS_H_of_Water" << 90 G4Element* H = new G4Element("TS_H_of_Water" ,"H" , 1., 1.0079*g/mole); 88 G4Element* O = new G4Element("Oxygen", "O", << 91 G4Element* O = new G4Element("Oxygen" ,"O" , 8., 16.00*g/mole); 89 G4Material* H2O = new G4Material("Water_ts", << 92 G4Material* H2O = 90 593 * kelvi << 93 new G4Material("Water_ts", 1.000*g/cm3, ncomponents=2, 91 H2O->AddElement(H, natoms = 2); << 94 kStateLiquid, 593*kelvin, 150*bar); 92 H2O->AddElement(O, natoms = 1); << 95 H2O->AddElement(H, natoms=2); 93 H2O->GetIonisation()->SetMeanExcitationEnerg << 96 H2O->AddElement(O, natoms=1); >> 97 H2O->GetIonisation()->SetMeanExcitationEnergy(78.0*eV); 94 98 95 // heavy water 99 // heavy water 96 G4Isotope* H2 = new G4Isotope("H2", 1, 2); << 100 G4Isotope* H2 = new G4Isotope("H2",1,2); 97 G4Element* D = new G4Element("TS_D_of_Heavy_ << 101 G4Element* D = new G4Element("TS_D_of_Heavy_Water", "D", 1); 98 D->AddIsotope(H2, 100 * perCent); << 102 D->AddIsotope(H2, 100*perCent); 99 G4Material* D2O = new G4Material("HeavyWater << 103 G4Material* D2O = new G4Material("HeavyWater", 1.11*g/cm3, ncomponents=2, 100 293.15 * ke << 104 kStateLiquid, 293.15*kelvin, 1*atmosphere); 101 D2O->AddElement(D, natoms = 2); << 105 D2O->AddElement(D, natoms=2); 102 D2O->AddElement(O, natoms = 1); << 106 D2O->AddElement(O, natoms=1); 103 107 104 // graphite 108 // graphite 105 G4Isotope* C12 = new G4Isotope("C12", 6, 12) << 109 G4Isotope* C12 = new G4Isotope("C12", 6, 12); 106 G4Element* C = new G4Element("TS_C_of_Graphi << 110 G4Element* C = new G4Element("TS_C_of_Graphite","C", ncomponents=1); 107 C->AddIsotope(C12, 100. * perCent); << 111 C->AddIsotope(C12, 100.*perCent); 108 G4Material* graphite = new G4Material("graph << 112 G4Material* graphite = 109 293 * << 113 new G4Material("graphite", 2.27*g/cm3, ncomponents=1, 110 graphite->AddElement(C, natoms = 1); << 114 kStateSolid, 293*kelvin, 1*atmosphere); 111 << 115 graphite->AddElement(C, natoms=1); 112 // NE213 << 116 113 G4Material* ne213 = new G4Material("NE213", << 117 //NE213 114 ne213->AddElement(H, 9.2 * perCent); << 118 G4Material* ne213 = 115 ne213->AddElement(C, 90.8 * perCent); << 119 new G4Material("NE213", 0.874*g/cm3, ncomponents=2); 116 << 120 ne213->AddElement(H, 9.2*perCent); >> 121 ne213->AddElement(C, 90.8*perCent); >> 122 117 // example of vacuum 123 // example of vacuum 118 fWorldMat = new G4Material("Galactic", 1, 1. << 124 fWorldMat = new G4Material("Galactic", 1, 1.01*g/mole, universe_mean_density, 119 2.73 * kelvin, 3. << 125 kStateGas, 2.73*kelvin, 3.e-18*pascal); 120 126 121 /// G4cout << *(G4Material::GetMaterialTable << 127 ///G4cout << *(G4Material::GetMaterialTable()) << G4endl; 122 } 128 } 123 129 124 //....oooOO0OOooo........oooOO0OOooo........oo 130 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 125 131 126 G4Material* DetectorConstruction::MaterialWith << 132 G4Material* DetectorConstruction::MaterialWithSingleIsotope( G4String name, 127 << 133 G4String symbol, G4double density, G4int Z, G4int A) 128 { 134 { 129 // define a material from an isotope << 135 // define a material from an isotope 130 // << 136 // 131 G4int ncomponents; << 137 G4int ncomponents; 132 G4double abundance, massfraction; << 138 G4double abundance, massfraction; 133 << 134 G4Isotope* isotope = new G4Isotope(symbol, Z << 135 139 136 G4Element* element = new G4Element(name, sym << 140 G4Isotope* isotope = new G4Isotope(symbol, Z, A); 137 element->AddIsotope(isotope, abundance = 100 << 141 >> 142 G4Element* element = new G4Element(name, symbol, ncomponents=1); >> 143 element->AddIsotope(isotope, abundance= 100.*perCent); >> 144 >> 145 G4Material* material = new G4Material(name, density, ncomponents=1); >> 146 material->AddElement(element, massfraction=100.*perCent); 138 147 139 G4Material* material = new G4Material(name, << 148 return material; 140 material->AddElement(element, massfraction = << 141 << 142 return material; << 143 } 149 } 144 150 145 //....oooOO0OOooo........oooOO0OOooo........oo 151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 146 152 147 G4VPhysicalVolume* DetectorConstruction::Const 153 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 148 { 154 { 149 // Cleanup old geometry 155 // Cleanup old geometry 150 G4GeometryManager::GetInstance()->OpenGeomet 156 G4GeometryManager::GetInstance()->OpenGeometry(); 151 G4PhysicalVolumeStore::GetInstance()->Clean( 157 G4PhysicalVolumeStore::GetInstance()->Clean(); 152 G4LogicalVolumeStore::GetInstance()->Clean() 158 G4LogicalVolumeStore::GetInstance()->Clean(); 153 G4SolidStore::GetInstance()->Clean(); 159 G4SolidStore::GetInstance()->Clean(); 154 << 160 155 // World 161 // World 156 // 162 // 157 G4Box* sWorld = new G4Box("World", // name << 163 G4Box* 158 fWorldSize, fWorld << 164 sWorld = new G4Box("World", //name 159 << 165 fWorldSize,fWorldSize,fWorldSize); //dimensions 160 G4LogicalVolume* lWorld = new G4LogicalVolum << 166 161 << 167 G4LogicalVolume* 162 << 168 lWorld = new G4LogicalVolume(sWorld, //shape 163 << 169 fWorldMat, //material 164 fPWorld = new G4PVPlacement(0, // no rotati << 170 "World"); //name 165 G4ThreeVector(), << 171 166 lWorld, // logi << 172 fPWorld = new G4PVPlacement(0, //no rotation 167 "World", // nam << 173 G4ThreeVector(), //at (0,0,0) 168 0, // mother vo << 174 lWorld, //logical volume 169 false, // no bo << 175 "World", //name 170 0); // copy num << 176 0, //mother volume 171 << 177 false, //no boolean operation >> 178 0); //copy number >> 179 172 // Absorber 180 // Absorber 173 // 181 // 174 G4Sphere* sAbsor = new G4Sphere("Absorber", << 182 G4Sphere* 175 0., fRadius, << 183 sAbsor = new G4Sphere("Absorber", //name 176 << 184 0., fRadius, 0., twopi, 0., pi); //dimensions 177 fLAbsor = new G4LogicalVolume(sAbsor, // sh << 185 178 fMaterial, // << 186 fLAbsor = new G4LogicalVolume(sAbsor, //shape 179 fMaterial->Get << 187 fMaterial, //material 180 << 188 fMaterial->GetName()); //name 181 new G4PVPlacement(0, // no rotation << 189 182 G4ThreeVector(), // at (0 << 190 new G4PVPlacement(0, //no rotation 183 fLAbsor, // logical volum << 191 G4ThreeVector(), //at (0,0,0) 184 fMaterial->GetName(), // << 192 fLAbsor, //logical volume 185 lWorld, // mother volume << 193 fMaterial->GetName(), //name 186 false, // no boolean oper << 194 lWorld, //mother volume 187 0); // copy number << 195 false, //no boolean operation >> 196 0); //copy number 188 PrintParameters(); 197 PrintParameters(); 189 << 198 190 // always return the root volume << 199 //always return the root volume 191 // 200 // 192 return fPWorld; 201 return fPWorld; 193 } 202 } 194 203 195 //....oooOO0OOooo........oooOO0OOooo........oo 204 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 196 205 197 void DetectorConstruction::PrintParameters() 206 void DetectorConstruction::PrintParameters() 198 { 207 { 199 G4cout << "\n The Absorber is " << G4BestUni << 208 G4cout << "\n The Absorber is " << G4BestUnit(fRadius,"Length") 200 << "\n \n" << 209 << " of " << fMaterial->GetName() 201 << fMaterial << G4endl; << 210 << "\n \n" << fMaterial << G4endl; 202 } 211 } 203 212 204 //....oooOO0OOooo........oooOO0OOooo........oo 213 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 205 214 206 void DetectorConstruction::SetMaterial(G4Strin 215 void DetectorConstruction::SetMaterial(G4String materialChoice) 207 { 216 { 208 // search the material by its name 217 // search the material by its name 209 G4Material* pttoMaterial = G4NistManager::In << 218 G4Material* pttoMaterial = 210 << 219 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 211 if (pttoMaterial) { << 220 >> 221 if (pttoMaterial) { 212 fMaterial = pttoMaterial; 222 fMaterial = pttoMaterial; 213 if (fLAbsor) { << 223 if(fLAbsor) { fLAbsor->SetMaterial(fMaterial); } 214 fLAbsor->SetMaterial(fMaterial); << 215 } << 216 G4RunManager::GetRunManager()->PhysicsHasB 224 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 217 } << 225 } else { 218 else { << 226 G4cout << "\n--> warning from DetectorConstruction::SetMaterial : " 219 G4cout << "\n--> warning from DetectorCons << 227 << materialChoice << " not found" << G4endl; 220 << " not found" << G4endl; << 228 } 221 } << 222 } 229 } 223 230 224 //....oooOO0OOooo........oooOO0OOooo........oo 231 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 225 232 226 void DetectorConstruction::SetRadius(G4double 233 void DetectorConstruction::SetRadius(G4double value) 227 { 234 { 228 fRadius = value; 235 fRadius = value; 229 fWorldSize = 1.1 * fRadius; << 230 G4RunManager::GetRunManager()->ReinitializeG 236 G4RunManager::GetRunManager()->ReinitializeGeometry(); 231 } 237 } 232 238 233 //....oooOO0OOooo........oooOO0OOooo........oo 239 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 240 234 241