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 // 29 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 32 33 #include "DetectorConstruction.hh" 33 #include "DetectorConstruction.hh" 34 << 35 #include "DetectorMessenger.hh" 34 #include "DetectorMessenger.hh" >> 35 #include "G4Material.hh" >> 36 #include "G4NistManager.hh" 36 37 37 #include "G4Box.hh" 38 #include "G4Box.hh" 38 #include "G4GeometryManager.hh" << 39 #include "G4LogicalVolume.hh" 39 #include "G4LogicalVolume.hh" 40 #include "G4LogicalVolumeStore.hh" << 41 #include "G4Material.hh" << 42 #include "G4NistManager.hh" << 43 #include "G4PVPlacement.hh" 40 #include "G4PVPlacement.hh" 44 #include "G4PhysicalConstants.hh" << 41 >> 42 #include "G4GeometryManager.hh" 45 #include "G4PhysicalVolumeStore.hh" 43 #include "G4PhysicalVolumeStore.hh" 46 #include "G4RunManager.hh" << 44 #include "G4LogicalVolumeStore.hh" 47 #include "G4SolidStore.hh" 45 #include "G4SolidStore.hh" >> 46 #include "G4RunManager.hh" >> 47 48 #include "G4SystemOfUnits.hh" 48 #include "G4SystemOfUnits.hh" >> 49 #include "G4PhysicalConstants.hh" 49 #include "G4UnitsTable.hh" 50 #include "G4UnitsTable.hh" 50 51 51 //....oooOO0OOooo........oooOO0OOooo........oo 52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 52 53 53 DetectorConstruction::DetectorConstruction() 54 DetectorConstruction::DetectorConstruction() 54 { 55 { 55 // default geometrical parameters 56 // default geometrical parameters 56 fAbsorThickness = 1 * cm; << 57 fAbsorThickness = 1*cm; 57 fAbsorSizeYZ = 1 * cm; << 58 fAbsorSizeYZ = 1*cm; 58 fWorldSizeX = 1.2 * fAbsorThickness; << 59 fWorldSizeX = 1.2*fAbsorThickness; 59 fWorldSizeYZ = 1.2 * fAbsorSizeYZ; << 60 fWorldSizeYZ = 1.2*fAbsorSizeYZ; 60 61 61 // materials 62 // materials 62 DefineMaterials(); 63 DefineMaterials(); 63 SetAbsorMaterial("G4_Co"); 64 SetAbsorMaterial("G4_Co"); 64 65 65 // create commands for interactive definitio 66 // create commands for interactive definition of the geometry 66 fDetectorMessenger = new DetectorMessenger(t 67 fDetectorMessenger = new DetectorMessenger(this); 67 } 68 } 68 69 69 //....oooOO0OOooo........oooOO0OOooo........oo 70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 70 71 71 DetectorConstruction::~DetectorConstruction() 72 DetectorConstruction::~DetectorConstruction() 72 { << 73 { delete fDetectorMessenger;} 73 delete fDetectorMessenger; << 74 } << 75 74 76 //....oooOO0OOooo........oooOO0OOooo........oo 75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 77 76 78 G4VPhysicalVolume* DetectorConstruction::Const 77 G4VPhysicalVolume* DetectorConstruction::Construct() 79 { 78 { 80 return ConstructVolumes(); 79 return ConstructVolumes(); 81 } 80 } 82 81 83 //....oooOO0OOooo........oooOO0OOooo........oo 82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 84 83 85 void DetectorConstruction::DefineMaterials() 84 void DetectorConstruction::DefineMaterials() 86 { 85 { 87 // specific element name for thermal neutron 86 // specific element name for thermal neutronHP 88 // (see G4ParticleHPThermalScatteringNames.c 87 // (see G4ParticleHPThermalScatteringNames.cc) 89 88 90 G4int ncomponents, natoms; 89 G4int ncomponents, natoms; 91 90 92 // pressurized water 91 // pressurized water 93 G4Element* H = new G4Element("TS_H_of_Water" << 92 G4Element* H = new G4Element("TS_H_of_Water" ,"H" , 1., 1.0079*g/mole); 94 G4Element* O = new G4Element("Oxygen", "O", << 93 G4Element* O = new G4Element("Oxygen" ,"O" , 8., 16.00*g/mole); 95 G4Material* H2O = new G4Material("Water_ts", << 94 G4Material* H2O = 96 593 * kelvi << 95 new G4Material("Water_ts", 1.000*g/cm3, ncomponents=2, 97 H2O->AddElement(H, natoms = 2); << 96 kStateLiquid, 593*kelvin, 150*bar); 98 H2O->AddElement(O, natoms = 1); << 97 H2O->AddElement(H, natoms=2); 99 H2O->GetIonisation()->SetMeanExcitationEnerg << 98 H2O->AddElement(O, natoms=1); >> 99 H2O->GetIonisation()->SetMeanExcitationEnergy(78.0*eV); 100 100 101 // heavy water 101 // heavy water 102 G4Isotope* H2 = new G4Isotope("H2", 1, 2); << 102 G4Isotope* H2 = new G4Isotope("H2",1,2); 103 G4Element* D = new G4Element("TS_D_of_Heavy_ << 103 G4Element* D = new G4Element("TS_D_of_Heavy_Water", "D", 1); 104 D->AddIsotope(H2, 100 * perCent); << 104 D->AddIsotope(H2, 100*perCent); 105 G4Material* D2O = new G4Material("HeavyWater << 105 G4Material* D2O = new G4Material("HeavyWater", 1.11*g/cm3, ncomponents=2, 106 293.15 * ke << 106 kStateLiquid, 293.15*kelvin, 1*atmosphere); 107 D2O->AddElement(D, natoms = 2); << 107 D2O->AddElement(D, natoms=2); 108 D2O->AddElement(O, natoms = 1); << 108 D2O->AddElement(O, natoms=1); 109 109 110 // graphite 110 // graphite 111 G4Isotope* C12 = new G4Isotope("C12", 6, 12) << 111 G4Isotope* C12 = new G4Isotope("C12", 6, 12); 112 G4Element* C = new G4Element("TS_C_of_Graphi << 112 G4Element* C = new G4Element("TS_C_of_Graphite","C", ncomponents=1); 113 C->AddIsotope(C12, 100. * perCent); << 113 C->AddIsotope(C12, 100.*perCent); 114 G4Material* graphite = new G4Material("graph << 114 G4Material* graphite = 115 293 * << 115 new G4Material("graphite", 2.27*g/cm3, ncomponents=1, 116 graphite->AddElement(C, natoms = 1); << 116 kStateSolid, 293*kelvin, 1*atmosphere); >> 117 graphite->AddElement(C, natoms=1); 117 118 118 // example of vacuum 119 // example of vacuum 119 fWorldMaterial = new G4Material("Galactic", << 120 fWorldMaterial = new G4Material("Galactic", 1, 1.01*g/mole, 120 2.73 * kelvi << 121 universe_mean_density, kStateGas, 2.73*kelvin, 3.e-18*pascal); 121 122 122 /// G4cout << *(G4Material::GetMaterialTable << 123 ///G4cout << *(G4Material::GetMaterialTable()) << G4endl; 123 } 124 } 124 125 125 //....oooOO0OOooo........oooOO0OOooo........oo 126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 126 127 127 G4Material* DetectorConstruction::MaterialWith << 128 G4Material* DetectorConstruction::MaterialWithSingleIsotope( G4String name, 128 << 129 G4String symbol, G4double density, G4int Z, G4int A) 129 { 130 { 130 // define a material from an isotope << 131 // define a material from an isotope 131 // << 132 // 132 G4int ncomponents; << 133 G4int ncomponents; 133 G4double abundance, massfraction; << 134 G4double abundance, massfraction; 134 << 135 G4Isotope* isotope = new G4Isotope(symbol, Z << 136 135 137 G4Element* element = new G4Element(name, sym << 136 G4Isotope* isotope = new G4Isotope(symbol, Z, A); 138 element->AddIsotope(isotope, abundance = 100 << 137 >> 138 G4Element* element = new G4Element(name, symbol, ncomponents=1); >> 139 element->AddIsotope(isotope, abundance= 100.*perCent); >> 140 >> 141 G4Material* material = new G4Material(name, density, ncomponents=1); >> 142 material->AddElement(element, massfraction=100.*perCent); 139 143 140 G4Material* material = new G4Material(name, << 144 return material; 141 material->AddElement(element, massfraction = << 142 << 143 return material; << 144 } 145 } 145 146 146 //....oooOO0OOooo........oooOO0OOooo........oo 147 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 147 148 148 G4VPhysicalVolume* DetectorConstruction::Const 149 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 149 { 150 { 150 // Cleanup old geometry 151 // Cleanup old geometry 151 G4GeometryManager::GetInstance()->OpenGeomet 152 G4GeometryManager::GetInstance()->OpenGeometry(); 152 G4PhysicalVolumeStore::GetInstance()->Clean( 153 G4PhysicalVolumeStore::GetInstance()->Clean(); 153 G4LogicalVolumeStore::GetInstance()->Clean() 154 G4LogicalVolumeStore::GetInstance()->Clean(); 154 G4SolidStore::GetInstance()->Clean(); 155 G4SolidStore::GetInstance()->Clean(); 155 156 156 // World 157 // World 157 // 158 // 158 fWorldSizeX = 1.2 * fAbsorThickness; << 159 fWorldSizeX = 1.2*fAbsorThickness; 159 fWorldSizeYZ = 1.2 * fAbsorSizeYZ; << 160 fWorldSizeYZ = 1.2*fAbsorSizeYZ; 160 << 161 161 G4Box* sWorld = new G4Box("World", // name << 162 G4Box* 162 fWorldSizeX / 2, f << 163 sWorld = new G4Box("World", //name 163 << 164 fWorldSizeX/2,fWorldSizeYZ/2,fWorldSizeYZ/2); //dimensions 164 G4LogicalVolume* lWorld = new G4LogicalVolum << 165 165 << 166 G4LogicalVolume* 166 << 167 lWorld = new G4LogicalVolume(sWorld, //shape 167 << 168 fWorldMaterial, //material 168 fWorldVolume = new G4PVPlacement(0, // no r << 169 "World"); //name 169 G4ThreeVect << 170 170 lWorld, // << 171 fWorldVolume = new G4PVPlacement(0, //no rotation 171 "World", / << 172 G4ThreeVector(), //at (0,0,0) 172 0, // moth << 173 lWorld, //logical volume 173 false, // << 174 "World", //name 174 0); // cop << 175 0, //mother volume 175 << 176 false, //no boolean operation >> 177 0); //copy number >> 178 176 // Absorber 179 // Absorber 177 // 180 // 178 G4Box* sAbsor = new G4Box("Absorber", // na << 181 G4Box* sAbsor = new G4Box("Absorber", //name 179 fAbsorThickness / << 182 fAbsorThickness/2, fAbsorSizeYZ/2, fAbsorSizeYZ/2); //dimensions 180 183 181 fLAbsor = new G4LogicalVolume(sAbsor, // sh << 184 fLAbsor = new G4LogicalVolume(sAbsor, //shape 182 fAbsorMaterial << 185 fAbsorMaterial, //material 183 fAbsorMaterial << 186 fAbsorMaterial->GetName()); //name 184 << 187 185 new G4PVPlacement(0, // no rotation << 188 new G4PVPlacement(0, //no rotation 186 G4ThreeVector(), // at (0 << 189 G4ThreeVector(), //at (0,0,0) 187 fLAbsor, // logical volum << 190 fLAbsor, //logical volume 188 fAbsorMaterial->GetName(), << 191 fAbsorMaterial->GetName(), //name 189 lWorld, // mother volume << 192 lWorld, //mother volume 190 false, // no boolean oper << 193 false, //no boolean operation 191 0); // copy number << 194 0); //copy number 192 195 193 PrintParameters(); 196 PrintParameters(); 194 << 197 195 // always return the root volume << 198 //always return the root volume 196 // 199 // 197 return fWorldVolume; 200 return fWorldVolume; 198 } 201 } 199 202 200 //....oooOO0OOooo........oooOO0OOooo........oo 203 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 201 204 202 void DetectorConstruction::PrintParameters() 205 void DetectorConstruction::PrintParameters() 203 { 206 { 204 G4cout << "\n The Absorber is " << G4BestUni << 207 G4cout << "\n The Absorber is " << G4BestUnit(fAbsorThickness,"Length") 205 << fAbsorMaterial->GetName() << "\n \ << 208 << " of " << fAbsorMaterial->GetName() 206 << fAbsorMaterial << G4endl; << 209 << "\n \n" << fAbsorMaterial << G4endl; 207 } 210 } 208 211 209 //....oooOO0OOooo........oooOO0OOooo........oo 212 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 210 213 211 void DetectorConstruction::SetAbsorMaterial(G4 214 void DetectorConstruction::SetAbsorMaterial(G4String materialChoice) 212 { 215 { 213 // search the material by its name 216 // search the material by its name 214 G4Material* pttoMaterial = G4NistManager::In << 217 G4Material* pttoMaterial = 215 << 218 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 216 if (pttoMaterial) { << 219 >> 220 if (pttoMaterial) { 217 fAbsorMaterial = pttoMaterial; 221 fAbsorMaterial = pttoMaterial; 218 if (fLAbsor) { << 222 if(fLAbsor) { fLAbsor->SetMaterial(fAbsorMaterial); } 219 fLAbsor->SetMaterial(fAbsorMaterial); << 220 } << 221 G4RunManager::GetRunManager()->PhysicsHasB 223 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 222 } << 224 } else { 223 else { << 225 G4cout << "\n--> warning from DetectorConstruction::SetMaterial : " 224 G4cout << "\n--> warning from DetectorCons << 226 << materialChoice << " not found" << G4endl; 225 << " not found" << G4endl; << 227 } 226 } << 227 } 228 } 228 229 229 //....oooOO0OOooo........oooOO0OOooo........oo 230 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 230 231 231 void DetectorConstruction::SetAbsorThickness(G 232 void DetectorConstruction::SetAbsorThickness(G4double value) 232 { 233 { 233 fAbsorThickness = value; 234 fAbsorThickness = value; 234 G4RunManager::GetRunManager()->ReinitializeG 235 G4RunManager::GetRunManager()->ReinitializeGeometry(); 235 } 236 } 236 237 237 //....oooOO0OOooo........oooOO0OOooo........oo 238 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 238 239 239 void DetectorConstruction::SetAbsorSizeYZ(G4do 240 void DetectorConstruction::SetAbsorSizeYZ(G4double value) 240 { 241 { 241 fAbsorSizeYZ = value; 242 fAbsorSizeYZ = value; 242 G4RunManager::GetRunManager()->ReinitializeG 243 G4RunManager::GetRunManager()->ReinitializeGeometry(); 243 } 244 } 244 245 245 //....oooOO0OOooo........oooOO0OOooo........oo 246 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 246 247