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 hadronic/Hadr03/src/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 "G4Tubs.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 "G4SystemOfUnits.hh" << 49 #include "G4RunManager.hh" 49 #include "G4Tubs.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() 55 { << 58 :G4VUserDetectorConstruction(), 56 fAbsorRadius = 15 * mm; << 59 fAbsorMaterial(0), fLAbsor(0), fContainMaterial(0), fLContain(0), 57 fAbsorLength = 60 * mm; << 60 fWorldMaterial(0), fPWorld(0), fDetectorMessenger(0) 58 fContainThickness = 2.4 * mm; << 61 { >> 62 fAbsorRadius = 15*mm; >> 63 fAbsorLength = 60*mm; >> 64 fContainThickness = 2.4*mm; 59 DefineMaterials(); 65 DefineMaterials(); 60 SetAbsorMaterial("BeO"); << 66 SetAbsorMaterial ("BeO"); 61 SetContainMaterial("Stainless-Steel"); 67 SetContainMaterial("Stainless-Steel"); 62 fDetectorMessenger = new DetectorMessenger(t 68 fDetectorMessenger = new DetectorMessenger(this); 63 } 69 } 64 70 65 //....oooOO0OOooo........oooOO0OOooo........oo 71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 66 72 67 DetectorConstruction::~DetectorConstruction() 73 DetectorConstruction::~DetectorConstruction() 68 { << 74 { delete fDetectorMessenger;} 69 delete fDetectorMessenger; << 70 } << 71 75 72 //....oooOO0OOooo........oooOO0OOooo........oo 76 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 73 77 74 G4VPhysicalVolume* DetectorConstruction::Const 78 G4VPhysicalVolume* DetectorConstruction::Construct() 75 { 79 { 76 return ConstructVolumes(); 80 return ConstructVolumes(); 77 } 81 } 78 82 79 //....oooOO0OOooo........oooOO0OOooo........oo 83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 80 84 81 void DetectorConstruction::DefineMaterials() 85 void DetectorConstruction::DefineMaterials() 82 { 86 { 83 G4int ncomponents, natoms; 87 G4int ncomponents, natoms; 84 << 88 85 G4Element* Be = new G4Element("Beryllium", " << 89 G4Element* Be = new G4Element("Beryllium","Be" , 4., 9.01*g/mole); 86 G4Element* N = new G4Element("Nitrogen", "N" << 90 G4Element* N = new G4Element("Nitrogen" ,"N" , 7., 14.01*g/mole); 87 G4Element* O = new G4Element("Oxygen", "O", << 91 G4Element* O = new G4Element("Oxygen" ,"O" , 8., 16.00*g/mole); 88 G4Element* Cr = new G4Element("Chromium", "C << 92 G4Element* Cr = new G4Element("Chromium" ,"Cr" , 24., 51.99*g/mole); 89 G4Element* Fe = new G4Element("Iron", "Fe", << 93 G4Element* Fe = new G4Element("Iron" ,"Fe" , 26., 55.84*g/mole); 90 G4Element* Ni = new G4Element("Nickel", "Ni" << 94 G4Element* Ni = new G4Element("Nickel" ,"Ni" , 28., 58.69*g/mole); 91 << 95 92 G4Material* BeO = new G4Material("BeO", 3.05 << 96 G4Material* BeO = 93 BeO->AddElement(Be, natoms = 1); << 97 new G4Material("BeO", 3.05*g/cm3, ncomponents=2); 94 BeO->AddElement(O, natoms = 1); << 98 BeO->AddElement(Be, natoms=1); 95 << 99 BeO->AddElement( O, natoms=1); 96 G4Material* inox = new G4Material("Stainless << 100 97 inox->AddElement(Fe, 74 * perCent); << 101 G4Material* inox = 98 inox->AddElement(Cr, 18 * perCent); << 102 new G4Material("Stainless-Steel", 8*g/cm3, ncomponents=3); 99 inox->AddElement(Ni, 8 * perCent); << 103 inox->AddElement(Fe, 74*perCent); 100 << 104 inox->AddElement(Cr, 18*perCent); 101 G4Material* Air = new G4Material("Air", 1.29 << 105 inox->AddElement(Ni, 8*perCent); 102 Air->AddElement(N, 70. * perCent); << 106 103 Air->AddElement(O, 30. * perCent); << 107 G4Material* Air = >> 108 new G4Material("Air", 1.290*mg/cm3, ncomponents=2); >> 109 Air->AddElement(N, 70.*perCent); >> 110 Air->AddElement(O, 30.*perCent); 104 111 105 fWorldMaterial = Air; 112 fWorldMaterial = Air; 106 << 113 107 /// G4cout << *(G4Material::GetMaterialTable << 114 ///G4cout << *(G4Material::GetMaterialTable()) << G4endl; 108 } 115 } 109 116 110 //....oooOO0OOooo........oooOO0OOooo........oo 117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 111 118 112 G4Material* DetectorConstruction::MaterialWith << 119 G4Material* DetectorConstruction::MaterialWithSingleIsotope( G4String name, 113 << 120 G4String symbol, G4double density, G4int Z, G4int A) 114 { 121 { 115 // define a material from an isotope << 122 // define a material from an isotope 116 // << 123 // 117 G4int ncomponents; << 124 G4int ncomponents; 118 G4double abundance, massfraction; << 125 G4double abundance, massfraction; 119 << 120 G4Isotope* isotope = new G4Isotope(symbol, Z << 121 << 122 G4Element* element = new G4Element(name, sym << 123 element->AddIsotope(isotope, abundance = 100 << 124 126 125 G4Material* material = new G4Material(name, << 127 G4Isotope* isotope = new G4Isotope(symbol, Z, A); 126 material->AddElement(element, massfraction = << 128 >> 129 G4Element* element = new G4Element(name, symbol, ncomponents=1); >> 130 element->AddIsotope(isotope, abundance= 100.*perCent); >> 131 >> 132 G4Material* material = new G4Material(name, density, ncomponents=1); >> 133 material->AddElement(element, massfraction=100.*perCent); 127 134 128 return material; << 135 return material; 129 } 136 } 130 137 131 //....oooOO0OOooo........oooOO0OOooo........oo 138 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 132 139 133 G4VPhysicalVolume* DetectorConstruction::Const 140 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 134 { 141 { 135 // Cleanup old geometry 142 // Cleanup old geometry 136 G4GeometryManager::GetInstance()->OpenGeomet 143 G4GeometryManager::GetInstance()->OpenGeometry(); 137 G4PhysicalVolumeStore::GetInstance()->Clean( 144 G4PhysicalVolumeStore::GetInstance()->Clean(); 138 G4LogicalVolumeStore::GetInstance()->Clean() 145 G4LogicalVolumeStore::GetInstance()->Clean(); 139 G4SolidStore::GetInstance()->Clean(); 146 G4SolidStore::GetInstance()->Clean(); 140 << 147 141 // compute dimensions 148 // compute dimensions 142 G4double ContainRadius = fAbsorRadius + fCon 149 G4double ContainRadius = fAbsorRadius + fContainThickness; 143 G4double ContainLength = fAbsorLength + 2 * << 150 G4double ContainLength = fAbsorLength + 2*fContainThickness; 144 << 151 145 G4double WorldSizeXY = 2.4 * ContainRadius; << 152 G4double WorldSizeXY = 2.4*ContainRadius; 146 G4double WorldSizeZ = 1.2 * ContainLength; << 153 G4double WorldSizeZ = 1.2*ContainLength; 147 << 154 148 // World 155 // World 149 // 156 // 150 G4Box* sWorld = new G4Box("World", // name << 157 G4Box* 151 0.5 * WorldSizeXY, << 158 sWorld = new G4Box("World", //name 152 << 159 0.5*WorldSizeXY,0.5*WorldSizeXY,0.5*WorldSizeZ); //dimensions 153 G4LogicalVolume* lWorld = new G4LogicalVolum << 160 154 << 161 G4LogicalVolume* 155 << 162 lWorld = new G4LogicalVolume(sWorld, //shape 156 << 163 fWorldMaterial, //material 157 fPWorld = new G4PVPlacement(0, // no rotati << 164 "World"); //name 158 G4ThreeVector(), << 165 159 lWorld, // logi << 166 fPWorld = new G4PVPlacement(0, //no rotation 160 "World", // nam << 167 G4ThreeVector(), //at (0,0,0) 161 0, // mother vo << 168 lWorld, //logical volume 162 false, // no bo << 169 "World", //name 163 0); // copy num << 170 0, //mother volume >> 171 false, //no boolean operation >> 172 0); //copy number 164 173 165 // Container 174 // Container 166 // 175 // 167 G4Tubs* sContain = new G4Tubs("Container", << 176 G4Tubs* 168 0., ContainRad << 177 sContain = new G4Tubs("Container", //name 169 << 178 0., ContainRadius, 0.5*ContainLength, 0., twopi); //dimensions 170 fLContain = new G4LogicalVolume(sContain, / << 179 171 fContainMate << 180 fLContain = new G4LogicalVolume(sContain, //shape 172 fContainMate << 181 fContainMaterial, //material 173 << 182 fContainMaterial->GetName()); //name 174 new G4PVPlacement(0, // no rotation << 183 175 G4ThreeVector(), // at (0 << 184 new G4PVPlacement(0, //no rotation 176 fLContain, // logical vol << 185 G4ThreeVector(), //at (0,0,0) 177 fContainMaterial->GetName( << 186 fLContain, //logical volume 178 lWorld, // mother volume << 187 fContainMaterial->GetName(), //name 179 false, // no boolean oper << 188 lWorld, //mother volume 180 0); // copy number << 189 false, //no boolean operation >> 190 0); //copy number 181 191 182 // Absorber 192 // Absorber 183 // 193 // 184 G4Tubs* sAbsor = new G4Tubs("Absorber", // << 194 G4Tubs* 185 0., fAbsorRadius << 195 sAbsor = new G4Tubs("Absorber", //name 186 << 196 0., fAbsorRadius, 0.5*fAbsorLength, 0., twopi); //dimensions 187 fLAbsor = new G4LogicalVolume(sAbsor, // sh << 197 188 fAbsorMaterial << 198 fLAbsor = new G4LogicalVolume(sAbsor, //shape 189 fAbsorMaterial << 199 fAbsorMaterial, //material 190 << 200 fAbsorMaterial->GetName()); //name 191 new G4PVPlacement(0, // no rotation << 201 192 G4ThreeVector(), // at (0 << 202 new G4PVPlacement(0, //no rotation 193 fLAbsor, // logical volum << 203 G4ThreeVector(), //at (0,0,0) 194 fAbsorMaterial->GetName(), << 204 fLAbsor, //logical volume 195 fLContain, // mother vol << 205 fAbsorMaterial->GetName(), //name 196 false, // no boolean oper << 206 fLContain, //mother volume 197 0); // copy number << 207 false, //no boolean operation >> 208 0); //copy number 198 209 199 PrintParameters(); 210 PrintParameters(); 200 << 211 201 // always return the root volume << 212 //always return the root volume 202 // 213 // 203 return fPWorld; 214 return fPWorld; 204 } 215 } 205 216 206 //....oooOO0OOooo........oooOO0OOooo........oo 217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 207 218 208 void DetectorConstruction::PrintParameters() 219 void DetectorConstruction::PrintParameters() 209 { 220 { 210 G4cout << "\n The Absorber is a cylinder of << 221 G4cout << "\n The Absorber is a cylinder of " << fAbsorMaterial->GetName() 211 << " radius = " << G4BestUnit(fAbsor << 222 << " radius = " << G4BestUnit(fAbsorRadius,"Length") 212 << " length = " << G4BestUnit(fAbsor << 223 << " length = " << G4BestUnit(fAbsorLength,"Length") << G4endl; 213 G4cout << " The Container is a cylinder of " << 224 G4cout << " The Container is a cylinder of " << fContainMaterial->GetName() 214 << " thickness = " << G4BestUnit(fCo << 225 << " thickness = " << G4BestUnit(fContainThickness,"Length") << G4endl; 215 << 226 216 G4cout << "\n" << fAbsorMaterial << G4endl; << 227 G4cout << "\n" << fAbsorMaterial << G4endl; 217 G4cout << "\n" << fContainMaterial << G4endl << 228 G4cout << "\n" << fContainMaterial << G4endl; 218 } 229 } 219 230 220 //....oooOO0OOooo........oooOO0OOooo........oo 231 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 221 232 222 void DetectorConstruction::SetAbsorMaterial(G4 233 void DetectorConstruction::SetAbsorMaterial(G4String materialChoice) 223 { 234 { 224 // search the material by its name 235 // search the material by its name 225 G4Material* pttoMaterial = G4NistManager::In << 236 G4Material* pttoMaterial = 226 << 237 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 227 if (pttoMaterial) { << 238 >> 239 if (pttoMaterial) { 228 fAbsorMaterial = pttoMaterial; 240 fAbsorMaterial = pttoMaterial; 229 if (fLAbsor) { << 241 if(fLAbsor) { fLAbsor->SetMaterial(fAbsorMaterial); } 230 fLAbsor->SetMaterial(fAbsorMaterial); << 231 } << 232 G4RunManager::GetRunManager()->PhysicsHasB 242 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 233 } << 243 } else { 234 else { << 244 G4cout << "\n--> warning from DetectorConstruction::SetAbsorMaterial : " 235 G4cout << "\n--> warning from DetectorCons << 245 << materialChoice << " not found" << G4endl; 236 << " not found" << G4endl; << 246 } 237 } << 238 } 247 } 239 248 240 //....oooOO0OOooo........oooOO0OOooo........oo 249 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 241 250 242 void DetectorConstruction::SetContainMaterial( 251 void DetectorConstruction::SetContainMaterial(G4String materialChoice) 243 { 252 { 244 // search the material by its name 253 // search the material by its name 245 G4Material* pttoMaterial = G4NistManager::In << 254 G4Material* pttoMaterial = 246 << 255 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 247 if (pttoMaterial) { << 256 >> 257 if (pttoMaterial) { 248 fContainMaterial = pttoMaterial; 258 fContainMaterial = pttoMaterial; 249 if (fLContain) { << 259 if(fLContain) { fLContain->SetMaterial(fContainMaterial); } 250 fLContain->SetMaterial(fContainMaterial) << 251 } << 252 G4RunManager::GetRunManager()->PhysicsHasB 260 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 253 } << 261 } else { 254 else { << 262 G4cout << "\n--> warning from DetectorConstruction::SetContainMaterial : " 255 G4cout << "\n--> warning from DetectorCons << 263 << materialChoice << " not found" << G4endl; 256 << " not found" << G4endl; << 264 } 257 } << 258 } 265 } 259 266 260 //....oooOO0OOooo........oooOO0OOooo........oo 267 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 261 268 262 void DetectorConstruction::SetAbsorRadius(G4do 269 void DetectorConstruction::SetAbsorRadius(G4double value) 263 { 270 { 264 fAbsorRadius = value; 271 fAbsorRadius = value; 265 G4RunManager::GetRunManager()->ReinitializeG 272 G4RunManager::GetRunManager()->ReinitializeGeometry(); 266 } 273 } 267 274 268 //....oooOO0OOooo........oooOO0OOooo........oo 275 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 269 276 270 void DetectorConstruction::SetAbsorLength(G4do 277 void DetectorConstruction::SetAbsorLength(G4double value) 271 { 278 { 272 fAbsorLength = value; 279 fAbsorLength = value; 273 G4RunManager::GetRunManager()->ReinitializeG 280 G4RunManager::GetRunManager()->ReinitializeGeometry(); 274 } 281 } 275 282 276 //....oooOO0OOooo........oooOO0OOooo........oo 283 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 277 284 278 void DetectorConstruction::SetContainThickness 285 void DetectorConstruction::SetContainThickness(G4double value) 279 { 286 { 280 fContainThickness = value; 287 fContainThickness = value; 281 G4RunManager::GetRunManager()->ReinitializeG 288 G4RunManager::GetRunManager()->ReinitializeGeometry(); 282 } 289 } 283 290 284 //....oooOO0OOooo........oooOO0OOooo........oo 291 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 292 285 293